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

io.cpp

Committer:
vwochnik
Date:
2014-02-20
Revision:
20:ef9cc1b42e9d
Parent:
19:7bee744fe527
Child:
21:f74b80a0cb38

File content as of revision 20:ef9cc1b42e9d:

#include "io.h"
#include "rtos.h"

void timer_callback(void const*);

// Using Arduino pin notation
C12832 lcdDisplay(D11, D13, D12, D7, D10);
MMA7660 accSensor(SDA,SCL);
LM75B tempSensor(SDA,SCL);
DigitalOut button(D4);
AnalogIn meter0(A0);
AnalogIn meter1(A1);

RtosTimer *timer;

bool tempFound = false, accFound = false;
uint32_t count = 0;
bool btnPressed = false;

void io_init(void)
{
    timer = new RtosTimer(&timer_callback, osTimerPeriodic);
    timer->start(50);
    tempFound = tempSensor.open();
    accFound = accSensor.testConnection();
    
    if (!tempFound)
        puts("Temperature sensor not found.");
    if (!accFound)
        puts("Accelerometer not found.");
    
    lcdDisplay.cls();
}

float temperature()
{
    if (!tempFound)
        return 0.0;

    return tempSensor.temp();
}

acceleration_t acceleration()
{
    float data[3];
    acceleration_t ret = { 0.0, 0.0, 0.0 };

    if (accFound) {
        accSensor.readData(data);
        ret.x = data[0];
        ret.y = data[1];
        ret.z = data[2];
    }

    return ret;
}

uint32_t counter()
{
    return count;
}

double potentiometer(uint8_t n)
{
    switch (n) {
        case 0: return (double)meter0;
        case 1: return (double)meter1;
        default: return 0.0;
    }
}

void lcd_signal(int8_t rssi, uint8_t ber)
{
    lcdDisplay.locate(0, 0);
    if ((rssi == 0) && (ber == 0))
        lcdDisplay.printf("No signal\n");
    else
        lcdDisplay.printf("RSSI: %d dBm  BER: %d %%\n", rssi, ber);
}

void lcd_tenant(const char* tenant)
{
    lcdDisplay.locate(0, 11);
    lcdDisplay.printf("Tenant: %s\n", tenant);
}

void lcd_status(const char* status)
{
    lcdDisplay.locate(0, 22);
    lcdDisplay.printf("%s\n", status);
}

void timer_callback(void const*)
{
    if ((!btnPressed) && (button))
        count++;
    btnPressed = button;
}