This is my final project for UCSC Extension - USB Programming. It is a home monitoring program for motion and temperature and requires host-side code.
Dependencies: C12832_lcd HomeMon LM75B MMA7660 USBDevice mbed
Diff: main.cpp
- Revision:
- 2:f6a1f96dc3cd
- Parent:
- 0:977f7cf68014
- Child:
- 3:21245644a2e3
--- a/main.cpp Sun Sep 01 23:43:10 2013 +0000 +++ b/main.cpp Tue Sep 03 08:55:16 2013 +0000 @@ -55,7 +55,7 @@ DigitalOut connectionLED(LED1); DigitalOut motionLED(LED2); DigitalOut tempHiLED(LED3); -DigitalOut tempLoLED(LED3); +DigitalOut tempLoLED(LED4); // Global State int state; @@ -79,6 +79,7 @@ // FIXME - for debug lcd.cls(); lcd.locate(0,3); + lcd.printf("Motion detected - sending alert!\n"); lcd.printf("x = %.2f y = %.2f z = %.2f\n", delta.x, delta.y, delta.z); return true; @@ -152,6 +153,9 @@ if (state == monDISCONNECTED) { if (check_connection()) { connectionLED = 1; + lcd.cls(); + lcd.locate(0,3); + lcd.printf("Connected to Host\n"); state = monCONNECTED; if (alertState.pendMotion) { alertState.pendMotion = false; @@ -159,14 +163,17 @@ } else if (alertState.pendTempHi) { alertState.pendTempHi = false; - send_alert(MOTION); + send_alert(TEMP_HI); } else if (alertState.pendTempLo) { alertState.pendTempLo = false; - send_alert(MOTION); + send_alert(TEMP_LOW); } } else { + lcd.cls(); + lcd.locate(0,3); + lcd.printf("Not Connected to Host\n"); connectionLED = 0; } } @@ -212,6 +219,9 @@ theTemp = get_temp(); if (theTemp > myTemp.get_max()) { if (sysMonTime.read() > (lastTempAlertSecs + TempAlertWaitSecs)) { + lcd.cls(); + lcd.locate(0,3); + lcd.printf("TEMP ALERT %.2f over %.2f - sending alert!\n", theTemp, myTemp.get_max()); tempHiLED = 1; if (state == monCONNECTED) { send_alert(TEMP_HI); @@ -226,6 +236,9 @@ } else if (theTemp < myTemp.get_min()) { if (sysMonTime.read() > (lastTempAlertSecs + TempAlertWaitSecs)) { + lcd.cls(); + lcd.locate(0,3); + lcd.printf("TEMP ALERT %.2f under %.2f - sending alert!\n", theTemp, myTemp.get_min()); tempLoLED = 1; if (state == monCONNECTED) { send_alert(TEMP_LOW); @@ -241,7 +254,7 @@ // See if it is time to store the temperature samples if (sysMonTime.read_ms()/MS_IN_SEC > (lastTimeMS + myTemp.get_period())) { - lcd.printf("time to send temperature\n"); + // DEBUG lcd.printf("time to send temperature\n"); lastTimeMS = sysMonTime.read_ms()/MS_IN_SEC; myTemp.add_sample(get_temp()); }