Ejemplo n.º 1
0
Archivo: console.c Proyecto: wugsh/wgs
/**
*  Reads an hexadecimal number
*
*  \param pvalue  Pointer to the uint32_t variable to contain the input value.
*/
extern uint32_t console_get_hexa_32(uint32_t * pvalue)
{
	uint8_t key;
	uint32_t dw = 0;
	uint32_t value = 0;

	for (dw = 0; dw < 8; dw++) {
		key = console_get_char();
		console_put_char(key);

		if (key >= '0' && key <= '9') {
			value = (value * 16) + (key - '0');
		} else {
			if (key >= 'A' && key <= 'F') {
				value = (value * 16) + (key - 'A' + 10);
			} else {
				if (key >= 'a' && key <= 'f') {
					value = (value * 16) + (key - 'a' + 10);
				} else {
					printf
					    ("\n\rIt is not a hexa character!\n\r");
					return 0;
				}
			}
		}
	}
	printf("\n\r");
	*pvalue = value;
	return 1;
}
Ejemplo n.º 2
0
Archivo: console.c Proyecto: wugsh/wgs
/**
*  Reads an integer
*
*  \param pvalue  Pointer to the uint32_t variable to contain the input value.
*/
extern uint32_t console_get_integer(uint32_t * pvalue)
{
	uint8_t key;
	uint8_t nb = 0;
	uint32_t value = 0;

	while (1) {
		key = console_get_char();
		console_put_char(key);

		if (key >= '0' && key <= '9') {
			value = (value * 10) + (key - '0');
			nb++;
		} else {
			if (key == 0x0D || key == ' ') {
				if (nb == 0) {
					printf
					    ("\n\rWrite a number and press ENTER or SPACE!\n\r");
					return 0;
				} else {
					printf("\n\r");
					*pvalue = value;
					return 1;
				}
			} else {
				printf("\n\r'%c' not a number!\n\r", key);
				return 0;
			}
		}
	}
}
Ejemplo n.º 3
0
/**
 *  \brief classd Application entry point
 *  \return Unused (ANSI-C compatibility)
 */
extern int main(void)
{
	uint8_t key;
	uint8_t attn = INITIAL_ATTENUATION;

	/* disable watchdog */
	wdt_disable();

	/* configure console */
	board_cfg_console();

	/* output example information */
	printf("-- CLASSD Example " SOFTPACK_VERSION " --\n\r");
	printf("-- " BOARD_NAME "\n\r");
	printf("-- Compiled: " __DATE__ " " __TIME__ " --\n\r");

	/* configure PIO muxing for ClassD */
	pio_configure(classd_pins, ARRAY_SIZE(classd_pins));

	/* initialize ClassD DMA channel */
	_initialize_dma();

	/* configure ClassD */
	_configure_classd();
	_set_attenuation(attn);

	while (1) {
		_display_menu();
		key = console_get_char();
		printf("%c\r\n", key);
		if (key == '1') {
			_display_audio_info((const struct _wav_header *)music_data);
		} else if (key == '2') {
			_playback_without_dma(attn);
		} else if (key == '3') {
			_playback_with_dma(attn);
		} else if (key == '4') {
			_output_audio_pmc_clock_to_pck1();
		} else if (key == '+') {
			if (attn > 1) {
				attn -= 3;
				_set_attenuation(attn);
			} else {
				printf("Attenuation is already at min (-1dB)\r\n");
			}
		} else if (key == '-') {
			if (attn < 76) {
				attn += 3;
				_set_attenuation(attn);
			} else {
				printf("Attenuation is already at max (-76dB)\r\n");
			}
		}
	}
}
Ejemplo n.º 4
0
/**
 * Monitor buttons of joystick status.
 * \param p_btn_status Pointer to button status bitmap.
 * \param p_dx        Pointer to fill x value.
 * \param p_dy        Pointer to fill y value.
 */
static uint8_t _buttons_monitor(uint8_t *btn_status, int8_t *dx, int8_t *dy)
{
	uint8_t is_changed = 0;
	btn_status = btn_status; /*dummy */

#ifdef NO_PUSHBUTTON
	/* - Movement W S A D */
	if (console_is_rx_ready())
	{
		uint8_t key = console_get_char();
		*dx = 0;
		*dy = 0;
		switch (key)
		{
		case 'i':
		case 'I':
			*dy = -SPEED_Y;
			is_changed = 1;
			break;
		case 'k':
		case 'K':
			*dy = +SPEED_Y;
			is_changed = 1;
			break;
		case 'j':
		case 'J':
			*dx = -SPEED_X;
			is_changed = 1;
			break;
		case 'l':
		case 'L':
			*dx = +SPEED_X;
			is_changed = 1;
			break;
		default:
			break;
		}
	}
#else
	/* - Movement buttons, Joystick or Push buttons */
	if (pio_get(&pins_joystick[JOYSTICK_LEFT]) == 0) {
		*dx = -SPEED_X;
		is_changed = 1;
	} else if (pio_get(&pins_joystick[JOYSTICK_RIGHT]) == 0) {
		*dx = SPEED_X;
		is_changed = 1;
	} else {
		*dx = 0;
	}
#endif

	return is_changed;
}
Ejemplo n.º 5
0
int console_read(void *buf, size_t count) {

	int i;
	unsigned char *buffer=buf;

	/* Read from input buffer */

	for(i=0;i<count;i++) {
		buffer[i]=console_get_char();
		if (buffer[i]==0) break;
	}

	return i;

}
Ejemplo n.º 6
0
static ssize_t sys_read(int fd, void *buf, size_t count)
{
    unsigned char *s = buf;
    size_t i = 0;
    for ( ; i < count; ) {
        // Get the next character.
        int ch = console_get_char();
        ++i;                    // Count the character.
        switch (ch) {
            // Some simple line handling.
        case 0x7F:
        case '\b':
            // Simple backspace handling.
            --i;
            if (i) {
              console_send_char('\b');
              console_send_char(' ');
              console_send_char('\b');
              --s;
              --i;
            }
            break;
        case '\n':
        case '\r':
            // Make sure we send both a CR and LF.
            console_send_char(ch == '\r' ? '\n' : '\r');
            *s = '\n';          // and send a newline back.
            return i;           // This read is done.
        default:
            // Echo input.
            console_send_char(ch);
            *s++ = ch;          // and send it back.
            break;
        }
    }
    return i;
}
Ejemplo n.º 7
0
/**
 * Displays a menu which enables the user to send several commands to the
 * smartcard and check its answers.
 */
