Proximity strip reader

Dependencies:   mbed sfh7779

Fork of StarterKit by Rick McConney

Files at this revision

API Documentation at this revision

Comitter:
elmkom
Date:
Fri Apr 21 17:58:35 2017 +0000
Parent:
45:fe90f1fcb4e0
Commit message:
Proximity strip reader

Changed in this revision

FXOS8700CQ.lib Show diff for this revision Revisions of this file
HTS221.h Show diff for this revision Revisions of this file
Proximity.cpp Show diff for this revision Revisions of this file
Proximity.h Show diff for this revision Revisions of this file
SerialBuffered/SerialBuffered.cpp Show diff for this revision Revisions of this file
SerialBuffered/SerialBuffered.h Show diff for this revision Revisions of this file
Wnc.cpp Show diff for this revision Revisions of this file
Wnc.h Show diff for this revision Revisions of this file
config_me.h Show diff for this revision Revisions of this file
hardware.h Show diff for this revision Revisions of this file
hts221_driver.cpp Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
sensors.cpp Show diff for this revision Revisions of this file
sensors.h Show diff for this revision Revisions of this file
sfh7779.lib Show annotated file Show diff for this revision Revisions of this file
diff -r fe90f1fcb4e0 -r 69966d555de7 FXOS8700CQ.lib
--- a/FXOS8700CQ.lib	Wed Nov 30 14:50:16 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://developer.mbed.org/users/elmkom/code/FXOS8700CQ/#3e0b32441a88
diff -r fe90f1fcb4e0 -r 69966d555de7 HTS221.h
--- a/HTS221.h	Wed Nov 30 14:50:16 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,92 +0,0 @@
-
-#ifndef HTS221_H_
-#define HTS221_H_
-
-class HTS221 {
-public:
-    HTS221(void);
-    int begin(void);
-    int activate(void);
-    int deactivate(void);
-
-    int bduActivate(void);
-    int bduDeactivate(void);
-
-    int readHumidity(void);
-    double readTemperature(void);
-private:
-    int storeCalibration(void);
-    unsigned char _h0_rH, _h1_rH;
-    unsigned int  _T0_degC, _T1_degC;
-    unsigned int  _H0_T0, _H1_T0;
-    unsigned int  _T0_OUT, _T1_OUT;
-    double _temperature;
-    int _humidity;
-    unsigned char _address;
-
-    unsigned char readRegister(unsigned char slaveAddress, unsigned char regToRead);
-    int writeRegister(unsigned char slaveAddress, unsigned char regToWrite, unsigned char dataToWrite);
-};
-
-#define HTS221_ADDRESS     0xBF
-
-//Define a few of the registers that we will be accessing on the HTS221
-#define WHO_AM_I           0x0F
-#define WHO_AM_I_RETURN    0xBC //This read-only register contains the device identifier, set to BCh
-
-#define AVERAGE_REG        0x10 // To configure humidity/temperature average.
-#define AVERAGE_DEFAULT    0x1B
-
-/*
- * [7] PD: power down control
- * (0: power-down mode; 1: active mode)
- *
- * [6:3] Reserved
- *
- * [2] BDU: block data update
- * (0: continuous update; 1: output registers not updated until MSB and LSB reading)
-The BDU bit is used to inhibit the output register update between the reading of the upper
-and lower register parts. In default mode (BDU = ?0?), the lower and upper register parts are
-updated continuously. If it is not certain whether the read will be faster than output data rate,
-it is recommended to set the BDU bit to ?1?. In this way, after the reading of the lower (upper)
-register part, the content of that output register is not updated until the upper (lower) part is
-read also.
- *
- * [1:0] ODR1, ODR0: output data rate selection (see table 17)
- */
-#define CTRL_REG1          0x20
-#define POWER_UP           0x80
-#define BDU_SET            0x4
-#define ODR0_SET           0x1   // setting sensor reading period 1Hz
-
-#define CTRL_REG2          0x21
-#define CTRL_REG3          0x22
-#define REG_DEFAULT        0x00
-
-#define STATUS_REG         0x27
-#define TEMPERATURE_READY  0x1
-#define HUMIDITY_READY     0x2
-
-#define HUMIDITY_L_REG     0x28
-#define HUMIDITY_H_REG     0x29
-#define TEMP_L_REG         0x2A
-#define TEMP_H_REG         0x2B
-/*
- * calibration registry should be read for temperature and humidity calculation.
- * Before the first calculation of temperature and humidity,
- * the master reads out the calibration coefficients.
- * will do at init phase
- */
-#define CALIB_START        0x30
-#define CALIB_END          0x3F
-/*
-#define CALIB_T0_DEGC_X8   0x32
-#define CALIB_T1_DEGC_X8   0x33
-#define CALIB_T1_T0_MSB    0x35
-#define CALIB_T0_OUT_L     0x3C
-#define CALIB_T0_OUT_H     0x3D
-#define CALIB_T1_OUT_L     0x3E
-#define CALIB_T1_OUT_H     0x3F
- */
- 
-#endif
diff -r fe90f1fcb4e0 -r 69966d555de7 Proximity.cpp
--- a/Proximity.cpp	Wed Nov 30 14:50:16 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-#include "mbed.h"
-#include "Proximity.h"
-
-
-
-Proximity::Proximity(void)
-{
-}
-
-void Proximity::init(I2C *i2c, char mAddress)
-{
-    muxAddress = mAddress;
-    proximityi2c = i2c;
-    proximityi2c->frequency(100000);
-}
-
-void Proximity::write_reg(char address,char reg, char cmd)
-{
-    char txbuffer [2];
-    txbuffer[0] = reg;
-    txbuffer[1] = cmd;
-
-    proximityi2c->write(address<<1, txbuffer, 2,false );
-
-} 
-
-void Proximity::write(char address, char cmd)
-{
-    char txbuffer [1];
-    txbuffer[0] = cmd;
-
-    proximityi2c->write(address<<1, txbuffer, 1,false );
-
-}  
-
-unsigned char Proximity::read_reg(char address,char reg)
-{
-    char txbuffer [1];
-    char rxbuffer [1];
-    rxbuffer[0] = 0;
-    txbuffer[0] = reg;
-    proximityi2c->write(address<<1, txbuffer, 1,false );
-    proximityi2c->read(address<<1, rxbuffer, 1 );
-    return (unsigned char)rxbuffer[0];
-}
-void Proximity::off()
-{
-    for(int sensor = 0;sensor<NUM_PROXIMIY_SENSORS;sensor++)
-    {
-        write(muxAddress,1<<sensor); 
-        write_reg(PROXIMITYADDRESS,0x41,0x00);
-    }
-}
-
-void Proximity::on()
-{  
-    for(int sensor = 0;sensor<NUM_PROXIMIY_SENSORS;sensor++)
-    {
-
-        lastProximityData[sensor][0] = 1000;
-        write(muxAddress,1<<sensor); 
-        write_reg(PROXIMITYADDRESS,0x41,Als400Ps400); // initiate ALS: and PS
-        write_reg(PROXIMITYADDRESS,0x42,GainAls64Ir64|C25ma); // set ALS_VIS=ALS_IR GAIN = 64 current 25ma
-    }
-    wait(0.5);
-}
-       
-void Proximity::scan()
-{  
-    for(int sensor = 0;sensor<NUM_PROXIMIY_SENSORS;sensor++)
-    {
-        write(muxAddress,1<<sensor);
-        //proximity_sensor_on(sensor);
-        unsigned char prox_lsb = read_reg(PROXIMITYADDRESS,0x44);
-        unsigned char prox_msb = read_reg(PROXIMITYADDRESS,0x45);
-        unsigned char ALS_lsb = read_reg(PROXIMITYADDRESS,0x46);
-        unsigned char ALS_msb = read_reg(PROXIMITYADDRESS,0x47);
-        unsigned char IR_lsb = read_reg(PROXIMITYADDRESS,0x48);
-        unsigned char IR_msb = read_reg(PROXIMITYADDRESS,0x49);
-    
-        short proximity = prox_msb*256+prox_lsb;
-        short ALS = ALS_msb*256+ALS_lsb;
-        short IR = IR_msb*256+IR_lsb;
-        proximityData[sensor][0] = proximity;
-        proximityData[sensor][1] = ALS;
-        proximityData[sensor][2] = IR;
-        //proximity_sensor_off(sensor);
-        //pc.printf(GRN "Sensor %d = %d, %d, %d\n\r",sensor,proximity,ALS,IR);
-    }
-
-}
-
-bool Proximity::changed(short delta)
-{
-    for(int sensor = 0;sensor<NUM_PROXIMIY_SENSORS;sensor++)
-    {
-        if(abs(proximityData[sensor][0] - lastProximityData[sensor][0]) > delta)
-        {
-            return true;
-        }
-    }
-
-    return false;
-}   
-
-short Proximity::getProximity(int sensor)
-{
-    return proximityData[sensor][0];
-}
-short Proximity::getAmbientLight(int sensor)
-{
-    return proximityData[sensor][1];
-}
-short Proximity::getIR(int sensor)
-{
-    return proximityData[sensor][2];
-}
-
-char* Proximity::getDataStr()
-{
-    int i=0;
-    int index = 0;
-    index += sprintf(&dataStr[index],"[");
-    for (i=0; i<NUM_PROXIMIY_SENSORS; i++)
-    {
-        if(i<NUM_PROXIMIY_SENSORS-1)
-            index += snprintf(&dataStr[index], 128, "{\"s\":%d,\"p\":%d,\"l\":%d,\"r\":%d},", i,proximityData[i][0],proximityData[i][1],proximityData[i][2]);
-        else
-            index += snprintf(&dataStr[index], 128, "{\"s\":%d,\"p\":%d,\"l\":%d,\"r\":%d}]", i,proximityData[i][0],proximityData[i][1],proximityData[i][2]);
-        lastProximityData[i][0] = proximityData[i][0];
-        lastProximityData[i][1] = proximityData[i][1];
-        lastProximityData[i][2] = proximityData[i][2];
-    } 
-    return dataStr;
-}
-    
-    
-
-
diff -r fe90f1fcb4e0 -r 69966d555de7 Proximity.h
--- a/Proximity.h	Wed Nov 30 14:50:16 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-#ifndef Proximity_
-#define Proximity_
-
-
-#define PROXIMITYADDRESS  0x39
-#define NUM_PROXIMIY_SENSORS 5
-
-#define C25ma 0x00
-#define C50ma 0x01
-#define C100m1 0x02
-#define C200ma 0x03
-    
-#define GainAls1Ir1 (0x00<<2)
-#define GainAls2Ir1 (0x04<<2)
-#define GainAls2Ir2 (0x05<<2)
-#define GainAls64Ir64 (0x0A<<2)
-#define GainAls128Ir64 (0x0D<<2)
-#define GainAls128Ir128 (0x0F<<2)
-    
-#define Als0Ps0 0x00
-#define Als0Ps10 0x01
-#define Als0Ps40 0x02
-#define Als0Ps100 0x03    
-#define Als0Ps400 0x04
-    
-#define Als100Ps0 0x05
-#define Als100Ps100 0x06
-#define Als100Ps400 0x07
-    
-#define Als401Ps0 0x08
-#define Als401Ps100 0x09
-#define Als400Ps0 0x0A   
-#define Als400Ps400 0x0B
-    
-#define Als50Ps50 0x0C
-
-
-class Proximity {
-private:
-I2C *proximityi2c;
-short proximityData [NUM_PROXIMIY_SENSORS][3];
-short lastProximityData [NUM_PROXIMIY_SENSORS][3];
-char dataStr[NUM_PROXIMIY_SENSORS*32];
-char muxAddress;
-public:
-    Proximity(void);
-    void init(I2C *i2c, char mAddress);
-    void write_reg(char address,char reg, char cmd);
-    void write(char address, char cmd);
-    unsigned char read_reg(char address,char reg);
-    void off();
-    void on();
-    void scan();
-    bool changed(short delta);
-    short getProximity(int sensor);
-    short getAmbientLight(int sensor);
-    short getIR(int sensor);
-    char* getDataStr();
-};
-
-#endif
\ No newline at end of file
diff -r fe90f1fcb4e0 -r 69966d555de7 SerialBuffered/SerialBuffered.cpp
--- a/SerialBuffered/SerialBuffered.cpp	Wed Nov 30 14:50:16 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,93 +0,0 @@
-
-#include "mbed.h"
-#include "SerialBuffered.h"
-
-SerialBuffered::SerialBuffered( PinName tx, PinName rx, size_t bufferSize ) : Serial(  tx,  rx ) 
-{
-    m_buffSize = 0;
-    m_contentStart = 0;
-    m_contentEnd = 0;
-    m_timeout = -1.0;
-    _txpin = tx;
-    _rxpin = rx;
-    
-    attach( this, &SerialBuffered::handleInterrupt );
-    
-    m_buff = (uint8_t *) malloc( bufferSize );
-    if( m_buff )
-        m_buffSize = bufferSize;
-}
-
-
-SerialBuffered::~SerialBuffered()
-{
-    if( m_buff )
-        free( m_buff );
-}
-
-void SerialBuffered::setTimeout( float seconds )
-{
-    m_timeout = seconds;
-}
-    
-size_t SerialBuffered::readBytes( uint8_t *bytes, size_t requested )
-{
-    int i = 0;
-
-    for( ; i < requested; )
-    {
-        int c = getc();
-        if( c < 0 )
-            break;
-        bytes[i] = c;
-        i++;
-    }
-    
-    return i;
-        
-}
-
-
-int SerialBuffered::_getc()
-{
-    m_timer.reset();
-    m_timer.start();
-    while (m_contentStart == m_contentEnd) {
-        if (m_timeout >= 0 &&  m_timer.read() >= m_timeout )
-            return EOF;
-        wait_ms( 1 );
-    }
-
-    m_timer.stop();
-   
-    int     nbp = (m_contentStart + 1) % m_buffSize;
-    uint8_t result = m_buff[m_contentStart];
-    m_contentStart = nbp;
-    return result;    
-}
-
-//int Serial::_getc() {
-//    return _base_getc();
-//}
-
-int SerialBuffered::_putc(int c) {
-    return _base_putc(c);
-}
-
-int SerialBuffered::readable()
-{
-    return m_contentStart != m_contentEnd ;
-}
-
-void SerialBuffered::handleInterrupt()
-{
-    while (serial_readable(&_serial)) {
-        char c_in = _base_getc();
-        int  nbp = (m_contentEnd + 1) % m_buffSize;
-        
-        if (nbp != m_contentStart) {
-            m_buff[m_contentEnd] = c_in;
-            m_contentEnd = nbp;
-        }
-    }
-}
diff -r fe90f1fcb4e0 -r 69966d555de7 SerialBuffered/SerialBuffered.h
--- a/SerialBuffered/SerialBuffered.h	Wed Nov 30 14:50:16 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-#pragma once
-
-// This is a buffered serial reading class, using the serial interrupt introduced in mbed library version 18 on 17/11/09
-
-// In the simplest case, construct it with a buffer size at least equal to the largest message you 
-// expect your program to receive in one go.
-
-class SerialBuffered : public Serial
-{
-public:
-    SerialBuffered( PinName tx, PinName rx, size_t bufferSize );
-    virtual ~SerialBuffered();
-    
-    int readable(); // returns 1 if there is a character available to read, 0 otherwise
-    
-    void setTimeout( float seconds );    // maximum time in seconds that getc() should block 
-                                         // while waiting for a character
-                                         // Pass -1 to disable the timeout.
-    
-    size_t readBytes( uint8_t *bytes, size_t requested );    // read requested bytes into a buffer, 
-                                                             // return number actually read, 
-                                                             // which may be less than requested if there has been a timeout
-    
-    void disable_flow_ctrl(void) { serial_set_flow_control(&_serial, FlowControlNone, NC, NC); }
-//    void suspend(bool enable) {
-//        if (enable) {
-//            serial_irq_set(&_serial, (SerialIrq)RxIrq, 0);
-//                serial_break_set(&_serial);
-//                _serial.uart->ENABLE         = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos);
-//        } else {
-//                _serial.uart->ENABLE         = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
-//                serial_break_clear(&_serial);
-//            _serial.uart->EVENTS_RXDRDY  = 0;
-//            // dummy write needed or TXDRDY trails write rather than leads write.
-//            //  pins are disconnected so nothing is physically transmitted on the wire
-//            _serial.uart->TXD            = 0;
-//            serial_irq_set(&_serial, (SerialIrq)RxIrq, 1);
-//        }
-//    }
-
-protected:
-    PinName _txpin;
-    PinName _rxpin;
-
-protected:
-    virtual int _getc();
-    virtual int _putc(int c);
-    
-private:
-    
-    void handleInterrupt();
-    
-   
-    uint8_t *m_buff;            // points at a circular buffer, containing data from m_contentStart, for m_contentSize bytes, wrapping when you get to the end
-    volatile uint16_t  m_contentStart;   // index of first bytes of content
-    volatile uint16_t  m_contentEnd;     // index of bytes after last byte of content
-    uint16_t m_buffSize;
-    float m_timeout;
-    Timer m_timer;
-
-};
diff -r fe90f1fcb4e0 -r 69966d555de7 Wnc.cpp
--- a/Wnc.cpp	Wed Nov 30 14:50:16 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,627 +0,0 @@
-#include "Wnc.h"
-#include "mbed.h"
-#include <cctype>
-#include "config_me.h"
-#include "SerialBuffered.h"
-
-
-extern Serial pc;
-
-DigitalOut  mdm_uart2_rx_boot_mode_sel(PTC17);  // on powerup, 0 = boot mode, 1 = normal boot
-DigitalOut  mdm_power_on(PTB9);                 // 0 = turn modem on, 1 = turn modem off (should be held high for >5 seconds to cycle modem)
-DigitalInOut  mdm_wakeup_in(PTC2);                // 0 = let modem sleep, 1 = keep modem awake -- Note: pulled high on shield
-
-DigitalOut  mdm_reset(PTC12);                   // active high      
-
-DigitalOut  shield_3v3_1v8_sig_trans_ena(PTC4); // 0 = disabled (all signals high impedence, 1 = translation active
-DigitalOut  mdm_uart1_cts(PTD0);
-
-DigitalOut uart1Rts(PTD1);
-
-SerialBuffered mdm(PTD3, PTD2, 512);
-
-int t3412Timer = 4*60*60;
-int t3324Timer = 20;
-bool powerSave = false;
-
-
-Wnc::Wnc(void)
-{
-}
-
-void Wnc::checkPassthrough()
-{
-    if(pc.readable())
-    {
-        if(pc.getc() == '~')
-        passthrough();
-    }
-}
-               
-
-void Wnc::passthrough()
-{
-    pc.printf(">>\r\n");
-    while(1)
-    {
-        char c;
-        if(pc.readable())
-        {
-            c =  pc.getc();
-            pc.putc(c);
-            if(c == '~')
-            {
-                pc.printf("exit\r\n");
-                 break;
-            }
-            else if(c == '<')
-            {
-                
-                 mdm_wakeup_in = 0;
-                 pc.printf("sleep\r\n");
-            }
-            else if(c == '>')
-            {
-                 mdm_wakeup_in = 1;
-                 pc.printf("wake\r\n");
-            }
-            else if(c == '}')
-            {
-                 mdm_uart2_rx_boot_mode_sel = 1;
-                 pc.printf("rx hi\r\n");
-            }
-            else if(c == '{')
-            {
-                 mdm_uart2_rx_boot_mode_sel = 0;
-                 pc.printf("rx low\r\n");
-            }
-
-            else if(c == '^')
-            {
-                pc.printf("reboot\r\n");
-                NVIC_SystemReset();
-            }
-            else
-            {
-               
-                mdm.putc(c);
-            }
-        }
-        if(mdm.readable())
-            pc.putc(mdm.getc());
-    }
-}
-
-bool Wnc::isPowerSaveOn()
-{
-    return powerSave;
-}
-
-void Wnc::resumePowerSave()
-{
-    mdm_wakeup_in = 0;
-}
-
-int Wnc::gett3412Timer()
-{
-    return t3412Timer;
-}
-
-int Wnc::gett3324Timer()
-{
-    return t3324Timer;
-}
-
-char* Wnc::read(int timeout_ms)
-{
-    static char response[3200]; 
-    int len = 0;
-    char c;
-    
-    if(timeout_ms > 0) // read until timeout or OK
-    {
-        Timer timer;
-        timer.start();
-        while ((len < (3200-1)) && (timer.read_ms() < timeout_ms)) {
-            if (mdm.readable()) {
-                c = mdm.getc();
-                // replace \r\n to make debug messages more compact
-                if(c == '\r') c = ' ';
-                if(c == '\n') c = ' ';
-                
-                response[len++] = c;
-                if(len>1 && response[len-2] == 'O' && response[len-1] == 'K')
-                    break;
-
-            }
-        }
-    }
- 
-    response[len] = (char)NULL;
-    pc.printf("{%d %s}\r\n",len,response);
-    return response;
-}
-
-char* Wnc::send(const char *cmd, int timeout_ms)
-{
-    char *reply;
-    
-    while (mdm.readable()) {
-         mdm.getc();
-    }
-        
-    int tries = 4;
-    while(tries > 0)
-    {
-        tries--;        
-        pc.printf("\r\n<%s>",cmd);
-        const char *pt = cmd;
-        size_t n = strlen(cmd);
-        while (n--) {
-            mdm.putc(*pt++);
-        };
-        mdm.putc('\r');
-        mdm.putc('\n');
-        reply = read(timeout_ms);
-        if(strlen(reply) > 0 && strstr(reply,"OK") !=0)
-            break; 
-        checkPassthrough();
-    }
-    return reply;
-}
-
-bool Wnc::isModemResponding()
-{    
-    char *reply = send("AT",WNC_WAIT_TIME_MS);
-    if(strlen(reply) > 0 && strstr(reply,"OK") !=0)
-        return true;
-    return false;
-}
-
-void Wnc::setIn()
-{
-    mdm_wakeup_in.input();
-}
-
-void Wnc::toggleWake()
-{
-    mdm_wakeup_in = 0;
-    wait_ms(2000);  
-    mdm_wakeup_in = 0; 
-}
-
-bool Wnc::init(void) {
-    uart1Rts = 0;
-    mdm_wakeup_in.output();
-    // disable signal level translator (necessary
-    // for the modem to boot properly)
-    shield_3v3_1v8_sig_trans_ena = 0;
-
-    // Hard reset the modem (doesn't go through
-    // the signal level translator)
-    mdm_reset = 1;
-    
-   // wait a moment for the modem to react
-    wait_ms(10);
-    
-    // Let modem boot
-    mdm_reset = 0;
-    
-    // wait a moment for the modem to react
-    wait(1.0);
-    
-    // power modem on //off
-    mdm_power_on = 0; //1;
-    
-    // insure modem boots into normal operating mode
-    // and does not go to sleep when powered on
-    mdm_uart2_rx_boot_mode_sel = 1;
-    mdm_wakeup_in = 1;
-    
-    // initialze comm with the modem
-    mdm.baud(115200);
-    // clear out potential garbage
-    while (mdm.readable())
-      mdm.getc();
-
-    mdm_uart1_cts = 0;
-    
-    // wait a moment for the modem to react to signal
-    // conditions while the level translator is disabled
-    // (sorry, don't have enough information to know
-    // what exactly the modem is doing with the current
-    // pin settings)
-    wait(1.0);
-
-    // enable the signal level translator to start
-    // modem reset process (modem will be powered down)
-    shield_3v3_1v8_sig_trans_ena = 1;
-    
-    // Give the modem 60 secons to start responding by
-    // sending simple 'AT' commands to modem once per second.
-    Timer timer;
-    timer.start();
-    while (timer.read() < 60) {
-        SetLedColor(0x1); //red     
-        if(isModemResponding())
-        {
-            SetLedColor(0);
-            //mdm_uart2_rx_boot_mode_sel = 0;
-            return true; 
-        }
-        SetLedColor(0); //off
-        wait_ms(1000 - (timer.read_ms() % 1000));
-        pc.printf("\r%d",timer.read_ms()/1000);
-         
-    }
-    return false;       
-}
-int Wnc::secToTau(int time)
-{
-    /*
-    0 - value is incremented in multiples of 10 minutes
-    1 - value is incremented in multiples of 1 hour
-    2 - value is incremented in multiples of 10 hours
-    3 - value is incremented in multiples of 2 seconds
-    4 - value is incremented in multiples of 30 seconds
-    5 - value is incremented in multiples of 1 minute
-*/
-    if(time/2 < 32)
-    {
-        return (0x3<<5)+time/2;
-    }
-    else if(time/30 < 32)
-    {
-        return (0x4<<5)+time/30;
-    }
-    else if(time/60 < 32)
-    {
-        return (0x5<<5)+time/60;
-    }
-    else if(time/3600 < 32)
-    {
-        return (0x1<<5)+time/3600;
-    }
-    else if(time/36000 < 32)
-    {
-        return (0x2<<5)+time/36000;
-    }
-    else
-        return (0x7<<5);
-        
-
-}
-int Wnc::secToActivity(int time)
-{
-    /*
-    0 - value is incremented in multiples of 2 seconds
-    1 - value is incremented in multiples of 1 minute
-    2 - value is incremented in multiples of decihours
-    7 - value indicates that the timer is deactivated.
-    */
-    if(time/2 < 32)
-    {
-        return (0x0<<5)+time/2;
-    }
-    else if(time/60 < 32)
-    {
-        return (0x1<<5)+time/60;
-    }
-    else if(time/36000 < 32)
-    {
-        return (0x2<<5)+time/36000;
-    }
-    else
-        return (0x7<<5);
-
-}    
-void Wnc::setPowerSave(bool on,int t3412,int t3324)
-{
-    if(on)
-    {
-        t3412Timer = t3412;
-        t3324Timer = t3324;
-        int tau = secToTau(t3412);
-        int activity = secToActivity(t3324);
-        mdm_wakeup_in = 0; //allow power sleep mode
-        powerSave = true;
-        char cmd[32];
-        snprintf(cmd,sizeof(cmd),"AT+CPSMS=1,,,%d,%d",tau,activity);
-        send(cmd,  WNC_WAIT_TIME_MS);
-    }
-    else
-    {
-        mdm_wakeup_in = 1; //disallow power sleep mode
-        powerSave = false;
-        send("AT+CPSMS=0",  WNC_WAIT_TIME_MS);
-    }
-}
-
-char* Wnc::getIccid()
-{
-    static char iccidBuf[32];
-    iccidBuf[0] = NULL;
-    char* reply = send("AT%CCID",500);
-    int index = 0;
-    int begin = -1;
-    int i = 0;
-
-    while (reply[index]) { // While there are more characters to process...
-        if (begin == -1 && isdigit(reply[index])) { // Upon finding a digit, ...
-            begin = index;
-        }
-        if(begin != -1)
-        { 
-            if(isdigit(reply[index]))
-            { 
-                iccidBuf[i++] = reply[index];
-            }
-            else
-            {
-                iccidBuf[i++] = NULL;
-                return iccidBuf;
-            }
-        }
-        index++;
-    }
-    return iccidBuf;
-}
-
-void Wnc::wakeFromPowerSave()
-{
-    mdm_wakeup_in = 1;
-    pc.printf("wake from power save\r\n");
-}
-
-bool Wnc::cmdFailed(char* reply,char* msg)
-{
-    if(strstr(reply,"OK") > 0)
-        return false;
-    pc.printf("%s\r\n",msg);
-    return true;
-}
-    
-bool Wnc::startInternet()
-{
-  char *reply;
-  reply = send("ATE1",WNC_WAIT_TIME_MS);           // Echo ON
-  char apn [32];
-  snprintf(apn,sizeof(apn),"AT%%PDNSET=1,%s,IP",MY_APN_STR);
-
-  reply = send(apn, 2*WNC_WAIT_TIME_MS); // Set APN, cmd seems to take a little longer sometimes
-  if(cmdFailed(reply,"Failed to set APN")) return false;
-
-  reply = send("AT%PDNSET?",  WNC_WAIT_TIME_MS);
-  
- // pc.printf("Wiating ...\r\n");
- // wait(10);
-  
-  reply = send("AT@INTERNET=1",  WNC_WAIT_TIME_MS);  // Internet services enabled
-  if(cmdFailed(reply,"Failed to start INTERNET"))
-  {
-    return false;
-  }
-  reply = send("AT@SOCKDIAL=1",  WNC_WAIT_TIME_MS);
-  if(cmdFailed(reply,"SOCKDIAL Failed")) 
-  {
-     // passthrough();
-      return false;
-  }
-  return true;
-}
-
-char* Wnc::ping(char* ip)
-{
-    char cmd[32];
-    snprintf(cmd,sizeof(cmd),"AT@PINGREQ=\"%s\"",ip);
-    return send(cmd,WNC_WAIT_TIME_MS);
-}
-
-bool Wnc::connect(char* ip, int port)
-{
-  char *reply;
-
-    for(int i = 0;i<2;i++)
-    {
-       if(isModemResponding()) 
-         break;
-       wait(0.5);
-    }
-    
-    if(isModemResponding())
-    {
-        reply = send("AT@SOCKCREAT=1", WNC_WAIT_TIME_MS);
-        if(cmdFailed(reply,"Socket Create Failed")) return false;
-    }
-    else
-    {
-        pc.printf("Error Modem not responding\r\n");
-        return false;
-    }
-
-    
-    char cmd[64];
-
-    snprintf(cmd,sizeof(cmd),"AT@SOCKCONN=1,\"%s\",%d",ip,port);
-    reply = send(cmd,12*WNC_WAIT_TIME_MS);
-    if(cmdFailed(reply,"Socket Connect Failed")) return false;
-    
-    for(int i = 0;i<10;i++)
-    {
-        reply = send("AT+CREG?",WNC_WAIT_TIME_MS);
-        if(strlen(reply) > 0 && strstr(reply,"2,1") != 0)
-        {
-             pc.printf("Connected %s\r\n",reply);
-            return true;
-        }
-        else
-        {
-            pc.printf("Unconnected %s\r\n",reply);
-        }
-        wait(1);
-    }
-    return false;
-}
-
-void Wnc::disconnect()
-{
-     send("AT@SOCKCLOSE=1", WNC_WAIT_TIME_MS);
-}
-
-char* Wnc::encode(int value, char* result, int base)                                                                                                          
-{                                                                                                                                                        
-    // check that the base if valid                                                                                                                      
-    if ( base < 2 || base > 36 ) {                                                                                                                       
-        *result = '\0';                                                                                                                                  
-        return result;                                                                                                                                   
-    }                                                                                                                                                    
- 
-    char* ptr = result, *ptr1 = result, tmp_char;                                                                                                        
-    int tmp_value;                                                                                                                                       
- 
-    do {                                                                                                                                                 
-        tmp_value = value;                                                                                                                               
-        value /= base;                                                                                                                                   
-        *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)];                             
-    } while ( value );                                                                                                                                   
- 
-    // Apply negative sign                                                                                                                               
-    if ( tmp_value < 0 )                                                                                                                                 
-    *ptr++ = '-';                                                                                                                                    
-    *ptr-- = '\0';                                                                                                                                       
- 
-    while ( ptr1 < ptr ) {                                                                                                                               
-    tmp_char = *ptr;                                                                                                                                 
-    *ptr-- = *ptr1;                                                                                                                                  
-    *ptr1++ = tmp_char;                                                                                                                              
-    }                                                                                                                                                    
-    return result;                                                                                                                                       
-}
-
-bool Wnc::writeSocket(const char * s)
-{
-
-  char num2str[6];
-  size_t sLen = strlen(s);
-  if (sLen <= 99999)
-  {
-    char cmd[sLen*2+32];
-    int index = snprintf(cmd,sizeof(cmd),"AT@SOCKWRITE=1,%d,\"",sLen);
-
-    while(*s != '\0')
-    {
-      encode((int)*s++, num2str, 16);
-      // Always 2-digit ascii hex:
-      if (strlen(num2str) == 1)
-      {
-        num2str[2] = '\0';
-        num2str[1] = num2str[0];
-        num2str[0] = '0';
-      }
-      cmd[index++] = num2str[0];
-      cmd[index++] = num2str[1];
-    }
-    cmd[index++] =  '"';
-    cmd[index] = '\0';
-    char* reply = send(cmd, WNC_WAIT_TIME_MS);
-    if(cmdFailed(reply,"Send Failed")) return false;
-    return true;
-  }
-  else
-  {
-    pc.puts("sockwrite Err, string to long\r\n");
-    return false;
-  }
-
-}
-
-int Wnc::hex_to_int(char A)
-{
-    return (A > '9')? (A &~ 0x20) - 'A' + 10: (A - '0');
-}
-
-int Wnc::hex_to_ascii(char h, char l)
-{  
-    return hex_to_int(h) * 16 + hex_to_int(l);      
-}
-
-int Wnc::indexOf(char* str, char c)
-{
-    int index = 0;
-    while(str[index] != 0)
-    {
-        if(str[index] == c)
-            return index;
-        index++;
-    }
-    return -1;
-}
-
-char* Wnc::readSocket()
-{
-
-     static char data[1000];
-     int i = 0;
-     char *reply;
-     reply = send("AT@SOCKREAD=1,1024",1000);
-     if(strlen(reply) > 0)
-     {
-        int pos_start = indexOf(reply,'"');
- 
-        if(pos_start > 0)
-        {
-            pos_start+=1;
-            int length  = indexOf(&reply[pos_start],'"');
-
-            if(length > 0)
-            {
-                char hi;
-                char low;
-                for(i = 0; i < length; i++){
-                    if(i % 2 != 0){
-                        low = reply[pos_start++];
-                        data[i/2] = (char) hex_to_ascii(hi,low);
-                    }else{
-                        hi = reply[pos_start++];
-                    }
-                }
-                data[length/2] = NULL;
-            }
-        }
-    }
-    data[i] = NULL;
-    return data;
-}
-
-char* Wnc::resolveDn(const char* name)
-{
-    char cmd[64];
-
-    snprintf(cmd,sizeof(cmd),"AT@DNSRESVDON=\"%s\"",name);
-    char* reply = send(cmd,12*WNC_WAIT_TIME_MS);
-    static char ipBuf[32];
-    ipBuf[0] = NULL; 
-    int index = 0;
-    int begin = -1;
-    int i = 0;
-
-    while (reply[index]) { // While there are more characters to process...
-        if (begin == -1 && isdigit(reply[index])) { // Upon finding a digit, ...
-            begin = index;
-        }
-        if(begin != -1)
-        { 
-            if(isdigit(reply[index]) || reply[index] == '.')
-            { 
-                ipBuf[i++] = reply[index];
-            }
-            else
-            {
-                ipBuf[i++] = NULL;
-                return ipBuf;
-            }
-        }
-        index++;
-    }
-    return ipBuf; 
-}
\ No newline at end of file
diff -r fe90f1fcb4e0 -r 69966d555de7 Wnc.h
--- a/Wnc.h	Wed Nov 30 14:50:16 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-
-#ifndef Wnc_
-#define Wnc_
-
-#define WNC_WAIT_TIME_MS 500
-
-
-extern void SetLedColor(unsigned char ucColor);
-
-
-class Wnc {
-public:
-    Wnc(void);
-    bool init(void);
-    bool isModemResponding();
-
-    char* read(int timeout_ms);
-    char* send(const char *cmd, int timeout_ms);
-    
-    
-    void setPowerSave(bool on,int t3412,int t3324);
-    void resumePowerSave();
-    bool isPowerSaveOn();
-    int gett3412Timer();
-    int gett3324Timer();
-    void wakeFromPowerSave();
-    
-    char* getIccid();
-    bool startInternet();
-    bool connect(char* ip, int port);
-    void disconnect();
-    bool writeSocket(const char * s);
-    char* readSocket();
-    char* ping(char* ip);
-    void setIn();
-    void passthrough();
-    void checkPassthrough();
-    void toggleWake();
-    char* resolveDn(const char* name);
-    bool cmdFailed(char* reply,char* msg);
-    
-private:
-    int secToTau(int time);
-    int secToActivity(int time);
-    int hex_to_int(char c);
-    int hex_to_ascii(char h, char l);
-    int indexOf(char* str, char c);
-    char* encode(int value, char* result, int base);
-};
-
-#endif
\ No newline at end of file
diff -r fe90f1fcb4e0 -r 69966d555de7 config_me.h
--- a/config_me.h	Wed Nov 30 14:50:16 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-#ifndef __CONFIG_ME_H_
-#define __CONFIG_ME_H_
-
-// User must set these for own context:
-
-// This is the server's base URL name.  Example "www.google.com"
-// Note that when you Fork a FLOW, it will typically assign  either
-// "run-east.att.io" or "run-west.att.io", so be sure to check this.
-static const char * MY_SERVER_URL       = "run-east.att.io";
-
-// These are FLOW fields from the Endpoints tab:
-#define FLOW_BASE_URL                   "/a80556051c438/f4cd2ed65f73/7ecb40fcd115f7a/in/flow"
-#define FLOW_INPUT_NAME                 "/shelf"
-//#define FLOW_BASE_URL                   "/d87b3ed23c5ca/93177ca6df10/cf972daf89febc2/in/flow"
-//#define FLOW_INPUT_NAME                 "/car"
-// Unless you want to use a different protocol, this field should be left as is:
-#define FLOW_URL_TYPE                   " HTTP/1.1\r\nHost: "
-
-// This identifier specifies with which FLOW device you are communicating. 
-// If you only have one devive there then you can just leave this as is.
-// Once your FLOW device has been initialized (Virtual Device Initialize clicked),
-// the Virtual Device will show up in M2X.  This is its "DEVICE SERIAL" field
-#define FLOW_DEVICE_NAME                "vstarterkit001"
-
-// This constant defines how often sensors are read and sent up to FLOW
-#define SENSOR_UPDATE_INTERVAL_MS       5000; //5 seconds
-
-// Specify here how many sensor parameters you want reported to FLOW.
-// You can use only the temperature and humidity from the shield HTS221
-// or you can add the reading of the FXO8700CQ motion sensor on the FRDM-K64F board
-// or if you have a SiLabs PMOD plugged into the shield, you can add its proximity sensor,
-// UV light, visible ambient light and infrared ambient light readings
-#define TEMP_HUMIDITY_ONLY                      1
-#define TEMP_HUMIDITY_ACCELEROMETER             2
-#define TEMP_HUMIDITY_ACCELEROMETER_PMODSENSORS 3
-#define PROXIMITY_ONLY 4
-#define SWITCH_ONLY 5
-static int iSensorsToReport = PROXIMITY_ONLY; //TEMP_HUMIDITY_ONLY; //modify this to change your selection
-
-// This is the APN name for the cellular network, you will need to change this, check the instructions included with your SIM card kit:
-//#define  MY_APN_STR  "m2m.com.attz"
-#define  MY_APN_STR  "attiotdemo"
-//#define  MY_APN_STR  "nxtgenphone"
-//This is for normal HTTP.  If you want to use TCP to a specific port, change that here:
-static int MY_PORT         = 80;
-
-#endif
diff -r fe90f1fcb4e0 -r 69966d555de7 hardware.h
--- a/hardware.h	Wed Nov 30 14:50:16 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-#ifndef Hardware_H_
-#define Hardware_H_
-extern I2C i2c;    //SDA, SCL -- define the I2C pins being used
-
-#endif
diff -r fe90f1fcb4e0 -r 69966d555de7 hts221_driver.cpp
--- a/hts221_driver.cpp	Wed Nov 30 14:50:16 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,249 +0,0 @@
-
-#include "HTS221.h"
-
-
-// ------------------------------------------------------------------------------
-//jmf  -- define I2C pins and functions to read & write to I2C device
-
-#include <string>
-#include "mbed.h"
-
-#include "hardware.h"
-//I2C i2c(PTC11, PTC10);    //SDA, SCL -- define the I2C pins being used. Defined in a 
-//common locatioin since sensors also use I2C
-
-// Read a single unsigned char from addressToRead and return it as a unsigned char
-unsigned char HTS221::readRegister(unsigned char slaveAddress, unsigned char ToRead)
-{
-    char data = ToRead;
-
-    i2c.write(slaveAddress, &data, 1, 1);
-    i2c.read(slaveAddress, &data, 1, 0);
-    return data;
-}
-
-// Writes a single unsigned char (dataToWrite) into regToWrite
-int HTS221::writeRegister(unsigned char slaveAddress, unsigned char regToWrite, unsigned char dataToWrite)
-{
-    const char data[] = {regToWrite, dataToWrite};
-
-    return i2c.write(slaveAddress,data,2,0);
-}
-
-
-//jmf end
-// ------------------------------------------------------------------------------
-
-//static inline int humidityReady(uint8_t data) {
-//    return (data & 0x02);
-//}
-//static inline int temperatureReady(uint8_t data) {
-//    return (data & 0x01);
-//}
-
-
-HTS221::HTS221(void) : _address(HTS221_ADDRESS)
-{
-    _temperature = 0;
-    _humidity = 0;
-}
-
-
-int HTS221::begin(void)
-{
-    uint8_t data;
-
-    data = readRegister(_address, WHO_AM_I);
-    if (data == WHO_AM_I_RETURN){
-        if (activate()){
-            storeCalibration();
-            return data;
-        }
-    }
-
-    return 0;
-}
-
-int
-HTS221::storeCalibration(void)
-{
-    uint8_t data;
-    uint16_t tmp;
-
-    for (int reg=CALIB_START; reg<=CALIB_END; reg++) {
-        if ((reg!=CALIB_START+8) && (reg!=CALIB_START+9) && (reg!=CALIB_START+4)) {
-
-            data = readRegister(HTS221_ADDRESS, reg);
-
-            switch (reg) {
-            case CALIB_START:
-                _h0_rH = data;
-                break;
-            case CALIB_START+1:
-            _h1_rH = data;
-            break;
-            case CALIB_START+2:
-            _T0_degC = data;
-            break;
-            case CALIB_START+3:
-            _T1_degC = data;
-            break;
-
-            case CALIB_START+5:
-            tmp = _T0_degC;
-            _T0_degC = (data&0x3)<<8;
-            _T0_degC |= tmp;
-
-            tmp = _T1_degC;
-            _T1_degC = ((data&0xC)>>2)<<8;
-            _T1_degC |= tmp;
-            break;
-            case CALIB_START+6:
-            _H0_T0 = data;
-            break;
-            case CALIB_START+7:
-            _H0_T0 |= data<<8;
-            break;
-            case CALIB_START+0xA:
-            _H1_T0 = data;
-            break;
-            case CALIB_START+0xB:
-            _H1_T0 |= data <<8;
-            break;
-            case CALIB_START+0xC:
-            _T0_OUT = data;
-            break;
-            case CALIB_START+0xD:
-            _T0_OUT |= data << 8;
-            break;
-            case CALIB_START+0xE:
-            _T1_OUT = data;
-            break;
-            case CALIB_START+0xF:
-            _T1_OUT |= data << 8;
-            break;
-
-
-            case CALIB_START+8:
-            case CALIB_START+9:
-            case CALIB_START+4:
-            //DO NOTHING
-            break;
-
-            // to cover any possible error
-            default:
-                return false;
-            } /* switch */
-        } /* if */
-    }  /* for */
-    return true;
-}
-
-
-int
-HTS221::activate(void)
-{
-    uint8_t data;
-
-    data = readRegister(_address, CTRL_REG1);
-    data |= POWER_UP;
-    data |= ODR0_SET;
-    writeRegister(_address, CTRL_REG1, data);
-
-    return true;
-}
-
-
-int HTS221::deactivate(void)
-{
-    uint8_t data;
-
-    data = readRegister(_address, CTRL_REG1);
-    data &= ~POWER_UP;
-    writeRegister(_address, CTRL_REG1, data);
-    return true;
-}
-
-
-int
-HTS221::bduActivate(void)
-{
-    uint8_t data;
-
-    data = readRegister(_address, CTRL_REG1);
-    data |= BDU_SET;
-    writeRegister(_address, CTRL_REG1, data);
-
-    return true;
-}
-
-
-int
-HTS221::bduDeactivate(void)
-{
-    uint8_t data;
-
-    data = readRegister(_address, CTRL_REG1);
-    data &= ~BDU_SET;
-    writeRegister(_address, CTRL_REG1, data);
-    return true;
-}
-
-
-int
-HTS221::readHumidity(void)
-{
-    uint8_t data   = 0;
-    uint16_t h_out = 0;
-    double h_temp  = 0.0;
-    double hum     = 0.0;
-
-    data = readRegister(_address, STATUS_REG);
-
-    if (data & HUMIDITY_READY) {
-        data = readRegister(_address, HUMIDITY_H_REG);
-        h_out = data << 8;  // MSB
-        data = readRegister(_address, HUMIDITY_L_REG);
-        h_out |= data;      // LSB
-
-        // Decode Humidity
-        hum = ((int16_t)(_h1_rH) - (int16_t)(_h0_rH))/2.0;  // remove x2 multiple
-
-        // Calculate humidity in decimal of grade centigrades i.e. 15.0 = 150.
-        h_temp = (((int16_t)h_out - (int16_t)_H0_T0) * hum) / ((int16_t)_H1_T0 - (int16_t)_H0_T0);
-        hum    = ((int16_t)_h0_rH) / 2.0; // remove x2 multiple
-        _humidity = (int16_t)((hum + h_temp)); // provide signed % measurement unit
-    }
-    return _humidity;
-}
-
-
-
-double
-HTS221::readTemperature(void)
-{
-    uint8_t data   = 0;
-    uint16_t t_out = 0;
-    double t_temp  = 0.0;
-    double deg     = 0.0;
-
-    data = readRegister(_address, STATUS_REG);
-
-    if (data & TEMPERATURE_READY) {
-
-        data= readRegister(_address, TEMP_H_REG);
-        t_out = data  << 8; // MSB
-        data = readRegister(_address, TEMP_L_REG);
-        t_out |= data;      // LSB
-
-        // Decode Temperature
-        deg    = ((int16_t)(_T1_degC) - (int16_t)(_T0_degC))/8.0; // remove x8 multiple
-
-        // Calculate Temperature in decimal of grade centigrades i.e. 15.0 = 150.
-        t_temp = (((int16_t)t_out - (int16_t)_T0_OUT) * deg) / ((int16_t)_T1_OUT - (int16_t)_T0_OUT);
-        deg    = ((int16_t)_T0_degC) / 8.0;     // remove x8 multiple
-        _temperature = deg + t_temp;   // provide signed celsius measurement unit
-    }
-
-    return _temperature;
-}
diff -r fe90f1fcb4e0 -r 69966d555de7 main.cpp
--- a/main.cpp	Wed Nov 30 14:50:16 2016 +0000
+++ b/main.cpp	Fri Apr 21 17:58:35 2017 +0000
@@ -1,30 +1,13 @@
 #include "mbed.h"
 #include <cctype>
