/*..........................................................................*/ QState AlarmClock_mode12hr(AlarmClock *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { printf("*** 12-hour mode\n"); return Q_HANDLED(); } case Q_TIMEOUT_SIG: { uint32_t h; /* temporary variable to hold hour */ /* timeout in one second */ QActive_arm((QActive *)me, BSP_TICKS_PER_SEC); if (++me->current_time == 12*60) { /* roll over in 12-hr mode? */ me->current_time = 0; } h = me->current_time/60; printf("%02d:%02d %s\n", (h % 12) ? (h % 12) : 12, me->current_time % 60, (h / 12) ? "PM" : "AM"); /* synchronously dispatch to the orthogonal component */ Q_SIG(&me->alarm) = TIME_SIG; Q_PAR(&me->alarm) = me->current_time; Alarm_dispatch(&me->alarm); return Q_HANDLED(); } } return Q_SUPER(&AlarmClock_timekeeping); }
/*..........................................................................*/ QState AlarmClock_mode24hr(AlarmClock *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { printf("*** 24-hour mode\n"); return Q_HANDLED(); } case Q_TIMEOUT_SIG: { /* timeout in one second */ QActive_arm((QActive *)me, BSP_TICKS_PER_SEC); if (++me->current_time == 24*60) { /* roll over in 24-hr mode? */ me->current_time = 0; } printf("%02d:%02d\n", me->current_time/60, me->current_time%60); /* synchronously dispatch to the orthogonal component */ Q_SIG(&me->alarm) = TIME_SIG; Q_PAR(&me->alarm) = me->current_time; Alarm_dispatch(&me->alarm); return Q_HANDLED(); } } return Q_SUPER(&AlarmClock_timekeeping); }
/*..........................................................................*/ QState AlarmClock_mode12hr(AlarmClock *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { printf("*** 12-hour mode\n"); return Q_HANDLED(); } case TICK_SIG: { TimeEvt pe; /* temporary synchronous event for the component */ uint32_t h; /* temporary variable to hold hour */ if (++me->current_time == 12*60) { /* roll over in 12-hr mode? */ me->current_time = 0; } h = me->current_time/60; printf("%02ld:%02ld %s\n", (h % 12) ? (h % 12) : 12, me->current_time % 60, (h / 12) ? "PM" : "AM"); ((QEvent *)&pe)->sig = TIME_SIG; pe.current_time = me->current_time; /* synchronously dispatch to the orthogonal component */ Alarm_dispatch(&me->alarm, (QEvent *)&pe); return Q_HANDLED(); } } return Q_SUPER(&AlarmClock_timekeeping); }
/* @(/2/0/9/1/2/8) .........................................................*/ QState CoffeeAO_set_clock_m2(CoffeeAO * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* @(/2/0/9/1/2/8) */ case Q_ENTRY_SIG: { lcd_clear(); status_ = Q_HANDLED(); break; } /* @(/2/0/9/1/2/8/0) */ case ADWHEEL_SIG: { char clock_message[20]; int value = ((AdEvt*)e)->val * 10 / 1024; HourAndMinute* ham = &l_CoffeeAO.alarm.current_time; ham->minutes = (ham->minutes / 10) * 10 + value; sprintf(clock_message, "%02u:%02u", ham->hours, ham->minutes); set_cursor(0, 0); lcd_print(clock_message); set_cursor(4, 1); lcd_print("^"); status_ = Q_HANDLED(); break; } /* @(/2/0/9/1/2/8/1) */ case INT_SIG: { RtcEvt* rtc_evt = Q_NEW(RtcEvt, TIME_SET_SIG); rtc_evt->rtc.hours = l_CoffeeAO.alarm.current_time.hours; rtc_evt->rtc.minutes = l_CoffeeAO.alarm.current_time.minutes; Alarm_dispatch((QFsm *)&l_CoffeeAO.alarm, (QEvt *) rtc_evt); QF_INT_ENABLE(); QActive_postFIFO((QActive *)&l_CoffeeAO, Q_NEW(QEvent, GO_BACK_SIG)); QF_INT_DISABLE(); status_ = Q_HANDLED(); break; } default: { status_ = Q_SUPER(&CoffeeAO_submenu); break; } } return status_; }
/*..........................................................................*/ QState AlarmClock_timekeeping(AlarmClock *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { /* timeout in one second */ QActive_arm((QActive *)me, BSP_TICKS_PER_SEC); return Q_HANDLED(); } case Q_EXIT_SIG: { QActive_disarm((QActive *)me); return Q_HANDLED(); } case Q_INIT_SIG: { return Q_TRAN(&AlarmClock_mode24hr); } case CLOCK_12H_SIG: { return Q_TRAN(&AlarmClock_mode12hr); } case CLOCK_24H_SIG: { return Q_TRAN(&AlarmClock_mode24hr); } case ALARM_SIG: { printf("Wake up!!!\n"); return Q_HANDLED(); } 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); Alarm_dispatch(&me->alarm); return Q_HANDLED(); } case TERMINATE_SIG: { return Q_TRAN(&AlarmClock_final); } } return Q_SUPER(&QHsm_top); }
/*..........................................................................*/ QState AlarmClock_timekeeping(AlarmClock *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { /* periodic timeout every second */ QTimeEvt_postEvery(&me->timeEvt, (QActive *)me, BSP_TICKS_PER_SEC); return Q_HANDLED(); } case Q_EXIT_SIG: { QTimeEvt_disarm(&me->timeEvt); return Q_HANDLED(); } case Q_INIT_SIG: { return Q_TRAN(&AlarmClock_mode24hr); } case CLOCK_12H_SIG: { return Q_TRAN(&AlarmClock_mode12hr); } case CLOCK_24H_SIG: { return Q_TRAN(&AlarmClock_mode24hr); } case ALARM_SIG: { printf("Wake up!!!\n"); return Q_HANDLED(); } case ALARM_SET_SIG: case ALARM_ON_SIG: case ALARM_OFF_SIG: { /* synchronously dispatch to the orthogonal component */ Alarm_dispatch(&me->alarm, e); return Q_HANDLED(); } case TERMINATE_SIG: { return Q_TRAN(&AlarmClock_final); } } return Q_SUPER(&QHsm_top); }
/*..........................................................................*/ QState AlarmClock_mode24hr(AlarmClock *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { printf("*** 24-hour mode\n"); return Q_HANDLED(); } case TICK_SIG: { TimeEvt pe; /* temporary synchronous event for the component */ if (++me->current_time == 24*60) { /* roll over in 24-hr mode? */ me->current_time = 0; } printf("%02ld:%02ld\n", me->current_time/60, me->current_time%60); ((QEvent *)&pe)->sig = TIME_SIG; pe.current_time = me->current_time; /* synchronously dispatch to the orthogonal component */ Alarm_dispatch(&me->alarm, (QEvent *)&pe); return Q_HANDLED(); } } return Q_SUPER(&AlarmClock_timekeeping); }
/* @(/2/0/9/1/2/3) .........................................................*/ QState CoffeeAO_timeBrewActivatedToggle(CoffeeAO * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* @(/2/0/9/1/2/3) */ case Q_ENTRY_SIG: { l_CoffeeAO.is_automatic_brew_active = l_CoffeeAO.is_automatic_brew_active == 0 ? 1 : 0; Alarm_dispatch((QFsm *)&l_CoffeeAO.alarm, Q_NEW(QEvent, ALARM_TOGGLE_SIG)); QActive_postFIFO((QActive *)&l_CoffeeAO, Q_NEW(QEvent, GO_BACK_SIG)); status_ = Q_HANDLED(); break; } /* @(/2/0/9/1/2/3) */ case Q_EXIT_SIG: { printf("toggled automatic brew to: %u\n", l_CoffeeAO.is_automatic_brew_active); status_ = Q_HANDLED(); break; } default: { status_ = Q_SUPER(&CoffeeAO_submenu); break; } } return status_; }