Dreameforce 2013 giveaway demo

Dependencies:   C12832_lcd EthernetInterface LM75B MMA7660 libxively mbed-rtos mbed

Fork of xively-dreamforce by Ilya Dmitrichenko

Revision:
14:1bb008e28de8
Parent:
11:bdf601a405fc
Child:
15:7443df31ff5b
--- a/main.cpp	Fri Nov 08 16:57:17 2013 +0000
+++ b/main.cpp	Sat Nov 09 10:15:50 2013 +0000
@@ -1,8 +1,8 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
 
-#define XI_FEED_ID 128488 // set Xively Feed ID (numerical, no quoutes)
-#define XI_API_KEY "T4KXAH_dasgw1PWBPc3fdsfsdgsdy-dUc4ND0g" // set Xively API key (double-quoted string)
+#define XI_FEED_ID 34525050 // set Xively Feed ID (numerical, no quoutes)
+#define XI_API_KEY "MsBCnO8YoVNiDBt3X1WbO5MkxO3No2hzMNx45OwbeHf5CecZ" // set Xively API key (double-quoted string)
 
 #include "app_board_io.h"
 
@@ -13,7 +13,6 @@
 #include "LM75B.h"
 #include "C12832_lcd.h"
 
-MMA7660 axl(p28, p27);
 LM75B tmp(p28, p27);
 C12832_LCD lcd;
 
@@ -43,30 +42,36 @@
         lcd_printf( "IP: %s\n", eth.getIPAddress() );    
     }
     
-    xi_feed_t feed;
-    memset( &feed, NULL, sizeof( xi_feed_t ) );
+    xi_feed_t output_channels;
+    memset( &output_channels, NULL, sizeof( xi_feed_t ) );
     
-    feed.feed_id = XI_FEED_ID;
-    feed.datastream_count = 3;
+    output_channels.feed_id = XI_FEED_ID;
+    output_channels.datastream_count = 1;
+    
+    output_channels.datastreams[0].datapoint_count = 1;
+    xi_datastream_t* temperature_datastream = &output_channels.datastreams[0];
+    strcpy( temperature_datastream->datastream_id, "temp" );
+    xi_datapoint_t* temp = &temperature_datastream->datapoints[0];
     
-    feed.datastreams[0].datapoint_count = 1;
-    xi_datastream_t* orientation_datastream = &feed.datastreams[0];
-    strcpy( orientation_datastream->datastream_id, "orientation" );
-    xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0];
+    xi_feed_t input_channels;
+    memset( &input_channels, NULL, sizeof( xi_feed_t ) );
 
-    feed.datastreams[1].datapoint_count = 1;
-    xi_datastream_t* side_rotation_datastream = &feed.datastreams[1];
-    strcpy( side_rotation_datastream->datastream_id, "side_rotation" );
-    xi_datapoint_t* current_side_rotation = &side_rotation_datastream->datapoints[0];
+    input_channels.feed_id = XI_FEED_ID;
+    input_channels.datastream_count = 2;
     
-    feed.datastreams[2].datapoint_count = 1;
-    xi_datastream_t* temperature_datastream = &feed.datastreams[2];
-    strcpy( temperature_datastream->datastream_id, "temperature" );
-    xi_datapoint_t* current_temperature = &temperature_datastream->datapoints[0];
+    input_channels.datastreams[0].datapoint_count = 1;
+    xi_datastream_t* fan_ctl_datastream = &input_channels.datastreams[0];
+    strcpy( fan_ctl_datastream->datastream_id, "fan" );
+    xi_datapoint_t* fan_ctl = &fan_ctl_datastream->datapoints[0];
+
+    input_channels.datastreams[1].datapoint_count = 1;
+    xi_datastream_t* led_ctl_datastream = &input_channels.datastreams[1];
+    strcpy( led_ctl_datastream->datastream_id, "led" );
+    xi_datapoint_t* led_ctl = &led_ctl_datastream->datapoints[0];
     
     // create the cosm library context
     xi_context_t* xi_context
-        = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
+        = xi_create_context( XI_HTTP, XI_API_KEY, output_channels.feed_id );
 
     // check if everything works
     if( xi_context == NULL )
@@ -76,41 +81,32 @@
 
     while(1) {
       
-      switch( axl.getSide() ) {
-        case MMA7660::Front:
-          xi_set_value_str( current_side_rotation, "front" );
-          break;
-        case MMA7660::Back:
-          xi_set_value_str( current_side_rotation, "back" );
-          break;
-        default:
-          xi_set_value_str( current_side_rotation, "unknown" );
-          break;
-      }
+      xi_set_value_f32( temp, tmp.read() );
+        
+      printf( "Updating output channels...\r\n" );
+      xi_feed_update( xi_context, &output_channels );
+      printf( "   [%s]\r\n", xi_get_error_string( xi_get_last_error() ) );
+      
+      printf( "Reading input channels...\r\n" );
+      xi_feed_get( xi_context, &input_channels );
+      printf( "   [%s]\r\n", xi_get_error_string( xi_get_last_error() ) );
       
-      switch( axl.getOrientation() ) {
-        case MMA7660::Down:
-          xi_set_value_str( current_orientation, "down" );
-          break;
-        case MMA7660::Up:
-           xi_set_value_str( current_orientation, "up" );
-           break;
-        case MMA7660::Right:
-          xi_set_value_str( current_orientation, "right" );
-          break;
-        case MMA7660::Left:
-          xi_set_value_str( current_orientation, "left" );
-          break;
-        default: 
-          xi_set_value_str( current_orientation, "unknown" );
-          break;
+      if( strcmp( xi_value_pointer_str( led_ctl ), "RED" ) == 0 )
+      {
+        lcd_printf( "Turning LED red\n" );
+      }
+      else if( strcmp( xi_value_pointer_str( led_ctl ), "GREEN" ) == 0 )
+      {
+        lcd_printf( "Turning LED green\n" );
       }
-      
-      xi_set_value_f32( current_temperature, tmp.read() );
-        
-      lcd_printf( "update...\n" );
-      xi_feed_update( xi_context, &feed );
-      lcd_printf( "done...\n" );
+      else if( strcmp( xi_value_pointer_str( led_ctl ), "BLUE" ) == 0 )
+      {
+        lcd_printf( "Turning LED blue\n" );
+      }
+      else /* OFF */
+      {
+        lcd_printf( "Turning off the LED\n" );
+      }
       
       wait( 15.0 );
     }