Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
6 changes: 4 additions & 2 deletions include/openosc/application/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions include/openosc/input/gestures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions include/openosc/input/key_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/openosc/platform/input_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 5 additions & 4 deletions include/openosc/settings/preferences.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) &&
Expand Down
31 changes: 22 additions & 9 deletions src/application/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/application/instruments/scope_keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/input/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/settings/preferences_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ bool PreferencesJson::parse(const char *input, size_t bytes, Preferences &output
if (!root["hold_ms"].is<unsigned>()) return false;
const unsigned ms = root["hold_ms"].as<unsigned>();
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")) {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/settings/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down