Скетчи не по делу: ручной монитор и тесты потенциометра

This commit is contained in:
AidarKC
2026-10-13 19:04:15 +03:00
parent bb725ee451
commit d25894149b
12 changed files with 2436 additions and 3 deletions
@@ -125,7 +125,11 @@ Initial screen:
- title: `BREATH MONITOR`
- state: `READY`
- action button: `START USB SENSOR`
- action button: `START BUTTONS`
- action button: `START MANUAL MONITOR`
- action button: `START POT 3-WIRE`
- action button: `START POT 2-WIRE`
- action button: `START POT CAL`
- action button: `START PIN DIAG`
After `START USB SENSOR`:
@@ -137,15 +141,54 @@ After `START USB SENSOR`:
- a short `KEY3 / GPIO18` press opens or closes settings in USB sensor mode
- the bottom line shows the durations of the last 5 accepted USB sensor cycles
After `START BUTTONS`:
After `START MANUAL MONITOR`:
- `KEY3 / GPIO18` is the external `INHALE` button, active LOW
- `BOOT / GPIO0` is the external `EXHALE` button, active LOW
- do not hold `BOOT` while booting or resetting the board
- the mode title is `MANUAL MONITOR`
- accepted manual phases strictly alternate: `INHALE`, then `EXHALE`; a repeated current button or `EXHALE` before the first `INHALE` is ignored without a beep or timer reset
- each accepted button press plays one quiet confirmation beep and starts a fresh `Phase time` timer for that inhale or exhale
- the working screen does not show touch `INHALE`/`EXHALE` buttons
- long-holding `KEY3 / INHALE` for about 850 ms opens settings; the long press still counts as an inhale press
- while settings are open, the next `KEY3 / INHALE` press closes settings and also counts as an inhale press
After `START POT 3-WIRE`:
- `GPIO19 / USB D-` is configured as `OUTPUT HIGH` and works as the 3.3 V side of the potentiometer test
- `GPIO20 / USB D+` is configured as ADC input and must be connected to the potentiometer wiper
- `USB GND` must be connected to the other edge pin of the potentiometer
- the screen shows position `0..100%`, a bar, ADC raw value, measured millivolts, and estimated `0..50 kΩ` resistance
- if ADC saturates or reaches an unsafe high-voltage threshold, the firmware releases `D-` and `D+` to `INPUT`, beeps, and shows `USB/PIN FAULT`
- this is only best-effort software protection; ESP32-S3 GPIO pins are not 5 V tolerant, so external wiring must still prevent 5 V from reaching `D+` or `D-`
After `START POT 2-WIRE`:
- `GPIO19 / USB D-` is configured as `OUTPUT HIGH`
- `GPIO20 / USB D+` is configured as ADC input with internal pulldown
- connect only two potentiometer pins between `D-` and `D+`: the wiper and one edge pin
- the screen shows rough position, raw ADC, millivolts, and rough estimated resistance
- this mode is intentionally approximate because the ESP32 internal pulldown value is not precise and can vary between boards
- use `START POT 3-WIRE` for stable and more linear future breath sensing
After `START POT CAL`:
- `GPIO19 / USB D-` is configured as `OUTPUT HIGH`
- `GPIO20 / USB D+` is configured as ADC input with internal pulldown
- connect only two potentiometer pins between `D-` and `D+`: the wiper and one edge pin
- the firmware tracks the observed minimum and maximum ADC millivolts
- the screen shows a calibrated `0..100%` position within the observed range, current millivolts, raw ADC, min-max range, and state
- `KEY3 / GPIO18` resets the learned min-max calibration
- this mode is for relative position testing on weak or shifted USB-pin ranges; it does not report real resistance
After `START PIN DIAG`:
- the firmware runs two alternating USB pin drive/read checks
- Test A drives `GPIO19 / USB D-` HIGH and reads `GPIO20 / USB D+` as ADC
- Test B drives `GPIO20 / USB D+` HIGH and reads `GPIO19 / USB D-` as ADC
- shorting `D-` and `D+` should make the ADC side rise if the pins are actually controllable as GPIO
- if both tests stay near 0 mV, the USB cable/host, USB PHY, or board wiring is likely holding the lines and the USB data pins are not usable as an analog sensor in that setup
In both modes:
- one breathing cycle is measured from one `EXHALE` tap to the next `EXHALE` tap
@@ -156,4 +199,5 @@ In both modes:
- the lower numeric fields use a larger font than before
- if the average of the last up to 5 completed cycles is shorter than the selected limit, warning beeps are played like in the USB contact breath monitor
- if the current cycle reaches 60 seconds, 5 loud warning beeps are played, then after 5 seconds another 5 loud warning beeps are played, repeating until the user changes phase / exits the long cycle
- in manual monitor mode, a single loud warning beep is also played at 35, 40, 45, 50, and 55 seconds of an unchanged inhale or exhale; the repeated five-beep alarm starts at 60 seconds
- settings keep the same sliders: limit `5/7/10/15/20` seconds, quiet cycle tick volume `0..10`, and alert volume `0..10`