static QState uiMenuSettimeHoursFlash(struct UI *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: display_set_time(me, FALSE, TRUE); QActive_armX((QActive*)me, 1, 8); return Q_HANDLED(); case Q_TIMEOUT1_SIG: display_set_time(me, TRUE, TRUE); return Q_TRAN(uiMenuSettimeHours); case BUTTON_UP_PRESS_SIGNAL: case BUTTON_UP_LONG_PRESS_SIGNAL: case BUTTON_UP_REPEAT_SIGNAL: case BUTTON_DOWN_PRESS_SIGNAL: case BUTTON_DOWN_LONG_PRESS_SIGNAL: case BUTTON_DOWN_REPEAT_SIGNAL: /** @see the comment in uiMenuSettimeMinutesFlash() */ display_set_time(me, TRUE, TRUE); break; case Q_EXIT_SIG: QActive_armX((QActive*)me, 1, 17); return Q_HANDLED(); } return Q_SUPER(uiMenuSettimeHours); }
static QState uiMenu(struct UI *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: ACTION(); BSP_fast_timer_1(TRUE); BSP_fast_timer_2(TRUE); return Q_HANDLED(); case UI_ACTION_SIGNAL: SERIALSTR("U"); me->timeoutcounter = 4; lcd_timeouts(me->timeoutcounter); QActive_armX((QActive*)(me), 2, 3 * BSP_TICKS_PER_SECOND_TIMER2); return Q_HANDLED(); case Q_TIMEOUT2_SIG: me->timeoutcounter --; lcd_timeouts(me->timeoutcounter); if (me->timeoutcounter) { QActive_armX((QActive*)(me), 2, 3 * BSP_TICKS_PER_SECOND_TIMER2); return Q_HANDLED(); } else { return Q_TRAN(uiRun); } case BUTTON_CANCEL_PRESS_SIGNAL: return Q_TRAN(uiRun); case Q_EXIT_SIG: BSP_fast_timer_1(FALSE); BSP_fast_timer_2(FALSE); lcd_timeouts(0); return Q_HANDLED(); } return Q_SUPER(uiTop); }
static QState uiMenuSettimeMinutesFlash(struct UI *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: display_set_time(me, TRUE, FALSE); QActive_armX((QActive*)me, 1, 8); return Q_HANDLED(); case Q_TIMEOUT1_SIG: display_set_time(me, TRUE, TRUE); return Q_TRAN(uiMenuSettimeMinutes); case BUTTON_UP_PRESS_SIGNAL: case BUTTON_UP_LONG_PRESS_SIGNAL: case BUTTON_UP_REPEAT_SIGNAL: case BUTTON_DOWN_PRESS_SIGNAL: case BUTTON_DOWN_LONG_PRESS_SIGNAL: case BUTTON_DOWN_REPEAT_SIGNAL: /** * React to the event by re-displaying the time (without the * minutes hidden), but don't handle it. This makes the time * appear on the display as the button is pressed, which is * move obvious to the user. */ display_set_time(me, TRUE, TRUE); break; case Q_EXIT_SIG: QActive_armX((QActive*)me, 1, 17); return Q_HANDLED(); } return Q_SUPER(uiMenuSettimeMinutes); }
static QState uiMenuSettimeHours(struct UI *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: lcd_buttons(LCD_BUTTONS_ALL); me->settime_YmdHM = 'H'; display_set_time(me, TRUE, TRUE); QActive_armX((QActive*)me, 1, 17); return Q_HANDLED(); case Q_TIMEOUT1_SIG: return Q_TRAN(uiMenuSettimeHoursFlash); case BUTTON_ENTER_PRESS_SIGNAL: ACTION(); return Q_TRAN(uiMenuSettimeMinutes); case BUTTON_UP_PRESS_SIGNAL: case BUTTON_UP_LONG_PRESS_SIGNAL: case BUTTON_UP_REPEAT_SIGNAL: ACTION(); inc_hour(&me->settime); display_set_time(me, TRUE, TRUE); QActive_armX((QActive*)me, 1, 17); return Q_HANDLED(); case BUTTON_DOWN_PRESS_SIGNAL: case BUTTON_DOWN_LONG_PRESS_SIGNAL: case BUTTON_DOWN_REPEAT_SIGNAL: ACTION(); dec_hour(&me->settime); display_set_time(me, TRUE, TRUE); QActive_armX((QActive*)me, 1, 17); return Q_HANDLED(); } return Q_SUPER(uiMenu); }
static QState Ped_wait(Ped * const me) { QState status_; switch (Q_SIG(me)) { /* @(/1/1/1/1/0) */ case Q_TIMEOUT_SIG: { --me->retryCtr; /* @(/1/1/1/1/0/0) */ if (me->retryCtr != 0U) { QActive_armX((QActive *)me, 0U, WAIT_TOUT); QACTIVE_POST((QActive *)&AO_Pelican, PEDS_WAITING_SIG); status_ = QM_HANDLED(); } /* @(/1/1/1/1/0/1) */ else { static QActionHandler const act_[] = { Q_ACTION_CAST(&Ped_off_e), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&Ped_off_s, &act_[0]); } break; } default: { status_ = QM_SUPER(); break; } } return status_; }
static QState uiMenuCalibrateTemperatureStarted(struct UI *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: QActive_armX(&me->super, 1, 1); return Q_HANDLED(); case Q_TIMEOUT1_SIG: return Q_TRAN(uiMenuCalibrateGetTemperature); } return Q_SUPER(uiMenuCalibrateDeferExit); }
/*${AOs::Blinky::SM} .......................................................*/ static QState Blinky_initial(Blinky * const me) { /*${AOs::Blinky::SM::initial} */ /* arm the private time event for tick rate 0 * to expire in 1/2s and periodically every 1/2 second */ QActive_armX(&me->super, 0U, BSP_TICKS_PER_SEC/2U, BSP_TICKS_PER_SEC/2U); return Q_TRAN(&Blinky_off); }
/*..........................................................................*/ QState AlarmClock_timekeeping(AlarmClock * const me) { QState status; switch (Q_SIG(me)) { case Q_ENTRY_SIG: { /* timeout in one second and every second */ QActive_armX(&me->super, 0U, BSP_TICKS_PER_SEC, BSP_TICKS_PER_SEC); status = Q_HANDLED(); break; } case Q_EXIT_SIG: { QActive_disarmX(&me->super, 0U); status = Q_HANDLED(); break; } case Q_INIT_SIG: { status = Q_TRAN(&AlarmClock_mode24hr); break; } case CLOCK_12H_SIG: { status = Q_TRAN(&AlarmClock_mode12hr); break; } case CLOCK_24H_SIG: { status = Q_TRAN(&AlarmClock_mode24hr); break; } case ALARM_SIG: { printf("Wake up!!!\n"); status = Q_HANDLED(); break; } case ALARM_SET_SIG: case ALARM_ON_SIG: case ALARM_OFF_SIG: { /* synchronously dispatch to the orthogonal component */ Q_SIG(&me->alarm) = Q_SIG(me); Q_PAR(&me->alarm) = Q_PAR(me); QHSM_DISPATCH(&me->alarm.super); status = Q_HANDLED(); break; } case TERMINATE_SIG: { status = Q_TRAN(&AlarmClock_final); break; } default: { status = Q_SUPER(&QHsm_top); break; } } return status; }
static QState Ble_ancs_setup_wait(Ble* const me) { uint32_t err_code; switch(Q_SIG(me)) { case Q_ENTRY_SIG: QActive_armX(&me->super, 0U, /* 10 ms delay */1, /* periodic = */0); return Q_HANDLED(); case Q_TIMEOUT_SIG: return Q_TRAN(&Ble_ancs_enabled); default: return Q_SUPER(&QHsm_top); } }
static QState uiMenuCalibrateTemperatureStart(struct UI *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: QActive_armX(&me->super, 1, 1); return Q_HANDLED(); case Q_TIMEOUT1_SIG: if (start_cal(me)) { return Q_TRAN(uiMenuCalibrateTemperatureStarted); } else { me->temperatureWaits ++; Q_ASSERT( me->temperatureWaits < 10 ); return Q_TRAN(uiMenuCalibrateTemperatureStart); } } return Q_SUPER(uiMenuCalibrateDeferExit); }
static void LEDSEQ_Run(LedSeq * const me) { ledAction *step; bool leave = false; if (-1 != me->activeSeq) { while(false == leave) { step = &sequences[me->activeSeq][me->state[me->activeSeq]]; me->state[me->activeSeq]++; switch(step->action) { case LEDSEQ_LOOP: me->state[me->activeSeq] = 0; break; case LEDSEQ_STOP: me->state[me->activeSeq] = LEDSEQ_STOP; LEDSEQ_UpdateActive(me); break; default: //The step is a LED action and a time if (step->value) { BSP_IO_On(me->led); } else { BSP_IO_Off(me->led); } if (step->action == 0) break; QActive_armX((QActive *)me, 0U, step->action, 0); leave = true; break; } } } }
static QState scrollText(struct UI *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: strncpy(me->scrolltext, me->scrollstring+me->scrollindex, 7); me->scrolltext[7] = '\0'; lcd_showstring(me->scrolltext); QActive_armX((QActive*)me, 1, 15); return Q_HANDLED(); case Q_TIMEOUT1_SIG: me->scrollindex ++; if (me->scrollstring[me->scrollindex]) { return Q_TRAN(scrollText); } else { return Q_TRAN(uiRun); } } return Q_SUPER(scroll); }
static QState uiMenuCalibratePause(struct UI *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: /* Process any event that will cause an exit out of calibration mode that we got while we were away doing the ADC processing. */ recall(me); /* Read the temperature fairly often. We only wait for 5/32 seconds here. We must wait for more than one tick so that the recorder, which has a lower priority, gets a chance to process its own ticks before ours and hence get the ADC when required. */ QActive_armX((QActive*)me, 1, 5); return Q_HANDLED(); case Q_TIMEOUT1_SIG: me->temperatureWaits = 0; return Q_TRAN(uiMenuCalibrateTemperatureStart); } return Q_SUPER(uiMenuCalibrate); }
static QState uiMenuCalibrateGetTemperature(struct UI *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: BSP_get_temperature(); /* Only need one tick to get the temperature, since we're guaranteed to be arriving here very near the start of a tick period. But take two anyway, to be sure. */ QActive_armX((QActive*)me, 1, 2); return Q_HANDLED(); case TEMPERATURE_SIGNAL: SERIALSTR("<okok>"); me->ti = Q_PAR(me); show_temperature_cal(me); return Q_TRAN(uiMenuCalibratePause); case Q_TIMEOUT1_SIG: /* Nothing has happened - give up. */ SERIALSTR("<BLAH>"); return Q_TRAN(uiMenuCalibratePause); } return Q_SUPER(uiMenuCalibrateDeferExit); }
static QState Pelican_offline(Pelican * const me) { QState status_; switch (Q_SIG(me)) { /* @(/1/0/1/2/0) */ case Q_TIMEOUT_SIG: { QActive_armX(&me->super, 0U, OFF_FLASH_TOUT); me->flashCtr ^= 1U; /* @(/1/0/1/2/0/0) */ if ((me->flashCtr & 1U) == 0U) { BSP_signalCars(CARS_RED); BSP_signalPeds(PEDS_DONT_WALK); status_ = QM_HANDLED(); } /* @(/1/0/1/2/0/1) */ else { BSP_signalCars(CARS_BLANK); BSP_signalPeds(PEDS_BLANK); status_ = QM_HANDLED(); } break; } /* @(/1/0/1/2/1) */ case ON_SIG: { static QActionHandler const act_[] = { Q_ACTION_CAST(&Pelican_operational_e), Q_ACTION_CAST(&Pelican_operational_i), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&Pelican_operational_s, &act_[0]); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
static QState Pelican_pedsFlash(Pelican * const me) { QState status_; switch (Q_SIG(me)) { /* @(/1/0/1/1/3/2/0) */ case Q_TIMEOUT_SIG: { /* @(/1/0/1/1/3/2/0/0) */ if (me->flashCtr != 0U) { --me->flashCtr; QActive_armX(&me->super, 0U, PEDS_FLASH_TOUT); /* @(/1/0/1/1/3/2/0/0/0) */ if ((me->flashCtr & 1U) == 0U) { BSP_signalPeds(PEDS_DONT_WALK); status_ = QM_HANDLED(); } /* @(/1/0/1/1/3/2/0/0/1) */ else { BSP_signalPeds(PEDS_BLANK); status_ = QM_HANDLED(); } } /* @(/1/0/1/1/3/2/0/1) */ else { static QActionHandler const act_[] = { Q_ACTION_CAST(&Pelican_pedsEnabled_x), Q_ACTION_CAST(&Pelican_carsEnabled_i), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&Pelican_carsEnabled_s, &act_[0]); } break; } default: { status_ = QM_SUPER(); break; } } return status_; }
/* @(/1/1/1/2) .............................................................*/ static QState Ped_off_e(Ped * const me) { QActive_armX(&me->super, 0U, OFF_TOUT); QACTIVE_POST((QActive *)&AO_Pelican, OFF_SIG); return QM_ENTRY(&Ped_off_s); }
/* @(/1/1/1/1) .............................................................*/ static QState Ped_wait_e(Ped * const me) { me->retryCtr = N_ATTEMPTS; QActive_armX(&me->super, 0U, WAIT_TOUT); return QM_ENTRY(&Ped_wait_s); }
static QState uiShowMin(struct UI *me) { QTimeEvtCtr timeout = showmaxmintimeout; int16_t ti; switch (Q_SIG(me)) { case Q_ENTRY_SIG: me->showmaxmincounter ++; switch (me->showmaxmincounter) { case 1: lcd_showstring("MIN T "); timeout = showmaxmintimeout; break; case 2: lcd_showstring("SINCE "); timeout = showmaxmintimeout; break; case 3: lcd_showstring("9 AM "); timeout = showmaxmintimeout; break; case 4: ti = get_min_today()->ti; if (INVALIDTI == ti) me->showmaxmincounter ++; show_temperature(ti); timeout = 3 * showmaxmintimeout; break; case 5: show_at(&(get_min_today()->time)); timeout = 3 * showmaxmintimeout; break; case 6: lcd_showstring("MIN T "); timeout = showmaxmintimeout; break; case 7: lcd_showstring("TO LAST"); timeout = showmaxmintimeout; break; case 8: lcd_showstring("9 AM "); timeout = showmaxmintimeout; break; case 9: ti = get_min_yesterday()->ti; if (INVALIDTI == ti) me->showmaxmincounter ++; show_temperature(ti); timeout = 3 * showmaxmintimeout; break; case 10: show_at(&(get_min_yesterday()->time)); timeout = 3 * showmaxmintimeout; break; default: Q_ASSERT( 0 ); break; } QActive_armX(&me->super, 1, timeout); return Q_HANDLED(); case Q_TIMEOUT1_SIG: case BUTTON_DOWN_PRESS_SIGNAL: if (10 == me->showmaxmincounter) return Q_TRAN(uiRun); else return Q_TRAN(uiShowMin); } return Q_SUPER(uiShowMinTop); }
QState s_light_initial(ao_light_t * const me) { QActive_armX((QActive *)me, 0U, BSP_TICKS_PER_SEC, BSP_TICKS_PER_SEC); return Q_TRAN(&s_light_off); }
/* @(/1/0/1/1/2/1) .........................................................*/ static QState Pelican_carsGreen_e(Pelican * const me) { BSP_signalCars(CARS_GREEN); QActive_armX(&me->super, 0U, CARS_GREEN_MIN_TOUT); return QM_ENTRY(&Pelican_carsGreen_s); }
/* @(/1/0/1/1/2/2) .........................................................*/ static QState Pelican_carsYellow_e(Pelican * const me) { BSP_showState(me->super.prio, "carsYellow"); BSP_signalCars(CARS_YELLOW); QActive_armX(&me->super, 0U, CARS_YELLOW_TOUT); return QM_ENTRY(&Pelican_carsYellow_s); }
/* @(/1/0/1/1/3/1) .........................................................*/ static QState Pelican_pedsWalk_e(Pelican * const me) { BSP_showState(me->super.prio, "pedsWalk"); BSP_signalPeds(PEDS_WALK); QActive_armX(&me->super, 0U, PEDS_WALK_TOUT); return QM_ENTRY(&Pelican_pedsWalk_s); }
/* @(/1/0/0/3) .............................................................*/ static QState Philo_eating_e(Philo * const me) { QActive_armX(&me->super, 0U, EAT_TIME); return QM_ENTRY(&Philo_eating_s); }
/* @(/1/0/0/1) .............................................................*/ static QState Philo_thinking_e(Philo * const me) { QActive_armX(&me->super, 0U, THINK_TIME); return QM_ENTRY(&Philo_thinking_s); }
/* @(/1/0/1/1/3/2) .........................................................*/ static QState Pelican_pedsFlash_e(Pelican * const me) { BSP_showState(me->super.prio, "pedsFlash"); QActive_armX(&me->super, 0U, PEDS_FLASH_TOUT); me->flashCtr = (PEDS_FLASH_NUM * 2U) + 1U; return QM_ENTRY(&Pelican_pedsFlash_s); }
/* @(/1/0/1/2) .............................................................*/ static QState Pelican_offline_e(Pelican * const me) { BSP_showState(me->super.prio, "offline"); QActive_armX(&me->super, 0U, OFF_FLASH_TOUT); me->flashCtr = 0U; return QM_ENTRY(&Pelican_offline_s); }