Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of StarterKit by
Diff: main.cpp
- Revision:
- 37:ee01f752524a
- Parent:
- 36:f8d96ff1dd1b
- Child:
- 38:532a0d929756
diff -r f8d96ff1dd1b -r ee01f752524a main.cpp --- a/main.cpp Wed Sep 21 15:42:01 2016 +0000 +++ b/main.cpp Wed Sep 21 18:03:43 2016 +0000 @@ -200,6 +200,7 @@ cin = mdm.getc(); if (isprint(cin)) { buff[len++] = (char)cin; + continue; } else if (('\r' == cin_last) && ('\n' == cin)) { break; @@ -664,6 +665,7 @@ int main() { int i; + int sendAttemps = 0; HTS221 hts221; pc.baud(115200); @@ -765,13 +767,10 @@ proximityData[i][0] = readings[0]; proximityData[i][1] = readings[1]; proximityData[i][2] = readings[2]; - if(abs(proximityData[i][0] - lastProximityData[i][0]) > 5) + if(abs(proximityData[i][0] - lastProximityData[i][0]) > 50) { proximityChange = true; - } - lastProximityData[i][0] = proximityData[i][0]; - - + } } @@ -791,8 +790,14 @@ // If any non-zero response from server, make it GREEN one-time // then the actual FLOW responses will set the color. if (MySocketData.length() > 0) - { + { + SetLedColor(0x2); // green + //only copy on sucessful send + for(int i = 0;i<NUM_PROXIMIY_SENSORS;i++) + { + lastProximityData[i][0] = proximityData[i][0]; + } printf(BLU "Read back : %s" DEF "\r\n", &MySocketData[0]); char myJsonResponse[512]; if (extract_JSON(&MySocketData[0], &myJsonResponse[0])) @@ -810,7 +815,17 @@ else { SetLedColor(0x1); //red - system_reset(); + // reset socket if read fails + if(sendAttemps < 2) + { + sendAttemps++; + sockclose_mdm(); + sockopen_mdm(); + } + else // give up and do full reset + { + system_reset(); + } }