Dreamforce 2014 Workshop RFID Case Generator - Completed Exercise
Dependencies: BufferedSerial C12832 EndpointMain-rfid EthernetInterface Logger StatusReporter-df2014 mbed-rtos mbed
Fork of df-2014-workshop-rfid-case-generator-k64f by
main.cpp@22:1b9e29933ab3, 2014-08-29 (annotated)
- Committer:
- ansond
- Date:
- Fri Aug 29 19:24:19 2014 +0000
- Revision:
- 22:1b9e29933ab3
- Parent:
- 20:f548e2de5b0b
- Child:
- 25:89a505a8e61c
updates for K64F support
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:df2aa79c64f2 | 1 | /* Copyright C2014 ARM, MIT License |
ansond | 0:df2aa79c64f2 | 2 | * |
ansond | 0:df2aa79c64f2 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 0:df2aa79c64f2 | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 0:df2aa79c64f2 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 0:df2aa79c64f2 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 0:df2aa79c64f2 | 7 | * furnished to do so, subject to the following conditions: |
ansond | 0:df2aa79c64f2 | 8 | * |
ansond | 0:df2aa79c64f2 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 0:df2aa79c64f2 | 10 | * substantial portions of the Software. |
ansond | 0:df2aa79c64f2 | 11 | * |
ansond | 0:df2aa79c64f2 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 0:df2aa79c64f2 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 0:df2aa79c64f2 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 0:df2aa79c64f2 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 0:df2aa79c64f2 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 0:df2aa79c64f2 | 17 | */ |
ansond | 0:df2aa79c64f2 | 18 | |
ansond | 13:2561e3855a81 | 19 | // StatusReporter |
ansond | 13:2561e3855a81 | 20 | #include "StatusReporter.h" |
ansond | 22:1b9e29933ab3 | 21 | |
ansond | 22:1b9e29933ab3 | 22 | // appboard LCD Panel |
ansond | 22:1b9e29933ab3 | 23 | #if _NXP_PLATFORM || _UBLOX_PLATFORM |
ansond | 22:1b9e29933ab3 | 24 | #include "C12832_lcd.h" |
ansond | 22:1b9e29933ab3 | 25 | C12832_LCD lcd; |
ansond | 22:1b9e29933ab3 | 26 | #endif |
ansond | 0:df2aa79c64f2 | 27 | |
ansond | 0:df2aa79c64f2 | 28 | // our Serial port |
ansond | 0:df2aa79c64f2 | 29 | #include "Serial.h" |
ansond | 0:df2aa79c64f2 | 30 | Serial pc(USBTX, USBRX); |
ansond | 0:df2aa79c64f2 | 31 | |
ansond | 3:03108e424931 | 32 | // Ethernet |
ansond | 3:03108e424931 | 33 | #include "EthernetInterface.h" |
ansond | 3:03108e424931 | 34 | EthernetInterface ethernet; |
ansond | 3:03108e424931 | 35 | |
ansond | 20:f548e2de5b0b | 36 | // HTTP |
ansond | 20:f548e2de5b0b | 37 | #include "HTTPClient.h" |
ansond | 20:f548e2de5b0b | 38 | HTTPClient http; |
ansond | 20:f548e2de5b0b | 39 | |
ansond | 6:427c387b10e7 | 40 | // HARD RESET |
ansond | 6:427c387b10e7 | 41 | extern "C" void HardFault_Handler() { NVIC_SystemReset(); } |
ansond | 6:427c387b10e7 | 42 | |
ansond | 0:df2aa79c64f2 | 43 | // Main Entry... |
ansond | 0:df2aa79c64f2 | 44 | int main() { |
ansond | 22:1b9e29933ab3 | 45 | // create our object instances |
ansond | 22:1b9e29933ab3 | 46 | #if _NXP_PLATFORM || _UBLOX_PLATFORM |
ansond | 13:2561e3855a81 | 47 | ErrorHandler logger(&pc,&lcd); |
ansond | 22:1b9e29933ab3 | 48 | #endif |
ansond | 22:1b9e29933ab3 | 49 | #if _K64F_PLATFORM |
ansond | 22:1b9e29933ab3 | 50 | ErrorHandler logger(&pc,NULL); |
ansond | 22:1b9e29933ab3 | 51 | #endif |
ansond | 0:df2aa79c64f2 | 52 | |
ansond | 0:df2aa79c64f2 | 53 | // announce |
ansond | 13:2561e3855a81 | 54 | logger.log("ARM/DreamForce 2014 mbed Status Reporter v%s",APP_VERSION); |
ansond | 19:341ce6a43a84 | 55 | logger.turnLEDBlue(); |
ansond | 0:df2aa79c64f2 | 56 | |
ansond | 3:03108e424931 | 57 | // initialize Ethernet |
ansond | 3:03108e424931 | 58 | logger.log("Initializing Ethernet..."); |
ansond | 3:03108e424931 | 59 | ethernet.init(); |
ansond | 0:df2aa79c64f2 | 60 | |
ansond | 3:03108e424931 | 61 | // get a DHCP address and bring the network interface up |
ansond | 3:03108e424931 | 62 | logger.log("Getting IP Address..."); |
ansond | 19:341ce6a43a84 | 63 | logger.turnLEDOrange(); |
ansond | 3:03108e424931 | 64 | if (ethernet.connect() == 0) { |
ansond | 3:03108e424931 | 65 | // log our IP address (DHCP) |
ansond | 3:03108e424931 | 66 | logger.log("IP Address: %s",ethernet.getIPAddress()); |
ansond | 3:03108e424931 | 67 | |
ansond | 13:2561e3855a81 | 68 | // create the StatusReporter |
ansond | 20:f548e2de5b0b | 69 | StatusReporter status_reporter(&logger,(void *)&http); |
ansond | 3:03108e424931 | 70 | |
ansond | 8:fefcecb66463 | 71 | // entering main loop |
ansond | 8:fefcecb66463 | 72 | logger.log("Entering Main Loop...\r\nScanning..."); |
ansond | 19:341ce6a43a84 | 73 | logger.turnLEDGreen(); |
ansond | 8:fefcecb66463 | 74 | |
ansond | 3:03108e424931 | 75 | // Enter the main loop |
ansond | 3:03108e424931 | 76 | while(true) { |
ansond | 13:2561e3855a81 | 77 | // check and report on status updates |
ansond | 13:2561e3855a81 | 78 | status_reporter.checkAndReportOnStatus(); |
ansond | 3:03108e424931 | 79 | |
ansond | 3:03108e424931 | 80 | // wait a bit and look again |
ansond | 3:03108e424931 | 81 | wait_ms(WAIT_TIME_MS); |
ansond | 3:03108e424931 | 82 | } |
ansond | 3:03108e424931 | 83 | } |
ansond | 3:03108e424931 | 84 | else { |
ansond | 3:03108e424931 | 85 | logger.log("No Network... Exiting..."); |
ansond | 19:341ce6a43a84 | 86 | logger.turnLEDRed(); |
ansond | 6:427c387b10e7 | 87 | exit(1); |
ansond | 3:03108e424931 | 88 | } |
ansond | 3:03108e424931 | 89 | |
ansond | 3:03108e424931 | 90 | // disconnect |
ansond | 4:46459ed734f3 | 91 | logger.log("Disconnecting..."); |
ansond | 19:341ce6a43a84 | 92 | logger.turnLEDOrange(); |
ansond | 3:03108e424931 | 93 | ethernet.disconnect(); |
ansond | 4:46459ed734f3 | 94 | |
ansond | 4:46459ed734f3 | 95 | // Exit |
ansond | 6:427c387b10e7 | 96 | logger.log("Exiting..."); |
ansond | 19:341ce6a43a84 | 97 | logger.turnLEDBlue(); |
ansond | 6:427c387b10e7 | 98 | exit(1); |
ansond | 0:df2aa79c64f2 | 99 | } |