/*..........................................................................*/
QState Calc_operand1(Calc * const me, QEvt const * const e) {
    QState status;
    switch (e->sig) {
        case Q_ENTRY_SIG: {
            BSP_message("operand1-ENTRY;");
            status = Q_HANDLED();
            break;
        }
        case Q_EXIT_SIG: {
            BSP_message("operand1-EXIT;");
            status = Q_HANDLED();
            break;
        }
        case CE_SIG: {
            BSP_clear();
            status = Q_TRAN(&Calc_begin);
            break;
        }
        case OPER_SIG: {
            me->operand1 = BSP_get_value();
            me->operator = ((CalcEvt const *)e)->key_code;
            status = Q_TRAN(&Calc_opEntered);
            break;
        }
        case EQUALS_SIG: {
            status = Q_TRAN(&Calc_result);
            break;
        }
        default: {
            status = Q_SUPER(&Calc_on);
            break;
        }
    }
    return status;
}
/*..........................................................................*/
QState Calc_ready(Calc * const me, QEvt const * const e) {
    QState status;
    switch (e->sig) {
        case Q_ENTRY_SIG: {
            BSP_message("ready-ENTRY;");
            status = Q_HANDLED();
            break;
        }
        case Q_EXIT_SIG: {
            BSP_message("ready-EXIT;");
            status = Q_HANDLED();
            break;
        }
        case Q_INIT_SIG: {
            BSP_message("ready-INIT;");
            status = Q_TRAN(&Calc_begin);
            break;
        }
        case DIGIT_0_SIG: {
            BSP_clear();
            status = Q_TRAN(&Calc_zero1);
            break;
        }
        case DIGIT_1_9_SIG: {
            BSP_clear();
            BSP_insert(((CalcEvt const *)e)->key_code);
            status = Q_TRAN(&Calc_int1);
            break;
        }
        case POINT_SIG: {
            BSP_clear();
            BSP_insert((int)'0');
            BSP_insert((int)'.');
            status = Q_TRAN(&Calc_frac1);
            break;
        }
        case OPER_SIG: {
            me->operand1 = BSP_get_value();
            me->operator = ((CalcEvt const *)e)->key_code;
            status = Q_TRAN(&Calc_opEntered);
            break;
        }
        default: {
            status = Q_SUPER(&Calc_on);
            break;
        }
    }
    return status;
}
Exemple #3
0
/* ${SMs::Calc::SM::on::operand1} */
static QState Calc_operand1(Calc * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* ${SMs::Calc::SM::on::operand1::CE} */
        case CE_SIG: {
            static struct {
                QMState const *target;
                QActionHandler act[4];
            } const tatbl_ = { /* transition-action table */
                &Calc_begin_s, /* target state */
                {
                    Q_ACTION_CAST(&Calc_operand1_x), /* exit */
                    Q_ACTION_CAST(&Calc_ready_e), /* entry */
                    Q_ACTION_CAST(&Calc_begin_e), /* entry */
                    Q_ACTION_CAST(0) /* zero terminator */
                }
            };
            BSP_clear();
            status_ = QM_TRAN(&tatbl_);
            break;
        }
        /* ${SMs::Calc::SM::on::operand1::OPER} */
        case OPER_SIG: {
            static struct {
                QMState const *target;
                QActionHandler act[3];
            } const tatbl_ = { /* transition-action table */
                &Calc_opEntered_s, /* target state */
                {
                    Q_ACTION_CAST(&Calc_operand1_x), /* exit */
                    Q_ACTION_CAST(&Calc_opEntered_e), /* entry */
                    Q_ACTION_CAST(0) /* zero terminator */
                }
            };
            me->operand1 = BSP_get_value();
            me->operator = Q_EVT_CAST(CalcEvt)->key_code;
            status_ = QM_TRAN(&tatbl_);
            break;
        }
        /* ${SMs::Calc::SM::on::operand1::EQUALS} */
        case EQUALS_SIG: {
            static struct {
                QMState const *target;
                QActionHandler act[4];
            } const tatbl_ = { /* transition-action table */
                &Calc_result_s, /* target state */
                {
                    Q_ACTION_CAST(&Calc_operand1_x), /* exit */
                    Q_ACTION_CAST(&Calc_ready_e), /* entry */
                    Q_ACTION_CAST(&Calc_result_e), /* entry */
                    Q_ACTION_CAST(0) /* zero terminator */
                }
            };
            status_ = QM_TRAN(&tatbl_);
            break;
        }
        default: {
            status_ = QM_SUPER();
            break;
        }
    }
    return status_;
}
Exemple #4
0
/* ${SMs::Calc::SM::on::ready} */
static QState Calc_ready(Calc * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* ${SMs::Calc::SM::on::ready::DIGIT_0} */
        case DIGIT_0_SIG: {
            static struct {
                QMState const *target;
                QActionHandler act[4];
            } const tatbl_ = { /* transition-action table */
                &Calc_zero1_s, /* target state */
                {
                    Q_ACTION_CAST(&Calc_ready_x), /* exit */
                    Q_ACTION_CAST(&Calc_operand1_e), /* entry */
                    Q_ACTION_CAST(&Calc_zero1_e), /* entry */
                    Q_ACTION_CAST(0) /* zero terminator */
                }
            };
            BSP_clear();
            status_ = QM_TRAN(&tatbl_);
            break;
        }
        /* ${SMs::Calc::SM::on::ready::DIGIT_1_9} */
        case DIGIT_1_9_SIG: {
            static struct {
                QMState const *target;
                QActionHandler act[4];
            } const tatbl_ = { /* transition-action table */
                &Calc_int1_s, /* target state */
                {
                    Q_ACTION_CAST(&Calc_ready_x), /* exit */
                    Q_ACTION_CAST(&Calc_operand1_e), /* entry */
                    Q_ACTION_CAST(&Calc_int1_e), /* entry */
                    Q_ACTION_CAST(0) /* zero terminator */
                }
            };
            BSP_clear();
            BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
            status_ = QM_TRAN(&tatbl_);
            break;
        }
        /* ${SMs::Calc::SM::on::ready::POINT} */
        case POINT_SIG: {
            static struct {
                QMState const *target;
                QActionHandler act[4];
            } const tatbl_ = { /* transition-action table */
                &Calc_frac1_s, /* target state */
                {
                    Q_ACTION_CAST(&Calc_ready_x), /* exit */
                    Q_ACTION_CAST(&Calc_operand1_e), /* entry */
                    Q_ACTION_CAST(&Calc_frac1_e), /* entry */
                    Q_ACTION_CAST(0) /* zero terminator */
                }
            };
            BSP_clear();
            BSP_insert((int)'0');
            BSP_insert((int)'.');
            status_ = QM_TRAN(&tatbl_);
            break;
        }
        /* ${SMs::Calc::SM::on::ready::OPER} */
        case OPER_SIG: {
            static struct {
                QMState const *target;
                QActionHandler act[3];
            } const tatbl_ = { /* transition-action table */
                &Calc_opEntered_s, /* target state */
                {
                    Q_ACTION_CAST(&Calc_ready_x), /* exit */
                    Q_ACTION_CAST(&Calc_opEntered_e), /* entry */
                    Q_ACTION_CAST(0) /* zero terminator */
                }
            };
            me->operand1 = BSP_get_value();
            me->operator = Q_EVT_CAST(CalcEvt)->key_code;
            status_ = QM_TRAN(&tatbl_);
            break;
        }
        default: {
            status_ = QM_SUPER();
            break;
        }
    }
    return status_;
}
Exemple #5
0
/* ${SMs::Calc::SM::on::operand2} */
static QState Calc_operand2(Calc * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /* ${SMs::Calc::SM::on::operand2::CE} */
        case CE_SIG: {
            static struct {
                QMState const *target;
                QActionHandler act[3];
            } const tatbl_ = { /* transition-action table */
                &Calc_opEntered_s, /* target state */
                {
                    Q_ACTION_CAST(&Calc_operand2_x), /* exit */
                    Q_ACTION_CAST(&Calc_opEntered_e), /* entry */
                    Q_ACTION_CAST(0) /* zero terminator */
                }
            };
            BSP_clear();
            status_ = QM_TRAN(&tatbl_);
            break;
        }
        /* ${SMs::Calc::SM::on::operand2::EQUALS} */
        case EQUALS_SIG: {
            /* ${SMs::Calc::SM::on::operand2::EQUALS::[BSP_eval()]} */
            if (BSP_eval(me->operand1, me->operator, BSP_get_value())) {
                static struct {
                    QMState const *target;
                    QActionHandler act[4];
                } const tatbl_ = { /* transition-action table */
                    &Calc_result_s, /* target state */
                    {
                        Q_ACTION_CAST(&Calc_operand2_x), /* exit */
                        Q_ACTION_CAST(&Calc_ready_e), /* entry */
                        Q_ACTION_CAST(&Calc_result_e), /* entry */
                        Q_ACTION_CAST(0) /* zero terminator */
                    }
                };
                status_ = QM_TRAN(&tatbl_);
            }
            /* ${SMs::Calc::SM::on::operand2::EQUALS::[else]} */
            else {
                static struct {
                    QMState const *target;
                    QActionHandler act[3];
                } const tatbl_ = { /* transition-action table */
                    &Calc_error_s, /* target state */
                    {
                        Q_ACTION_CAST(&Calc_operand2_x), /* exit */
                        Q_ACTION_CAST(&Calc_error_e), /* entry */
                        Q_ACTION_CAST(0) /* zero terminator */
                    }
                };
                status_ = QM_TRAN(&tatbl_);
            }
            break;
        }
        /* ${SMs::Calc::SM::on::operand2::OPER} */
        case OPER_SIG: {
            /* ${SMs::Calc::SM::on::operand2::OPER::[BSP_eval()]} */
            if (BSP_eval(me->operand1, me->operator, BSP_get_value())) {
                static struct {
                    QMState const *target;
                    QActionHandler act[3];
                } const tatbl_ = { /* transition-action table */
                    &Calc_opEntered_s, /* target state */
                    {
                        Q_ACTION_CAST(&Calc_operand2_x), /* exit */
                        Q_ACTION_CAST(&Calc_opEntered_e), /* entry */
                        Q_ACTION_CAST(0) /* zero terminator */
                    }
                };
                status_ = QM_TRAN(&tatbl_);
            }
            /* ${SMs::Calc::SM::on::operand2::OPER::[else]} */
            else {
                static struct {
                    QMState const *target;
                    QActionHandler act[3];
                } const tatbl_ = { /* transition-action table */
                    &Calc_error_s, /* target state */
                    {
                        Q_ACTION_CAST(&Calc_operand2_x), /* exit */
                        Q_ACTION_CAST(&Calc_error_e), /* entry */
                        Q_ACTION_CAST(0) /* zero terminator */
                    }
                };
                status_ = QM_TRAN(&tatbl_);
            }
            break;
        }
        default: {
            status_ = QM_SUPER();
            break;
        }
    }
    return status_;
}
/*..........................................................................*/
QState Calc_operand2(Calc * const me, QEvt const * const e) {
    QState status;
    switch (e->sig) {
        case Q_ENTRY_SIG: {
            BSP_message("operand2-ENTRY;");
            status = Q_HANDLED();
            break;
        }
        case Q_EXIT_SIG: {
            BSP_message("operand2-EXIT;");
            status = Q_HANDLED();
            break;
        }
        case CE_SIG: {
            BSP_clear();
            status = Q_TRAN(&Calc_opEntered);
            break;
        }
        case OPER_SIG: {
            if (BSP_eval(me->operand1, me->operator, BSP_get_value())) {
                me->operand1 = BSP_get_value();
                me->operator = ((CalcEvt const *)e)->key_code;
                status = Q_TRAN(&Calc_opEntered);
            }
            else {
                status = Q_TRAN(&Calc_error);
            }
            break;
        }
        case EQUALS_SIG: {
            if (BSP_eval(me->operand1, me->operator, BSP_get_value())) {
                status = Q_TRAN(&Calc_result);
            }
            else {
                status = Q_TRAN(&Calc_error);
            }
            break;
        }
        case PERCENT_SIG: {
            double operand2 = 0.0;
            switch (me->operator) {
                case KEY_PLUS:
                case KEY_MINUS: {
                    operand2 = (me->operand1 * BSP_get_value())/100.0;
                    break;
                }
                case KEY_MULT:
                case KEY_DIVIDE: {
                    operand2 = BSP_get_value()/100.0;
                    break;
                }
            }

            if (BSP_eval(me->operand1, me->operator, operand2)) {
                status = Q_TRAN(&Calc_result);
            }
            else {
                status = Q_TRAN(&Calc_error);
            }
            break;
        }
        default: {
            status = Q_SUPER(&Calc_on);
            break;
        }
    }
    return status;
}