Leon Wehmeier / Mbed OS fiasco_max32630

Dependencies:   SoftSerial MAX14690 Buffer

Fork of rtos_threading_with_callback by mbed_example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers getDHT.cpp Source File

getDHT.cpp

00001 #include "mbed.h"
00002 #include "DHT.h"
00003 #include "rtos.h"
00004 #include "global.h"
00005 #include "logger.h"
00006 
00007 class DHTData
00008 {
00009 public:
00010     static void run()
00011     {
00012         while(1)
00013         {
00014             int error = dht.readData();
00015             if (0 == error) {
00016                 float c   = dht.ReadTemperature(CELCIUS);
00017                 float h   = dht.ReadHumidity();
00018                 humidity = h;
00019                 float dpf = dht.CalcdewPointFast(c, h);
00020                 char *buffer = new char[50];
00021                 sprintf(buffer, "Temperature: %3.2f, Humidity: %3.2f\r\n", c,h);
00022                 Logger::log(buffer);
00023             
00024                 printf("DHT: Temperature in Celcius: %4.2f\r\n", c);
00025                 printf("DHT: Humidity is %4.2f, Dewpoint: %4.2f\r\n", h, dpf);
00026                 
00027                 {
00028                     linkPacket *p = new linkPacket();
00029                     uint8_t *data = new uint8_t[4];
00030                     data[0]=((uint8_t*)&h)[0];
00031                     data[1]=((uint8_t*)&h)[1];
00032                     data[2]=((uint8_t*)&h)[2];
00033                     data[3]=((uint8_t*)&h)[3];
00034                     p->payload=data;
00035                     p->payloadSz=4;
00036                     p->priority =3;
00037                     p->frameType = FRAMETYPE_HUMIDITY;
00038                     txQueue.addPacket(p);
00039                 }
00040                 {
00041                     linkPacket *p = new linkPacket();
00042                     uint8_t *data = new uint8_t[4];
00043                     data[0]=((uint8_t*)&dpf)[0];
00044                     data[1]=((uint8_t*)&dpf)[1];
00045                     data[2]=((uint8_t*)&dpf)[2];
00046                     data[3]=((uint8_t*)&dpf)[3];
00047                     p->payload=data;
00048                     p->payloadSz=4;
00049                     p->priority =3;
00050                     p->frameType = FRAMETYPE_DEWPOINT;
00051                     txQueue.addPacket(p);
00052                 }
00053             
00054             } else {
00055                 printf("DHT: Error: %d\r\n", error);
00056             }
00057             rtos::Thread::wait(20000);//ms
00058         }
00059     }
00060     DHTData()
00061     {
00062         registerThread(DHTData::run);
00063     }
00064     static DHT dht;
00065 };
00066 DHT DHTData::dht(P3_2, DHT11);;
00067 
00068 // some witchcraft to register run function without touching anything outside our library
00069 static DHTData _dummy;