set led to common anode

Dependencies:   C12832_lcd EthernetInterface LM75B MMA7660 libxively mbed-rtos mbed

Fork of xively-dreamforce by Ilya Dmitrichenko

Committer:
xively
Date:
Fri Oct 11 12:46:15 2013 +0000
Revision:
8:81743e1228a7
Parent:
7:0eff5db44b8b
Parent:
6:9e4f4a8c1829
Child:
9:c5dc85d192e2
Merged r6 with r7

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xively 0:efdea27c3b81 1 #include "mbed.h"
xively 0:efdea27c3b81 2 #include "EthernetInterface.h"
xively 7:0eff5db44b8b 3
xively 7:0eff5db44b8b 4 #define XI_FEED_ID 128488 // set Xively Feed ID (numerical, no quoutes
xively 7:0eff5db44b8b 5 #define XI_API_KEY "T4KXAH_dasgw1PWBPc3fdsfsdgsdy-dUc4ND0g" // set Xively API key (double-quoted string)
xively 7:0eff5db44b8b 6
xively 7:0eff5db44b8b 7 #include "app_board_io.h"
xively 7:0eff5db44b8b 8
xively 7:0eff5db44b8b 9 #define XI_DEBUG_PRINTF lcd_printf
xively 7:0eff5db44b8b 10 #define XI_DEBUG_OUTPUT 1
xively 7:0eff5db44b8b 11 #define XI_DEBUG_ASSERT 0
xively 7:0eff5db44b8b 12
xively 0:efdea27c3b81 13 #include "xively.h"
xively 0:efdea27c3b81 14 #include "xi_err.h"
xively 0:efdea27c3b81 15
xively 0:efdea27c3b81 16 MMA7660 axl(p28, p27);
xively 3:7ad3f6543b6e 17 LM75B tmp(p28, p27);
xively 0:efdea27c3b81 18
xively 0:efdea27c3b81 19 int main() {
xively 0:efdea27c3b81 20
xively 0:efdea27c3b81 21 EthernetInterface eth;
xively 0:efdea27c3b81 22
xively 0:efdea27c3b81 23 int s = eth.init(); //Use DHCP
xively 0:efdea27c3b81 24
xively 0:efdea27c3b81 25 if( s != NULL )
xively 0:efdea27c3b81 26 {
xively 7:0eff5db44b8b 27 lcd_printf( "Could not initialise. Will halt!\n" );
xively 0:efdea27c3b81 28 exit( 0 );
xively 0:efdea27c3b81 29 }
xively 0:efdea27c3b81 30
xively 0:efdea27c3b81 31 s = eth.connect();
xively 0:efdea27c3b81 32
xively 0:efdea27c3b81 33 if( s != NULL )
xively 0:efdea27c3b81 34 {
xively 7:0eff5db44b8b 35 lcd_printf( "Could not connect. Will halt!\n" );
xively 0:efdea27c3b81 36 exit( 0 );
xively 0:efdea27c3b81 37 }
xively 0:efdea27c3b81 38 else
xively 0:efdea27c3b81 39 {
xively 7:0eff5db44b8b 40 lcd_printf( "IP: %s\n", eth.getIPAddress() );
xively 0:efdea27c3b81 41 }
xively 0:efdea27c3b81 42
xively 0:efdea27c3b81 43 xi_feed_t feed;
xively 0:efdea27c3b81 44 memset( &feed, NULL, sizeof( xi_feed_t ) );
xively 0:efdea27c3b81 45
xively 0:efdea27c3b81 46 feed.feed_id = XI_FEED_ID;
xively 3:7ad3f6543b6e 47 feed.datastream_count = 3;
xively 0:efdea27c3b81 48
xively 0:efdea27c3b81 49 feed.datastreams[0].datapoint_count = 1;
xively 0:efdea27c3b81 50 xi_datastream_t* orientation_datastream = &feed.datastreams[0];
xively 0:efdea27c3b81 51 strcpy( orientation_datastream->datastream_id, "orientation" );
xively 0:efdea27c3b81 52 xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0];
xively 0:efdea27c3b81 53
xively 0:efdea27c3b81 54 feed.datastreams[1].datapoint_count = 1;
xively 0:efdea27c3b81 55 xi_datastream_t* side_rotation_datastream = &feed.datastreams[1];
xively 0:efdea27c3b81 56 strcpy( side_rotation_datastream->datastream_id, "side_rotation" );
xively 0:efdea27c3b81 57 xi_datapoint_t* current_side_rotation = &side_rotation_datastream->datapoints[0];
xively 0:efdea27c3b81 58
xively 3:7ad3f6543b6e 59 feed.datastreams[2].datapoint_count = 1;
xively 3:7ad3f6543b6e 60 xi_datastream_t* temperature_datastream = &feed.datastreams[2];
xively 3:7ad3f6543b6e 61 strcpy( temperature_datastream->datastream_id, "temperature" );
xively 3:7ad3f6543b6e 62 xi_datapoint_t* current_temperature = &temperature_datastream->datapoints[0];
xively 3:7ad3f6543b6e 63
xively 0:efdea27c3b81 64 // create the cosm library context
xively 0:efdea27c3b81 65 xi_context_t* xi_context
xively 0:efdea27c3b81 66 = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
xively 0:efdea27c3b81 67
xively 0:efdea27c3b81 68 // check if everything works
xively 0:efdea27c3b81 69 if( xi_context == NULL )
xively 0:efdea27c3b81 70 {
xively 0:efdea27c3b81 71 return -1;
xively 0:efdea27c3b81 72 }
xively 0:efdea27c3b81 73
xively 7:0eff5db44b8b 74 lcd_printf("feed:%d datastreams:[%s,%s]\n", feed.feed_id,
xively 0:efdea27c3b81 75 orientation_datastream->datastream_id,
xively 0:efdea27c3b81 76 side_rotation_datastream->datastream_id);
xively 0:efdea27c3b81 77
xively 0:efdea27c3b81 78 while(1) {
xively 0:efdea27c3b81 79
xively 0:efdea27c3b81 80 switch( axl.getSide() ) {
xively 0:efdea27c3b81 81 case MMA7660::Front:
xively 0:efdea27c3b81 82 xi_set_value_str( current_side_rotation, "front" );
xively 0:efdea27c3b81 83 break;
xively 0:efdea27c3b81 84 case MMA7660::Back:
xively 0:efdea27c3b81 85 xi_set_value_str( current_side_rotation, "back" );
xively 0:efdea27c3b81 86 break;
xively 0:efdea27c3b81 87 default:
xively 0:efdea27c3b81 88 xi_set_value_str( current_side_rotation, "unknown" );
xively 0:efdea27c3b81 89 break;
xively 0:efdea27c3b81 90 }
xively 0:efdea27c3b81 91
xively 0:efdea27c3b81 92 switch( axl.getOrientation() ) {
xively 0:efdea27c3b81 93 case MMA7660::Down:
xively 7:0eff5db44b8b 94 lcd_printf("down %s\n",
xively 0:efdea27c3b81 95 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 96 xi_set_value_str( current_orientation, "down" );
xively 0:efdea27c3b81 97 break;
xively 0:efdea27c3b81 98 case MMA7660::Up:
xively 7:0eff5db44b8b 99 lcd_printf("up %s\n",
xively 0:efdea27c3b81 100 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 101 xi_set_value_str( current_orientation, "up" );
xively 0:efdea27c3b81 102 break;
xively 0:efdea27c3b81 103 case MMA7660::Right:
xively 7:0eff5db44b8b 104 lcd_printf("right %s\n",
xively 0:efdea27c3b81 105 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 106 xi_set_value_str( current_orientation, "right" );
xively 0:efdea27c3b81 107 break;
xively 0:efdea27c3b81 108 case MMA7660::Left:
xively 7:0eff5db44b8b 109 lcd_printf("left %s\n",
xively 0:efdea27c3b81 110 (axl.getSide() == MMA7660::Front ? "front" : "back"));
xively 0:efdea27c3b81 111 xi_set_value_str( current_orientation, "left" );
xively 0:efdea27c3b81 112 break;
xively 0:efdea27c3b81 113 default:
xively 0:efdea27c3b81 114 xi_set_value_str( current_orientation, "unknown" );
xively 0:efdea27c3b81 115 break;
xively 0:efdea27c3b81 116 }
xively 3:7ad3f6543b6e 117
xively 3:7ad3f6543b6e 118 xi_set_value_f32( current_temperature, tmp.read() );
xively 4:e7ca62a11595 119
xively 7:0eff5db44b8b 120 lcd_printf( "update...\n" );
xively 0:efdea27c3b81 121 xi_feed_update(xi_context, &feed);
xively 7:0eff5db44b8b 122 lcd_printf( "done...\n" );
xively 3:7ad3f6543b6e 123
xively 3:7ad3f6543b6e 124 wait( 15.0 );
xively 0:efdea27c3b81 125 }
Ilya Dmitrichenko 6:9e4f4a8c1829 126 }