set led to common anode
Dependencies: C12832_lcd EthernetInterface LM75B MMA7660 libxively mbed-rtos mbed
Fork of xively-dreamforce by
main.cpp@16:878226cefdb1, 2013-11-11 (annotated)
- Committer:
- errordeveloper
- Date:
- Mon Nov 11 17:34:30 2013 +0000
- Revision:
- 16:878226cefdb1
- Parent:
- 15:7443df31ff5b
- Child:
- 17:6457dc373c2d
Remove commented code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xively | 0:efdea27c3b81 | 1 | #include "mbed.h" |
xively | 0:efdea27c3b81 | 2 | #include "EthernetInterface.h" |
xively | 7:0eff5db44b8b | 3 | |
errordeveloper | 14:1bb008e28de8 | 4 | #define XI_FEED_ID 34525050 // set Xively Feed ID (numerical, no quoutes) |
errordeveloper | 14:1bb008e28de8 | 5 | #define XI_API_KEY "MsBCnO8YoVNiDBt3X1WbO5MkxO3No2hzMNx45OwbeHf5CecZ" // set Xively API key (double-quoted string) |
errordeveloper | 10:86ffba646df1 | 6 | |
errordeveloper | 10:86ffba646df1 | 7 | #include "app_board_io.h" |
xively | 7:0eff5db44b8b | 8 | |
xively | 0:efdea27c3b81 | 9 | #include "xively.h" |
xively | 0:efdea27c3b81 | 10 | #include "xi_err.h" |
xively | 0:efdea27c3b81 | 11 | |
errordeveloper | 10:86ffba646df1 | 12 | #include "MMA7660.h" |
errordeveloper | 10:86ffba646df1 | 13 | #include "LM75B.h" |
errordeveloper | 11:bdf601a405fc | 14 | #include "C12832_lcd.h" |
errordeveloper | 10:86ffba646df1 | 15 | |
xively | 3:7ad3f6543b6e | 16 | LM75B tmp(p28, p27); |
errordeveloper | 15:7443df31ff5b | 17 | DigitalOut fan(p22); |
errordeveloper | 11:bdf601a405fc | 18 | C12832_LCD lcd; |
errordeveloper | 11:bdf601a405fc | 19 | |
errordeveloper | 11:bdf601a405fc | 20 | #include "logo.h" |
xively | 0:efdea27c3b81 | 21 | |
xively | 0:efdea27c3b81 | 22 | int main() { |
errordeveloper | 11:bdf601a405fc | 23 | lcd_print_xively_logo(); |
errordeveloper | 16:878226cefdb1 | 24 | |
xively | 0:efdea27c3b81 | 25 | EthernetInterface eth; |
xively | 0:efdea27c3b81 | 26 | |
errordeveloper | 15:7443df31ff5b | 27 | Thread _rgbpwm(rgbpwm_thread); |
errordeveloper | 15:7443df31ff5b | 28 | |
xively | 0:efdea27c3b81 | 29 | int s = eth.init(); //Use DHCP |
xively | 0:efdea27c3b81 | 30 | |
xively | 0:efdea27c3b81 | 31 | if( s != NULL ) |
xively | 0:efdea27c3b81 | 32 | { |
xively | 7:0eff5db44b8b | 33 | lcd_printf( "Could not initialise. Will halt!\n" ); |
xively | 0:efdea27c3b81 | 34 | exit( 0 ); |
xively | 0:efdea27c3b81 | 35 | } |
xively | 0:efdea27c3b81 | 36 | |
xively | 0:efdea27c3b81 | 37 | s = eth.connect(); |
xively | 0:efdea27c3b81 | 38 | |
xively | 0:efdea27c3b81 | 39 | if( s != NULL ) |
xively | 0:efdea27c3b81 | 40 | { |
xively | 7:0eff5db44b8b | 41 | lcd_printf( "Could not connect. Will halt!\n" ); |
xively | 0:efdea27c3b81 | 42 | exit( 0 ); |
xively | 0:efdea27c3b81 | 43 | } |
xively | 0:efdea27c3b81 | 44 | else |
xively | 0:efdea27c3b81 | 45 | { |
xively | 7:0eff5db44b8b | 46 | lcd_printf( "IP: %s\n", eth.getIPAddress() ); |
xively | 0:efdea27c3b81 | 47 | } |
xively | 0:efdea27c3b81 | 48 | |
errordeveloper | 14:1bb008e28de8 | 49 | xi_feed_t output_channels; |
errordeveloper | 14:1bb008e28de8 | 50 | memset( &output_channels, NULL, sizeof( xi_feed_t ) ); |
xively | 0:efdea27c3b81 | 51 | |
errordeveloper | 14:1bb008e28de8 | 52 | output_channels.feed_id = XI_FEED_ID; |
errordeveloper | 14:1bb008e28de8 | 53 | output_channels.datastream_count = 1; |
errordeveloper | 14:1bb008e28de8 | 54 | |
errordeveloper | 14:1bb008e28de8 | 55 | output_channels.datastreams[0].datapoint_count = 1; |
errordeveloper | 14:1bb008e28de8 | 56 | xi_datastream_t* temperature_datastream = &output_channels.datastreams[0]; |
errordeveloper | 14:1bb008e28de8 | 57 | strcpy( temperature_datastream->datastream_id, "temp" ); |
errordeveloper | 14:1bb008e28de8 | 58 | xi_datapoint_t* temp = &temperature_datastream->datapoints[0]; |
xively | 0:efdea27c3b81 | 59 | |
errordeveloper | 14:1bb008e28de8 | 60 | xi_feed_t input_channels; |
errordeveloper | 14:1bb008e28de8 | 61 | memset( &input_channels, NULL, sizeof( xi_feed_t ) ); |
xively | 0:efdea27c3b81 | 62 | |
errordeveloper | 14:1bb008e28de8 | 63 | input_channels.feed_id = XI_FEED_ID; |
errordeveloper | 14:1bb008e28de8 | 64 | input_channels.datastream_count = 2; |
xively | 0:efdea27c3b81 | 65 | |
errordeveloper | 14:1bb008e28de8 | 66 | input_channels.datastreams[0].datapoint_count = 1; |
errordeveloper | 14:1bb008e28de8 | 67 | xi_datastream_t* fan_ctl_datastream = &input_channels.datastreams[0]; |
errordeveloper | 14:1bb008e28de8 | 68 | strcpy( fan_ctl_datastream->datastream_id, "fan" ); |
errordeveloper | 14:1bb008e28de8 | 69 | xi_datapoint_t* fan_ctl = &fan_ctl_datastream->datapoints[0]; |
errordeveloper | 14:1bb008e28de8 | 70 | |
errordeveloper | 14:1bb008e28de8 | 71 | input_channels.datastreams[1].datapoint_count = 1; |
errordeveloper | 14:1bb008e28de8 | 72 | xi_datastream_t* led_ctl_datastream = &input_channels.datastreams[1]; |
errordeveloper | 14:1bb008e28de8 | 73 | strcpy( led_ctl_datastream->datastream_id, "led" ); |
errordeveloper | 14:1bb008e28de8 | 74 | xi_datapoint_t* led_ctl = &led_ctl_datastream->datapoints[0]; |
xively | 3:7ad3f6543b6e | 75 | |
xively | 0:efdea27c3b81 | 76 | // create the cosm library context |
xively | 0:efdea27c3b81 | 77 | xi_context_t* xi_context |
errordeveloper | 14:1bb008e28de8 | 78 | = xi_create_context( XI_HTTP, XI_API_KEY, output_channels.feed_id ); |
xively | 0:efdea27c3b81 | 79 | |
xively | 0:efdea27c3b81 | 80 | // check if everything works |
xively | 0:efdea27c3b81 | 81 | if( xi_context == NULL ) |
xively | 0:efdea27c3b81 | 82 | { |
xively | 0:efdea27c3b81 | 83 | return -1; |
xively | 0:efdea27c3b81 | 84 | } |
xively | 0:efdea27c3b81 | 85 | |
errordeveloper | 15:7443df31ff5b | 86 | while( true ) { |
xively | 0:efdea27c3b81 | 87 | |
errordeveloper | 14:1bb008e28de8 | 88 | xi_set_value_f32( temp, tmp.read() ); |
errordeveloper | 14:1bb008e28de8 | 89 | |
errordeveloper | 14:1bb008e28de8 | 90 | printf( "Updating output channels...\r\n" ); |
errordeveloper | 14:1bb008e28de8 | 91 | xi_feed_update( xi_context, &output_channels ); |
errordeveloper | 14:1bb008e28de8 | 92 | printf( " [%s]\r\n", xi_get_error_string( xi_get_last_error() ) ); |
errordeveloper | 14:1bb008e28de8 | 93 | |
errordeveloper | 14:1bb008e28de8 | 94 | printf( "Reading input channels...\r\n" ); |
errordeveloper | 14:1bb008e28de8 | 95 | xi_feed_get( xi_context, &input_channels ); |
errordeveloper | 14:1bb008e28de8 | 96 | printf( " [%s]\r\n", xi_get_error_string( xi_get_last_error() ) ); |
xively | 0:efdea27c3b81 | 97 | |
errordeveloper | 15:7443df31ff5b | 98 | lcd_printf( "led: %s\nfan: %d\n", xi_value_pointer_str( led_ctl ), xi_get_value_i32( fan_ctl ) ); |
errordeveloper | 15:7443df31ff5b | 99 | |
errordeveloper | 15:7443df31ff5b | 100 | switch( xi_get_value_i32( fan_ctl ) ) { |
errordeveloper | 15:7443df31ff5b | 101 | case 0: fan = 0; break; |
errordeveloper | 15:7443df31ff5b | 102 | case 1: fan = 1; break; |
errordeveloper | 15:7443df31ff5b | 103 | } |
errordeveloper | 14:1bb008e28de8 | 104 | if( strcmp( xi_value_pointer_str( led_ctl ), "RED" ) == 0 ) |
errordeveloper | 14:1bb008e28de8 | 105 | { |
errordeveloper | 15:7443df31ff5b | 106 | |
errordeveloper | 14:1bb008e28de8 | 107 | } |
errordeveloper | 14:1bb008e28de8 | 108 | else if( strcmp( xi_value_pointer_str( led_ctl ), "GREEN" ) == 0 ) |
errordeveloper | 14:1bb008e28de8 | 109 | { |
errordeveloper | 15:7443df31ff5b | 110 | |
xively | 0:efdea27c3b81 | 111 | } |
errordeveloper | 14:1bb008e28de8 | 112 | else if( strcmp( xi_value_pointer_str( led_ctl ), "BLUE" ) == 0 ) |
errordeveloper | 14:1bb008e28de8 | 113 | { |
errordeveloper | 15:7443df31ff5b | 114 | |
errordeveloper | 14:1bb008e28de8 | 115 | } |
errordeveloper | 14:1bb008e28de8 | 116 | else /* OFF */ |
errordeveloper | 14:1bb008e28de8 | 117 | { |
errordeveloper | 15:7443df31ff5b | 118 | |
errordeveloper | 14:1bb008e28de8 | 119 | } |
xively | 3:7ad3f6543b6e | 120 | |
errordeveloper | 15:7443df31ff5b | 121 | wait( 5.0 ); |
xively | 0:efdea27c3b81 | 122 | } |
Ilya Dmitrichenko |
6:9e4f4a8c1829 | 123 | } |