/** * Idle state handler */ static QState CoffeeMachineAO_Idle(CoffeeMachineAO *me, QEvent const *e) { switch ( e->sig ) { case Q_INIT_SIG: { DBG("CoffeeMachine Idle: INIT"); return Q_HANDLED(); } case Q_ENTRY_SIG: { DBG("CoffeeMachine Idle: ENTRY"); LED_Out(ALL_LEDS_OFF); return Q_HANDLED(); } case ALARM_SIG: { DBG("CoffeeMachine Idle: ALARM"); return Q_TRAN(&CoffeeMachineAO_Brewing); } case BREWSTRENGTH_SET_SIG: { int brewStrength; int LEDsToFlash; int i; DBG("CoffeeMachine Idle: BREW STRENGH SET"); brewStrength = ((BrewStrengthSetEvt const *)e)->brewStrength; // exptected value: 0, 1 or 2 (weak, medium or strong) brewStrength++; // make sure that value is between 1 and 3 LEDsToFlash = brewStrength * LEDS_PER_BREW_STRENGH; LED_Out(ALL_LEDS_OFF); for(i = 0; i < LEDsToFlash; i++) LED_On(i); return Q_HANDLED(); } case Q_EXIT_SIG: { DBG("CoffeeMachine Idle: EXIT"); return Q_HANDLED(); } } return Q_SUPER(&QHsm_top); }
/*---------------------------------------------------------------------------- MAIN function *----------------------------------------------------------------------------*/ int main (void) { int32_t num = -1; int32_t dir = 1; uint32_t btns = 0; SystemCoreClockUpdate(); /* Get Core Clock Frequency */ if (SysTick_Config(SystemCoreClock / 1000)) { /* SysTick 1 msec interrupts */ while (1); /* Capture error */ } LED_Init(); BTN_Init(); while(1) { /* Loop forever */ btns = BTN_Get(); /* Read button states */ if (btns != (1UL << 0)) { /* Calculate 'num': 0,1,...,LED_NUM-1,LED_NUM-1,...,1,0,0,... */ num += dir; if (num == LED_NUM) { dir = -1; num = LED_NUM-1; } else if (num < 0) { dir = 1; num = 0; } LED_On (num); Delay( 50); /* Delay 50ms */ LED_Off(num); Delay(200); /* Delay 200ms */ } else { LED_Out (0x0F); Delay(10); /* Delay 10ms */ } } }
// Process data received by POST request. // Type code: - 0 = www-url-encoded form data. // - 1 = filename for file upload (null-terminated string). // - 2 = file upload raw data. // - 3 = end of file upload (file close requested). // - 4 = any XML encoded POST data (single or last stream). // - 5 = the same as 4, but with more XML data to follow. void cgi_process_data (uint8_t code, const char *data, uint32_t len) { char var[40],passw[12]; if (code != 0) { // Ignore all other codes return; } P2 = 0; LEDrun = true; if (len == 0) { // No data or all items (radio, checkbox) are off LED_Out (P2); return; } passw[0] = 1; do { // Parse all parameters data = http_get_env_var (data, var, sizeof (var)); if (var[0] != 0) { // First character is non-null, string exists if (strcmp (var, "led0=on") == 0) { P2 |= 0x01; } else if (strcmp (var, "led1=on") == 0) { P2 |= 0x02; } else if (strcmp (var, "led2=on") == 0) { P2 |= 0x04; } else if (strcmp (var, "led3=on") == 0) { P2 |= 0x08; } else if (strcmp (var, "led4=on") == 0) { P2 |= 0x10; } else if (strcmp (var, "led5=on") == 0) { P2 |= 0x20; } else if (strcmp (var, "led6=on") == 0) { P2 |= 0x40; } else if (strcmp (var, "led7=on") == 0) { P2 |= 0x80; } else if (strcmp (var, "ctrl=Browser") == 0) { LEDrun = false; } else if ((strncmp (var, "pw0=", 4) == 0) || (strncmp (var, "pw2=", 4) == 0)) { // Change password, retyped password if (http_EnAuth) { if (passw[0] == 1) { strcpy (passw, var+4); } else if (strcmp (passw, var+4) == 0) { // Both strings are equal, change the password strcpy (http_auth_passw, passw); } } } else if (strncmp (var, "lcd1=", 5) == 0) { // LCD Module line 1 text strcpy (lcd_text[0], var+5); LCDupdate = true; } else if (strncmp (var, "lcd2=", 5) == 0) { // LCD Module line 2 text strcpy (lcd_text[1], var+5); LCDupdate = true; } } } while (data); LED_Out (P2); }
int32_t LED_SetOut (uint32_t val) { LED_Out(val); return 0; }