sleep logic implemented
This commit is contained in:
parent
8bde85723d
commit
48b9fb5015
1 changed files with 11 additions and 5 deletions
|
@ -2,9 +2,9 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "../modules/pico-onewire/api/one_wire.h"
|
||||||
#include "hardware/i2c.h"
|
#include "hardware/i2c.h"
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
#include "../modules/pico-onewire/api/one_wire.h"
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "ds18b20.h"
|
#include "ds18b20.h"
|
||||||
|
@ -55,7 +55,8 @@ int main() {
|
||||||
sleep_ms(3000);
|
sleep_ms(3000);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int duration = oneWire.convert_temperature(address, true, false);
|
absolute_time_t start = get_absolute_time();
|
||||||
|
oneWire.convert_temperature(address, true, false);
|
||||||
temp_act = oneWire.temperature(address);
|
temp_act = oneWire.temperature(address);
|
||||||
|
|
||||||
if (isSystemOn && temp_act < temp_tgt - temp_diff) {
|
if (isSystemOn && temp_act < temp_tgt - temp_diff) {
|
||||||
|
@ -78,8 +79,13 @@ int main() {
|
||||||
|
|
||||||
myLCD.setCursor(0, 0);
|
myLCD.setCursor(0, 0);
|
||||||
myLCD.sendString(lcdText.str());
|
myLCD.sendString(lcdText.str());
|
||||||
if (duration > 0 && duration <= 1000) {
|
|
||||||
sleep_ms(1000 - duration);
|
absolute_time_t stop = get_absolute_time();
|
||||||
}
|
|
||||||
|
int64_t duration_ms = absolute_time_diff_us(start, stop) / 1000;
|
||||||
|
int64_t timeToSleep = 1000 - duration_ms;
|
||||||
|
|
||||||
|
if (timeToSleep > 0)
|
||||||
|
sleep_ms(timeToSleep);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue