misc small changes
This commit is contained in:
8
main.cpp
8
main.cpp
@@ -39,7 +39,7 @@ struct Sensors {
|
||||
std::mutex mtx; // making sure the struct isnt accessed by multiple threads at once
|
||||
};
|
||||
|
||||
void sighandler(int s) { // can i remove int s
|
||||
void sighandler(int) {
|
||||
log(LOG::WRN, "Signal", "got SIGINT/SIGTERM, exiting...");
|
||||
sem::main.release();
|
||||
sem::display.release();
|
||||
@@ -53,6 +53,7 @@ void hassThread(std::stop_token st, Sensors* s) {
|
||||
pc_power.service();
|
||||
{
|
||||
// locks mutex for the lifetime of the scope, unlocks when it goes out of scope
|
||||
// mutex can only be locked in one place, so when its locked here, other threads need to wait until its unlocked before they can lock it again
|
||||
std::lock_guard<std::mutex> lock(s->mtx);
|
||||
s->hass_state = pc_power.state;
|
||||
}
|
||||
@@ -68,7 +69,6 @@ void sensorsThread(std::stop_token st, Sensors* s) {
|
||||
while (!st.stop_requested()) {
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
{
|
||||
// this will unlock when program goes out of scope
|
||||
std::lock_guard<std::mutex> lock(s->mtx);
|
||||
|
||||
sys::getTimeDate(&s->td);
|
||||
@@ -79,7 +79,7 @@ void sensorsThread(std::stop_token st, Sensors* s) {
|
||||
gpu::update(&s->gpu);
|
||||
}
|
||||
|
||||
// std::println("[Sensors] took {} microseconds", std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start).count());
|
||||
// log(LOG::DBG, "Sensors", "took {} microseconds", std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start).count());
|
||||
sem::display.release(); // unlocks display loop
|
||||
std::this_thread::sleep_until(start + std::chrono::milliseconds(LCD_INTERVAL_MS));
|
||||
}
|
||||
@@ -95,7 +95,7 @@ void displayThread(std::stop_token st, Sensors* s) {
|
||||
|
||||
lcd.setCustomChar(0, {16, 6, 9, 8, 8, 9, 6, 0}); // celcius
|
||||
lcd.setCustomChar(1, {0, 0, 4, 10, 10, 17, 31, 0}); // delta
|
||||
lcd.setCustomChar(2, {0, 0, 8, 21, 2, 0, 0, 0}); // home (tilde)
|
||||
lcd.setCustomChar(2, {0, 8, 21, 21, 2, 0, 0, 0}); // home (tilde)
|
||||
|
||||
while (!st.stop_requested()) {
|
||||
sem::display.acquire(); // holds the loop until sensor data is ready
|
||||
|
||||
Reference in New Issue
Block a user