static void _send_receive_commands( const struct _iso7816_desc* iso7816 )
{
    uint8_t pMessage[MAX_ANSWER_SIZE];
    uint8_t ucSize ;
    uint8_t ucKey ;
    uint8_t command;
    uint8_t i;

    /*  Clear message buffer */
    memset( pMessage, 0, sizeof( pMessage ) ) ;

    /*  Display menu */
    printf( "-I- Choose the command to send:\n\r" ) ;
    printf( "  1. " ) ;
    for ( i=0 ; i < sizeof( testCommand1 ) ; i++ ) {
        printf( "0x%X ", testCommand1[i] ) ;
    }
    printf( "\n\r  2. " ) ;
    for ( i=0 ; i < sizeof( testCommand2 ) ; i++ ) {
        printf( "0x%X ", testCommand2[i] ) ;
    }
    printf( "\n\r  3. " ) ;
    for ( i=0 ; i < sizeof( testCommand3 ) ; i++ ) {
        printf( "0x%X ", testCommand3[i] ) ;
    }
    printf( "\n\r" ) ;

    /*  Get user input */
    ucKey = 0 ;
    while ( ucKey != 'q' ) {
        printf( "\r                        " ) ;
        printf( "\rChoice ? (q to quit): " ) ;
        ucKey = console_get_char() ;
        printf( "%c", ucKey ) ;
        command = ucKey - '0';

        /*  Check user input */
        ucSize = 0 ;
        if ( command == 1 ) {
            printf( "\n\r-I- Sending command " ) ;
            for ( i=0 ; i < sizeof( testCommand1 ) ; i++ ) {
                printf( "0x%02X ", testCommand1[i] ) ;
            }
            printf( "...\n\r" ) ;
            ucSize = iso7816_xfr_block_TPDU_T0(iso7816, testCommand1, pMessage, sizeof( testCommand1 ) ) ;
        }
        else {
            if ( command == 2 ) {
                printf( "\n\r-I- Sending command " ) ;
                for ( i=0 ; i < sizeof( testCommand2 ) ; i++ ) {
                    printf("0x%02X ", testCommand2[i] ) ;
                }
                printf( "...\n\r" ) ;
                ucSize = iso7816_xfr_block_TPDU_T0(iso7816, testCommand2, pMessage, sizeof( testCommand2 ) ) ;
            }
			else {
                if ( command == 3 ) {
                    printf( "\n\r-I- Sending command " ) ;
                    for ( i=0 ; i < sizeof( testCommand3 ) ; i++ ) {
                        printf( "0x%02X ", testCommand3[i] ) ;
                    }
                    printf( "...\n\r" ) ;
                    ucSize = iso7816_xfr_block_TPDU_T0(iso7816, testCommand3, pMessage, sizeof( testCommand3 ) ) ;
                }
            }
       }

        /*  Output smartcard answer */
        if ( ucSize > 0 ) {
            printf( "\n\rAnswer: " ) ;
            for ( i=0 ; i < ucSize ; i++ ) {
                printf( "0x%02X ", pMessage[i] ) ;
            }
            printf( "\n\r" ) ;
        }
    }
    printf( "Exit ...\n\r" ) ;
}
Ejemplo n.º 8
0
static void get_command(char *p_buffer)
{
  unsigned char input = 0;
  int pos = 0;
  memset(p_buffer, 0, 256);

  do
  {
    input = console_get_char();
    //it's for secureCRT.
    //if(input == 10)
    //  continue;
    
    // add support for backspace key
    if(input == KEY_BACKSPACE) 
    {
      if(pos >= 1)
      {
        p_buffer[--pos] = '\0';
        Console_PutChar(input);
      }
    }
#ifdef ENABLE_CMD_HISTORY
    else if((input == KEY_PRE) || (input == KEY_NEXT))
    {
      char *tmp = NULL;
      
      if(input == KEY_PRE)
        tmp = get_pre_command();
      else
        tmp = get_next_command();
      if(tmp != NULL)
      {
        memset(p_buffer, 0, 256);
        memcpy(p_buffer, tmp, 256);

        for(; pos > 0; pos--)
          Console_PutChar(KEY_BACKSPACE);
        
        pos = strlen(p_buffer);
        OS_PRINTK("%s", p_buffer);
      }
      else
      {
        memset(p_buffer, 0, 256);
        for(; pos > 0; pos--)
          Console_PutChar(KEY_BACKSPACE);
        pos = 0;
      }
    }
#endif
    else
    {
      if(pos >= CU_MAX_STR_LENGTH)
      {
        OS_PRINTK("Stop. Exceed the input buffer!!!\n");
      }
      else
      {
          p_buffer[pos++] = input;
      }
    }
    TESTFM_ASSERT(pos != CU_MAX_STR_LENGTH);
  } while(input != 10 && input != 13);
  //} while(input != 13);

  p_buffer[pos-1] = '\0';
}
Ejemplo n.º 9
0
int si_comm_read(char message_data[], int message_data_size)
{
#ifdef BUILD_ARM_BB
    int read_status; 
    char c; 
    int pos;
    int n_tries; 
    int max_tries = 100000;  
    int end_found; 
    int stop_reading; 
    int char_found; 

    read_status = console_get_char(&c); 
    // console_put_char(c); 

    if (read_status == -1)
    {
        return SI_COMM_ERROR; 
    }
    if ((int) c < 32)
    {
        return SI_COMM_ERROR; 
    }

    // console_put_char((int) c + 1); 

    // there seems to be some writable characters for us

    // store first character
    message_data[0] = c; 

    // look for the rest
    end_found = 0; 
    stop_reading = 0; 
    pos = 1; 
    while (!end_found && !stop_reading)
    {
        // console_put_string("after a while\n"); 
        n_tries = 0; 
	char_found = 0; 
        while (n_tries < max_tries && !char_found)
        {
            read_status = console_get_char(&c); 
            char_found = read_status != 1 && (int) c >= 32; 
            n_tries++; 
        } 
        // console_put_string("after DO while\n"); 
        // console_put_char(c); 
        if (char_found)
	{
            // console_put_char(c); 
            if (c == '#')
	    {
                end_found = 1; 
                stop_reading = 1; 
	    }
            else
	    {
                message_data[pos] = c; 
                pos++; 
	    }
	}
	else
	{
            console_put_char(c); 
            stop_reading = 1; 
	}
    }
    if (end_found)
    {
        // console_put_string("end found\n"); 
        message_data[pos] = '\0'; 
        return SI_COMM_OK; 
    }
    else
    {
        // console_put_string("end NOT found\n"); 
        return SI_COMM_ERROR; 
    }
#else
    fd_set read_fds; 
    struct timeval waitd; 
    int stat; 
    int n; 

    int return_value; 

    waitd.tv_sec = 0;  
    waitd.tv_usec = 0; 

    FD_ZERO(&read_fds);
    FD_SET(newsockfd, &read_fds); 
    
    stat = select(newsockfd + 1, &read_fds, NULL, NULL, &waitd);

    if (stat < 0)
    {    
        printf("SELECT ERROR\n");
        return SI_COMM_ERROR; 
    }

    if (!(FD_ISSET(newsockfd, &read_fds)))
    {
        /* nothing to read, but otherwise OK */ 
        return SI_COMM_EMPTY; 
    }

    // printf("there seems to be data to be read\n");

    /* read the data */ 
#ifdef BUILD_X86_WIN_HOST
    n = recv(newsockfd,message_data,255,0);
#else
    n = read(newsockfd,message_data,255);
#endif
    if (n < 0) 
    {
        printf("ERROR reading from socket"); 
        return SI_COMM_ERROR; 
    }

    /* now we have data, let's check how many */ 
    if (n > message_data_size-1)
    {
        /* too many */
        message_data[message_data_size-1] = '\0'; 
        return_value = SI_COMM_ERROR; 
    }
    else
    {
        /* everything is ok - we have some data! */ 
        message_data[n-1] = '\0'; 
        return_value = SI_COMM_OK; 
    }           
    // printf("Here is the message: %sSTOP\n", message_data);

    return return_value; 
#endif
}
Ejemplo n.º 10
0
/**
 * \brief usb_cdc_serial Application entry point.
 *
 * Initializes drivers and start the USB <-> Serial bridge.
 */
