moon

Dependencies:   Hexi_OLED_SSD1351

Files at this revision

API Documentation at this revision

Comitter:
raynard
Date:
Fri Jul 26 13:37:55 2019 +0000
Commit message:
watch

Changed in this revision

Barometer.cpp Show annotated file Show diff for this revision Revisions of this file
Barometer.h Show annotated file Show diff for this revision Revisions of this file
GYROMETER.cpp Show annotated file Show diff for this revision Revisions of this file
GYROMETER.h Show annotated file Show diff for this revision Revisions of this file
Hexi_KW40Z.lib Show annotated file Show diff for this revision Revisions of this file
Hexi_OLED_SSD1351.lib Show annotated file Show diff for this revision Revisions of this file
MOON_HUMTEMP.cpp Show annotated file Show diff for this revision Revisions of this file
Moon_HUMTEMP.h Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
accel_mag.cpp Show annotated file Show diff for this revision Revisions of this file
accel_mag.h Show annotated file Show diff for this revision Revisions of this file
lum.cpp Show annotated file Show diff for this revision Revisions of this file
lum.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Barometer.cpp	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,570 @@
+#include "Barometer.h"
+
+#define deviceDetail_REG        0x0C        // return 0xC4 by default
+#define STATUS_REG          0x00
+#define	CTRL_REG_1			0x26
+#define	CTRL_REG_3   		0x28
+#define	CTRL_REG_4	 	 	0x29
+#define CTRL_REG_5		    0x2A
+#define PRESSURE_MSB    	0x01        // pressure data
+#define ALTIMETER_MSB   	0x01        //  altimeter data
+#define TEMP_MSB        	0x04        // temperature data
+#define PT_DATA_CFG     	0x13
+#define P_TGT_MSB       	0x16
+#define P_WND_MSB       	0x19
+#define OFF_P           0x2b
+#define OFF_T           0x2c
+#define OFF_H           0x2d
+#define MIN_PRESSURE_MSB    0x1c
+#define ALTI_MIN_MSB    	0x1c
+#define TEMP_MIN_MSB    	0x1f
+#define PRES_MAX_MSB    	0x21
+#define ALTI_MAX_MSB    	0x21
+#define TEMP_MAX_MSB    	0x24
+#define PRES_DELTA_MSB  	0x07
+#define ALTI_DELTA_MSB  	0x07
+#define TEMP_DELTA_MSB  	0x0a
+
+
+#define UINT14_MAX        16383
+
+// Status flag for data ready.
+#define PTDR_STATUS       0x03        // Pressure Altitude
+#define PDR_STATUS        0x02        // Pressure and Altitude data ready
+#define TDR_STATUS        0x01
+
+
+void (*MPL3115A2_usr2_fptr)(void);               // Pointers to user function called after
+void (*MPL3115A2_usr1_fptr)(void);               // IRQ assertion.
+
+//
+InterruptIn Device_Int1( PTD4);       // INT1
+InterruptIn Device_Int2( PTA12);      // INT2
+
+DEVICE::DEVICE(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) {
+    unsigned char data[6];
+    
+    Device_mode = MODE_BAR;
+    Device_oversampling = OVERSAMPLE_1;
+
+    MPL3115A2_usr1_fptr = NULL;
+    MPL3115A2_usr2_fptr = NULL;
+    Device_Int1.fall( NULL);
+    Device_Int2.fall( NULL);
+    
+    Reset();		//soft reset
+    
+    data[0]=MIN_PRESSURE_MSB;
+    data[1]=0;data[2]=0;data[3]=0;data[4]=0;data[5]=0;
+    writeRegs( &data[0], 6);
+}
+
+void DEVICE::Reset( void)
+{
+    unsigned char t;
+    
+
+    readRegs( CTRL_REG_1, &t, 1);
+    unsigned char data[2] = { CTRL_REG_1, t|0x04};
+
+
+    writeRegs(data, 2);      //soft reset
+    wait( 0.1);
+
+}
+
+void DEVICE::DReady( void(*fptr)(void), unsigned char OS)
+{
+    unsigned char dt[5];
+    unsigned char data[2];
+    
+    // Soft Reset
+    Reset();
+    
+    Standby();
+    
+    // Clear all interrupts by reading the output registers.
+    readRegs( ALTIMETER_MSB, &dt[0], 5);
+    statusRequest();
+    // Configure INT active low and pullup
+    data[0] = CTRL_REG_3;
+    data[1] = 0x00;
+    writeRegs(data, 2);    
+    // Enable Interrupt fot data ready
+    data[0] = CTRL_REG_4;
+    data[1] = 0x80;
+    writeRegs(data, 2);    
+    // Configure Interrupt to route to INT2
+    data[0] = CTRL_REG_5;
+    data[1] = 0x00;
+    writeRegs(data, 2);    
+    data[0] = PT_DATA_CFG;
+    data[1] = 0x07;
+    writeRegs(data, 2);    
+
+    // Configure the OverSampling rate, Altimeter/Barometer mode and set the sensor Active
+    data[0] = CTRL_REG_1;
+    data[1] = (OS<<3);
+    //
+    if (Device_mode == MODE_BAR)
+        data[1] &= 0x7F;
+    else
+        data[1] |= 0x80;
+    //
+    data[1] |= 0x01; 
+    writeRegs(data, 2);    
+
+    MPL3115A2_usr2_fptr = fptr;
+    Device_Int2.fall( this, &DEVICE::DReady_IRQ);
+
+}
+
+void DEVICE::DReady_IRQ( void)
+{
+    // Clear the IRQ flag
+	statusRequest();
+    // Run the user supplied function
+    MPL3115A2_usr2_fptr();   
+}
+
+void DEVICE::AltitudeTrigger( void(*fptr)(void), unsigned short level)
+{
+    unsigned char dt[5];
+    unsigned char data[2];
+
+    // Soft Reset
+    Reset();
+    
+    // The device is on standby
+    Standby();
+    
+    // Clear all interrupts by reading the output registers.
+    readRegs( ALTIMETER_MSB, &dt[0], 5);
+    statusRequest();
+
+    // Write Target and Window Values
+    dt[0] = P_TGT_MSB;
+    dt[1] = (level>>8);
+    dt[2] = (level&0xFF);
+    writeRegs( dt, 3);
+    
+    // Window values are zero
+    dt[0] = P_WND_MSB;
+    dt[1] = 0;
+    dt[2] = 0;
+    writeRegs( dt, 3);
+
+    // Enable Pressure Threshold interrupt
+    data[0] = CTRL_REG_4;
+    data[1] = 0x08;
+    writeRegs( data, 2);
+    // Interrupt is routed to INT1
+    data[0] = CTRL_REG_5;
+    data[1] = 0x08;
+    writeRegs( data, 2);
+    data[0] = PT_DATA_CFG;
+    data[1] = 0x07;
+    writeRegs(data, 2);    
+    // Configure the OverSampling rate, Altimeter mode and set the sensor Active
+    data[0] = CTRL_REG_1;
+    data[1] = 0x81 | (Device_oversampling<<3);
+    writeRegs(data, 2);    
+
+    MPL3115A2_usr1_fptr = fptr;
+    Device_Int1.fall( this, &DEVICE::AltitudeTrg_IRQ);
+
+}
+
+void DEVICE::AltitudeTrg_IRQ( void)
+{
+    // Clear the IRQ flag
+	statusRequest();
+    // Run the user supplied function
+    MPL3115A2_usr1_fptr();   
+
+}
+
+void DEVICE::Barometric( void)
+{
+    unsigned char t;
+    unsigned char data[2];
+    
+    Standby();
+
+    // soft reset...
+    Reset();
+        
+    Standby();
+    readRegs( CTRL_REG_1, &t, 1);
+    
+    // Set the Barometric mode
+    data[0] = CTRL_REG_1;
+    data[1] = t&0x7F;
+    writeRegs(data, 2);    
+
+    data[0] = PT_DATA_CFG;
+    data[1] = 0x07;
+    writeRegs(data, 2);    
+
+    sampling_Ratio( Device_oversampling);
+    
+    Active();
+    
+    Device_mode = MODE_BAR;
+}
+
+void DEVICE::Altimeter( void)
+{
+    unsigned char t;
+    unsigned char data[2];
+    
+    Standby();
+
+    // soft reset...
+    Reset();    
+    
+    Standby();
+    readRegs( CTRL_REG_1, &t, 1);
+
+    data[0] = CTRL_REG_1;
+    data[1] = t|0x80;
+    writeRegs(data, 2);    
+
+    data[0] = PT_DATA_CFG;
+    data[1] = 0x07;
+    writeRegs(data, 2);    
+
+    sampling_Ratio( Device_oversampling);
+    
+    Active();
+    
+    Device_mode = MODE_ALT;
+}
+
+void DEVICE::sampling_Ratio( unsigned int ratio)
+{
+    unsigned char t;
+    
+    Standby();
+    readRegs( CTRL_REG_1, &t, 1);
+
+    t = t & 0xE7;
+    t = t | ( ratio<<3);
+
+    unsigned char data[2] = { CTRL_REG_1, t};
+    writeRegs(data, 2);    
+
+    Active();
+    
+
+    Device_oversampling = ratio;
+}
+
+
+void DEVICE::Active( void)
+{
+    unsigned char t;
+    
+    // Activate the peripheral
+    readRegs(CTRL_REG_1, &t, 1);
+    unsigned char data[2] = {CTRL_REG_1, t|0x01};
+    writeRegs(data, 2);
+}
+
+void DEVICE::Standby( void)
+{
+    unsigned char t;
+    
+    // Standby
+    readRegs(CTRL_REG_1, &t, 1);
+    unsigned char data[2] = {CTRL_REG_1, t&0xFE};
+    writeRegs(data, 2);
+}
+
+unsigned char DEVICE::requestDeviceID() {
+    unsigned char device_id = 0;
+    readRegs(deviceDetail_REG, &device_id, 1);
+    return device_id;
+}
+
+unsigned int DEVICE::isDataAvailable( void)
+{
+    unsigned char status;
+    
+    readRegs( STATUS_REG, &status, 1);
+
+    return ((status>>1));
+    
+}
+
+unsigned char DEVICE::statusRequest( void)
+{
+    unsigned char status;
+    
+    readRegs( STATUS_REG, &status, 1);
+    return status;
+}
+
+unsigned int DEVICE::requestAllData( float *f)
+{
+    if ( isDataAvailable() & PTDR_STATUS) {
+        if ( Device_mode == MODE_ALT) {
+            f[0] = requestAltimeter( ALTIMETER_MSB);
+        } else {
+            f[0] = requestPressure( PRESSURE_MSB);
+        }
+        
+    //    f[1] = requestTemperature( TEMP_MSB);
+
+        return 1;
+    } else
+        return 0;
+}
+
+unsigned int DEVICE::requestAllData( float *f, float *d)
+{
+    if ( isDataAvailable() & PTDR_STATUS) {
+        if ( Device_mode == MODE_ALT) {
+            f[0] = requestAltimeter();
+            d[0] = requestAltimeter( ALTI_DELTA_MSB);
+        } else {
+            f[0] = requestPressure();
+            d[0] = requestPressure( PRES_DELTA_MSB);
+        }
+        
+      //  f[1] = requestTemperature();
+     //   d[1] = requestTemperature( TEMP_DELTA_MSB);
+        //
+        return 1;
+    } else
+        return 0;
+}
+
+void DEVICE::requestAllMaximumData( float *f)
+{
+    if ( Device_mode == MODE_ALT) {
+        f[0] = requestAltimeter( ALTI_MAX_MSB);
+    } else {
+        f[0] = requestPressure( PRES_MAX_MSB);
+    }
+    
+   // f[1] = requestTemperature( TEMP_MAX_MSB);
+}
+
+void DEVICE::requestAllMinimumData( float *f)
+{
+    if ( Device_mode == MODE_ALT) {
+        f[0] = requestAltimeter( ALTI_MIN_MSB);
+    } else {
+        f[0] = requestPressure( MIN_PRESSURE_MSB);
+    }
+    
+   // f[1] = requestTemperature( TEMP_MIN_MSB);
+}
+
+float DEVICE::requestAltimeter( void)
+{
+    float a;
+    
+    a = requestAltimeter( ALTIMETER_MSB);
+    return a;
+}
+
+float DEVICE::requestAltimeter( unsigned char reg)
+{
+    unsigned char dt[3];
+    unsigned short altm;
+    short tmp;
+    float faltm;
+    
+    /*
+    * dt[0] = Bits 12-19 of 20-bit real-time Altitude sample. (b7-b0)
+    * dt[1] = Bits 4-11 of 20-bit real-time Altitude sample. (b7-b0)
+    * dt[2] = Bits 0-3 of 20-bit real-time Altitude sample (b7-b4)
+    */
+    readRegs( reg, &dt[0], 3);
+    altm = (dt[0]<<8) | dt[1];
+    //
+    if ( dt[0] > 0x7F) {
+        // negative number
+        tmp = ~altm + 1;
+        faltm = (float)tmp * -1.0f;
+    } else {
+        faltm = (float)altm * 1.0f;
+    }
+    //
+    faltm = faltm+((float)(dt[2]>>4) * 0.0625f);
+    return faltm;
+}
+
+float DEVICE::requestPressure( void)
+{
+    float a;
+    
+    a = requestPressure(PRESSURE_MSB);
+    return a;
+}
+
+float DEVICE::requestPressure( unsigned char reg)
+{
+    unsigned char dt[3];
+    unsigned int prs;
+    int tmp;
+    float fprs;
+    
+
+    readRegs( reg, &dt[0], 3);
+    prs = ((dt[0]<<10) | (dt[1]<<2) | (dt[2]>>6));
+    //
+    if ( dt[0] > 0x7f) {
+        // negative number
+        if ( dt[0] & 0x80)
+            prs |= 0xFFFC0000;      // set at 1 the bits to complete the word len
+        else
+            prs |= 0xFFFE0000;
+        tmp = ~prs + 1;             //  invert bits
+        fprs = (float)tmp * -1.0f;  // set the signe..
+    } else {
+        fprs = (float)prs * 1.0f;
+    }
+
+    if ( dt[2] & 0x10)
+        fprs += 0.25f;
+    if ( dt[2] & 0x20)
+        fprs += 0.5f;
+        
+    return fprs;
+}
+
+/*
+ float DEVICE::requestTemperature( void)
+{
+    float a;
+    
+    a = requestTemperature( TEMP_MSB);
+    return a;
+}
+
+float DEVICE::requestTemperature( unsigned char reg)
+{
+    unsigned char dt[2];
+    unsigned short temp;
+    float ftemp;
+    
+
+    readRegs( reg, &dt[0], 2);
+    temp = dt[0];
+    //
+    if ( dt[0] > 0x7F) {
+        temp = ~temp + 1;
+        ftemp = (float)temp * -1.0f;
+    } else {
+        ftemp = (float)temp * 1.0f;
+    }
+    //
+    ftemp = ftemp+((float)(dt[1]>>4) * 0.0625f);
+    return ftemp;
+
+}
+
+*/
+unsigned int DEVICE::getAllDataRaw( unsigned char *dt)
+{
+    // Check for Press/Alti and Temp value ready
+    if ( isDataAvailable() & PTDR_STATUS) {
+        if ( Device_mode == MODE_ALT) {
+        	getAltimeterRaw( &dt[0]);               // 3 bytes
+        } else {
+        	getPressureRaw( &dt[0]);                   // 3 bytes
+        }
+        
+       // getTemperatureRaw( &dt[3]);                    // 2 bytes
+        
+        return 1;
+    } else {
+        return 0;
+    }
+}
+
+unsigned int DEVICE::getAltimeterRaw( unsigned char *dt)
+{
+    
+
+    
+    // Check for Press/Alti value ready
+    if ( isDataAvailable() & PDR_STATUS) {
+        readRegs( ALTIMETER_MSB, &dt[0], 3);
+        return 1;
+    } else
+        return 0;
+}
+
+unsigned int  DEVICE::getPressureRaw( unsigned char *dt)
+{
+    
+
+    
+    // Check for Press/Alti value ready
+    if ( isDataAvailable() & PDR_STATUS) {
+        readRegs( PRESSURE_MSB, &dt[0], 3);
+        return 1;
+    } else 
+        return 0;
+        
+}
+/*
+unsigned int DEVICE::getTemperatureRaw( unsigned char *dt)
+{
+    
+
+    
+    // Check for Temp value ready
+    if ( isDataAvailable() & TDR_STATUS) {
+        readRegs( TEMP_MSB, &dt[0], 2);
+        return 1;
+    } else
+        return 0;        
+}
+*/
+void DEVICE::SetPressureOffset( char offset)
+{
+    unsigned char data [2] = {OFF_P, offset};
+
+    Standby();
+    writeRegs(data,2);
+
+    Active(); 
+}
+/*
+void DEVICE::SetTemperatureOffset( char offset)
+{
+    unsigned char data [2] = {OFF_T, offset};
+
+    Standby();
+    writeRegs(data,2);
+
+    Active(); 
+}
+*/
+void DEVICE::SetAltitudeOffset( char offset)
+{
+    unsigned char data [2] = {OFF_H, offset};
+
+    Standby();
+    writeRegs(data,2);
+
+    Active(); 
+}
+
+void DEVICE::readRegs(int addr, uint8_t * data, int len) {
+    char t[1] = {addr};
+    m_i2c.write(m_addr, t, 1, true);
+    m_i2c.read(m_addr, (char *)data, len);
+}
+
+void DEVICE::writeRegs(uint8_t * data, int len) {
+    m_i2c.write(m_addr, (char *)data, len);
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Barometer.h	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,258 @@
+
+#ifndef MPL3115A2_H
+#define MPL3115A2_H
+
+#include "mbed.h"
+
+// Oversampling value and minimum time between sample
+#define OVERSAMPLE_1      0       // 6 ms
+#define OVERSAMPLE_2      1       // 10 ms
+#define OVERSAMPLE_4      2       // 18 ms
+#define OVERSAMPLE_8      3       // 34 ms
+#define OVERSAMPLE_16     4       // 66 ms
+#define OVERSAMPLE_32     5       // 130 ms
+#define OVERSAMPLE_64     6       // 258 ms
+#define OVERSAMPLE_128    7       // 512 ms
+
+/* Mode */
+#define MODE_ALT      1
+#define MODE_BAR     2
+
+
+class DEVICE
+{
+public:
+
+    DEVICE(PinName sda, PinName scl, int addr);  //return the value of 0xC4
+
+    uint8_t requestDeviceID();
+
+    /**
+    * Return the STATUS register value
+    *
+    * @returns STATUS register value
+    */
+    unsigned char statusRequest( void);
+
+    /**
+    * Get the altimeter value
+    *
+    * @returns altimeter value as float
+    */
+    float requestAltimeter( void);
+
+    /**
+    * Get the altimeter value in raw mode
+    *
+    * @param    dt      pointer to unsigned char array
+    * @returns 1 if data are available, 0 if not.
+    */
+    unsigned int getAltimeterRaw( unsigned char *dt);
+
+    /**
+    * Get the pressure value
+    *
+    * @returns pressure value as float
+    */
+    float requestPressure( void);
+
+    /**
+    * Get the pressure value in raw mode
+    *
+    * @param    dt      pointer to unsigned char array
+    * @returns 1 if data are available, 0 if not.
+    */
+    unsigned int  getPressureRaw( unsigned char *dt);
+
+    /**
+    * Get the temperature value
+    *
+    * @returns temperature value as float
+    */
+    float requestTemperature( void);
+
+    /**
+    * Get the temperature value in raw mode
+    *
+    * @param    dt      pointer to unsigned char array
+    * @returns 1 if data are available, 0 if not.
+    */
+    unsigned int getTemperatureRaw( unsigned char *dt);
+
+    /**
+    * Set the Altimeter Mode
+    *
+    * @returns none
+    */
+    void Altimeter( void);
+
+    /**
+    * Set the Barometric Mode
+    *
+    * @returns none
+    */
+    void Barometric( void);
+
+    /**
+    * Get the altimeter or pressure and temperature values
+    *
+    * @param array of float f[2]
+    * @returns 0 no data available, 1 for data available
+    */
+    unsigned int  requestAllData( float *f);
+
+    /**
+    * Get the altimeter or pressure and temperature values and the delta values
+    *
+    * @param array of float f[2], array of float d[2]
+    * @returns 0 no data available, 1 for data available
+    */
+    unsigned int requestAllData( float *f, float *d);
+
+    /**
+    * Get the altimeter or pressure and temperature captured maximum value
+    *
+    * @param array of float f[2]
+    * @returns 0 no data available, 1 for data available
+    */
+    void requestAllMaximumData( float *f);
+
+    /**
+    * Get the altimeter or pressure and temperature captured minimum value
+    *
+    * @param array of float f[2]
+    * @returns 0 no data available, 1 for data available
+    */
+    void requestAllMinimumData( float *f);
+
+    /**
+    * Get the altimeter or pressure, and temperature values in raw mode
+    *
+    * @param array of unsigned char[5]
+    * @returns 1 if data are available, 0 if not.
+    */
+    unsigned int getAllDataRaw( unsigned char *dt);
+
+    /**
+    * Return if there are date available
+    *
+    * @return 0 for no data available, bit0 set for Temp data available, bit1 set for Press/Alti data available
+    *         bit2 set for both Temp and Press/Alti data available
+    */
+    unsigned int isDataAvailable( void);
+
+    /**
+    * Set the oversampling rate value
+    *
+    * @param oversampling values. See MPL3115A2.h
+    * @return none
+    */
+    void sampling_Ratio( unsigned int ratio);
+
+    /**
+    * Configure the sensor to streaming data using Interrupt
+    *
+    * @param user functin callback, oversampling values. See MPL3115A2.h
+    * @return none
+    */
+    void DReady( void(*fptr)(void), unsigned char OS);
+
+
+    void AltitudeTrigger( void(*fptr)(void), unsigned short level);
+
+    /**
+    * Soft Reset
+    *
+    * @param none
+    * @return none
+    */
+    void Reset( void);
+
+    /**
+    * Configure the Pressure offset.
+    * Pressure user accessible offset trim value expressed as an 8-bit 2's complement number.
+    * The user offset registers may be adjusted to enhance accuracy and optimize the system performance.
+    * Range is from -512 to +508 Pa, 4 Pa per LSB.
+    * In RAW output mode no scaling or offsets will be applied in the digital domain
+    *
+    * @param    offset
+    * @return   none
+    */
+    void SetPressureOffset( char offset);
+
+    /**
+    * Configure the Temperature offset.
+    * Temperature user accessible offset trim value expressed as an 8-bit 2's complement number.
+    * The user offset registers may be adjusted to enhance accuracy and optimize the system performance.
+    * Range is from -8 to +7.9375°C 0.0625°C per LSB.
+    * In RAW output mode no scaling or offsets will be applied in the digital domain
+    *
+    * @param    offset
+    * @return   none
+    */
+    void SetTemperatureOffset( char offset);
+
+    /**
+    * Configure the Altitude offset.
+    * Altitude Data User Offset Register (OFF_H) is expressed as a 2’s complement number in meters.
+    * The user offset register provides user adjustment to the vertical height of the Altitude output.
+    * The range of values are from -128 to +127 meters.
+    * In RAW output mode no scaling or offsets will be applied in the digital domain
+    *
+    * @param    offset
+    * @return   none
+    */
+    void SetAltitudeOffset( char offset);
+
+private:
+    I2C m_i2c;
+    int m_addr;
+    unsigned char Device_mode;
+    unsigned char Device_oversampling;
+    void DReady_IRQ( void);
+    void AltitudeTrg_IRQ( void);
+
+    /** Set the device in active mode
+    */
+    void Active( void);
+
+    /** Set the device in standby mode
+    */
+    void Standby( void);
+
+    /** Get the altimiter value from the sensor.
+    *
+    * @param    reg the register from which read the data.
+    *           Can be: REG_ALTIMETER_MSB for altimeter value
+    *                   REG_ALTI_MIN_MSB for the minimum value captured
+    *                   REG_ALTI_MAX_MSB for the maximum value captured
+    */
+    float requestAltimeter( unsigned char reg);
+
+    /** Get the pressure value from the sensor.
+    *
+    * @param    reg the register from which read the data.
+    *           Can be: REG_PRESSURE_MSB for altimeter value
+    *                   REG_PRES_MIN_MSB for the minimum value captured
+    *                   REG_PRES_MAX_MSB for the maximum value captured
+    */
+    float requestPressure( unsigned char reg);
+
+    /** Get the altimiter value from the sensor.
+    *
+    * @param    reg the register from which read the data.
+    *           Can be: REG_TEMP_MSB for altimeter value
+    *                   REG_TEMP_MIN_MSB for the minimum value captured
+    *                   REG_TEMP_MAX_MSB for the maximum value captured
+    */
+    float requestTemperature( unsigned char reg);
+
+    void readRegs(int addr, uint8_t * data, int len);
+    void writeRegs(uint8_t * data, int len);
+
+};
+
+#endif
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GYROMETER.cpp	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,45 @@
+
+#include "GYROMETER.h"
+ #include "mbed.h"
+
+GYROMETER::GYROMETER(PinName sda, PinName scl) : gyroi2c(sda,scl)
+ {
+
+ }
+
+ void GYROMETER::Config(void)
+ {
+   char d[2];
+   d[0] = GYRO_CTRL_REG1;                       //standby mode
+   d[1] = 0x08;
+   gyroi2c.write(GYRO_I2C_ADDRESS, d,2);
+
+
+   d[0] = GYRO_CTRL_REG0;
+   d[1] = 0x00;
+   gyroi2c.write(GYRO_I2C_ADDRESS, d, 2);
+
+
+   d[0] = GYRO_CTRL_REG1;                       // active mode
+   d[1] = 0x0A;
+   gyroi2c.write(GYRO_I2C_ADDRESS, d,2);
+
+ }
+
+ void GYROMETER::getData(float * g_data)
+ {
+
+    char data_bytes[7];
+   gyroi2c.write(GYRO_I2C_ADDRESS,GYRO_STATUS,1,true);  // Read the 6 data bytes
+   gyroi2c.read(GYRO_I2C_ADDRESS,data_bytes,7);
+
+   g_data[0] =  (float)((int16_t)((data_bytes[1]*256) + (data_bytes[2]))) * 0.0625;
+   g_data[1] =  (float)((int16_t)((data_bytes[3]*256) + (data_bytes[4]))) * 0.0625;
+   g_data[2] =  (float)((int16_t)((data_bytes[5]*256) + (data_bytes[6]))) * 0.0625;
+
+ }
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GYROMETER.h	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,29 @@
+#ifndef FXAS21002_H
+#define FXAS21002_H
+#include "mbed.h"
+
+#define GYRO_I2C_ADDRESS 0x40
+
+#define GYRO_STATUS 0x00
+#define GYRO_DEVICE_DETAIL 	0x0C
+#define GYRO_CTRL_REG0		0x0D
+#define GYRO_CTRL_REG1		0x13
+#define GYRO_WHO_AM_I_VALUE 0xD1
+
+class GYROMETER
+{
+    public:
+
+    GYROMETER(PinName sda, PinName scl);
+
+    void Config(void);
+
+    void getData(float * du);
+
+    private:
+    I2C gyroi2c;
+
+};
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Hexi_KW40Z.lib	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/moonshot/code/Screen_Botton/#96bdda7b02d5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Hexi_OLED_SSD1351.lib	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/Hexiwear/code/Hexi_OLED_SSD1351/#ae5fad429790
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MOON_HUMTEMP.cpp	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,81 @@
+#include "Moon_HUMTEMP.h"
+ 
+HTU21D::HTU21D(PinName sda, PinName scl) {
+ 
+    i2c_ = new I2C(sda, scl);
+    //400KHz, as specified by the datasheet.
+    i2c_->frequency(400000);
+ 
+ 
+ 
+}
+ 
+int HTU21D::sampleTemp_cel(void) {
+ 
+    char tx[1];
+    char rx[2];
+ 
+    tx[0] = TRIGGER_TEMP_MEASURE; // Triggers a temperature measure by feeding correct opcode.
+    i2c_->write((HTU21D_I2C_ADDRESS << 1) & 0xFE, tx, 1);
+    wait_ms(50); // Per datasheet, wait long enough for device to sample temperature
+    
+    // Reads triggered measure
+    i2c_->read((HTU21D_I2C_ADDRESS << 1) | 0x01, rx, 2);
+    wait_ms(1);
+    
+    // Algorithm from datasheet to compute temperature.
+    unsigned int rawTemperature = ((unsigned int) rx[0] << 8) | (unsigned int) rx[1];
+    rawTemperature &= 0xFFFC;
+ 
+    float tempTemperature = rawTemperature / (float)65536; //2^16 = 65536
+    float realTemperature = -46.85 + (175.72 * tempTemperature); //From page 14
+ 
+    return (int)realTemperature;
+ 
+}
+ 
+int HTU21D::sampleTemp_fah(void){
+    int Temp_Original = sampleTemp_cel();
+    int fah_temp = Temp_Original * 1.8 + 32;
+    
+    return fah_temp;
+}
+ 
+int HTU21D::sampleTemp_kel(void){
+    int Temp_Original = sampleTemp_cel();
+    int kel_temp = Temp_Original + 274;
+    
+    return kel_temp;
+    
+    
+}
+ 
+int HTU21D:: sample_Humid(void) {
+ 
+    char tx[1];
+    char rx[2];
+ 
+ 
+    tx[0] = TRIGGER_HUMD_MEASURE; // Triggers a humidity measure by feeding correct opcode.
+    i2c_->write((HTU21D_I2C_ADDRESS << 1) & 0xFE, tx, 1);
+    wait_ms(16); // Per datasheet, wait long enough for device to sample humidity
+    
+    // Reads triggered measure
+    i2c_->read((HTU21D_I2C_ADDRESS << 1) | 0x01, rx, 2);
+    wait_ms(1);
+    
+    //Algorithm from datasheet.
+    unsigned int rawHumidity = ((unsigned int) rx[0] << 8) | (unsigned int) rx[1];
+ 
+    rawHumidity &= 0xFFFC; //Zero out the status bits but keep them in place
+    
+    //Given the raw humidity data, calculate the actual relative humidity
+    float tempRH = rawHumidity / (float)65536; //2^16 = 65536
+    float rh = -6 + (125 * tempRH); //From page 14
+ 
+ 
+    return (int)rh;
+ 
+}
+ 
+ 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Moon_HUMTEMP.h	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,57 @@
+
+#include "mbed.h"
+
+// Acquired from Datasheet.
+ 
+#define HTU21D_I2C_ADDRESS  0x40 
+#define TRIGGER_TEMP_MEASURE  0xE3
+#define TRIGGER_HUMD_MEASURE  0xE5
+ 
+ 
+//Commands.
+#define HTU21D_EEPROM_WRITE 0x80
+#define HTU21D_EEPROM_READ  0x81
+
+#ifndef HTU21D_H
+#define HTU21D_H
+
+ 
+/**
+ * MOONSHOT HTU21D digital humidity and temperature sensor.
+ */
+class HTU21D {
+ 
+public:
+ 
+
+    HTU21D(PinName sda, PinName scl);
+ 
+ 
+    //    GET SAMPLES FOR TEMP(in Celcuis)
+    int sampleTemp_cel(void);
+    
+  //    GET SAMPLES FOR TEMP(in  fahrenheit)
+    int sampleTemp_fah(void);
+    
+  //    GET SAMPLES FOR TEMP(in  Kelvin)
+    int sampleTemp_kel(void);
+    
+// SAMPLES OF HUMIDITY 
+    int sample_Humid(void);
+ 
+   
+ 
+private:
+ 
+    I2C* i2c_;
+ 
+
+    void write(int EepromOrRam, int address, int data);   // writing to EEPROM or Ram (destination, address to write to, data to write)
+ 
+
+    int read(int EepromOrRam, int address);  //Reading from EEprom (destination, add to read from)
+ 
+};
+ 
+#endif /* HTU21D_H */
+ 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,3 @@
+# softcom
+Hexiwear 
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/accel_mag.cpp	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,79 @@
+#include "accel_mag.h"
+#include "mbed.h"
+
+FXOS8700::FXOS8700(PinName sda, PinName scl) : FXOS8700_i2c(sda,scl)
+ {
+       
+ }
+    
+ /*Configure the accelerometer*/
+void FXOS8700::configureAccelerometer(void)
+ {
+   char d[2]; 
+//Put accelerometer in standby mode
+   d[0] = FXOS8700_CTRL_REG1;                     
+   d[1] = 0x00; 
+   FXOS8700_i2c.write(FXOS8700_I2C_ADDRESS, d,2);   
+          
+//Put accelerometer in active mode
+   d[0] = FXOS8700_CTRL_REG1;                     
+   d[1] = 0x01;
+   FXOS8700_i2c.write(FXOS8700_I2C_ADDRESS, d, 2);   
+      
+ }
+ /*Configure the magnetometer*/
+  void FXOS8700:: configureMagnetometer(void)
+ {
+   char d[2];
+   d[0] = FXOS8700_CTRL_REG1;                     //Standby mode (Magnetometer)
+   d[1] = 0x00;
+   FXOS8700_i2c.write(FXOS8700_I2C_ADDRESS, d,2);   
+          
+   
+   d[0] = FXOS8700_M_CTRL_REG1;                   //hybrid mode (both accelerometer and magnetometer are active)
+   d[1] = 0x03;
+   FXOS8700_i2c.write(FXOS8700_I2C_ADDRESS, d, 2);   
+   
+
+   d[0] = FXOS8700_CTRL_REG1;                     //Active mode (Magnetometer)
+   d[1] = 0x01;
+   FXOS8700_i2c.write(FXOS8700_I2C_ADDRESS, d,2);  
+   
+ }
+ 
+ void FXOS8700::getAccelData(float * accelData)
+ {
+  
+   char data_bytes[7];
+   char d[1];
+   d[0]=FXOS8700_STATUS;
+   FXOS8700_i2c.write(FXOS8700_I2C_ADDRESS,d,1,true);
+//Read data from X Y Z
+   FXOS8700_i2c.read(FXOS8700_I2C_ADDRESS,data_bytes,7);
+   
+/*Calculation derived from the datasheet*/
+/*256 = 2^8  or >>8 can be used*/
+   accelData[0] =  ((float)((int16_t)(((data_bytes[1]<<8) + (data_bytes[2])))>> 2) * 0.000244);
+   accelData[1] =  ((float)((int16_t)(((data_bytes[3]<<8) + (data_bytes[4])))>> 2) * 0.000244);
+   accelData[2] =  ((float)((int16_t)(((data_bytes[5]<<8) + (data_bytes[6])))>> 2) * 0.000244);
+   
+ }
+
+ void FXOS8700::getMagData(float * magData)
+ {
+  
+   char data_bytes[7];
+   char d[1];
+   d[0]=FXOS8700_MDR_STATUS;
+   FXOS8700_i2c.write(FXOS8700_I2C_ADDRESS,d,1,true);  // Read data from X Y Z
+   FXOS8700_i2c.read(FXOS8700_I2C_ADDRESS,data_bytes,7);
+   
+   magData[0] =  (float)((int16_t)((data_bytes[1]<<8) + (data_bytes[2]))) * 0.1;
+   magData[1] =  (float)((int16_t)((data_bytes[3]<<8) + (data_bytes[4]))) * 0.1;
+   magData[2] =  (float)((int16_t)((data_bytes[5]<<8) + (data_bytes[6]))) * 0.1;
+   
+ }
+     
+     
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/accel_mag.h	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,36 @@
+#ifndef accel_mag_h
+#define accel_mag_h
+#include "mbed.h"
+
+#define FXOS8700_I2C_ADDRESS (0x1E<<1) //SA0pin and SA1pin =0
+
+#define FXOS8700_STATUS             0x00
+#define FXOS8700_MDR_STATUS         0x32
+#define FXOS8700_WHOAMI             0x0D
+#define FXOS8700_CTRL_REG1          0x2A
+#define FXOS8700_M_CTRL_REG1        0x5B
+#define FXOS8700_WHOAMI_VALUE       0xC7
+
+class FXOS8700
+{
+/*Call functions for configuration and data acquisition*/
+    public:
+    
+    FXOS8700(PinName sda, PinName scl);
+
+    void configureAccelerometer(void); 
+    
+    void configureMagnetometer(void);  
+        
+    void getAccelData(float * da); 
+    
+    void getMagData(float * dm);
+    
+    private:
+   I2C FXOS8700_i2c;   
+    
+};
+
+#endif
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lum.cpp	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,160 @@
+#include "lum.h"
+
+TSL2561::TSL2561 (PinName sda, PinName scl)
+ : _i2c_p(new I2C(sda, scl)), _i2c(*_i2c_p)
+{
+    TSL2561_addr = TSL2561_ADDRESS_GND;
+    init();
+}
+
+TSL2561::TSL2561 (PinName sda, PinName scl, uint8_t addr)
+ : _i2c_p(new I2C(sda, scl)), _i2c(*_i2c_p)
+{
+    TSL2561_addr = addr;
+    init();
+}
+
+TSL2561::TSL2561 (I2C& TSL2561_i2c)
+ : _i2c(TSL2561_i2c)
+{
+    TSL2561_addr = TSL2561_ADDRESS_GND;
+    init();
+}
+
+TSL2561::TSL2561 (I2C& TSL2561_i2c, uint8_t addr)
+ : _i2c(TSL2561_i2c)
+{
+    TSL2561_addr = addr;
+    init();
+}
+
+
+void TSL2561::init()            //Initialize sensor
+{
+    _i2c.frequency(100000);
+    power_up();
+    set_timing_reg(TIMING_DEFAULT);
+}
+
+
+float TSL2561::lux()            // Read Lux from sensor
+{
+    double lux0, lux1;
+    double ratio;
+    double dlux;
+
+    dt[0] = CMD_MULTI + TSL2561_DATA0LOW;
+    _i2c.write((int)TSL2561_addr, (char *)dt, 1, true);
+    _i2c.read(TSL2561_addr, (char *)dt, 2, false);
+    ch0 = dt[1] << 8 | dt[0];
+    dt[0] = CMD_MULTI + TSL2561_DATA1LOW;
+    _i2c.write((int)TSL2561_addr, (char *)dt, 1, true);
+    _i2c.read(TSL2561_addr, (char *)dt, 2, false);
+    ch1 = dt[1] << 8 | dt[0];
+    if (ch0 == 0xFFFF) {
+        return 2500.0;
+    }
+    lux0 = (double)ch0;
+    lux1 = (double)ch1;
+    ratio = lux1 / lux0;
+    read_timing_reg();
+    lux0 *= (402.0/integ_time);
+    lux1 *= (402.0/integ_time);
+    lux0 /= gain;
+    lux1 /= gain;
+    if (ratio <= 0.5) {
+        dlux = 0.03040 * lux0 - 0.06200 * lux0 * pow(ratio,1.4);
+    } else if (ratio <= 0.61) {
+        dlux = 0.02240 * lux0 - 0.03100 * lux1;
+    } else if (ratio <= 0.80) {
+        dlux = 0.01280 * lux0 - 0.01530 * lux1;
+    } else if (ratio <= 1.30) {
+        dlux = 0.00146 * lux0 - 0.00112 * lux1;
+    } else {
+        dlux = 0;
+    }
+    return (float)dlux;
+}
+
+
+uint8_t TSL2561::set_timing_reg(uint8_t parameter)
+{
+    dt[0] = CMD_SINGLE + TSL2561_TIMING;
+    dt[1] = parameter;
+    _i2c.write((int)TSL2561_addr, (char *)dt, 2, false);
+    dt[0] = CMD_SINGLE + TSL2561_TIMING;
+    _i2c.write((int)TSL2561_addr, (char *)dt, 1, true);
+    _i2c.read(TSL2561_addr, (char *)dt, 1, false);
+    return dt[0];
+}
+
+uint8_t TSL2561::read_timing_reg(void)
+{
+    uint8_t i;
+
+    dt[0] = CMD_SINGLE + TSL2561_TIMING;
+    _i2c.write((int)TSL2561_addr, (char *)dt, 1, true);
+    _i2c.read(TSL2561_addr, (char *)dt, 1, false);
+    if (dt[0] & TIMING_GAIN_16){
+        gain = 16;
+    } else {
+        gain = 1;
+    }
+    i = dt[0] & 0x3;
+    switch (i) {
+        case 0:
+            integ_time = 13.7;
+            break;
+        case 1:
+            integ_time = 101.0;
+            break;
+        case 2:
+            integ_time = 402.0;
+            break;
+        default:
+            integ_time = 0;
+            break;
+    }
+    return dt[0];
+}
+
+uint16_t TSL2561::get_ID()
+{
+    dt[0] = CMD_SINGLE + TSL2561_ID;
+    _i2c.write((int)TSL2561_addr, (char *)dt, 1, true);
+    _i2c.read(TSL2561_addr, (char *)dt, 2, false);
+    id_number = dt[0] << 8 | dt[1];
+    return id_number;
+}
+
+uint8_t TSL2561::get_device_ID()
+{
+    get_ID();
+    if ((id_number >> 8) == I_AM_TSL2561) {
+        return 1;
+    } else {
+        return 0;
+    }
+}
+
+void TSL2561::power_up()
+{
+    dt[0] = CMD_SINGLE + TSL2561_CONTROL;
+    dt[1] = 3;
+    _i2c.write((int)TSL2561_addr, (char *)dt, 2, false);
+}
+
+void TSL2561::power_down()
+{
+    dt[0] = CMD_SINGLE + TSL2561_CONTROL;
+    dt[1] = 0;
+    _i2c.write((int)TSL2561_addr, (char *)dt, 2, false);
+}
+
+void TSL2561::frequency(int hz)
+{
+    _i2c.frequency(hz);
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lum.h	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,81 @@
+#ifndef lum_H
+#define lum_H
+
+#include "mbed.h"
+
+// Luminosity sensor, TSL2561
+// Address b7=0,b6=1,b5=1,b4=1,b3=0,b2=0,b1=1, b0=R/W
+#define TSL2561_ADDRESS_GND         (0x29 << 1)
+#define TSL2561_ADDRESS_FLOAT       (0x39 << 1)
+#define TSL2561_ADDRESS_VDD         (0x49 << 1)
+
+
+// Registers
+#define TSL2561_CONTROL             0x00 //Control of basic functions
+#define TSL2561_TIMING              0x01 //Integration time/gain control
+#define TSL2561_THRESHLOWLOW        0x02 //Low byte of low interrupt threshold
+#define TSL2561_THRESHHIGHLOW       0x04 //High byte of low interrupt threshold
+#define TSL2561_INTERRUPT           0x06 //Interrupt control
+#define TSL2561_CRC                 0x08 //Factory test — not a user register
+#define TSL2561_ID                  0x0A //Part number/ Rev ID
+#define TSL2561_DATA0LOW            0x0C //Low byte of ADC channel 0
+#define TSL2561_DATA0HIGH           0x0D //High byte of ADC channel 0
+#define TSL2561_DATA1LOW            0x0E //Low byte of ADC channel 1
+#define TSL2561_DATA1HIGH           0x0F //High byte of ADC channel 1
+
+
+#define TIMING_GAIN_1               (0UL << 4)
+#define TIMING_GAIN_16              (1UL << 4)
+#define TIMING_TIME_13R7            (0x0)
+#define TIMING_TIME_101             (0x1)
+#define TIMING_TIME_402             (0x2)
+#define TIMING_TIME_MANU            (0x3)
+#define TIMING_DEFAULT              (TIMING_GAIN_1 + TIMING_TIME_402)
+
+// ID 
+#define I_AM_TSL2561                0x50
+#define REG_NO_MASK                 0x0F
+
+// COMMAND 
+#define CMD_CMDMODE                 (1UL << 7)
+#define CMD_CLEAR                   (1UL << 6)
+#define CMD_WORD                    (1UL << 5)
+#define CMD_BLOCK                   (1UL << 4)
+#define CMD_SINGLE                  (CMD_CMDMODE)
+#define CMD_MULTI                   (CMD_CMDMODE + CMD_WORD)
+
+class TSL2561
+{
+public:
+    TSL2561(PinName sda, PinName scl);      //set pinname
+    TSL2561(PinName sda, PinName scl, uint8_t addr);
+
+    TSL2561(I2C& TSL2561_i2c);
+    TSL2561(I2C& TSL2561_i2c, uint8_t addr);
+
+    float lux(void);
+    uint8_t set_timing_reg(uint8_t parameter);    //Set timing register
+    uint8_t read_timing_reg(void);    //Read timing register
+    void frequency(int hz);           //Set I2C clock frequency
+    uint8_t get_device_ID(void);           //check Device ID number
+    uint16_t get_ID(void);           //Read ID and Revision Number
+    void power_up(void);
+    void power_down(void);
+
+protected:
+    I2C *_i2c_p;
+    I2C &_i2c;
+
+    void init(void);   //initialize
+
+private:
+    uint8_t  TSL2561_addr;
+    uint8_t  dt[4];
+    uint32_t ch0;
+    uint32_t ch1;
+    int8_t   gain;
+    uint16_t  id_number;
+    double   integ_time;
+};
+
+#endif    
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,253 @@
+#include "mbed.h"
+#include "Hexi_KW40Z.h"
+#include "Hexi_OLED_SSD1351.h"
+#include "OLED_types.h"
+#include "OpenSans_Font.h"
+#include "string.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+#define LED_ON      0
+#define LED_OFF     1
+#define MPL3115A2_I2C_ADDRESS (0x60<<1)
+
+void StartHaptic(void);
+void StopHaptic(void const *n);
+
+
+
+DigitalOut redLed(LED1,1);
+DigitalOut greenLed(LED2,1);
+DigitalOut WHITELed(LED3,1);
+DigitalOut haptic(PTB9);
+DigitalOut sensorPowerEn(PTB12);
+DigitalOut powerEN (PTB12);
+DigitalOut led1(LED_GREEN); // RGB LED
+Serial pc(USBTX,USBRX); // Serial interface
+
+char text[20]; // Text Buffer for dynamic value displayed
+char text1[20]; // Text Buffer for dynamic value displayed
+char text2[20]; // Text Buffer for dynamic value displayed
+char text3[20]; // Text Buffer for dynamic value displayed
+char text4[20]; // Text Buffer for dynamic value displayed
+
+/* Define timer for haptic feedback */
+RtosTimer hapticTimer(StopHaptic, osTimerOnce);
+
+/* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */
+KW40Z kw40z_device(PTE24, PTE25);
+
+/* Instantiate the SSD1351 OLED Driver */
+SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); /* (MOSI,SCLK,POWER,CS,RST,DC) */
+//void page_1(void);
+
+
+
+
+/****************************Call Back Functions*******************************/
+
+
+void ButtonRight(void)
+{
+    StartHaptic();
+    pc.printf("opoooooooo");
+
+}
+
+void ButtonLeft(void)
+{
+    StartHaptic();
+
+}
+
+void ButtonDown(void)
+{
+
+    StartHaptic();
+    pc.printf("down");
+
+}
+
+void ButtonUp(void)
+{
+    StartHaptic();
+    pc.printf("up once");
+
+}
+
+void ButtonSlide(void)
+{
+    StartHaptic();
+}
+void PassKey(void)
+{
+    StartHaptic();
+    strcpy((char *) text,"PAIR CODE");
+    oled.TextBox((uint8_t *)text,0,25,95,18);
+
+    /* Display Bond Pass Key in a 95px by 18px textbox at x=0,y=40 */
+    sprintf(text,"%d", kw40z_device.GetPassKey());
+    oled.TextBox((uint8_t *)text,0,40,95,18);
+}
+
+/***********************End of Call Back Functions*****************************/
+
+
+
+
+
+/********************************Main******************************************/
+
+
+int pages[5];
+
+int row_count = 0;
+
+void pag_1(){
+    
+    
+    pc.printf("page1\n");
+    }
+void pag_2(){
+    
+    
+    pc.printf("page2\n");
+    }
+
+void pag_3(){
+    
+    
+    pc.printf("page3\n");
+    }
+
+void pag_4(){
+    
+    
+    pc.printf("page4\n");
+    }
+void pag_5(){
+    
+    
+    pc.printf("page5\n");
+    }
+void switch_page (int count)
+{
+    //This function checks
+    //the int value of the count to determine what page to load to the screen
+    switch (count) {
+        //checks and calls appropriate function
+        case 0:
+            // pull first page function
+            pag_1();
+            break;
+
+        case 1:
+            // pull 2nd  page function
+            pag_2();
+            break;
+
+        case 2:
+            // pull 3rd page function
+            pag_3();
+            break;
+
+        case 3:
+            // pull 4th page function
+            pag_4();
+            break;
+
+
+        case 4:
+            // pull 5th page function
+            pag_5();
+            break;
+
+        default:
+            // Do nothing
+            break;
+
+    }
+
+}
+ 
+void ButtonTouch()
+{
+  StartHaptic();
+    
+  //  typedef int(*pageFunction)();
+  //  pageFunction page_1 = pag_1;
+    
+   
+       switch_page(row_count);
+        if (row_count > 4) row_count = 4;
+         
+         row_count++;
+}
+
+
+void ButtonTouch2()
+{
+  StartHaptic();
+    
+ //   typedef int(*pageFunction)();
+ //   pageFunction page_1 = pag_1;
+    
+   
+       
+        if (row_count > 4) row_count = 4;
+        row_count--;
+        switch_page(row_count);
+}
+
+int main()
+{
+    
+    
+
+    //kw40z_device.ToggleAdvertisementMode();
+    /* Register callbacks to application functions */
+    kw40z_device.attach_buttonLeft(&ButtonLeft);
+    kw40z_device.attach_buttonRight(&ButtonRight);
+    kw40z_device.attach_passkey(&PassKey);
+    kw40z_device.attach_buttonDown(&ButtonDown);
+    kw40z_device.attach_buttonUp(&ButtonUp);
+    kw40z_device.PageIndex(&ButtonTouch);
+    kw40z_device.PageIndex2(&ButtonTouch2);
+
+
+    /* Turn on the backlight of the OLED Display */
+    oled.DimScreenON();
+    /* Fills the screen with solid black */
+    oled.FillScreen(COLOR_BLACK);
+    /* Get OLED Class Default Text Properties */
+    oled_text_properties_t textProperties = {0};
+    oled.GetTextProperties(&textProperties);
+    oled.FillScreen(COLOR_BLACK);
+
+    while (true) {
+    
+        Thread::wait(0.1);
+        WHITELed = !kw40z_device.GetAdvertisementMode(); /*Indicate BLE Advertisment Mode*/
+        Thread::wait(50);
+    }
+}
+
+/******************************End of Main*************************************/
+
+
+void StartHaptic(void)
+{
+    hapticTimer.start(50);
+    haptic = 1;
+}
+
+void StopHaptic(void const *n)
+{
+    haptic = 0;
+    hapticTimer.stop();
+}
+
+    
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,2 @@
+https://github.com/ARMmbed/mbed-os/#21dd7008a1540c02150f1b87c12294301db979bb
+