mirror of
https://github.com/QuantumLeaps/qpcpp.git
synced 2025-01-28 06:02:56 +08:00
640 lines
20 KiB
XML
640 lines
20 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<model version="4.5.0" links="0">
|
|
<documentation>Improved model of the Calculator described in Chapter 4 of PSiCC2. Improvements include:
|
|
|
|
- using "no me->" pointer implementation
|
|
- placing the "negated1" state inside "operand1" superstate
|
|
- placing the "negated2" state inside "operand2" superstate
|
|
- adding handling of operator precedence '*','/' before '+','-'</documentation>
|
|
<framework name="qpcpp"/>
|
|
<package name="Events" stereotype="0x01">
|
|
<class name="CalcEvt" superclass="qpcpp::QEvt">
|
|
<attribute name="key_code" type="uint8_t" visibility="0x00" properties="0x00"/>
|
|
</class>
|
|
</package>
|
|
<package name="SMs" stereotype="0x02">
|
|
<class name="Calc" superclass="qpcpp::QHsm">
|
|
<documentation>Calculator state machine</documentation>
|
|
<attribute name="inst" type="Calc" visibility="0x00" properties="0x01">
|
|
<documentation>The only inst of the Calc object (Singleton pattern).</documentation>
|
|
</attribute>
|
|
<attribute name="m_op1" type="double" visibility="0x02" properties="0x00"/>
|
|
<attribute name="m_op2" type="double" visibility="0x02" properties="0x00"/>
|
|
<attribute name="m_oper1" type="uint8_t" visibility="0x02" properties="0x00"/>
|
|
<attribute name="m_oper2" type="uint8_t" visibility="0x02" properties="0x00"/>
|
|
<operation name="Calc" type="" visibility="0x00" properties="0x00">
|
|
<documentation>constructor</documentation>
|
|
<code> : QHsm(Q_STATE_CAST(&Calc::initial))</code>
|
|
</operation>
|
|
<operation name="eval" type="bool" visibility="0x00" properties="0x00">
|
|
<documentation>// guard function to evaluate the current expression
|
|
// taking into account the precedence of operands.
|
|
// return: true if evaluation successfull
|
|
// false when error encountered</documentation>
|
|
<parameter name="op" type="double"/>
|
|
<parameter name="oper" type="uint8_t"/>
|
|
<code>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;</code>
|
|
</operation>
|
|
<statechart properties="0x02">
|
|
<initial target="../1">
|
|
<action>BSP_clear();
|
|
(void)e; /* unused parameter */</action>
|
|
<initial_glyph conn="2,2,5,1,92,4,-2">
|
|
<action box="1,-2,13,4"/>
|
|
</initial_glyph>
|
|
</initial>
|
|
<state name="on">
|
|
<entry>BSP_message("on-ENTRY;");</entry>
|
|
<exit>BSP_message("on-EXIT;");</exit>
|
|
<initial target="../3">
|
|
<action>BSP_message("on-INIT;");</action>
|
|
<initial_glyph conn="15,9,5,1,45,9,-2">
|
|
<action box="1,0,5,2"/>
|
|
</initial_glyph>
|
|
</initial>
|
|
<tran trig="C" target="..">
|
|
<action>BSP_clear();</action>
|
|
<tran_glyph conn="2,12,3,1,90">
|
|
<action box="0,-2,4,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="OFF" target="../../2">
|
|
<tran_glyph conn="2,14,3,1,92,104,-75">
|
|
<action box="0,0,5,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state name="ready">
|
|
<entry>BSP_message("ready-ENTRY;");
|
|
m_oper2 = KEY_NULL;</entry>
|
|
<exit>BSP_message("ready-EXIT;");</exit>
|
|
<initial target="../5">
|
|
<action>BSP_message("ready-INIT;");</action>
|
|
<initial_glyph conn="18,20,5,0,20,2">
|
|
<action box="0,-2,6,2"/>
|
|
</initial_glyph>
|
|
</initial>
|
|
<tran trig="DIGIT_0" target="../../4/3">
|
|
<action>BSP_clear();</action>
|
|
<tran_glyph conn="18,34,2,0,11">
|
|
<action box="1,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="DIGIT_1_9" target="../../4/4">
|
|
<action>BSP_clear();
|
|
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="32,34,2,0,11">
|
|
<action box="1,0,9,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="POINT" target="../../4/5">
|
|
<action>BSP_clear();
|
|
BSP_insert((int)'0');
|
|
BSP_insert((int)'.');</action>
|
|
<tran_glyph conn="52,34,2,0,11">
|
|
<action box="0,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="OPER" target="../../5">
|
|
<action>m_op1 = BSP_get_value();
|
|
m_oper1 = Q_EVT_CAST(CalcEvt)->key_code;</action>
|
|
<tran_glyph conn="58,24,1,1,32,48,-32">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state name="begin">
|
|
<entry>BSP_message("begin-ENTRY;");</entry>
|
|
<exit>BSP_message("begin-EXIT;");</exit>
|
|
<tran trig="OPER">
|
|
<choice target="../../../../4/6">
|
|
<guard brief="e->key == '-'">Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS</guard>
|
|
<choice_glyph conn="40,30,5,0,34,15">
|
|
<action box="1,0,11,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<choice>
|
|
<guard>else</guard>
|
|
<choice_glyph conn="40,30,4,-1,-4,4">
|
|
<action box="1,-3,6,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<tran_glyph conn="30,30,3,-1,10">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="30,22,16,10">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="result">
|
|
<entry>BSP_message("result-ENTRY;");</entry>
|
|
<exit>BSP_message("result-EXIT;");</exit>
|
|
<state_glyph node="14,22,10,10">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state_glyph node="8,16,50,18">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="operand1">
|
|
<entry>BSP_message("operand1-ENTRY;");</entry>
|
|
<exit>BSP_message("operand1-EXIT;");</exit>
|
|
<tran trig="CE" target="../../3/5">
|
|
<action>BSP_clear();</action>
|
|
<tran_glyph conn="26,38,0,3,-14,4">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="OPER" target="../../5">
|
|
<action>m_op1 = BSP_get_value();
|
|
m_oper1 = Q_EVT_CAST(CalcEvt)->key_code;</action>
|
|
<tran_glyph conn="60,64,2,1,6,-2">
|
|
<action box="1,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="EQUALS" target="../../3/6">
|
|
<tran_glyph conn="10,38,0,3,-12,4">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state name="zero1">
|
|
<entry>BSP_message("zero1-ENTRY;");</entry>
|
|
<exit>BSP_message("zero1-EXIT;");</exit>
|
|
<tran trig="DIGIT_0">
|
|
<action>;</action>
|
|
<tran_glyph conn="12,56,3,-1,10">
|
|
<action box="0,-2,7,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="DIGIT_1_9" target="../../4">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="12,53,3,3,16,-6,2">
|
|
<action box="0,-2,9,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="POINT" target="../../5">
|
|
<action>BSP_insert((int)'0');
|
|
BSP_insert((int)'.');</action>
|
|
<tran_glyph conn="14,58,2,2,2,40,-2">
|
|
<action box="1,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="12,45,14,13">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="int1">
|
|
<entry>BSP_message("int1-ENTRY;");</entry>
|
|
<exit>BSP_message("int1-EXIT;");</exit>
|
|
<tran trig="POINT" target="../../5">
|
|
<action>BSP_insert((int)'.');</action>
|
|
<tran_glyph conn="30,53,3,3,16,-6,2">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="DIGIT_0, DIGIT_1_9">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="30,56,3,-1,10">
|
|
<action box="0,-2,14,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="30,45,14,13">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="frac1">
|
|
<entry>BSP_message("frac1-ENTRY;");</entry>
|
|
<exit>BSP_message("frac1-EXIT;");</exit>
|
|
<tran trig="POINT">
|
|
<action>;</action>
|
|
<tran_glyph conn="48,56,3,-1,10">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="DIGIT_0, DIGIT_1_9">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="48,53,3,-1,10">
|
|
<action box="0,-2,15,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="48,45,14,13">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="negated1">
|
|
<entry>BSP_message("negated1-ENTRY;");
|
|
BSP_negate();</entry>
|
|
<exit>BSP_message("negated1-EXIT;");</exit>
|
|
<tran trig="DIGIT_0" target="../../3">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="66,57,2,2,4,-44,-3">
|
|
<action box="0,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="DIGIT_1_9" target="../../4">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="73,57,2,2,5,-35,-4">
|
|
<action box="0,0,9,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="POINT" target="../../5">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="81,57,2,2,6,-25,-5">
|
|
<action box="1,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="OPER">
|
|
<choice>
|
|
<guard>else</guard>
|
|
<choice_glyph conn="74,53,4,-1,-4,8">
|
|
<action box="1,-4,6,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<choice>
|
|
<guard brief="e->key == '-'">Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS</guard>
|
|
<action>;</action>
|
|
<choice_glyph conn="74,53,5,-1,8">
|
|
<action box="1,0,11,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<tran_glyph conn="64,53,3,-1,10">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="64,45,22,12">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state_glyph node="8,38,80,26">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="opEntered">
|
|
<entry>BSP_message("opEntered-ENTRY;");</entry>
|
|
<exit>BSP_message("opEntered-EXIT;");</exit>
|
|
<tran trig="DIGIT_0" target="../../6/3">
|
|
<action>BSP_clear();</action>
|
|
<tran_glyph conn="27,82,2,0,2,-5,9">
|
|
<action box="1,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="DIGIT_1_9" target="../../6/4">
|
|
<action>BSP_clear();
|
|
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="34,82,2,0,11">
|
|
<action box="1,0,9,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="POINT" target="../../6/5">
|
|
<action>BSP_clear();
|
|
BSP_insert((int)'0');
|
|
BSP_insert((int)'.');</action>
|
|
<tran_glyph conn="52,82,2,0,11">
|
|
<action box="0,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="OPER">
|
|
<choice target="../../../6/6">
|
|
<guard brief="e->key == '-'">Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS</guard>
|
|
<choice_glyph conn="34,78,5,0,40,15">
|
|
<action box="1,0,11,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<choice>
|
|
<guard>else</guard>
|
|
<choice_glyph conn="34,78,4,-1,-4,4">
|
|
<action box="1,-3,6,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<tran_glyph conn="26,78,3,-1,8">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="26,68,32,14">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="operand2">
|
|
<entry>BSP_message("operand2-ENTRY;");</entry>
|
|
<exit>BSP_message("operand2-EXIT;");</exit>
|
|
<tran trig="CE" target="../../5">
|
|
<action>BSP_clear();</action>
|
|
<tran_glyph conn="16,86,0,3,-5,8,-5,2">
|
|
<action box="0,-4,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="EQUALS">
|
|
<choice target="../../../7">
|
|
<guard brief="else"/>
|
|
<choice_glyph conn="4,70,5,3,7">
|
|
<action box="1,0,6,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<choice target="../../../3/6">
|
|
<guard brief="eval()">eval(BSP_get_value(), KEY_NULL)</guard>
|
|
<choice_glyph conn="4,70,4,3,-46,10">
|
|
<action box="0,-4,10,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<tran_glyph conn="8,102,3,-1,-4,-32">
|
|
<action box="-4,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="OPER">
|
|
<choice target="../../../7">
|
|
<guard brief="else"/>
|
|
<choice_glyph conn="6,79,4,3,-5,5">
|
|
<action box="0,-5,6,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<choice target="../../../5">
|
|
<guard brief="eval()">eval(BSP_get_value(), Q_EVT_CAST(CalcEvt)->key_code)</guard>
|
|
<choice_glyph conn="6,79,5,3,16,-5,4">
|
|
<action box="1,0,12,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<tran_glyph conn="8,98,3,-1,-2,-19">
|
|
<action box="-4,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state name="zero2">
|
|
<entry>BSP_message("zero2-ENTRY;");</entry>
|
|
<exit>BSP_message("zero2-EXIT;");</exit>
|
|
<tran trig="DIGIT_0">
|
|
<action>;</action>
|
|
<tran_glyph conn="12,104,3,-1,10">
|
|
<action box="0,-2,7,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="DIGIT_1_9" target="../../4">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="12,101,3,3,16,-6,2">
|
|
<action box="0,-2,9,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="POINT" target="../../5">
|
|
<action>BSP_insert((int)'0');
|
|
BSP_insert((int)'.');</action>
|
|
<tran_glyph conn="14,106,2,2,2,40,-2">
|
|
<action box="1,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="12,93,14,13">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="int2">
|
|
<entry>BSP_message("int2-ENTRY;");</entry>
|
|
<exit>BSP_message("int2-EXIT;");</exit>
|
|
<tran trig="POINT" target="../../5">
|
|
<action>BSP_insert((int)'.');</action>
|
|
<tran_glyph conn="30,101,3,3,16,-6,2">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="DIGIT_0, DIGIT_1_9">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="30,104,3,-1,10">
|
|
<action box="0,-2,14,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="30,93,14,13">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="frac2">
|
|
<entry>BSP_message("frac2-ENTRY;");</entry>
|
|
<exit>BSP_message("frac2-EXIT;");</exit>
|
|
<tran trig="POINT">
|
|
<action>;</action>
|
|
<tran_glyph conn="48,104,3,-1,10">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="DIGIT_0, DIGIT_1_9">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="48,101,3,-1,10">
|
|
<action box="0,-2,15,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="48,93,14,13">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="negated2">
|
|
<entry>BSP_message("negated2-ENTRY;");
|
|
BSP_negate();</entry>
|
|
<exit>BSP_message("negated2-EXIT;");</exit>
|
|
<tran trig="DIGIT_0" target="../../3">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="66,105,2,2,4,-44,-3">
|
|
<action box="0,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="DIGIT_1_9" target="../../4">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="73,105,2,2,5,-37,-4">
|
|
<action box="0,0,9,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="POINT" target="../../5">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="81,105,2,2,6,-25,-5">
|
|
<action box="1,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="OPER">
|
|
<choice>
|
|
<guard>else</guard>
|
|
<choice_glyph conn="74,102,4,-1,-4,8">
|
|
<action box="1,-4,6,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<choice>
|
|
<guard brief="e->key == '-'">Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS</guard>
|
|
<action>;</action>
|
|
<choice_glyph conn="74,102,5,-1,8">
|
|
<action box="1,0,11,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<tran_glyph conn="64,102,3,-1,10">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="64,93,22,12">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state_glyph node="8,86,80,26">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="error">
|
|
<entry>BSP_message("error-ENTRY;");</entry>
|
|
<exit>BSP_message("error-EXIT;");</exit>
|
|
<state_glyph node="11,68,9,8">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state_glyph node="2,4,90,110">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="final">
|
|
<entry>BSP_message("final-ENTRY;");
|
|
BSP_exit();</entry>
|
|
<state_glyph node="2,116,17,6">
|
|
<entry box="1,2,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state_diagram size="96,124"/>
|
|
</statechart>
|
|
</class>
|
|
<attribute name="the_calc" type="QP::QHsm * const" visibility="0x00" properties="0x00">
|
|
<documentation>Global opaque pointer to the Calc inst</documentation>
|
|
<code>= &Calc::inst;</code>
|
|
</attribute>
|
|
</package>
|
|
<directory name=".">
|
|
<file name="calc1.h">
|
|
<text>#ifndef calc1_h
|
|
#define calc1_h
|
|
|
|
enum CalcSignals {
|
|
C_SIG = QP::Q_USER_SIG,
|
|
CE_SIG,
|
|
DIGIT_0_SIG,
|
|
DIGIT_1_9_SIG,
|
|
POINT_SIG,
|
|
OPER_SIG,
|
|
EQUALS_SIG,
|
|
OFF_SIG
|
|
};
|
|
|
|
$declare${Events::CalcEvt}
|
|
|
|
$declare${SMs::the_calc}
|
|
|
|
#endif // calc1_h
|
|
</text>
|
|
</file>
|
|
<file name="calc1.cpp">
|
|
<text>#include "qpcpp.h" // QP/C++
|
|
#include "bsp.h" // board support package
|
|
#include "calc1.h" // application
|
|
|
|
Q_DEFINE_THIS_FILE
|
|
|
|
#define KEY_NULL '\0'
|
|
#define KEY_PLUS '+'
|
|
#define KEY_MINUS '-'
|
|
#define KEY_MULT '*'
|
|
#define KEY_DIVIDE '/'
|
|
|
|
$declare${SMs::Calc}
|
|
|
|
$define${SMs::the_calc}
|
|
$define(SMs::Calc)</text>
|
|
</file>
|
|
</directory>
|
|
</model>
|