예제 #1
0
void shellProcess()
{
	if(console_process(CONSOLE_NON_BLOCKING,input_str, CONSOLE_MAXLEN)) {
		USART_printf("\r\n");
		shell_process(input_str);
		USART_printf("->");
	}
}
예제 #2
0
/*******************************************
      INITIALIZE
*******************************************/
int main(void)
{
  WDTCTL  = WDTPW + WDTHOLD;                // Stop watchdog timer
  BCSCTL1 = CALBC1_1MHZ;
  DCOCTL  = CALDCO_1MHZ;

  serial_init(9600);

  __dint();                                 // Enable global interrupts

/*******************************************
      MAIN LOOP
*******************************************/
  for(;;)
  {
    int j = 0;                              // Char array counter
    char cmd_line[90] = { 0 };              // Init empty array

    cio_print((char *) "$ ");               // Display prompt
    char c = cio_getc();                    // Wait for a character
    while(c != '\r') {                      // until return sent then ...
      if(c == 0x08) {                       //  was it the delete key?
        if(j != 0) {                        //  cursor NOT at start?
          cmd_line[--j] = 0;                //  delete key logic
          cio_printc(0x08); cio_printc(' '); cio_printc(0x08);
        }
      } else {                              // otherwise ...
        cmd_line[j++] = c; cio_printc(c);   //  echo received char
      }
      c = cio_getc();                       // Wait for another
    }

    cio_print((char *) "\n\n\r");           // Delimit command result

    switch(shell_process(cmd_line))         // Execute specified shell command
    {                                       // and handle any errors
      case SHELL_PROCESS_ERR_CMD_UNKN:
        cio_print((char *) "ERROR, unknown command given\n\r");
        break;
      case SHELL_PROCESS_ERR_ARGS_LEN:
        cio_print((char *) "ERROR, an arguement is too lengthy\n\r");
        break;
      case SHELL_PROCESS_ERR_ARGS_MAX:
        cio_print((char *) "ERROR, too many arguements given\n\r");
        break;
      default:
        break;
    }

    cio_print((char *) "\n");               // Delimit before prompt
  }

  return 0;
}
예제 #3
0
/*******************************************
			INITIALIZE
*******************************************/
void main(void) {


   	 //Basic prep
    WDTCTL  = WDTPW + WDTHOLD;     //Stop Watchdog TImer
    BCSCTL1 = CALBC1_1MHZ;         //Clocks
    DCOCTL  = CALDCO_1MHZ;
    P1REN = BIT3; //turn on pull-resistor on 0b0001000
	P1OUT |= BIT3; //powers pin3 (button)
	P1IE = BIT3;	//enables p1 interrupt on pin 1.3
	P1IES |= BIT3;	//sets interrupt on high to low
	P1IFG &= ~BIT3;	//clears interrupt flag

		//Prep 1st PWM channel  (X AXIS)
    TA0CCTL1 = OUTMOD_7;            // TA0CCR1 reset/set
    TA0CTL  = TASSEL_2 + MC_1;     // SMCLK + upmode
    //upmode(MC_1): the Timer repeatedly counts from 0 to the value set in register TACCR0)
    TACCR0  = PWM_PRD-1;        //set pwm period
    TACCR1  = 0;                   //set TA0CCR1 PWM Duty Cycle
    P1DIR |= BIT6; //Pin 1.6 set as output
    P1SEL |= BIT6; //Set Pin 1.6 for pwm use

  	  //Prep 2nd PWM channel (Y AXIS)
    TA1CCTL1    = OUTMOD_7; //set/reset mode
    TA1CTL     = TASSEL_2 + MC_1; //SMCLK + upmode
    TA1CCR0     = PWM_PRD-1; //set pwm period
    TA1CCR1     = 0;   //set TA0CCR1_ pwm duty cycle
    P2DIR       |= BIT2 | BIT3;  //set as output
    P2OUT		|= BIT2;
    P2SEL       |= BIT2;  //Set pin 2.2 for pwm use

	serial_init(9600); // set serial clockrate

	__enable_interrupt();									// Enable global interrupts

/*******************************************
			MAIN LOOP
*******************************************/
	for(;;) {
		int j = 0;											// Char array counter
		char cmd_line[255] = {0};							// Init empty array

		cio_print((char *) "$ ");							// Display prompt
		char c = cio_getc();								// Wait for a character
		while(c != '\r') {									// until return sent then ...
			if(c == 0x08) {									//   was it the delete key?
				if(j != 0) {								//   cursor NOT at start?
					cmd_line[--j] = 0; cio_printc(0x08); cio_printc(' '); cio_printc(0x08);
				}											//   delete key logic
			} else {										// otherwise ...
				cmd_line[j++] = c; cio_printc(c);			//   echo received char
			}
			c = cio_getc();									// Wait for another
		}

		cio_print((char *) "\n\n\r");						// Delimit command result

		switch(shell_process(cmd_line))						// Execute specified shell command
		{													// and handle any errors
			case SHELL_PROCESS_ERR_CMD_UNKN:
				cio_print((char *) "ERROR, unknown command given\n\r");
				break;
			case SHELL_PROCESS_ERR_ARGS_LEN:
				cio_print((char *) "ERROR, an arguement is too lengthy\n\r");
				break;
			case SHELL_PROCESS_ERR_ARGS_MAX:
				cio_print((char *) "ERROR, too many arguements given\n\r");
				break;
			default:
				break;
		}

		cio_print((char *) "\n");							// Delimit before prompt
	}
}
int main(void)
{

    /* Initialize Leds mounted on STM32F0-discovery */
    STM_EVAL_LEDInit(LED3);
    STM_EVAL_LEDInit(LED4);

    /* Turn on LED3 and LED4 */
    STM_EVAL_LEDOn(LED3);
    STM_EVAL_LEDOn(LED4);
    
    /* Initialize other outputs and inputs */
    STM_EVAL_LEDInit(RELAIS1);
    STM_EVAL_LEDInit(RELAIS2);
    STM_EVAL_LEDInit(OUT_12V_1);
    STM_EVAL_LEDInit(OUT_12V_2);
    STM_EVAL_PBInit(IN_12V_1, BUTTON_MODE_PDOWN);
    STM_EVAL_PBInit(IN_12V_2, BUTTON_MODE_PDOWN);
    
    /* Initialize the User_Button */
    STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);

    /* Setup SysTick Timer for 1 msec interrupts. */
    if (SysTick_Config(SystemCoreClock / 1000))
    {
        /* Capture error */
        while (1);
    }

    usart_1_init();

