wang tang / Mbed 2 deprecated Turbidity_sensor_online

Dependencies:   watersenor_and_temp_code MQTT NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed

Fork of Dissolved_oxygen_sensor_online by wang tang

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BME280.hpp Source File

BME280.hpp

00001 #include "mbed.h"
00002 #ifndef BME280_HPP
00003 #define BME280_HPP
00004 
00005 #define BME280_size 5
00006 
00007 Serial sensor(PA_11,PA_12);// Tx,Rx
00008 Serial pc(USBTX,USBRX);
00009 class BME280{
00010 public:
00011     void judgement_data(char buf[]);
00012     int data_read();
00013 
00014     int datareadfuiction(int data);
00015     void receive();   
00016 private:
00017     char buf[BME280_size];
00018     void send_AT();
00019 
00020     int data;
00021 
00022 };
00023 int BME280::datareadfuiction(int data)
00024 {
00025    return  buf[data];
00026 }
00027 void BME280::judgement_data(char buf[])
00028 {
00029 //    int i=0;
00030     
00031 /*    if(buf[i++]== 0x5A){
00032         //pc.printf("first_step\n");
00033         if(buf[i++]== 0x5A){
00034             //pc.printf("second_step\n");
00035            //i++;//go to data type
00036             if(buf[i] == 0x15){
00037                 //pc.printf("Lux type\n");
00038                 i++;//04
00039                 Lux = ((buf[i+1]<<24) | (buf[i+2]<<16) | (buf[i+3]<<8) | buf[i+4])/100;
00040                 //Lux = (0x00<<24) | (0x00<<16) | (0xFE<<8) | 0x40;//test
00041                 //pc.printf("Lux = %d\n", Lux);
00042             }else if(buf[i] == 0x45){
00043                 //pc.printf("temp type\n");
00044                 i++;//0A
00045                 Temp = ((buf[i+1]<<8)|(buf[i+2]))/100;
00046                 Preesure = ((buf[i+3]<<24)|(buf[i+4]<<16)|(buf[i+5]<<8)|(buf[i+6]))/100;
00047                 Hum = ((buf[i+7]<<8)|(buf[i+8]))/100;
00048                 Height = ((buf[i+9]<<8)|(buf[i+10]));
00049                 //pc.printf("Temp = %d\n", Temp);
00050                 //pc.printf("Preesure = %d\n", Preesure);
00051                 //pc.printf("Hum = %d\n", Hum);
00052                 //pc.printf("Height = %d\n", Height);
00053             }
00054         }
00055     }*/
00056 }
00057 void BME280::receive()
00058 {
00059     pc.printf("start receive \n");
00060     for(int i=0;i<BME280_size;i++)
00061     {
00062         sensor.gets(buf,8); 
00063     }
00064     
00065 }
00066 
00067 int BME280::data_read()
00068 {
00069     receive();
00070     //wait(0.2);
00071     judgement_data(this->buf);
00072     
00073     return data;
00074 }
00075 
00076 #endif