-#include "SerialBuffered.h"
-#include "HTS221.h"
-#include "config_me.h"
-#include "sensors.h"
-#include "Proximity.h"
-#include "Wnc.h"
-
-#include "hardware.h"
 #include "att160826.h"
 
-extern SerialBuffered mdm;
-Wnc wnc;
-
-I2C i2c(PTC11, PTC10);    //SDA, SCL -- define the I2C pins being used
 I2C *myi2c;
 
-#define PROXIMITYON 1
-
-#if PROXIMITYON == 1
 att160826_data_t strip_data[2];
 att160826_data_t last_data[2];
-ATT160826 *strips[2];
-#elif PROXIMITYON == 2
-Proximity proximityStrip[2];
-#endif
+ATT160826 *strips[4];
+
 
 // comment out the following line if color is not supported on the terminal
 #define USE_COLOR
@@ -50,16 +33,6 @@
  #define DEF
 #endif
 
-#define MDM_DBG_OFF                             0
-#define MDM_DBG_AT_CMDS                         (1 << 0)
-
-
-
-
-
-
-
-int mdm_dbgmask = MDM_DBG_OFF;
 
 Serial         pc(USBTX, USBRX);
 
@@ -68,29 +41,8 @@
 DigitalOut led_blue(LED_BLUE);
 
 
