Docs and code: translate Polish comments, messages and documentation to English
check / check-without-hardware (push) Successful in 6m45s

- README, CHANGELOG, RELEASE_NOTES, THIRD_PARTY_NOTICES and docs/*.md
  translated to English; cross-markdown anchors updated
- C/C++/Python/shell comments and user-facing messages translated
- identifiers, protocol names, commands and literals unchanged
- native tests re-verified: 24/24 PASS; tpms_frame.py self-test PASS
This commit is contained in:
czcionka committed 2026-10-30 18:01:32 +00:00
1 parent 1563e34d05
commit e183d23950
42 files changed
+1106 -1019

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
/* Przenosna maszyna stanow NORMAL/LEARN/SINGLE (fake clock/radio w testach). */
/* Portable NORMAL/LEARN/SINGLE state machine (fake clock/radio in tests). */
#ifndef TPMS_APP_STATE_H
#define TPMS_APP_STATE_H
+25 -24
View File
@@ -1,37 +1,37 @@
/* Konfiguracja sprzetu. Dane czujnikow i RF sa w NVS, nie wymagaja rekompilacji. */
/* Hardware configuration. Sensor and RF data live in NVS, no recompile needed. */
#ifndef TPMS_CONFIG_H
#define TPMS_CONFIG_H
#define FW_VERSION "2.0.0-rc.1"
/* ESP32-S2-MINI (ESP32-S2FN4R2) + CC1101 433 MHz (3,3 V).
* GPIO19/20 to natywne USB, GPIO26-32 obsluguja flash/PSRAM w obudowie,
* GPIO45/46 to piny strapping - nie uzywac ich do CC1101. */
/* ESP32-S2-MINI (ESP32-S2FN4R2) + CC1101 433 MHz (3.3 V).
* GPIO19/20 are native USB, GPIO26-32 serve in-package flash/PSRAM,
* GPIO45/46 are strapping pins - do not use them for the CC1101. */
#define PIN_CC1101_SCK 4
#define PIN_CC1101_MISO 5
#define PIN_CC1101_MOSI 6
#define PIN_CC1101_CS 7
#define PIN_CC1101_GDO0 10
/* Przycisk sterujacy i budzenie z deep sleep: przycisk BOOT plytki
* (GPIO0 do GND), potwierdzony testem na sprzecie. GPIO0 to pin strapping:
* przytrzymany podczas zasilania/reset uruchamia bootloader zamiast firmware.
* Zewnetrzny przycisk monostabilny mozna podlaczyc zamiast tego pod GPIO3
* i przelaczyc -DPIN_BUTTON=3 w build_flags. */
/* Control button and wake from deep sleep: the board's BOOT button
* (GPIO0 to GND), confirmed by a bench test. GPIO0 is a strapping pin:
* held during power-up/reset it starts the bootloader instead of the firmware.
* An external momentary button can be wired to GPIO3 instead, selecting
* -DPIN_BUTTON=3 in build_flags. */
#ifndef PIN_BUTTON
#define PIN_BUTTON 0
#endif
#define BTN_ACTIVE_LEVEL 0
/* Wbudowana niebieska LED S2 Mini na GPIO15 jest aktywna stanem wysokim. */
/* The S2 Mini's built-in blue LED on GPIO15 is active-high. */
#define PIN_LED 15
#define LED_ACTIVE_LEVEL 1
/* Opcje wylaczone do czasu zmontowania i przetestowania sprzetu. */
/* Options disabled until the hardware is assembled and tested. */
#ifndef PIN_LF_TRIGGER
#define PIN_LF_TRIGGER -1
#endif
/* LF dzieli z przyciskiem GPIO wakeup LOW; na ESP32-S2 wakeup wymaga pinu
* RTC (GPIO0-21). Proponowane GPIO14, bo GPIO1 zajmuje ADC zasilania. */
/* LF shares the button's GPIO wakeup LOW; on ESP32-S2 wakeup requires an
* RTC pin (GPIO0-21). GPIO14 is suggested because GPIO1 holds the supply ADC. */
#define LF_ACTIVE_LEVEL 0
#ifndef PIN_ACC
#define PIN_ACC -1
@@ -39,28 +39,29 @@
#ifndef PIN_VBAT_ADC
#define PIN_VBAT_ADC 1
#endif
/* Dzielnik mierzy zasilanie 12 V (prog LOWBATT 11,5 V). R2 = 180 kOhm
* daje pelny zakres ADC ok. 16,4 V przy pelnej skali 2,5 V (11 dB):
* 14,8 V ladowania daje 2,25 V na pinie, wiec odczyt nie nasyci sie.
* Wczesniejsze 270 kOhm nasycale ADC juz przy ok. 11,8 V. */
/* Divider measures the 12 V supply (LOWBATT threshold 11.5 V). R2 = 180 kOhm
* gives the ADC a full-scale range of about 16.4 V at 2.5 V full scale (11 dB):
* a 14.8 V charge voltage yields 2.25 V at the pin, so the reading saturates
* no earlier. The previous 270 kOhm divider saturated the ADC at ~11.8 V. */
#define VBAT_DIVIDER_R1 1000000.0f
#define VBAT_DIVIDER_R2 180000.0f
#define VBAT_CAL 1.000f
#define VBAT_SAMPLES 16
#define LOWBATT_THRESHOLD_MV 11500
/* Jedyny profil produkcyjny: OOK, Manchester 0->01, 1->10. */
/* The only production profile: OOK, Manchester 0->01, 1->10. */
#define TPMS_CHIP_US 120u
/* Harmonogram i moc poczatkowa: settings_defaults() w settings.cpp.
* Sa to parametry eksperymentalne, a nie potwierdzony harmonogram OE. */
/* Schedule and initial power: settings_defaults() in settings.cpp.
* These are experimental parameters, not a confirmed OE schedule. */
#define BOOT_STAY_AWAKE_MS 10000u
/* Mikrodrzemki: zamiast jednego dlugiego snu LED miga co NAP_PERIOD_MS takze
* miedzy wysylkami. Sen to reszta okresu po czasie boot + okno, a TX ramek
* TPMS pozostaje co interwal (licznik w pamieci RTC). */
/* Micro-naps: instead of one long sleep the LED blinks every NAP_PERIOD_MS,
* also between transmissions. Sleep is the remainder of the period after
* boot time + window, and TPMS frame TX remains on the interval (counter
* in RTC memory). */
#define NAP_PERIOD_MS 2000u
#define NAP_AWAKE_MS 400u /* widoczne migniecie LED po budziku timera */
#define NAP_AWAKE_MS 400u /* visible LED blink after the timer wake */
#define NAP_MIN_SLEEP_MS 200u
#define SERIAL_BAUD 115200
+28 -28
View File
@@ -1,4 +1,4 @@
/* Konsola szeregowa: konfiguracja zapisywana w NVS, bez rekompilacji. */
/* Serial console: configuration stored in NVS, no recompilation needed. */
#include <Arduino.h>
#include <esp_system.h>
#include <string.h>
@@ -29,18 +29,18 @@ static bool parse_wheel(const char *text, uint8_t *wheel, bool allow_all = false
static void cmd_help(void)
{
Serial.println(F("POMOC (zmiany konfiguracji zapisuja sie automatycznie):"));
Serial.println(F("HELP (configuration changes are saved automatically):"));
Serial.println(F(" info | hex [1-4|all] | send [1-4|all] | batt"));
Serial.println(F(" mode normal | mode learn [1-4] | mode single 1-4 | next"));
Serial.println(F(" id 1-4 XXXXXX - ustaw 24-bit ID (hex)"));
Serial.println(F(" ids new - wygeneruj 4 unikalne ID"));
Serial.println(F(" pressure 1-4|all KPA - np. pressure all 260"));
Serial.println(F(" temp 1-4|all C - temperatura -40..85 C"));
Serial.println(F(" id 1-4 XXXXXX - set 24-bit ID (hex)"));
Serial.println(F(" ids new - generate 4 unique IDs"));
Serial.println(F(" pressure 1-4|all KPA - e.g. pressure all 260"));
Serial.println(F(" temp 1-4|all C - temperature -40..85 C"));
Serial.println(F(" interval normal|ignition|parking 5-86400"));
Serial.println(F(" rf freq 433.05-434.79 | rf power -30..5 | rf burst 1-8"));
Serial.println(F(" rf gap 20-500 - odstep miedzy ramkami [ms]"));
Serial.println(F(" flags HEX - 32-bit flags (znaczenie nie w pelni znane)"));
Serial.println(F(" factory YES - przywroc fabryczne | save | stay [s] | sleep"));
Serial.println(F(" rf gap 20-500 - gap between frames [ms]"));
Serial.println(F(" flags HEX - 32-bit flags (meaning not fully known)"));
Serial.println(F(" factory YES - restore factory | save | stay [s] | sleep"));
}
static void cmd_send(const char *arg)
@@ -52,21 +52,21 @@ static void cmd_send(const char *arg)
} else if (parse_wheel(arg, &wheel, true)) {
ok = wheel == 0xFFu ? g_app->send_all() : g_app->send_wheel(wheel);
} else {
Serial.println(F("BLAD: send [1-4|all]"));
Serial.println(F("ERROR: send [1-4|all]"));
return;
}
Serial.println(ok ? F("OK") : F("BLAD TX"));
Serial.println(ok ? F("OK") : F("TX ERROR"));
}
static void cmd_mode(const char *arg1, const char *arg2)
{
if (arg1 == NULL) {
Serial.println(F("BLAD: mode normal|learn|single [1-4]"));
Serial.println(F("ERROR: mode normal|learn|single [1-4]"));
return;
}
uint8_t wheel = WHEEL_FL;
if (arg2 != NULL && !parse_wheel(arg2, &wheel)) {
Serial.println(F("BLAD: kolo 1-4"));
Serial.println(F("ERROR: wheel 1-4"));
return;
}
if (strcmp(arg1, "normal") == 0) {
@@ -76,7 +76,7 @@ static void cmd_mode(const char *arg1, const char *arg2)
} else if (strcmp(arg1, "single") == 0 && arg2 != NULL) {
g_app->set_mode(AppMode::SINGLE, wheel, millis());
} else {
Serial.println(F("BLAD: mode normal|learn [1-4]|single 1-4"));
Serial.println(F("ERROR: mode normal|learn [1-4]|single 1-4"));
return;
}
Serial.println(F("OK"));
@@ -88,7 +88,7 @@ static void cmd_id(const char *wheel_text, const char *id_text)
uint32_t id;
if (!parse_wheel(wheel_text, &wheel) || !parse_u32(id_text, 1u, 0xFFFFFEu, &id, 16)
|| !settings_set_id(&g_settings, wheel, id)) {
Serial.println(F("BLAD: id 1-4 000001..FFFFFE; ID musza byc unikalne"));
Serial.println(F("ERROR: id 1-4 000001..FFFFFE; IDs must be unique"));
return;
}
app_save_and_apply();
@@ -99,7 +99,7 @@ static void cmd_pressure_temp(const char *which, const char *wheel_text,
{
uint8_t wheel;
if (!parse_wheel(wheel_text, &wheel, true)) {
Serial.println(F("BLAD: kolo 1-4 lub all"));
Serial.println(F("ERROR: wheel 1-4 or all"));
return;
}
uint8_t first = wheel == 0xFFu ? 0u : wheel;
@@ -107,7 +107,7 @@ static void cmd_pressure_temp(const char *which, const char *wheel_text,
if (strcmp(which, "pressure") == 0) {
float kpa;
if (!parse_float(value_text, 0.0f, 637.5f, &kpa)) {
Serial.println(F("BLAD: cisnienie 0..637.5 kPa"));
Serial.println(F("ERROR: pressure 0..637.5 kPa"));
return;
}
uint16_t value = (uint16_t)(kpa * 10.0f + 0.5f);
@@ -117,7 +117,7 @@ static void cmd_pressure_temp(const char *which, const char *wheel_text,
} else {
int32_t value;
if (!parse_i32(value_text, -40, 85, &value)) {
Serial.println(F("BLAD: temperatura -40..85 C"));
Serial.println(F("ERROR: temperature -40..85 C"));
return;
}
for (uint8_t i = first; i < last; ++i) {
@@ -132,7 +132,7 @@ static void cmd_interval(const char *which, const char *value_text)
uint32_t value;
if (which == NULL || !parse_u32(value_text, SETTINGS_INTERVAL_MIN_S,
SETTINGS_INTERVAL_MAX_S, &value)) {
Serial.println(F("BLAD: interval normal|ignition|parking 5-86400"));
Serial.println(F("ERROR: interval normal|ignition|parking 5-86400"));
return;
}
if (strcmp(which, "normal") == 0) {
@@ -142,7 +142,7 @@ static void cmd_interval(const char *which, const char *value_text)
} else if (strcmp(which, "parking") == 0) {
g_settings.parking_interval_s = value;
} else {
Serial.println(F("BLAD: rodzaj interwalu"));
Serial.println(F("ERROR: interval kind"));
return;
}
app_save_and_apply();
@@ -154,7 +154,7 @@ static void cmd_rf(const char *which, const char *value_text)
int32_t signed_value;
float frequency;
if (which == NULL) {
Serial.println(F("BLAD: rf freq|power|burst|gap"));
Serial.println(F("ERROR: rf freq|power|burst|gap"));
return;
}
if (strcmp(which, "freq") == 0 && parse_float(value_text, 433.05f, 434.79f, &frequency)) {
@@ -168,7 +168,7 @@ static void cmd_rf(const char *which, const char *value_text)
} else if (strcmp(which, "gap") == 0 && parse_u32(value_text, 20u, 500u, &value)) {
g_settings.frame_gap_ms = (uint16_t)value;
} else {
Serial.println(F("BLAD: parametr RF poza dozwolonym zakresem"));
Serial.println(F("ERROR: RF parameter out of the allowed range"));
return;
}
app_save_and_apply();
@@ -199,7 +199,7 @@ static void handle_line(char *text)
app_print_frame(wheel);
}
} else {
Serial.println(F("BLAD: hex [1-4|all]"));
Serial.println(F("ERROR: hex [1-4|all]"));
}
} else if (strcmp(cmd, "send") == 0) {
cmd_send(arg1);
@@ -208,7 +208,7 @@ static void handle_line(char *text)
} else if (strcmp(cmd, "mode") == 0) {
cmd_mode(arg1, arg2);
} else if (strcmp(cmd, "next") == 0) {
Serial.println(g_app->next_wheel(millis()) ? F("OK") : F("BLAD: tylko LEARN/SINGLE"));
Serial.println(g_app->next_wheel(millis()) ? F("OK") : F("ERROR: LEARN/SINGLE only"));
} else if (strcmp(cmd, "id") == 0) {
cmd_id(arg1, arg2);
} else if (strcmp(cmd, "ids") == 0 && arg1 != NULL && strcmp(arg1, "new") == 0) {
@@ -222,7 +222,7 @@ static void handle_line(char *text)
cmd_rf(arg1, arg2);
} else if (strcmp(cmd, "flags") == 0) {
if (!parse_u32(arg1, 0u, 0xFFFFFFFFu, &value, 16)) {
Serial.println(F("BLAD: flags HEX"));
Serial.println(F("ERROR: flags HEX"));
return;
}
g_settings.flags = value;
@@ -238,13 +238,13 @@ static void handle_line(char *text)
} else if (strcmp(cmd, "stay") == 0) {
value = 60u;
if (arg1 != NULL && !parse_u32(arg1, 1u, 3600u, &value)) {
Serial.println(F("BLAD: stay 1-3600"));
Serial.println(F("ERROR: stay 1-3600"));
return;
}
app_stay_awake(value * 1000u);
Serial.println(F("OK"));
} else {
Serial.println(F("Nieznana komenda; help"));
Serial.println(F("Unknown command; help"));
}
}
@@ -260,7 +260,7 @@ void console_poll(void)
char c = (char)Serial.read();
if (c == '\r' || c == '\n') {
if (line_overflow) {
Serial.println(F("BLAD: linia za dluga"));
Serial.println(F("ERROR: line too long"));
} else if (line_len > 0u) {
line[line_len] = '\0';
handle_line(line);
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* console.h - debugowa konsola szeregowa (bez String, stalobuforowa)
* console.h - debug serial console (no String, fixed buffer)
*/
#ifndef TPMS_CONSOLE_H
#define TPMS_CONSOLE_H
@@ -9,7 +9,7 @@ extern "C" {
#endif
void console_init(void);
void console_poll(void); // nieblokujaca obsluga linii - wywolywac w petli
void console_poll(void); // non-blocking line handling - call in the loop
#ifdef __cplusplus
}
+24 -24
View File
@@ -1,4 +1,4 @@
/* Symulator diagnostyczny TPMS. Sztuczne cisnienie moze ukryc usterke opony. */
/* TPMS diagnostic simulator. Synthetic pressure can mask a tyre fault. */
#include <Arduino.h>
#include <esp_attr.h>
#include <esp_sleep.h>
@@ -19,8 +19,8 @@ static const char *const WHEEL_NAMES[WHEEL_COUNT] = {"FL", "FR", "RR", "RL"};
static uint32_t stay_awake_until;
static bool request_sleep;
static uint32_t supply_mv;
/* Mikrodrzemki: czas przespany od ostatniego cyklu TX i dlugosc ostatniego
* kawalka snu przetrwaja deep sleep w pamieci RTC (kasowane przez power-on). */
/* Micro-naps: time slept since the last TX cycle and the length of the last
* sleep slice survive deep sleep in RTC memory (cleared by power-on). */
RTC_DATA_ATTR static uint32_t slept_ms;
RTC_DATA_ATTR static uint32_t last_slice_ms;
#if PIN_LF_TRIGGER >= 0
@@ -79,13 +79,13 @@ void app_request_sleep(void)
bool app_save_and_apply(void)
{
if (!settings_store_save()) {
Serial.println(F("BLAD: nie zapisano NVS (walidacja lub zapis)"));
Serial.println(F("ERROR: NVS not saved (validation or write)"));
return false;
}
if (!radio_init(&g_settings)) {
Serial.println(F("OSTRZEZENIE: zapisano, ale CC1101 nie odpowiada"));
Serial.println(F("WARNING: saved, but the CC1101 does not respond"));
}
Serial.println(F("OK: zapisano w NVS"));
Serial.println(F("OK: saved in NVS"));
return true;
}
@@ -101,7 +101,7 @@ void app_print_frame(uint8_t wheel)
g_settings.flags)
|| !tpms_build_payload(payload, s.id, s.pressure_kpa10,
(int8_t)s.temp_c, g_settings.flags)) {
Serial.println(F("BLAD: nieprawidlowa konfiguracja ramki"));
Serial.println(F("ERROR: invalid frame configuration"));
return;
}
Serial.printf("%s payload:", WHEEL_NAMES[wheel]);
@@ -135,7 +135,7 @@ void app_print_info(void)
(unsigned long)g_settings.normal_interval_s,
(unsigned long)g_settings.ignition_interval_s,
(unsigned long)g_settings.parking_interval_s);
Serial.printf("Vcc=%u mV (nie zmienia flag TPMS)\n", (unsigned)supply_mv);
Serial.printf("Vcc=%u mV (does not change TPMS flags)\n", (unsigned)supply_mv);
}
static void sync_ui(void)
@@ -177,8 +177,8 @@ static void go_sleep(void)
app_stay_awake(500u);
return;
}
/* Mikrodrzemka: reszta okresu po czasie boot+okno, zeby migniecia LED
* wypadaly co NAP_PERIOD_MS niezaleznie od dlugosci budzenia. */
/* Micro-nap: the rest of the period after boot time + window, so that
* LED blinks land on NAP_PERIOD_MS regardless of awake duration. */
uint32_t awake_ms = millis();
uint32_t slice_ms = NAP_PERIOD_MS;
if (awake_ms + NAP_MIN_SLEEP_MS < NAP_PERIOD_MS) {
@@ -210,18 +210,18 @@ void setup(void)
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
/* Chipy z GPIO wakeup w deep sleep (np. ESP32-C3). */
/* Chips with GPIO wakeup in deep sleep (e.g. ESP32-C3). */
bool pin_wake = cause == ESP_SLEEP_WAKEUP_GPIO;
#else
/* ESP32-S2: budzenie z pinow RTC zglasza EXT1. */
/* ESP32-S2: waking from RTC pins raises EXT1. */
bool pin_wake = cause == ESP_SLEEP_WAKEUP_EXT1;
#endif
bool timer_wake = cause == ESP_SLEEP_WAKEUP_TIMER;
if (timer_wake) {
slept_ms += last_slice_ms;
}
/* TX co interwal: power-on, budzenie po przespaniu calego cyklu albo
* wyczerpany licznik snu. Budzenie przyciskiem nie nadaje (jak wczesniej). */
/* TX on the interval: power-on, wake after sleeping the whole cycle, or
* an exhausted sleep counter. A button wake does not transmit (as before). */
uint32_t interval_ms = g_app->interval_s(ignition_on()) * 1000u;
bool transmit = !pin_wake && (!timer_wake || slept_ms >= interval_ms);
bool quick_nap = timer_wake && !transmit;
@@ -232,15 +232,15 @@ void setup(void)
bool radio_ready = radio_init(&g_settings);
if (!quick_nap) {
supply_mv = power_read_mv();
Serial.printf("\nTPMS DIAG FW %s - DANE SZTUCZNE, NIE DO JAZDY\n", FW_VERSION);
Serial.printf("NVS: %s; dostep=%s\n",
Serial.printf("\nTPMS DIAG FW %s - SYNTHETIC DATA, NOT FOR ROAD USE\n", FW_VERSION);
Serial.printf("NVS: %s; access=%s\n",
settings_load_result_text(settings_store_last_load()),
settings_store_available() ? "tak" : "nie");
settings_store_available() ? "yes" : "no");
if (!radio_ready) {
Serial.println(F("BLAD: brak CC1101; sprawdz 3V3/SPI"));
Serial.println(F("ERROR: no CC1101; check 3V3/SPI"));
}
if (power_low_battery(supply_mv)) {
Serial.println(F("OSTRZEZENIE: niskie zasilanie emulatora"));
Serial.println(F("WARNING: emulator supply low"));
}
}
@@ -258,14 +258,14 @@ void setup(void)
g_app->send_current();
}
#endif
/* Okna: power-on/przycisk/LF = konsola 10 s; budzenie timera = od razu
* sen po TX, a mikrodrzemka tylko na widoczne migniecie LED. */
/* Windows: power-on/button/LF = 10 s console; timer wake = straight to
* sleep after TX, the micro-nap only for a visible LED blink. */
stay_awake_until = millis() + (timer_wake
? (transmit ? 0u : NAP_AWAKE_MS) : BOOT_STAY_AWAKE_MS);
sync_ui();
if (!quick_nap) {
app_print_info();
Serial.println(F("gotowy; help = komendy; stay 60 = konsola 60 s"));
Serial.println(F("ready; help = commands; stay 60 = 60 s console"));
}
}
@@ -281,8 +281,8 @@ void loop(void)
default: break;
}
if (ev != UI_EV_NONE) {
/* Kazdy gest = okno konsoli 10 s (POWER.md), takze po wyjsciu
* z LEARN/SINGLE - urzadzenie nie zasypia natychmiast po przycisku. */
/* Every gesture = a 10 s console window (POWER.md), also when leaving
* LEARN/SINGLE - the device does not fall asleep right after a button. */
app_stay_awake(BOOT_STAY_AWAKE_MS);
}
console_poll();
+1 -1
View File
@@ -43,7 +43,7 @@ bool parse_float(const char *text, float lo, float hi, float *out)
errno = 0;
char *end = NULL;
float value = strtof(text, &end);
/* Odwrocone porownanie odrzuca tez NaN (obie strony falszywe). */
/* Inverted comparison also rejects NaN (both sides false). */
if (errno != 0 || end == text || *end != '\0'
|| !(value >= lo && value <= hi)) {
return false;
+2 -2
View File
@@ -1,4 +1,4 @@
/* Parsowanie argumentow konsoli; modul przenosny (testy native). */
/* Console argument parsing; portable module (native tests). */
#ifndef TPMS_PARSE_H
#define TPMS_PARSE_H
@@ -12,7 +12,7 @@ extern "C" {
bool parse_u32(const char *text, uint32_t lo, uint32_t hi, uint32_t *out,
int base = 10);
bool parse_i32(const char *text, int32_t lo, int32_t hi, int32_t *out);
/* Odrzuca NaN i nieskonczonosc; zakres domkniety [lo, hi]. */
/* Rejects NaN and infinity; closed range [lo, hi]. */
bool parse_float(const char *text, float lo, float hi, float *out);
#ifdef __cplusplus
+12 -12
View File
@@ -1,4 +1,4 @@
/* Zasilanie i deep sleep. Stan zasilania NIE zmienia pol protokolu TPMS. */
/* Power and deep sleep. Supply state does NOT change TPMS protocol fields. */
#include <Arduino.h>
#include <esp_sleep.h>
#include <driver/gpio.h>
@@ -19,7 +19,7 @@ void power_init(void)
gpio_hold_dis((gpio_num_t)PIN_CC1101_SCK);
gpio_hold_dis((gpio_num_t)PIN_CC1101_MOSI);
#if SOC_BT_SUPPORTED
/* ESP32-S2 nie ma radia Bluetooth; btStop istnieje tylko na chipach z BT. */
/* ESP32-S2 has no Bluetooth radio; btStop only exists on chips with BT. */
btStop();
#endif
#if PIN_VBAT_ADC >= 0
@@ -57,18 +57,18 @@ void power_deep_sleep(uint32_t ms)
gpio_deep_sleep_hold_en();
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
/* PARKING_SHUTDOWN nie istnieje: kazdy sen ma budzik i nie mozna
* zatrzymac urzadzenia do czasu recznego wybudzenia. Dolny prog
* gwarantuje budzik takze dla mikrodrzemek. */
/* PARKING_SHUTDOWN does not exist: every sleep has an RTC alarm and the
* device cannot be stopped until a manual wake. The lower bound also
* guarantees an alarm for micro-naps. */
if (ms < NAP_MIN_SLEEP_MS) {
ms = NAP_MIN_SLEEP_MS;
}
esp_sleep_enable_timer_wakeup((uint64_t)ms * 1000ULL);
#if PIN_BUTTON >= 0 || PIN_LF_TRIGGER >= 0
/* Budzenie z pinow RTC (na ESP32-S2: GPIO0-21). Oba wejscia sa aktywne
* nisko, wiec moga wspoldzielic jeden tryb. ESP32-S2 nie obsluguje
* GPIO wakeup w deep sleep - uzywa EXT1 ANY_LOW. */
/* Waking from RTC pins (on ESP32-S2: GPIO0-21). Both inputs are active
* low, so they can share one mode. ESP32-S2 does not support GPIO wakeup
* in deep sleep - it uses EXT1 ANY_LOW. */
uint64_t wake_mask = 0;
#if PIN_BUTTON >= 0
wake_mask |= 1ULL << PIN_BUTTON;
@@ -77,10 +77,10 @@ void power_deep_sleep(uint32_t ms)
wake_mask |= 1ULL << PIN_LF_TRIGGER;
#endif
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
/* Cyfrowe pull-up/pull-down (pinMode) nie dzialaja w deep sleep, gdy
* domena RTC_PERIPH jest wylaczona. Bez pociagniec RTC piny budzenia
* plywaja i EXT1 moze budzic losowo; konfigurujemy je tu i utrzymujemy
* mechanizmem HOLD (wg ESP-IDF sleep_modes dla EXT1). */
/* Digital pull-up/pull-down (pinMode) does not work in deep sleep while
* the RTC_PERIPH domain is off. Without RTC pulls the wake pins float and
* EXT1 can wake randomly; we configure them here and keep them with the
* HOLD mechanism (per ESP-IDF sleep_modes for EXT1). */
#if PIN_BUTTON >= 0
rtc_gpio_init((gpio_num_t)PIN_BUTTON);
#if BTN_ACTIVE_LEVEL == 0
+2 -2
View File
@@ -6,7 +6,7 @@
void power_init(void);
uint32_t power_read_mv(void);
bool power_low_battery(uint32_t mv); /* tylko ostrzezenie o zasilaniu emulatora */
void power_deep_sleep(uint32_t ms); /* zawsze ma budzik RTC; nie wraca */
bool power_low_battery(uint32_t mv); /* only a warning about the emulator supply */
void power_deep_sleep(uint32_t ms); /* always has an RTC alarm; does not return */
#endif
+6 -6
View File
@@ -1,4 +1,4 @@
/* CC1101: surowe 30 bajtow Manchester w fixed-length FIFO, bez wstawek HW. */
/* CC1101: raw 30 Manchester bytes into the fixed-length FIFO, no HW extras. */
#include <Arduino.h>
#include <SPI.h>
#include <ELECHOUSE_CC1101_SRC_DRV.h>
@@ -30,13 +30,13 @@ bool radio_init(const settings_t *cfg)
}
ELECHOUSE_cc1101.setCCMode(1);
ELECHOUSE_cc1101.setModulation(2); /* ASK/OOK; brak profilu FSK. */
ELECHOUSE_cc1101.setModulation(2); /* ASK/OOK; no FSK profile. */
ELECHOUSE_cc1101.setMHZ(cfg->frequency_mhz);
ELECHOUSE_cc1101.setDRate(1000.0f / (float)TPMS_CHIP_US);
ELECHOUSE_cc1101.setPA(cfg->tx_power_dbm);
ELECHOUSE_cc1101.setChannel(0);
/* SYNC_MODE=0: packet engine nie dodaje preambuly ani slowa sync. */
/* SYNC_MODE=0: the packet engine adds no preamble or sync word. */
ELECHOUSE_cc1101.setSyncMode(0);
ELECHOUSE_cc1101.setPRE(0);
ELECHOUSE_cc1101.setAdrChk(0);
@@ -66,8 +66,8 @@ bool radio_send_frame(const uint8_t *buf, uint8_t len)
ELECHOUSE_cc1101.SpiWriteBurstReg(CC1101_TXFIFO, (uint8_t *)buf, len);
ELECHOUSE_cc1101.SpiStrobe(CC1101_STX);
/* Czekamy na MARCSTATE, nie na samo TXBYTES=0: ostatni bajt moze byc
* jeszcze w rejestrze przesuwnym. Limit obejmuje start i pelny ogon. */
/* We wait for MARCSTATE, not just TXBYTES=0: the last byte may still be
* in the shift register. The limit covers the start and the full tail. */
const uint32_t timeout_us = (uint32_t)len * 8u * TPMS_CHIP_US + 10000u;
const uint32_t start = micros();
bool finished = false;
@@ -78,7 +78,7 @@ bool radio_send_frame(const uint8_t *buf, uint8_t len)
underflow = true;
break;
}
if (state == 0x01u) { /* IDLE po automatycznym zakonczeniu pakietu */
if (state == 0x01u) { /* IDLE after the automatic end of the packet */
finished = true;
break;
}
+8 -8
View File
@@ -160,13 +160,13 @@ const char *settings_load_result_text(settings_load_result_t result)
{
switch (result) {
case SETTINGS_LOAD_OK: return "OK";
case SETTINGS_LOAD_EMPTY: return "pusta konfiguracja";
case SETTINGS_LOAD_BAD_MAGIC: return "nieprawidlowy magic";
case SETTINGS_LOAD_BAD_VERSION: return "nieobslugiwana wersja";
case SETTINGS_LOAD_BAD_SIZE: return "nieprawidlowy rozmiar";
case SETTINGS_LOAD_BAD_CRC: return "blad CRC";
case SETTINGS_LOAD_INVALID: return "nieprawidlowe wartosci";
case SETTINGS_LOAD_IO_ERROR: return "blad NVS";
default: return "nieznany blad";
case SETTINGS_LOAD_EMPTY: return "empty configuration";
case SETTINGS_LOAD_BAD_MAGIC: return "bad magic";
case SETTINGS_LOAD_BAD_VERSION: return "unsupported version";
case SETTINGS_LOAD_BAD_SIZE: return "invalid size";
case SETTINGS_LOAD_BAD_CRC: return "CRC error";
case SETTINGS_LOAD_INVALID: return "invalid values";
case SETTINGS_LOAD_IO_ERROR: return "NVS error";
default: return "unknown error";
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
/* Trwala konfiguracja uzytkownika; modul niezalezny od Arduino. */
/* Persistent user configuration; module independent of Arduino. */
#ifndef TPMS_SETTINGS_H
#define TPMS_SETTINGS_H
+1 -1
View File
@@ -33,7 +33,7 @@ void settings_store_begin()
}
if (last_load != SETTINGS_LOAD_OK) {
settings_defaults(&g_settings);
/* Odzyskiwanie po uszkodzeniu: zapisz spojne domyslne. */
/* Recovery from corruption: save consistent defaults. */
settings_store_save();
}
}
+3 -3
View File
@@ -1,4 +1,4 @@
/* Generator ramek EG53MA4. Sztuczne dane wylacznie do diagnostyki. */
/* EG53MA4 frame generator. Synthetic data for diagnostics only. */
#include <string.h>
#include "settings.h"
@@ -12,7 +12,7 @@ static void put_bit(uint8_t *buf, unsigned *nbits, unsigned value)
++(*nbits);
}
/* Polaryzacja potwierdzona nagraniami i rtl_433 OOK_MC_ZEROBIT: 0=01, 1=10. */
/* Polarity confirmed by captures and rtl_433 OOK_MC_ZEROBIT: 0=01, 1=10. */
static void put_cell(uint8_t *buf, unsigned *nbits, unsigned bit)
{
put_bit(buf, nbits, bit != 0u ? 1u : 0u);
@@ -68,7 +68,7 @@ bool tpms_build_frame(uint8_t out[TPMS_TX_BYTES], uint32_t id,
memset(out, 0, TPMS_TX_BYTES);
unsigned nbits = 0;
put_bit(out, &nbits, 1u); /* chip startowy */
put_bit(out, &nbits, 1u); /* starting chip */
for (unsigned i = 0; i < TPMS_SYNC_BITS - 1u; ++i) {
put_cell(out, &nbits, 0u);
}
+10 -9
View File
@@ -1,4 +1,4 @@
/* Schrader EG53MA4: 40 bitow sync + 80 bitow danych, OOK Manchester. */
/* Schrader EG53MA4: 40 sync bits + 80 data bits, OOK Manchester. */
#ifndef TPMS_FRAME_H
#define TPMS_FRAME_H
@@ -15,20 +15,21 @@ extern "C" {
#define TPMS_TX_BYTES 30
#define TPMS_TX_CHIPS (TPMS_TX_BYTES * 8)
/* Kalibracja pola P: tyle setnych kPa przypada na jeden bit bajtu P.
* Skala rtl_433 (250 = 2,5 kPa/bit) nie jest potwierdzona nagraniami
* (wszystkie maja P=0), a pomiar z auta: 260 kPa -> 284 kPa na wyswietlaczu
* przy P=104, wiec korekta skalujaca 2,73 kPa/bit daje P=95 dla 260 kPa.
* Potwierdzone z autem: 260 kPa -> 260 kPa na wyswietlaczu (docs/AUDIT.md) -
* zmienic tez PRESSURE_KPA100_PER_RAW w tools/tpms_frame.py. */
/* Calibration of the P field: how many hundredths of a kPa one bit of the
* P byte represents. The rtl_433 scale (250 = 2.5 kPa/bit) is not confirmed
* by the captures (all have P=0), while a car measurement showed
* 260 kPa -> 284 kPa on the display at P=104, so a scaling correction of
* 2.73 kPa/bit gives P=95 for 260 kPa. Confirmed with the car:
* 260 kPa -> 260 kPa on the display (docs/AUDIT.md) -
* also change PRESSURE_KPA100_PER_RAW in tools/tpms_frame.py. */
#define TPMS_PRESSURE_KPA100_PER_RAW 273
#ifdef __cplusplus
static_assert(TPMS_TX_CHIPS == 1 + 2 * (TPMS_ROW_BITS - 1) + 1,
"Nieprawidlowa dlugosc bufora Manchester");
"Invalid Manchester buffer length");
#endif
/* Zwraca false dla ID 0, 0xFFFFFF i wartosci spoza 24 bitow. */
/* Returns false for ID 0, 0xFFFFFF and values outside 24 bits. */
bool tpms_build_payload(uint8_t out[TPMS_PAYLOAD_LEN], uint32_t id,
uint16_t press_kpa10, int8_t temp_c, uint32_t flags);
bool tpms_build_frame(uint8_t out[TPMS_TX_BYTES], uint32_t id,
+17 -17
View File
@@ -1,19 +1,19 @@
/*
* ui.cpp - przycisk (gesty) i LED statusowy (nieblokujaco, bez delay())
* ui.cpp - button (gestures) and status LED (non-blocking, no delay())
*/
#include <Arduino.h>
#include "config.h"
#include "ui.h"
/* ---------------------------- przycisk ---------------------------- */
/* Debounce: nowy stan surowy musi sie utrzymac BTN_DEBOUNCE_MS, zanim
* zostanie uznany za stan stabilny (kandydat + czas jego zmiany). */
/* ---------------------------- button ---------------------------- */
/* Debounce: the new raw state must persist for BTN_DEBOUNCE_MS before it is
* accepted as stable (candidate + the time it changed). */
static bool btn_raw_last = false; // ostatni surowy odczyt
static uint32_t btn_raw_change = 0; // czas ostatniej zmiany surowej
static bool btn_stable = false; // stan po debounce
static bool btn_raw_last = false; // last raw reading
static uint32_t btn_raw_change = 0; // time of the last raw change
static bool btn_stable = false; // debounced state
static uint32_t btn_press_start = 0;
static bool btn_long_fired = false; // bardzo dlugie zdarzenie juz wyslane
static bool btn_long_fired = false; // very long event already reported
bool ui_button_down(void)
{
@@ -31,7 +31,7 @@ void ui_init(void)
btn_raw_last = raw;
btn_raw_change = now;
btn_stable = raw;
btn_press_start = now; // start z wcisnietym przyciskiem = poczatek gestu
btn_press_start = now; // starting pressed = beginning of a gesture
btn_long_fired = false;
}
@@ -42,12 +42,12 @@ ui_event_t ui_poll(void)
uint32_t now = millis();
if (raw != btn_raw_last) {
/* kandydat - czekaj az stan sie utrzyma */
/* candidate - wait until the state persists */
btn_raw_last = raw;
btn_raw_change = now;
}
else if (raw != btn_stable && (now - btn_raw_change) >= BTN_DEBOUNCE_MS) {
btn_stable = raw; // zaakceptowany po debounce
btn_stable = raw; // accepted after debounce
if (btn_stable) {
btn_press_start = now;
btn_long_fired = false;
@@ -60,7 +60,7 @@ ui_event_t ui_poll(void)
}
}
/* bardzo dlugi przycisk sygnalizujemy od razu (nie czekajac na puszczenie) */
/* very long press is signalled immediately (without waiting for release) */
if (btn_stable && !btn_long_fired && (now - btn_press_start) >= BTN_VERYLONG_MS) {
btn_long_fired = true;
ev = UI_EV_VERYLONG;
@@ -73,7 +73,7 @@ ui_event_t ui_poll(void)
static ui_pat_t led_pat = UI_PAT_OFF;
static uint8_t led_blinks_left = 0;
static bool led_on = false;
static bool led_series = false; // seria migniec w trakcie
static bool led_series = false; // blink series in progress
static uint32_t led_next = 0;
void ui_set_pattern(ui_pat_t pat)
@@ -103,7 +103,7 @@ void ui_update(void)
if (led_series) {
if (led_on) {
/* koniec migniecia */
/* end of a blink */
digitalWrite(PIN_LED, LED_ACTIVE_LEVEL ? LOW : HIGH);
led_on = false;
if (led_blinks_left > 0) {
@@ -112,13 +112,13 @@ void ui_update(void)
led_next = now + 90;
}
else if (led_blinks_left > 0) {
/* kolejne migniecie */
/* next blink */
digitalWrite(PIN_LED, LED_ACTIVE_LEVEL ? HIGH : LOW);
led_on = true;
led_next = now + 90;
}
else {
/* koniec serii - przerwa zalezna od wzorca */
/* end of the series - gap depends on the pattern */
led_series = false;
uint32_t idle = 2000;
switch (led_pat) {
@@ -133,7 +133,7 @@ void ui_update(void)
return;
}
/* rozpoczynamy serie wg wzorca */
/* start the series for the pattern */
if (led_pat == UI_PAT_OFF) {
digitalWrite(PIN_LED, LED_ACTIVE_LEVEL ? LOW : HIGH);
led_next = now + 50;
+9 -9
View File
@@ -1,5 +1,5 @@
/*
* ui.h - przycisk (gesty) i LED statusowy
* ui.h - button (gestures) and status LED
*/
#ifndef TPMS_UI_H
#define TPMS_UI_H
@@ -14,28 +14,28 @@ extern "C" {
typedef enum {
UI_EV_NONE = 0,
UI_EV_SHORT, // < BTN_LONG_MS
UI_EV_LONG, // >= BTN_LONG_MS (wejscie/wyjscie LEARN)
UI_EV_VERYLONG, // >= BTN_VERYLONG_MS (wejscie/wyjscie SINGLE)
UI_EV_LONG, // >= BTN_LONG_MS (enter/exit LEARN)
UI_EV_VERYLONG, // >= BTN_VERYLONG_MS (enter/exit SINGLE)
} ui_event_t;
typedef enum {
UI_PAT_OFF = 0,
UI_PAT_NORMAL, // 1 migniecie co 2 s
UI_PAT_LEARN, // 3 szybkie migniecia co 0.5 s
UI_PAT_SINGLE, // 2 szybkie migniecia co 0.5 s
UI_PAT_LOWBAT, // 10 szybkich migniec co 3 s
UI_PAT_NORMAL, // 1 blink every 2 s
UI_PAT_LEARN, // 3 quick blinks every 0.5 s
UI_PAT_SINGLE, // 2 quick blinks every 0.5 s
UI_PAT_LOWBAT, // 10 quick blinks every 3 s
} ui_pat_t;
void ui_init(void);
/* Nieblokujaca obsluga przycisku i LED - wywolywac w kazdej petli. */
/* Non-blocking button and LED handling - call in every loop. */
ui_event_t ui_poll(void);
void ui_update(void);
bool ui_button_down(void);
void ui_set_pattern(ui_pat_t pat);
/* Seria n szybkich migniec (np. numer kola: 1-4). */
/* Series of n quick blinks (e.g. wheel number: 1-4). */
void ui_blink_count(uint8_t n);
#ifdef __cplusplus