diff --git a/Dockerfile b/Dockerfile index 21e42ad87..76aa3e2a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:bullseye-slim AS builder +FROM debian:bookworm-slim AS builder ENV DEBIAN_FRONTEND=noninteractive ENV TZ=Etc/UTC @@ -11,31 +11,45 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Install build deps USER root -RUN apt-get update && \ - apt-get -y install wget python3 g++ zip python3-venv git vim ca-certificates libgpiod-dev libyaml-cpp-dev libbluetooth-dev -# create a non-priveleged user & group +# trunk-ignore(terrascan/AC_DOCKER_0002): Known terrascan issue +# trunk-ignore(hadolint/DL3008): Use latest version of packages for buildchain +RUN apt-get update && apt-get install --no-install-recommends -y wget python3 python3-pip python3-wheel python3-venv g++ zip git \ + ca-certificates libgpiod-dev libyaml-cpp-dev libbluetooth-dev \ + libulfius-dev liborcania-dev libssl-dev pkg-config && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + RUN groupadd -g 1000 mesh && useradd -ml -u 1000 -g 1000 mesh - USER mesh -RUN wget https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py -qO /tmp/get-platformio.py && \ - chmod +x /tmp/get-platformio.py && \ - python3 /tmp/get-platformio.py && \ - git clone https://github.com/meshtastic/firmware --recurse-submodules /tmp/firmware && \ - cd /tmp/firmware && \ - chmod +x /tmp/firmware/bin/build-native.sh && \ - source ~/.platformio/penv/bin/activate && \ - ./bin/build-native.sh -FROM frolvlad/alpine-glibc:glibc-2.31 +WORKDIR /tmp/firmware +RUN python3 -m venv /tmp/firmware +RUN source ./bin/activate && pip3 install --no-cache-dir -U platformio==6.1.14 -RUN apk --update add --no-cache g++ shadow && \ - groupadd -g 1000 mesh && useradd -ml -u 1000 -g 1000 mesh +COPY . /tmp/firmware +RUN source ./bin/activate && chmod +x /tmp/firmware/bin/build-native.sh && ./bin/build-native.sh +RUN cp "/tmp/firmware/release/meshtasticd_linux_$(uname -m)" "/tmp/firmware/release/meshtasticd" -COPY --from=builder /tmp/firmware/release/meshtasticd_linux_x86_64 /home/mesh/ +##### PRODUCTION BUILD ############# + +FROM debian:bookworm-slim +ENV DEBIAN_FRONTEND=noninteractive +ENV TZ=Etc/UTC + +# trunk-ignore(terrascan/AC_DOCKER_0002): Known terrascan issue +# trunk-ignore(hadolint/DL3008): Use latest version of packages for buildchain +RUN apt-get update && apt-get --no-install-recommends -y install libc-bin libc6 libgpiod2 libyaml-cpp0.7 libulfius2.7 liborcania2.3 libssl3 && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + +RUN groupadd -g 1000 mesh && useradd -ml -u 1000 -g 1000 mesh USER mesh + WORKDIR /home/mesh -CMD sh -cx "./meshtasticd_linux_x86_64 --hwid '${HWID:-$RANDOM}'" +COPY --from=builder /tmp/firmware/release/meshtasticd /home/mesh/ -HEALTHCHECK NONE \ No newline at end of file +VOLUME /home/mesh/data + +CMD [ "sh", "-cx", "./meshtasticd -d /home/mesh/data --hwid=${HWID:-$RANDOM}" ] + +HEALTHCHECK NONE diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index 58a05ff14..6358b8e96 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -34,4 +34,4 @@ build_flags = -DPORTDUINO_LINUX_HARDWARE -lbluetooth -lgpiod - -lyaml-cpp \ No newline at end of file + -lyaml-cpp diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index 22ca3e7db..5a8e658cb 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -1,5 +1,6 @@ ### Define your devices here using Broadcom pin numbering ### Uncomment the block that corresponds to your hardware +### Including the "Module:" line! --- Lora: # Module: sx1262 # Waveshare SX126X XXXM diff --git a/src/ButtonThread.cpp b/src/ButtonThread.cpp index a1f0170e8..069a92308 100644 --- a/src/ButtonThread.cpp +++ b/src/ButtonThread.cpp @@ -48,7 +48,7 @@ ButtonThread::ButtonThread() : OSThread("Button") userButton.setPressMs(c_longPressTime); userButton.setDebounceMs(1); userButton.attachDoubleClick(userButtonDoublePressed); - userButton.attachMultiClick(userButtonMultiPressed); + userButton.attachMultiClick(userButtonMultiPressed, this); // Reference to instance: get click count from non-static OneButton #ifndef T_DECK // T-Deck immediately wakes up after shutdown, so disable this function userButton.attachLongPressStart(userButtonPressedLongStart); userButton.attachLongPressStop(userButtonPressedLongStop); @@ -86,7 +86,8 @@ ButtonThread::ButtonThread() : OSThread("Button") #ifdef BUTTON_PIN_TOUCH userButtonTouch = OneButton(BUTTON_PIN_TOUCH, true, true); - userButtonTouch.attachClick(touchPressed); + userButtonTouch.setPressMs(400); + userButtonTouch.attachLongPressStart(touchPressedLongStart); // Better handling with longpress than click? wakeOnIrq(BUTTON_PIN_TOUCH, FALLING); #endif } @@ -138,26 +139,42 @@ int32_t ButtonThread::runOnce() case BUTTON_EVENT_DOUBLE_PRESSED: { LOG_BUTTON("Double press!\n"); -#if defined(USE_EINK) && defined(PIN_EINK_EN) - digitalWrite(PIN_EINK_EN, digitalRead(PIN_EINK_EN) == LOW); -#endif service.refreshLocalMeshNode(); service.sendNetworkPing(NODENUM_BROADCAST, true); - if (screen) + if (screen) { screen->print("Sent ad-hoc ping\n"); - break; - } -#if HAS_GPS - case BUTTON_EVENT_MULTI_PRESSED: { - LOG_BUTTON("Multi press!\n"); - if (!config.device.disable_triple_click && (gps != nullptr)) { - gps->toggleGpsMode(); - if (screen) - screen->forceDisplay(); + screen->forceDisplay(true); // Force a new UI frame, then force an EInk update } break; } + + case BUTTON_EVENT_MULTI_PRESSED: { + LOG_BUTTON("Mulitipress! %hux\n", multipressClickCount); + switch (multipressClickCount) { +#if HAS_GPS + // 3 clicks: toggle GPS + case 3: + if (!config.device.disable_triple_click && (gps != nullptr)) { + gps->toggleGpsMode(); + if (screen) + screen->forceDisplay(true); // Force a new UI frame, then force an EInk update + } + break; #endif +#if defined(USE_EINK) && defined(PIN_EINK_EN) // i.e. T-Echo + // 4 clicks: toggle backlight + case 4: + digitalWrite(PIN_EINK_EN, digitalRead(PIN_EINK_EN) == LOW); + break; +#endif + // No valid multipress action + default: + break; + } // end switch: click count + + break; + } // end multipress event + case BUTTON_EVENT_LONG_PRESSED: { LOG_BUTTON("Long press!\n"); powerFSM.trigger(EVENT_PRESS); @@ -176,12 +193,24 @@ int32_t ButtonThread::runOnce() power->shutdown(); break; } - case BUTTON_EVENT_TOUCH_PRESSED: { + +#ifdef BUTTON_PIN_TOUCH + case BUTTON_EVENT_TOUCH_LONG_PRESSED: { LOG_BUTTON("Touch press!\n"); - if (screen) - screen->forceDisplay(); + if (config.display.wake_on_tap_or_motion) { + if (screen) { + // Wake if asleep + if (powerFSM.getState() == &stateDARK) + powerFSM.trigger(EVENT_PRESS); + + // Update display (legacy behaviour) + screen->forceDisplay(); + } + } break; } +#endif // BUTTON_PIN_TOUCH + default: break; } @@ -206,6 +235,25 @@ void ButtonThread::wakeOnIrq(int irq, int mode) FALLING); } +// Static callback +void ButtonThread::userButtonMultiPressed(void *callerThread) +{ + // Grab click count from non-static button, while the info is still valid + ButtonThread *thread = (ButtonThread *)callerThread; + thread->storeClickCount(); + + // Then handle later, in the usual way + btnEvent = BUTTON_EVENT_MULTI_PRESSED; +} + +// Non-static method, runs during callback. Grabs info while still valid +void ButtonThread::storeClickCount() +{ +#ifdef BUTTON_PIN + multipressClickCount = userButton.getNumberClicks(); +#endif +} + void ButtonThread::userButtonPressedLongStart() { if (millis() > c_holdOffTime) { diff --git a/src/ButtonThread.h b/src/ButtonThread.h index 554c1f0c4..3f177302d 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -17,11 +17,12 @@ class ButtonThread : public concurrency::OSThread BUTTON_EVENT_MULTI_PRESSED, BUTTON_EVENT_LONG_PRESSED, BUTTON_EVENT_LONG_RELEASED, - BUTTON_EVENT_TOUCH_PRESSED + BUTTON_EVENT_TOUCH_LONG_PRESSED, }; ButtonThread(); int32_t runOnce() override; + void storeClickCount(); private: #ifdef BUTTON_PIN @@ -40,13 +41,16 @@ class ButtonThread : public concurrency::OSThread // set during IRQ static volatile ButtonEventType btnEvent; + // Store click count during callback, for later use + volatile int multipressClickCount = 0; + static void wakeOnIrq(int irq, int mode); // IRQ callbacks - static void touchPressed() { btnEvent = BUTTON_EVENT_TOUCH_PRESSED; } static void userButtonPressed() { btnEvent = BUTTON_EVENT_PRESSED; } static void userButtonDoublePressed() { btnEvent = BUTTON_EVENT_DOUBLE_PRESSED; } - static void userButtonMultiPressed() { btnEvent = BUTTON_EVENT_MULTI_PRESSED; } + static void userButtonMultiPressed(void *callerThread); // Retrieve click count from non-static Onebutton while still valid static void userButtonPressedLongStart(); static void userButtonPressedLongStop(); + static void touchPressedLongStart() { btnEvent = BUTTON_EVENT_TOUCH_LONG_PRESSED; } }; diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 77ca60d18..be063ee53 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1153,10 +1153,33 @@ void Screen::setup() MeshModule::observeUIEvents(&uiFrameEventObserver); } -void Screen::forceDisplay() +void Screen::forceDisplay(bool forceUiUpdate) { // Nasty hack to force epaper updates for 'key' frames. FIXME, cleanup. #ifdef USE_EINK + // If requested, make sure queued commands are run, and UI has rendered a new frame + if (forceUiUpdate) { + // No delay between UI frame rendering + setFastFramerate(); + + // Make sure all CMDs have run first + while (!cmdQueue.isEmpty()) + runOnce(); + + // Ensure at least one frame has drawn + uint64_t startUpdate; + do { + startUpdate = millis(); // Handle impossibly unlikely corner case of a millis() overflow.. + delay(10); + ui->update(); + } while (ui->getUiState()->lastUpdate < startUpdate); + + // Return to normal frame rate + targetFramerate = IDLE_FRAMERATE; + ui->setTargetFPS(targetFramerate); + } + + // Tell EInk class to update the display static_cast(dispdev)->forceDisplay(); #endif } diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index d03ba4320..2cb1cd5a9 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -20,7 +20,7 @@ class Screen void setOn(bool) {} void print(const char *) {} void doDeepSleep() {} - void forceDisplay() {} + void forceDisplay(bool forceUiUpdate = false) {} void startBluetoothPinScreen(uint32_t pin) {} void stopBluetoothPinScreen() {} void startRebootScreen() {} @@ -318,7 +318,7 @@ class Screen : public concurrency::OSThread int handleInputEvent(const InputEvent *arg); /// Used to force (super slow) eink displays to draw critical frames - void forceDisplay(); + void forceDisplay(bool forceUiUpdate = false); /// Draws our SSL cert screen during boot (called from WebServer) void setSSLFrames();