AN: Capstone Dive Computer Example - Quantum Leaps
AN: Capstone Dive Computer Example - Quantum Leaps
AN: Capstone Dive Computer Example - Quantum Leaps
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Application Note:<br />
<strong>Capstone</strong> <strong>Dive</strong> <strong>Computer</strong> <strong>Example</strong><br />
www.state-machine.com<br />
(2) B1_DOWN_SIG = Q_USER_SIG, /**< button B1 depressed */<br />
B1_UP_SIG,<br />
B2_DOWN_SIG,<br />
/**< button B1 released */<br />
/**< button B2 depressed */<br />
B2_UP_SIG, /**< button B2 released */<br />
(3) MAX_PUB_SIG, /**< the last published signal */<br />
ASCENT_RATE_ADC_SIG, /**< raw ascent rate ADC reading */<br />
HEARTBEAT_SIG, /**< heartbeat of the <strong>Capstone</strong> scuba diving computer */<br />
DT_TTS_SIG, /**< signal to alternate dive time/time to surface display */<br />
ALARM_REQUEST_SIG,<br />
ALARM_SILENCE_SIG,<br />
/**< alarm request to AlarmMgr */<br />
/**< alarm silence to AlarmMgr */<br />
TIMEOUT_SIG, /**< timeout for playing a note in AlarmMgr */<br />
(4) MAX_SIG /**< the last signal */<br />
};<br />
(5) typedef struct ADCEvtTag {<br />
(6) QEvent super; /* derives from QEvent */<br />
(7) uint16_t raw; /* raw ADC reading */<br />
} ADCEvt;<br />
(8) typedef struct AlarmEvtTag {<br />
QEvent super; /* derives from QEvent */<br />
(9) uint8_t alarm_type; /* alarm type */<br />
} AlarmEvt;<br />
(10) enum AlarmTypes { /* arranged in ascending order of alarm priority */<br />
ALL_ALARMS,<br />
DEPTH_ALARM,<br />
ASCENT_RATE_ALARM,<br />
OUT_OF_AIR_ALARM,<br />
MAX_ALARM /* keep always last */<br />
};<br />
/*..........................................................................*/<br />
(11) void <strong>Capstone</strong>_ctor(void);<br />
(12) void AlarmMgr_ctor(void);<br />
(13) extern QActive * const AO_<strong>Capstone</strong>; /* "opaque" pointer to <strong>Capstone</strong> AO */<br />
(14) extern QActive * const AO_AlarmMgr; /* "opaque" pointer to AlarmMgr AO */<br />
#endif /* capstone_h */<br />
Listing 1 Signals and events used in the <strong>Dive</strong> <strong>Computer</strong> (file capstone.h)<br />
(1) For smaller applications, such as the <strong>Dive</strong> <strong>Computer</strong>, all signals can be defined in one enumeration<br />
(rather than in separate enumerations or, worse, as preprocessor #define macros). An<br />
enumeration automatically guarantees the uniqueness of signals.<br />
(2) Note that the user signals must start with the offset Q_USER_SIG to avoid overlapping the reserved<br />
QEP signals.<br />
(3) The globally published signals are grouped at top of the enumeration. The MAX_PUB_SIG enumeration<br />
automatically keeps track of the maximum published signals in the application.<br />
(4) The MAX_SIG enumeration automatically keeps track of the total number of signals used in the<br />
application.<br />
(5-7) Every event with parameters, such as the ADCEvt derives from the QEvent base structure.<br />
Any number of event parameters can be added after the first member super (see also the sidebar<br />
below).<br />
Copyright © <strong>Quantum</strong> <strong>Leaps</strong>, LLC. All Rights Reserved.<br />
10 of 29