Experimental low power mode

This commit is contained in:
2026-11-12 21:53:43 +01:00
parent 2d6864b1c7
commit 95724fd4d3
4 changed files with 124 additions and 12 deletions

No files matched your search

+1 -1
View File
@@ -70,7 +70,7 @@ The menu contains:
The tuner steps in 25 kHz increments across 433.000 to 435.500 MHz. Up/Down choose either direction; Select applies the frequency, recalibrates the CC1101, and resumes reception. With BOOT only, short presses step upward and wrap at the end; a long press applies the candidate.
The live screen updates while a message is decoded. Messages up to 159 characters are displayed over multiple pages. In Live, BOOT short-press advances message pages and then opens history. The OLED turns off after 60 seconds without UI activity; button presses and displayed pages wake it.
The live screen updates while a message is decoded. Messages up to 159 characters are displayed over multiple pages. In Live, BOOT short-press advances message pages and then opens history. The OLED turns off after 5 seconds without UI activity; button presses wake it. Incoming messages are still decoded and saved while the OLED is off, but do not wake the display. Once the UI is idle and no carrier is detected, the ESP32 enters light sleep while the CC1101 remains in continuous receive. Carrier sense on GDO0 wakes the ESP32; GDO0 is restored to asynchronous data output for POCSAG decoding.
Pages addressed to `MY_RIC` (default `1234567`) flash the normal LED on GPIO13 and NeoPixel on GPIO8 for approximately three seconds.
+1 -1
View File
@@ -1,3 +1,3 @@
idf_component_register(SRCS "main.c" "pager_presets.c" "pager_tx.c" "pocsag_bch.c"
INCLUDE_DIRS "."
REQUIRES esp_driver_gpio esp_driver_spi esp_driver_gptimer esp_adc esp_rom nvs_flash led_strip)
REQUIRES esp_driver_gpio esp_driver_spi esp_driver_gptimer esp_hw_support esp_adc esp_rom nvs_flash led_strip)
+120 -8
View File
@@ -29,6 +29,7 @@
#include "esp_err.h"
#include "esp_log.h"
#include "esp_attr.h"
#include "esp_sleep.h"
#include "driver/gpio.h"
#include "driver/spi_master.h"
@@ -571,10 +572,12 @@ static void history_add(uint32_t ric, unsigned baud, unsigned function,
history_cursor = 0;
history_storage_save();
ui_note_activity();
ESP_LOGI(TAG, "PAGER RIC=%lu function=%u baud=%u: %s",
(unsigned long)ric, function, baud, text);
ui_render();
if (oled_is_on) {
ui_note_activity();
ui_render();
}
}
#define POCSAG_SYNC 0x7CD215D8UL
@@ -589,6 +592,7 @@ typedef enum {
} baud_t;
static baud_t current_baud = RATE_UNKNOWN;
static TickType_t baud_detected_at;
static uint32_t bit_period_q16;
static uint32_t phase_q16;
@@ -847,7 +851,7 @@ static void ui_draw_tx(void)
static void ui_render(void)
{
if (!oled_is_on)
oled_power_on();
return;
oled_clear();
if (ui_screen == UI_MENU)
ui_draw_menu();
@@ -870,7 +874,8 @@ static void ui_render(void)
static void oled_draw_history(void)
{
ui_render();
if (oled_is_on)
ui_render();
}
static void ui_move_menu(int direction)
@@ -1120,6 +1125,8 @@ static void ui_update_display_flash(void)
oled_set_inverted(!oled_inverted);
rx_flash_toggles--;
if (!rx_flash_toggles)
oled_set_inverted(false);
rx_flash_next_toggle = now + pdMS_TO_TICKS(RX_DISPLAY_FLASH_MS);
}
@@ -1407,7 +1414,7 @@ static void decode_codeword(uint32_t raw, unsigned slot)
decode_numeric(payload);
else
decode_alpha(payload);
if (live_page && ui_screen == UI_LIVE) {
if (live_page && ui_screen == UI_LIVE && oled_is_on) {
ui_note_activity();
ui_render();
}
@@ -1466,6 +1473,7 @@ static void set_detected_baud(baud_t rate)
return;
current_baud = rate;
baud_detected_at = xTaskGetTickCount();
bit_period_q16 = (uint32_t)(((uint64_t)SAMPLE_RATE_HZ << 16) /
(unsigned)rate);
phase_q16 = bit_period_q16 / 2U;
@@ -1495,11 +1503,11 @@ static void process_sample(uint8_t sample)
edge_period_max = edge_samples;
}
if (edge_samples >= 69 && edge_samples <= 81) {
if (edge_samples >= 34 && edge_samples <= 42) {
hit512++; hit1200 = hit2400 = 0;
} else if (edge_samples >= 28 && edge_samples <= 36) {
} else if (edge_samples >= 14 && edge_samples <= 18) {
hit1200++; hit512 = hit2400 = 0;
} else if (edge_samples >= 13 && edge_samples <= 19) {
} else if (edge_samples >= 7 && edge_samples <= 10) {
hit2400++; hit512 = hit1200 = 0;
} else {
hit512 = hit1200 = hit2400 = 0;
@@ -1575,6 +1583,108 @@ static void start_sampler(void)
(unsigned long)SAMPLE_RATE_HZ);
}
static bool ui_allows_light_sleep(TickType_t now)
{
if (oled_is_on || rx_flash_toggles || hold_cue_visible ||
message_active || batch_locked ||
(int32_t)(now - page_alert_until) < 0 ||
now - ui_last_activity < pdMS_TO_TICKS(OLED_IDLE_OFF_MS))
return false;
for (unsigned i = 0; i < BUTTON_COUNT; i++) {
if (ui_buttons[i].down || gpio_get_level(ui_buttons[i].pin) == 0)
return false;
}
return true;
}
static void reset_receiver_after_wake(void)
{
sample_wr = 0;
sample_rd = 0;
current_baud = RATE_UNKNOWN;
baud_detected_at = 0;
bit_period_q16 = 0;
phase_q16 = 0;
edge_samples = 0;
hit512 = 0;
hit1200 = 0;
hit2400 = 0;
last_sample = gpio_get_level(PIN_CC1101_GDO0) ? 1U : 0U;
sync_shift = 0;
sync_bits = 0;
batch_locked = false;
invert_bits = false;
codeword_shift = 0;
codeword_bits = 0;
batch_word_index = 0;
message_abort();
}
static void reset_sync_after_carrier_probe(void)
{
sample_wr = 0;
sample_rd = 0;
edge_samples = 0;
hit512 = 0;
hit1200 = 0;
hit2400 = 0;
last_sample = gpio_get_level(PIN_CC1101_GDO0) ? 1U : 0U;
if (current_baud != RATE_UNKNOWN) {
phase_q16 = bit_period_q16 / 2U;
sync_shift = 0;
sync_bits = 0;
codeword_shift = 0;
codeword_bits = 0;
batch_word_index = 0;
}
}
static void receiver_light_sleep_check(void)
{
static TickType_t last_check;
TickType_t now = xTaskGetTickCount();
if (now - last_check < pdMS_TO_TICKS(100) ||
!ui_allows_light_sleep(now))
return;
if (current_baud != RATE_UNKNOWN) {
TickType_t acquisition_guard = pdMS_TO_TICKS(
1152000U / (unsigned)current_baud + 50U);
if (now - baud_detected_at < acquisition_guard)
return;
}
last_check = now;
ESP_ERROR_CHECK(gptimer_stop(sample_timer));
ESP_ERROR_CHECK(gptimer_disable(sample_timer));
cc_write(0x02, 0x0E); /* GDO0: carrier sense while the MCU sleeps */
vTaskDelay(pdMS_TO_TICKS(1));
bool carrier_detected = gpio_get_level(PIN_CC1101_GDO0) != 0;
if (carrier_detected || !ui_allows_light_sleep(xTaskGetTickCount())) {
cc_write(0x02, 0x0D); /* GDO0: asynchronous data */
reset_sync_after_carrier_probe();
ESP_ERROR_CHECK(gptimer_enable(sample_timer));
ESP_ERROR_CHECK(gptimer_start(sample_timer));
return;
}
ESP_ERROR_CHECK(esp_light_sleep_start());
cc_write(0x02, 0x0D); /* Restore data output before sampling */
reset_receiver_after_wake();
ESP_ERROR_CHECK(gptimer_enable(sample_timer));
ESP_ERROR_CHECK(gptimer_start(sample_timer));
}
static void configure_light_sleep_wakeup(void)
{
ESP_ERROR_CHECK(gpio_wakeup_enable(PIN_CC1101_GDO0, GPIO_INTR_HIGH_LEVEL));
for (unsigned i = 0; i < BUTTON_COUNT; i++)
ESP_ERROR_CHECK(gpio_wakeup_enable(ui_buttons[i].pin, GPIO_INTR_LOW_LEVEL));
ESP_ERROR_CHECK(esp_sleep_enable_gpio_wakeup());
}
/* Send is explicit from the TX screen; pause sampling so our own RF cannot enter RX decode. */
static void tx_send_selected(void)
{
@@ -1664,6 +1774,7 @@ void app_main(void)
setup_spi();
oled_init();
ui_hardware_init();
configure_light_sleep_wakeup();
battery_adc_init();
ui_screen = UI_LIVE;
ui_render();
@@ -1689,6 +1800,7 @@ void app_main(void)
ui_update_alert();
ui_update_display_flash();
ui_idle_power_down();
receiver_light_sleep_check();
if (xTaskGetTickCount() - last_battery_read >= pdMS_TO_TICKS(5000)) {
last_battery_read = xTaskGetTickCount();
+2 -2
View File
@@ -37,7 +37,7 @@
#define TX_PATABLE_VALUE 0xC0U /* CC1101 high-power entry for the 433 MHz band */
#define TX_BATCH_COUNT 3U
#define OLED_IDLE_OFF_MS 60000U
#define OLED_IDLE_OFF_MS 5000U
#define OWN_PAGE_ALERT_MS 3000U
#define RX_DISPLAY_FLASHES 4U
#define RX_DISPLAY_FLASH_MS 120U
@@ -48,7 +48,7 @@
#define BATTERY_DIVIDER_BOTTOM_OHMS 100000U
#define SAMPLE_TIMER_HZ 1000000UL
#define SAMPLE_PERIOD_TICKS 26UL
#define SAMPLE_PERIOD_TICKS 52UL
#define SAMPLE_RATE_HZ (SAMPLE_TIMER_HZ / SAMPLE_PERIOD_TICKS)
#define SAMPLE_BUF_SIZE 16384U
#define SAMPLE_BUF_MASK (SAMPLE_BUF_SIZE - 1U)