2015-05-14 16:05:04 -04:00
|
|
|
//****************************************************************************
|
|
|
|
// Model: comp.qm
|
|
|
|
// File: ./clock.cpp
|
|
|
|
//
|
|
|
|
// This code has been generated by QM tool (see state-machine.com/qm).
|
|
|
|
// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
|
|
|
|
//
|
|
|
|
// This program is open source software: you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as published
|
|
|
|
// by the Free Software Foundation.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
// for more details.
|
|
|
|
//****************************************************************************
|
|
|
|
//${.::clock.cpp} ............................................................
|
|
|
|
#include "qpcpp.h"
|
|
|
|
#include "bsp.h"
|
|
|
|
#include "alarm.h"
|
|
|
|
#include "clock.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
Q_DEFINE_THIS_FILE
|
|
|
|
|
|
|
|
// Active object class -------------------------------------------------------
|
|
|
|
//${Components::AlarmClock} ..................................................
|
|
|
|
class AlarmClock : public QP::QMActive {
|
|
|
|
private:
|
|
|
|
uint32_t m_current_time;
|
|
|
|
Alarm m_alarm;
|
|
|
|
|
|
|
|
public:
|
|
|
|
QTimeEvt m_timeEvt;
|
|
|
|
|
|
|
|
public:
|
|
|
|
AlarmClock();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static QP::QState initial(AlarmClock * const me, QP::QEvt const * const e);
|
|
|
|
static QP::QState timekeeping (AlarmClock * const me, QP::QEvt const * const e);
|
|
|
|
static QP::QState timekeeping_e(AlarmClock * const me);
|
|
|
|
static QP::QState timekeeping_x(AlarmClock * const me);
|
|
|
|
static QP::QState timekeeping_i(AlarmClock * const me);
|
|
|
|
static QP::QMState const timekeeping_s;
|
|
|
|
static QP::QState mode24h (AlarmClock * const me, QP::QEvt const * const e);
|
|
|
|
static QP::QState mode24h_e(AlarmClock * const me);
|
|
|
|
static QP::QMState const mode24h_s;
|
|
|
|
static QP::QState mode12h (AlarmClock * const me, QP::QEvt const * const e);
|
|
|
|
static QP::QState mode12h_e(AlarmClock * const me);
|
|
|
|
static QP::QMState const mode12h_s;
|
|
|
|
static QP::QState final (AlarmClock * const me, QP::QEvt const * const e);
|
|
|
|
static QP::QState final_e(AlarmClock * const me);
|
|
|
|
static QP::QMState const final_s;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Local objects -------------------------------------------------------------
|
|
|
|
static AlarmClock l_alarmClock; // the single instance of the AO
|
|
|
|
|
|
|
|
// Global-scope objects ------------------------------------------------------
|
|
|
|
QMActive * const APP_alarmClock = &l_alarmClock; // "opaque" AO pointer
|
|
|
|
|
|
|
|
//............................................................................
|
|
|
|
//${Components::AlarmClock} ..................................................
|
|
|
|
//${Components::AlarmClock::AlarmClock} ......................................
|
|
|
|
AlarmClock::AlarmClock()
|
|
|
|
: QMActive(Q_STATE_CAST(&AlarmClock::initial)),
|
|
|
|
m_alarm(), // orthogonal component ctor
|
|
|
|
m_timeEvt(this, TICK_SIG, 0U)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//${Components::AlarmClock::SM} ..............................................
|
|
|
|
QP::QState AlarmClock::initial(AlarmClock * const me, QP::QEvt const * const e) {
|
|
|
|
static struct {
|
|
|
|
QP::QMState const *target;
|
|
|
|
QP::QActionHandler act[3];
|
|
|
|
} const tatbl_ = { // transition-action table
|
|
|
|
&timekeeping_s,
|
|
|
|
{
|
|
|
|
Q_ACTION_CAST(&timekeeping_e), // entry
|
|
|
|
Q_ACTION_CAST(&timekeeping_i), // initial tran.
|
|
|
|
Q_ACTION_CAST(0) // zero terminator
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// ${Components::AlarmClock::SM::initial}
|
|
|
|
(void)e; // unused parameter
|
|
|
|
me->m_current_time = 0U;
|
|
|
|
|
|
|
|
// (!) trigger the initial transition in the component
|
|
|
|
me->m_alarm.init();
|
|
|
|
return QM_TRAN_INIT(&tatbl_);
|
|
|
|
}
|
|
|
|
//${Components::AlarmClock::SM::timekeeping} .................................
|
|
|
|
QP::QMState const AlarmClock::timekeeping_s = {
|
|
|
|
static_cast<QP::QMState const *>(0), // superstate (top)
|
|
|
|
Q_STATE_CAST(&timekeeping),
|
|
|
|
Q_ACTION_CAST(&timekeeping_e),
|
|
|
|
Q_ACTION_CAST(&timekeeping_x),
|
|
|
|
Q_ACTION_CAST(&timekeeping_i)
|
|
|
|
};
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping}
|
|
|
|
QP::QState AlarmClock::timekeeping_e(AlarmClock * const me) {
|
|
|
|
// periodic timeout every second
|
|
|
|
me->m_timeEvt.armX(BSP_TICKS_PER_SEC, BSP_TICKS_PER_SEC);
|
|
|
|
return QM_ENTRY(&timekeeping_s);
|
|
|
|
}
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping}
|
|
|
|
QP::QState AlarmClock::timekeeping_x(AlarmClock * const me) {
|
|
|
|
me->m_timeEvt.disarm();
|
|
|
|
return QM_EXIT(&timekeeping_s);
|
|
|
|
}
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping::initial}
|
|
|
|
QP::QState AlarmClock::timekeeping_i(AlarmClock * const me) {
|
|
|
|
static struct {
|
|
|
|
QP::QMState const *target;
|
|
|
|
QP::QActionHandler act[2];
|
|
|
|
} const tatbl_ = { // transition-action table
|
|
|
|
&mode24h_s,
|
|
|
|
{
|
|
|
|
Q_ACTION_CAST(&mode24h_e), // entry
|
|
|
|
Q_ACTION_CAST(0) // zero terminator
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping::initial}
|
|
|
|
return QM_TRAN_INIT(&tatbl_);
|
|
|
|
}
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping}
|
|
|
|
QP::QState AlarmClock::timekeeping(AlarmClock * const me, QP::QEvt const * const e) {
|
|
|
|
QP::QState status_;
|
|
|
|
switch (e->sig) {
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping::CLOCK_24H}
|
|
|
|
case CLOCK_24H_SIG: {
|
|
|
|
static struct {
|
|
|
|
QP::QMState const *target;
|
|
|
|
QP::QActionHandler act[2];
|
|
|
|
} const tatbl_ = { // transition-action table
|
|
|
|
&mode24h_s,
|
|
|
|
{
|
|
|
|
Q_ACTION_CAST(&mode24h_e), // entry
|
|
|
|
Q_ACTION_CAST(0) // zero terminator
|
|
|
|
}
|
|
|
|
};
|
|
|
|
status_ = QM_TRAN(&tatbl_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping::CLOCK_12H}
|
|
|
|
case CLOCK_12H_SIG: {
|
|
|
|
static struct {
|
|
|
|
QP::QMState const *target;
|
|
|
|
QP::QActionHandler act[2];
|
|
|
|
} const tatbl_ = { // transition-action table
|
|
|
|
&mode12h_s,
|
|
|
|
{
|
|
|
|
Q_ACTION_CAST(&mode12h_e), // entry
|
|
|
|
Q_ACTION_CAST(0) // zero terminator
|
|
|
|
}
|
|
|
|
};
|
|
|
|
status_ = QM_TRAN(&tatbl_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping::ALARM}
|
|
|
|
case ALARM_SIG: {
|
|
|
|
BSP_showMsg("Wake up!!!");
|
|
|
|
status_ = QM_HANDLED();
|
|
|
|
break;
|
|
|
|
}
|
2015-05-22 20:38:16 -04:00
|
|
|
// ${Components::AlarmClock::SM::timekeeping::ALARM_SET, ALARM_ON, ALARM_OFF}
|
|
|
|
case ALARM_SET_SIG: // intentionally fall through
|
|
|
|
case ALARM_ON_SIG: // intentionally fall through
|
2015-05-14 16:05:04 -04:00
|
|
|
case ALARM_OFF_SIG: {
|
|
|
|
// (!) synchronously dispatch to the orthogonal component
|
|
|
|
me->m_alarm.dispatch(e);
|
|
|
|
status_ = QM_HANDLED();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping::TERMINATE}
|
|
|
|
case TERMINATE_SIG: {
|
|
|
|
static struct {
|
|
|
|
QP::QMState const *target;
|
|
|
|
QP::QActionHandler act[3];
|
|
|
|
} const tatbl_ = { // transition-action table
|
|
|
|
&final_s,
|
|
|
|
{
|
|
|
|
Q_ACTION_CAST(&timekeeping_x), // exit
|
|
|
|
Q_ACTION_CAST(&final_e), // entry
|
|
|
|
Q_ACTION_CAST(0) // zero terminator
|
|
|
|
}
|
|
|
|
};
|
|
|
|
BSP_showMsg("--> final");
|
|
|
|
status_ = QM_TRAN(&tatbl_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
status_ = QM_SUPER();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status_;
|
|
|
|
}
|
|
|
|
//${Components::AlarmClock::SM::timekeeping::mode24h} ........................
|
|
|
|
QP::QMState const AlarmClock::mode24h_s = {
|
|
|
|
&AlarmClock::timekeeping_s, // superstate
|
|
|
|
Q_STATE_CAST(&mode24h),
|
|
|
|
Q_ACTION_CAST(&mode24h_e),
|
|
|
|
Q_ACTION_CAST(0), // no exit action
|
|
|
|
Q_ACTION_CAST(0) // no intitial tran.
|
|
|
|
};
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping::mode24h}
|
|
|
|
QP::QState AlarmClock::mode24h_e(AlarmClock * const me) {
|
|
|
|
BSP_showMsg("*** 24-hour mode");
|
|
|
|
(void)me; // avoid compiler warning in case 'me' is not used
|
|
|
|
return QM_ENTRY(&mode24h_s);
|
|
|
|
}
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping::mode24h}
|
|
|
|
QP::QState AlarmClock::mode24h(AlarmClock * const me, QP::QEvt const * const e) {
|
|
|
|
QP::QState status_;
|
|
|
|
switch (e->sig) {
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping::mode24h::TICK}
|
|
|
|
case TICK_SIG: {
|
|
|
|
// roll over in 24-hr mode?
|
|
|
|
if (++me->m_current_time == 24U*60U) {
|
|
|
|
me->m_current_time = 0U;
|
|
|
|
}
|
|
|
|
BSP_showTime24H("", me->m_current_time, 60U);
|
|
|
|
|
|
|
|
TimeEvt pe; // temporary synchronous event for the component
|
|
|
|
pe.sig = TIME_SIG;
|
|
|
|
pe.current_time = me->m_current_time;
|
|
|
|
|
|
|
|
// (!) synchronously dispatch to the orthogonal component
|
|
|
|
me->m_alarm.dispatch(&pe);
|
|
|
|
status_ = QM_HANDLED();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
status_ = QM_SUPER();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status_;
|
|
|
|
}
|
|
|
|
//${Components::AlarmClock::SM::timekeeping::mode12h} ........................
|
|
|
|
QP::QMState const AlarmClock::mode12h_s = {
|
|
|
|
&AlarmClock::timekeeping_s, // superstate
|
|
|
|
Q_STATE_CAST(&mode12h),
|
|
|
|
Q_ACTION_CAST(&mode12h_e),
|
|
|
|
Q_ACTION_CAST(0), // no exit action
|
|
|
|
Q_ACTION_CAST(0) // no intitial tran.
|
|
|
|
};
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping::mode12h}
|
|
|
|
QP::QState AlarmClock::mode12h_e(AlarmClock * const me) {
|
|
|
|
BSP_showMsg("*** 12-hour mode");
|
|
|
|
(void)me; // avoid compiler warning in case 'me' is not used
|
|
|
|
return QM_ENTRY(&mode12h_s);
|
|
|
|
}
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping::mode12h}
|
|
|
|
QP::QState AlarmClock::mode12h(AlarmClock * const me, QP::QEvt const * const e) {
|
|
|
|
QP::QState status_;
|
|
|
|
switch (e->sig) {
|
|
|
|
// ${Components::AlarmClock::SM::timekeeping::mode12h::TICK}
|
|
|
|
case TICK_SIG: {
|
|
|
|
// roll over in 12-hr mode?
|
|
|
|
if (++me->m_current_time == 12U*60U) {
|
|
|
|
me->m_current_time = 0U;
|
|
|
|
}
|
|
|
|
BSP_showTime12H("", me->m_current_time, 60U);
|
|
|
|
|
|
|
|
TimeEvt pe; // temporary synchronous event for the component
|
|
|
|
pe.sig = TIME_SIG;
|
|
|
|
pe.current_time = me->m_current_time;
|
|
|
|
|
|
|
|
// (!) synchronously dispatch to the orthogonal component
|
|
|
|
me->m_alarm.dispatch(&pe);
|
|
|
|
status_ = QM_HANDLED();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
status_ = QM_SUPER();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status_;
|
|
|
|
}
|
|
|
|
//${Components::AlarmClock::SM::final} .......................................
|
|
|
|
QP::QMState const AlarmClock::final_s = {
|
|
|
|
static_cast<QP::QMState const *>(0), // superstate (top)
|
|
|
|
Q_STATE_CAST(&final),
|
|
|
|
Q_ACTION_CAST(&final_e),
|
|
|
|
Q_ACTION_CAST(0), // no exit action
|
|
|
|
Q_ACTION_CAST(0) // no intitial tran.
|
|
|
|
};
|
|
|
|
// ${Components::AlarmClock::SM::final}
|
|
|
|
QP::QState AlarmClock::final_e(AlarmClock * const me) {
|
|
|
|
BSP_showMsg("Bye! Bye!");
|
|
|
|
QF::stop(); // terminate the application
|
|
|
|
(void)me; // avoid compiler warning in case 'me' is not used
|
|
|
|
return QM_ENTRY(&final_s);
|
|
|
|
}
|
|
|
|
// ${Components::AlarmClock::SM::final}
|
|
|
|
QP::QState AlarmClock::final(AlarmClock * const me, QP::QEvt const * const e) {
|
|
|
|
QP::QState status_;
|
|
|
|
switch (e->sig) {
|
|
|
|
default: {
|
|
|
|
status_ = QM_SUPER();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-05-22 20:38:16 -04:00
|
|
|
(void)me; // avoid compiler warning in case 'me' is not used
|
2015-05-14 16:05:04 -04:00
|
|
|
return status_;
|
|
|
|
}
|
|
|
|
|