int main(void)
{
	uint8_t is_usb_connected = 0;
	uint8_t usb_serial_read = 1;

	/* Disable watchdog */
	wdt_disable();

	/* Configure console */
	board_cfg_console();

	/* Output example information */
	printf("-- USB Device CDC Serial Project %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

	/* Initialize all USB power (off) */
	usb_power_configure();

	/* Configure USART */
	_configure_usart();

	/* CDC serial driver initialization */
	cdcd_serial_driver_initialize(&cdcd_serial_driver_descriptors);

	/* Help informaiton */
	_debug_help();

	/* connect if needed */
	usb_vbus_configure();

	/* Driver loop */
	while (1) {

		/* Device is not configured */
		if (usbd_get_state() < USBD_STATE_CONFIGURED) {

			if (is_usb_connected) {
				is_usb_connected = 0;
				is_cdc_serial_on  = 0;
			}

		} else if (is_usb_connected == 0) {
				is_usb_connected = 1;
		}

		/* Serial port ON/OFF */
		if (cdcd_serial_driver_get_control_line_state()
					& CDCControlLineState_DTR) {
			if (!is_cdc_serial_on) {
				is_cdc_serial_on = 1;
				}
			if(usb_serial_read == 1) {
				usb_serial_read = 0;
				/* Start receiving data on the USB */
				cdcd_serial_driver_read(usb_buffer, DATAPACKETSIZE,
							_usb_data_received, &usb_serial_read);
			}
			if(usart_rx_flag == true) {
				usart_rx_flag = false;
				cdcd_serial_driver_write((void *)&char_recv, 1, 0, 0);
				if(is_cdc_echo_on) {
					_usart_dma_tx((uint8_t*)&char_recv, 1);
				}
			}
		} else if (is_cdc_serial_on) {
			is_cdc_serial_on = 0;
		}
		
		if (console_is_rx_ready()) {
			uint8_t key = console_get_char();
			/* ESC: CDC Echo ON/OFF */
			if (key == 27) {

				printf("** CDC Echo %s\n\r",
						is_cdc_echo_on ? "OFF" : "ON");
				is_cdc_echo_on = !is_cdc_echo_on;

			} else if (key == 't') {
				/* 't': Test CDC writing  */
				_send_text();

			} else {
				printf("Alive\n\r");
				cdcd_serial_driver_write((char*)"Alive\n\r", 8,
						NULL, NULL);
				_usart_dma_tx((uint8_t*)"Alive\n\r", 8);
				_debug_help();
			}
		}
	}
}
Ejemplo n.º 11
0
/**
 *  \brief dma Application entry point
 *  \return Unused (ANSI-C compatibility)
 */
extern int main(void)
{
	uint8_t key;
	bool configured = false;

	/* Output example information */
	console_example_info("XDMA Example");

	/* Allocate a XDMA channel. */
	xdmad_channel = xdmad_allocate_channel(XDMAD_PERIPH_MEMORY, XDMAD_PERIPH_MEMORY);
	if (!xdmad_channel) {
		printf("-E- Can't allocate XDMA channel\n\r");
		return 0;
	}

	/* Display menu */
	_display_menu();
	while (1) {
		key = console_get_char();
		if (key >= 'a' && key <= 'd') {
			dma_data_width = key - 'a';
			_display_menu();
		} else if (key >= '0' && key <= '3') {
			dma_src_addr_mode = key - '0';
			_display_menu();
		} else if (key >= '4' && key <= '7') {
			dma_dest_addr_mode = key - '4';
			_display_menu();
		} else if (key >= '8' && key <= '9') {
			dma_memset = key - '8';
			if (dma_memset == 0 && dma_view == 0) {
				printf("-I- DMA View 0 cannot be used when MEMSET is in NORMAL mode, selecting DMA View 1 instead.\r\n");
				dma_view = 1;
			}
			_display_menu();
		}
		else if (key >= 'e' && key <= 'h') {
			dma_view = key - 'e';
			if (dma_view == 0 && dma_memset == 0) {
				printf("-I- DMA View 0 can only be used when MEMSET is in HW mode, enabling HW mode.\r\n");
				dma_memset = 1;
			}
			_display_menu();
		} else if (key == 'S' || key == 's') {
			dma_mode = 1;
			_configure_transfer();
			configured = true;
		} else if (key == 'M' || key == 'm') {
			dma_mode = 2;
			_configure_transfer();
			configured = true;
		} else if (key == 'L' || key == 'l') {
			dma_mode = 3;
			_configure_transfer();
			configured = true;
		} else if (key == 'H') {
			_display_menu();
		} else if (configured && (key == 'T' || key == 't')) {
			printf("-I- Start XDMA transfer\n\r");
			_start_dma_transfer();
			configured = false;
		}
	}
}
Ejemplo n.º 12
0
int main(void)
{
	uint8_t ucKey;

	/* Disable watchdog */
	wdt_disable();

	/* Configure console */
	board_cfg_console();

	/* Output example information */
	printf("\r\n\r\n\r\n");
	printf("-- RTC Example " SOFTPACK_VERSION " --\r\n");
	printf("-- " BOARD_NAME "\r\n");
	printf("-- Compiled: " __DATE__ " " __TIME__ " --\n\r");

	// put 25 °C as a default temp, if there is no temprature sensor
	Temperature = 25;

	printf("Configure TC.\r\n");
	configure_tc();

	/* Default RTC configuration */
	rtc_set_hour_mode(0);	/* 24-hour mode */
	struct _time empty_time = {0,0,0};
	if (rtc_set_time_alarm(&empty_time)) {
		printf("\r\n Disable time alarm fail!");
	}
	struct _date empty_date = {0,0,0};
	if (rtc_set_date_alarm(&empty_date)) {
		printf("\r\n Disable date alarm fail!");
	}

	/* Configure RTC interrupts */
	rtc_enable_it(RTC_IER_SECEN | RTC_IER_ALREN);
	aic_set_source_vector(ID_SYSC, sysc_handler);
	aic_enable(ID_SYSC);

	/* Refresh display once */
	_RefreshDisplay();
	new_time.hour = 0;
	new_time.min = 0;
	new_time.sec = 30;
	rtc_set_time_alarm(&new_time);
	bMenuShown = 0;
	alarmTriggered = 0;
	rtc_calibration(Temperature);

	/* Handle keypresses */
	while (1) {
		ucKey = console_get_char();

		/* set time */
		if (ucKey == 't') {
			bState = STATE_SET_TIME;
			aic_disable(ID_TC0);

			do {
				printf("\r\n\r\n Set time(hh:mm:ss): ");
			} while (get_new_time());

			/* if valid input, none of variable for time is 0xff */
			if (new_time.hour != 0xFF) {
				if (rtc_set_time (&new_time)) {
					printf
					    ("\r\n Time not set, invalid input!\n\r");
				}
			}

			bState = STATE_MENU;
			bMenuShown = 0;
			_RefreshDisplay();
			CountDownTimer = 0;
			aic_enable(ID_TC0);
		}

		/* clock calibration */
		else if (ucKey == 'p') {

			rtc_calibration(30);

			bState = STATE_MENU;
			bMenuShown = 0;
			_RefreshDisplay();
		}

		/* set date */
		else if (ucKey == 'd') {
			bState = STATE_SET_DATE;
			aic_disable(ID_TC0);

			do {
				printf("\r\n\r\n Set date(mm/dd/yyyy): ");
			} while (get_new_date());

			/* if valid input, none of variable for date is 0xff(ff) */
			if (new_date.year != 0xFFFF) {
				if (rtc_set_date(&new_date)) {
					printf
					    ("\r\n Date not set, invalid input!\r\n");
				}
			}

			/* only 'mm/dd' inputed */
			if (new_date.month != 0xFF && new_date.year == 0xFFFF) {
				printf("\r\n Not Set for no year field!\r\n");
			}

			bState = STATE_MENU;
			bMenuShown = 0;
			CountDownTimer = 0;
			aic_enable(ID_TC0);
			_RefreshDisplay();
		}

		/* set time alarm */
		else if (ucKey == 'i') {
			bState = STATE_SET_TIME_ALARM;
			aic_disable(ID_TC0);

			do {
				printf("\r\n\r\n Set time alarm(hh:mm:ss): ");
			} while (get_new_time());

			if (new_time.hour != 0xFF) {
				if (rtc_set_time_alarm(&new_time)) {
					printf
					    ("\r\n Time alarm not set, invalid input!\r\n");
				} else {
					printf
					    ("\r\n Time alarm is set at %02d:%02d:%02d!",
					     new_time.hour, new_time.min, new_time.sec);
				}
			}
			bState = STATE_MENU;
			bMenuShown = 0;
			alarmTriggered = 0;
			CountDownTimer = 0;
			aic_enable(ID_TC0);
			_RefreshDisplay();
		}

		/* set date alarm */
		else if (ucKey == 'm') {
			bState = STATE_SET_DATE_ALARM;
			aic_disable(ID_TC0);

			do {
				printf("\r\n\r\n Set date alarm(mm/dd/): ");
			} while (get_new_date());

			if (new_date.year == 0xFFFF && new_date.month != 0xFF) {
				if (rtc_set_date_alarm(&new_date)) {
					printf
					    ("\r\n Date alarm not set, invalid input!\r\n");
				} else {
					printf
					    ("\r\n Date alarm is set on %02d/%02d!",
					     new_date.month, new_date.day);
				}

			}
			bState = STATE_MENU;
			bMenuShown = 0;
			alarmTriggered = 0;
			CountDownTimer = 0;
			aic_enable(ID_TC0);
			_RefreshDisplay();
		}

		/* clear trigger flag */
		else if (ucKey == 'c') {
			alarmTriggered = 0;
			bMenuShown = 0;
			_RefreshDisplay();
		}

		/* quit */
		else if (ucKey == 'q') {
			break;
		}
	}

	return 0;
}
Ejemplo n.º 13
0
/**
 * \brief Get new time, successful value is put in new_date.year, new_date.month, new_date.day, new_date.week.
 */
static int get_new_date(void)
{
	char ucKey;
	int i = 0;

	/* clear setting variable */
	new_date.year = 0xFFFF;
	new_date.month = new_date.day = new_date.week = 0xFF;

	/* use time[] as a format template */
	while (1) {
		ucKey = console_get_char();

		/* end input */
		if (ucKey == 0x0d || ucKey == 0x0a) {
			printf("\r\n");
			break;
		}

		/* DEL or BACKSPACE */
		if (ucKey == 0x7f || ucKey == 0x08) {
			if (i > 0) {
				/* end of date[], index then one more back */
				if (!date[i]) {
					--i;
				}

				printf(pEraseSeq);
				--i;

				/* delimitor '/' for date is uneditable */
				if (!is_digit(date[i]) && i > 0) {
					printf(pEraseSeq);
					--i;
				}
			}
		}

		/* end of time[], no more input except above DEL/BS or enter to end */
		if (!date[i]) {
			continue;
		}

		if (!is_digit(ucKey)) {
			continue;
		}

		console_put_char(ucKey);
		date[i++] = ucKey;

		/* ignore non digit position */
		if (!is_digit(date[i]) && i < 10) {
			console_put_char(date[i]);
			++i;
		}
	}

	if (i == 0) {
		return 0;
	}

	if (i != 0 && date[i] != '\0' && i != 6) {
		return 1;	/* failure input */
	}

	/* MM-DD-YY */
	new_date.month = to_digit(date[0]) * 10 + to_digit(date[1]);
	new_date.day = to_digit(date[3]) * 10 + to_digit(date[4]);
	/* not scenario of getting mm/dd/ only for alarm */
	if (i != 6) {
		new_date.year =
		    to_digit(date[6]) * 1000 + to_digit(date[7]) * 100 +
		    to_digit(date[8]) * 10 + to_digit(date[9]);
		new_date.week = compute_week(new_date.year, new_date.month, new_date.day);
	}

	/* success input. verification of data is left to RTC internal Error Checking */
	return 0;
}
Ejemplo n.º 14
0
/**
 * \brief Get new time, successful value is put in new_time.hour, new_time.min, new_time.sec.
 */
static int get_new_time(void)
{
	char ucKey;
	int i = 0;

	/* clear setting variable */
	new_time.hour = new_time.min = new_time.sec = 0xFF;

	/* use time[] as a format template */
	while (1) {
		ucKey = console_get_char();

		/* end input */
		if (ucKey == 0x0d || ucKey == 0x0a) {
			printf("\r\n");
			break;
		}

		/* DEL or BACKSPACE */
		if (ucKey == 0x7f || ucKey == 0x08) {
			if (i > 0) {
				/* end of time[], index then one more back */
				if (!rtc_time[i]) {
					--i;
				}

				printf(pEraseSeq);
				--i;

				/* delimitor ':' for time is uneditable */
				if (!is_digit(rtc_time[i]) && i > 0) {
					printf(pEraseSeq);
					--i;
				}
			}
		}

		/* end of time[], no more input except above DEL/BS or enter to end */
		if (!rtc_time[i]) {
			continue;
		}

		if (!is_digit(ucKey)) {
			continue;
		}

		console_put_char(ucKey);
		rtc_time[i++] = ucKey;

		/* ignore non digit position if not end */
		if (!is_digit(rtc_time[i]) && i < 8) {
			console_put_char(rtc_time[i]);
			++i;
		}
	}

	if (i == 0) {
		return 0;
	}

	if (i != 0 && rtc_time[i] != '\0') {
		return 1;	/* failure input */
	}

	new_time.hour = to_digit(rtc_time[0]) * 10 + to_digit(rtc_time[1]);
	new_time.min = to_digit(rtc_time[3]) * 10 + to_digit(rtc_time[4]);
	new_time.sec = to_digit(rtc_time[6]) * 10 + to_digit(rtc_time[7]);

	/* success input. verification of data is left to RTC internal Error Checking */
	return 0;
}