voor Arne

Dependencies:   ESP8266Interface FXAS21002 FXOS8700 Hexi_OLED_SSD1351

Fork of Hexi_Magneto-v2_Example by Hexiwear

main.cpp

Committer:
blownelco
Date:
2016-12-05
Revision:
2:3c1fe1657db9
Parent:
1:31908216b9ac
Child:
3:e259f976e1fc

File content as of revision 2:3c1fe1657db9:

#include "mbed.h"
#include "FXOS8700.h"
#include "Hexi_OLED_SSD1351.h"
#include "images.h"
#include "string.h"
#include "ESP8266Interface.h"

// Pin connections
DigitalOut led1(LED_GREEN); // RGB LED
DigitalOut led2(PTA12); // RGB LED


DigitalOut PWD(PTB2);
DigitalOut G15(PTB11);



//Serial pc(USBTX, USBRX); // Serial interface
//RawSerial wifi(PTD3, PTD2);
FXOS8700 mag(PTC11, PTC10);
SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver (MOSI,SCLK,POWER,CS,RST,DC)

// Variables
float mag_data[3]; // Storage for the data from the sensor
float mag_rms=0.0; // RMS value from the sensor
float mx, my, mz; // Integer value from the sensor to be displayed
const uint8_t *image1; // Pointer for the image to be 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


//void Rx_interrupt();
//void read_line();


// Circular buffers for serial TX and RX data - used by interrupt routines
const int buffer_size = 255;
// might need to increase buffer size for high baud rates
char rx_buffer[buffer_size+1];
// Circular buffer pointers
// volatile makes read-modify-write atomic 
volatile int rx_in=0;
volatile int rx_out=0;
// Line buffers for sprintf and sscanf
char tx_line[80];
char rx_line[80];

ESP8266Interface wifi(PTD3,PTD2,PTD11,"MINI","kplaetevoet",9600); // TX,RX,Reset,SSID,Password,Baud

int main() {
    

    /* wifi3 board reset etc */
    PWD = 1;
    G15 = 0;     
    /*Wifi initialisation commands */
    
    wifi.init(); //Reset
    printf("init done");
    wifi.connect(); 
    wifi.getIPAddress();
    
    //ebsocket ws("ws://192.168.1.20:8888/ws");

     
    // Configure Accelerometer FXOS8700, Magnetometer FXOS8700
    mag.mag_config();
    
    /* Setting pointer location of the 96 by 96 pixel bitmap */
    image1  = Magneto;

    /* Turn on the backlight of the OLED Display */
//    oled.DimScreenON();
    
    /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */
    oled.DrawImage(image1,0,0);  

    
    while (true) 
    {
    
      mag.acquire_mag_data_uT(mag_data);
      mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3);
      printf("Magnetometer \tX-Axis %4.2f \tY-Axis %4.2f \tZ-Axis %4.2f \tRMS %4.2f\n\n\r",mag_data[0],mag_data[1],mag_data[2],mag_rms);
      wait(0.01);
      mx = mag_data[0];
      my = mag_data[1];
      mz = mag_data[2];

      /* Get OLED Class Default Text Properties */
      oled_text_properties_t textProperties = {0};
      oled.GetTextProperties(&textProperties); 
      
      /* Set text properties to white and right aligned for the dynamic text */
      textProperties.fontColor = COLOR_BLUE;
      textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
      oled.SetTextProperties(&textProperties);  
      
      /* Display Legends */
      strcpy((char *) text1,"X-Axis (uT):");
      oled.Label((uint8_t *)text1,3,45);      
      
      /* Format the value */
      sprintf(text1,"%4.2f",mx);
      /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
      oled.TextBox((uint8_t *)text1,70,45,20,15); //Increase textbox for more digits

      /* Set text properties to white and right aligned for the dynamic text */ 
      textProperties.fontColor = COLOR_GREEN;
      textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
      oled.SetTextProperties(&textProperties);  

      /* Display Legends */
      strcpy((char *) text2,"Y-Axis (uT):");
      oled.Label((uint8_t *)text2,3,62); 
      
      /* Format the value */
      sprintf(text2,"%4.2f",my);
      /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
      oled.TextBox((uint8_t *)text2,70,62,20,15); //Increase textbox for more digits
      
      /* Set text properties to white and right aligned for the dynamic text */ 
      textProperties.fontColor = COLOR_RED;
      textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
      oled.SetTextProperties(&textProperties);  
      
      /* Display Legends */
      strcpy((char *) text3,"Z-Axis (uT):");
      oled.Label((uint8_t *)text3,3,79);       
      
      /* Format the value */
      sprintf(text3,"%4.2f",mz);
      /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
      oled.TextBox((uint8_t *)text3,70,79,20,15); //Increase textbox for more digits

      led1 = !led1;
      Thread::wait(250);
    }
}