-
-
-
-DigitalIn   slot1(PTB3,PullUp);
-DigitalIn   slot2(PTB10,PullUp);
-DigitalIn   slot3(PTB11,PullUp);
-
-DigitalIn   sw2(SW2);
+bool toggleLed = false;
 
-int lastSlot1;
-int lastSlot2;
-int lastSlot3;
-char *iccid;
-#define TOUPPER(a) (a) //toupper(a)
-
-
-#define MDM_OK                                  0
-#define MDM_ERR_TIMEOUT                         -1
-
-#define MAX_AT_RSP_LEN                          255
-
-bool toggleLed = false;
-int seqNum;
 
 
 //********************************************************************************************************************************************
@@ -99,481 +51,74 @@
 //********************************************************************************************************************************************
 void SetLedColor(unsigned char ucColor)
 {
-    if(wnc.isPowerSaveOn()) 
-    {
-        led_red = !0;
-        led_green = !0;
-        led_blue = !(ucColor & 0x4);
-    }
-    else
-    {
-        //Note that when an LED is on, you write a 0 to it:
-        led_red = !(ucColor & 0x1); //bit 0
-        led_green = !(ucColor & 0x2); //bit 1
-        led_blue = !(ucColor & 0x4); //bit 2
-    }
-} //SetLedColor() 
-
-
-void system_reset()
-{
-    //wnc.passthrough();
-    printf(RED "\n\rSystem resetting..." DEF "\n");
-    NVIC_SystemReset();
-}
 
