Public Access
lib/services holds the host-tested logic: - Settings: typed, validated, persisted, SettingChanged events, transmit gated on a confirmed Region - BatteryEstimator: LiPo curve, median smoothing against TX sags - ClockModel: source priority GNSS > NTP > mesh, relative ages, Europe/Brussels local time via POSIX TZ - StorageMonitor: warning once per boot at 80%, Logs stop at 90%, Captures stop with < 2 MiB left - PowerPolicy / PowerButton: dim/off timeouts, wake key swallowed only when the screen was off, G0 long press src/services wires them to the hardware (NVS, battery ADC, SD on the shared SPI bus with the LoRa CS held high, backlight, deep sleep), and main.cpp is a temporary diagnostics screen for the hardware checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
66 lines
2.4 KiB
C++
66 lines
2.4 KiB
C++
#include <unity.h>
|
|
|
|
#include "power_policy.h"
|
|
|
|
using namespace roro;
|
|
|
|
void setUp() {}
|
|
void tearDown() {}
|
|
|
|
void test_screen_dims_then_turns_off_after_inactivity() {
|
|
PowerPolicy p(30000, 60000);
|
|
p.activity(0);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::On), static_cast<int>(p.update(29999)));
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Dimmed), static_cast<int>(p.update(30000)));
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Off), static_cast<int>(p.update(60000)));
|
|
}
|
|
|
|
void test_key_on_dimmed_screen_wakes_and_still_acts() {
|
|
PowerPolicy p(30000, 60000);
|
|
p.activity(0);
|
|
p.update(40000);
|
|
TEST_ASSERT_FALSE(p.activity(40000)); // not swallowed
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::On), static_cast<int>(p.update(40001)));
|
|
}
|
|
|
|
void test_key_on_off_screen_only_wakes() {
|
|
PowerPolicy p(30000, 60000);
|
|
p.activity(0);
|
|
p.update(70000);
|
|
TEST_ASSERT_TRUE(p.activity(70000)); // swallowed
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::On), static_cast<int>(p.update(70001)));
|
|
}
|
|
|
|
void test_new_timeouts_apply_immediately() {
|
|
PowerPolicy p(30000, 60000);
|
|
p.activity(0);
|
|
p.setTimeouts(10000, 20000);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Off), static_cast<int>(p.update(20000)));
|
|
}
|
|
|
|
void test_short_press_reported_on_release() {
|
|
PowerButton b(2000);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ButtonAction::None), static_cast<int>(b.update(true, 0)));
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ButtonAction::None), static_cast<int>(b.update(true, 500)));
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ButtonAction::ShortPress), static_cast<int>(b.update(false, 600)));
|
|
}
|
|
|
|
void test_long_press_fires_once_while_still_held() {
|
|
PowerButton b(2000);
|
|
b.update(true, 0);
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ButtonAction::LongPress), static_cast<int>(b.update(true, 2000)));
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ButtonAction::None), static_cast<int>(b.update(true, 3000)));
|
|
TEST_ASSERT_EQUAL(static_cast<int>(ButtonAction::None), static_cast<int>(b.update(false, 3100)));
|
|
}
|
|
|
|
int main() {
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_screen_dims_then_turns_off_after_inactivity);
|
|
RUN_TEST(test_key_on_dimmed_screen_wakes_and_still_acts);
|
|
RUN_TEST(test_key_on_off_screen_only_wakes);
|
|
RUN_TEST(test_new_timeouts_apply_immediately);
|
|
RUN_TEST(test_short_press_reported_on_release);
|
|
RUN_TEST(test_long_press_fires_once_while_still_held);
|
|
return UNITY_END();
|
|
}
|