compile ok 20140330 , update mbed and mbed-rtos

Dependencies:   C12832 EthernetInterface HTTPClient mbed-rtos mbed MbedJSONValue

Fork of HTTPClient_HelloWorld by Takahiro Kubo

Files at this revision

API Documentation at this revision

Comitter:
lamadio
Date:
Fri Apr 25 20:24:32 2014 +0000
Parent:
5:6d5842b97059
Commit message:
Round Trip through Dweet

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Apr 25 20:00:33 2014 +0000
+++ b/main.cpp	Fri Apr 25 20:24:32 2014 +0000
@@ -8,44 +8,79 @@
 HTTPClient http;
 char str[2048];
 C12832 lcd(p5, p7, p6, p8, p11);
+bool updateLEDs = false;
+void timeoutCallback()
+{
+    updateLEDs = true;
+}
 
 int main() 
 {
+    BusIn joy(p15,p12,p13,p16);
+    DigitalIn fire(p14);
+    BusOut leds(LED1,LED2,LED3,LED4);
+    Timeout timeout;
+    
+    timeout.attach(&timeoutCallback, 5);
+ 
     eth.init(); //Use DHCP
     eth.connect();
     
-    //GET data
-    lcd.printf("\nTrying to fetch page...\n");
-    int ret = http.get("https://dweet.io/get/latest/dweet/for/modern-wheel", str, sizeof(str));
-    if (!ret)
-    {
-        lcd.cls();
-        lcd.locate(0,0);
-        lcd.printf("read %d", strlen(str));
-        MbedJSONValue v;
-        const char* start = str;
-        const char* end = (const char*)(str + strlen(str));
-        std::string err;
-        parse(v, start, end, &err);
-        if (!err.empty()) 
-        {
-            lcd.cls();
-            lcd.printf("Error - %s", err.c_str());
-        }
-        else
-        {
-            lcd.cls();
-            int mousex = v["with"][0]["content"]["mouse_x"].get<int>();
-            lcd.printf("Success  %d", mousex);
-        }
-    }
-    else
-    {
-      lcd.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
-    }
-    
+    int lastJoy = 0;
     while(1) 
     {
+        int currentJoy = joy;
+        if (currentJoy != lastJoy)
+        {
+            lastJoy = currentJoy;
+            updateLEDs = true;
+            
+            char url[1024];
+            sprintf(url, "https://dweet.io/dweet/for/modern-wheel?joy=%d", currentJoy);
+            
+            http.get(url, str, sizeof(str));
+        }
+        
+        if (updateLEDs)
+        {
+            //GET data
+            int ret = http.get("https://dweet.io/get/latest/dweet/for/modern-wheel", str, sizeof(str));
+            if (!ret)
+            {
+                lcd.cls();
+                lcd.locate(0,0);
+                lcd.printf("read %d", strlen(str));
+                MbedJSONValue v;
+                const char* start = str;
+                const char* end = (const char*)(str + strlen(str));
+                std::string err;
+                parse(v, start, end, &err);
+                if (!err.empty()) 
+                {
+                    lcd.cls();
+                    lcd.printf("Error - %s", err.c_str());
+                }
+                else
+                {
+                    lcd.cls();
+                    int joyValue = v["with"][0]["content"]["joy"].get<int>();
+                    if (fire) 
+                    {
+                        leds=0xf;
+                    } 
+                    else 
+                    {
+                        leds=joyValue;
+                    }
+                }
+            }
+            else
+            {
+              lcd.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+            }
+        }        
+        updateLEDs = false;
+        
     }
     eth.disconnect();  
 }