-
-#define CTOF(x)  ((x)*1.8+32)
+    led_red = !(ucColor & 0x1); //bit 0
+    led_green = !(ucColor & 0x2); //bit 1
+    led_blue = !(ucColor & 0x4); //bit 2
 
-//********************************************************************************************************************************************
-//* Create string with sensor readings that can be sent to flow as an HTTP get
-//********************************************************************************************************************************************
-K64F_Sensors_t  SENSOR_DATA =
-{
-    .Temperature        = "0",
-    .Humidity           = "0",
-    .AccelX             = "0",
-    .AccelY             = "0",
-    .AccelZ             = "0",
-    .MagnetometerX      = "0",
-    .MagnetometerY      = "0",
-    .MagnetometerZ      = "0",
-    .AmbientLightVis    = "0",
-    .AmbientLightIr     = "0",
-    .UVindex            = "0",
-    .Proximity          = "0",
-    .Temperature_Si7020 = "0",
-    .Humidity_Si7020    = "0"
-};
+} //SetLedColor() 
 
 
 
-void GenerateModemString(char * modem_string,int sensor,int strip)
-{
-    switch(sensor)
-    {
-#if PROXIMITYON == 1
-
-        case PROXIMITY_ONLY:
-        {
-            if(strip == -1)
-            {
-                seqNum++;
-                sprintf(modem_string, "GET %s%s?ver=cat1&strip=%d&serial=%s&seq=%d&psm=%d&T=%d&t=%d %s%s\r\n\r\n", FLOW_BASE_URL, "/shelf", strip, iccid, seqNum, wnc.isPowerSaveOn(),wnc.gett3412Timer(),wnc.gett3324Timer(),FLOW_URL_TYPE, MY_SERVER_URL);
-                break;
-            }
-            int stripIndex = 0;
-            if(strip == 3)
-                stripIndex = 1;
-            char data[256];
-            int i=0;
-            int index = 0;
-            index += sprintf(&data[index],"[");
-            for (i=1; i<SENSORS_PER_STRIP; i++)
-            {
-                short  p = last_data[stripIndex].sensor[i].sample.prox;
-                short l = last_data[stripIndex].sensor[i].sample.als_vis;
-                short r = last_data[stripIndex].sensor[i].sample.als_ir;
-                if(i<SENSORS_PER_STRIP-1)
-                    index += snprintf(&data[index], 128, "{\"s\":%d,\"p\":%d,\"l\":%d,\"r\":%d},", i,p,l,r);
-                else
-                    index += snprintf(&data[index], 128, "{\"s\":%d,\"p\":%d,\"l\":%d,\"r\":%d}]", i,p,l,r);
-
-            } 
-            
-
-            seqNum++;
-            sprintf(modem_string, "GET %s%s?ver=cat1&strip=%d&serial=%s&seq=%d&psm=%d&T=%d&t=%d&data=%s %s%s\r\n\r\n", FLOW_BASE_URL, "/shelf", strip, iccid, seqNum, wnc.isPowerSaveOn(),wnc.gett3412Timer(),wnc.gett3324Timer(), data,  FLOW_URL_TYPE, MY_SERVER_URL);
-            break;
-        }
-#elif PROXIMITYON == 2
-        case PROXIMITY_ONLY:
-        {
-
-            char* data0 = proximityStrip[0].getDataStr();
-            char* data1 = proximityStrip[1].getDataStr();
-            seqNum++;
-            sprintf(modem_string, "GET %s%s?serial=%s&seq=%d&data=%s&data1=%s %s%s\r\n\r\n", FLOW_BASE_URL, "/shelf", iccid, seqNum, data0,data1,  FLOW_URL_TYPE, MY_SERVER_URL);
-            break;
-        }
-#endif
-        case SWITCH_ONLY:
-        {
-            char data[32];
-            sprintf(data,"[{\"p\":%d},{\"p\":%d},{\"p\":%d}]",lastSlot1*26,lastSlot2*26,lastSlot3*26);
-            seqNum++;
-            sprintf(modem_string, "GET %s%s?serial=%s&seq=%d&data=%s %s%s\r\n\r\n", FLOW_BASE_URL, "/car", iccid, seqNum, data,  FLOW_URL_TYPE, MY_SERVER_URL);
-            break;
-        }
-        case TEMP_HUMIDITY_ONLY:
-        {
-            sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, FLOW_URL_TYPE, MY_SERVER_URL);
-            break;
-        }
-        case TEMP_HUMIDITY_ACCELEROMETER:
-        {
-            sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, SENSOR_DATA.AccelX,SENSOR_DATA.AccelY,SENSOR_DATA.AccelZ, FLOW_URL_TYPE, MY_SERVER_URL);
-            break;
-        }
-        case TEMP_HUMIDITY_ACCELEROMETER_PMODSENSORS:
-        {
-            sprintf(modem_string, "GET %s%s?serial=%s&temp=%s&humidity=%s&accelX=%s&accelY=%s&accelZ=%s&proximity=%s&light_uv=%s&light_vis=%s&light_ir=%s %s%s\r\n\r\n", FLOW_BASE_URL, FLOW_INPUT_NAME, FLOW_DEVICE_NAME, SENSOR_DATA.Temperature, SENSOR_DATA.Humidity, SENSOR_DATA.AccelX,SENSOR_DATA.AccelY,SENSOR_DATA.AccelZ, SENSOR_DATA.Proximity, SENSOR_DATA.UVindex, SENSOR_DATA.AmbientLightVis, SENSOR_DATA.AmbientLightIr, FLOW_URL_TYPE, MY_SERVER_URL);
-            break;
-        }
-        default:
-        {
-            sprintf(modem_string, "Invalid sensor selected\r\n\r\n");
-            break;
-        }
-    } //switch(iSensorsToReport)
-} //GenerateModemString        
-            
-            
-//********************************************************************************************************************************************
-//* Process JSON response messages
-//********************************************************************************************************************************************
-bool extract_reply(char* search_field, char* found_string)
-{
-    char* beginquote;
-    char* endquote;
-    beginquote = strstr(search_field, "\r\n\r\n"); //start of data
-    endquote = strchr(search_field, '\0');
-    if (beginquote != 0)
-    {
-        uint16_t ifoundlen;
-        if (endquote != 0)
-        {
-            ifoundlen = (uint16_t) (endquote - beginquote) + 1;
-            strncpy(found_string, beginquote, ifoundlen );
-            found_string[ifoundlen] = 0; //null terminate
-            return true;
-        }
-    }
-
-    return false;
-
-} //extract_reply
 
 
-void parse_reply(char* reply)
+void scanStrip(int id)
 {
-    char *tokens[5];
-    int index = 0;
-    tokens[index++] = strtok(reply," ");  
-    while( index < 5 ) 
-    {    
-      char* token = strtok(NULL, " ");
-      if(token == NULL) break;
-      tokens[index++] = token;
-    }
-    if(strcmp("PSM",tokens[1]) == 0)
-    {
-
-        int t3412 = atoi(tokens[3]);
-        int t3324 = atoi(tokens[4]);
-        pc.printf("t3412 %d t3324 %d\r\n",t3412,t3324);
-        // setTauTimer(t3412);
-        //setActivityTimer(t3324);
-        
-        if(strcmp("true",tokens[2]) == 0)
-        {
-            pc.printf("PSM ON\r\n");
-            wnc.setPowerSave(true,t3412,t3324);
-        }
-        else
-        {
-            pc.printf("PSM OFF\r\n");
-            wnc.setPowerSave(false,t3412,t3324);
-        }
-    }        
-}
-
-bool checkSlots()
-{
-    bool changed = false;
-    int s1 = !slot1;
-    int s2 = !slot2;
-    int s3 = !slot3;
-    if(lastSlot1 != s1 || lastSlot2 != s2 ||lastSlot3 != s3)
-    {
-        pc.printf("slot 1 %d\r\n",s1);
-        pc.printf("slot 2 %d\r\n",s2);
-        pc.printf("slot 3 %d\r\n",s3);
-        changed = true;
-    }
-    lastSlot1 = s1;
-    lastSlot2 = s2;
-    lastSlot3 = s3;
-    return changed;
-}
-#if PROXIMITYON == 1 
-bool scanStrip(int id)
-{
-    bool stripChanged = false;
     ATT160826&  strip = *strips[id];
     att160826_data_t *data = &strip_data[id];
     bool ok = strip.scan(data);
      
     if(ok)
     {  
-       // printf("%d\r\n",id);
-        for (int i = 1; i < SENSORS_PER_STRIP;i++) { // ignore first sensor it is blocked
-         
-          /*  
+        printf("%d : ",id);
+        for (int i = 0; i < SENSORS_PER_STRIP;i++) { 
+                  
             if (strip_data[id].sensor[i].present) {
-                printf(" %3d", strip_data[id].sensor[i].sample.prox);
+                printf(" [%3d %3d %3d] ", strip_data[id].sensor[i].sample.prox,
+                strip_data[id].sensor[i].sample.als_vis,
+                strip_data[id].sensor[i].sample.als_ir);
             } else {
                 printf(" %3s", "---");
             }
-            */
-            if (strip_data[id].sensor[i].present) {
-                
-                if (abs(last_data[id].sensor[i].sample.prox - strip_data[id].sensor[i].sample.prox) > 50)
-                {
-                    stripChanged = true; 
-                    last_data[id].sensor[i].sample.prox = strip_data[id].sensor[i].sample.prox;
-                    last_data[id].sensor[i].sample.als_vis = strip_data[id].sensor[i].sample.als_vis;
-                    last_data[id].sensor[i].sample.als_ir = strip_data[id].sensor[i].sample.als_ir;   
-                }
-
-            }
         }
-        // printf("\r\n");
     }
     else
         printf("scan of strip %d failed",id);
-    return stripChanged;
+    printf("\r\n");
 }
