Dissolved oxygen code

Dependencies:   mbed

Committer:
e58136782000
Date:
Fri Nov 03 09:16:32 2017 +0000
Revision:
0:9522c4dc43b8
Dissolved oxygen code;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
e58136782000 0:9522c4dc43b8 1 #include "mbed.h"
e58136782000 0:9522c4dc43b8 2
e58136782000 0:9522c4dc43b8 3 #ifndef BME280_HPP
e58136782000 0:9522c4dc43b8 4 #define BME280_HPP
e58136782000 0:9522c4dc43b8 5
e58136782000 0:9522c4dc43b8 6 #define BME280_size 5
e58136782000 0:9522c4dc43b8 7
e58136782000 0:9522c4dc43b8 8 Serial sensor(PA_11,PA_12);// Tx,Rx
e58136782000 0:9522c4dc43b8 9 Serial pc(USBTX,USBRX);
e58136782000 0:9522c4dc43b8 10 class BME280{
e58136782000 0:9522c4dc43b8 11 public:
e58136782000 0:9522c4dc43b8 12 void judgement_data(char buf[]);
e58136782000 0:9522c4dc43b8 13 int data_read();
e58136782000 0:9522c4dc43b8 14
e58136782000 0:9522c4dc43b8 15 int datareadfuiction(int data);
e58136782000 0:9522c4dc43b8 16 void receive();
e58136782000 0:9522c4dc43b8 17 private:
e58136782000 0:9522c4dc43b8 18 int buf[BME280_size];
e58136782000 0:9522c4dc43b8 19 void send_AT();
e58136782000 0:9522c4dc43b8 20
e58136782000 0:9522c4dc43b8 21 int data;
e58136782000 0:9522c4dc43b8 22
e58136782000 0:9522c4dc43b8 23 };
e58136782000 0:9522c4dc43b8 24 int BME280::datareadfuiction(int data)
e58136782000 0:9522c4dc43b8 25 {
e58136782000 0:9522c4dc43b8 26 return buf[data];
e58136782000 0:9522c4dc43b8 27 }
e58136782000 0:9522c4dc43b8 28 void BME280::judgement_data(char buf[])
e58136782000 0:9522c4dc43b8 29 {
e58136782000 0:9522c4dc43b8 30 // int i=0;
e58136782000 0:9522c4dc43b8 31
e58136782000 0:9522c4dc43b8 32 /* if(buf[i++]== 0x5A){
e58136782000 0:9522c4dc43b8 33 //pc.printf("first_step\n");
e58136782000 0:9522c4dc43b8 34 if(buf[i++]== 0x5A){
e58136782000 0:9522c4dc43b8 35 //pc.printf("second_step\n");
e58136782000 0:9522c4dc43b8 36 //i++;//go to data type
e58136782000 0:9522c4dc43b8 37 if(buf[i] == 0x15){
e58136782000 0:9522c4dc43b8 38 //pc.printf("Lux type\n");
e58136782000 0:9522c4dc43b8 39 i++;//04
e58136782000 0:9522c4dc43b8 40 Lux = ((buf[i+1]<<24) | (buf[i+2]<<16) | (buf[i+3]<<8) | buf[i+4])/100;
e58136782000 0:9522c4dc43b8 41 //Lux = (0x00<<24) | (0x00<<16) | (0xFE<<8) | 0x40;//test
e58136782000 0:9522c4dc43b8 42 //pc.printf("Lux = %d\n", Lux);
e58136782000 0:9522c4dc43b8 43 }else if(buf[i] == 0x45){
e58136782000 0:9522c4dc43b8 44 //pc.printf("temp type\n");
e58136782000 0:9522c4dc43b8 45 i++;//0A
e58136782000 0:9522c4dc43b8 46 Temp = ((buf[i+1]<<8)|(buf[i+2]))/100;
e58136782000 0:9522c4dc43b8 47 Preesure = ((buf[i+3]<<24)|(buf[i+4]<<16)|(buf[i+5]<<8)|(buf[i+6]))/100;
e58136782000 0:9522c4dc43b8 48 Hum = ((buf[i+7]<<8)|(buf[i+8]))/100;
e58136782000 0:9522c4dc43b8 49 Height = ((buf[i+9]<<8)|(buf[i+10]));
e58136782000 0:9522c4dc43b8 50 //pc.printf("Temp = %d\n", Temp);
e58136782000 0:9522c4dc43b8 51 //pc.printf("Preesure = %d\n", Preesure);
e58136782000 0:9522c4dc43b8 52 //pc.printf("Hum = %d\n", Hum);
e58136782000 0:9522c4dc43b8 53 //pc.printf("Height = %d\n", Height);
e58136782000 0:9522c4dc43b8 54 }
e58136782000 0:9522c4dc43b8 55 }
e58136782000 0:9522c4dc43b8 56 }*/
e58136782000 0:9522c4dc43b8 57 }
e58136782000 0:9522c4dc43b8 58 void BME280::receive()
e58136782000 0:9522c4dc43b8 59 {
e58136782000 0:9522c4dc43b8 60 pc.printf("start receive\n");
e58136782000 0:9522c4dc43b8 61 pc.printf("buf 0 %d\n",buf[0]);
e58136782000 0:9522c4dc43b8 62 for(int i=0;i<BME280_size;i++){
e58136782000 0:9522c4dc43b8 63 buf[i] = sensor.getc();
e58136782000 0:9522c4dc43b8 64 pc.printf("data %d\n",i);
e58136782000 0:9522c4dc43b8 65 //pc.putc(buf[i]);
e58136782000 0:9522c4dc43b8 66 }
e58136782000 0:9522c4dc43b8 67
e58136782000 0:9522c4dc43b8 68 }
e58136782000 0:9522c4dc43b8 69
e58136782000 0:9522c4dc43b8 70 int BME280::data_read()
e58136782000 0:9522c4dc43b8 71 {\
e58136782000 0:9522c4dc43b8 72 receive();
e58136782000 0:9522c4dc43b8 73 //wait(0.2);
e58136782000 0:9522c4dc43b8 74 // judgement_data(this->buf);
e58136782000 0:9522c4dc43b8 75
e58136782000 0:9522c4dc43b8 76 return data;
e58136782000 0:9522c4dc43b8 77 }
e58136782000 0:9522c4dc43b8 78
e58136782000 0:9522c4dc43b8 79 #endif