Skip to content

Commit

Permalink
Only send calibration request messages during calibration mode
Browse files Browse the repository at this point in the history
  • Loading branch information
maniacbug committed Aug 21, 2013
1 parent ecff492 commit d17ff67
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions examples/sensornet/sensornet.pde
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void loop(void)
if ( temp_pin > -1 && ( ! Sleep || test_mode ) )
{
// if the received message is a test message, we can respond with a 'C' message in return
if ( header.type == 's' )
if ( header.type == 'c' )
{
// Take a reading
S_message response;
Expand All @@ -350,11 +350,11 @@ void loop(void)
// AND we have a temp sensor
// AND it's time to send a reading
// AND we're in the mode where we send readings...
if ( this_node.address > 0 && temp_pin > -1 && ( ( Sleep && ! test_mode ) || send_timer.wasFired() ) && ! calibration_mode && ! startup_leds )
if ( this_node.address > 0 && temp_pin > -1 && ( ( Sleep && ! test_mode ) || send_timer.wasFired() ) && ! startup_leds )
{
// Transmission beginning, TX LED ON
Yellow = true;
if ( test_mode )
if ( test_mode && ! calibration_mode )
{
Green = false;
Red = false;
Expand All @@ -366,19 +366,25 @@ void loop(void)

printf_P(PSTR("---------------------------------\n\r"));
printf_P(PSTR("%lu: APP Sending %s to 0%o...\n\r"),millis(),message.toString(),0);


char message_type = 'S';
if ( calibration_mode )
message_type = 'c';
else if (test_mode )
message_type = 't';

// Send it to the base (regular readings) or just to our parent (test mode)
RF24NetworkHeader header(/*to node*/ test_mode ? -1 : 0, /*type*/ test_mode ? 's' : 'S');
RF24NetworkHeader header(/*to node*/ test_mode ? -1 : 0, /*type*/ message_type);
bool ok = network.write(header,&message,sizeof(message));
if (ok)
{
if ( test_mode )
if ( test_mode && ! calibration_mode )
Green = true;
printf_P(PSTR("%lu: APP Send ok\n\r"),millis());
}
else
{
if ( test_mode )
if ( test_mode && ! calibration_mode )
Red = true;
printf_P(PSTR("%lu: APP Send failed\n\r"),millis());
}
Expand Down Expand Up @@ -414,6 +420,13 @@ void loop(void)
send_timer.setInterval(1000);
printf_P(PSTR("%lu: APP Start test mode\n\r"),millis());
}
else if ( calibration_mode )
{
calibration_mode = false;
test_mode = true;
calibration_leds.disable();
printf_P(PSTR("%lu: APP Stop calibration mode\n\r"),millis());
}
else if ( test_mode )
{
test_mode = false;
Expand All @@ -422,20 +435,14 @@ void loop(void)
send_timer.setInterval(8000);
printf_P(PSTR("%lu: APP Stop test mode\n\r"),millis());
}
else if ( calibration_mode )
{
calibration_mode = false;
test_mode = true;
calibration_leds.disable();
}
}

// Long press
if ( ButtonLong.wasPressed() && test_mode )
{
test_mode = false;
calibration_mode = true;
calibration_leds.reset();
printf_P(PSTR("%lu: APP Start calibration mode\n\r"),millis());
}

// Listen for a new node address
Expand Down

0 comments on commit d17ff67

Please sign in to comment.