MBED_DEMOS / Mbed 2 deprecated df-2014-rfid-case-gen-k64f-exercise

Dependencies:   BufferedSerial C12832 EndpointMain-rfid EthernetInterface Logger StatusReporter-df2014 mbed-rtos mbed

Fork of df-2014-workshop-rfid-case-generator-k64f by Doug Anson

Revision:
0:df2aa79c64f2
Child:
3:03108e424931
diff -r 000000000000 -r df2aa79c64f2 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Aug 23 20:17:18 2014 +0000
@@ -0,0 +1,91 @@
+/* Copyright C2014 ARM, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files the "Software", to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+ 
+ // our definitions
+ #include "Definitions.h"
+
+ // RFID Reader - on P14 pin 
+ #include "ID12RFID.h"
+ ID12RFID rfid_reader(p14); 
+
+ // Salesforce Case Generator
+ #include "SalesForceCaseGenerator.h"
+ 
+ // our Logger
+ #include "Logger.h"
+ 
+ // our WidgetDB
+ #include "WidgetDB.h"
+ 
+ // our LCD Panel
+ #include "C12832_lcd.h"
+ C12832_LCD lcd;
+ 
+ // our Serial port
+ #include "Serial.h"
+ Serial pc(USBTX, USBRX);
+ 
+ // Main Entry...
+ int main() {
+    // create our object instances
+    Logger logger(&pc,&lcd);
+    
+    // announce
+    logger.log("DF 2014 RFID Reader\r\nVersion: %s",APP_VERSION);
+    
+    // create the WidgetDB
+    WidgetDB db;
+    
+    // create the Salesforce Case Generator
+    SalesForceCaseGenerator case_generator(&logger);
+    
+    // Enter the main loop
+    while(true) {
+        // look for a readable RFID tag
+        if(rfid_reader.readable()) {
+            // capture the RFID id...
+            int rfid = rfid_reader.read();
+            logger.log("RFID: %d found...\r\nProcessing...",rfid);
+            
+            // look it up in our WidgetDB... proceed only if we find something we know about...
+            char *name = db.lookupWidgetName(rfid);
+            if (name != NULL) {
+                // build out a simple subject for the case
+                char subject[MAX_NAME_LENGTH+1];
+                memset(subject,0,MAX_NAME_LENGTH+1);
+                sprintf(subject,"Widget %s detected",name);
+                
+                // create and dispatch a case
+                bool success = case_generator.createCase(subject,db.lookupWidgetDescription(rfid));
+                if (success == true) {
+                    logger.log("Case Generated!");
+                }
+                else {
+                    logger.log("Case Generation FAILED");
+                }
+            }
+            else {
+                // unrecognized RFID
+                logger.log("RFID unknown. Ignoring...");
+            }
+         }
+      
+         // wait a bit and look again
+         wait_ms(WAIT_TIME_MS);
+      }
+  }
\ No newline at end of file