set led to common anode

Dependencies:   C12832_lcd EthernetInterface LM75B MMA7660 libxively mbed-rtos mbed

Fork of xively-dreamforce by Ilya Dmitrichenko

main.cpp

Committer:
errordeveloper
Date:
2013-11-11
Revision:
15:7443df31ff5b
Parent:
14:1bb008e28de8
Child:
16:878226cefdb1

File content as of revision 15:7443df31ff5b:

#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)

#include "app_board_io.h"

#include "xively.h"
#include "xi_err.h"

#include "MMA7660.h"
#include "LM75B.h"
#include "C12832_lcd.h"

LM75B tmp(p28, p27);
DigitalOut fan(p22);
C12832_LCD lcd;

#include "logo.h"

int main() {
    lcd_print_xively_logo();
    //r.period( 0.001 );
    //g.period( 0.001 );
    //b.period( 0.001 );
    EthernetInterface eth;
    
    Thread _rgbpwm(rgbpwm_thread);
    
    int s = eth.init(); //Use DHCP
    
    if( s != NULL )
    {
        lcd_printf( "Could not initialise. Will halt!\n" );        
        exit( 0 );
    }    
        
    s = eth.connect();
    
    if( s != NULL )
    {
        lcd_printf( "Could not connect. Will halt!\n" );
        exit( 0 );
    }
    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" );
    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, output_channels.feed_id );

    // check if everything works
    if( xi_context == NULL )
    {
        return -1;
    }

    while( true ) {
      
      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() ) );
      
      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 )
      {
 
      }
      else if( strcmp( xi_value_pointer_str( led_ctl ), "GREEN" ) == 0 )
      {
   
      }
      else if( strcmp( xi_value_pointer_str( led_ctl ), "BLUE" ) == 0 )
      {
      
      }
      else /* OFF */
      {
      
      }
      
      wait( 5.0 );
    }
}