@@ -19,6 +19,7 @@ void handleBroadcastMessage(BroadcastData& bd, uintptr_t data);
19
19
void handleAntError (uint8_t code, uintptr_t data);
20
20
void handleStartUpMessage (StartUpMessage& sum, uintptr_t data);
21
21
void handleChannelEventResponse (ChannelEventResponse& cer, uintptr_t data);
22
+ bool itsAlive (StartUpMessage& sm, uintptr_t data);
22
23
23
24
void setup ()
24
25
{
@@ -29,6 +30,7 @@ void setup()
29
30
ChannelPeriod cp;
30
31
ChannelRfFrequency crf;
31
32
OpenChannel oc;
33
+ StartUpMessage sm;
32
34
33
35
Serial1.begin (BAUD_RATE);
34
36
ant.onBroadcastData (handleBroadcastMessage);
@@ -37,24 +39,39 @@ void setup()
37
39
ant.onChannelEventResponse (handleChannelEventResponse);
38
40
ant.onOtherResponse (handleMessageWithNoCallback);
39
41
ant.begin (Serial1);
40
- ant.send (rs);
41
- // Delay after resetting the radio to give the user time to connect on serial
42
- delay (10000 );
42
+
43
43
Serial.begin (9600 );
44
+ delay (10000 );
45
+ // Delay to give the user time to connect on serial
46
+
44
47
Serial.println (" Running" );
45
48
49
+ ant.send (rs);
50
+ ant.waitFor (sm, 2000 , itsAlive); // wait 2s for device to start
51
+
46
52
snk = SetNetworkKey ();
47
53
snk.setNetwork (0 );
48
54
snk.setKey ((uint8_t *)NETWORK_KEY);
49
55
ant.send (snk);
50
- ant.loop ();
56
+ if (ant.waitForStatus (snk.getMsgId (), 1000 )) {
57
+ Serial.println (" No Response for setting network key" );
58
+ } else {
59
+ ChannelEventResponse cer = ChannelEventResponse ();
60
+ ant.getResponse ().getChannelEventResponseMsg (cer);
61
+ handleChannelEventResponse (cer, 0 );
62
+ }
51
63
52
64
ac = AssignChannel ();
53
65
ac.setChannel (0 );
54
66
ac.setChannelType (CHANNEL_TYPE_BIDIRECTIONAL_RECEIVE); // can't wildcard this
55
67
ac.setChannelNetwork (0 );
56
- ant.send (ac);
57
- ant.loop ();
68
+ if (ant.sendAndWait (ac, 2000 )) {
69
+ Serial.println (" No Response for assigning channel" );
70
+ } else {
71
+ ChannelEventResponse cer = ChannelEventResponse ();
72
+ ant.getResponse ().getChannelEventResponseMsg (cer);
73
+ handleChannelEventResponse (cer, 0 );
74
+ }
58
75
59
76
ci = ChannelId ();
60
77
ci.setChannel (0 );
@@ -145,3 +162,8 @@ void handleChannelEventResponse(ChannelEventResponse& cer, uintptr_t data) {
145
162
break ;
146
163
}
147
164
}
165
+
166
+ bool itsAlive (StartUpMessage& sm, uintptr_t data) {
167
+ Serial.println (" Radio Reset!" );
168
+ return true ;
169
+ }
0 commit comments