SmartREST client reference implementation for the u-blox C027 mbed compatible device.

Dependencies:   C027 C027_Support mbed mbed-rtos MbedSmartRest LM75B MMA7660 C12832

Fork of MbedSmartRestTest by Vincent Wochnik

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers io.cpp Source File

io.cpp

00001 #include "io.h"
00002 #include "rtos.h"
00003 #include "mbed.h"
00004 
00005 void timer_callback(void const*);
00006 void lcd_update(void);
00007 
00008 // Using Arduino pin notation
00009 C12832 lcdDisplay(D11, D13, D12, D7, D10);
00010 MMA7660 accSensor(SDA,SCL);
00011 LM75B tempSensor(SDA,SCL);
00012 DigitalOut button(D4);
00013 AnalogIn meter0(A0);
00014 AnalogIn meter1(A1);
00015 
00016 RtosTimer *timer;
00017 
00018 bool tempFound = false, accFound = false;
00019 uint32_t count = 0;
00020 bool btnPressed = false;
00021 
00022 char cSignal[80] = "", cTenant[80] = "", cStatus[80] = "";
00023 
00024 void io_init(void)
00025 {
00026     timer = new RtosTimer(&timer_callback, osTimerPeriodic);
00027     timer->start(50);
00028     tempFound = tempSensor.open();
00029     accFound = accSensor.testConnection();
00030     
00031     if (!tempFound)
00032         puts("Temperature sensor not found.");
00033     if (!accFound)
00034         puts("Accelerometer not found.");
00035     
00036     lcd_update();
00037 }
00038 
00039 float temperature()
00040 {
00041     if (!tempFound)
00042         return 0.0;
00043 
00044     return tempSensor.temp();
00045 }
00046 
00047 acceleration_t acceleration()
00048 {
00049     float data[3];
00050     acceleration_t ret = { 0.0, 0.0, 0.0 };
00051 
00052     if (accFound) {
00053         accSensor.readData(data);
00054         ret.x = data[0];
00055         ret.y = data[1];
00056         ret.z = data[2];
00057     }
00058 
00059     return ret;
00060 }
00061 
00062 uint32_t counter()
00063 {
00064     return count;
00065 }
00066 
00067 double potentiometer(uint8_t n)
00068 {
00069     switch (n) {
00070         case 0: return (double)meter0;
00071         case 1: return (double)meter1;
00072         default: return 0.0;
00073     }
00074 }
00075 
00076 void lcd_signal(int8_t rssi, uint8_t ber)
00077 {
00078     if ((rssi == 0) && (ber == 0))
00079         snprintf(cSignal, 80, "%s", "No signal");
00080     else
00081         snprintf(cSignal, 80, "RSSI: %d dBm  BER: %d %%", rssi, ber);
00082     lcd_update();
00083 }
00084 
00085 void lcd_tenant(const char* tenant)
00086 {
00087     snprintf(cTenant, 80, "Tenant: %s", tenant);
00088     lcd_update();
00089 }
00090 
00091 void lcd_status(const char* status)
00092 {
00093     snprintf(cStatus, 80, "%s", status);
00094     lcd_update();
00095 }
00096 
00097 void timer_callback(void const*)
00098 {
00099     if ((!btnPressed) && (button))
00100         count++;
00101     btnPressed = button;
00102 }
00103 
00104 void lcd_update(void)
00105 {
00106     lcdDisplay.cls();
00107     lcdDisplay.locate(0, 0);
00108     lcdDisplay.printf("%s\n%s\n%s\n", cSignal, cTenant, cStatus);
00109 }