endpoint including temperature and distance sensors
Dependencies: mbed mbedConnectorInterface mbedEndpointNetwork TrashSensors
Fork of TempAndDistTest by
main.cpp@4:1ca75e77ae33, 2015-05-02 (annotated)
- Committer:
- coyotebush
- Date:
- Sat May 02 01:36:41 2015 +0000
- Revision:
- 4:1ca75e77ae33
- Parent:
- 2:b51fcb5fd114
- Child:
- 6:bbea44df21e8
cleanup
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Luminoscity | 0:cb422b231ea5 | 1 | #include "mbed.h" |
coyotebush | 2:b51fcb5fd114 | 2 | #include "EthernetInterface.h" |
coyotebush | 2:b51fcb5fd114 | 3 | #include "ConnectorEndpoint.h" |
coyotebush | 2:b51fcb5fd114 | 4 | #include "OptionsBuilder.h" |
coyotebush | 2:b51fcb5fd114 | 5 | |
Luminoscity | 0:cb422b231ea5 | 6 | #include "hcsr04.h" |
Luminoscity | 0:cb422b231ea5 | 7 | #include "GroveTemp.h" |
coyotebush | 2:b51fcb5fd114 | 8 | #include "OnBoardLED.h" |
Luminoscity | 0:cb422b231ea5 | 9 | |
coyotebush | 2:b51fcb5fd114 | 10 | #include "StaticResource.h" |
coyotebush | 2:b51fcb5fd114 | 11 | |
coyotebush | 2:b51fcb5fd114 | 12 | /* Terminal connection */ |
coyotebush | 2:b51fcb5fd114 | 13 | RawSerial term(USBTX, USBRX); |
coyotebush | 2:b51fcb5fd114 | 14 | Logger logger(&term); |
coyotebush | 2:b51fcb5fd114 | 15 | |
coyotebush | 2:b51fcb5fd114 | 16 | /* Sensors */ |
Luminoscity | 0:cb422b231ea5 | 17 | #define TRIG_PIN D6 |
Luminoscity | 0:cb422b231ea5 | 18 | #define ECHO_PIN D7 |
Luminoscity | 0:cb422b231ea5 | 19 | #define FIRE_THRESH 32.0 |
coyotebush | 2:b51fcb5fd114 | 20 | HCSR04 distS(TRIG_PIN, ECHO_PIN); |
coyotebush | 2:b51fcb5fd114 | 21 | GroveTempSensor tempS; |
Luminoscity | 0:cb422b231ea5 | 22 | |
coyotebush | 2:b51fcb5fd114 | 23 | /* Resources */ |
coyotebush | 2:b51fcb5fd114 | 24 | StaticResource mfg(&logger, "3/0/0", "Freescale"); |
coyotebush | 2:b51fcb5fd114 | 25 | StaticResource model(&logger, "3/0/1", "K64F mbed Ethernet demo"); |
coyotebush | 2:b51fcb5fd114 | 26 | |
coyotebush | 2:b51fcb5fd114 | 27 | /* |
coyotebush | 4:1ca75e77ae33 | 28 | DistanceResource distR(&logger, "3302/0/5600", distS); |
coyotebush | 2:b51fcb5fd114 | 29 | TemperatureResource tempR(&logger, "3303/0/5700", tempS); |
coyotebush | 2:b51fcb5fd114 | 30 | */ |
coyotebush | 2:b51fcb5fd114 | 31 | LEDResource led(&logger, "3311/1/5706"); |
Luminoscity | 0:cb422b231ea5 | 32 | |
coyotebush | 2:b51fcb5fd114 | 33 | /* invoked through linker magic via Endpoint::start() */ |
coyotebush | 2:b51fcb5fd114 | 34 | Connector::Options *configure_endpoint(Connector::OptionsBuilder &config) |
coyotebush | 2:b51fcb5fd114 | 35 | { |
coyotebush | 4:1ca75e77ae33 | 36 | /* NSP configuration is in nsp_configuration.h */ |
coyotebush | 2:b51fcb5fd114 | 37 | logger.log("configure_endpoint: building endpoint configuration..."); |
coyotebush | 2:b51fcb5fd114 | 38 | return config.addResource(&mfg) |
coyotebush | 2:b51fcb5fd114 | 39 | .addResource(&model) |
coyotebush | 2:b51fcb5fd114 | 40 | /* .addResource(&distR) */ |
coyotebush | 2:b51fcb5fd114 | 41 | /* .addResource(&tempR) */ |
coyotebush | 2:b51fcb5fd114 | 42 | .addResource(&led) |
coyotebush | 2:b51fcb5fd114 | 43 | .build(); |
coyotebush | 2:b51fcb5fd114 | 44 | } |
coyotebush | 2:b51fcb5fd114 | 45 | |
Luminoscity | 0:cb422b231ea5 | 46 | int main() { |
coyotebush | 2:b51fcb5fd114 | 47 | double temperature; |
Luminoscity | 0:cb422b231ea5 | 48 | unsigned int distance; |
coyotebush | 2:b51fcb5fd114 | 49 | |
coyotebush | 2:b51fcb5fd114 | 50 | logger.log("\r\n\r\nSmart Trash Can booting\r\n"); |
coyotebush | 2:b51fcb5fd114 | 51 | Connector::Endpoint::plumbNetwork(); |
coyotebush | 2:b51fcb5fd114 | 52 | Connector::Endpoint::start(); |
coyotebush | 4:1ca75e77ae33 | 53 | // actually, we never reach here because the Endpoint takes over |
Luminoscity | 0:cb422b231ea5 | 54 | |
Luminoscity | 0:cb422b231ea5 | 55 | while (1) { |
Luminoscity | 0:cb422b231ea5 | 56 | temperature = tempS.getTemp() * 3.0 / 5.0; |
coyotebush | 2:b51fcb5fd114 | 57 | logger.logIt("Temp: %0.1f\n\r", temperature); |
Luminoscity | 0:cb422b231ea5 | 58 | if (temperature > FIRE_THRESH) { |
coyotebush | 2:b51fcb5fd114 | 59 | logger.logIt(" OMG! THE TRASH CAN CAN IS TOTALLY ON FIRE!!\n\r"); |
Luminoscity | 0:cb422b231ea5 | 60 | } |
Luminoscity | 0:cb422b231ea5 | 61 | |
Luminoscity | 0:cb422b231ea5 | 62 | distS.start(); |
Luminoscity | 0:cb422b231ea5 | 63 | wait_ms(500); |
Luminoscity | 0:cb422b231ea5 | 64 | distance = distS.get_dist_cm(); |
coyotebush | 2:b51fcb5fd114 | 65 | logger.logIt("Distance: %d\n\r", distance); |
Luminoscity | 0:cb422b231ea5 | 66 | } |
coyotebush | 2:b51fcb5fd114 | 67 | } |