MAIN

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

Committer:
J_Satchell
Date:
Mon May 15 11:38:07 2017 +0000
Revision:
37:13f74964a045
Parent:
36:af6abc6f7590
fff

Who changed what in which revision?

UserRevisionLine numberNew contents of line
J_Satchell 36:af6abc6f7590 1 #include "mbed.h"
J_Satchell 36:af6abc6f7590 2 #include "rtos.h"
J_Satchell 36:af6abc6f7590 3 #include "hts221.h"
J_Satchell 36:af6abc6f7590 4 #include "LPS25H.h"
J_Satchell 36:af6abc6f7590 5 #include "Data.hpp"
J_Satchell 36:af6abc6f7590 6 #include "log.hpp"
J_Satchell 36:af6abc6f7590 7
J_Satchell 36:af6abc6f7590 8 DigitalOut myled(LED1);
J_Satchell 36:af6abc6f7590 9 I2C i2c2(I2C_SDA, I2C_SCL);
J_Satchell 36:af6abc6f7590 10 Mutex mutex_s;
J_Satchell 36:af6abc6f7590 11
J_Satchell 36:af6abc6f7590 12 float tempCelsius = 25.50;
J_Satchell 36:af6abc6f7590 13 float humi = 55;
J_Satchell 36:af6abc6f7590 14 char cmd=0;
J_Satchell 36:af6abc6f7590 15 uint32_t seconds = 0, minutes=0, hours=0;
J_Satchell 36:af6abc6f7590 16
J_Satchell 36:af6abc6f7590 17 LPS25H barometer(i2c2, LPS25H_V_CHIP_ADDR);
J_Satchell 36:af6abc6f7590 18 HTS221 humidity(I2C_SDA, I2C_SCL);
J_Satchell 36:af6abc6f7590 19
J_Satchell 36:af6abc6f7590 20
J_Satchell 36:af6abc6f7590 21 void sensor_init()
J_Satchell 36:af6abc6f7590 22 {
J_Satchell 36:af6abc6f7590 23 humidity.init();
J_Satchell 36:af6abc6f7590 24 humidity.calib();
J_Satchell 36:af6abc6f7590 25 myled = 0;
J_Satchell 36:af6abc6f7590 26 }
J_Satchell 36:af6abc6f7590 27
J_Satchell 36:af6abc6f7590 28 void sensor_run()
J_Satchell 36:af6abc6f7590 29 {
J_Satchell 36:af6abc6f7590 30 while (1){
J_Satchell 36:af6abc6f7590 31
J_Satchell 36:af6abc6f7590 32 humidity.ReadTempHumi(&tempCelsius, &humi);
J_Satchell 36:af6abc6f7590 33 /*printf("%4.2fC %3.1f%%", tempCelsius, humi);*/
J_Satchell 36:af6abc6f7590 34 barometer.get();
J_Satchell 36:af6abc6f7590 35 /*printf(" %6.1f %4.1f\r\n", barometer.pressure(), barometer.temperature());*/
J_Satchell 36:af6abc6f7590 36 myled = 1; // LED is ON
J_Satchell 36:af6abc6f7590 37 Thread::wait(200); // 200 ms NB 'Thread::wait(int d);' !!! d is in milliseconds!
J_Satchell 36:af6abc6f7590 38 myled = 0; // LED is OFF
J_Satchell 36:af6abc6f7590 39 Thread::wait(100); // 100 ms
J_Satchell 36:af6abc6f7590 40 mutex_s.lock();
J_Satchell 36:af6abc6f7590 41 Data entry;
J_Satchell 36:af6abc6f7590 42 entry.tempCelsius = tempCelsius;
J_Satchell 36:af6abc6f7590 43 entry.humi = humi;
J_Satchell 36:af6abc6f7590 44 entry.pressure= barometer.pressure();
J_Satchell 37:13f74964a045 45 entry.logtime = time(0);
J_Satchell 36:af6abc6f7590 46 log_push(entry);
J_Satchell 36:af6abc6f7590 47 mutex_s.unlock();
J_Satchell 37:13f74964a045 48 Thread::wait(1000);
J_Satchell 36:af6abc6f7590 49
J_Satchell 36:af6abc6f7590 50 }
J_Satchell 36:af6abc6f7590 51
J_Satchell 36:af6abc6f7590 52 }