-#endif
-
-int main() {
-
-    int i;
-
-    HTS221 hts221;
-    pc.baud(115200);
-   
-    void hts221_init(void);
-
-    // Set LED to RED until init finishes
-    SetLedColor(0x1);
-
-    pc.printf(BLU "Hello World from AT&T Shape!\r\n\n\r");
-    pc.printf(GRN "Initialize the HTS221\n\r");
-
-    i = hts221.begin();  
-    if( i ) 
-        pc.printf(BLU "HTS221 Detected! (0x%02X)\n\r",i);
-    else
-        pc.printf(RED "HTS221 NOT DETECTED!!\n\r");
-
-    printf("Temp  is: %0.2f F \n\r",CTOF(hts221.readTemperature()));
-    printf("Humid is: %02d %%\n\r",hts221.readHumidity());
 
 
-    // Initialize the modem
-    printf(GRN "Modem initializing... will take up to 60 seconds" DEF "\r\n");
-    if(!wnc.init()) 
-    {
-        pc.printf(RED "Modem initialization failed!" DEF "\n");
-        system_reset();
-    }
-       
-    
-    iccid = wnc.getIccid();
-    printf(GRN "ICCID = %s" DEF "\r\n",iccid);
-    
-
-           
-    //Software init
-    if(!wnc.startInternet())
-        system_reset();
-    
-    char* ip = wnc.resolveDn(MY_SERVER_URL);
-    if(strlen(ip) == 0)
-    {
-       printf(RED "Failed to resolve IP for %s" DEF "\r\n",MY_SERVER_URL); 
-    }
-    else
-        printf(GRN "IP = %s" DEF "\r\n",ip);
-
-    // Set LED BLUE for partial init
-    SetLedColor(0x4);
+int main() {
+ 
+    pc.baud(115200);
  
-    wnc.setPowerSave(true,wnc.gett3412Timer(),wnc.gett3324Timer());
- 
-#if PROXIMITYON == 1 
-    bool stripChanged[2];
-    myi2c = new I2C(PTE25, PTE24); 
-    //myi2c = new I2C(PTC11, PTC10); 
+    myi2c = new I2C(PTC11, PTC10); 
     myi2c->frequency(100000);
-    ATT160826 strip0 (myi2c, 0);
-    ATT160826 strip1 (myi2c, 3);
+    ATT160826 strip0 (myi2c, 0 );
+    ATT160826 strip1 (myi2c, 1 );
+    ATT160826 strip2 (myi2c, 2 );
+    ATT160826 strip3 (myi2c, 3 );
     strips[0] = &strip0;
     strips[1] = &strip1;
-    
-#elif PROXIMITYON == 2
-
-    myi2c = new I2C(PTE25, PTE24); 
+    strips[2] = &strip2;
+    strips[3] = &strip3;
     
-    myi2c->frequency(100000);
-    Proximity strip0;
-    Proximity strip1;
-    proximityStrip[0] = strip0;
-    proximityStrip[1] = strip1;
-    proximityStrip[0].init(myi2c, 0x70); 
-    proximityStrip[1].init(myi2c, 0x73);
-    proximityStrip[0].on(); 
-    proximityStrip[1].on(); 
-     
-#endif
-
-    int count = 5*120;
-    // Send and receive data perpetually
+    pc.printf(GRN "I2c init \n\r");
+    
     while(1) {
        
-        wnc.checkPassthrough();
-        //sprintf(SENSOR_DATA.Temperature, "%0.2f", CTOF(hts221.readTemperature()));
-        //sprintf(SENSOR_DATA.Humidity, "%02d", hts221.readHumidity());
-        // read_sensors(); //read available external sensors from a PMOD and the on-board motion sensor
         toggleLed = !toggleLed;
         if(toggleLed)
             SetLedColor(0x2); //green 
         else    
-            SetLedColor(0); //off   
-
-#if PROXIMITYON == 1            
-    
-     if(stripChanged[0] == false)
-        stripChanged[0] = scanStrip(0);
-     if(stripChanged[1] == false)
-        stripChanged[1] = scanStrip(1); 
-     
-#elif PROXIMITYON == 2
-
-    printf("scan %d\r\n",count);
-    bool stripChanged = false;
-    proximityStrip[0].scan();
-    printf("scan0 done %d\r\n",count);
-    proximityStrip[1].scan();
-    printf("scan1 done %d\r\n",count);
-    stripChanged |= proximityStrip[0].changed(50);
-    printf("scan0 change %d\r\n",stripChanged);
-    stripChanged |= proximityStrip[1].changed(50);
-    printf("scan1 change %d\r\n",stripChanged);
-    
-#else
-        bool slotsChanged = checkSlots();
-#endif
-
-     char modem_string[512];                
-        
-#if PROXIMITYON == 1 
-/*           
-        if(count >= 5*120)
-        {
-            stripChanged[0] = true;
-            stripChanged[1] = true;
-        }
- */     
-        if(sw2 == 0)
-        {
-            stripChanged[0] = true;
-            stripChanged[1] = true;
-        }             
-        if(stripChanged[0] || stripChanged[1])
-
-        
-#elif PROXIMITYON == 2
-        if(count >= 5*60 || stripChanged )
-#else
-        if(count >= 5*60 || slotsChanged)
-#endif
-        {
-            if(wnc.isPowerSaveOn())
-            {
-                wnc.wakeFromPowerSave();
-                //wnc.ping("108.244.165.22");
-            }
-            count = 0;
-            SetLedColor(0x04); //blue
-                
-
+            SetLedColor(0); //off    
             
-#if PROXIMITYON == 1
-        if(stripChanged[0])
-        {
-            GenerateModemString(&modem_string[0],PROXIMITY_ONLY,0);
-            stripChanged[0] = false;
-        }
-        else if (stripChanged[1])
-        {
-            GenerateModemString(&modem_string[0],PROXIMITY_ONLY,3);
-            stripChanged[1] = false;
-        }
-        else
-            GenerateModemString(&modem_string[0],PROXIMITY_ONLY,-1);
-#elif PROXIMITYON == 2
-            GenerateModemString(&modem_string[0],PROXIMITY_ONLY,0);
-#else
-            GenerateModemString(&modem_string[0],SWITCH_ONLY,0);
-#endif
-  
-            printf(BLU "Sending to modem : %s" DEF "\r\n", modem_string);
-
-            //if(wnc.connect("108.244.165.22",5005)) // node-red
-            
-            
-            if(wnc.connect(ip,MY_PORT)) // shelf
-            //if(wnc.connect("52.33.231.251",80)) // car
-            {
-                if(wnc.writeSocket(modem_string))
-                {
-           
-                    char* mydata;
-                    int tries = 8;
-                    while(tries > 0) // wait for reply
-                    {
-                        tries--;
-                        mydata = wnc.readSocket();
-                        if (strlen(mydata) > 0)
-                            break;
-                 
-                        wait(0.5);
-                    }
-            
-                    if (strlen(mydata) > 0)
-                    {   
-                                
-                        SetLedColor(0x2); // green
-                        //only copy on sucessful send
-
-                        printf(BLU "Read back : [%s]" DEF "\r\n", mydata);
-                        char datareply[512];
-                        if (extract_reply(mydata, datareply))
-                        {
-                            printf(GRN "JSON : %s" DEF "\r\n", datareply);
-                            parse_reply(datareply);
-                        }
-                        SetLedColor(0); // off             
-                    }
-                    else // no reply reset
-                    {
-                        SetLedColor(0x1); //red
-                        system_reset();                 
-                    } 
-                }
-                wnc.disconnect();
-            }
-            else // failed to connect reset
-            {
-                SetLedColor(0x1); //red
-                system_reset(); 
-            }
-            if(wnc.isPowerSaveOn())
-                wnc.resumePowerSave();   
-        }
-        count++;
-        wait(0.2); 
+        scanStrip(0);  
+       // scanStrip(1); 
+       // scanStrip(2); 
+      //  scanStrip(3);         
+    
+        
+        wait(1); 
     } //forever loop
 }
diff -r fe90f1fcb4e0 -r 69966d555de7 sensors.cpp
--- a/sensors.cpp	Wed Nov 30 14:50:16 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,375 +0,0 @@
-#include "mbed.h"
-#include "sensors.h"
-
-//I2C for pmod sensors:
-#define Si1145_PMOD_I2C_ADDR   0xC0 //this is for 7-bit addr 0x60 for the Si7020
-#define Si7020_PMOD_I2C_ADDR   0x80 //this is for 7-bit addr 0x4 for the Si7020
-
-#include "hardware.h"
-
-#include "FXOS8700CQ.h"
-// Storage for the data from the motion sensor
-SRAWDATA accel_data;
-SRAWDATA magn_data;
-//InterruptIn fxos_int1(PTC6); // unused, common with SW2 on FRDM-K64F
-InterruptIn fxos_int2(PTC13); // should just be the Data-Ready interrupt
-bool fxos_int2_triggered = false;
-void trigger_fxos_int2(void)
-{
-    fxos_int2_triggered = true;
-}
-
-/*------------------------------------------------------------------------------
- * Perform I2C single read.
- *------------------------------------------------------------------------------*/
-unsigned char I2C_ReadSingleByte(unsigned char ucDeviceAddress)
-{
-    char rxbuffer [1];
-    i2c.read(ucDeviceAddress, rxbuffer, 1 );
-    return (unsigned char)rxbuffer[0];
-} //I2C_ReadSingleByte()
-
-/*------------------------------------------------------------------------------
- * Perform I2C single read from address.
- *------------------------------------------------------------------------------*/
-unsigned char I2C_ReadSingleByteFromAddr(unsigned char ucDeviceAddress, unsigned char Addr)
-{
-    char txbuffer [1];
-    char rxbuffer [1];
-    txbuffer[0] = (char)Addr;
-    i2c.write(ucDeviceAddress, txbuffer, 1 );
-    i2c.read(ucDeviceAddress, rxbuffer, 1 );
-    return (unsigned char)rxbuffer[0];
-} //I2C_ReadSingleByteFromAddr()
-
-/*------------------------------------------------------------------------------
- * Perform I2C read of more than 1 byte.
- *------------------------------------------------------------------------------*/
-int I2C_ReadMultipleBytes(unsigned char ucDeviceAddress, char *ucData, unsigned char ucLength)
-{
-    int status;
-    status = i2c.read(ucDeviceAddress, ucData, ucLength);
-    return status;
-} //I2C_ReadMultipleBytes()
-
-/*------------------------------------------------------------------------------
- * Perform I2C write of a single byte.
- *------------------------------------------------------------------------------*/
-int I2C_WriteSingleByte(unsigned char ucDeviceAddress, unsigned char Data, bool bSendStop)
-{
-    int status;
-    char txbuffer [1];
-    txbuffer[0] = (char)Data; //data
-    status = i2c.write(ucDeviceAddress, txbuffer, 1, !bSendStop); //true: do not send stop
-    return status;
-} //I2C_WriteSingleByte()
-
-/*------------------------------------------------------------------------------
- * Perform I2C write of 1 byte to an address.
- *------------------------------------------------------------------------------*/
-int I2C_WriteSingleByteToAddr(unsigned char ucDeviceAddress, unsigned char Addr, unsigned char Data, bool bSendStop)
-{
-    int status;
-    char txbuffer [2];
-    txbuffer[0] = (char)Addr; //address
-    txbuffer[1] = (char)Data; //data
-    //status = i2c.write(ucDeviceAddress, txbuffer, 2, false); //stop at end
-    status = i2c.write(ucDeviceAddress, txbuffer, 2, !bSendStop); //true: do not send stop
-    return status;
-} //I2C_WriteSingleByteToAddr()
-
-/*------------------------------------------------------------------------------
- * Perform I2C write of more than 1 byte.
- *------------------------------------------------------------------------------*/
-int I2C_WriteMultipleBytes(unsigned char ucDeviceAddress, char *ucData, unsigned char ucLength, bool bSendStop)
-{
-    int status;
-    status = i2c.write(ucDeviceAddress, ucData, ucLength, !bSendStop); //true: do not send stop
-    return status;
-} //I2C_WriteMultipleBytes()
-
-bool bSi7020_present = false;
-void Init_Si7020(void)
-{
-    char SN_7020 [8];
-    //SN part 1:
-    I2C_WriteSingleByteToAddr(Si7020_PMOD_I2C_ADDR, 0xFA, 0x0F, false);
-    I2C_ReadMultipleBytes(Si7020_PMOD_I2C_ADDR, &SN_7020[0], 4);
-
-    //SN part 1:
-    I2C_WriteSingleByteToAddr(Si7020_PMOD_I2C_ADDR, 0xFC, 0xC9, false);
-    I2C_ReadMultipleBytes(Si7020_PMOD_I2C_ADDR, &SN_7020[4], 4);
-
-    char Ver_7020 [2];
-    //FW version:
-    I2C_WriteSingleByteToAddr(Si7020_PMOD_I2C_ADDR, 0x84, 0xB8, false);
-    I2C_ReadMultipleBytes(Si7020_PMOD_I2C_ADDR, &Ver_7020[0], 2);
-
-    if (SN_7020[4] != 0x14)
-    {
-        bSi7020_present = false;
-        printf("Si7020 sensor not found\n");
-    }
-    else 
-    {
-        bSi7020_present = true;
-        printf("Si7020 SN = 0x%02X%02X%02X%02X%02X%02X%02X%02X\n", SN_7020[0], SN_7020[1], SN_7020[2], SN_7020[3], SN_7020[4], SN_7020[5], SN_7020[6], SN_7020[7]);
-        printf("Si7020 Version# = 0x%02X\n", Ver_7020[0]);
-    } //bool bSi7020_present = true
-
-} //Init_Si7020()
-
-void Read_Si7020(void)
-{
-    if (bSi7020_present)
-    {
-        char Humidity [2];
-        char Temperature [2];
-        //Command to measure humidity (temperature also gets measured):
-        I2C_WriteSingleByte(Si7020_PMOD_I2C_ADDR, 0xF5, false); //no hold, must do dummy read
-        I2C_ReadMultipleBytes(Si7020_PMOD_I2C_ADDR, &Humidity[0], 1); //dummy read, should get an nack until it is done
-        wait (0.05); //wait for measurement.  Can also keep reading until no NACK is received
-        //I2C_WriteSingleByte(Si7020_PMOD_I2C_ADDR, 0xE5, false); //Hold mod, the device does a clock stretch on the read until it is done (crashes the I2C bus...
-        I2C_ReadMultipleBytes(Si7020_PMOD_I2C_ADDR, &Humidity[0], 2); //read humidity
-        //printf("Read Si7020 Humidity = 0x%02X%02X\n", Humidity[0], Humidity[1]);
-        int rh_code = (Humidity[0] << 8) + Humidity[1];
-        float fRh = (125.0*rh_code/65536.0) - 6.0; //from datasheet
-        //printf("Si7020 Humidity = %*.*f %%\n", 4, 2, fRh); //double % sign for escape //printf("%*.*f\n", myFieldWidth, myPrecision, myFloatValue);
-        sprintf(SENSOR_DATA.Humidity_Si7020, "%0.2f", fRh);
-        
-        //Command to read temperature when humidity is already done:
-        I2C_WriteSingleByte(Si7020_PMOD_I2C_ADDR, 0xE0, false);
-        I2C_ReadMultipleBytes(Si7020_PMOD_I2C_ADDR, &Temperature[0], 2); //read temperature
-        //printf("Read Si7020 Temperature = 0x%02X%02X\n", Temperature[0], Temperature[1]);
-        int temp_code = (Temperature[0] << 8) + Temperature[1];
-        float fTemp = (175.72*temp_code/65536.0) - 46.85; //from datasheet in Celcius
-        //printf("Si7020 Temperature = %*.*f deg C\n", 4, 2, fTemp);
-        sprintf(SENSOR_DATA.Temperature_Si7020, "%0.2f", fTemp);
-    } //bool bSi7020_present = true
-
-} //Read_Si7020()
-
-/*------------------------------------------------------------------------------
- * The following are aliases so that the Si1145 coding examples can be used as-is.
- *------------------------------------------------------------------------------*/
-unsigned char ReadFrom_Si1145_Register(unsigned char reg) //returns byte from I2C Register 'reg'
-{
-    unsigned char result = I2C_ReadSingleByteFromAddr(Si1145_PMOD_I2C_ADDR, reg);
-    return (result);
-} //ReadFrom_Si1145_Register()
-
-void WriteTo_Si1145_Register(unsigned char reg, unsigned char value) //writes 'value' into I2C Register reg'
-{
-    I2C_WriteSingleByteToAddr(Si1145_PMOD_I2C_ADDR, reg, value, true);
-} //WriteTo_Si1145_Register()
-
-#define REG_PARAM_WR 0x17
-#define REG_PARAM_RD 0x2E
-#define REG_COMMAND 0x18
-#define REG_RESPONSE 0x20
-#define REG_HW_KEY 0x07
-#define HW_KEY_VAL0 0x17
-#define REG_MEAS_RATE_LSB 0x08
-#define REG_MEAS_RATE_MSB 0x09
-#define REG_PS_LED21 0x0F
-#define REG_PS_LED3 0x10
-#define MAX_LED_CURRENT 0xF
-#define PARAM_CH_LIST 0x01
-#define REG_ALS_VIS_DATA0 0x22
-#define REG_ALS_VIS_DATA1 0x23
-#define REG_ALS_IR_DATA0 0x24
-#define REG_ALS_IR_DATA1 0x25
-#define REG_PS1_DATA0 0x26
-#define REG_PS1_DATA1 0x27
-#define REG_PS2_DATA0 0x28
-#define REG_PS2_DATA1 0x29
-#define REG_PS3_DATA0 0x2A
-#define REG_PS3_DATA1 0x2B
-#define REG_UVINDEX0 0x2C
-#define REG_UVINDEX1 0x2D
-int Si1145_ParamSet(unsigned char address, unsigned char value) //writes 'value' into Parameter 'address'
-{
-    char txbuffer [3];
-    txbuffer[0] = (char)REG_PARAM_WR; //destination
-    txbuffer[1] = (char)value;
-    txbuffer[2] = (char)(0xA0 + (address & 0x1F));
-    int retval;
-    //if((retval = _waitUntilSleep(si114x_handle))!=0) return retval;
-    retval = I2C_WriteMultipleBytes(Si1145_PMOD_I2C_ADDR, &txbuffer[0], 3, true);
-    if(retval!=0) return retval;
-    while(1)
-    {
-        retval=ReadFrom_Si1145_Register(REG_PARAM_RD);
-        if (retval==value) break;
-    }
-    return (0);
-} //Si1145_ParamSet()
-
-void PsAlsForce(void) //equivalent to WriteTo_Si1145_Register(REG_COMMAND,0x07).  This forces PS and ALS measurements
-{
-    WriteTo_Si1145_Register(REG_COMMAND,0x07);
-} //PsAlsForce()
-
-bool bSi1145_present = false;
-void Init_Si1145(void)
-{
-    unsigned char readbyte;
-    //Read Si1145 part ID:
-    readbyte = ReadFrom_Si1145_Register(0x00);
-    if (readbyte != 0x45)
-    {
-        bSi1145_present = false;
-        printf("Si1145 sensor not found\n");
-    }
-    else
-    {
-        bSi1145_present = true;
-        printf("Si1145 Part ID : 0x%02X\n", readbyte);
-        //Initialize Si1145 by writing to HW_KEY (I2C Register 0x07 = 0x17)
-        WriteTo_Si1145_Register(REG_HW_KEY, HW_KEY_VAL0);
-    
-        // Initialize LED Current
-        // I2C Register 0x0F = 0xFF
-        // I2C Register 0x10 = 0x0F
-        WriteTo_Si1145_Register(REG_PS_LED21,(MAX_LED_CURRENT<<4) + MAX_LED_CURRENT);
-        WriteTo_Si1145_Register(REG_PS_LED3, MAX_LED_CURRENT);
-
-        // Parameter 0x01 = 0x37
-        //Si1145_ParamSet(PARAM_CH_LIST, ALS_IR_TASK + ALS_VIS_TASK + PS1_TASK + PS2_TASK + PS3_TASK);
-        //Si1145_ParamSet(0x01, 0x37); //CHLIST is address 0x01 in the parameter RAM.  It defines which sensors are enabled (here, some)
-        Si1145_ParamSet(0x01, 0x7F); //CHLIST is address 0x01 in the parameter RAM.  It defines which sensors are enabled (here, all but UV.  One can only use AUX or UV but here we use AUX because UV does not work...)
-        // I2C Register 0x18 = 0x0x07 //This is PSALS_FORCE to the Command register => Force a single PS (proximity sensor) and ALS (ambient light sensor) reading - The factory code has this as 0x05 which only does PS...
-        PsAlsForce(); // can also be written as WriteTo_Si1145_Register(REG_COMMAND,0x07);
-        WriteTo_Si1145_Register(REG_COMMAND, 0x0F);//command to put it into auto mode
-        //Set MES_RATE to 0x1000.  I.e. the device will automatically wake up every 16 * 256* 31.25 us = 0.128 seconds to measure
-        WriteTo_Si1145_Register(REG_MEAS_RATE_LSB, 0x00);
-        WriteTo_Si1145_Register(REG_MEAS_RATE_MSB, 0x10);
-    } //bSi1145_present = true
-} //Init_Si1145()
-
-void Read_Si1145(void)
-{
-    if (bSi1145_present)
-    {
-        // Once the measurements are completed, here is how to reconstruct them
-        // Note very carefully that 16-bit registers are in the 'Little Endian' byte order
-        // It may be more efficient to perform block I2C Reads, but this example shows
-        // individual reads of registers
-    
-        int PS1 = ReadFrom_Si1145_Register(REG_PS1_DATA0) + 256 * ReadFrom_Si1145_Register(REG_PS1_DATA1);
-        int PS2 = ReadFrom_Si1145_Register(REG_PS2_DATA0) + 256 * ReadFrom_Si1145_Register(REG_PS2_DATA1);
-        int PS3 = ReadFrom_Si1145_Register(REG_PS3_DATA0) + 256 * ReadFrom_Si1145_Register(REG_PS3_DATA1);
-        //printf("PS1_Data = %d\n", PS1);
-        //printf("PS2_Data = %d\n", PS2);
-        //printf("PS3_Data = %d\n", PS3);
-        //OBJECT PRESENT?
-#if (0)
-        if(PS1 < 22000){
-            //printf("Object Far\n");
-            sprintf(SENSOR_DATA.Proximity, "Object Far\0");
-        }
-        else if(PS1 < 24000)
-        {
-            //printf("Object in Vicinity\n");
-            sprintf(SENSOR_DATA.Proximity, "Object in Vicinity\0");
-        }
-        else if (PS1 < 30000)
-        {
-            //printf("Object Near\n");
-            sprintf(SENSOR_DATA.Proximity, "Object Near\0");
-        }
-        else
-        {
-            //printf("Object Very Near\n");
-            sprintf(SENSOR_DATA.Proximity, "Object Very Near\0");
-        }
-#else    
-        sprintf(SENSOR_DATA.Proximity, "%d\0", PS1);
-#endif            
-    
-        //Force ALS read:
-        //WriteTo_Si1145_Register(REG_COMMAND, 0x06);
-        //wait (0.1);
-        int ALS_VIS = ReadFrom_Si1145_Register(REG_ALS_VIS_DATA0) + 256 * ReadFrom_Si1145_Register(REG_ALS_VIS_DATA1);
-        int ALS_IR = ReadFrom_Si1145_Register(REG_ALS_IR_DATA0) + 256 * ReadFrom_Si1145_Register(REG_ALS_IR_DATA1);
-        int UV_INDEX = ReadFrom_Si1145_Register(REG_UVINDEX0) + 256 * ReadFrom_Si1145_Register(REG_UVINDEX1);
-        //printf("ALS_VIS_Data = %d\n", ALS_VIS);
-        //printf("ALS_IR_Data = %d\n", ALS_IR);
-        //printf("UV_INDEX_Data = %d\n", UV_INDEX);
-    
-        //printf("Ambient Light Visible  Sensor = %d\n", ALS_VIS);
-        sprintf(SENSOR_DATA.AmbientLightVis, "%d", ALS_VIS);
-        //printf("Ambient Light Infrared Sensor = %d\n", ALS_IR);
-        sprintf(SENSOR_DATA.AmbientLightIr, "%d", ALS_IR);
-        //float fUV_value = (UV_INDEX -50.0)/10000.0;
-        float fUV_value = (UV_INDEX)/100.0; //this is the aux reading
-        //printf("UV_Data = %0.2f\n", fUV_value);
-        sprintf(SENSOR_DATA.UVindex, "%0.2f", fUV_value);
-    } //bSi1145_present = true
-} //Read_Si1145()
-
-//********************************************************************************************************************************************
-//* Read the FXOS8700CQ - 6-axis combo Sensor Accelerometer and Magnetometer
-//********************************************************************************************************************************************
-bool bMotionSensor_present = false;
-void init_motion_sensor()
-{
-    // Note: this class is instantiated here because if it is statically declared, the cellular shield init kills the I2C bus...
-    // Class instantiation with pin names for the motion sensor on the FRDM-K64F board:
-    FXOS8700CQ fxos(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // SDA, SCL, (addr << 1)
-    int iWhoAmI = fxos.get_whoami();
-    printf("FXOS8700CQ WhoAmI = %X\r\n", iWhoAmI);
-    // Iterrupt for active-low interrupt line from FXOS
-    // Configured with only one interrupt on INT2 signaling Data-Ready
-    //fxos_int2.fall(&trigger_fxos_int2);
-    if (iWhoAmI != 0xC7)
-    {
-        bMotionSensor_present = false;
-        printf("FXOS8700CQ motion sensor not found\n");
-    }
-    else
-    {
-        bMotionSensor_present = true;
-        fxos.enable();
-    }
-} //init_motion_sensor
-
-void read_motion_sensor()
-{
-    // Note: this class is instantiated here because if it is statically declared, the cellular shield init kills the I2C bus...
-    // Class instantiation with pin names for the motion sensor on the FRDM-K64F board:
-    FXOS8700CQ fxos(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // SDA, SCL, (addr << 1)
-    if (bMotionSensor_present)
-    {
-        fxos.enable();
-        fxos.get_data(&accel_data, &magn_data);
-        //printf("Roll=%5d, Pitch=%5d, Yaw=%5d;\r\n", magn_data.x, magn_data.y, magn_data.z);
-        sprintf(SENSOR_DATA.MagnetometerX, "%5d", magn_data.x);
-        sprintf(SENSOR_DATA.MagnetometerY, "%5d", magn_data.y);
-        sprintf(SENSOR_DATA.MagnetometerZ, "%5d", magn_data.z);
-    
-        //Try to normalize (/2048) the values so they will match the eCompass output:
-        float fAccelScaled_x, fAccelScaled_y, fAccelScaled_z;
-        fAccelScaled_x = (accel_data.x/2048.0);
-        fAccelScaled_y = (accel_data.y/2048.0);
-        fAccelScaled_z = (accel_data.z/2048.0);
-        //printf("Acc: X=%2.3f Y=%2.3f Z=%2.3f;\r\n", fAccelScaled_x, fAccelScaled_y, fAccelScaled_z);
-        sprintf(SENSOR_DATA.AccelX, "%2.3f", fAccelScaled_x);
-        sprintf(SENSOR_DATA.AccelY, "%2.3f", fAccelScaled_y);
-        sprintf(SENSOR_DATA.AccelZ, "%2.3f", fAccelScaled_z);
-    } //bMotionSensor_present
-} //read_motion_sensor
-
-void sensors_init(void)
-{
-    Init_Si7020();
-    Init_Si1145();
-    init_motion_sensor();
-} //sensors_init
-
-void read_sensors(void)
-{
-    Read_Si7020();
-    Read_Si1145();
-    read_motion_sensor();
-} //read_sensors
diff -r fe90f1fcb4e0 -r 69966d555de7 sensors.h
--- a/sensors.h	Wed Nov 30 14:50:16 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#ifndef __SENSORS_H_
-#define __SENSORS_H_
-
-void sensors_init(void);
-void read_sensors(void);
-
-#define SENSOR_FIELD_LEN_LIMIT  32
-typedef struct
-{
-    char  Temperature[SENSOR_FIELD_LEN_LIMIT];
-    char  Humidity[SENSOR_FIELD_LEN_LIMIT];
-    char  AccelX[SENSOR_FIELD_LEN_LIMIT];
-    char  AccelY[SENSOR_FIELD_LEN_LIMIT];
-    char  AccelZ[SENSOR_FIELD_LEN_LIMIT];
-    char  MagnetometerX[SENSOR_FIELD_LEN_LIMIT];
-    char  MagnetometerY[SENSOR_FIELD_LEN_LIMIT];
-    char  MagnetometerZ[SENSOR_FIELD_LEN_LIMIT];
-    char  AmbientLightVis[SENSOR_FIELD_LEN_LIMIT];
-    char  AmbientLightIr[SENSOR_FIELD_LEN_LIMIT];
-    char  UVindex[SENSOR_FIELD_LEN_LIMIT];
-    char  Proximity[SENSOR_FIELD_LEN_LIMIT];
-    char  Temperature_Si7020[SENSOR_FIELD_LEN_LIMIT];
-    char  Humidity_Si7020[SENSOR_FIELD_LEN_LIMIT];
-} K64F_Sensors_t ;
-
-extern K64F_Sensors_t  SENSOR_DATA;
-
-#endif
\ No newline at end of file
diff -r fe90f1fcb4e0 -r 69966d555de7 sfh7779.lib
--- a/sfh7779.lib	Wed Nov 30 14:50:16 2016 +0000
+++ b/sfh7779.lib	Fri Apr 21 17:58:35 2017 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/elmkom/code/sfh7779/#5e15a306a518
+https://developer.mbed.org/users/elmkom/code/sfh7779/#fc2dbccffe34