set led to common anode

Dependencies:   C12832_lcd EthernetInterface LM75B MMA7660 libxively mbed-rtos mbed

Fork of xively-dreamforce by Ilya Dmitrichenko

Revision:
20:4bb2758223fb
Parent:
19:ca595d80895b
--- a/main.cpp	Mon Nov 11 18:41:18 2013 +0000
+++ b/main.cpp	Thu Nov 14 17:27:17 2013 +0000
@@ -1,8 +1,8 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
 
-#define XI_FEED_ID 34525050 // set Xively Feed ID (numerical, no quoutes)
-#define XI_API_KEY "MsBCnO8YoVNiDBt3X1WbO5MkxO3No2hzMNx45OwbeHf5CecZ" // set Xively API key (double-quoted string)
+#define XI_FEED_ID 60544303 // set Xively Feed ID (numerical, no quoutes)
+#define XI_API_KEY "l3JC4iQeiw7k5LGvoKAGydQnJ0ekmIDr7z8mh6fBh5j130hP" // set Xively API key (double-quoted string)
 
 #include "app_board_io.h"
 
@@ -18,54 +18,51 @@
 PwmOut progress_led(LED1);
 C12832_LCD lcd;
 
-DigitalOut r (p23); // blue?
-DigitalOut g (p24); // purple?
-DigitalOut b (p25); // yellow?
+DigitalOut r (p23);
+DigitalOut g (p24);
+DigitalOut b (p25);
 
 #include "logo.h"
 
-int main() {
+int main()
+{
     lcd_print_xively_logo();
 
     EthernetInterface eth;
-      
+
     int s = eth.init(); //Use DHCP
-    
-    if( s != NULL )
-    {
-        lcd_printf( "Could not initialise. Will halt!\n" );        
+
+    if( s != NULL ) {
+        lcd_printf( "Could not initialise. Will halt!\n" );
         exit( 0 );
-    }    
-        
+    }
+
     s = eth.connect();
-    
-    if( s != NULL )
-    {
+
+    if( s != NULL ) {
         lcd_printf( "Could not connect. Will halt!\n" );
         exit( 0 );
+    } else {
+        lcd_printf( "IP: %s\n", eth.getIPAddress() );
     }
-    else 
-    {
-        lcd_printf( "IP: %s\n", eth.getIPAddress() );    
-    }
-    
+
     xi_feed_t output_channels;
     memset( &output_channels, NULL, sizeof( xi_feed_t ) );
-    
+
     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];
-    
+
     xi_feed_t input_channels;
     memset( &input_channels, NULL, sizeof( xi_feed_t ) );
 
     input_channels.feed_id = XI_FEED_ID;
     input_channels.datastream_count = 2;
-    
+
     input_channels.datastreams[0].datapoint_count = 1;
     xi_datastream_t* fan_ctl_datastream = &input_channels.datastreams[0];
     strcpy( fan_ctl_datastream->datastream_id, "fan" );
@@ -75,60 +72,66 @@
     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
+
+    // create the xively library context
     xi_context_t* xi_context
-        = xi_create_context( XI_HTTP, XI_API_KEY, output_channels.feed_id );
+    = xi_create_context( XI_HTTP, XI_API_KEY, output_channels.feed_id );
 
     // check if everything works
-    if( xi_context == NULL )
-    {
+    if( xi_context == NULL ) {
         return -1;
     }
 
     while( true ) {
-      
-      xi_set_value_f32( temp, tmp.read() );
-        
-      printf( "Updating output channels...\r\n" );
-      progress_led = 0.6;
-      lcd_printf( "updating...\n" );
-      xi_feed_update( xi_context, &output_channels );
-      progress_led = 0.1;
-      printf( "   [ec:%s]\r\n", xi_get_last_error() );
-    
-      printf( "Reading input channels...\r\n" );
-      progress_led = 0.8;
-      lcd_printf( "reading...\n" );
-      xi_feed_get( xi_context, &input_channels );
-      progress_led = 0.1;
-      printf( "   [ec:%s]\r\n", xi_get_last_error() );
-      
-      lcd_printf( "led: %s\nfan: %d\n", xi_value_pointer_str( led_ctl ), xi_get_value_i32( fan_ctl ) );
-      
-      switch( xi_get_value_i32( fan_ctl ) ) {
-        case 0: fan = 0; break;
-        case 1: fan = 1; break;
-      }
-      
-      if( strcmp( xi_value_pointer_str( led_ctl ), "RED" ) == 0 )
-      {
-        r = 1; g = 0; b = 0;
-      }
-      else if( strcmp( xi_value_pointer_str( led_ctl ), "GREEN" ) == 0 )
-      {
-        r = 0; g = 1; b = 0;
-      }
-      else if( strcmp( xi_value_pointer_str( led_ctl ), "BLUE" ) == 0 )
-      {
-        r = 0; g = 0; b = 1;
-      }
-      else /* OFF */
-      {
-        r = 0; g = 0; b = 0;
-      }
-      
-      wait( 5.0 );
-      progress_led = 0;
+
+        xi_set_value_f32( temp, tmp.read() );
+
+        printf( "Updating output channels...\r\n" );
+        progress_led = 0.6;
+        lcd_printf( "updating...\n" );
+        xi_feed_update( xi_context, &output_channels );
+        progress_led = 0.1;
+        printf( "   [ec:%s]\r\n", xi_get_last_error() );
+
+        printf( "Reading input channels...\r\n" );
+        progress_led = 0.8;
+        lcd_printf( "reading...\n" );
+        xi_feed_get( xi_context, &input_channels );
+        progress_led = 0.1;
+        printf( "   [ec:%s]\r\n", xi_get_last_error() );
+
+        lcd_printf("Now updating ...");
+        wait( 4.0 );
+        lcd_printf( "led: %s\nfan: %d\n", xi_value_pointer_str( led_ctl ), xi_get_value_i32( fan_ctl ) );
+
+        switch( xi_get_value_i32( fan_ctl ) ) {
+            case 0:
+                fan = 0;
+                break;
+            case 1:
+                fan = 1;
+                break;
+        }
+
+        if( strcmp( xi_value_pointer_str( led_ctl ), "RED" ) == 0 ) {
+            r = 0;
+            g = 1;
+            b = 1;
+        } else if( strcmp( xi_value_pointer_str( led_ctl ), "GREEN" ) == 0 ) {
+            r = 1;
+            g = 0;
+            b = 1;
+        } else if( strcmp( xi_value_pointer_str( led_ctl ), "BLUE" ) == 0 ) {
+            r = 1;
+            g = 1;
+            b = 0;
+        } else { /* OFF */
+            r = 1;
+            g = 1;
+            b = 1;
+        }
+
+        wait( 5.0 );
+        progress_led = 0;
     }
 }