Owner manual

28 Using the NodeBuilder FX/PL Example
7. Right-click the RealTimeKeeper functional block’s Optional CPs folder and select Implement
Optional CP from the shortcut menu. The Implement Optional CP dialog appears.
8. Implement the nciUpdateRate configuration property. Name the new configuration property
cpRtcUpdRate. Set Initial Value to 3L.
9. Right-click the RealTimeKeeper functional block’s Implementation-specific NVs folder and
select Add NV from the shortcut menu. The Add NV to Functional Block dialog appears.
10. Add a SNVT_time_stamp network variable. Set the direction to Input. Name the new network
variable nviAlarmTime.
11. Right-click the RealTimeKeeper functional block’s Implementation-specific NVs folder and
select Add Implementation-specific NV from the shortcut menu. The Add NV dialog appears.
12. Add a SNVT_switch network variable. Set the direction to Output. Name the new network
variable nvoAlarmState.
13. Right-click the RealTimeKeeper functional block’s Implementation-specific NVs folder and
select Add NV from the shortcut menu. The Add NV to Functional Block dialog appears.
14. Add a SNVT_switch network variable. Set the direction to Input. Name the new network
variable nviAlarmAck.
15. Click Generate and Close.
16. Open the RealTimeKeeper.nc file from the Source Files folder and add the following code in
bold:
#define RTC_CORETICK 250L
mtimer rtc_coretick;
enum {
rtc_alarm_idle, rtc_alarm_armed, rtc_alarm_alarm
} eeprom rtc_alarmstate = rtc_alarm_idle;
//{{NodeBuilder Code Wizard Start
This code adds a core timer to the device, which is used to poll the Gizmo 4’s real-time clock
hardware on a regular interval. The RTC_CORETICK enumeration is used to control the state
engine within the alarm clock. The states are: alarm disabled, waiting for alarm condition, and
alarm currently on (awaiting acknowledgement).
Sending a value to the nviAlarmTime network variable specifies the alarm time. The second,
minute and hour fields of the network variable are used to input the alarm time. The date,
month, and year fields can be set to 0 to disable the alarm, or to any non-zero value to arm the
alarm clock.
17. Still in RealTimeKeeper.nc, add the following code in bold:
#endif //_HAS_INPUT_NV_
when (timer_expires(rtc_coretick)) {
SNVT_time_stamp current;
if (fblockNormalNotLockedOut(RealTimeKeeper::global_index)) {
GizmoGetTime(&current);
RealTimeKeeper::nvoTimeDate = current;
switch(rtc_alarmstate ) {
case rtc_alarm_idle:
// alarm is off
break;
case rtc_alarm_armed:
// waiting for alarm condition to occur
if ((current.second
== RealTimeKeeper::nviAlarmTime.second)
&& (current.minute
== RealTimeKeeper::nviAlarmTime.minute)