1305 lines
38 KiB
C++
Raw Normal View History

2019-12-31 15:56:23 -05:00
//.$file${.::calc1_sub.cpp} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
2017-11-12 21:35:04 -05:00
//
2016-09-01 11:58:57 -04:00
// Model: calc1_sub.qm
2018-04-13 16:28:25 -04:00
// File: ${.::calc1_sub.cpp}
2016-09-01 11:58:57 -04:00
//
2019-12-31 15:56:23 -05:00
// This code has been generated by QM 4.6.0 <www.state-machine.com/qm/>.
2016-09-01 11:58:57 -04:00
// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
//
2017-05-27 10:39:57 -04:00
// This code is covered by the following QP license:
2019-03-06 20:08:32 -05:00
// License # : QPCPP-EVAL
// Issued to : Institution or an individual evaluating the QP/C++ framework
2016-12-01 10:31:49 -05:00
// Framework(s): qpcpp
2019-12-31 15:56:23 -05:00
// Support ends: 2020-12-31
2016-12-01 10:31:49 -05:00
// Product(s) :
// This license is available only for evaluation purposes and
// the generated code is still licensed under the terms of GPL.
// Please submit request for extension of the evaluaion period at:
2019-12-31 15:56:23 -05:00
// <www.state-machine.com/licensing/#RequestForm>
2017-11-12 21:35:04 -05:00
//
2019-12-31 15:56:23 -05:00
//.$endhead${.::calc1_sub.cpp} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2019-10-27 12:26:31 -04:00
#include "qpcpp.hpp" // QP/C++ API
#include "bsp.hpp" // board support package
#include "calc1_sub.hpp" // application
2016-09-01 11:58:57 -04:00
2019-03-28 11:59:31 -04:00
Q_DEFINE_THIS_FILE
#define KEY_NULL '\0'
#define KEY_PLUS '+'
#define KEY_MINUS '-'
#define KEY_MULT '*'
#define KEY_DIVIDE '/'
2019-12-31 15:56:23 -05:00
//.$declare${SMs::Calc} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//.${SMs::Calc} ..............................................................
2016-09-01 11:58:57 -04:00
class Calc : public QP::QMsm {
2019-03-28 11:59:31 -04:00
public:
static Calc inst;
2016-09-01 11:58:57 -04:00
private:
double m_op1;
2019-03-28 11:59:31 -04:00
double m_op2;
uint8_t m_oper1;
uint8_t m_oper2;
2019-03-06 20:08:32 -05:00
2016-09-01 11:58:57 -04:00
public:
Calc();
2019-03-28 11:59:31 -04:00
// guard function to evaluate the current expression
// taking into account the precedence of operands.
// return: true if evaluation successfull
// false when error encountered
bool eval(double op, uint8_t oper);
2016-09-01 11:58:57 -04:00
protected:
2019-03-28 11:59:31 -04:00
struct SM_operand { // submachine "operand"
2016-09-01 11:58:57 -04:00
QP::QMState super;
2019-12-31 15:56:23 -05:00
QP::QActionHandler const CE; // exit-point segment
2016-09-01 11:58:57 -04:00
} const *sub_operand;
2019-03-28 11:59:31 -04:00
QM_STATE_DECL( initial);
QM_STATE_DECL( on);
QM_ACTION_DECL(on_e);
QM_ACTION_DECL(on_x);
QM_ACTION_DECL(on_i);
QM_STATE_DECL( ready);
QM_ACTION_DECL(ready_e);
QM_ACTION_DECL(ready_x);
QM_ACTION_DECL(ready_i);
QM_STATE_DECL( result);
QM_ACTION_DECL(result_e);
QM_ACTION_DECL(result_x);
QM_STATE_DECL( begin);
QM_ACTION_DECL(begin_e);
QM_ACTION_DECL(begin_x);
QM_SM_STATE_DECL(operand, operand1);
QM_ACTION_DECL(operand1_e);
2019-12-31 15:56:23 -05:00
QM_ACTION_DECL(operand1_CE);
2019-03-28 11:59:31 -04:00
QM_STATE_DECL( opEntered);
QM_ACTION_DECL(opEntered_e);
QM_ACTION_DECL(opEntered_x);
QM_SM_STATE_DECL(operand, operand2);
QM_ACTION_DECL(operand2_e);
2019-12-31 15:56:23 -05:00
QM_ACTION_DECL(operand2_CE);
2019-03-28 11:59:31 -04:00
QM_STATE_DECL( error);
QM_ACTION_DECL(error_e);
QM_ACTION_DECL(error_x);
QM_STATE_DECL( final);
QM_ACTION_DECL(final_e);
// submachine "operand"
QM_STATE_DECL( operand);
QM_ACTION_DECL(operand_e);
QM_ACTION_DECL(operand_x);
QM_ACTION_DECL(operand_i);
QM_ACTION_DECL(operand_zero_ep);
QM_ACTION_DECL(operand_intgr_ep);
QM_ACTION_DECL(operand_frac_ep);
QM_ACTION_DECL(operand_neg_ep);
QM_STATE_DECL( operand_zero);
QM_ACTION_DECL(operand_zero_e);
QM_ACTION_DECL(operand_zero_x);
QM_STATE_DECL( operand_intgr);
QM_ACTION_DECL(operand_intgr_e);
QM_ACTION_DECL(operand_intgr_x);
QM_STATE_DECL( operand_frac);
QM_ACTION_DECL(operand_frac_e);
QM_ACTION_DECL(operand_frac_x);
QM_STATE_DECL( operand_neg);
QM_ACTION_DECL(operand_neg_e);
QM_ACTION_DECL(operand_neg_x);
2016-09-01 11:58:57 -04:00
};
2019-12-31 15:56:23 -05:00
//.$enddecl${SMs::Calc} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2016-09-01 11:58:57 -04:00
2019-12-31 15:56:23 -05:00
//.$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//. Check for the minimum required QP version
2019-03-28 11:59:31 -04:00
#if (QP_VERSION < 650U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
#error qpcpp version 6.5.0 or higher required
2017-11-12 21:35:04 -05:00
#endif
2019-12-31 15:56:23 -05:00
//.$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//.$define${SMs::the_calc} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//.${SMs::the_calc} ..........................................................
2019-03-28 11:59:31 -04:00
QP::QHsm * const the_calc = &Calc::inst;
2019-12-31 15:56:23 -05:00
//.$enddef${SMs::the_calc} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//.$define${SMs::Calc} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//.${SMs::Calc} ..............................................................
2019-03-28 11:59:31 -04:00
Calc Calc::inst;
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::Calc} ........................................................
2016-09-01 11:58:57 -04:00
Calc::Calc()
2019-03-28 11:59:31 -04:00
: QMsm(&initial)
2016-09-01 11:58:57 -04:00
{}
2019-03-28 11:59:31 -04:00
// guard function to evaluate the current expression
// taking into account the precedence of operands.
// return: true if evaluation successfull
// false when error encountered
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::eval} ........................................................
2019-03-28 11:59:31 -04:00
bool Calc::eval(double op, uint8_t oper) {
double result;
if ((oper == KEY_NULL) || (oper == KEY_PLUS) || (oper == KEY_MINUS)) {
switch (m_oper2) {
case KEY_MULT: {
m_op2 *= op;
break;
}
case KEY_DIVIDE: {
if ((-1e-30 < op) && (op < 1e-30)) {
BSP_display_error(" Error 0 "); // divide by zero
return false;
}
m_op2 /= op;
break;
}
default: { /* no op2 yet */
m_op2 = op;
m_oper2 = oper;
break;
}
}
switch (m_oper1) {
case KEY_PLUS: {
m_op1 += m_op2;
break;
}
case KEY_MINUS: {
m_op1 -= m_op2;
break;
}
case KEY_MULT: {
m_op1 *= m_op2;
break;
}
case KEY_DIVIDE: {
if ((-1e-30 < m_op2) && (m_op2 < 1e-30)) {
BSP_display_error(" Error 0 "); // divide by zero
return false;
}
m_op1 /= m_op2;
break;
}
default: {
Q_ERROR();
break;
}
}
m_oper1 = oper;
m_oper2 = KEY_NULL;
result = m_op1;
}
else { // (oper == KEY_MULT) || (oper == KEY_DIV)
switch (m_oper2) {
case KEY_MULT: {
m_op2 *= op;
break;
}
case KEY_DIVIDE: {
if ((-1e-30 < op) && (op < 1e-30)) {
BSP_display_error(" Error 0 "); // divide by zero
return false;
}
m_op2 /= op;
break;
}
default: { // oper2 not provided yet
m_op2 = op;
break;
}
}
m_oper2 = oper;
result = m_op2;
}
if ((result < -99999999.0) || (99999999.0 < result)) {
BSP_display_error(" Error 1 "); // out of range
return false;
}
if ((-0.0000001 < result) && (result < 0.0000001)) {
result = 0.0;
}
BSP_display(result);
return true;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM} ..........................................................
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, initial) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::initial}
2019-03-28 11:59:31 -04:00
BSP_clear();
(void)e; // unused parameter
QS_FUN_DICTIONARY(&on);
QS_FUN_DICTIONARY(&ready);
QS_FUN_DICTIONARY(&result);
QS_FUN_DICTIONARY(&begin);
QS_FUN_DICTIONARY(&operand1);
QS_FUN_DICTIONARY(&opEntered);
QS_FUN_DICTIONARY(&operand2);
QS_FUN_DICTIONARY(&error);
QS_FUN_DICTIONARY(&final);
QS_FUN_DICTIONARY(&operand_zero);
QS_FUN_DICTIONARY(&operand_intgr);
QS_FUN_DICTIONARY(&operand_frac);
QS_FUN_DICTIONARY(&operand_neg);
QS_FUN_DICTIONARY(&operand);
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[3];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2016-09-01 11:58:57 -04:00
&on_s, // target state
{
2019-03-28 11:59:31 -04:00
&on_e, // entry
&on_i, // initial tran.
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
return qm_tran_init(&tatbl_);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on} ......................................................
2016-09-01 11:58:57 -04:00
QP::QMState const Calc::on_s = {
2019-03-28 11:59:31 -04:00
QM_STATE_NULL, // superstate (top)
&Calc::on,
&Calc::on_e,
&Calc::on_x,
&Calc::on_i
2016-09-01 11:58:57 -04:00
};
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, on_e) {
2016-09-01 11:58:57 -04:00
BSP_message("on-ENTRY;");
2019-03-28 11:59:31 -04:00
return qm_entry(&on_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, on_x) {
2016-09-01 11:58:57 -04:00
BSP_message("on-EXIT;");
2019-03-28 11:59:31 -04:00
return qm_exit(&on_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::initial}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, on_i) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::initial}
2019-03-28 11:59:31 -04:00
BSP_message("on-INIT;");
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[3];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2016-09-01 11:58:57 -04:00
&ready_s, // target state
{
2019-03-28 11:59:31 -04:00
&ready_e, // entry
&ready_i, // initial tran.
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
return qm_tran_init(&tatbl_);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on}
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, on) {
2016-09-01 11:58:57 -04:00
QP::QState status_;
switch (e->sig) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::C}
2016-09-01 11:58:57 -04:00
case C_SIG: {
2019-03-28 11:59:31 -04:00
BSP_clear();
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[4];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2016-09-01 11:58:57 -04:00
&on_s, // target state
{
2019-03-28 11:59:31 -04:00
&on_x, // exit
&on_e, // entry
&on_i, // initial tran.
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::OFF}
2016-09-01 11:58:57 -04:00
case OFF_SIG: {
2019-03-28 11:59:31 -04:00
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[3];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2016-09-01 11:58:57 -04:00
&final_s, // target state
{
2019-03-28 11:59:31 -04:00
&on_x, // exit
&final_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
default: {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_SUPER;
2016-09-01 11:58:57 -04:00
break;
}
}
return status_;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready} ...............................................
2016-09-01 11:58:57 -04:00
QP::QMState const Calc::ready_s = {
&Calc::on_s, // superstate
2019-03-28 11:59:31 -04:00
&Calc::ready,
&Calc::ready_e,
&Calc::ready_x,
&Calc::ready_i
2016-09-01 11:58:57 -04:00
};
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, ready_e) {
2016-09-01 11:58:57 -04:00
BSP_message("ready-ENTRY;");
2019-03-28 11:59:31 -04:00
m_oper2 = KEY_NULL;
return qm_entry(&ready_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, ready_x) {
2016-09-01 11:58:57 -04:00
BSP_message("ready-EXIT;");
2019-03-28 11:59:31 -04:00
return qm_exit(&ready_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::initial}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, ready_i) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::initial}
2019-03-28 11:59:31 -04:00
BSP_message("ready-INIT;");
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[2];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2016-09-01 11:58:57 -04:00
&begin_s, // target state
{
2019-03-28 11:59:31 -04:00
&begin_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
return qm_tran_init(&tatbl_);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready}
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, ready) {
2016-09-01 11:58:57 -04:00
QP::QState status_;
switch (e->sig) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::DIGIT_0}
2016-09-01 11:58:57 -04:00
case DIGIT_0_SIG: {
2019-03-28 11:59:31 -04:00
BSP_clear();
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[4];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2018-05-07 16:05:00 -04:00
&operand_s, // target submachine
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&ready_x, // exit
&operand1_e, // entry
&operand_zero_ep, // EP
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran_ep(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::DIGIT_1_9}
2016-09-01 11:58:57 -04:00
case DIGIT_1_9_SIG: {
2019-03-28 11:59:31 -04:00
BSP_clear();
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[4];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2018-05-07 16:05:00 -04:00
&operand_s, // target submachine
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&ready_x, // exit
&operand1_e, // entry
&operand_intgr_ep, // EP
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran_ep(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::POINT}
2016-09-01 11:58:57 -04:00
case POINT_SIG: {
2019-03-28 11:59:31 -04:00
BSP_clear();
BSP_insert((int)'0');
BSP_insert((int)'.');
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
2016-12-01 10:31:49 -05:00
QP::QActionHandler act[4];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2018-05-07 16:05:00 -04:00
&operand_s, // target submachine
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&ready_x, // exit
&operand1_e, // entry
&operand_frac_ep, // EP
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran_ep(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::OPER}
2016-09-01 11:58:57 -04:00
case OPER_SIG: {
2019-03-28 11:59:31 -04:00
m_op1 = BSP_get_value();
m_oper1 = Q_EVT_CAST(CalcEvt)->key_code;
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[3];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2016-09-01 11:58:57 -04:00
&opEntered_s, // target state
{
2019-03-28 11:59:31 -04:00
&ready_x, // exit
&opEntered_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
default: {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_SUPER;
2016-09-01 11:58:57 -04:00
break;
}
}
return status_;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::result} .......................................
2016-09-01 11:58:57 -04:00
QP::QMState const Calc::result_s = {
&Calc::ready_s, // superstate
2019-03-28 11:59:31 -04:00
&Calc::result,
&Calc::result_e,
&Calc::result_x,
Q_ACTION_NULL // no initial tran.
2016-09-01 11:58:57 -04:00
};
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::result}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, result_e) {
2016-09-01 11:58:57 -04:00
BSP_message("result-ENTRY;");
2019-03-28 11:59:31 -04:00
return qm_entry(&result_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::result}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, result_x) {
2016-09-01 11:58:57 -04:00
BSP_message("result-EXIT;");
2019-03-28 11:59:31 -04:00
return qm_exit(&result_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::result}
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, result) {
2016-09-01 11:58:57 -04:00
QP::QState status_;
switch (e->sig) {
default: {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_SUPER;
2016-09-01 11:58:57 -04:00
break;
}
}
return status_;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::begin} ........................................
2016-09-01 11:58:57 -04:00
QP::QMState const Calc::begin_s = {
&Calc::ready_s, // superstate
2019-03-28 11:59:31 -04:00
&Calc::begin,
&Calc::begin_e,
&Calc::begin_x,
Q_ACTION_NULL // no initial tran.
2016-09-01 11:58:57 -04:00
};
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::begin}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, begin_e) {
2016-09-01 11:58:57 -04:00
BSP_message("begin-ENTRY;");
2019-03-28 11:59:31 -04:00
return qm_entry(&begin_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::begin}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, begin_x) {
2016-09-01 11:58:57 -04:00
BSP_message("begin-EXIT;");
2019-03-28 11:59:31 -04:00
return qm_exit(&begin_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::begin}
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, begin) {
2016-09-01 11:58:57 -04:00
QP::QState status_;
switch (e->sig) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::begin::OPER}
2016-09-01 11:58:57 -04:00
case OPER_SIG: {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::begin::OPER::[e->key=='-']}
2016-09-01 11:58:57 -04:00
if (Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS) {
2019-03-28 11:59:31 -04:00
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[5];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2018-05-07 16:05:00 -04:00
&operand_s, // target submachine
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&begin_x, // exit
&ready_x, // exit
&operand1_e, // entry
&operand_neg_ep, // EP
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran_ep(&tatbl_);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::ready::begin::OPER::[else]}
2016-09-01 11:58:57 -04:00
else {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_HANDLED;
2016-09-01 11:58:57 -04:00
}
break;
}
default: {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_SUPER;
2016-09-01 11:58:57 -04:00
break;
}
}
return status_;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand1} ............................................
2016-09-01 11:58:57 -04:00
Calc::SM_operand const Calc::operand1_s = {
{
&Calc::on_s, // superstate
2019-03-28 11:59:31 -04:00
&Calc::operand1,
&Calc::operand1_e,
Q_ACTION_NULL, // no exit action
Q_ACTION_NULL // no initial tran.
2016-09-01 11:58:57 -04:00
}
2017-11-12 21:35:04 -05:00
2019-12-31 15:56:23 -05:00
,&Calc::operand1_CE
2016-09-01 11:58:57 -04:00
};
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand1}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand1_e) {
sub_operand = &Calc::operand1_s; // attach submachine
return operand_e(this); // enter submachine
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand1}
QM_ACTION_DEF(Calc, operand1_CE) {
BSP_message("operand1:XP-CE;");
2019-03-28 11:59:31 -04:00
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
2017-06-06 15:12:43 -04:00
QP::QActionHandler act[4];
} const tatbl_ = { // tran-action table
2016-09-01 11:58:57 -04:00
&ready_s, // target state
{
2019-03-28 11:59:31 -04:00
&operand_x, // submachine exit
&ready_e, // entry
&ready_i, // initial tran.
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
return qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand1}
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, operand1) {
2016-09-01 11:58:57 -04:00
QP::QState status_;
switch (e->sig) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand1::OPER}
2016-09-01 11:58:57 -04:00
case OPER_SIG: {
2019-03-28 11:59:31 -04:00
m_op1 = BSP_get_value();
m_oper1 = Q_EVT_CAST(CalcEvt)->key_code;
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
2016-12-01 10:31:49 -05:00
QP::QActionHandler act[2];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2016-09-01 11:58:57 -04:00
&opEntered_s, // target state
{
2019-03-28 11:59:31 -04:00
&opEntered_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand1::EQUALS}
2016-09-01 11:58:57 -04:00
case EQUALS_SIG: {
2019-03-28 11:59:31 -04:00
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
2016-12-01 10:31:49 -05:00
QP::QActionHandler act[3];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2016-09-01 11:58:57 -04:00
&result_s, // target state
{
2019-03-28 11:59:31 -04:00
&ready_e, // entry
&result_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
default: {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_SUPER;
2016-09-01 11:58:57 -04:00
break;
}
}
return status_;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::opEntered} ...........................................
2016-09-01 11:58:57 -04:00
QP::QMState const Calc::opEntered_s = {
&Calc::on_s, // superstate
2019-03-28 11:59:31 -04:00
&Calc::opEntered,
&Calc::opEntered_e,
&Calc::opEntered_x,
Q_ACTION_NULL // no initial tran.
2016-09-01 11:58:57 -04:00
};
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::opEntered}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, opEntered_e) {
2016-09-01 11:58:57 -04:00
BSP_message("opEntered-ENTRY;");
2019-03-28 11:59:31 -04:00
return qm_entry(&opEntered_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::opEntered}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, opEntered_x) {
2016-09-01 11:58:57 -04:00
BSP_message("opEntered-EXIT;");
2019-03-28 11:59:31 -04:00
return qm_exit(&opEntered_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::opEntered}
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, opEntered) {
2016-09-01 11:58:57 -04:00
QP::QState status_;
switch (e->sig) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::opEntered::DIGIT_0}
2016-09-01 11:58:57 -04:00
case DIGIT_0_SIG: {
2019-03-28 11:59:31 -04:00
BSP_clear();
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[4];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2018-05-07 16:05:00 -04:00
&operand_s, // target submachine
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&opEntered_x, // exit
&operand2_e, // entry
&operand_zero_ep, // EP
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran_ep(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::opEntered::DIGIT_1_9}
2016-09-01 11:58:57 -04:00
case DIGIT_1_9_SIG: {
2019-03-28 11:59:31 -04:00
BSP_clear();
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[4];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2018-05-07 16:05:00 -04:00
&operand_s, // target submachine
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&opEntered_x, // exit
&operand2_e, // entry
&operand_intgr_ep, // EP
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran_ep(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::opEntered::POINT}
2016-09-01 11:58:57 -04:00
case POINT_SIG: {
2019-03-28 11:59:31 -04:00
BSP_clear();
BSP_insert((int)'0');
BSP_insert((int)'.');
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[4];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2018-05-07 16:05:00 -04:00
&operand_s, // target submachine
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&opEntered_x, // exit
&operand2_e, // entry
&operand_frac_ep, // EP
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran_ep(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::opEntered::OPER}
2016-09-01 11:58:57 -04:00
case OPER_SIG: {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::opEntered::OPER::[e->key=='-']}
2016-09-01 11:58:57 -04:00
if (Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS) {
2019-03-28 11:59:31 -04:00
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[4];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2018-05-07 16:05:00 -04:00
&operand_s, // target submachine
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&opEntered_x, // exit
&operand2_e, // entry
&operand_neg_ep, // EP
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran_ep(&tatbl_);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::opEntered::OPER::[else]}
2016-09-01 11:58:57 -04:00
else {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_HANDLED;
2016-09-01 11:58:57 -04:00
}
break;
}
default: {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_SUPER;
2016-09-01 11:58:57 -04:00
break;
}
}
return status_;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand2} ............................................
2016-09-01 11:58:57 -04:00
Calc::SM_operand const Calc::operand2_s = {
{
&Calc::on_s, // superstate
2019-03-28 11:59:31 -04:00
&Calc::operand2,
&Calc::operand2_e,
Q_ACTION_NULL, // no exit action
Q_ACTION_NULL // no initial tran.
2016-09-01 11:58:57 -04:00
}
2017-11-12 21:35:04 -05:00
2019-12-31 15:56:23 -05:00
,&Calc::operand2_CE
2016-09-01 11:58:57 -04:00
};
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand2}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand2_e) {
sub_operand = &Calc::operand2_s; // attach submachine
return operand_e(this); // enter submachine
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand2}
QM_ACTION_DEF(Calc, operand2_CE) {
BSP_message("operand2:XP-CE;");
2019-03-28 11:59:31 -04:00
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
2017-06-06 15:12:43 -04:00
QP::QActionHandler act[3];
} const tatbl_ = { // tran-action table
2016-09-01 11:58:57 -04:00
&opEntered_s, // target state
{
2019-03-28 11:59:31 -04:00
&operand_x, // submachine exit
&opEntered_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
return qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand2}
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, operand2) {
2016-09-01 11:58:57 -04:00
QP::QState status_;
switch (e->sig) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand2::OPER}
2016-09-01 11:58:57 -04:00
case OPER_SIG: {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand2::OPER::[eval()]}
2019-03-28 11:59:31 -04:00
if (eval(BSP_get_value(), Q_EVT_CAST(CalcEvt)->key_code)) {
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
2016-12-01 10:31:49 -05:00
QP::QActionHandler act[2];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2016-09-01 11:58:57 -04:00
&opEntered_s, // target state
{
2019-03-28 11:59:31 -04:00
&opEntered_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand2::OPER::[else]}
2016-09-01 11:58:57 -04:00
else {
2019-03-28 11:59:31 -04:00
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
2016-12-01 10:31:49 -05:00
QP::QActionHandler act[2];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2016-09-01 11:58:57 -04:00
&error_s, // target state
{
2019-03-28 11:59:31 -04:00
&error_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
}
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand2::EQUALS}
2016-09-01 11:58:57 -04:00
case EQUALS_SIG: {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand2::EQUALS::[eval()]}
2019-03-28 11:59:31 -04:00
if (eval(BSP_get_value(), KEY_NULL)) {
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
2016-12-01 10:31:49 -05:00
QP::QActionHandler act[3];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2016-09-01 11:58:57 -04:00
&result_s, // target state
{
2019-03-28 11:59:31 -04:00
&ready_e, // entry
&result_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::operand2::EQUALS::[else]}
2016-09-01 11:58:57 -04:00
else {
2019-03-28 11:59:31 -04:00
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
2016-12-01 10:31:49 -05:00
QP::QActionHandler act[2];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2016-09-01 11:58:57 -04:00
&error_s, // target state
{
2019-03-28 11:59:31 -04:00
&error_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
}
break;
}
default: {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_SUPER;
break;
}
}
return status_;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::error} ...............................................
2019-03-28 11:59:31 -04:00
QP::QMState const Calc::error_s = {
&Calc::on_s, // superstate
&Calc::error,
&Calc::error_e,
&Calc::error_x,
Q_ACTION_NULL // no initial tran.
};
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::error}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, error_e) {
BSP_message("error-ENTRY;");
return qm_entry(&error_s);
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::error}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, error_x) {
BSP_message("error-EXIT;");
return qm_exit(&error_s);
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::on::error}
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, error) {
QP::QState status_;
switch (e->sig) {
default: {
status_ = Q_RET_SUPER;
2016-09-01 11:58:57 -04:00
break;
}
}
return status_;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::final} ...................................................
2016-09-01 11:58:57 -04:00
QP::QMState const Calc::final_s = {
2019-03-28 11:59:31 -04:00
QM_STATE_NULL, // superstate (top)
&Calc::final,
&Calc::final_e,
Q_ACTION_NULL, // no exit action
Q_ACTION_NULL // no initial tran.
2016-09-01 11:58:57 -04:00
};
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::final}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, final_e) {
2016-09-01 11:58:57 -04:00
BSP_message("final-ENTRY;");
BSP_exit();
2019-03-28 11:59:31 -04:00
return qm_entry(&final_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::final}
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, final) {
2016-09-01 11:58:57 -04:00
QP::QState status_;
switch (e->sig) {
default: {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_SUPER;
2016-09-01 11:58:57 -04:00
break;
}
}
return status_;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand} .................................................
//.${SMs::Calc::SM::operand}
2016-09-01 11:58:57 -04:00
QP::QMState const Calc::operand_s = {
2019-03-28 11:59:31 -04:00
QM_STATE_NULL, // superstate unused
&Calc::operand,
&Calc::operand_e,
&Calc::operand_x,
&Calc::operand_i
2016-09-01 11:58:57 -04:00
};
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_e) {
2016-09-01 11:58:57 -04:00
BSP_message("operand-ENTRY;");
2019-03-28 11:59:31 -04:00
return qm_entry(&operand_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_x) {
2016-09-01 11:58:57 -04:00
BSP_message("operand-EXIT;");
2019-03-28 11:59:31 -04:00
return qm_sm_exit(&sub_operand->super);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::initial}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_i) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::initial}
2019-03-28 11:59:31 -04:00
BSP_message("operand-INIT;");
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[2];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2019-03-28 11:59:31 -04:00
&operand_zero_s, // target state
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&operand_zero_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
return qm_tran_init(&tatbl_);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand}
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, operand) {
2016-09-01 11:58:57 -04:00
QP::QState status_;
switch (e->sig) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::CE}
2016-09-01 11:58:57 -04:00
case CE_SIG: {
2019-03-28 11:59:31 -04:00
BSP_message("operand::CE;");
BSP_clear();
2017-06-06 15:12:43 -04:00
static QP::QMTranActTable const tatbl_ = { // tran-action table
2017-05-27 10:39:57 -04:00
&operand_s, // target submachine
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-12-31 15:56:23 -05:00
status_ = qm_tran_xp(sub_operand->CE, &tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
default: {
2019-03-28 11:59:31 -04:00
status_ = qm_super_sub(&sub_operand->super);
2016-09-01 11:58:57 -04:00
break;
}
}
return status_;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::EP-zero}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_zero_ep) {
2019-12-31 15:56:23 -05:00
BSP_message("operand::EP-zero;");
2019-03-28 11:59:31 -04:00
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[2];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2019-03-28 11:59:31 -04:00
&operand_zero_s, // target state
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&operand_zero_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
return qm_tran_ep(&tatbl_);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::EP-intgr}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_intgr_ep) {
2019-12-31 15:56:23 -05:00
BSP_message("operand::EP-intgr;");
2019-03-28 11:59:31 -04:00
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[2];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2019-03-28 11:59:31 -04:00
&operand_intgr_s, // target state
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&operand_intgr_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
return qm_tran_ep(&tatbl_);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::EP-frac}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_frac_ep) {
2019-12-31 15:56:23 -05:00
BSP_message("operand::EP-frac;");
2019-03-28 11:59:31 -04:00
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[2];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2019-03-28 11:59:31 -04:00
&operand_frac_s, // target state
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&operand_frac_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
return qm_tran_ep(&tatbl_);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::EP-neg}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_neg_ep) {
2019-12-31 15:56:23 -05:00
BSP_message("operand::EP-neg;");
2019-03-28 11:59:31 -04:00
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[2];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2019-03-28 11:59:31 -04:00
&operand_neg_s, // target state
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&operand_neg_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
return qm_tran_ep(&tatbl_);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::zero} ...........................................
2019-03-28 11:59:31 -04:00
QP::QMState const Calc::operand_zero_s = {
2016-09-01 11:58:57 -04:00
&Calc::operand_s, // superstate
2019-03-28 11:59:31 -04:00
&Calc::operand_zero,
&Calc::operand_zero_e,
&Calc::operand_zero_x,
Q_ACTION_NULL // no initial tran.
2016-09-01 11:58:57 -04:00
};
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::zero}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_zero_e) {
2016-09-01 11:58:57 -04:00
BSP_message("operand::zero-ENTRY;");
2019-03-28 11:59:31 -04:00
return qm_entry(&operand_zero_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::zero}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_zero_x) {
2016-09-01 11:58:57 -04:00
BSP_message("operand::zero-EXIT;");
2019-03-28 11:59:31 -04:00
return qm_exit(&operand_zero_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::zero}
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, operand_zero) {
2016-09-01 11:58:57 -04:00
QP::QState status_;
switch (e->sig) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::zero::DIGIT_0}
2016-09-01 11:58:57 -04:00
case DIGIT_0_SIG: {
;
2019-03-28 11:59:31 -04:00
status_ = Q_RET_HANDLED;
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::zero::DIGIT_1_9}
2016-09-01 11:58:57 -04:00
case DIGIT_1_9_SIG: {
2019-03-28 11:59:31 -04:00
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[3];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2019-03-28 11:59:31 -04:00
&operand_intgr_s, // target state
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&operand_zero_x, // exit
&operand_intgr_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::zero::POINT}
2016-09-01 11:58:57 -04:00
case POINT_SIG: {
2019-03-28 11:59:31 -04:00
BSP_insert((int)'0');
BSP_insert((int)'.');
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[3];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2019-03-28 11:59:31 -04:00
&operand_frac_s, // target state
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&operand_zero_x, // exit
&operand_frac_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
default: {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_SUPER;
2016-09-01 11:58:57 -04:00
break;
}
}
return status_;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::intgr} ..........................................
2019-03-28 11:59:31 -04:00
QP::QMState const Calc::operand_intgr_s = {
2016-09-01 11:58:57 -04:00
&Calc::operand_s, // superstate
2019-03-28 11:59:31 -04:00
&Calc::operand_intgr,
&Calc::operand_intgr_e,
&Calc::operand_intgr_x,
Q_ACTION_NULL // no initial tran.
2016-09-01 11:58:57 -04:00
};
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::intgr}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_intgr_e) {
2016-09-01 11:58:57 -04:00
BSP_message("operand::intgr-ENTRY;");
2019-03-28 11:59:31 -04:00
return qm_entry(&operand_intgr_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::intgr}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_intgr_x) {
2016-09-01 11:58:57 -04:00
BSP_message("operand::intgr-EXIT;");
2019-03-28 11:59:31 -04:00
return qm_exit(&operand_intgr_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::intgr}
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, operand_intgr) {
2016-09-01 11:58:57 -04:00
QP::QState status_;
switch (e->sig) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::intgr::POINT}
2016-09-01 11:58:57 -04:00
case POINT_SIG: {
2019-03-28 11:59:31 -04:00
BSP_insert((int)'.');
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[3];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2019-03-28 11:59:31 -04:00
&operand_frac_s, // target state
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&operand_intgr_x, // exit
&operand_frac_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::intgr::DIGIT_0, DIGIT_1_9}
2016-09-01 11:58:57 -04:00
case DIGIT_0_SIG: // intentionally fall through
case DIGIT_1_9_SIG: {
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
2019-03-28 11:59:31 -04:00
status_ = Q_RET_HANDLED;
2016-09-01 11:58:57 -04:00
break;
}
default: {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_SUPER;
2016-09-01 11:58:57 -04:00
break;
}
}
return status_;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::frac} ...........................................
2019-03-28 11:59:31 -04:00
QP::QMState const Calc::operand_frac_s = {
2016-09-01 11:58:57 -04:00
&Calc::operand_s, // superstate
2019-03-28 11:59:31 -04:00
&Calc::operand_frac,
&Calc::operand_frac_e,
&Calc::operand_frac_x,
Q_ACTION_NULL // no initial tran.
2016-09-01 11:58:57 -04:00
};
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::frac}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_frac_e) {
2016-09-01 11:58:57 -04:00
BSP_message("operand::frac-ENTRY;");
2019-03-28 11:59:31 -04:00
return qm_entry(&operand_frac_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::frac}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_frac_x) {
2016-09-01 11:58:57 -04:00
BSP_message("operand::frac-EXIT;");
2019-03-28 11:59:31 -04:00
return qm_exit(&operand_frac_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::frac}
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, operand_frac) {
2016-09-01 11:58:57 -04:00
QP::QState status_;
switch (e->sig) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::frac::POINT}
2016-09-01 11:58:57 -04:00
case POINT_SIG: {
;
2019-03-28 11:59:31 -04:00
status_ = Q_RET_HANDLED;
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::frac::DIGIT_0, DIGIT_1_9}
2016-09-01 11:58:57 -04:00
case DIGIT_0_SIG: // intentionally fall through
case DIGIT_1_9_SIG: {
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
2019-03-28 11:59:31 -04:00
status_ = Q_RET_HANDLED;
2016-09-01 11:58:57 -04:00
break;
}
default: {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_SUPER;
2016-09-01 11:58:57 -04:00
break;
}
}
return status_;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::neg} ............................................
2019-03-28 11:59:31 -04:00
QP::QMState const Calc::operand_neg_s = {
2016-09-01 11:58:57 -04:00
&Calc::operand_s, // superstate
2019-03-28 11:59:31 -04:00
&Calc::operand_neg,
&Calc::operand_neg_e,
&Calc::operand_neg_x,
Q_ACTION_NULL // no initial tran.
2016-09-01 11:58:57 -04:00
};
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::neg}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_neg_e) {
2016-09-01 11:58:57 -04:00
BSP_message("operand::neg-ENTRY;");
BSP_negate();
2019-03-28 11:59:31 -04:00
return qm_entry(&operand_neg_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::neg}
2019-03-28 11:59:31 -04:00
QM_ACTION_DEF(Calc, operand_neg_x) {
2016-09-01 11:58:57 -04:00
BSP_message("operand::neg-EXIT;");
2019-03-28 11:59:31 -04:00
return qm_exit(&operand_neg_s);
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::neg}
2019-03-28 11:59:31 -04:00
QM_STATE_DEF(Calc, operand_neg) {
2016-09-01 11:58:57 -04:00
QP::QState status_;
switch (e->sig) {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::neg::DIGIT_0}
2016-09-01 11:58:57 -04:00
case DIGIT_0_SIG: {
2019-03-28 11:59:31 -04:00
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[3];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2019-03-28 11:59:31 -04:00
&operand_zero_s, // target state
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&operand_neg_x, // exit
&operand_zero_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::neg::DIGIT_1_9}
2016-09-01 11:58:57 -04:00
case DIGIT_1_9_SIG: {
2019-03-28 11:59:31 -04:00
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[3];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2019-03-28 11:59:31 -04:00
&operand_intgr_s, // target state
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&operand_neg_x, // exit
&operand_intgr_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::neg::POINT}
2016-09-01 11:58:57 -04:00
case POINT_SIG: {
2019-03-28 11:59:31 -04:00
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
2016-09-01 11:58:57 -04:00
static struct {
QP::QMState const *target;
QP::QActionHandler act[3];
2017-06-06 15:12:43 -04:00
} const tatbl_ = { // tran-action table
2019-03-28 11:59:31 -04:00
&operand_frac_s, // target state
2016-09-01 11:58:57 -04:00
{
2019-03-28 11:59:31 -04:00
&operand_neg_x, // exit
&operand_frac_e, // entry
Q_ACTION_NULL // zero terminator
2016-09-01 11:58:57 -04:00
}
};
2019-03-28 11:59:31 -04:00
status_ = qm_tran(&tatbl_);
2016-09-01 11:58:57 -04:00
break;
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::neg::OPER}
2016-09-01 11:58:57 -04:00
case OPER_SIG: {
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::neg::OPER::[e->key=='-']}
2016-09-01 11:58:57 -04:00
if (Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS) {
;
2019-03-28 11:59:31 -04:00
status_ = Q_RET_HANDLED;
2016-09-01 11:58:57 -04:00
}
2019-12-31 15:56:23 -05:00
//.${SMs::Calc::SM::operand::neg::OPER::[else]}
2016-09-01 11:58:57 -04:00
else {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_HANDLED;
2016-09-01 11:58:57 -04:00
}
break;
}
default: {
2019-03-28 11:59:31 -04:00
status_ = Q_RET_SUPER;
2016-09-01 11:58:57 -04:00
break;
}
}
return status_;
}
2019-12-31 15:56:23 -05:00
//.$enddef${SMs::Calc} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^