#ifndef WIFI_CONNECTED
    /* Output a message on Hyperterminal using printf function */
    cio_printf("%s", welcome_msg);
#else
    wifi_intit_pins();
    wifi_init_connections();
    
    // If the button is pressed on power on,
    // do not init the WiFi module to keep current WiFi connections
    // and save development time
    if (!STM_EVAL_PBGetState(BUTTON_USER))
        wifi_init_ap_mode();
#endif

    while (1)
    {
        // Everything should be non-blocking

#ifndef WIFI_CONNECTED
        if (serve_command_promt(line_buffer, LINEBUFFERSIZE, "microcli> ") > 0)
        {
            shell_process(line_buffer);
        }
#else
        if (wifi_get_msg(line_buffer, LINEBUFFERSIZE, &cid) > 0)
        {
            bool add_header = (cid != -1); // send back to the current connection
            if (add_header)
            {
                cio_printf("\x1bS%c", cid);
                cio_printf("microcli> %s\r\n", line_buffer);
            }
            shell_process(line_buffer);

            if (add_header)
            {
                cio_print("[end]\r\n");
                cio_print("\x1b" "E");
            }
        }
#endif

        if (timeout_0 == 0)
        {
            static uint8_t counter = 0;
            switch (counter++)
            {
            case 0:
                /* Toggle LED4 */
                if (options.elements[TOGGLE_LEDS_IDX].value == 1)
                    STM_EVAL_LEDToggle(LED4);
                break;
            case 1:
                /* Toggle LED3 */
                if (options.elements[TOGGLE_LEDS_IDX].value == 1)
                    STM_EVAL_LEDToggle(LED3);
                break;
            case 2:
                break;
            default:
                counter = 0;
            }
            timeout_0 = TIMEOUT_0_DEFAULT;
        }
        
        if (options.elements[REALTIME_MSG_IDX].value == 1)
        {
            enum {WAITFOR_PRESSED, WAITFOR_RELEASED};
            static uint8_t what = WAITFOR_PRESSED;
            char msg[30];
            msg[0] = '\0';
            if (what == WAITFOR_PRESSED)
            {
                if (UserButtonPressed != 0x00) // Interrupt based, don't miss an event
                //if (STM_EVAL_PBGetState(BUTTON_USER) == 1)
                {
                    strcpy(msg, "User button pressed");
                    what = WAITFOR_RELEASED;
                }
            }
            else if (what == WAITFOR_RELEASED)
            {
                if (STM_EVAL_PBGetState(BUTTON_USER) == 0)
                {
                    UserButtonPressed = 0x00;
                    strcpy(msg, "User button released");
                    what = WAITFOR_PRESSED;
                }
            }
            if (msg[0] != '\0')
            {
#ifndef WIFI_CONNECTED
                cio_printf("\r\n[info] %s %i\r\n", msg, uptime);
#else
                // send message to each client
                for(int i=0; i<16; i++)
                {
                    if(wifi_connections[i].state == CONNECTED)
                    {
                        cio_printf("\x1bS%c[info] %s %i\r\n\x1b""E", wifi_connections[i].cid, msg, uptime);
                    }
                }
#endif
            }
        }
    }
}