add mcu_sleep routines

This commit is contained in:
harald42 2016-04-12 10:34:40 +02:00
parent 743245e230
commit 9a3c6adf8d
9 changed files with 71 additions and 37 deletions

View file

@ -14,12 +14,9 @@
#include "Adafruit_HTU21DF.h"
extern "C" {
#include "arduino-process.h"
#include "rest-engine.h"
extern volatile uint8_t mcusleepcycle; // default 16
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
extern resource_t res_htu21dtemp, res_htu21dhum, res_battery;
@ -51,19 +48,19 @@ void setup (void)
// LOOP_INTERVAL (10 * CLOCK_SECOND)
void loop (void)
{
mcusleepcycle=0; // dont sleep
htu21d_temp = htu.readTemperature();
htu21d_hum = htu.readHumidity();
mcusleepcycle=32; // sleep, wakeup every 32 cycles
dtostrf(htu21d_temp , 6, 2, htu21d_temp_s );
dtostrf(htu21d_hum , 6, 2, htu21d_hum_s );
// remove space
if(htu21d_temp_s[0]==' '){
memcpy (htu21d_temp_s,htu21d_temp_s+1,strlen(htu21d_temp_s)+1);
}
if(htu21d_hum_s[0]==' '){
mcu_sleep_off();
htu21d_temp = htu.readTemperature();
htu21d_hum = htu.readHumidity();
mcu_sleep_on();
dtostrf(htu21d_temp , 6, 2, htu21d_temp_s );
tostrf(htu21d_hum , 6, 2, htu21d_hum_s );
// remove space
if(htu21d_temp_s[0]==' '){
memcpy (htu21d_temp_s,htu21d_temp_s+1,strlen(htu21d_temp_s)+1);
}
if(htu21d_hum_s[0]==' '){
memcpy (htu21d_hum_s,htu21d_hum_s+1,strlen(htu21d_hum_s)+1);
}
}
// debug only
// printf("Temp: %s",htu21d_temp_s);