From 3ae5c845599e5417b9c2a0d8fd0d107ce86745aa Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Mon, 23 Nov 2026 18:59:47 +0300 Subject: [PATCH] Add a short-press option for the REL power off Settings > Device > Power > Power-off hold gets a fourth choice, Short press: a short REL press powers off from every screen, and REL's own function (relative measurement, the oscilloscope footer page) moves to a 1 s hold. The 2 s long press does nothing in this mode and no hold progress is shown; instead "Powering off..." is drawn at once, before the saves hold the screen. A wake from a dark screen takes REL's stroke in this mode, as it does for every other key. Stored as hold_ms 0 in settings.json; the default stays at 2 s. --- README.md | 4 ++- include/openosc/application/controller.hpp | 6 +++-- include/openosc/input/gestures.hpp | 5 ++-- include/openosc/input/key_input.hpp | 10 ++++--- include/openosc/platform/input_service.hpp | 2 +- include/openosc/settings/preferences.hpp | 9 ++++--- src/application/controller.cpp | 31 +++++++++++++++------- src/application/instruments/scope_keys.cpp | 2 +- src/input/service.cpp | 4 +-- src/settings/preferences_json.cpp | 4 +-- src/ui/settings/properties.cpp | 4 +-- 11 files changed, 52 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index ce01df47..8279de4d 100644 --- a/README.md +++ b/README.md @@ -264,7 +264,9 @@ Captured on a ZT703S running OpenOSC. The Bode screens replay a recorded twin-T you switch the device off, restart it or enter Recovery. The microcontroller's internal Flash holds only the firmware. You can edit the files from a computer; a damaged settings file is restored from its previous version or from a copy in `/openosc/SETCOPY/`. -- Hold-to-power-off with a progress bar +- Hold-to-power-off with a progress bar. **Settings → Device → Power → Power-off hold → Short press** + powers off on a short REL press instead; REL's own function (relative measurement, the oscilloscope + footer page) then moves to a 1 s hold - Hardware watchdog in both the firmware and Recovery: a hang or a crash restarts the device **Recovery bootloader** diff --git a/include/openosc/application/controller.hpp b/include/openosc/application/controller.hpp index 4aa75175..d3f55d8b 100644 --- a/include/openosc/application/controller.hpp +++ b/include/openosc/application/controller.hpp @@ -85,7 +85,7 @@ class ApplicationController { uint8_t triggerRepeats_ = 0; int8_t triggerSign_ = 0; PerformanceCounter performance_; - void onKeys(const KeyEvents &events, uint32_t now); + void onKeys(const KeyEvents &events, uint32_t now, bool relativeHeld = false); void settingsKeys(uint32_t keys, uint32_t now); void showSettings(); void closeSettings(); @@ -413,8 +413,10 @@ class ApplicationController { MeterRestore meterRestore_; // The DMM entry's range restore (meter_restore.hpp). uint32_t dmmRestarts_ = 0, dmmReselects_ = 0; bool powerFired_ = false; // The REL hold (Preferences::holdMs) powered off once this stroke. + bool relativeFired_ = false; // The 1 s REL hold ran REL's function once this stroke (Preferences::shortPowerOff). ScopeAutoKey autoKey_; // AUTO's open stroke on the Scope waveform screen. - void powerOff(uint32_t now); + // announce: "Powering off..." drawn at once, before the saves block the screen (the short press has no hold progress). + void powerOff(uint32_t now, bool announce = false); // An explicit DMM command (keys, SCPI): accepted, it supersedes the entry's pending restore. bool meterCommand(bool accepted) { if (accepted) meterRestore_.cancel(); return accepted; } // *OPC?'s view of that restore (InstrumentBackend::busy): owed and still able to happen. diff --git a/include/openosc/input/gestures.hpp b/include/openosc/input/gestures.hpp index 395d4e42..a1bdaeef 100644 --- a/include/openosc/input/gestures.hpp +++ b/include/openosc/input/gestures.hpp @@ -26,8 +26,9 @@ class KeyGestures { // REL/Power and AUTO/RANGE hold as the factory's KEY4/KEY5: four 500 ms intervals (703S 080459F4). static constexpr uint32_t LongHoldMs = 2000; // REL/Power: from the first interval (500 ms after the debounced press) the power-off progress - // shows, and a release from then on cancels it with no REL (as the factory's poll); a release - // before it is REL. AUTO/RANGE keeps its short press below LongHoldMs. + // shows (the hold settings), and a release from then on cancels it with no REL (as the factory's + // poll); a release before it is REL, or the power off with the short-press setting. AUTO/RANGE + // keeps its short press below LongHoldMs. static constexpr uint32_t PowerCommitMs = 500; static constexpr uint32_t RepeatDelayMs = 400, RepeatPeriodMs = 80; // The factory's KEY5 intervals: the long flag at the first 500 ms interval, slot2 at the fourth diff --git a/include/openosc/input/key_input.hpp b/include/openosc/input/key_input.hpp index b0915430..eaa2c564 100644 --- a/include/openosc/input/key_input.hpp +++ b/include/openosc/input/key_input.hpp @@ -14,9 +14,13 @@ class KeyInput { gestures_=KeyGestures{}; gestures_.poll(keys,now); written_=read_=0; keys_=keys; activity_=false; dropped_=0; holding_=false; } - // A wake takes the stroke of every key held, except that REL/Power still counts towards its - // hold (power off from a dark screen); its short release gives nothing. - void wake(uint32_t keys,uint32_t now) { reset(keys,now); gestures_.holdOnly(Keypad::Relative,now); } + // A wake takes the stroke of every key held. With relativeHold (the power-off hold settings) REL/Power + // still counts towards its hold (power off from a dark screen); its short release gives nothing. + // Without it (the short-press power off) REL's hold is REL's own function, so the wake takes it too. + void wake(uint32_t keys,uint32_t now,bool relativeHold) { + reset(keys,now); + if (relativeHold) gestures_.holdOnly(Keypad::Relative,now); + } void sample(uint32_t keys,uint32_t now) { if (keys_.exchange(keys,std::memory_order_relaxed)!=keys) activity_.store(true,std::memory_order_release); const auto events=gestures_.poll(keys,now); diff --git a/include/openosc/platform/input_service.hpp b/include/openosc/platform/input_service.hpp index 6316ad43..d8b59dbf 100644 --- a/include/openosc/platform/input_service.hpp +++ b/include/openosc/platform/input_service.hpp @@ -11,7 +11,7 @@ class InputService { static bool take(TimedKeyEvents &event); static bool overflowed(); static void suppress(); - static void wake(); // suppress(), but a REL/Power hold goes on (KeyInput::wake). + static void wake(bool relativeHold); // suppress(); with relativeHold a REL/Power hold goes on (KeyInput::wake). static bool powerHold(uint32_t &elapsed); }; } // namespace openosc diff --git a/include/openosc/settings/preferences.hpp b/include/openosc/settings/preferences.hpp index 37ad7418..0bfff184 100644 --- a/include/openosc/settings/preferences.hpp +++ b/include/openosc/settings/preferences.hpp @@ -30,9 +30,10 @@ struct Preferences { // Bytes beside batteryOffsetMv, with bode after them: the space four 32-bit words took (sizeof checked below). uint8_t panReverse = 0; // Left/Right pan: 0 moves the view, 1 the waveform. uint8_t clockIndicator = 0; // Scope top bar L/M/H run profile glyph: 0 off (older files), 1 on. - uint8_t holdTime = 2; // REL power-off hold: HoldTimes index. - static constexpr uint32_t HoldTimes[] = {1000, 1500, 2000}; - uint32_t holdMs() const { return HoldTimes[holdTime < 3 ? holdTime : 2]; } + uint8_t holdTime = 3; // REL power-off hold: HoldTimes index; 0 is a short press, no hold. + static constexpr uint32_t HoldTimes[] = {0, 1000, 1500, 2000}; + bool shortPowerOff() const { return holdTime == 0; } // REL's short press powers off; its own function moves to a 1 s hold. + uint32_t holdMs() const { return HoldTimes[holdTime < 4 ? holdTime : 3]; } // Settings > Files & USB > USB controller: 1 enabled (USB data where the clock allows it, 200 MHz), // 0 disabled (the OTG controller stays off; Recovery's USB disk is not affected). Older files: enabled. uint8_t usbController = 1; @@ -54,7 +55,7 @@ struct Preferences { return brightness >= 10 && brightness <= 100 && mode < InstrumentModeCount && timebaseNs >= 10 && timebaseNs <= 20000000000ULL && scope::VoltageRanges::contains(millivolts[0]) && scope::VoltageRanges::contains(millivolts[1]) && meterFunction < MeterFunctionCount && - useBuiltinTheme <= 1 && showFps <= 2 && Tooltips::valid(tooltipsHidden) && batteryDisplay < 3 && power::BatteryGauge::trimValid(batteryGainPermille, batteryOffsetMv) && panReverse < 2 && clockIndicator <= 1 && holdTime < 3 && usbController <= 1 && bode.valid() && + useBuiltinTheme <= 1 && showFps <= 2 && Tooltips::valid(tooltipsHidden) && batteryDisplay < 3 && power::BatteryGauge::trimValid(batteryGainPermille, batteryOffsetMv) && panReverse < 2 && clockIndicator <= 1 && holdTime < 4 && usbController <= 1 && bode.valid() && generatorShape < 6 && generatorMillihertz >= generator::Capabilities::MinimumMillihertz && generatorMillihertz <= generator::Capabilities::maximumMillihertz(generator::Shape(generatorShape),generator::Level(generatorLevel)) && diff --git a/src/application/controller.cpp b/src/application/controller.cpp index 51487e39..4492e2da 100644 --- a/src/application/controller.cpp +++ b/src/application/controller.cpp @@ -167,7 +167,7 @@ void ApplicationController::serviceMcuTemperature(uint32_t now) { const bool activity=InputService::activity(); const bool wake=servicePower(InputService::keys() || activity,now); if (wake) { - InputService::wake(); + InputService::wake(!prefs_.shortPowerOff()); // Short press: the wake takes REL's stroke like any key's. autoKey_.cancel(); } if (InputService::overflowed()) { @@ -176,12 +176,20 @@ void ApplicationController::serviceMcuTemperature(uint32_t now) { data_.closeDmmRange(); // Its release may be among the lost events. if (uiReady_) view_.notify(Tooltip::Critical, "Input overflow; press again",now); } - { // The REL/Power hold, from the input sampler's own timing; the long press covers headless. + { // The REL/Power hold, from the input sampler's own timing; the long press covers headless. With the + // short-press power off the hold is REL's own function and the power off is onKeys' short press. uint32_t held = 0; const bool down = InputService::powerHold(held), holding = shutdown_ == Shutdown::None && down; - if (!down) powerFired_ = false; // Up (debounced): the long press's end is no new hold. - else if (holding && held >= prefs_.holdMs() && !recoveryPending_) powerOff(now); - const int power = PowerHold::percent(holding, held, prefs_.holdMs()); + const bool shortOff = prefs_.shortPowerOff(); // REL's short press powers off; its hold is REL's own function. + if (!down) powerFired_ = relativeFired_ = false; // Up (debounced): the long press's end is no new hold. + else if (shortOff) { + if (holding && held >= KeyGestures::HoldMs && !relativeFired_) { + relativeFired_ = true; + onKeys(KeyEvents{Keypad::Relative}, now, true); // Held, not released: the short press's own routing. + refreshSoftKeys(); + } + } else if (holding && held >= prefs_.holdMs() && !recoveryPending_) powerOff(now); + const int power = shortOff ? -1 : PowerHold::percent(holding, held, prefs_.holdMs()); const int automatic = scopeAutoCountdown(now, power >= 0); // Every pass: its input state must not depend on the drawing. if (uiReady_) { if (power >= 0) view_.powerHold(power, "Hold to power off"); @@ -262,7 +270,7 @@ void ApplicationController::applyPreferences() { applyBrightness(); dataRefresh_=true; } -void ApplicationController::powerOff(uint32_t now) { +void ApplicationController::powerOff(uint32_t now, bool announce) { if (powerFired_) return; // Once a hold: a refusal is not repeated every pass. powerFired_ = true; if (panel_==Panel::Zero) data_.cancelZero(now); @@ -271,9 +279,10 @@ void ApplicationController::powerOff(uint32_t now) { if (panel_ == Panel::InterleaveMatch) finishInterleaveMatch(now, Tooltip::Done, nullptr, false); #endif if (dropEdit(now) && uiReady_) showSettings(); // Not saved, not kept if the power off is refused. + if (announce && uiReady_) { shutdownNotice("Powering off...", now); lv_refr_now(nullptr); display_.settle(); } confirmAction_=ShutdownAction::PowerOff; requestShutdown(now); } -void ApplicationController::onKeys(const KeyEvents& events, uint32_t now) { +void ApplicationController::onKeys(const KeyEvents& events, uint32_t now, bool relativeHeld) { const uint32_t keys = events.shortPress | events.repeat; // A held Right steps a Number but never runs through a Choice (relays, run mode): the navigator // takes the next option on its press only. @@ -284,8 +293,12 @@ void ApplicationController::onKeys(const KeyEvents& events, uint32_t now) { if (!(events.shortPress | events.longPress | events.repeat)) return; // REL/Power held to the end of its progress (PowerHold): the power-off pipeline at once, from // every screen, menu, dialog, Remote or headless; it saves settings and files and stops the - // instruments, and says why when it cannot. - if (events.longPress & Keypad::Relative) { powerOff(now); return; } + // instruments, and says why when it cannot. With the short-press setting that is REL's tap, and + // its long press does nothing; relativeHeld: the 1 s hold, REL's own function, not a tap. + if (prefs_.shortPowerOff()) { + if (events.longPress & Keypad::Relative) return; + if (!relativeHeld && (events.shortPress & Keypad::Relative)) { powerOff(now, true); return; } + } else if (events.longPress & Keypad::Relative) { powerOff(now); return; } if (panel_==Panel::Zero) { zeroKeys(keys,now); return; } if (panel_ == Panel::GainMatch) { gainMatchKeys(keys, now); return; } #if OPENOSC_BOARD == 703 diff --git a/src/application/instruments/scope_keys.cpp b/src/application/instruments/scope_keys.cpp index 77374e35..0456b8e4 100644 --- a/src/application/instruments/scope_keys.cpp +++ b/src/application/instruments/scope_keys.cpp @@ -260,7 +260,7 @@ void ApplicationController::scopeKeys(uint32_t keys, uint32_t now, bool fine) { return; } holdKeys(keys, now); - if (keys & Keypad::Relative) view_.scopeFooterPage(); // REL has no other Scope use; its hold is power. + if (keys & Keypad::Relative) view_.scopeFooterPage(); // REL's tap (a 1 s hold with the short-press power off); REL has no other Scope use. // A second F1/F2 press changes the channel only to one that is shown (followShownChannel). if (keys & Keypad::F1) { if (focus_ == plot::Focus::Scale && channelShown(selectedChannel_ ^ 1)) selectedChannel_ ^= 1; diff --git a/src/input/service.cpp b/src/input/service.cpp index 35a992db..fedb62d3 100644 --- a/src/input/service.cpp +++ b/src/input/service.cpp @@ -18,9 +18,9 @@ void InputService::suppress() { CriticalSection guard; input.reset(Keypad::read(),Board::milliseconds()); } -void InputService::wake() { +void InputService::wake(bool relativeHold) { CriticalSection guard; - input.wake(Keypad::read(),Board::milliseconds()); + input.wake(Keypad::read(),Board::milliseconds(),relativeHold); } bool InputService::powerHold(uint32_t &elapsed) { return input.powerHold(elapsed); } } // namespace openosc diff --git a/src/settings/preferences_json.cpp b/src/settings/preferences_json.cpp index 26e22047..004feb2d 100644 --- a/src/settings/preferences_json.cpp +++ b/src/settings/preferences_json.cpp @@ -74,8 +74,8 @@ bool PreferencesJson::parse(const char *input, size_t bytes, Preferences &output if (!root["hold_ms"].is()) return false; const unsigned ms = root["hold_ms"].as(); unsigned index = 0; - while (index < 3 && Preferences::HoldTimes[index] != ms) ++index; - if (index == 3) return false; + while (index < 4 && Preferences::HoldTimes[index] != ms) ++index; + if (index == 4) return false; candidate.holdTime = index; } if (indicators.containsKey("battery")) { diff --git a/src/ui/settings/properties.cpp b/src/ui/settings/properties.cpp index e39cced8..ed8a0e97 100644 --- a/src/ui/settings/properties.cpp +++ b/src/ui/settings/properties.cpp @@ -82,7 +82,7 @@ unsigned SettingsProperties::options(unsigned row) const { case Action::ShowFps: return 3; case Action::ClockIndicator: return 2; case Action::PanDirection: return 2; - case Action::HoldTime: return 3; + case Action::HoldTime: return 4; case Action::BatteryDisplay: return 3; case Action::RunProfile: return RunModeCount; case Action::BufferSize: return scope::RecordBudget::StepCount; @@ -127,7 +127,7 @@ void SettingsProperties::optionName(unsigned row, unsigned index, char *output, case Action::PanDirection: std::snprintf(output, capacity, "%s", index ? "Move waveform" : "Move view"); break; case Action::ClockIndicator: case Action::TooltipUsage: case Action::TooltipUnavailable: case Action::TooltipProgress: case Action::TooltipDone: case Action::TooltipAdvisory: std::snprintf(output, capacity, "%s", index ? "On" : "Off"); break; - case Action::HoldTime: { static constexpr const char *holds[] = {"1 s", "1.5 s", "2 s"}; std::snprintf(output, capacity, "%s", holds[index % 3]); break; } + case Action::HoldTime: { static constexpr const char *holds[] = {"Short press", "1 s", "1.5 s", "2 s"}; std::snprintf(output, capacity, "%s", holds[index % 4]); break; } case Action::RunProfile: { const auto &mode = RunModes[index % RunModeCount]; std::snprintf(output, capacity, "CPU %lu MHz ADC %lu", (unsigned long)mode.coreHz / 1000000UL,