diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index d599f447f..30af24bd2 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -29,7 +29,11 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ gpg \ gnupg2 \ libusb-1.0-0-dev \ + libuv1-dev \ libi2c-dev \ + libxcb-xkb-dev \ + libxkbcommon-dev \ + libinput-dev \ && apt-get clean && rm -rf /var/lib/apt/lists/* RUN pipx install platformio diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index 0b2665f84..7c7487cc8 100755 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -1,3 +1,6 @@ #!/usr/bin/env sh git submodule update --init + +pip install --no-cache-dir setuptools +pipx install esptool diff --git a/.gitattributes b/.gitattributes index 584097061..1c945f060 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,5 @@ * text=auto eol=lf -*.{cmd,[cC][mM][dD]} text eol=crlf -*.{bat,[bB][aA][tT]} text eol=crlf +*.cmd text eol=crlf +*.bat text eol=crlf +*.ps1 text eol=crlf *.{sh,[sS][hH]} text eol=lf diff --git a/.github/ISSUE_TEMPLATE/Bug Report.yml b/.github/ISSUE_TEMPLATE/Bug Report.yml index f638b9018..bc77e8c1b 100644 --- a/.github/ISSUE_TEMPLATE/Bug Report.yml +++ b/.github/ISSUE_TEMPLATE/Bug Report.yml @@ -72,6 +72,15 @@ body: validations: required: true + - type: checkboxes + id: mui + attributes: + label: Is this bug report about any UI component firmware like InkHUD or Meshtatic UI (MUI)? + options: + - label: Meshtastic UI aka MUI colorTFT + - label: InkHUD ePaper + - label: OLED slide UI on any display + - type: input id: version attributes: diff --git a/.github/actions/setup-native/action.yml b/.github/actions/setup-native/action.yml index 36c95d943..05f95cd40 100644 --- a/.github/actions/setup-native/action.yml +++ b/.github/actions/setup-native/action.yml @@ -11,4 +11,4 @@ runs: - name: Install libs needed for native build shell: bash run: | - sudo apt-get install -y libbluetooth-dev libgpiod-dev libyaml-cpp-dev openssl libssl-dev libulfius-dev liborcania-dev libusb-1.0-0-dev libi2c-dev + sudo apt-get install -y libbluetooth-dev libgpiod-dev libyaml-cpp-dev openssl libssl-dev libulfius-dev liborcania-dev libusb-1.0-0-dev libi2c-dev libuv1-dev diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a7b4a0f1b..b14290be2 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -19,6 +19,8 @@ updates: interval: daily time: "05:00" timezone: US/Pacific + ignore: + - dependency-name: protobufs - package-ecosystem: github-actions directory: /.github/workflows schedule: diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 6ccb4a105..a15b34aae 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,7 +1,6 @@ +## 🙏 Thank you for sending in a pull request, here's some tips to get started! + ### ❌ (Please delete all these tips and replace them with your text) ❌ - -## Thank you for sending in a pull request, here's some tips to get started! - - Before starting on some new big chunk of code, it it is optional but highly recommended to open an issue first to say "Hey, I think this idea X should be implemented and I'm starting work on it. My general plan is Y, any feedback is appreciated." This will allow other devs to potentially save you time by not accidentially duplicating work etc... @@ -12,4 +11,17 @@ - If your PR fixes a bug, mention "fixes #bugnum" somewhere in your pull request description. - If your other co-developers have comments on your PR please tweak as needed. - Please also enable "Allow edits by maintainers". +- Please do not submit untested code. +- If you do not have the affected hardware to test your code changes adequately against regressions, please indicate this, so that contributors and commnunity members can help test your changes. - If your PR gets accepted you can request a "Contributor" role in the Meshtastic Discord + + +## 🤝 Attestations +- [ ] I have tested that my proposed changes behave as described. +- [ ] I have tested that my proposed changes do not cause any obvious regressions on the following devices: + - [ ] Heltec (Lora32) V3 + - [ ] LilyGo T-Deck + - [ ] LilyGo T-Beam + - [ ] RAK WisBlock 4631 + - [ ] Seeed Studio T-1000E tracker card + - [ ] Other (please specify below) diff --git a/.github/workflows/build_debian_src.yml b/.github/workflows/build_debian_src.yml index 714542047..5c441f085 100644 --- a/.github/workflows/build_debian_src.yml +++ b/.github/workflows/build_debian_src.yml @@ -4,7 +4,7 @@ on: workflow_call: secrets: PPA_GPG_PRIVATE_KEY: - required: true + required: false inputs: series: description: Ubuntu/Debian series to target diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index da4b4e6f3..5b11926f2 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -136,6 +136,7 @@ jobs: secrets: inherit package-pio-deps-native-tft: + if: ${{ github.event_name == 'workflow_dispatch' }} uses: ./.github/workflows/package_pio_deps.yml with: pio_env: native-tft @@ -329,13 +330,13 @@ jobs: with: pattern: platformio-deps-native-tft-${{ steps.version.outputs.long }} merge-multiple: true - path: ./output/pio-deps-native + path: ./output/pio-deps-native-tft - name: Zip linux sources working-directory: output run: | zip -j -9 -r ./meshtasticd-${{ steps.version.outputs.deb }}-src.zip ./debian-src - zip -9 -r ./platformio-deps-native-${{ steps.version.outputs.long }}.zip ./pio-deps-native + zip -9 -r ./platformio-deps-native-tft-${{ steps.version.outputs.long }}.zip ./pio-deps-native-tft # For diagnostics - name: Display structure of downloaded files @@ -344,32 +345,10 @@ jobs: - name: Add linux sources to release run: | gh release upload v${{ steps.version.outputs.long }} ./output/meshtasticd-${{ steps.version.outputs.deb }}-src.zip - gh release upload v${{ steps.version.outputs.long }} ./output/platformio-deps-native-${{ steps.version.outputs.long }}.zip + gh release upload v${{ steps.version.outputs.long }} ./output/platformio-deps-native-tft-${{ steps.version.outputs.long }}.zip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Bump version.properties - run: >- - bin/bump_version.py - - - name: Ensure debian deps are installed - shell: bash - run: | - sudo apt-get update -y --fix-missing - sudo apt-get install -y devscripts - - - name: Update debian changelog - run: >- - debian/ci_changelog.sh - - - name: Create version.properties pull request - uses: peter-evans/create-pull-request@v7 - with: - title: Bump version.properties - add-paths: | - version.properties - debian/changelog - release-firmware: strategy: fail-fast: false diff --git a/.github/workflows/release_channels.yml b/.github/workflows/release_channels.yml index 9cdabde9e..710e8e51d 100644 --- a/.github/workflows/release_channels.yml +++ b/.github/workflows/release_channels.yml @@ -43,3 +43,49 @@ jobs: copr_project: |- ${{ contains(github.event.release.name, 'Beta') && 'beta' || contains(github.event.release.name, 'Alpha') && 'alpha' }} secrets: inherit + + # Create a PR to bump version when a release is Published + bump-version: + if: ${{ github.event.release.published }} + runs-on: ubuntu-latest + permissions: + pull-requests: write + contents: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.x + + - name: Get release version string + run: | + echo "long=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT + echo "deb=$(./bin/buildinfo.py deb)" >> $GITHUB_OUTPUT + id: version + env: + BUILD_LOCATION: local + + - name: Bump version.properties + run: >- + bin/bump_version.py + + - name: Ensure debian deps are installed + shell: bash + run: | + sudo apt-get update -y --fix-missing + sudo apt-get install -y devscripts + + - name: Update debian changelog + run: >- + debian/ci_changelog.sh + + - name: Create version.properties pull request + uses: peter-evans/create-pull-request@v7 + with: + title: Bump version.properties + add-paths: | + version.properties + debian/changelog diff --git a/.github/workflows/sec_sast_semgrep_cron.yml b/.github/workflows/sec_sast_semgrep_cron.yml index 944103562..db308c9f5 100644 --- a/.github/workflows/sec_sast_semgrep_cron.yml +++ b/.github/workflows/sec_sast_semgrep_cron.yml @@ -6,11 +6,14 @@ on: schedule: - cron: 0 1 * * 6 -permissions: read-all +permissions: + actions: read + contents: read + security-events: write jobs: semgrep-full: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 container: image: semgrep/semgrep diff --git a/.github/workflows/stale_bot.yml b/.github/workflows/stale_bot.yml index 19b7cf7fd..5ae6bdfc9 100644 --- a/.github/workflows/stale_bot.yml +++ b/.github/workflows/stale_bot.yml @@ -18,5 +18,6 @@ jobs: - name: Stale PR+Issues uses: actions/stale@v9.1.0 with: + days-before-stale: 45 exempt-issue-labels: pinned,3.0 exempt-pr-labels: pinned,3.0 diff --git a/.github/workflows/test_native.yml b/.github/workflows/test_native.yml index c7b0ef34c..c3643dcbd 100644 --- a/.github/workflows/test_native.yml +++ b/.github/workflows/test_native.yml @@ -143,7 +143,7 @@ jobs: merge-multiple: true - name: Test Report - uses: dorny/test-reporter@v1.9.1 + uses: dorny/test-reporter@v2.0.0 with: name: PlatformIO Tests path: testreport.xml diff --git a/.gitmodules b/.gitmodules index 964204476..7c54ad513 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "protobufs"] path = protobufs url = https://github.com/meshtastic/protobufs.git -[submodule "lib/device-ui"] - path = lib/device-ui - url = https://github.com/meshtastic/device-ui.git [submodule "meshtestic"] path = meshtestic url = https://github.com/meshtastic/meshTestic diff --git a/.trunk/configs/.clang-tidy b/.trunk/configs/.clang-tidy deleted file mode 100644 index e4bd819fa..000000000 --- a/.trunk/configs/.clang-tidy +++ /dev/null @@ -1,39 +0,0 @@ -Checks: >- - bugprone-*, - cppcoreguidelines-*, - google-*, - misc-*, - modernize-*, - performance-*, - readability-*, - -bugprone-lambda-function-name, - -bugprone-reserved-identifier, - -cppcoreguidelines-avoid-goto, - -cppcoreguidelines-avoid-magic-numbers, - -cppcoreguidelines-avoid-non-const-global-variables, - -cppcoreguidelines-pro-bounds-array-to-pointer-decay, - -cppcoreguidelines-pro-type-vararg, - -google-readability-braces-around-statements, - -google-readability-function-size, - -misc-no-recursion, - -modernize-return-braced-init-list, - -modernize-use-nodiscard, - -modernize-use-trailing-return-type, - -performance-unnecessary-value-param, - -readability-magic-numbers, - -CheckOptions: - - key: readability-function-cognitive-complexity.Threshold - value: 100 - - key: readability-function-cognitive-complexity.IgnoreMacros - value: true - # Set naming conventions for your style below (there are dozens of naming settings possible): - # See https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html - # - key: readability-identifier-naming.ClassCase - # value: CamelCase - # - key: readability-identifier-naming.NamespaceCase - # value: lower_case - # - key: readability-identifier-naming.PrivateMemberSuffix - # value: _ - # - key: readability-identifier-naming.StructCase - # value: CamelCase diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 78fdb8e45..4c570c856 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,6 +1,6 @@ version: 0.1 cli: - version: 1.22.10 + version: 1.22.11 plugins: sources: - id: trunk @@ -8,15 +8,15 @@ plugins: uri: https://github.com/trunk-io/plugins lint: enabled: - - prettier@3.5.2 - - trufflehog@3.88.14 - - yamllint@1.35.1 + - prettier@3.5.3 + - trufflehog@3.88.20 + - yamllint@1.37.0 - bandit@1.8.3 - - checkov@3.2.378 + - checkov@3.2.394 - terrascan@1.19.9 - - trivy@0.59.1 + - trivy@0.61.0 - taplo@0.9.3 - - ruff@0.9.7 + - ruff@0.11.2 - isort@6.0.1 - markdownlint@0.44.0 - oxipng@9.1.4 @@ -28,9 +28,8 @@ lint: - shellcheck@0.10.0 - black@25.1.0 - git-diff-check - - gitleaks@8.24.0 + - gitleaks@8.24.2 - clang-format@16.0.3 - - clang-tidy@16.0.3 ignore: - linters: [ALL] paths: diff --git a/.vscode/settings.json b/.vscode/settings.json index bf9b82111..81deca8f9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,8 @@ "cmake.configureOnOpen": false, "[cpp]": { "editor.defaultFormatter": "trunk.io" + }, + "[powershell]": { + "editor.defaultFormatter": "ms-vscode.powershell" } } diff --git a/Dockerfile b/Dockerfile index fd1bb6164..733a46325 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ ENV TZ=Etc/UTC ENV PIP_ROOT_USER_ACTION=ignore RUN apt-get update && apt-get install --no-install-recommends -y \ wget g++ zip git ca-certificates \ - libgpiod-dev libyaml-cpp-dev libbluetooth-dev libi2c-dev \ + libgpiod-dev libyaml-cpp-dev libbluetooth-dev libi2c-dev libuv1-dev \ libusb-1.0-0-dev libulfius-dev liborcania-dev libssl-dev pkg-config \ && apt-get clean && rm -rf /var/lib/apt/lists/* \ && pip install --no-cache-dir -U platformio \ @@ -38,7 +38,7 @@ ENV TZ=Etc/UTC USER root RUN apt-get update && apt-get --no-install-recommends -y install \ - libc-bin libc6 libgpiod2 libyaml-cpp0.7 libi2c0 libulfius2.7 libusb-1.0-0-dev liborcania2.3 libssl3 \ + libc-bin libc6 libgpiod2 libyaml-cpp0.7 libi2c0 libuv1 libusb-1.0-0-dev liborcania2.3 libulfius2.7 libssl3 \ && apt-get clean && rm -rf /var/lib/apt/lists/* \ && mkdir -p /var/lib/meshtasticd \ && mkdir -p /etc/meshtasticd/config.d \ diff --git a/alpine.Dockerfile b/alpine.Dockerfile index b6d91a75a..17afc2964 100644 --- a/alpine.Dockerfile +++ b/alpine.Dockerfile @@ -9,7 +9,7 @@ FROM python:3.13-alpine3.21 AS builder ENV PIP_ROOT_USER_ACTION=ignore RUN apk --no-cache add \ bash g++ libstdc++-dev linux-headers zip git ca-certificates libgpiod-dev yaml-cpp-dev bluez-dev \ - libusb-dev i2c-tools-dev openssl-dev pkgconf argp-standalone \ + libusb-dev i2c-tools-dev libuv-dev openssl-dev pkgconf argp-standalone \ && rm -rf /var/cache/apk/* \ && pip install --no-cache-dir -U platformio \ && mkdir /tmp/firmware @@ -32,7 +32,7 @@ FROM alpine:3.21 USER root RUN apk --no-cache add \ - libstdc++ libgpiod yaml-cpp libusb i2c-tools \ + libstdc++ libgpiod yaml-cpp libusb i2c-tools libuv \ && rm -rf /var/cache/apk/* \ && mkdir -p /var/lib/meshtasticd \ && mkdir -p /etc/meshtasticd/config.d \ diff --git a/arch/esp32/esp32.ini b/arch/esp32/esp32.ini index 256781ba1..df3778002 100644 --- a/arch/esp32/esp32.ini +++ b/arch/esp32/esp32.ini @@ -45,11 +45,11 @@ lib_deps = ${networking_base.lib_deps} ${environmental_base.lib_deps} ${radiolib_base.lib_deps} - https://github.com/meshtastic/esp32_https_server.git#23665b3adc080a311dcbb586ed5941b5f94d6ea2 + https://github.com/meshtastic/esp32_https_server/archive/23665b3adc080a311dcbb586ed5941b5f94d6ea2.zip h2zero/NimBLE-Arduino@^1.4.3 - https://github.com/dbinfrago/libpax.git#3cdc0371c375676a97967547f4065607d4c53fd1 + https://github.com/dbinfrago/libpax/archive/3cdc0371c375676a97967547f4065607d4c53fd1.zip lewisxhe/XPowersLib@^0.2.7 - https://github.com/meshtastic/ESP32_Codec2.git#633326c78ac251c059ab3a8c430fcdf25b41672f + https://github.com/meshtastic/ESP32_Codec2/archive/633326c78ac251c059ab3a8c430fcdf25b41672f.zip rweather/Crypto@^0.4.0 lib_ignore = diff --git a/arch/esp32/esp32c6.ini b/arch/esp32/esp32c6.ini index d0425812f..dba3bac08 100644 --- a/arch/esp32/esp32c6.ini +++ b/arch/esp32/esp32c6.ini @@ -1,6 +1,6 @@ [esp32c6_base] extends = esp32_base -platform = https://github.com/Jason2866/platform-espressif32.git#22faa566df8c789000f8136cd8d0aca49617af55 +platform = https://github.com/Jason2866/platform-espressif32/archive/22faa566df8c789000f8136cd8d0aca49617af55.zip build_flags = ${arduino_base.build_flags} -Wall @@ -25,7 +25,7 @@ lib_deps = ${environmental_base.lib_deps} ${radiolib_base.lib_deps} lewisxhe/XPowersLib@^0.2.7 - https://github.com/meshtastic/ESP32_Codec2.git#633326c78ac251c059ab3a8c430fcdf25b41672f + https://github.com/meshtastic/ESP32_Codec2/archive/633326c78ac251c059ab3a8c430fcdf25b41672f.zip rweather/Crypto@^0.4.0 build_src_filter = diff --git a/arch/nrf52/nrf52.ini b/arch/nrf52/nrf52.ini index 606cabac6..ca12be6b1 100644 --- a/arch/nrf52/nrf52.ini +++ b/arch/nrf52/nrf52.ini @@ -1,10 +1,10 @@ [nrf52_base] ; Instead of the standard nordicnrf52 platform, we use our fork which has our added variant files -platform = platformio/nordicnrf52@^10.7.0 +platform = platformio/nordicnrf52@^10.8.0 extends = arduino_base platform_packages = ; our custom Git version until they merge our PR - platformio/framework-arduinoadafruitnrf52 @ https://github.com/meshtastic/Adafruit_nRF52_Arduino.git#e13f5820002a4fb2a5e6754b42ace185277e5adf + platformio/framework-arduinoadafruitnrf52 @ https://github.com/meshtastic/Adafruit_nRF52_Arduino#e13f5820002a4fb2a5e6754b42ace185277e5adf platformio/toolchain-gccarmnoneeabi@~1.90301.0 build_type = debug @@ -17,7 +17,6 @@ build_flags = -DLFS_NO_ASSERT ; Disable LFS assertions , see https://github.com/meshtastic/firmware/pull/3818 -DMESHTASTIC_EXCLUDE_AUDIO=1 -DMESHTASTIC_EXCLUDE_PAXCOUNTER=1 - -DMAX_NUM_NODES=80 build_src_filter = ${arduino_base.build_src_filter} - - - - - - - - - - diff --git a/arch/nrf52/nrf52840.ini b/arch/nrf52/nrf52840.ini index a13a600f3..0dab5d9ba 100644 --- a/arch/nrf52/nrf52840.ini +++ b/arch/nrf52/nrf52840.ini @@ -6,7 +6,7 @@ build_flags = ${nrf52_base.build_flags} lib_deps = ${nrf52_base.lib_deps} ${environmental_base.lib_deps} - https://github.com/Kongduino/Adafruit_nRFCrypto.git#e31a8825ea3300b163a0a3c1ddd5de34e10e1371 + https://github.com/Kongduino/Adafruit_nRFCrypto/archive/e31a8825ea3300b163a0a3c1ddd5de34e10e1371.zip ; Common NRF52 debugging settings follow. See the Meshtastic developer docs for how to connect SWD debugging probes to your board. diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index 7ea6a77a2..e0488aeff 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -1,6 +1,6 @@ ; The Portduino based 'native' environment. Currently supported on Linux targets with real LoRa hardware (or simulated). [portduino_base] -platform = https://github.com/meshtastic/platform-native.git#562d189828f09fbf4c4093b3c0104bae9d8e9ff9 +platform = https://github.com/meshtastic/platform-native/archive/c5bd469ab9b5a6966321e09557b27d906961da63.zip framework = arduino build_src_filter = @@ -26,7 +26,7 @@ lib_deps = ${radiolib_base.lib_deps} rweather/Crypto@^0.4.0 lovyan03/LovyanGFX@^1.2.0 - https://github.com/pine64/libch341-spi-userspace#a9b17e3452f7fb747000d9b4ad4409155b39f6ef + https://github.com/pine64/libch341-spi-userspace/archive/a9b17e3452f7fb747000d9b4ad4409155b39f6ef.zip build_flags = ${arduino_base.build_flags} @@ -34,10 +34,12 @@ build_flags = -Isrc/platform/portduino -DRADIOLIB_EEPROM_UNSUPPORTED -DPORTDUINO_LINUX_HARDWARE + -DHAS_UDP_MULTICAST -lpthread -lstdc++fs -lbluetooth -lgpiod -lyaml-cpp -li2c + -luv -std=c++17 diff --git a/arch/rp2xx0/rp2040.ini b/arch/rp2xx0/rp2040.ini index 74644800d..33fcfb211 100644 --- a/arch/rp2xx0/rp2040.ini +++ b/arch/rp2xx0/rp2040.ini @@ -1,8 +1,8 @@ ; Common settings for rp2040 Processor based targets [rp2040_base] -platform = https://github.com/maxgerhardt/platform-raspberrypi.git#19e30129fb1428b823be585c787dcb4ac0d9014c ; For arduino-pico >=4.2.1 +platform = https://github.com/maxgerhardt/platform-raspberrypi#76ecf3c7e9dd4503af0331154c4ca1cddc4b03e5 ; For arduino-pico >= 4.4.3 extends = arduino_base -platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#6024e9a7e82a72e38dd90f42029ba3748835eb2e ; 4.3.0 with fix MDNS +platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico#4.4.3 board_build.core = earlephilhower board_build.filesystem_size = 0.5m diff --git a/arch/rp2xx0/rp2350.ini b/arch/rp2xx0/rp2350.ini index 6f1e4400e..841035c80 100644 --- a/arch/rp2xx0/rp2350.ini +++ b/arch/rp2xx0/rp2350.ini @@ -1,8 +1,8 @@ ; Common settings for rp2040 Processor based targets [rp2350_base] -platform = https://github.com/maxgerhardt/platform-raspberrypi.git#76ecf3c7e9dd4503af0331154c4ca1cddc4b03e5 ; For arduino-pico >= 4.4.3 +platform = https://github.com/maxgerhardt/platform-raspberrypi#76ecf3c7e9dd4503af0331154c4ca1cddc4b03e5 ; For arduino-pico >= 4.4.3 extends = arduino_base -platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#4.4.3 +platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico#4.4.3 board_build.core = earlephilhower board_build.filesystem_size = 0.5m diff --git a/arch/stm32/stm32.ini b/arch/stm32/stm32.ini index efa1ab0e4..c1b58bb82 100644 --- a/arch/stm32/stm32.ini +++ b/arch/stm32/stm32.ini @@ -1,13 +1,14 @@ [stm32_base] extends = arduino_base -platform = platformio/ststm32 -platform_packages = platformio/framework-arduinoststm32@^4.20900.0 +platform = ststm32 +platform_packages = platformio/framework-arduinoststm32@https://github.com/stm32duino/Arduino_Core_STM32/archive/2.10.1.zip +extra_scripts = + ${env.extra_scripts} + post:extra_scripts/extra_stm32.py build_type = release -;board_build.flash_offset = 0x08000000 - -build_flags = +build_flags = ${arduino_base.build_flags} -flto -Isrc/platform/stm32wl -g @@ -18,27 +19,24 @@ build_flags = -DMESHTASTIC_EXCLUDE_SCREEN -DMESHTASTIC_EXCLUDE_MQTT -DMESHTASTIC_EXCLUDE_BLUETOOTH - -DMESHTASTIC_EXCLUDE_PKI -DMESHTASTIC_EXCLUDE_GPS -; -DVECT_TAB_OFFSET=0x08000000 - -DconfigUSE_CMSIS_RTOS_V2=1 -; -DSPI_MODE_0=SPI_MODE0 + ;-DDEBUG_MUTE -fmerge-all-constants -ffunction-sections -fdata-sections - -build_src_filter = + +build_src_filter = ${arduino_base.build_src_filter} - - - - - - - - - - - - - - board_upload.offset_address = 0x08000000 upload_protocol = stlink +debug_tool = stlink lib_deps = ${env.lib_deps} - charlesbaynham/OSFS@^1.2.3 - jgromes/RadioLib@7.0.2 - https://github.com/caveman99/Crypto.git#f61ae26a53f7a2d0ba5511625b8bf8eff3a35d5e + ${radiolib_base.lib_deps} + https://github.com/caveman99/Crypto/archive/eae9c768054118a9399690f8af202853d1ae8516.zip lib_ignore = mathertel/OneButton@2.6.1 - Wire \ No newline at end of file + Wire diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index da4c192c7..722f80fae 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -6,6 +6,12 @@ ### Including the "Module:" line! --- Lora: + # Default to auto-detecting the module type + # This will be overridden by configs from config.d + Module: auto + +# # Uncomment to enable Simulation mode, or use --sim +# Module: sim # Module: sx1262 # Waveshare SX1302 LISTEN ONLY AT THIS TIME! # CS: 7 diff --git a/bin/config.d/lora-Adafruit-RFM9x b/bin/config.d/lora-Adafruit-RFM9x deleted file mode 100644 index 2d64f1f91..000000000 --- a/bin/config.d/lora-Adafruit-RFM9x +++ /dev/null @@ -1,5 +0,0 @@ -# Module: RF95 # Adafruit RFM9x -# Reset: 25 -# CS: 7 -# IRQ: 22 -# Busy: 23 \ No newline at end of file diff --git a/bin/config.d/lora-Adafruit-RFM9x.yaml b/bin/config.d/lora-Adafruit-RFM9x.yaml new file mode 100644 index 000000000..20295dc72 --- /dev/null +++ b/bin/config.d/lora-Adafruit-RFM9x.yaml @@ -0,0 +1,6 @@ +Lora: + Module: RF95 # Adafruit RFM9x + Reset: 25 + CS: 7 + IRQ: 22 +# Busy: 23 diff --git a/bin/config.d/lora-raxda-rock2f-starter-edition-hat.yaml b/bin/config.d/lora-raxda-rock2f-starter-edition-hat.yaml new file mode 100644 index 000000000..ea86a3728 --- /dev/null +++ b/bin/config.d/lora-raxda-rock2f-starter-edition-hat.yaml @@ -0,0 +1,49 @@ +Lora: + +### Raxda Rock 2F running Armbian Linux 6.1.99-vendor-rk35xx +### https://github.com/markbirss/rock-2f +### https://github.com/markbirss/lora-starter-edition-sx1262-i2c +### https://github.com/radxa-pkg/radxa-overlays/blob/main/arch/arm64/boot/dts/rockchip/overlays/rk3528-spi0-cs1-spidev.dts +### Require install of https://github.com/radxa-pkg/radxa-overlays and rk3528-spi0-cs1-spidev.dtbo copied to /boot/dtb/rockchip/overlay and enabled +### in /boot/armbianEnv.txt - overlays=rk3528-spi0-cs1-spidev +### The Radxa Rock 2F employs multiple gpio chips. +### Each gpio pin must be unique, but can be assigned to a specific gpio chip and line. +### In case solely a no. is given, the default gpio chip and pin == line will be employed. +### + Module: sx1262 # Radxa Rock 2F + Starter Edition SX1262 HAT by Mark Birss + DIO2_AS_RF_SWITCH: true + DIO3_TCXO_VOLTAGE: 1.8 + spidev: spidev0.1 + CS: # NSS PIN_24 -> chip 4, line 14 + pin: 24 + gpiochip: 4 + line: 14 + SCK: # SCK PIN_23 -> chip 4, line 12 + pin: 23 + gpiochip: 4 + line: 12 + Busy: # BUSY PIN_7 -> chip 4, line 6 + pin: 7 + gpiochip: 4 + line: 6 + MOSI: # MOSI PIN_19 -> chip 4, line 10 + pin: 19 + gpiochip: 4 + line: 10 + MISO: # MISO PIN_21 -> chip 4, line 11 + pin: 21 + gpiochip: 4 + line: 11 + Reset: # NRST PIN_12 -> chip 1, line 13 + pin: 12 + gpiochip: 1 + line: 13 + IRQ: # DIO1 PIN_15 -> chip 4, line 22 + pin: 15 + gpiochip: 4 + line: 22 +# RXen: # RXEN PIN_22 -> chip 3!, line 17 +# pin: 22 +# gpiochip: 3 +# line: 17 +# TXen: RADIOLIB_NC # TXEN no PIN, no line, fallback to default gpio chip diff --git a/bin/config.d/lora-usb-meshtoad-e22.yaml b/bin/config.d/lora-usb-meshtoad-e22.yaml new file mode 100644 index 000000000..b6cb61c6b --- /dev/null +++ b/bin/config.d/lora-usb-meshtoad-e22.yaml @@ -0,0 +1,17 @@ +Lora: + Module: sx1262 + CS: 0 + IRQ: 6 + Reset: 2 + Busy: 4 + RXen: 1 + DIO2_AS_RF_SWITCH: true + DIO3_TCXO_VOLTAGE: true + spidev: ch341 + USB_PID: 0x5512 + USB_VID: 0x1A86 + # Optional: Reduce power to 10 dBm to + # avoid over-drawing the USB port + # SX126X_MAX_POWER: 10 + # Optional: Set the serial number for multi-radio support + # USB_Serialnum: 13374201 diff --git a/bin/device-install.bat b/bin/device-install.bat index c18be89a8..594d973f5 100755 --- a/bin/device-install.bat +++ b/bin/device-install.bat @@ -1,72 +1,295 @@ @ECHO OFF +SETLOCAL EnableDelayedExpansion +TITLE Meshtastic device-install -set PYTHON=python -set WEB_APP=0 +SET "SCRIPT_NAME=%~nx0" +SET "DEBUG=0" +SET "PYTHON=" +SET "WEB_APP=0" +SET "TFT_BUILD=0" +SET "BIGDB8=0" +SET "BIGDB16=0" +SET "ESPTOOL_BAUD=115200" +SET "ESPTOOL_CMD=" +SET "LOGCOUNTER=0" -:: Determine the correct esptool command to use -where esptool >nul 2>&1 -if %ERRORLEVEL% EQU 0 ( - set "ESPTOOL_CMD=esptool" -) else ( - set "ESPTOOL_CMD=%PYTHON% -m esptool" -) +@REM FIXME: Determine mcu from PlatformIO variant, this is unmaintainable. +SET "S3=s3 v3 t-deck wireless-paper wireless-tracker station-g2 unphone" +SET "C3=esp32c3" +@REM FIXME: Determine flash size from PlatformIO variant, this is unmaintainable. +SET "BIGDB_8MB=picomputer-s3 unphone seeed-sensecap-indicator crowpanel-esp32s3 heltec_capsule_sensor_v3 heltec-v3 heltec-vision-master-e213 heltec-vision-master-e290 heltec-vision-master-t190 heltec-wireless-paper heltec-wireless-tracker heltec-wsl-v3 icarus seeed-xiao-s3 tbeam-s3-core t-watch-s3 tracksenger" +SET "BIGDB_16MB=t-deck mesh-tab t-energy-s3 dreamcatcher ESP32-S3-Pico m5stack-cores3 station-g2 t-eth-elite" -goto GETOPTS -:HELP -echo Usage: %~nx0 [-h] [-p ESPTOOL_PORT] [-P PYTHON] [-f FILENAME^|FILENAME] [--web] -echo Flash image file to device, but first erasing and writing system information -echo. -echo -h Display this help and exit -echo -p ESPTOOL_PORT Set the environment variable for ESPTOOL_PORT. If not set, ESPTOOL iterates all ports (Dangerrous). -echo -P PYTHON Specify alternate python interpreter to use to invoke esptool. (Default: %PYTHON%) -echo -f FILENAME The .bin file to flash. Custom to your device type and region. -echo --web Flash WEB APP. -goto EOF +GOTO getopts +:help +ECHO Flash image file to device, but first erasing and writing system information. +ECHO. +ECHO Usage: %SCRIPT_NAME% -f filename [-p PORT] [-P python] (--web) +ECHO. +ECHO Options: +ECHO -f filename The firmware .bin file to flash. Custom to your device type and region. (required) +ECHO The file must be located in this current directory. +ECHO -p PORT Set the environment variable for ESPTOOL_PORT. +ECHO If not set, ESPTOOL iterates all ports (Dangerous). +ECHO -P python Specify alternate python interpreter to use to invoke esptool. (default: python) +ECHO If supplied the script will use python. +ECHO If not supplied the script will try to find esptool in Path. +ECHO --web Enable WebUI. (default: false) +ECHO. +ECHO Example: %SCRIPT_NAME% -f firmware-t-deck-tft-2.6.0.0b106d4.bin -p COM11 +ECHO Example: %SCRIPT_NAME% -f firmware-unphone-2.6.0.0b106d4.bin -p COM11 --web +GOTO eof -:GETOPTS -if /I "%1"=="-h" goto HELP -if /I "%1"=="--help" goto HELP -if /I "%1"=="-F" set "FILENAME=%2" & SHIFT -if /I "%1"=="-p" set ESPTOOL_PORT=%2 & SHIFT -if /I "%1"=="-P" set PYTHON=%2 & SHIFT -if /I "%1"=="--web" set WEB_APP=1 & SHIFT +:version +ECHO %SCRIPT_NAME% [Version 2.6.1] +ECHO Meshtastic +GOTO eof + +:getopts +IF "%~1"=="" GOTO endopts +IF /I "%~1"=="-?" GOTO help +IF /I "%~1"=="-h" GOTO help +IF /I "%~1"=="--help" GOTO help +IF /I "%~1"=="-v" GOTO version +IF /I "%~1"=="--version" GOTO version +IF /I "%~1"=="--debug" SET "DEBUG=1" & CALL :LOG_MESSAGE DEBUG "DEBUG mode: enabled." +IF /I "%~1"=="-f" SET "FILENAME=%~2" & SHIFT +IF "%~1"=="-p" SET "ESPTOOL_PORT=%~2" & SHIFT +IF /I "%~1"=="--port" SET "ESPTOOL_PORT=%~2" & SHIFT +IF "%~1"=="-P" SET "PYTHON=%~2" & SHIFT +IF /I "%~1"=="--web" SET "WEB_APP=1" SHIFT -IF NOT "__%1__"=="____" goto GETOPTS +GOTO getopts +:endopts -IF "__%FILENAME%__" == "____" ( - echo "Missing FILENAME" - goto HELP -) -IF EXIST %FILENAME% IF x%FILENAME:update=%==x%FILENAME% ( - echo Trying to flash update %FILENAME%, but first erasing and writing system information" - %ESPTOOL_CMD% --baud 115200 erase_flash - %ESPTOOL_CMD% --baud 115200 write_flash 0x00 %FILENAME% - - @REM Account for S3 and C3 board's different OTA partition - IF x%FILENAME:s3=%==x%FILENAME% IF x%FILENAME:v3=%==x%FILENAME% IF x%FILENAME:t-deck=%==x%FILENAME% IF x%FILENAME:wireless-paper=%==x%FILENAME% IF x%FILENAME:wireless-tracker=%==x%FILENAME% IF x%FILENAME:station-g2=%==x%FILENAME% IF x%FILENAME:unphone=%==x%FILENAME% ( - IF x%FILENAME:esp32c3=%==x%FILENAME% ( - %ESPTOOL_CMD% --baud 115200 write_flash 0x260000 bleota.bin - ) else ( - %ESPTOOL_CMD% --baud 115200 write_flash 0x260000 bleota-c3.bin - ) - ) else ( - %ESPTOOL_CMD% --baud 115200 write_flash 0x260000 bleota-s3.bin +CALL :LOG_MESSAGE DEBUG "Checking FILENAME parameter..." +IF "__!FILENAME!__"=="____" ( + CALL :LOG_MESSAGE DEBUG "Missing -f filename input." + GOTO help +) ELSE ( + CALL :LOG_MESSAGE DEBUG "Filename: !FILENAME!" + IF NOT "__!FILENAME: =!__"=="__!FILENAME!__" ( + CALL :LOG_MESSAGE ERROR "Filename containing spaces are not supported." + GOTO help ) - IF %WEB_APP%==1 ( - for %%f in (littlefswebui-*.bin) do ( - %ESPTOOL_CMD% --baud 115200 write_flash 0x300000 %%f - ) - ) else ( - for %%f in (littlefs-*.bin) do ( - %ESPTOOL_CMD% --baud 115200 write_flash 0x300000 %%f - ) + IF "__!FILENAME:firmware-=!__"=="__!FILENAME!__" ( + CALL :LOG_MESSAGE ERROR "Filename must be a firmware-* file." + GOTO help ) -) else ( - echo "Invalid file: %FILENAME%" - goto HELP -) else ( - echo "Invalid file: %FILENAME%" - goto HELP + @REM Remove ".\" or "./" file prefix if present. + SET "FILENAME=!FILENAME:.\=!" + SET "FILENAME=!FILENAME:./=!" ) -:EOF +CALL :LOG_MESSAGE DEBUG "Checking if !FILENAME! exists..." +IF NOT EXIST !FILENAME! ( + CALL :LOG_MESSAGE ERROR "File does not exist: !FILENAME!. Terminating." + GOTO eof +) + +IF NOT "!FILENAME:update=!"=="!FILENAME!" ( + CALL :LOG_MESSAGE DEBUG "We are working with a *update* file. !FILENAME!" + CALL :LOG_MESSAGE INFO "Use script device-update.bat to flash update !FILENAME!." + GOTO eof +) ELSE ( + CALL :LOG_MESSAGE DEBUG "We are NOT working with a *update* file. !FILENAME!" +) + +CALL :LOG_MESSAGE DEBUG "Determine the correct esptool command to use..." +IF NOT "__%PYTHON%__"=="____" ( + SET "ESPTOOL_CMD=!PYTHON! -m esptool" + CALL :LOG_MESSAGE DEBUG "Python interpreter supplied." +) ELSE ( + CALL :LOG_MESSAGE DEBUG "Python interpreter NOT supplied. Looking for esptool... + WHERE esptool >nul 2>&1 + IF %ERRORLEVEL% EQU 0 ( + @REM WHERE exits with code 0 if esptool is found. + SET "ESPTOOL_CMD=esptool" + ) ELSE ( + SET "ESPTOOL_CMD=python -m esptool" + CALL :RESET_ERROR + ) +) + +CALL :LOG_MESSAGE DEBUG "Checking esptool command !ESPTOOL_CMD!..." +!ESPTOOL_CMD! >nul 2>&1 +IF %ERRORLEVEL% GEQ 2 ( + @REM esptool exits with code 1 if help is displayed. + CALL :LOG_MESSAGE ERROR "esptool not found: !ESPTOOL_CMD!" + EXIT /B 1 + GOTO eof +) +IF %DEBUG% EQU 1 ( + CALL :LOG_MESSAGE DEBUG "Skipping ESPTOOL_CMD steps." + SET "ESPTOOL_CMD=REM !ESPTOOL_CMD!" +) + +CALL :LOG_MESSAGE DEBUG "Using esptool command: !ESPTOOL_CMD!" +IF "__!ESPTOOL_PORT!__" == "____" ( + CALL :LOG_MESSAGE WARN "Using esptool port: UNSET." +) ELSE ( + SET "ESPTOOL_CMD=!ESPTOOL_CMD! --port !ESPTOOL_PORT!" + CALL :LOG_MESSAGE INFO "Using esptool port: !ESPTOOL_PORT!." +) +CALL :LOG_MESSAGE INFO "Using esptool baud: !ESPTOOL_BAUD!." + +@REM Check if FILENAME contains "-tft-" and set target partitionScheme accordingly. +@REM https://github.com/meshtastic/web-flasher/blob/main/types/resources.ts#L3 +IF NOT "!FILENAME:-tft-=!"=="!FILENAME!" ( + CALL :LOG_MESSAGE DEBUG "We are working with a *-tft-* file. !FILENAME!" + IF %WEB_APP% EQU 1 ( + CALL :LOG_MESSAGE ERROR "Cannot enable WebUI (--web) and MUI." & GOTO eof + ) + SET "TFT_BUILD=1" +) ELSE ( + CALL :LOG_MESSAGE DEBUG "We are NOT working with a *-tft-* file. !FILENAME!" +) + +FOR %%a IN (%BIGDB_8MB%) DO ( + IF NOT "!FILENAME:%%a=!"=="!FILENAME!" ( + @REM We are working with any of %BIGDB_8MB%. + SET "BIGDB8=1" + GOTO end_loop_bigdb_8mb + ) +) +:end_loop_bigdb_8mb + +FOR %%a IN (%BIGDB_16MB%) DO ( + IF NOT "!FILENAME:%%a=!"=="!FILENAME!" ( + @REM We are working with any of %BIGDB_16MB%. + SET "BIGDB16=1" + GOTO end_loop_bigdb_16mb + ) +) +:end_loop_bigdb_16mb + +IF %BIGDB8% EQU 1 CALL :LOG_MESSAGE INFO "BigDB 8mb partition selected." +IF %BIGDB16% EQU 1 CALL :LOG_MESSAGE INFO "BigDB 16mb partition selected." + +@REM Extract BASENAME from %FILENAME% for later use. +SET "BASENAME=!FILENAME:firmware-=!" +CALL :LOG_MESSAGE DEBUG "Computed firmware basename: !BASENAME!" + +@REM Account for S3 and C3 board's different OTA partition. +FOR %%a IN (%S3%) DO ( + IF NOT "!FILENAME:%%a=!"=="!FILENAME!" ( + @REM We are working with any of %S3%. + SET "OTA_FILENAME=bleota-s3.bin" + GOTO :end_loop_s3 + ) +) + +FOR %%a IN (%C3%) DO ( + IF NOT "!FILENAME:%%a=!"=="!FILENAME!" ( + @REM We are working with any of %C3%. + SET "OTA_FILENAME=bleota-c3.bin" + GOTO :end_loop_c3 + ) +) + +@REM Everything else +SET "OTA_FILENAME=bleota.bin" +:end_loop_s3 +:end_loop_c3 +CALL :LOG_MESSAGE DEBUG "Set OTA_FILENAME to: !OTA_FILENAME!" + +@REM Check if (--web) is enabled and prefix BASENAME with "littlefswebui-" else "littlefs-". +IF %WEB_APP% EQU 1 ( + CALL :LOG_MESSAGE INFO "WebUI selected." + SET "SPIFFS_FILENAME=littlefswebui-%BASENAME%" +) ELSE ( + SET "SPIFFS_FILENAME=littlefs-%BASENAME%" +) +CALL :LOG_MESSAGE DEBUG "Set SPIFFS_FILENAME to: !SPIFFS_FILENAME!" + +@REM Default offsets. +@REM https://github.com/meshtastic/web-flasher/blob/main/stores/firmwareStore.ts#L202 +SET "OTA_OFFSET=0x260000" +SET "SPIFFS_OFFSET=0x300000" + +@REM Offsets for BigDB 8mb. +IF %BIGDB8% EQU 1 ( + SET "OTA_OFFSET=0x340000" + SET "SPIFFS_OFFSET=0x670000" +) + +@REM Offsets for BigDB 16mb. +IF %BIGDB16% EQU 1 ( + SET "OTA_OFFSET=0x650000" + SET "SPIFFS_OFFSET=0xc90000" +) + +CALL :LOG_MESSAGE DEBUG "Set OTA_OFFSET to: !OTA_OFFSET!" +CALL :LOG_MESSAGE DEBUG "Set SPIFFS_OFFSET to: !SPIFFS_OFFSET!" + +@REM Ensure target files exist before flashing operations. +IF NOT EXIST !FILENAME! CALL :LOG_MESSAGE ERROR "File does not exist: "!FILENAME!". Terminating." & EXIT /B 2 & GOTO eof +IF NOT EXIST !OTA_FILENAME! CALL :LOG_MESSAGE ERROR "File does not exist: "!OTA_FILENAME!". Terminating." & EXIT /B 2 & GOTO eof +IF NOT EXIST !SPIFFS_FILENAME! CALL :LOG_MESSAGE ERROR "File does not exist: "!SPIFFS_FILENAME!". Terminating." & EXIT /B 2 & GOTO eof + +@REM Flashing operations. +CALL :LOG_MESSAGE INFO "Trying to flash "!FILENAME!", but first erasing and writing system information..." +CALL :RUN_ESPTOOL !ESPTOOL_BAUD! erase_flash || GOTO eof +CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write_flash 0x00 "!FILENAME!" || GOTO eof + +CALL :LOG_MESSAGE INFO "Trying to flash BLEOTA "!OTA_FILENAME!" at OTA_OFFSET !OTA_OFFSET!..." +CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write_flash !OTA_OFFSET! "!OTA_FILENAME!" || GOTO eof + +CALL :LOG_MESSAGE INFO "Trying to flash SPIFFS "!SPIFFS_FILENAME!" at SPIFFS_OFFSET !SPIFFS_OFFSET!..." +CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write_flash !SPIFFS_OFFSET! "!SPIFFS_FILENAME!" || GOTO eof + +CALL :LOG_MESSAGE INFO "Script complete!." + +:eof +ENDLOCAL +EXIT /B %ERRORLEVEL% + + +:RUN_ESPTOOL +@REM Subroutine used to run ESPTOOL_CMD with arguments. +@REM Also handles %ERRORLEVEL%. +@REM CALL :RUN_ESPTOOL [Baud] [erase_flash|write_flash] [OFFSET] [Filename] +@REM. +@REM Example:: CALL :RUN_ESPTOOL 115200 write_flash 0x10000 "firmwarefile.bin" +IF %DEBUG% EQU 1 CALL :LOG_MESSAGE DEBUG "About to run command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4" +CALL :RESET_ERROR +!ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4 +IF %ERRORLEVEL% NEQ 0 ( + CALL :LOG_MESSAGE ERROR "Error running command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4" + EXIT /B %ERRORLEVEL% +) +GOTO :eof + +:LOG_MESSAGE +@REM Subroutine used to print log messages in four different levels. +@REM DEBUG messages only get printed if [-d] flag is passed to script. +@REM CALL :LOG_MESSAGE [ERROR|INFO|WARN|DEBUG] "Message" +@REM. +@REM Example:: CALL :LOG_MESSAGE INFO "Message." +SET /A LOGCOUNTER=LOGCOUNTER+1 +IF "%1" == "ERROR" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2 +IF "%1" == "INFO" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2 +IF "%1" == "WARN" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2 +IF "%1" == "DEBUG" IF %DEBUG% EQU 1 CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2 +GOTO :eof + +:GET_TIMESTAMP +@REM Subroutine used to set !TIMESTAMP! to HH:MM:ss. +@REM CALL :GET_TIMESTAMP +@REM. +@REM Updates: !TIMESTAMP! +FOR /F "tokens=1,2,3 delims=:,." %%a IN ("%TIME%") DO ( + SET "HH=%%a" + SET "MM=%%b" + SET "ss=%%c" +) +SET "TIMESTAMP=!HH!:!MM!:!ss!" +GOTO :eof + +:RESET_ERROR +@REM Subroutine to reset %ERRORLEVEL% to 0. +@REM CALL :RESET_ERROR +@REM. +@REM Updates: %ERRORLEVEL% +EXIT /B 0 +GOTO :eof diff --git a/bin/device-install.sh b/bin/device-install.sh index 4698b88e5..bacf48f69 100755 --- a/bin/device-install.sh +++ b/bin/device-install.sh @@ -1,18 +1,60 @@ -#!/bin/sh +#!/bin/bash PYTHON=${PYTHON:-$(which python3 python | head -n 1)} WEB_APP=false +TFT_BUILD=false +MCU="" + +# Variant groups +BIGDB_8MB=( + "picomputer-s3" + "unphone" + "seeed-sensecap-indicator" + "crowpanel-esp32s3" + "heltec_capsule_sensor_v3" + "heltec-v3" + "heltec-vision-master-e213" + "heltec-vision-master-e290" + "heltec-vision-master-t190" + "heltec-wireless-paper" + "heltec-wireless-tracker" + "heltec-wsl-v3" + "icarus" + "seeed-xiao-s3" + "tbeam-s3-core" + "t-watch-s3" + "tracksenger" +) +BIGDB_16MB=( + "t-deck" + "mesh-tab" + "t-energy-s3" + "dreamcatcher" + "ESP32-S3-Pico" + "m5stack-cores3" + "station-g2" + "t-eth-elite" +) +S3_VARIANTS=( + "s3" + "-v3" + "t-deck" + "wireless-paper" + "wireless-tracker" + "station-g2" + "unphone" +) # Determine the correct esptool command to use if "$PYTHON" -m esptool version >/dev/null 2>&1; then - ESPTOOL_CMD="$PYTHON -m esptool" + ESPTOOL_CMD="$PYTHON -m esptool" elif command -v esptool >/dev/null 2>&1; then - ESPTOOL_CMD="esptool" + ESPTOOL_CMD="esptool" elif command -v esptool.py >/dev/null 2>&1; then - ESPTOOL_CMD="esptool.py" + ESPTOOL_CMD="esptool.py" else - echo "Error: esptool not found" - exit 1 + echo "Error: esptool not found" + exit 1 fi set -e @@ -20,75 +62,141 @@ set -e # Usage info show_help() { cat <&2 + echo "Unknown argument: $1" >&2 exit 1 ;; esac + shift # Move to the next argument done -shift "$((OPTIND - 1))" [ -z "$FILENAME" -a -n "$1" ] && { FILENAME=$1 shift } +if [[ $FILENAME != firmware-* ]]; then + echo "Filename must be a firmware-* file." + exit 1 +fi + +# Check if FILENAME contains "-tft-" and prevent web/mui comingling. +if [[ ${FILENAME//-tft-/} != "$FILENAME" ]]; then + TFT_BUILD=true + if [[ $WEB_APP == true ]] && [[ $TFT_BUILD == true ]]; then + echo "Cannot enable WebUI (--web) and MUI." + exit 1 + fi +fi + +# Extract BASENAME from %FILENAME% for later use. +BASENAME="${FILENAME/firmware-/}" + if [ -f "${FILENAME}" ] && [ -n "${FILENAME##*"update"*}" ]; then + # Default littlefs* offset (--web). + OFFSET=0x300000 + + # Default OTA Offset + OTA_OFFSET=0x260000 + + # littlefs* offset for BigDB 8mb and OTA OFFSET. + for variant in "${BIGDB_8MB[@]}"; do + if [ -n "${FILENAME##*"$variant"*}" ]; then + OFFSET=0x670000 + OTA_OFFSET=0x340000 + fi + done + + # littlefs* offset for BigDB 16mb and OTA OFFSET. + for variant in "${BIGDB_16MB[@]}"; do + if [ -n "${FILENAME##*"$variant"*}" ]; then + OFFSET=0xc90000 + OTA_OFFSET=0x650000 + fi + done + + # Account for S3 board's different OTA partition + # FIXME: Use PlatformIO info to determine MCU type, this is unmaintainable + for variant in "${S3_VARIANTS[@]}"; do + if [ -n "${FILENAME##*"$variant"*}" ]; then + MCU="esp32s3" + fi + done + + if [ "$MCU" != "esp32s3" ]; then + if [ -n "${FILENAME##*"esp32c3"*}" ]; then + OTAFILE=bleota.bin + else + OTAFILE=bleota-c3.bin + fi + else + OTAFILE=bleota-s3.bin + fi + + # Check if WEB_APP (--web) is enabled and add "littlefswebui-" to BASENAME else "littlefs-". + if [ "$WEB_APP" = true ]; then + SPIFFSFILE=littlefswebui-${BASENAME} + else + SPIFFSFILE=littlefs-${BASENAME} + fi + + if [[ ! -f $FILENAME ]]; then + echo "Error: file ${FILENAME} wasn't found. Terminating." + exit 1 + fi + if [[ ! -f $OTAFILE ]]; then + echo "Error: file ${OTAFILE} wasn't found. Terminating." + exit 1 + fi + if [[ ! -f $SPIFFSFILE ]]; then + echo "Error: file ${SPIFFSFILE} wasn't found. Terminating." + exit 1 + fi + echo "Trying to flash ${FILENAME}, but first erasing and writing system information" $ESPTOOL_CMD erase_flash $ESPTOOL_CMD write_flash 0x00 "${FILENAME}" - # Account for S3 board's different OTA partition - if [ -n "${FILENAME##*"s3"*}" ] && [ -n "${FILENAME##*"-v3"*}" ] && [ -n "${FILENAME##*"t-deck"*}" ] && [ -n "${FILENAME##*"wireless-paper"*}" ] && [ -n "${FILENAME##*"wireless-tracker"*}" ] && [ -n "${FILENAME##*"station-g2"*}" ] && [ -n "${FILENAME##*"unphone"*}" ]; then - if [ -n "${FILENAME##*"esp32c3"*}" ]; then - $ESPTOOL_CMD write_flash 0x260000 bleota.bin - else - $ESPTOOL_CMD write_flash 0x260000 bleota-c3.bin - fi - else - $ESPTOOL_CMD write_flash 0x260000 bleota-s3.bin - fi - if [ "$WEB_APP" = true ]; then - $ESPTOOL_CMD write_flash 0x300000 littlefswebui-*.bin - else - $ESPTOOL_CMD write_flash 0x300000 littlefs-*.bin - fi + echo "Trying to flash ${OTAFILE} at offset ${OTA_OFFSET}" + $ESPTOOL_CMD write_flash $OTA_OFFSET "${OTAFILE}" + echo "Trying to flash ${SPIFFSFILE}, at offset ${OFFSET}" + $ESPTOOL_CMD write_flash $OFFSET "${SPIFFSFILE}" else show_help diff --git a/bin/device-install_test.ps1 b/bin/device-install_test.ps1 new file mode 100644 index 000000000..ae4a61cb7 --- /dev/null +++ b/bin/device-install_test.ps1 @@ -0,0 +1,112 @@ +<# + .SYNOPSIS + Unit-test for .\device-install.bat. + + .DESCRIPTION + This script performs a positive unit-test on .\device-install.bat by creating the expected .bin + files for a device followed by running the .bat script without flashing the firmware (--debug). + If any errors are hit they are presented in the standard output. Investigate accordingly. + + This script needs to be placed in the same directory as .\device-install.bat. + + .EXAMPLE + .\device-install_test.ps1 + + .EXAMPLE + .\device-install_test.ps1 -Verbose + + .LINK + .\device-install.bat --help +#> + +[CmdletBinding()] +param() + +function New-EmptyFile() { + [CmdletBinding()] + param ( + [Parameter(Position = 0, Mandatory = $true)] + # Specifies the file name. + [string]$FileName, + [Parameter(Position = 1)] + # Specifies the target path. (Get-Location).Path is the default. + [string]$Directory = (Get-Location).Path + ) + + $filePath = Join-Path -Path $Directory -ChildPath $FileName + + Write-Verbose -Message "Create empty test file if it doesn't exist: $($FileName)" + New-Item -Path "$filePath" -ItemType File -ErrorAction SilentlyContinue | Out-Null +} + +function Remove-EmptyFile() { + [CmdletBinding()] + param ( + [Parameter(Position = 0, Mandatory = $true)] + # Specifies the file name. + [string]$FileName, + [Parameter(Position = 1)] + # Specifies the target path. (Get-Location).Path is the default. + [string]$Directory = (Get-Location).Path + ) + + $filePath = Join-Path -Path $Directory -ChildPath $FileName + + Write-Verbose -Message "Deleted empty test file: $($FileName)" + Remove-Item -Path "$filePath" | Out-Null +} + + +$TestCases = New-Object -TypeName PSObject -Property @{ + # Use this PSObject to define testcases according to this syntax: + # "testname" = @("firmware-testname","bleota","littlefs-testname","args") + "t-deck" = @("firmware-t-deck-2.6.0.0b106d4.bin", "bleota-s3.bin", "littlefs-t-deck-2.6.0.0b106d4.bin", "") + "t-deck_web" = @("firmware-t-deck-2.6.0.0b106d4.bin", "bleota-s3.bin", "littlefswebui-t-deck-2.6.0.0b106d4.bin", "--web") + "t-deck-tft" = @("firmware-t-deck-tft-2.6.0.0b106d4.bin", "bleota-s3.bin", "littlefs-t-deck-tft-2.6.0.0b106d4.bin", "") + "heltec-ht62-esp32c3" = @("firmware-heltec-ht62-esp32c3-sx1262-2.6.0.0b106d4.bin", "bleota-c3.bin", "littlefs-heltec-ht62-esp32c3-sx1262-2.6.0.0b106d4.bin", "") + "tlora-c6" = @("firmware-tlora-c6-2.6.0.0b106d4.bin", "bleota.bin", "littlefs-tlora-c6-2.6.0.0b106d4.bin", "") + "heltec-v3_web" = @("firmware-heltec-v3-2.6.0.0b106d4.bin", "bleota-s3.bin", "littlefswebui-heltec-v3-2.6.0.0b106d4.bin", "--web") + "seeed-sensecap-indicator-tft" = @("firmware-seeed-sensecap-indicator-tft-2.6.0.0b106d4.bin", "bleota.bin", "littlefs-seeed-sensecap-indicator-tft-2.6.0.0b106d4.bin", "") + "picomputer-s3-tft" = @("firmware-picomputer-s3-tft-2.6.0.0b106d4.bin", "bleota-s3.bin", "littlefs-picomputer-s3-tft-2.6.0.0b106d4.bin", "") +} + +foreach ($TestCase in $TestCases.PSObject.Properties) { + $Name = $TestCase.Name + $Files = $TestCase.Value + $Errors = $null + $Counter = 0 + + Write-Host -Object "Testcase: $Name`:" -ForegroundColor Green + foreach ($File in $Files) { + if ($File.EndsWith(".bin")) { + New-EmptyFile -FileName $File + } + } + + Write-Host -Object "Performing test on $Name..." -ForegroundColor Blue + $Test = Invoke-Expression -Command "cmd /c .\device-install.bat --debug -f $($TestCases."$Name"[0]) $($TestCases."$Name"[3])" + + foreach ($Line in $Test) { + if ($Line -match "Set OTA_OFFSET to" -or ` + $Line -match "Set SPIFFS_OFFSET to") { + Write-Host -Object "$($Line -replace "^.*?Set","Set")" -ForegroundColor Blue + } + elseif ($VerbosePreference -eq "Continue") { + Write-Host -Object $Line + } + if ($Line -match "ERROR") { + $Errors += $Line + $Counter++ + } + } + if ($null -ne $Errors) { + Write-Host -Object "$Counter ERROR(s) detected!" -ForegroundColor Red + if (-not ($VerbosePreference -eq "Continue")) { Write-Host -Object $Errors } + } + + foreach ($File in $Files) { + if ($File.EndsWith(".bin")) { + Remove-EmptyFile -FileName $File + } + } +} diff --git a/bin/device-update.bat b/bin/device-update.bat index a52f3d33f..d9a4bd19a 100755 --- a/bin/device-update.bat +++ b/bin/device-update.bat @@ -1,48 +1,176 @@ @ECHO OFF +SETLOCAL EnableDelayedExpansion +TITLE Meshtastic device-update -set PYTHON=python +SET "SCRIPT_NAME=%~nx0" +SET "DEBUG=0" +SET "PYTHON=" +SET "ESPTOOL_BAUD=115200" +SET "ESPTOOL_CMD=" +SET "LOGCOUNTER=0" -:: Determine the correct esptool command to use -where esptool >nul 2>&1 -if %ERRORLEVEL% EQU 0 ( - set "ESPTOOL_CMD=esptool" -) else ( - set "ESPTOOL_CMD=%PYTHON% -m esptool" -) +GOTO getopts +:help +ECHO Flash image file to device, but leave existing system intact. +ECHO. +ECHO Usage: %SCRIPT_NAME% -f filename [-p PORT] [-P python] +ECHO. +ECHO Options: +ECHO -f filename The update .bin file to flash. Custom to your device type and region. (required) +ECHO The file must be located in this current directory. +ECHO -p PORT Set the environment variable for ESPTOOL_PORT. +ECHO If not set, ESPTOOL iterates all ports (Dangerous). +ECHO -P python Specify alternate python interpreter to use to invoke esptool. (default: python) +ECHO If supplied the script will use python. +ECHO If not supplied the script will try to find esptool in Path. +ECHO. +ECHO Example: %SCRIPT_NAME% -f firmware-t-deck-tft-2.6.0.0b106d4-update.bin -p COM11 +GOTO eof -goto GETOPTS -:HELP -echo Usage: %~nx0 [-h] [-p ESPTOOL_PORT] [-P PYTHON] [-f FILENAME^|FILENAME] -echo Flash image file to device, leave existing system intact. -echo. -echo -h Display this help and exit -echo -p ESPTOOL_PORT Set the environment variable for ESPTOOL_PORT. If not set, ESPTOOL iterates all ports (Dangerrous). -echo -P PYTHON Specify alternate python interpreter to use to invoke esptool. (Default: %PYTHON%) -echo -f FILENAME The *update.bin file to flash. Custom to your device type. -goto EOF +:version +ECHO %SCRIPT_NAME% [Version 2.6.1] +ECHO Meshtastic +GOTO eof -:GETOPTS -if /I "%1"=="-h" goto HELP -if /I "%1"=="--help" goto HELP -if /I "%1"=="-F" set "FILENAME=%2" & SHIFT -if /I "%1"=="-p" set ESPTOOL_PORT=%2 & SHIFT -if /I "%1"=="-P" set PYTHON=%2 & SHIFT +:getopts +IF "%~1"=="" GOTO endopts +IF /I "%~1"=="-?" GOTO help +IF /I "%~1"=="-h" GOTO help +IF /I "%~1"=="--help" GOTO help +IF /I "%~1"=="-v" GOTO version +IF /I "%~1"=="--version" GOTO version +IF /I "%~1"=="--debug" SET "DEBUG=1" & CALL :LOG_MESSAGE DEBUG "DEBUG mode: enabled." +IF /I "%~1"=="-f" SET "FILENAME=%~2" & SHIFT +IF "%~1"=="-p" SET "ESPTOOL_PORT=%~2" & SHIFT +IF /I "%~1"=="--port" SET "ESPTOOL_PORT=%~2" & SHIFT +IF "%~1"=="-P" SET "PYTHON=%~2" & SHIFT SHIFT -IF NOT "__%1__"=="____" goto GETOPTS +GOTO getopts +:endopts -IF "__%FILENAME%__" == "____" ( - echo "Missing FILENAME" - goto HELP -) -IF EXIST %FILENAME% IF NOT x%FILENAME:update=%==x%FILENAME% ( - echo Trying to flash update %FILENAME% - %ESPTOOL_CMD% --baud 115200 write_flash 0x10000 %FILENAME% -) else ( - echo "Invalid file: %FILENAME%" - goto HELP -) else ( - echo "Invalid file: %FILENAME%" - goto HELP +CALL :LOG_MESSAGE DEBUG "Checking FILENAME parameter..." +IF "__!FILENAME!__"=="____" ( + CALL :LOG_MESSAGE DEBUG "Missing -f filename input." + GOTO help +) ELSE ( + CALL :LOG_MESSAGE DEBUG "Filename: !FILENAME!" + IF NOT "__!FILENAME: =!__"=="__!FILENAME!__" ( + CALL :LOG_MESSAGE ERROR "Filename containing spaces are not supported." + GOTO help + ) + @REM Remove ".\" or "./" file prefix if present. + SET "FILENAME=!FILENAME:.\=!" + SET "FILENAME=!FILENAME:./=!" ) -:EOF +CALL :LOG_MESSAGE DEBUG "Checking if !FILENAME! exists..." +IF NOT EXIST !FILENAME! ( + CALL :LOG_MESSAGE ERROR "File does not exist: !FILENAME!. Terminating." + GOTO eof +) + +IF "!FILENAME:update=!"=="!FILENAME!" ( + CALL :LOG_MESSAGE DEBUG "We are NOT working with a *update* file. !FILENAME!" + CALL :LOG_MESSAGE INFO "Use script device-install.bat to flash !FILENAME!." + GOTO eof +) ELSE ( + CALL :LOG_MESSAGE DEBUG "We are working with a *update* file. !FILENAME!" +) + +CALL :LOG_MESSAGE DEBUG "Determine the correct esptool command to use..." +IF NOT "__%PYTHON%__"=="____" ( + SET "ESPTOOL_CMD=!PYTHON! -m esptool" + CALL :LOG_MESSAGE DEBUG "Python interpreter supplied." +) ELSE ( + CALL :LOG_MESSAGE DEBUG "Python interpreter NOT supplied. Looking for esptool... + WHERE esptool >nul 2>&1 + IF %ERRORLEVEL% EQU 0 ( + @REM WHERE exits with code 0 if esptool is found. + SET "ESPTOOL_CMD=esptool" + ) ELSE ( + SET "ESPTOOL_CMD=python -m esptool" + CALL :RESET_ERROR + ) +) + +CALL :LOG_MESSAGE DEBUG "Checking esptool command !ESPTOOL_CMD!..." +!ESPTOOL_CMD! >nul 2>&1 +IF %ERRORLEVEL% GEQ 2 ( + @REM esptool exits with code 1 if help is displayed. + CALL :LOG_MESSAGE ERROR "esptool not found: !ESPTOOL_CMD!" + EXIT /B 1 + GOTO eof +) +IF %DEBUG% EQU 1 ( + CALL :LOG_MESSAGE DEBUG "Skipping ESPTOOL_CMD steps." + SET "ESPTOOL_CMD=REM !ESPTOOL_CMD!" +) + +CALL :LOG_MESSAGE DEBUG "Using esptool command: !ESPTOOL_CMD!" +IF "__!ESPTOOL_PORT!__" == "____" ( + CALL :LOG_MESSAGE WARN "Using esptool port: UNSET." +) ELSE ( + SET "ESPTOOL_CMD=!ESPTOOL_CMD! --port !ESPTOOL_PORT!" + CALL :LOG_MESSAGE INFO "Using esptool port: !ESPTOOL_PORT!." +) +CALL :LOG_MESSAGE INFO "Using esptool baud: !ESPTOOL_BAUD!." + +@REM Flashing operations. +CALL :LOG_MESSAGE INFO "Trying to flash update "!FILENAME!" at OFFSET 0x10000..." +CALL :RUN_ESPTOOL !ESPTOOL_BAUD! write_flash 0x10000 "!FILENAME!" || GOTO eof + +CALL :LOG_MESSAGE INFO "Script complete!." + +:eof +ENDLOCAL +EXIT /B %ERRORLEVEL% + + +:RUN_ESPTOOL +@REM Subroutine used to run ESPTOOL_CMD with arguments. +@REM Also handles %ERRORLEVEL%. +@REM CALL :RUN_ESPTOOL [Baud] [erase_flash|write_flash] [OFFSET] [Filename] +@REM. +@REM Example:: CALL :RUN_ESPTOOL 115200 write_flash 0x10000 "firmwarefile.bin" +IF %DEBUG% EQU 1 CALL :LOG_MESSAGE DEBUG "About to run command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4" +CALL :RESET_ERROR +!ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4 +IF %ERRORLEVEL% NEQ 0 ( + CALL :LOG_MESSAGE ERROR "Error running command: !ESPTOOL_CMD! --baud %~1 %~2 %~3 %~4" + EXIT /B %ERRORLEVEL% +) +GOTO :eof + +:LOG_MESSAGE +@REM Subroutine used to print log messages in four different levels. +@REM DEBUG messages only get printed if [-d] flag is passed to script. +@REM CALL :LOG_MESSAGE [ERROR|INFO|WARN|DEBUG] "Message" +@REM. +@REM Example:: CALL :LOG_MESSAGE INFO "Message." +SET /A LOGCOUNTER=LOGCOUNTER+1 +IF "%1" == "ERROR" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2 +IF "%1" == "INFO" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2 +IF "%1" == "WARN" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2 +IF "%1" == "DEBUG" IF %DEBUG% EQU 1 CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2 +GOTO :eof + +:GET_TIMESTAMP +@REM Subroutine used to set !TIMESTAMP! to HH:MM:ss. +@REM CALL :GET_TIMESTAMP +@REM. +@REM Updates: !TIMESTAMP! +FOR /F "tokens=1,2,3 delims=:,." %%a IN ("%TIME%") DO ( + SET "HH=%%a" + SET "MM=%%b" + SET "ss=%%c" +) +SET "TIMESTAMP=!HH!:!MM!:!ss!" +GOTO :eof + +:RESET_ERROR +@REM Subroutine to reset %ERRORLEVEL% to 0. +@REM CALL :RESET_ERROR +@REM. +@REM Updates: %ERRORLEVEL% +EXIT /B 0 +GOTO :eof diff --git a/bin/device-update.sh b/bin/device-update.sh index 67281dc4f..ae7b52ea2 100755 --- a/bin/device-update.sh +++ b/bin/device-update.sh @@ -35,8 +35,8 @@ while getopts ":hp:P:f:" opt; do show_help exit 0 ;; - p) export ESPTOOL_PORT=${OPTARG} - ;; + p) ESPTOOL_CMD="$ESPTOOL_CMD --port ${OPTARG}" + ;; P) PYTHON=${OPTARG} ;; f) FILENAME=${OPTARG} diff --git a/bin/platformio-custom.py b/bin/platformio-custom.py index 09e8e6d83..600f9447f 100644 --- a/bin/platformio-custom.py +++ b/bin/platformio-custom.py @@ -83,7 +83,7 @@ if platform.name == "espressif32": if platform.name == "nordicnrf52": env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex", - env.VerboseAction(f"{sys.executable} ./bin/uf2conv.py $BUILD_DIR/firmware.hex -c -f 0xADA52840 -o $BUILD_DIR/firmware.uf2", + env.VerboseAction(f"\"{sys.executable}\" ./bin/uf2conv.py $BUILD_DIR/firmware.hex -c -f 0xADA52840 -o $BUILD_DIR/firmware.uf2", "Generating UF2 file")) Import("projenv") @@ -125,4 +125,9 @@ for flag in flags: projenv.Append( CCFLAGS=flags, -) \ No newline at end of file +) + +for lb in env.GetLibBuilders(): + if lb.name == "meshtastic-device-ui": + lb.env.Append(CPPDEFINES=[("APP_VERSION", verObj["long"])]) + break diff --git a/bin/regen-protos.bat b/bin/regen-protos.bat index 7fa8f333d..0bbfbe38a 100644 --- a/bin/regen-protos.bat +++ b/bin/regen-protos.bat @@ -1 +1,10 @@ -cd protobufs && ..\nanopb-0.4.9\generator-bin\protoc.exe --experimental_allow_proto3_optional "--nanopb_out=-S.cpp -v:..\src\mesh\generated" -I=..\protobufs\ ..\protobufs\meshtastic\*.proto +@ECHO OFF +SETLOCAL + +cd protobufs +..\nanopb-0.4.9\generator-bin\protoc.exe --experimental_allow_proto3_optional "--nanopb_out=-S.cpp -v:..\src\mesh\generated" -I=..\protobufs\ ..\protobufs\meshtastic\*.proto +GOTO eof + +:eof +ENDLOCAL +EXIT /B %ERRORLEVEL% diff --git a/bin/uf2-convert.bat b/bin/uf2-convert.bat index 242bec3ab..5e36617e3 100644 --- a/bin/uf2-convert.bat +++ b/bin/uf2-convert.bat @@ -1,2 +1,124 @@ -@echo off -if [%1]==[] (echo "Please specify a platformio NRF target (i.e. rak4631) as the first argument.") else (python3 .\bin\uf2conv.py .\.pio\build\%1\firmware.hex -c -o .\.pio\build\%1\firmware.uf2 -f 0xADA52840) \ No newline at end of file +@ECHO OFF +SETLOCAL EnableDelayedExpansion +TITLE Meshtastic uf2-convert + +SET "SCRIPT_NAME=%~nx0" +SET "DEBUG=0" +SET "NRF=0" +SET "UF2CONV_CMD=python3 .\bin\uf2conv.py" + +GOTO getopts +:help +ECHO. +ECHO Usage: %SCRIPT_NAME% -t [t-echo^|rak4631^|nano-g2-ultra^|wio-tracker-wm1110^|canaryone^| +ECHO heltec-mesh-node-t114^|tracker-t1000-e^|rak_wismeshtap^|rak2560^| +ECHO nrf52_promicro_diy_tcxo] +ECHO. +ECHO Options: +ECHO -t target Specify a platformio NRF target to build for. (required) +ECHO. +ECHO Example: %SCRIPT_NAME% -t rak4631 +GOTO eof + +:version +ECHO %SCRIPT_NAME% [Version 2.6.0] +ECHO Meshtastic +GOTO eof + +:getopts +IF "%~1"=="" GOTO endopts +IF /I "%~1"=="-?" GOTO help +IF /I "%~1"=="-h" GOTO help +IF /I "%~1"=="--help" GOTO help +IF /I "%~1"=="-v" GOTO version +IF /I "%~1"=="--version" GOTO version +IF /I "%~1"=="--debug" SET "DEBUG=1" & CALL :LOG_MESSAGE DEBUG "DEBUG mode: enabled." +IF /I "%~1"=="-t" SET "TARGETNAME=%~2" & SHIFT +IF /I "%~1"=="--target" SET "TARGETNAME=%~2" & SHIFT +SHIFT +GOTO getopts +:endopts + +CALL :LOG_MESSAGE DEBUG "Checking TARGETNAME parameter..." +IF "__!TARGETNAME!__"=="____" ( + CALL :LOG_MESSAGE DEBUG "Missing -t target input." + GOTO help +) + +IF %DEBUG% EQU 1 SET "UF2CONV_CMD=REM python3 .\bin\uf2conv.py" + +SET "NRFTARGETS=t-echo rak4631 nano-g2-ultra wio-tracker-wm1110 canaryone heltec-mesh-node-t114 tracker-t1000-e rak_wismeshtap rak2560 nrf52_promicro_diy_tcxo" +FOR %%a IN (%NRFTARGETS%) DO ( + IF /I "%%a"=="!TARGETNAME!" ( + @REM We are working with any of %NRFTARGETS%. + SET "NRF=1" + GOTO end_loop_nrf + ) +) +:end_loop_nrf + +@REM Building operations. +IF !NRF! EQU 1 ( + CALL :LOG_MESSAGE INFO "Trying to build for !TARGETNAME!..." + CALL :RUN_UF2CONV !TARGETNAME! || GOTO eof +) ELSE ( + CALL :LOG_MESSAGE WARN "!TARGETNAME! is not supported..." + GOTO eof +) + +CALL :LOG_MESSAGE INFO "Script complete!." + + +:eof +ENDLOCAL +EXIT /B %ERRORLEVEL% + + +:RUN_UF2CONV +@REM Subroutine used to run .\bin\uf2conv.py with arguments. +@REM Also handles %ERRORLEVEL%. +@REM CALL :RUN_UF2CONV [target] +@REM. +@REM Example:: CALL :RUN_UF2CONV rak4631 +IF %DEBUG% EQU 1 CALL :LOG_MESSAGE DEBUG "About to run command: !UF2CONV_CMD! .\.pio\build\%~1\firmware.hex -c -o .\.pio\build\%~1\firmware.uf2 -f 0xADA52840" +CALL :RESET_ERROR +!UF2CONV_CMD! .\.pio\build\%~1\firmware.hex -c -o .\.pio\build\%~1\firmware.uf2 -f 0xADA52840 +IF %ERRORLEVEL% NEQ 0 ( + CALL :LOG_MESSAGE ERROR "Error running command: !UF2CONV_CMD! .\.pio\build\%~1\firmware.hex -c -o .\.pio\build\%~1\firmware.uf2 -f 0xADA52840" + EXIT /B %ERRORLEVEL% +) +GOTO :eof + +:LOG_MESSAGE +@REM Subroutine used to print log messages in four different levels. +@REM DEBUG messages only get printed if [-d] flag is passed to script. +@REM CALL :LOG_MESSAGE [ERROR|INFO|WARN|DEBUG] "Message" +@REM. +@REM Example:: CALL :LOG_MESSAGE INFO "Message." +SET /A LOGCOUNTER=LOGCOUNTER+1 +IF "%1" == "ERROR" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2 +IF "%1" == "INFO" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2 +IF "%1" == "WARN" CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2 +IF "%1" == "DEBUG" IF %DEBUG% EQU 1 CALL :GET_TIMESTAMP & ECHO %1 ^| !TIMESTAMP! !LOGCOUNTER! %~2 +GOTO :eof + +:GET_TIMESTAMP +@REM Subroutine used to set !TIMESTAMP! to HH:MM:ss. +@REM CALL :GET_TIMESTAMP +@REM. +@REM Updates: !TIMESTAMP! +FOR /F "tokens=1,2,3 delims=:,." %%a IN ("%TIME%") DO ( + SET "HH=%%a" + SET "MM=%%b" + SET "ss=%%c" +) +SET "TIMESTAMP=!HH!:!MM!:!ss!" +GOTO :eof + +:RESET_ERROR +@REM Subroutine to reset %ERRORLEVEL% to 0. +@REM CALL :RESET_ERROR +@REM. +@REM Updates: %ERRORLEVEL% +EXIT /B 0 +GOTO :eof diff --git a/boards/ThinkNode-M1.json b/boards/ThinkNode-M1.json new file mode 100644 index 000000000..e55da3ec7 --- /dev/null +++ b/boards/ThinkNode-M1.json @@ -0,0 +1,53 @@ +{ + "build": { + "arduino": { + "ldscript": "nrf52840_s140_v6.ld" + }, + "core": "nRF5", + "cpu": "cortex-m4", + "extra_flags": "-DARDUINO_NRF52840_TTGO_EINK -DNRF52840_XXAA", + "f_cpu": "64000000L", + "hwids": [ + ["0x239A", "0x4405"], + ["0x239A", "0x0029"], + ["0x239A", "0x002A"] + ], + "usb_product": "elecrow_eink", + "mcu": "nrf52840", + "variant": "ELECROW-ThinkNode-M1", + "variants_dir": "variants", + "bsp": { + "name": "adafruit" + }, + "softdevice": { + "sd_flags": "-DS140", + "sd_name": "s140", + "sd_version": "6.1.1", + "sd_fwid": "0x00B6" + }, + "bootloader": { + "settings_addr": "0xFF000" + } + }, + "connectivity": ["bluetooth"], + "debug": { + "jlink_device": "nRF52840_xxAA", + "onboard_tools": ["jlink"], + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" + }, + "frameworks": ["arduino"], + "name": "elecrow eink", + "upload": { + "maximum_ram_size": 248832, + "maximum_size": 815104, + "speed": 115200, + "protocol": "nrfutil", + "protocols": ["jlink", "nrfjprog", "nrfutil", "stlink"], + "use_1200bps_touch": true, + "require_upload_port": true, + "wait_for_upload_port": true + }, + "url": "FIXME", + "vendor": "ELECROW" +} diff --git a/boards/esp32-s3-pico.json b/boards/esp32-s3-pico.json index 8f8c6fdb7..c092bfb74 100644 --- a/boards/esp32-s3-pico.json +++ b/boards/esp32-s3-pico.json @@ -7,13 +7,15 @@ "core": "esp32", "extra_flags": [ "-DARDUINO_ESP32S3_DEV", - "-DARDUINO_USB_MODE=1", "-DARDUINO_RUNNING_CORE=1", - "-DARDUINO_EVENT_RUNNING_CORE=1" + "-DARDUINO_EVENT_RUNNING_CORE=1", + "-DARDUINO_USB_CDC_ON_BOOT=1", + "-DBOARD_HAS_PSRAM" ], "f_cpu": "240000000L", "f_flash": "80000000L", "flash_mode": "qio", + "psram_type": "qio", "hwids": [["0x303A", "0x1001"]], "mcu": "esp32s3", "variant": "esp32s3" diff --git a/boards/seeed_xiao_nrf52840_kit.json b/boards/seeed_xiao_nrf52840_kit.json new file mode 100644 index 000000000..4c5fdbeda --- /dev/null +++ b/boards/seeed_xiao_nrf52840_kit.json @@ -0,0 +1,56 @@ +{ + "build": { + "arduino": { + "ldscript": "nrf52840_s140_v7.ld" + }, + "core": "nRF5", + "cpu": "cortex-m4", + "extra_flags": "-DARDUINO_MDBT50Q_RX -DNRF52840_XXAA", + "f_cpu": "64000000L", + "hwids": [ + ["0x2886", "0x0166"] + ], + "usb_product": "XIAO-BOOT", + "mcu": "nrf52840", + "variant": "seeed_xiao_nrf52840_kit", + "bsp": { + "name": "adafruit" + }, + "softdevice": { + "sd_flags": "-DS140", + "sd_name": "s140", + "sd_version": "7.3.0", + "sd_fwid": "0x0123" + }, + "bootloader": { + "settings_addr": "0xFF000" + } + }, + "connectivity": ["bluetooth"], + "debug": { + "jlink_device": "nRF52840_xxAA", + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" + }, + "frameworks": ["arduino"], + "name": "seeed_xiao_nrf52840_kit", + "upload": { + "maximum_ram_size": 248832, + "maximum_size": 815104, + "speed": 115200, + "protocol": "nrfutil", + "protocols": [ + "jlink", + "nrfjprog", + "nrfutil", + "stlink", + "cmsis-dap", + "blackmagic" + ], + "use_1200bps_touch": true, + "require_upload_port": true, + "wait_for_upload_port": true + }, + "url": "https://www.seeedstudio.com/XIAO-nRF52840-Wio-SX1262-Kit-for-Meshtastic-p-6400.html", + "vendor": "seeed" +} diff --git a/boards/t-watch-s3.json b/boards/t-watch-s3.json index e6e363305..5d4afd322 100644 --- a/boards/t-watch-s3.json +++ b/boards/t-watch-s3.json @@ -23,7 +23,7 @@ "mcu": "esp32s3", "variant": "t-watch-s3" }, - "connectivity": ["wifi"], + "connectivity": ["wifi", "bluetooth"], "debug": { "openocd_target": "esp32s3.cfg" }, diff --git a/boards/wiscore_rak11300.json b/boards/wiscore_rak11300.json deleted file mode 100644 index 19beee74d..000000000 --- a/boards/wiscore_rak11300.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "build": { - "arduino": { - "earlephilhower": { - "boot2_source": "boot2_w25q080_2_padded_checksum.S", - "usb_vid": "0x2E8A", - "usb_pid": "0x000A" - } - }, - "core": "earlephilhower", - "cpu": "cortex-m0plus", - "extra_flags": "-DARDUINO_GENERIC_RP2040 -DRASPBERRY_PI_PICO -DARDUINO_ARCH_RP2040 -DUSBD_MAX_POWER_MA=250", - "f_cpu": "133000000L", - "hwids": [ - ["0x2E8A", "0x00C0"], - ["0x2E8A", "0x000A"] - ], - "mcu": "rp2040", - "variant": "WisBlock_RAK11300_Board" - }, - "debug": { - "jlink_device": "RP2040_M0_0", - "openocd_target": "rp2040.cfg", - "svd_path": "rp2040.svd" - }, - "frameworks": ["arduino"], - "name": "WisBlock RAK11300", - "upload": { - "maximum_ram_size": 270336, - "maximum_size": 2097152, - "require_upload_port": true, - "native_usb": true, - "use_1200bps_touch": true, - "wait_for_upload_port": false, - "protocol": "picotool", - "protocols": ["cmsis-dap", "raspberrypi-swd", "picotool", "picoprobe"] - }, - "url": "https://docs.rakwireless.com/", - "vendor": "RAKwireless" -} diff --git a/debian/control b/debian/control index b3a8eb58e..693cd6aa5 100644 --- a/debian/control +++ b/debian/control @@ -17,6 +17,7 @@ Build-Depends: debhelper-compat (= 13), libbluetooth-dev, libusb-1.0-0-dev, libi2c-dev, + libuv1-dev, openssl, libssl-dev, libulfius-dev, diff --git a/extra_scripts/extra_stm32.py b/extra_scripts/extra_stm32.py new file mode 100755 index 000000000..f3bd8c514 --- /dev/null +++ b/extra_scripts/extra_stm32.py @@ -0,0 +1,22 @@ +# trunk-ignore-all(ruff/F821) +# trunk-ignore-all(flake8/F821): For SConstruct imports + +Import("env") +# Custom HEX from ELF +env.AddPostAction( + "$BUILD_DIR/${PROGNAME}.elf", + env.VerboseAction( + " ".join( + [ + "$OBJCOPY", + "-O", + "ihex", + "-R", + ".eeprom", + "$BUILD_DIR/${PROGNAME}.elf", + "$BUILD_DIR/${PROGNAME}.hex", + ] + ), + "Building $BUILD_DIR/${PROGNAME}.hex", + ), +) diff --git a/lib/device-ui b/lib/device-ui deleted file mode 160000 index 5c6156d2a..000000000 --- a/lib/device-ui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5c6156d2aa10d62cca3e57ffc117b934ef2fbffe diff --git a/meshtasticd.spec.rpkg b/meshtasticd.spec.rpkg index 0a0f03557..a09261056 100644 --- a/meshtasticd.spec.rpkg +++ b/meshtasticd.spec.rpkg @@ -36,6 +36,7 @@ BuildRequires: pkgconfig(libgpiod) BuildRequires: pkgconfig(bluez) BuildRequires: pkgconfig(libusb-1.0) BuildRequires: libi2c-devel +BuildRequires: pkgconfig(libuv) # Web components: BuildRequires: pkgconfig(openssl) BuildRequires: pkgconfig(liborcania) diff --git a/platformio.ini b/platformio.ini index 1875c5324..f485b7aeb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -7,6 +7,8 @@ default_envs = tbeam extra_configs = arch/*/*.ini variants/*/platformio.ini + src/graphics/niche/InkHUD/PlatformioConfig.ini + description = Meshtastic [env] @@ -55,11 +57,11 @@ build_flags = -Wno-missing-field-initializers monitor_speed = 115200 monitor_filters = direct lib_deps = - https://github.com/meshtastic/esp8266-oled-ssd1306.git#e16cee124fe26490cb14880c679321ad8ac89c95 + https://github.com/meshtastic/esp8266-oled-ssd1306/archive/e16cee124fe26490cb14880c679321ad8ac89c95.zip mathertel/OneButton@2.6.1 - https://github.com/meshtastic/arduino-fsm.git#7db3702bf0cfe97b783d6c72595e3f38e0b19159 - https://github.com/meshtastic/TinyGPSPlus.git#71a82db35f3b973440044c476d4bcdc673b104f4 - https://github.com/meshtastic/ArduinoThread.git#1ae8778c85d0a2a729f989e0b1e7d7c4dc84eef0 + https://github.com/meshtastic/arduino-fsm/archive/7db3702bf0cfe97b783d6c72595e3f38e0b19159.zip + https://github.com/meshtastic/TinyGPSPlus/archive/71a82db35f3b973440044c476d4bcdc673b104f4.zip + https://github.com/meshtastic/ArduinoThread/archive/7c3ee9e1951551b949763b1f5280f8db1fa4068d.zip nanopb/Nanopb@0.4.91 erriez/ErriezCRC32@1.0.1 @@ -78,7 +80,7 @@ lib_deps = ${env.lib_deps} end2endzone/NonBlockingRTTTL@1.3.0 build_flags = ${env.build_flags} -Os -build_src_filter = ${env.build_src_filter} - +build_src_filter = ${env.build_src_filter} - - ; Common libs for communicating over TCP/IP networks such as MQTT [networking_base] @@ -91,16 +93,21 @@ lib_deps = lib_deps = jgromes/RadioLib@7.1.2 +[device-ui_base] +lib_deps = + https://github.com/meshtastic/device-ui/archive/99171e87a70452395b56cce713a951c1c2964370.zip + ; Common libs for environmental measurements in telemetry module ; (not included in native / portduino) [environmental_base] lib_deps = - adafruit/Adafruit BusIO@1.16.2 - adafruit/Adafruit Unified Sensor@1.1.14 + adafruit/Adafruit BusIO@1.17.0 + adafruit/Adafruit Unified Sensor@1.1.15 adafruit/Adafruit BMP280 Library@2.6.8 adafruit/Adafruit BMP085 Library@1.2.4 adafruit/Adafruit BME280 Library@2.2.4 - adafruit/Adafruit BMP3XX Library@2.1.5 + adafruit/Adafruit BMP3XX Library@2.1.6 + adafruit/Adafruit DPS310@1.1.5 adafruit/Adafruit MCP9808 Library@2.0.2 adafruit/Adafruit INA260 Library@1.5.2 adafruit/Adafruit INA219@1.2.3 @@ -108,27 +115,27 @@ lib_deps = adafruit/Adafruit SHTC3 Library@1.0.1 adafruit/Adafruit LPS2X@2.0.6 adafruit/Adafruit SHT31 Library@2.2.2 - adafruit/Adafruit PM25 AQI Sensor@1.1.1 + adafruit/Adafruit PM25 AQI Sensor@1.2.0 adafruit/Adafruit MPU6050@2.2.6 adafruit/Adafruit LIS3DH@1.3.0 adafruit/Adafruit AHTX0@2.0.5 - adafruit/Adafruit LSM6DS@4.7.3 + adafruit/Adafruit LSM6DS@4.7.4 adafruit/Adafruit VEML7700 Library@2.1.6 adafruit/Adafruit SHT4x Library@1.0.5 adafruit/Adafruit TSL2591 Library@1.4.5 sparkfun/SparkFun Qwiic Scale NAU7802 Arduino Library@1.0.6 - sparkfun/SparkFun 9DoF IMU Breakout - ICM 20948 - Arduino Library@1.2.13 + sparkfun/SparkFun 9DoF IMU Breakout - ICM 20948 - Arduino Library@1.3.0 ClosedCube OPT3001@1.1.2 emotibit/EmotiBit MLX90632@1.0.8 adafruit/Adafruit MLX90614 Library@2.1.5 - https://github.com/boschsensortec/Bosch-BSEC2-Library#v1.7.2502 + https://github.com/boschsensortec/Bosch-BSEC2-Library/archive/v1.7.2502.zip boschsensortec/BME68x Sensor Library@1.1.40407 - https://github.com/KodinLanewave/INA3221@1.0.1 + https://github.com/KodinLanewave/INA3221/archive/1.0.1.zip mprograms/QMC5883LCompass@1.2.3 dfrobot/DFRobot_RTU@1.0.3 - https://github.com/meshtastic/DFRobot_LarkWeatherStation#4de3a9cadef0f6a5220a8a906cf9775b02b0040d - https://github.com/DFRobot/DFRobot_RainfallSensor#38fea5e02b40a5430be6dab39a99a6f6347d667e - robtillaart/INA226@0.6.0 + https://github.com/meshtastic/DFRobot_LarkWeatherStation/archive/4de3a9cadef0f6a5220a8a906cf9775b02b0040d.zip + https://github.com/DFRobot/DFRobot_RainfallSensor/archive/38fea5e02b40a5430be6dab39a99a6f6347d667e.zip + robtillaart/INA226@0.6.4 ; Health Sensor Libraries sparkfun/SparkFun MAX3010x Pulse and Proximity Sensor Library@1.1.2 diff --git a/protobufs b/protobufs index 2a3a67f04..484d002a5 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 2a3a67f0431926dc3f32a8b216d264daab09b9bf +Subproject commit 484d002a52bc20fa9f91ebf1b216d585c5f93a1b diff --git a/src/AudioThread.h b/src/AudioThread.h index 6d560ec55..04ff64a6e 100644 --- a/src/AudioThread.h +++ b/src/AudioThread.h @@ -41,10 +41,8 @@ class AudioThread : public concurrency::OSThread delete i2sRtttl; i2sRtttl = nullptr; } - if (rtttlFile != nullptr) { - delete rtttlFile; - rtttlFile = nullptr; - } + delete rtttlFile; + rtttlFile = nullptr; setCPUFast(false); } diff --git a/src/BluetoothStatus.h b/src/BluetoothStatus.h index e29139001..526b6f243 100644 --- a/src/BluetoothStatus.h +++ b/src/BluetoothStatus.h @@ -30,7 +30,7 @@ class BluetoothStatus : public Status BluetoothStatus() { statusType = STATUS_TYPE_BLUETOOTH; } // New BluetoothStatus: connected or disconnected - BluetoothStatus(ConnectionState state) + explicit BluetoothStatus(ConnectionState state) { assert(state != ConnectionState::PAIRING); // If pairing, use constructor which specifies passkey statusType = STATUS_TYPE_BLUETOOTH; @@ -38,7 +38,7 @@ class BluetoothStatus : public Status } // New BluetoothStatus: pairing, with passkey - BluetoothStatus(std::string passkey) : Status() + explicit BluetoothStatus(const std::string &passkey) : Status() { statusType = STATUS_TYPE_BLUETOOTH; this->state = ConnectionState::PAIRING; diff --git a/src/ButtonThread.cpp b/src/ButtonThread.cpp index ec0bc5fc2..2363f804c 100644 --- a/src/ButtonThread.cpp +++ b/src/ButtonThread.cpp @@ -47,7 +47,7 @@ ButtonThread::ButtonThread() : OSThread("Button") #ifdef USERPREFS_BUTTON_PIN int pin = config.device.button_gpio ? config.device.button_gpio : USERPREFS_BUTTON_PIN; // Resolved button pin #endif -#if defined(HELTEC_CAPSULE_SENSOR_V3) +#if defined(HELTEC_CAPSULE_SENSOR_V3) || defined(HELTEC_SENSOR_HUB) this->userButton = OneButton(pin, false, false); #elif defined(BUTTON_ACTIVE_LOW) this->userButton = OneButton(pin, BUTTON_ACTIVE_LOW, BUTTON_ACTIVE_PULLUP); @@ -73,23 +73,28 @@ ButtonThread::ButtonThread() : OSThread("Button") userButton.setDebounceMs(1); userButton.attachDoubleClick(userButtonDoublePressed); 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 +#if !defined(T_DECK) && \ + !defined( \ + ELECROW_ThinkNode_M2) // T-Deck immediately wakes up after shutdown, Thinknode M2 has this on the smaller ALT button userButton.attachLongPressStart(userButtonPressedLongStart); userButton.attachLongPressStop(userButtonPressedLongStop); #endif #endif #ifdef BUTTON_PIN_ALT - userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true); +#if defined(ELECROW_ThinkNode_M2) + this->userButtonAlt = OneButton(BUTTON_PIN_ALT, false, false); +#else + this->userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true); +#endif #ifdef INPUT_PULLUP_SENSE // Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did pinMode(BUTTON_PIN_ALT, INPUT_PULLUP_SENSE); #endif - userButtonAlt.attachClick(userButtonPressed); + userButtonAlt.attachClick(userButtonPressedScreen); userButtonAlt.setClickMs(BUTTON_CLICK_MS); userButtonAlt.setPressMs(BUTTON_LONGPRESS_MS); userButtonAlt.setDebounceMs(1); - userButtonAlt.attachDoubleClick(userButtonDoublePressed); userButtonAlt.attachLongPressStart(userButtonPressedLongStart); userButtonAlt.attachLongPressStop(userButtonPressedLongStop); #endif @@ -117,6 +122,40 @@ int32_t ButtonThread::runOnce() canSleep = true; // Assume we should not keep the board awake #if defined(BUTTON_PIN) || defined(USERPREFS_BUTTON_PIN) + // #if defined(ELECROW_ThinkNode_M1) || defined(ELECROW_ThinkNode_M2) + // buzzer_updata(); + // if (buttonPressed) { + // buttonPressed = false; // 清除标志 + // LOG_INFO("PIN_BUTTON2 pressed!"); // 串口打印信息 + // // off_currentTime = millis(); + // while (digitalRead(PIN_BUTTON2) == HIGH) { + // if (cont < 40) { + // // unsigned long currentTime = millis(); // 获取当前时间 + // // if (currentTime - off_currentTime >= 1000) { + // cont++; + // // off_currentTime = currentTime; + // // } + // delay(100); + // } else { + + // currentState = OFF; + // isBuzzing = false; + // cont = 0; + // BEEP_STATE = false; + // analogWrite(M2_buzzer, 0); + // pinMode(M2_buzzer, INPUT); + // screen->setOn(false); + // cont = 0; + // LOG_INFO("GGGGGGGGGGGGGGGGGGGGGGGGG"); + // pinMode(1, OUTPUT); + // digitalWrite(1, LOW); + // pinMode(6, OUTPUT); + // digitalWrite(6, LOW); + // } + // } + // } + + // #endif userButton.tick(); canSleep &= userButton.isIdle(); #elif defined(ARCH_PORTDUINO) @@ -166,6 +205,14 @@ int32_t ButtonThread::runOnce() break; } + case BUTTON_EVENT_PRESSED_SCREEN: { + // turn screen on or off + screen_flag = !screen_flag; + if (screen) + screen->setOn(screen_flag); + break; + } + case BUTTON_EVENT_DOUBLE_PRESSED: { LOG_BUTTON("Double press!"); service->refreshLocalMeshNode(); @@ -192,7 +239,16 @@ int32_t ButtonThread::runOnce() screen->forceDisplay(true); // Force a new UI frame, then force an EInk update } break; +#elif defined(ELECROW_ThinkNode_M2) + case 3: + LOG_INFO("3 clicks: toggle buzzer"); + buzzer_flag = !buzzer_flag; + if (buzzer_flag) { + playBeep(); + } + break; #endif + #if defined(USE_EINK) && defined(PIN_EINK_EN) // i.e. T-Echo // 4 clicks: toggle backlight case 4: diff --git a/src/ButtonThread.h b/src/ButtonThread.h index 54b833d03..a8f1f77c3 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -24,6 +24,7 @@ class ButtonThread : public concurrency::OSThread enum ButtonEventType { BUTTON_EVENT_NONE, BUTTON_EVENT_PRESSED, + BUTTON_EVENT_PRESSED_SCREEN, BUTTON_EVENT_DOUBLE_PRESSED, BUTTON_EVENT_MULTI_PRESSED, BUTTON_EVENT_LONG_PRESSED, @@ -42,7 +43,6 @@ class ButtonThread : public concurrency::OSThread int beforeLightSleep(void *unused); int afterLightSleep(esp_sleep_wakeup_cause_t cause); #endif - private: #if defined(BUTTON_PIN) || defined(ARCH_PORTDUINO) || defined(USERPREFS_BUTTON_PIN) static OneButton userButton; // Static - accessed from an interrupt @@ -64,6 +64,8 @@ class ButtonThread : public concurrency::OSThread // set during IRQ static volatile ButtonEventType btnEvent; + bool buzzer_flag = false; + bool screen_flag = true; // Store click count during callback, for later use volatile int multipressClickCount = 0; @@ -72,6 +74,12 @@ class ButtonThread : public concurrency::OSThread // IRQ callbacks static void userButtonPressed() { btnEvent = BUTTON_EVENT_PRESSED; } + static void userButtonPressedScreen() + { + if (millis() > c_holdOffTime) { + btnEvent = BUTTON_EVENT_PRESSED_SCREEN; + } + } static void userButtonDoublePressed() { btnEvent = BUTTON_EVENT_DOUBLE_PRESSED; } static void userButtonMultiPressed(void *callerThread); // Retrieve click count from non-static Onebutton while still valid static void userButtonPressedLongStart(); diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index 7987e7fa1..a34710eb0 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -121,10 +121,15 @@ extern "C" void logLegacy(const char *level, const char *fmt, ...); // Default Bluetooth PIN #define defaultBLEPin 123456 -#if HAS_ETHERNET +#if HAS_ETHERNET && !defined(USE_WS5500) #include #endif // HAS_ETHERNET +#if HAS_ETHERNET && defined(USE_WS5500) +#include +#define ETH ETH2 +#endif // HAS_ETHERNET + #if HAS_WIFI #include #endif // HAS_WIFI @@ -164,4 +169,4 @@ class Syslog bool vlogf(uint16_t pri, const char *appName, const char *fmt, va_list args) __attribute__((format(printf, 3, 0))); }; -#endif // HAS_ETHERNET || HAS_WIFI \ No newline at end of file +#endif // HAS_NETWORKING \ No newline at end of file diff --git a/src/FSCommon.cpp b/src/FSCommon.cpp index 31fe69c93..88f0764b5 100644 --- a/src/FSCommon.cpp +++ b/src/FSCommon.cpp @@ -29,30 +29,6 @@ SPIClass SPI1(HSPI); #endif // HAS_SDCARD -#if defined(ARCH_STM32WL) - -uint16_t OSFS::startOfEEPROM = 1; -uint16_t OSFS::endOfEEPROM = 2048; - -// 3) How do I read from the medium? -void OSFS::readNBytes(uint16_t address, unsigned int num, byte *output) -{ - for (uint16_t i = address; i < address + num; i++) { - *output = EEPROM.read(i); - output++; - } -} - -// 4) How to I write to the medium? -void OSFS::writeNBytes(uint16_t address, unsigned int num, const byte *input) -{ - for (uint16_t i = address; i < address + num; i++) { - EEPROM.update(i, *input); - input++; - } -} -#endif - /** * @brief Copies a file from one location to another. * @@ -62,33 +38,7 @@ void OSFS::writeNBytes(uint16_t address, unsigned int num, const byte *input) */ bool copyFile(const char *from, const char *to) { -#ifdef ARCH_STM32WL - unsigned char cbuffer[2048]; - - // Var to hold the result of actions - OSFS::result r; - - r = OSFS::getFile(from, cbuffer); - - if (r == notfound) { - LOG_ERROR("Failed to open source file %s", from); - return false; - } else if (r == noerr) { - r = OSFS::newFile(to, cbuffer, true); - if (r == noerr) { - return true; - } else { - LOG_ERROR("OSFS Error %d", r); - return false; - } - - } else { - LOG_ERROR("OSFS Error %d", r); - return false; - } - return true; - -#elif defined(FSCom) +#ifdef FSCom // take SPI Lock concurrency::LockGuard g(spiLock); unsigned char cbuffer[16]; @@ -127,13 +77,7 @@ bool copyFile(const char *from, const char *to) */ bool renameFile(const char *pathFrom, const char *pathTo) { -#ifdef ARCH_STM32WL - if (copyFile(pathFrom, pathTo) && (OSFS::deleteFile(pathFrom) == OSFS::result::NO_ERROR)) { - return true; - } else { - return false; - } -#elif defined(FSCom) +#ifdef FSCom #ifdef ARCH_ESP32 // take SPI Lock diff --git a/src/FSCommon.h b/src/FSCommon.h index 10ce4aeec..fdc0b76ec 100644 --- a/src/FSCommon.h +++ b/src/FSCommon.h @@ -15,13 +15,11 @@ #endif #if defined(ARCH_STM32WL) -// STM32WL series 2 Kbytes (8 rows of 256 bytes) -#include -#include - -// Useful consts -const OSFS::result noerr = OSFS::result::NO_ERROR; -const OSFS::result notfound = OSFS::result::FILE_NOT_FOUND; +// STM32WL +#include "LittleFS.h" +#define FSCom InternalFS +#define FSBegin() FSCom.begin() +using namespace STM32_LittleFS_Namespace; #endif #if defined(ARCH_RP2040) diff --git a/src/Power.cpp b/src/Power.cpp index 8d5fe1c32..0dec0fc21 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -32,6 +32,11 @@ #include #endif +#if HAS_ETHERNET && defined(USE_WS5500) +#include +#define ETH ETH2 +#endif // HAS_ETHERNET + #endif #ifndef DELAY_FOREVER @@ -386,7 +391,7 @@ class AnalogBatteryLevel : public HasBatteryLevel virtual bool isVbusIn() override { #ifdef EXT_PWR_DETECT -#ifdef HELTEC_CAPSULE_SENSOR_V3 +#if defined(HELTEC_CAPSULE_SENSOR_V3) || defined(HELTEC_SENSOR_HUB) // if external powered that pin will be pulled down if (digitalRead(EXT_PWR_DETECT) == LOW) { return true; @@ -528,6 +533,9 @@ Power::Power() : OSThread("Power") { statusHandler = {}; low_voltage_counter = 0; +#if defined(ELECROW_ThinkNode_M1) || defined(POWER_CFG) + low_voltage_counter_led3 = 0; +#endif #ifdef DEBUG_HEAP lastheap = memGet.getFreeHeap(); #endif @@ -536,7 +544,7 @@ Power::Power() : OSThread("Power") bool Power::analogInit() { #ifdef EXT_PWR_DETECT -#ifdef HELTEC_CAPSULE_SENSOR_V3 +#if defined(HELTEC_CAPSULE_SENSOR_V3) || defined(HELTEC_SENSOR_HUB) pinMode(EXT_PWR_DETECT, INPUT_PULLUP); #else pinMode(EXT_PWR_DETECT, INPUT); @@ -663,12 +671,12 @@ void Power::readPowerStatus() int8_t batteryChargePercent = -1; OptionalBool usbPowered = OptUnknown; OptionalBool hasBattery = OptUnknown; // These must be static because NRF_APM code doesn't run every time - OptionalBool isCharging = OptUnknown; + OptionalBool isChargingNow = OptUnknown; if (batteryLevel) { hasBattery = batteryLevel->isBatteryConnect() ? OptTrue : OptFalse; usbPowered = batteryLevel->isVbusIn() ? OptTrue : OptFalse; - isCharging = batteryLevel->isCharging() ? OptTrue : OptFalse; + isChargingNow = batteryLevel->isCharging() ? OptTrue : OptFalse; if (hasBattery) { batteryVoltageMv = batteryLevel->getBattVoltage(); // If the AXP192 returns a valid battery percentage, use it @@ -697,17 +705,20 @@ void Power::readPowerStatus() // If changed to DISCONNECTED if (nrf_usb_state == NRFX_POWER_USB_STATE_DISCONNECTED) - isCharging = usbPowered = OptFalse; + isChargingNow = usbPowered = OptFalse; // If changed to CONNECTED / READY else - isCharging = usbPowered = OptTrue; + isChargingNow = usbPowered = OptTrue; #endif // Notify any status instances that are observing us - const PowerStatus powerStatus2 = PowerStatus(hasBattery, usbPowered, isCharging, batteryVoltageMv, batteryChargePercent); + const PowerStatus powerStatus2 = PowerStatus(hasBattery, usbPowered, isChargingNow, batteryVoltageMv, batteryChargePercent); LOG_DEBUG("Battery: usbPower=%d, isCharging=%d, batMv=%d, batPct=%d", powerStatus2.getHasUSB(), powerStatus2.getIsCharging(), powerStatus2.getBatteryVoltageMv(), powerStatus2.getBatteryChargePercent()); +#if defined(ELECROW_ThinkNode_M1) || defined(POWER_CFG) + power_num = powerStatus2.getBatteryVoltageMv(); +#endif newStatus.notifyObservers(&powerStatus2); #ifdef DEBUG_HEAP if (lastheap != memGet.getFreeHeap()) { @@ -751,9 +762,13 @@ void Power::readPowerStatus() // If we have a battery at all and it is less than 0%, force deep sleep if we have more than 10 low readings in // a row. NOTE: min LiIon/LiPo voltage is 2.0 to 2.5V, current OCV min is set to 3100 that is large enough. // + if (batteryLevel && powerStatus2.getHasBattery() && !powerStatus2.getHasUSB()) { if (batteryLevel->getBattVoltage() < OCV[NUM_OCV_POINTS - 1]) { low_voltage_counter++; +#if defined(ELECROW_ThinkNode_M1) + low_voltage_counter_led3 = low_voltage_counter; +#endif LOG_DEBUG("Low voltage counter: %d/10", low_voltage_counter); if (low_voltage_counter > 10) { #ifdef ARCH_NRF52 @@ -766,7 +781,13 @@ void Power::readPowerStatus() } } else { low_voltage_counter = 0; +#if defined(ELECROW_ThinkNode_M1) + low_voltage_counter_led3 = low_voltage_counter; +#endif } +#ifdef POWER_CFG + low_voltage_counter_led3 = low_voltage_counter; +#endif } } diff --git a/src/SafeFile.cpp b/src/SafeFile.cpp index c942aa0ee..45b96ad07 100644 --- a/src/SafeFile.cpp +++ b/src/SafeFile.cpp @@ -11,12 +11,18 @@ static File openFile(const char *filename, bool fullAtomic) FSCom.remove(filename); return FSCom.open(filename, FILE_O_WRITE); #endif - if (!fullAtomic) + if (!fullAtomic) { FSCom.remove(filename); // Nuke the old file to make space (ignore if it !exists) + } String filenameTmp = filename; filenameTmp += ".tmp"; + // FIXME: If we are doing a full atomic write, we may need to remove the old tmp file now + // if (fullAtomic) { + // FSCom.remove(filename); + // } + // clear any previous LFS errors return FSCom.open(filenameTmp.c_str(), FILE_O_WRITE); } diff --git a/src/buzz/buzz.cpp b/src/buzz/buzz.cpp index 8db9602bc..6ba2f4140 100644 --- a/src/buzz/buzz.cpp +++ b/src/buzz/buzz.cpp @@ -30,8 +30,11 @@ struct ToneDuration { #define NOTE_B3 247 #define NOTE_CS4 277 -const int DURATION_1_8 = 125; // 1/8 note -const int DURATION_1_4 = 250; // 1/4 note +const int DURATION_1_8 = 125; // 1/8 note +const int DURATION_1_4 = 250; // 1/4 note +const int DURATION_1_2 = 500; // 1/2 note +const int DURATION_3_4 = 750; // 1/4 note +const int DURATION_1_1 = 1000; // 1/1 note void playTones(const ToneDuration *tone_durations, int size) { @@ -55,6 +58,12 @@ void playBeep() playTones(melody, sizeof(melody) / sizeof(ToneDuration)); } +void playLongBeep() +{ + ToneDuration melody[] = {{NOTE_B3, DURATION_1_1}}; + playTones(melody, sizeof(melody) / sizeof(ToneDuration)); +} + void playGPSEnableBeep() { ToneDuration melody[] = {{NOTE_C3, DURATION_1_8}, {NOTE_FS3, DURATION_1_4}, {NOTE_CS4, DURATION_1_4}}; diff --git a/src/buzz/buzz.h b/src/buzz/buzz.h index c52c3020c..adeaca73d 100644 --- a/src/buzz/buzz.h +++ b/src/buzz/buzz.h @@ -1,6 +1,7 @@ #pragma once void playBeep(); +void playLongBeep(); void playStartMelody(); void playShutdownMelody(); void playGPSEnableBeep(); diff --git a/src/configuration.h b/src/configuration.h index 6f5255ec9..fd4a5b196 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -135,6 +135,7 @@ along with this program. If not, see . #define LPS22HB_ADDR 0x5C #define LPS22HB_ADDR_ALT 0x5D #define SHT31_4x_ADDR 0x44 +#define SHT31_4x_ADDR_ALT 0x45 #define PMSA0031_ADDR 0x12 #define QMA6100P_ADDR 0x12 #define AHT10_ADDR 0x38 @@ -150,6 +151,7 @@ along with this program. If not, see . #define MAX30102_ADDR 0x57 #define MLX90614_ADDR_DEF 0x5A #define CGRADSENS_ADDR 0x66 +#define LTR390UV_ADDR 0x53 // ----------------------------------------------------------------------------- // ACCELEROMETER diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index faa94c7d3..5b6bbe629 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -67,6 +67,8 @@ class ScanI2C INA226, NXP_SE050, DFROBOT_RAIN, + DPS310, + LTR390UV, } DeviceType; // typedef uint8_t DeviceAddress; diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 41cfe1517..8b779277d 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -237,6 +237,16 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) logFoundDevice("BMP085/BMP180", (uint8_t)addr.address); type = BMP_085; break; + case 0x00: + // do we have a DPS310 instead? + registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x0D), 1); + switch (registerValue) { + case 0x10: + logFoundDevice("DPS310", (uint8_t)addr.address); + type = DPS310; + break; + } + break; default: registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x00), 1); // GET_ID switch (registerValue) { @@ -339,7 +349,8 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) } break; } - case SHT31_4x_ADDR: + case SHT31_4x_ADDR: // same as OPT3001_ADDR_ALT + case SHT31_4x_ADDR_ALT: // same as OPT3001_ADDR registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x89), 2); if (registerValue == 0x11a2 || registerValue == 0x11da || registerValue == 0xe9c) { type = SHT4X; @@ -412,11 +423,11 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) SCAN_SIMPLE_CASE(TCA9555_ADDR, TCA9555, "TCA9555", (uint8_t)addr.address); SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700", (uint8_t)addr.address); SCAN_SIMPLE_CASE(TSL25911_ADDR, TSL2591, "TSL2591", (uint8_t)addr.address); - SCAN_SIMPLE_CASE(OPT3001_ADDR, OPT3001, "OPT3001", (uint8_t)addr.address); SCAN_SIMPLE_CASE(MLX90632_ADDR, MLX90632, "MLX90632", (uint8_t)addr.address); SCAN_SIMPLE_CASE(NAU7802_ADDR, NAU7802, "NAU7802", (uint8_t)addr.address); SCAN_SIMPLE_CASE(MAX1704X_ADDR, MAX17048, "MAX17048", (uint8_t)addr.address); SCAN_SIMPLE_CASE(DFROBOT_RAIN_ADDR, DFROBOT_RAIN, "DFRobot Rain Gauge", (uint8_t)addr.address); + SCAN_SIMPLE_CASE(LTR390UV_ADDR, LTR390UV, "LTR390UV", (uint8_t)addr.address); #ifdef HAS_TPS65233 SCAN_SIMPLE_CASE(TPS65233_ADDR, TPS65233, "TPS65233", (uint8_t)addr.address); #endif diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 2989a59bd..41a2ff980 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -1,3 +1,7 @@ +#include // Include for strstr +#include +#include + #include "configuration.h" #if !MESHTASTIC_EXCLUDE_GPS #include "Default.h" @@ -977,15 +981,16 @@ void GPS::down() setPowerState(GPS_IDLE); else { - // Check whether the GPS hardware is capable of GPS_SOFTSLEEP - // If not, fallback to GPS_HARDSLEEP instead +// Check whether the GPS hardware is capable of GPS_SOFTSLEEP +// If not, fallback to GPS_HARDSLEEP instead +#ifdef PIN_GPS_STANDBY // L76B, L76K and clones have a standby pin + bool softsleepSupported = true; +#else bool softsleepSupported = false; +#endif // U-blox is supported via PMREQ if (IS_ONE_OF(gnssModel, GNSS_MODEL_UBLOX6, GNSS_MODEL_UBLOX7, GNSS_MODEL_UBLOX8, GNSS_MODEL_UBLOX9, GNSS_MODEL_UBLOX10)) softsleepSupported = true; -#ifdef PIN_GPS_STANDBY // L76B, L76K and clones have a standby pin - softsleepSupported = true; -#endif if (softsleepSupported) { // How long does gps_update_interval need to be, for GPS_HARDSLEEP to become more efficient than @@ -1100,12 +1105,16 @@ int32_t GPS::runOnce() return (powerState == GPS_ACTIVE) ? GPS_THREAD_INTERVAL : 5000; } -// clear the GPS rx buffer as quickly as possible +// clear the GPS rx/tx buffer as quickly as possible void GPS::clearBuffer() { +#ifdef ARCH_ESP32 + _serial_gps->flush(false); +#else int x = _serial_gps->available(); while (x--) _serial_gps->read(); +#endif } /// Prepare the GPS for the cpu entering deep or light sleep, expect to be gone for at least 100s of msecs @@ -1117,7 +1126,7 @@ int GPS::prepareDeepSleep(void *unused) } static const char *PROBE_MESSAGE = "Trying %s (%s)..."; -static const char *DETECTED_MESSAGE = "%s detected, using %s Module"; +static const char *DETECTED_MESSAGE = "%s detected"; #define PROBE_SIMPLE(CHIP, TOWRITE, RESPONSE, DRIVER, TIMEOUT, ...) \ do { \ @@ -1125,11 +1134,22 @@ static const char *DETECTED_MESSAGE = "%s detected, using %s Module"; clearBuffer(); \ _serial_gps->write(TOWRITE "\r\n"); \ if (getACK(RESPONSE, TIMEOUT) == GNSS_RESPONSE_OK) { \ - LOG_INFO(DETECTED_MESSAGE, CHIP, #DRIVER); \ + LOG_INFO(DETECTED_MESSAGE, CHIP); \ return DRIVER; \ } \ } while (0) +#define PROBE_FAMILY(FAMILY_NAME, COMMAND, RESPONSE_MAP, TIMEOUT) \ + do { \ + LOG_DEBUG(PROBE_MESSAGE, COMMAND, FAMILY_NAME); \ + clearBuffer(); \ + _serial_gps->write(COMMAND "\r\n"); \ + GnssModel_t detectedDriver = getProbeResponse(TIMEOUT, RESPONSE_MAP); \ + if (detectedDriver != GNSS_MODEL_UNKNOWN) { \ + return detectedDriver; \ + } \ + } while (0) + GnssModel_t GPS::probe(int serialSpeed) { #if defined(ARCH_NRF52) || defined(ARCH_PORTDUINO) || defined(ARCH_STM32WL) @@ -1160,31 +1180,34 @@ GnssModel_t GPS::probe(int serialSpeed) delay(20); // Unicore UFirebirdII Series: UC6580, UM620, UM621, UM670A, UM680A, or UM681A - PROBE_SIMPLE("UC6580", "$PDTINFO", "UC6580", GNSS_MODEL_UC6580, 500); - PROBE_SIMPLE("UM600", "$PDTINFO", "UM600", GNSS_MODEL_UC6580, 500); - PROBE_SIMPLE("ATGM336H", "$PCAS06,1*1A", "$GPTXT,01,01,02,HW=ATGM336H", GNSS_MODEL_ATGM336H, 500); - /* ATGM332D series (-11(GPS), -21(BDS), -31(GPS+BDS), -51(GPS+GLONASS), -71-0(GPS+BDS+GLONASS)) - based on AT6558 */ - PROBE_SIMPLE("ATGM332D", "$PCAS06,1*1A", "$GPTXT,01,01,02,HW=ATGM332D", GNSS_MODEL_ATGM336H, 500); + std::vector unicore = {{"UC6580", "UC6580", GNSS_MODEL_UC6580}, {"UM600", "UM600", GNSS_MODEL_UC6580}}; + PROBE_FAMILY("Unicore Family", "$PDTINFO", unicore, 500); + + std::vector atgm = { + {"ATGM336H", "$GPTXT,01,01,02,HW=ATGM336H", GNSS_MODEL_ATGM336H}, + /* ATGM332D series (-11(GPS), -21(BDS), -31(GPS+BDS), -51(GPS+GLONASS), -71-0(GPS+BDS+GLONASS)) based on AT6558 */ + {"ATGM332D", "$GPTXT,01,01,02,HW=ATGM332D", GNSS_MODEL_ATGM336H}}; + PROBE_FAMILY("ATGM33xx Family", "$PCAS06,1*1A", atgm, 500); /* Airoha (Mediatek) AG3335A/M/S, A3352Q, Quectel L89 2.0, SimCom SIM65M */ _serial_gps->write("$PAIR062,2,0*3C\r\n"); // GSA OFF to reduce volume _serial_gps->write("$PAIR062,3,0*3D\r\n"); // GSV OFF to reduce volume _serial_gps->write("$PAIR513*3D\r\n"); // save configuration - PROBE_SIMPLE("AG3335", "$PAIR021*39", "$PAIR021,AG3335", GNSS_MODEL_AG3335, 500); - PROBE_SIMPLE("AG3352", "$PAIR021*39", "$PAIR021,AG3352", GNSS_MODEL_AG3352, 500); - PROBE_SIMPLE("LC86", "$PQTMVERNO*58", "$PQTMVERNO,LC86", GNSS_MODEL_AG3352, 500); + std::vector airoha = {{"AG3335", "$PAIR021,AG3335", GNSS_MODEL_AG3335}, + {"AG3352", "$PAIR021,AG3352", GNSS_MODEL_AG3352}, + {"RYS3520", "$PAIR021,REYAX_RYS3520_V2", GNSS_MODEL_AG3352}}; + PROBE_FAMILY("Airoha Family", "$PAIR021*39", airoha, 1000); + PROBE_SIMPLE("LC86", "$PQTMVERNO*58", "$PQTMVERNO,LC86", GNSS_MODEL_AG3352, 500); PROBE_SIMPLE("L76K", "$PCAS06,0*1B", "$GPTXT,01,01,02,SW=", GNSS_MODEL_MTK, 500); - // Close all NMEA sentences, valid for L76B MTK platform (Waveshare Pico GPS) + // Close all NMEA sentences, valid for MTK3333 and MTK3339 platforms _serial_gps->write("$PMTK514,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*2E\r\n"); delay(20); - - PROBE_SIMPLE("L76B", "$PMTK605*31", "Quectel-L76B", GNSS_MODEL_MTK_L76B, 500); - PROBE_SIMPLE("PA1616S", "$PMTK605*31", "1616S", GNSS_MODEL_MTK_PA1616S, 500); - - PROBE_SIMPLE("LS20031", "$PMTK605*31", "MC-1513", GNSS_MODEL_LS20031, 500); + std::vector mtk = {{"L76B", "Quectel-L76B", GNSS_MODEL_MTK_L76B}, + {"PA1616S", "1616S", GNSS_MODEL_MTK_PA1616S}, + {"LS20031", "MC-1513", GNSS_MODEL_MTK_L76B}}; + PROBE_FAMILY("MTK Family", "$PMTK605*31", mtk, 500); uint8_t cfg_rate[] = {0xB5, 0x62, 0x06, 0x08, 0x00, 0x00, 0x00, 0x00}; UBXChecksum(cfg_rate, sizeof(cfg_rate)); @@ -1281,6 +1304,38 @@ GnssModel_t GPS::probe(int serialSpeed) return GNSS_MODEL_UNKNOWN; } +GnssModel_t GPS::getProbeResponse(unsigned long timeout, const std::vector &responseMap) +{ + String response = ""; + unsigned long start = millis(); + while (millis() - start < timeout) { + if (_serial_gps->available()) { + response += (char)_serial_gps->read(); + + if (response.endsWith(",") || response.endsWith("\r\n")) { +#ifdef GPS_DEBUG + LOG_DEBUG(response.c_str()); +#endif + // check if we can see our chips + for (const auto &chipInfo : responseMap) { + if (strstr(response.c_str(), chipInfo.detectionString.c_str()) != nullptr) { + LOG_INFO("%s detected", chipInfo.chipName.c_str()); + return chipInfo.driver; + } + } + } + if (response.endsWith("\r\n")) { + response.trim(); + response = ""; // Reset the response string for the next potential message + } + } + } +#ifdef GPS_DEBUG + LOG_DEBUG(response.c_str()); +#endif + return GNSS_MODEL_UNKNOWN; // Return empty string on timeout +} + GPS *GPS::createGps() { int8_t _rx_gpio = config.position.rx_gpio; diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 01a4fe745..240cf66d2 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -48,6 +48,11 @@ enum GPSPowerState : uint8_t { GPS_OFF // Powered off indefinitely }; +struct ChipInfo { + String chipName; // The name of the chip (for logging) + String detectionString; // The string to match in the response + GnssModel_t driver; // The driver to use +}; /** * A gps class that only reads from the GPS periodically and keeps the gps powered down except when reading * @@ -230,6 +235,8 @@ class GPS : private concurrency::OSThread virtual int32_t runOnce() override; + GnssModel_t getProbeResponse(unsigned long timeout, const std::vector &responseMap); + // Get GNSS model GnssModel_t probe(int serialSpeed); diff --git a/src/graphics/EInkDisplay2.cpp b/src/graphics/EInkDisplay2.cpp index 9702b0086..96c6b44c1 100644 --- a/src/graphics/EInkDisplay2.cpp +++ b/src/graphics/EInkDisplay2.cpp @@ -128,16 +128,24 @@ bool EInkDisplay::connect() #ifdef PIN_EINK_EN // backlight power, HIGH is backlight on, LOW is off pinMode(PIN_EINK_EN, OUTPUT); +#ifdef ELECROW_ThinkNode_M1 digitalWrite(PIN_EINK_EN, LOW); +#else + digitalWrite(PIN_EINK_EN, HIGH); +#endif #endif -#if defined(TTGO_T_ECHO) +#if defined(TTGO_T_ECHO) || defined(ELECROW_ThinkNode_M1) { auto lowLevel = new EINK_DISPLAY_MODEL(PIN_EINK_CS, PIN_EINK_DC, PIN_EINK_RES, PIN_EINK_BUSY, SPI1); adafruitDisplay = new GxEPD2_BW(*lowLevel); adafruitDisplay->init(); +#ifdef ELECROW_ThinkNode_M1 + adafruitDisplay->setRotation(4); +#else adafruitDisplay->setRotation(3); +#endif adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight); } #elif defined(MESHLINK) @@ -166,7 +174,8 @@ bool EInkDisplay::connect() } #elif defined(HELTEC_WIRELESS_PAPER_V1_0) || defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_VISION_MASTER_E213) || \ - defined(HELTEC_VISION_MASTER_E290) || defined(TLORA_T3S3_EPAPER) + defined(HELTEC_VISION_MASTER_E290) || defined(TLORA_T3S3_EPAPER) || defined(CROWPANEL_ESP32S3_5_EPAPER) || \ + defined(CROWPANEL_ESP32S3_4_EPAPER) || defined(CROWPANEL_ESP32S3_2_EPAPER) { // Start HSPI hspi = new SPIClass(HSPI); @@ -182,6 +191,9 @@ bool EInkDisplay::connect() // Init GxEPD2 adafruitDisplay->init(); adafruitDisplay->setRotation(3); +#if defined(CROWPANEL_ESP32S3_5_EPAPER) || defined(CROWPANEL_ESP32S3_4_EPAPER) + adafruitDisplay->setRotation(0); +#endif } #elif defined(PCA10059) || defined(ME25LS01) { diff --git a/src/graphics/EInkDisplay2.h b/src/graphics/EInkDisplay2.h index af631150e..9c1c8d18e 100644 --- a/src/graphics/EInkDisplay2.h +++ b/src/graphics/EInkDisplay2.h @@ -68,7 +68,8 @@ class EInkDisplay : public OLEDDisplay // If display uses HSPI #if defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0) || defined(HELTEC_VISION_MASTER_E213) || \ - defined(HELTEC_VISION_MASTER_E290) || defined(TLORA_T3S3_EPAPER) + defined(HELTEC_VISION_MASTER_E290) || defined(TLORA_T3S3_EPAPER) || defined(CROWPANEL_ESP32S3_5_EPAPER) || \ + defined(CROWPANEL_ESP32S3_4_EPAPER) || defined(CROWPANEL_ESP32S3_2_EPAPER) SPIClass *hspi = NULL; #endif @@ -77,4 +78,4 @@ class EInkDisplay : public OLEDDisplay uint32_t lastDrawMsec = 0; }; -#endif \ No newline at end of file +#endif diff --git a/src/graphics/EInkDynamicDisplay.cpp b/src/graphics/EInkDynamicDisplay.cpp index 47012ca47..8e4adf87e 100644 --- a/src/graphics/EInkDynamicDisplay.cpp +++ b/src/graphics/EInkDynamicDisplay.cpp @@ -324,6 +324,14 @@ void EInkDynamicDisplay::checkConsecutiveFastRefreshes() if (refresh != UNSPECIFIED) return; + // Bypass limit if UNLIMITED_FAST mode is active + if (frameFlags & UNLIMITED_FAST) { + refresh = FAST; + reason = NO_OBJECTIONS; + LOG_DEBUG("refresh=FAST, reason=UNLIMITED_FAST_MODE_ACTIVE, frameFlags=0x%x", frameFlags); + return; + } + // If too many FAST refreshes consecutively - force a FULL refresh if (fastRefreshCount >= EINK_LIMIT_FASTREFRESH) { refresh = FULL; diff --git a/src/graphics/EInkDynamicDisplay.h b/src/graphics/EInkDynamicDisplay.h index 9e131dca7..d5e29e3f0 100644 --- a/src/graphics/EInkDynamicDisplay.h +++ b/src/graphics/EInkDynamicDisplay.h @@ -23,6 +23,10 @@ class EInkDynamicDisplay : public EInkDisplay, protected concurrency::NotifiedWo EInkDynamicDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY geometry, HW_I2C i2cBus); ~EInkDynamicDisplay(); + // Methods to enable or disable unlimited fast refresh mode + void enableUnlimitedFastMode() { addFrameFlag(UNLIMITED_FAST); } + void disableUnlimitedFastMode() { frameFlags = (frameFlagTypes)(frameFlags & ~UNLIMITED_FAST); } + // What kind of frame is this enum frameFlagTypes : uint8_t { BACKGROUND = (1 << 0), // For frames via display() @@ -30,6 +34,7 @@ class EInkDynamicDisplay : public EInkDisplay, protected concurrency::NotifiedWo COSMETIC = (1 << 2), // For splashes DEMAND_FAST = (1 << 3), // Special case only BLOCKING = (1 << 4), // Modifier - block while refresh runs + UNLIMITED_FAST = (1 << 5) }; void addFrameFlag(frameFlagTypes flag); diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 0c18f3287..e27495f54 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1641,6 +1641,11 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) setScreensaverFrames(einkScreensaver); #endif LOG_INFO("Turn off screen"); +#ifdef ELECROW_ThinkNode_M1 + if (digitalRead(PIN_EINK_EN) == HIGH) { + digitalWrite(PIN_EINK_EN, LOW); + } +#endif dispdev->displayOff(); #ifdef USE_ST7789 SPI1.end(); @@ -2664,14 +2669,19 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat // minutes %= 60; // hours %= 24; + // Show uptime as days, hours, minutes OR seconds + std::string uptime = screen->drawTimeDelta(days, hours, minutes, seconds); + + // Line 1 (Still) + display->drawString(x + SCREEN_WIDTH - display->getStringWidth(uptime.c_str()), y, uptime.c_str()); + if (config.display.heading_bold) + display->drawString(x - 1 + SCREEN_WIDTH - display->getStringWidth(uptime.c_str()), y, uptime.c_str()); + display->setColor(WHITE); // Setup string to assemble analogClock string std::string analogClock = ""; - // Show uptime as days, hours, minutes OR seconds - std::string uptime = screen->drawTimeDelta(days, hours, minutes, seconds); - uint32_t rtc_sec = getValidTime(RTCQuality::RTCQualityDevice, true); // Display local timezone if (rtc_sec > 0) { long hms = rtc_sec % SEC_PER_DAY; @@ -2704,9 +2714,6 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat analogClock += timebuf; } - // Line 1 - display->drawString(x + SCREEN_WIDTH - display->getStringWidth(uptime.c_str()), y, uptime.c_str()); - // Line 2 display->drawString(x, y + FONT_HEIGHT_SMALL * 1, analogClock.c_str()); @@ -2728,7 +2735,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat drawGPSpowerstat(display, x, y + FONT_HEIGHT_SMALL * 2, gpsStatus); } #endif - /* Display a heartbeat pixel that blinks every time the frame is redrawn */ +/* Display a heartbeat pixel that blinks every time the frame is redrawn */ #ifdef SHOW_REDRAWS if (heartbeat) display->setPixel(0, 0); diff --git a/src/graphics/ScreenFonts.h b/src/graphics/ScreenFonts.h index f6abec0f5..079a3e282 100644 --- a/src/graphics/ScreenFonts.h +++ b/src/graphics/ScreenFonts.h @@ -16,6 +16,10 @@ #include "graphics/fonts/OLEDDisplayFontsCS.h" #endif +#ifdef CROWPANEL_ESP32S3_5_EPAPER +#include "graphics/fonts/EinkDisplayFonts.h" +#endif + #ifdef OLED_PL #define FONT_SMALL_LOCAL ArialMT_Plain_10_PL #else @@ -73,6 +77,15 @@ #define FONT_LARGE FONT_LARGE_LOCAL // Height: 28 #endif +#if defined(CROWPANEL_ESP32S3_5_EPAPER) +#undef FONT_SMALL +#undef FONT_MEDIUM +#undef FONT_LARGE +#define FONT_SMALL Monospaced_plain_30 +#define FONT_MEDIUM Monospaced_plain_30 +#define FONT_LARGE Monospaced_plain_30 +#endif + #define _fontHeight(font) ((font)[1] + 1) // height is position 1 #define FONT_HEIGHT_SMALL _fontHeight(FONT_SMALL) diff --git a/src/graphics/fonts/EinkDisplayFonts.cpp b/src/graphics/fonts/EinkDisplayFonts.cpp new file mode 100644 index 000000000..cfe2c931f --- /dev/null +++ b/src/graphics/fonts/EinkDisplayFonts.cpp @@ -0,0 +1,1184 @@ +#include "EinkDisplayFonts.h" + +// Created by https://oleddisplay.squix.ch/ Consider a donation +// In case of problems make sure that you are using the font file with the correct version! +const uint8_t Monospaced_plain_30[] PROGMEM = { + 0x12, // Width: 18 + 0x24, // Height: 36 + 0x20, // First Char: 32 + 0xE0, // Numbers of Chars: 224 + + // Jump Table: + 0xFF, 0xFF, 0x00, 0x12, // 32:65535 + 0x00, 0x00, 0x36, 0x12, // 33:0 + 0x00, 0x36, 0x3E, 0x12, // 34:54 + 0x00, 0x74, 0x57, 0x12, // 35:116 + 0x00, 0xCB, 0x54, 0x12, // 36:203 + 0x01, 0x1F, 0x54, 0x12, // 37:287 + 0x01, 0x73, 0x59, 0x12, // 38:371 + 0x01, 0xCC, 0x2F, 0x12, // 39:460 + 0x01, 0xFB, 0x40, 0x12, // 40:507 + 0x02, 0x3B, 0x3A, 0x12, // 41:571 + 0x02, 0x75, 0x4D, 0x12, // 42:629 + 0x02, 0xC2, 0x4E, 0x12, // 43:706 + 0x03, 0x10, 0x36, 0x12, // 44:784 + 0x03, 0x46, 0x3F, 0x12, // 45:838 + 0x03, 0x85, 0x36, 0x12, // 46:901 + 0x03, 0xBB, 0x51, 0x12, // 47:955 + 0x04, 0x0C, 0x4E, 0x12, // 48:1036 + 0x04, 0x5A, 0x54, 0x12, // 49:1114 + 0x04, 0xAE, 0x4F, 0x12, // 50:1198 + 0x04, 0xFD, 0x4E, 0x12, // 51:1277 + 0x05, 0x4B, 0x53, 0x12, // 52:1355 + 0x05, 0x9E, 0x4E, 0x12, // 53:1438 + 0x05, 0xEC, 0x4E, 0x12, // 54:1516 + 0x06, 0x3A, 0x4D, 0x12, // 55:1594 + 0x06, 0x87, 0x4F, 0x12, // 56:1671 + 0x06, 0xD6, 0x4E, 0x12, // 57:1750 + 0x07, 0x24, 0x36, 0x12, // 58:1828 + 0x07, 0x5A, 0x36, 0x12, // 59:1882 + 0x07, 0x90, 0x4F, 0x12, // 60:1936 + 0x07, 0xDF, 0x4E, 0x12, // 61:2015 + 0x08, 0x2D, 0x4E, 0x12, // 62:2093 + 0x08, 0x7B, 0x48, 0x12, // 63:2171 + 0x08, 0xC3, 0x59, 0x12, // 64:2243 + 0x09, 0x1C, 0x59, 0x12, // 65:2332 + 0x09, 0x75, 0x4F, 0x12, // 66:2421 + 0x09, 0xC4, 0x4F, 0x12, // 67:2500 + 0x0A, 0x13, 0x4E, 0x12, // 68:2579 + 0x0A, 0x61, 0x4F, 0x12, // 69:2657 + 0x0A, 0xB0, 0x4D, 0x12, // 70:2736 + 0x0A, 0xFD, 0x54, 0x12, // 71:2813 + 0x0B, 0x51, 0x4F, 0x12, // 72:2897 + 0x0B, 0xA0, 0x4F, 0x12, // 73:2976 + 0x0B, 0xEF, 0x44, 0x12, // 74:3055 + 0x0C, 0x33, 0x59, 0x12, // 75:3123 + 0x0C, 0x8C, 0x54, 0x12, // 76:3212 + 0x0C, 0xE0, 0x54, 0x12, // 77:3296 + 0x0D, 0x34, 0x4F, 0x12, // 78:3380 + 0x0D, 0x83, 0x53, 0x12, // 79:3459 + 0x0D, 0xD6, 0x52, 0x12, // 80:3542 + 0x0E, 0x28, 0x53, 0x12, // 81:3624 + 0x0E, 0x7B, 0x59, 0x12, // 82:3707 + 0x0E, 0xD4, 0x4F, 0x12, // 83:3796 + 0x0F, 0x23, 0x57, 0x12, // 84:3875 + 0x0F, 0x7A, 0x4E, 0x12, // 85:3962 + 0x0F, 0xC8, 0x51, 0x12, // 86:4040 + 0x10, 0x19, 0x57, 0x12, // 87:4121 + 0x10, 0x70, 0x59, 0x12, // 88:4208 + 0x10, 0xC9, 0x56, 0x12, // 89:4297 + 0x11, 0x1F, 0x54, 0x12, // 90:4383 + 0x11, 0x73, 0x45, 0x12, // 91:4467 + 0x11, 0xB8, 0x54, 0x12, // 92:4536 + 0x12, 0x0C, 0x3B, 0x12, // 93:4620 + 0x12, 0x47, 0x52, 0x12, // 94:4679 + 0x12, 0x99, 0x5A, 0x12, // 95:4761 + 0x12, 0xF3, 0x34, 0x12, // 96:4851 + 0x13, 0x27, 0x4F, 0x12, // 97:4903 + 0x13, 0x76, 0x53, 0x12, // 98:4982 + 0x13, 0xC9, 0x4F, 0x12, // 99:5065 + 0x14, 0x18, 0x4F, 0x12, // 100:5144 + 0x14, 0x67, 0x53, 0x12, // 101:5223 + 0x14, 0xBA, 0x4D, 0x12, // 102:5306 + 0x15, 0x07, 0x4F, 0x12, // 103:5383 + 0x15, 0x56, 0x4F, 0x12, // 104:5462 + 0x15, 0xA5, 0x4F, 0x12, // 105:5541 + 0x15, 0xF4, 0x3B, 0x12, // 106:5620 + 0x16, 0x2F, 0x54, 0x12, // 107:5679 + 0x16, 0x83, 0x4F, 0x12, // 108:5763 + 0x16, 0xD2, 0x54, 0x12, // 109:5842 + 0x17, 0x26, 0x4F, 0x12, // 110:5926 + 0x17, 0x75, 0x4E, 0x12, // 111:6005 + 0x17, 0xC3, 0x53, 0x12, // 112:6083 + 0x18, 0x16, 0x50, 0x12, // 113:6166 + 0x18, 0x66, 0x52, 0x12, // 114:6246 + 0x18, 0xB8, 0x4A, 0x12, // 115:6328 + 0x19, 0x02, 0x4A, 0x12, // 116:6402 + 0x19, 0x4C, 0x4F, 0x12, // 117:6476 + 0x19, 0x9B, 0x4D, 0x12, // 118:6555 + 0x19, 0xE8, 0x57, 0x12, // 119:6632 + 0x1A, 0x3F, 0x54, 0x12, // 120:6719 + 0x1A, 0x93, 0x52, 0x12, // 121:6803 + 0x1A, 0xE5, 0x4A, 0x12, // 122:6885 + 0x1B, 0x2F, 0x4B, 0x12, // 123:6959 + 0x1B, 0x7A, 0x32, 0x12, // 124:7034 + 0x1B, 0xAC, 0x4E, 0x12, // 125:7084 + 0x1B, 0xFA, 0x4E, 0x12, // 126:7162 + 0x1C, 0x48, 0x55, 0x12, // 127:7240 + 0x1C, 0x9D, 0x55, 0x12, // 128:7325 + 0x1C, 0xF2, 0x55, 0x12, // 129:7410 + 0x1D, 0x47, 0x55, 0x12, // 130:7495 + 0x1D, 0x9C, 0x55, 0x12, // 131:7580 + 0x1D, 0xF1, 0x55, 0x12, // 132:7665 + 0x1E, 0x46, 0x55, 0x12, // 133:7750 + 0x1E, 0x9B, 0x55, 0x12, // 134:7835 + 0x1E, 0xF0, 0x55, 0x12, // 135:7920 + 0x1F, 0x45, 0x55, 0x12, // 136:8005 + 0x1F, 0x9A, 0x55, 0x12, // 137:8090 + 0x1F, 0xEF, 0x55, 0x12, // 138:8175 + 0x20, 0x44, 0x55, 0x12, // 139:8260 + 0x20, 0x99, 0x55, 0x12, // 140:8345 + 0x20, 0xEE, 0x55, 0x12, // 141:8430 + 0x21, 0x43, 0x55, 0x12, // 142:8515 + 0x21, 0x98, 0x55, 0x12, // 143:8600 + 0x21, 0xED, 0x55, 0x12, // 144:8685 + 0x22, 0x42, 0x55, 0x12, // 145:8770 + 0x22, 0x97, 0x55, 0x12, // 146:8855 + 0x22, 0xEC, 0x55, 0x12, // 147:8940 + 0x23, 0x41, 0x55, 0x12, // 148:9025 + 0x23, 0x96, 0x55, 0x12, // 149:9110 + 0x23, 0xEB, 0x55, 0x12, // 150:9195 + 0x24, 0x40, 0x55, 0x12, // 151:9280 + 0x24, 0x95, 0x55, 0x12, // 152:9365 + 0x24, 0xEA, 0x55, 0x12, // 153:9450 + 0x25, 0x3F, 0x55, 0x12, // 154:9535 + 0x25, 0x94, 0x55, 0x12, // 155:9620 + 0x25, 0xE9, 0x55, 0x12, // 156:9705 + 0x26, 0x3E, 0x55, 0x12, // 157:9790 + 0x26, 0x93, 0x55, 0x12, // 158:9875 + 0x26, 0xE8, 0x55, 0x12, // 159:9960 + 0xFF, 0xFF, 0x00, 0x12, // 160:65535 + 0x27, 0x3D, 0x37, 0x12, // 161:10045 + 0x27, 0x74, 0x4A, 0x12, // 162:10100 + 0x27, 0xBE, 0x54, 0x12, // 163:10174 + 0x28, 0x12, 0x54, 0x12, // 164:10258 + 0x28, 0x66, 0x56, 0x12, // 165:10342 + 0x28, 0xBC, 0x32, 0x12, // 166:10428 + 0x28, 0xEE, 0x49, 0x12, // 167:10478 + 0x29, 0x37, 0x42, 0x12, // 168:10551 + 0x29, 0x79, 0x58, 0x12, // 169:10617 + 0x29, 0xD1, 0x49, 0x12, // 170:10705 + 0x2A, 0x1A, 0x4F, 0x12, // 171:10778 + 0x2A, 0x69, 0x4E, 0x12, // 172:10857 + 0x2A, 0xB7, 0x3F, 0x12, // 173:10935 + 0x2A, 0xF6, 0x58, 0x12, // 174:10998 + 0x2B, 0x4E, 0x43, 0x12, // 175:11086 + 0x2B, 0x91, 0x3E, 0x12, // 176:11153 + 0x2B, 0xCF, 0x4F, 0x12, // 177:11215 + 0x2C, 0x1E, 0x3F, 0x12, // 178:11294 + 0x2C, 0x5D, 0x43, 0x12, // 179:11357 + 0x2C, 0xA0, 0x42, 0x12, // 180:11424 + 0x2C, 0xE2, 0x59, 0x12, // 181:11490 + 0x2D, 0x3B, 0x4F, 0x12, // 182:11579 + 0x2D, 0x8A, 0x35, 0x12, // 183:11658 + 0x2D, 0xBF, 0x3C, 0x12, // 184:11711 + 0x2D, 0xFB, 0x3F, 0x12, // 185:11771 + 0x2E, 0x3A, 0x49, 0x12, // 186:11834 + 0x2E, 0x83, 0x53, 0x12, // 187:11907 + 0x2E, 0xD6, 0x54, 0x12, // 188:11990 + 0x2F, 0x2A, 0x4F, 0x12, // 189:12074 + 0x2F, 0x79, 0x54, 0x12, // 190:12153 + 0x2F, 0xCD, 0x4A, 0x12, // 191:12237 + 0x30, 0x17, 0x59, 0x12, // 192:12311 + 0x30, 0x70, 0x59, 0x12, // 193:12400 + 0x30, 0xC9, 0x59, 0x12, // 194:12489 + 0x31, 0x22, 0x59, 0x12, // 195:12578 + 0x31, 0x7B, 0x59, 0x12, // 196:12667 + 0x31, 0xD4, 0x59, 0x12, // 197:12756 + 0x32, 0x2D, 0x54, 0x12, // 198:12845 + 0x32, 0x81, 0x4F, 0x12, // 199:12929 + 0x32, 0xD0, 0x4F, 0x12, // 200:13008 + 0x33, 0x1F, 0x4F, 0x12, // 201:13087 + 0x33, 0x6E, 0x4F, 0x12, // 202:13166 + 0x33, 0xBD, 0x4F, 0x12, // 203:13245 + 0x34, 0x0C, 0x4F, 0x12, // 204:13324 + 0x34, 0x5B, 0x4F, 0x12, // 205:13403 + 0x34, 0xAA, 0x4F, 0x12, // 206:13482 + 0x34, 0xF9, 0x4F, 0x12, // 207:13561 + 0x35, 0x48, 0x4E, 0x12, // 208:13640 + 0x35, 0x96, 0x4F, 0x12, // 209:13718 + 0x35, 0xE5, 0x53, 0x12, // 210:13797 + 0x36, 0x38, 0x53, 0x12, // 211:13880 + 0x36, 0x8B, 0x53, 0x12, // 212:13963 + 0x36, 0xDE, 0x53, 0x12, // 213:14046 + 0x37, 0x31, 0x53, 0x12, // 214:14129 + 0x37, 0x84, 0x4F, 0x12, // 215:14212 + 0x37, 0xD3, 0x56, 0x12, // 216:14291 + 0x38, 0x29, 0x4E, 0x12, // 217:14377 + 0x38, 0x77, 0x4E, 0x12, // 218:14455 + 0x38, 0xC5, 0x4E, 0x12, // 219:14533 + 0x39, 0x13, 0x4E, 0x12, // 220:14611 + 0x39, 0x61, 0x56, 0x12, // 221:14689 + 0x39, 0xB7, 0x53, 0x12, // 222:14775 + 0x3A, 0x0A, 0x54, 0x12, // 223:14858 + 0x3A, 0x5E, 0x4F, 0x12, // 224:14942 + 0x3A, 0xAD, 0x4F, 0x12, // 225:15021 + 0x3A, 0xFC, 0x4F, 0x12, // 226:15100 + 0x3B, 0x4B, 0x4F, 0x12, // 227:15179 + 0x3B, 0x9A, 0x4F, 0x12, // 228:15258 + 0x3B, 0xE9, 0x4F, 0x12, // 229:15337 + 0x3C, 0x38, 0x59, 0x12, // 230:15416 + 0x3C, 0x91, 0x4F, 0x12, // 231:15505 + 0x3C, 0xE0, 0x53, 0x12, // 232:15584 + 0x3D, 0x33, 0x53, 0x12, // 233:15667 + 0x3D, 0x86, 0x53, 0x12, // 234:15750 + 0x3D, 0xD9, 0x53, 0x12, // 235:15833 + 0x3E, 0x2C, 0x4F, 0x12, // 236:15916 + 0x3E, 0x7B, 0x4F, 0x12, // 237:15995 + 0x3E, 0xCA, 0x4F, 0x12, // 238:16074 + 0x3F, 0x19, 0x4F, 0x12, // 239:16153 + 0x3F, 0x68, 0x4E, 0x12, // 240:16232 + 0x3F, 0xB6, 0x4F, 0x12, // 241:16310 + 0x40, 0x05, 0x4E, 0x12, // 242:16389 + 0x40, 0x53, 0x4E, 0x12, // 243:16467 + 0x40, 0xA1, 0x4E, 0x12, // 244:16545 + 0x40, 0xEF, 0x4E, 0x12, // 245:16623 + 0x41, 0x3D, 0x4E, 0x12, // 246:16701 + 0x41, 0x8B, 0x53, 0x12, // 247:16779 + 0x41, 0xDE, 0x52, 0x12, // 248:16862 + 0x42, 0x30, 0x4F, 0x12, // 249:16944 + 0x42, 0x7F, 0x4F, 0x12, // 250:17023 + 0x42, 0xCE, 0x4F, 0x12, // 251:17102 + 0x43, 0x1D, 0x4F, 0x12, // 252:17181 + 0x43, 0x6C, 0x52, 0x12, // 253:17260 + 0x43, 0xBE, 0x53, 0x12, // 254:17342 + 0x44, 0x11, 0x52, 0x12, // 255:17425 + + // Font Data: + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, + 0x1F, 0x0F, 0x00, 0xC0, 0xFF, 0x1F, 0x0F, 0x00, 0xC0, 0xFF, 0x1F, 0x0F, // 33 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x3F, 0x00, 0x00, 0x00, 0xC0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x3F, 0x00, 0x00, 0x00, 0xC0, 0x3F, // 34 + 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x38, 0x08, 0x00, 0x00, 0x70, 0xB8, 0x0F, 0x00, 0x00, + 0x70, 0xF8, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x01, 0x00, 0x00, 0xFC, 0x3F, 0x00, 0x00, 0x80, 0xFF, 0x38, 0x00, 0x00, 0xC0, 0x7F, + 0x38, 0x08, 0x00, 0xC0, 0x70, 0xB8, 0x0F, 0x00, 0x00, 0x70, 0xFC, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0xFC, 0x3F, + 0x00, 0x00, 0xC0, 0xFF, 0x38, 0x00, 0x00, 0xC0, 0x7F, 0x38, 0x00, 0x00, 0xC0, 0x70, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, + 0x00, 0x00, 0x70, // 35 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x01, 0x07, 0x00, 0x00, + 0xF8, 0x03, 0x07, 0x00, 0x00, 0xFC, 0x03, 0x0E, 0x00, 0x00, 0x1E, 0x07, 0x0E, 0x00, 0x00, 0x0E, 0x06, 0x0E, 0x00, 0x00, 0x0E, + 0x06, 0x0E, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0E, 0x0C, 0x0E, 0x00, 0x00, 0x0E, 0x0C, + 0x0E, 0x00, 0x00, 0x0E, 0x1C, 0x0F, 0x00, 0x00, 0x1C, 0xF8, 0x07, 0x00, 0x00, 0x1C, 0xF8, 0x03, 0x00, 0x00, 0x00, 0xE0, + 0x01, // 36 + 0x00, 0x1F, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x10, 0x00, 0x00, 0xC0, 0x71, 0x18, 0x00, 0x00, 0xC0, 0x60, 0x08, 0x00, 0x00, 0xC0, + 0x60, 0x0C, 0x00, 0x00, 0xC0, 0x60, 0x04, 0x00, 0x00, 0xC0, 0x71, 0x06, 0x00, 0x00, 0x80, 0x3F, 0x02, 0x00, 0x00, 0x00, 0x1F, + 0xE3, 0x03, 0x00, 0x00, 0x00, 0xF1, 0x07, 0x00, 0x00, 0x80, 0x39, 0x0E, 0x00, 0x00, 0x80, 0x18, 0x0C, 0x00, 0x00, 0xC0, 0x18, + 0x0C, 0x00, 0x00, 0x40, 0x18, 0x0C, 0x00, 0x00, 0x60, 0x38, 0x0E, 0x00, 0x00, 0x20, 0xF0, 0x07, 0x00, 0x00, 0x00, 0xC0, + 0x03, // 37 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x03, 0x00, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, + 0x1F, 0x87, 0x07, 0x00, 0x80, 0xFF, 0x03, 0x0F, 0x00, 0x80, 0xFF, 0x01, 0x0F, 0x00, 0xC0, 0xE3, 0x03, 0x0E, 0x00, 0xC0, 0x81, + 0x07, 0x0E, 0x00, 0xC0, 0x01, 0x1F, 0x0E, 0x00, 0xC0, 0x01, 0x3E, 0x0E, 0x00, 0xC0, 0x01, 0x7C, 0x07, 0x00, 0x80, 0x03, 0xF0, + 0x07, 0x00, 0x00, 0x00, 0xE0, 0x03, 0x00, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0xE0, 0x0F, 0x00, 0x00, 0x00, 0x7E, 0x0E, + 0x00, 0x00, 0x00, 0x1E, 0x08, // 38 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x3F, + 0x00, 0x00, 0x00, 0xC0, 0x3F, // 39 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x7F, 0x00, 0x00, 0x00, 0xF8, 0xFF, 0x03, 0x00, 0x00, 0xFE, + 0xFF, 0x0F, 0x00, 0x80, 0x3F, 0x80, 0x3F, 0x00, 0xE0, 0x03, 0x00, 0xF8, 0x00, 0xE0, 0x00, 0x00, 0xE0, 0x00, 0x20, 0x00, 0x00, + 0x80, // 40 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x80, 0x00, 0xE0, 0x00, 0x00, 0xE0, 0x00, 0xE0, 0x03, 0x00, 0xF8, 0x00, 0x80, 0x3F, + 0x80, 0x3F, 0x00, 0x00, 0xFE, 0xFF, 0x0F, 0x00, 0x00, 0xF8, 0xFF, 0x03, 0x00, 0x00, 0xC0, 0x7F, // 41 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x86, 0x01, 0x00, 0x00, 0x00, + 0xCC, 0x00, 0x00, 0x00, 0x00, 0xCC, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0xC0, 0xFF, + 0x0F, 0x00, 0x00, 0xC0, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0xCC, 0x00, + 0x00, 0x00, 0x00, 0xCC, 0x00, 0x00, 0x00, 0x00, 0x86, 0x01, 0x00, 0x00, 0x00, 0x84, // 42 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, + 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0xF8, + 0xFF, 0x07, 0x00, 0x00, 0xF8, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, + 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, // 43 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xFF, 0x01, 0x00, 0x00, + 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x0F, // 44 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x18, // 45 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, + 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, // 46 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, + 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0xF8, 0x03, 0x00, 0x00, 0x00, + 0xFE, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0xE0, 0x0F, 0x00, 0x00, 0x00, 0xF8, 0x03, 0x00, 0x00, 0x00, 0x7E, 0x00, + 0x00, 0x00, 0x80, 0x1F, 0x00, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0x40, // 47 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, + 0xFF, 0xFF, 0x03, 0x00, 0x80, 0x0F, 0xC0, 0x07, 0x00, 0xC0, 0x03, 0x00, 0x0F, 0x00, 0xC0, 0x01, 0x06, 0x0E, 0x00, 0xC0, 0x01, + 0x07, 0x0E, 0x00, 0xC0, 0x01, 0x07, 0x0E, 0x00, 0xC0, 0x01, 0x02, 0x0E, 0x00, 0xC0, 0x03, 0x00, 0x0F, 0x00, 0x80, 0x0F, 0xC0, + 0x07, 0x00, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, 0xF0, 0x3F, // 48 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0x03, 0x00, 0x0E, 0x00, 0x80, 0x03, 0x00, 0x0E, 0x00, 0xC0, 0x03, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, + 0x00, 0x0E, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, + 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, + 0x0E, // 49 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x0E, 0x00, 0x80, 0x03, 0x00, 0x0F, 0x00, 0xC0, + 0x01, 0x80, 0x0F, 0x00, 0xC0, 0x01, 0xC0, 0x0F, 0x00, 0xC0, 0x01, 0xE0, 0x0E, 0x00, 0xC0, 0x01, 0xF0, 0x0E, 0x00, 0xC0, 0x01, + 0x78, 0x0E, 0x00, 0xC0, 0x01, 0x3C, 0x0E, 0x00, 0xC0, 0x01, 0x1E, 0x0E, 0x00, 0xC0, 0x03, 0x0F, 0x0E, 0x00, 0x80, 0x87, 0x0F, + 0x0E, 0x00, 0x80, 0xFF, 0x07, 0x0E, 0x00, 0x00, 0xFF, 0x01, 0x0E, 0x00, 0x00, 0xFC, 0x00, 0x0E, // 50 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x80, 0x03, 0x00, 0x07, 0x00, 0x80, + 0x03, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, + 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0xC1, 0x03, 0x0E, 0x00, 0x80, 0xC3, 0x06, 0x0F, 0x00, 0x80, 0xFF, 0x8E, + 0x07, 0x00, 0x00, 0x7F, 0xFE, 0x07, 0x00, 0x00, 0x3E, 0xFC, 0x03, 0x00, 0x00, 0x00, 0xF0, // 51 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, + 0x00, 0x7F, 0x00, 0x00, 0x00, 0xC0, 0x77, 0x00, 0x00, 0x00, 0xE0, 0x71, 0x00, 0x00, 0x00, 0x78, 0x70, 0x00, 0x00, 0x00, 0x1E, + 0x70, 0x00, 0x00, 0x00, 0x0F, 0x70, 0x00, 0x00, 0xC0, 0x03, 0x70, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, + 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x70, // 52 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0x03, 0x07, 0x00, 0xC0, + 0xFF, 0x01, 0x0E, 0x00, 0xC0, 0xFF, 0x01, 0x0E, 0x00, 0xC0, 0xC1, 0x01, 0x0E, 0x00, 0xC0, 0xC1, 0x01, 0x0E, 0x00, 0xC0, 0xC1, + 0x01, 0x0E, 0x00, 0xC0, 0xC1, 0x01, 0x0E, 0x00, 0xC0, 0xC1, 0x03, 0x0E, 0x00, 0xC0, 0xC1, 0x03, 0x07, 0x00, 0xC0, 0x81, 0x87, + 0x07, 0x00, 0xC0, 0x81, 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0xFC, // 53 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0x01, 0x00, 0x00, + 0xFF, 0xFF, 0x03, 0x00, 0x80, 0x1F, 0x87, 0x07, 0x00, 0x80, 0x87, 0x03, 0x0F, 0x00, 0xC0, 0x83, 0x01, 0x0E, 0x00, 0xC0, 0xC1, + 0x01, 0x0E, 0x00, 0xC0, 0xC1, 0x01, 0x0E, 0x00, 0xC0, 0xC1, 0x01, 0x0E, 0x00, 0xC0, 0xC1, 0x03, 0x0F, 0x00, 0xC0, 0x81, 0x87, + 0x07, 0x00, 0x80, 0x83, 0xFF, 0x07, 0x00, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, // 54 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, + 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x08, 0x00, 0xC0, 0x01, 0x00, 0x0F, 0x00, 0xC0, 0x01, 0xE0, 0x0F, 0x00, 0xC0, 0x01, + 0xF8, 0x07, 0x00, 0xC0, 0x01, 0xFF, 0x01, 0x00, 0xC0, 0xE1, 0x3F, 0x00, 0x00, 0xC0, 0xF9, 0x07, 0x00, 0x00, 0xC0, 0xFF, 0x01, + 0x00, 0x00, 0xC0, 0x3F, 0x00, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0xC0, 0x01, // 55 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x01, 0x00, 0x00, 0x3E, 0xFC, 0x03, 0x00, 0x00, + 0x7F, 0xFE, 0x07, 0x00, 0x80, 0xFF, 0x8E, 0x07, 0x00, 0xC0, 0xC3, 0x06, 0x0F, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, + 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0xC3, 0x06, 0x0F, 0x00, 0x80, 0xFF, 0x8E, + 0x07, 0x00, 0x00, 0x7F, 0xFE, 0x07, 0x00, 0x00, 0x3E, 0xFC, 0x03, 0x00, 0x00, 0x00, 0xF8, 0x01, // 56 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, 0x80, + 0xFF, 0x07, 0x07, 0x00, 0x80, 0x87, 0x07, 0x0E, 0x00, 0xC0, 0x03, 0x0F, 0x0E, 0x00, 0xC0, 0x01, 0x0E, 0x0E, 0x00, 0xC0, 0x01, + 0x0E, 0x0E, 0x00, 0xC0, 0x01, 0x0E, 0x0E, 0x00, 0xC0, 0x01, 0x0E, 0x0F, 0x00, 0xC0, 0x03, 0x87, 0x07, 0x00, 0x80, 0x87, 0xE1, + 0x07, 0x00, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0xFE, 0xFF, 0x00, 0x00, 0x00, 0xF0, 0x3F, // 57 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x0F, 0x00, 0x00, 0xF0, + 0x00, 0x0F, 0x00, 0x00, 0xF0, 0x00, 0x0F, 0x00, 0x00, 0xF0, 0x00, 0x0F, // 58 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0xF0, 0x00, 0xFF, 0x01, 0x00, 0xF0, + 0x00, 0xFF, 0x00, 0x00, 0xF0, 0x00, 0x3F, 0x00, 0x00, 0xF0, 0x00, 0x0F, // 59 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, + 0x00, 0x1B, 0x00, 0x00, 0x00, 0x80, 0x3B, 0x00, 0x00, 0x00, 0x80, 0x33, 0x00, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0xC0, + 0x71, 0x00, 0x00, 0x00, 0xC0, 0x60, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x70, 0xC0, + 0x01, 0x00, 0x00, 0x70, 0xC0, 0x01, 0x00, 0x00, 0x30, 0x80, 0x01, 0x00, 0x00, 0x38, 0x80, 0x03, // 60 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, + 0x80, 0x31, 0x00, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x80, + 0x31, 0x00, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x80, 0x31, + 0x00, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x80, 0x31, // 61 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x80, 0x03, 0x00, 0x00, 0x30, 0x80, 0x01, 0x00, 0x00, 0x70, 0xC0, 0x01, 0x00, 0x00, + 0x70, 0xC0, 0x01, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0xC0, 0x60, 0x00, 0x00, 0x00, 0xC0, + 0x71, 0x00, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x80, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x1B, + 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, // 62 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x80, + 0x03, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x3E, 0x0F, 0x00, 0xC0, 0x01, + 0x3F, 0x0F, 0x00, 0xC0, 0xC1, 0x3F, 0x0F, 0x00, 0xC0, 0xC1, 0x03, 0x00, 0x00, 0xC0, 0xF3, 0x01, 0x00, 0x00, 0x80, 0xFF, 0x00, + 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x1E, // 63 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x01, 0x00, 0x00, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xF0, 0x00, 0x1F, 0x00, 0x00, + 0x38, 0x00, 0x38, 0x00, 0x00, 0x0C, 0x00, 0x70, 0x00, 0x00, 0x0E, 0x7C, 0xE0, 0x00, 0x00, 0x06, 0xFF, 0xC1, 0x00, 0x00, 0x83, + 0x83, 0xC3, 0x00, 0x00, 0x83, 0x01, 0x87, 0x01, 0x00, 0xC3, 0x00, 0x86, 0x01, 0x00, 0xC3, 0x00, 0x86, 0x01, 0x00, 0xC3, 0x00, + 0x86, 0x01, 0x00, 0xC7, 0x00, 0x86, 0x01, 0x00, 0x86, 0x01, 0xC3, 0x01, 0x00, 0x9E, 0x83, 0xC3, 0x01, 0x00, 0xFC, 0xFF, 0x07, + 0x00, 0x00, 0xF0, 0xFF, 0x07, // 64 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, + 0x00, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0xFC, 0x7F, 0x00, 0x00, 0x80, 0xFF, 0x71, 0x00, 0x00, 0xC0, 0x3F, + 0x70, 0x00, 0x00, 0xC0, 0x03, 0x70, 0x00, 0x00, 0xC0, 0x3F, 0x70, 0x00, 0x00, 0x80, 0xFF, 0x71, 0x00, 0x00, 0x00, 0xFC, 0x7F, + 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0x80, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x0C, // 65 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, + 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0xC3, 0x07, 0x0F, 0x00, 0x80, 0xFF, 0x0E, + 0x07, 0x00, 0x00, 0x7F, 0xFE, 0x07, 0x00, 0x00, 0x3E, 0xFC, 0x03, 0x00, 0x00, 0x00, 0xF0, 0x01, // 66 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x1F, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0x00, 0x00, 0x00, + 0xFE, 0xFF, 0x01, 0x00, 0x00, 0x1F, 0xE0, 0x03, 0x00, 0x80, 0x07, 0x80, 0x07, 0x00, 0x80, 0x03, 0x00, 0x07, 0x00, 0xC0, 0x01, + 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, + 0x0E, 0x00, 0xC0, 0x03, 0x00, 0x0E, 0x00, 0x80, 0x03, 0x00, 0x07, 0x00, 0x00, 0x07, 0x80, 0x03, // 67 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, + 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0x80, 0x03, 0x00, 0x07, 0x00, 0x80, 0x07, 0x80, 0x07, 0x00, 0x00, 0x1F, 0xE0, + 0x03, 0x00, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0xFC, 0xFF, 0x00, 0x00, 0x00, 0xF0, 0x3F, // 68 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, + 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, + 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, // 69 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0x81, 0x03, 0x00, 0x00, 0xC0, 0x81, 0x03, 0x00, 0x00, 0xC0, 0x81, + 0x03, 0x00, 0x00, 0xC0, 0x81, 0x03, 0x00, 0x00, 0xC0, 0x81, 0x03, 0x00, 0x00, 0xC0, 0x81, 0x03, 0x00, 0x00, 0xC0, 0x81, 0x03, + 0x00, 0x00, 0xC0, 0x81, 0x03, 0x00, 0x00, 0xC0, 0x81, 0x03, 0x00, 0x00, 0xC0, 0x01, // 70 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x1F, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0x00, 0x00, 0x00, + 0xFE, 0xFF, 0x01, 0x00, 0x00, 0x1F, 0xE0, 0x03, 0x00, 0x80, 0x07, 0x80, 0x07, 0x00, 0x80, 0x03, 0x00, 0x07, 0x00, 0xC0, 0x01, + 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x07, 0x0E, 0x00, 0xC0, 0x01, 0x07, + 0x0E, 0x00, 0xC0, 0x01, 0x07, 0x0F, 0x00, 0x80, 0x03, 0xFF, 0x07, 0x00, 0x00, 0x07, 0xFF, 0x07, 0x00, 0x00, 0x00, 0xFF, + 0x03, // 71 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x80, + 0x03, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x80, 0x03, + 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, // 72 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, + 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0xFF, + 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, + 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, // 73 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, + 0x00, 0x00, 0x07, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, + 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x07, 0x00, 0xC0, 0xFF, 0xFF, + 0x03, 0x00, 0xC0, 0xFF, 0xFF, // 74 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x00, 0xE0, 0x03, 0x00, 0x00, 0x00, 0xF0, + 0x07, 0x00, 0x00, 0x00, 0xF8, 0x1F, 0x00, 0x00, 0x00, 0x3C, 0x3E, 0x00, 0x00, 0x00, 0x1E, 0xFC, 0x00, 0x00, 0x00, 0x0F, 0xF0, + 0x01, 0x00, 0x80, 0x03, 0xE0, 0x07, 0x00, 0xC0, 0x01, 0x80, 0x0F, 0x00, 0xC0, 0x00, 0x00, 0x0F, 0x00, 0x40, 0x00, 0x00, 0x0C, + 0x00, 0x00, 0x00, 0x00, 0x08, // 75 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, + 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, + 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, + 0x0E, // 76 + 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0x03, 0x00, 0x00, 0x00, 0x80, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x80, 0x1F, 0x00, + 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, + 0x0F, // 77 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xE0, + 0x07, 0x00, 0x00, 0x00, 0x80, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x03, 0x00, 0x00, 0x00, 0x80, + 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, // 78 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, + 0xFF, 0xFF, 0x03, 0x00, 0x80, 0x0F, 0xC0, 0x07, 0x00, 0x80, 0x03, 0x00, 0x07, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, + 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0x80, 0x03, 0x00, + 0x07, 0x00, 0x80, 0x0F, 0xC0, 0x07, 0x00, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, 0xF0, 0x3F, // 79 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0x01, 0x07, 0x00, 0x00, 0xC0, 0x01, 0x07, 0x00, 0x00, 0xC0, 0x01, + 0x07, 0x00, 0x00, 0xC0, 0x01, 0x07, 0x00, 0x00, 0xC0, 0x01, 0x07, 0x00, 0x00, 0xC0, 0x01, 0x07, 0x00, 0x00, 0xC0, 0x83, 0x07, + 0x00, 0x00, 0x80, 0xC7, 0x03, 0x00, 0x00, 0x80, 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x7C, // 80 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, + 0xFF, 0xFF, 0x03, 0x00, 0x80, 0x0F, 0xC0, 0x07, 0x00, 0x80, 0x03, 0x00, 0x07, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, + 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x3E, 0x00, 0x80, 0x03, 0x00, + 0x7F, 0x00, 0x80, 0x0F, 0xC0, 0xF7, 0x00, 0x00, 0xFF, 0xFF, 0x63, 0x00, 0x00, 0xFE, 0xFF, 0x41, 0x00, 0x00, 0xF0, 0x3F, // 81 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0x01, 0x07, 0x00, 0x00, 0xC0, 0x01, 0x07, 0x00, 0x00, 0xC0, 0x01, 0x07, 0x00, 0x00, 0xC0, 0x01, + 0x07, 0x00, 0x00, 0xC0, 0x01, 0x07, 0x00, 0x00, 0xC0, 0x01, 0x0F, 0x00, 0x00, 0xC0, 0x83, 0x1F, 0x00, 0x00, 0x80, 0xC7, 0x7D, + 0x00, 0x00, 0x80, 0xFF, 0xF9, 0x01, 0x00, 0x00, 0xFF, 0xF0, 0x07, 0x00, 0x00, 0x7C, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0E, + 0x00, 0x00, 0x00, 0x00, 0x08, // 82 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x07, 0x00, 0x00, 0xFF, 0x00, 0x07, 0x00, 0x80, + 0xFF, 0x01, 0x0E, 0x00, 0x80, 0xC7, 0x01, 0x0E, 0x00, 0xC0, 0xC3, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, + 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x07, 0x0E, 0x00, 0xC0, 0x01, 0x07, 0x0E, 0x00, 0xC0, 0x01, 0x07, 0x0F, 0x00, 0xC0, 0x01, 0x8F, + 0x07, 0x00, 0x80, 0x03, 0xFE, 0x07, 0x00, 0x80, 0x03, 0xFC, 0x03, 0x00, 0x00, 0x00, 0xF8, 0x01, // 83 + 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, + 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0xFF, + 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, + 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, + 0x00, 0xC0, 0x01, // 84 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x03, 0x00, 0xC0, + 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, + 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x80, + 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0x03, 0x00, 0xC0, 0xFF, 0xFF, // 85 + 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0xC0, 0x7F, 0x00, 0x00, 0x00, 0x80, + 0xFF, 0x03, 0x00, 0x00, 0x00, 0xF8, 0x3F, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x01, 0x00, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0x00, + 0xE0, 0x0F, 0x00, 0x00, 0x00, 0xE0, 0x0F, 0x00, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xC0, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0x3F, + 0x00, 0x00, 0x80, 0xFF, 0x03, 0x00, 0x00, 0xC0, 0x7F, 0x00, 0x00, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0xC0, // 86 + 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x0F, 0x00, 0x00, + 0x00, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0xE0, 0x0F, 0x00, 0x00, 0x00, 0xFE, 0x03, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xF0, + 0x01, 0x00, 0x00, 0x00, 0xF0, 0x01, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x03, 0x00, 0x00, 0x00, 0xE0, + 0x0F, 0x00, 0x00, 0x00, 0xFF, 0x0F, 0x00, 0x00, 0xFE, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0x7F, 0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, + 0x00, 0xC0, 0x01, // 87 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x08, 0x00, 0xC0, 0x00, 0x00, 0x0E, 0x00, 0xC0, 0x03, 0x00, 0x0F, 0x00, 0xC0, + 0x07, 0xC0, 0x0F, 0x00, 0x80, 0x1F, 0xE0, 0x03, 0x00, 0x00, 0x3E, 0xF8, 0x01, 0x00, 0x00, 0x7C, 0x7E, 0x00, 0x00, 0x00, 0xF0, + 0x1F, 0x00, 0x00, 0x00, 0xE0, 0x0F, 0x00, 0x00, 0x00, 0xE0, 0x0F, 0x00, 0x00, 0x00, 0xF8, 0x3F, 0x00, 0x00, 0x00, 0x7C, 0x7C, + 0x00, 0x00, 0x00, 0x3E, 0xF8, 0x01, 0x00, 0x80, 0x0F, 0xE0, 0x03, 0x00, 0xC0, 0x07, 0xC0, 0x0F, 0x00, 0xC0, 0x03, 0x00, 0x0F, + 0x00, 0xC0, 0x00, 0x00, 0x0C, // 88 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x00, 0xC0, + 0x0F, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x01, 0x00, 0x00, 0x00, 0xE0, + 0xFF, 0x0F, 0x00, 0x00, 0x80, 0xFF, 0x0F, 0x00, 0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0xF8, 0x01, 0x00, 0x00, 0x00, 0xFC, 0x00, + 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, + 0x00, 0x40, // 89 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x80, 0x0F, 0x00, 0xC0, + 0x01, 0xC0, 0x0F, 0x00, 0xC0, 0x01, 0xF0, 0x0F, 0x00, 0xC0, 0x01, 0xF8, 0x0E, 0x00, 0xC0, 0x01, 0x7E, 0x0E, 0x00, 0xC0, 0x01, + 0x1F, 0x0E, 0x00, 0xC0, 0xC1, 0x0F, 0x0E, 0x00, 0xC0, 0xE1, 0x03, 0x0E, 0x00, 0xC0, 0xF9, 0x01, 0x0E, 0x00, 0xC0, 0x7D, 0x00, + 0x0E, 0x00, 0xC0, 0x3F, 0x00, 0x0E, 0x00, 0xC0, 0x0F, 0x00, 0x0E, 0x00, 0xC0, 0x07, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, + 0x0E, // 90 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x00, 0xE0, 0xFF, + 0xFF, 0xFF, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x00, 0xE0, 0x00, 0x00, 0xE0, 0x00, 0xE0, 0x00, 0x00, 0xE0, 0x00, 0xE0, 0x00, 0x00, + 0xE0, 0x00, 0xE0, 0x00, 0x00, 0xE0, // 91 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, + 0x07, 0x00, 0x00, 0x00, 0x80, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x01, 0x00, 0x00, 0x00, 0xE0, + 0x0F, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x03, 0x00, 0x00, 0x00, 0xC0, + 0x0F, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, + 0x40, // 92 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0xE0, 0x00, 0xE0, 0x00, 0x00, 0xE0, 0x00, 0xE0, 0x00, 0x00, 0xE0, 0x00, 0xE0, 0x00, + 0x00, 0xE0, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, // 93 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, + 0x1C, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x00, 0xC0, 0x01, + 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, + 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x20, // 94 + 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, + 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, // 95 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x02, // 96 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0xC0, 0xF1, 0x07, 0x00, 0x00, + 0xE0, 0xF8, 0x07, 0x00, 0x00, 0xE0, 0x38, 0x0F, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0x70, + 0x1C, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x06, 0x00, 0x00, 0x70, 0x1C, 0x07, 0x00, 0x00, 0xE0, 0x9C, + 0x01, 0x00, 0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0xC0, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0xFF, 0x0F, // 97 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0x0F, 0x00, 0xE0, + 0xFF, 0xFF, 0x0F, 0x00, 0xE0, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xC0, 0x81, 0x03, 0x00, 0x00, 0xE0, 0x00, 0x07, 0x00, 0x00, 0x70, + 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0xF0, 0x00, + 0x0F, 0x00, 0x00, 0xE0, 0x81, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFF, // 98 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, + 0x80, 0xFF, 0x01, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0xE0, 0xC3, 0x07, 0x00, 0x00, 0xE0, 0x00, 0x07, 0x00, 0x00, 0xF0, + 0x00, 0x0F, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, + 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0xE0, 0x00, 0x07, 0x00, 0x00, 0xC0, 0x81, 0x03, // 99 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, + 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0x81, 0x07, 0x00, 0x00, 0xF0, 0x00, 0x0F, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, + 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0xE0, 0x00, 0x07, 0x00, 0x00, 0xC0, 0x81, + 0x03, 0x00, 0xE0, 0xFF, 0xFF, 0x0F, 0x00, 0xE0, 0xFF, 0xFF, 0x0F, 0x00, 0xE0, 0xFF, 0xFF, 0x0F, // 100 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x01, 0x00, 0x00, + 0xC0, 0xFF, 0x03, 0x00, 0x00, 0xE0, 0x9D, 0x07, 0x00, 0x00, 0xE0, 0x1C, 0x07, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0x70, + 0x1C, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0xF0, 0x1C, + 0x0E, 0x00, 0x00, 0xE0, 0x1C, 0x07, 0x00, 0x00, 0xE0, 0x1F, 0x07, 0x00, 0x00, 0xC0, 0x9F, 0x03, 0x00, 0x00, 0x00, 0x1F, // 101 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, + 0x70, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, + 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xE0, 0x71, 0x00, 0x00, 0x00, 0xE0, 0x70, 0x00, 0x00, 0x00, 0xE0, 0x70, 0x00, + 0x00, 0x00, 0xE0, 0x70, 0x00, 0x00, 0x00, 0xE0, 0x70, 0x00, 0x00, 0x00, 0xE0, 0x70, // 102 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, + 0xE0, 0xFF, 0xC7, 0x01, 0x00, 0xE0, 0x81, 0xC7, 0x01, 0x00, 0xF0, 0x00, 0x8F, 0x03, 0x00, 0x70, 0x00, 0x8E, 0x03, 0x00, 0x70, + 0x00, 0x8E, 0x03, 0x00, 0x70, 0x00, 0x8E, 0x03, 0x00, 0x70, 0x00, 0x8E, 0x03, 0x00, 0xE0, 0x00, 0xC7, 0x03, 0x00, 0xC0, 0x81, + 0xE3, 0x01, 0x00, 0xF0, 0xFF, 0xFF, 0x01, 0x00, 0xF0, 0xFF, 0xFF, 0x00, 0x00, 0xF0, 0xFF, 0x3F, // 103 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0x0F, 0x00, 0xE0, + 0xFF, 0xFF, 0x0F, 0x00, 0xE0, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x60, + 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, + 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0xFF, 0x0F, // 104 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, + 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0xE0, 0xF0, + 0xFF, 0x0F, 0x00, 0xE0, 0xF0, 0xFF, 0x0F, 0x00, 0xE0, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, + 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, // 105 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, + 0x70, 0x00, 0x80, 0x03, 0x00, 0x70, 0x00, 0x80, 0x03, 0x00, 0x70, 0x00, 0x80, 0x03, 0x00, 0x70, 0x00, 0x80, 0x03, 0x00, 0x70, + 0x00, 0xC0, 0x03, 0xE0, 0xF0, 0xFF, 0xFF, 0x01, 0xE0, 0xF0, 0xFF, 0xFF, 0x00, 0xE0, 0xF0, 0xFF, 0x7F, // 106 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0x0F, 0x00, 0xE0, + 0xFF, 0xFF, 0x0F, 0x00, 0xE0, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x00, + 0x1F, 0x00, 0x00, 0x00, 0x80, 0x7F, 0x00, 0x00, 0x00, 0xC0, 0xFB, 0x00, 0x00, 0x00, 0xE0, 0xF3, 0x03, 0x00, 0x00, 0xF0, 0xC1, + 0x07, 0x00, 0x00, 0xF0, 0x80, 0x0F, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x30, 0x00, 0x0C, 0x00, 0x00, 0x10, 0x00, + 0x08, // 107 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0xE0, + 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0x01, 0x00, 0xE0, 0xFF, + 0xFF, 0x03, 0x00, 0xE0, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, + 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, // 108 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, + 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0xF0, + 0xFF, 0x0F, 0x00, 0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0xFF, 0x0F, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, + 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0xC0, 0xFF, + 0x0F, // 109 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, + 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x60, + 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, + 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0xFF, 0x0F, // 110 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, + 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0x81, 0x07, 0x00, 0x00, 0xF0, 0x00, 0x0F, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, + 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0xF0, 0x00, 0x0F, 0x00, 0x00, 0xE0, 0x81, + 0x07, 0x00, 0x00, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFF, // 111 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0x03, 0x00, + 0xF0, 0xFF, 0xFF, 0x03, 0x00, 0xF0, 0xFF, 0xFF, 0x03, 0x00, 0xC0, 0x81, 0x03, 0x00, 0x00, 0xE0, 0x00, 0x07, 0x00, 0x00, 0x70, + 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0xF0, 0x00, + 0x0F, 0x00, 0x00, 0xE0, 0x81, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFF, // 112 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, + 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0x81, 0x07, 0x00, 0x00, 0xF0, 0x00, 0x0F, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, + 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0xE0, 0x00, 0x07, 0x00, 0x00, 0xC0, 0x81, + 0x03, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0x03, 0x00, 0xF0, 0xFF, 0xFF, 0x03, 0x00, 0xF0, 0xFF, 0xFF, 0x03, // 113 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0x80, + 0x03, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, + 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0xE0, // 114 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x83, 0x03, 0x00, 0x00, + 0xE0, 0x07, 0x07, 0x00, 0x00, 0xE0, 0x0F, 0x07, 0x00, 0x00, 0xF0, 0x0E, 0x0E, 0x00, 0x00, 0x70, 0x0E, 0x0E, 0x00, 0x00, 0x70, + 0x0E, 0x0E, 0x00, 0x00, 0x70, 0x1E, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x0F, 0x00, 0x00, 0x70, 0xFC, + 0x07, 0x00, 0x00, 0xE0, 0xF8, 0x07, 0x00, 0x00, 0x00, 0xF0, 0x01, // 115 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, + 0x70, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x03, 0x00, 0x80, 0xFF, 0xFF, 0x07, 0x00, 0x80, 0xFF, + 0xFF, 0x0F, 0x00, 0x00, 0x70, 0x00, 0x0F, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, + 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, // 116 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x01, 0x00, 0x00, + 0xF0, 0xFF, 0x07, 0x00, 0x00, 0xF0, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, + 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x80, + 0x01, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, // 117 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x07, 0x00, 0x00, 0x00, + 0xE0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x07, 0x00, 0x00, 0x00, 0xE0, 0x0F, 0x00, 0x00, 0x00, + 0x00, 0x0F, 0x00, 0x00, 0x00, 0xE0, 0x0F, 0x00, 0x00, 0x00, 0xFC, 0x07, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xE0, 0x3F, + 0x00, 0x00, 0x00, 0xF0, 0x07, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x10, // 118 + 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x03, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x07, 0x00, 0x00, + 0x00, 0xFC, 0x0F, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0xFC, 0x01, 0x00, 0x00, 0x00, + 0x1E, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0xC0, + 0x0F, 0x00, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xC0, 0xFF, 0x07, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xF0, 0x03, 0x00, + 0x00, 0x00, 0x30, // 119 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x30, 0x00, 0x0E, 0x00, 0x00, + 0x70, 0x00, 0x0F, 0x00, 0x00, 0xF0, 0xC1, 0x07, 0x00, 0x00, 0xE0, 0xE3, 0x03, 0x00, 0x00, 0xC0, 0xFF, 0x01, 0x00, 0x00, 0x00, + 0x7F, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x01, 0x00, 0x00, 0xE0, 0xE3, 0x03, 0x00, 0x00, 0xF0, 0xC1, + 0x07, 0x00, 0x00, 0x70, 0x00, 0x0F, 0x00, 0x00, 0x30, 0x00, 0x0E, 0x00, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, + 0x08, // 120 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x80, 0x03, 0x00, + 0xF0, 0x03, 0x80, 0x03, 0x00, 0xE0, 0x1F, 0x80, 0x03, 0x00, 0x80, 0x7F, 0xC0, 0x03, 0x00, 0x00, 0xFC, 0xF3, 0x01, 0x00, 0x00, + 0xF0, 0xFF, 0x01, 0x00, 0x00, 0xC0, 0x7F, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0xFE, 0x03, 0x00, 0x00, 0x80, 0x7F, + 0x00, 0x00, 0x00, 0xE0, 0x1F, 0x00, 0x00, 0x00, 0xF0, 0x03, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x10, // 121 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, + 0x70, 0x00, 0x0F, 0x00, 0x00, 0x70, 0xC0, 0x0F, 0x00, 0x00, 0x70, 0xE0, 0x0F, 0x00, 0x00, 0x70, 0xF8, 0x0F, 0x00, 0x00, 0x70, + 0x7C, 0x0E, 0x00, 0x00, 0x70, 0x3F, 0x0E, 0x00, 0x00, 0xF0, 0x0F, 0x0E, 0x00, 0x00, 0xF0, 0x07, 0x0E, 0x00, 0x00, 0xF0, 0x03, + 0x0E, 0x00, 0x00, 0xF0, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, // 122 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, + 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x80, 0xFF, + 0xFB, 0x7F, 0x00, 0xC0, 0xFF, 0xFB, 0xFF, 0x00, 0xE0, 0xFF, 0xF1, 0xFF, 0x01, 0xE0, 0x01, 0x00, 0xE0, 0x01, 0xE0, 0x00, 0x00, + 0xC0, 0x01, 0xE0, 0x00, 0x00, 0xC0, 0x01, 0xE0, 0x00, 0x00, 0xC0, 0x01, // 123 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, + 0xFF, 0xFF, 0x07, 0xE0, 0xFF, 0xFF, 0xFF, 0x07, // 124 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, + 0x00, 0x00, 0xC0, 0x01, 0xE0, 0x00, 0x00, 0xC0, 0x01, 0xE0, 0x00, 0x00, 0xC0, 0x01, 0xE0, 0x01, 0x00, 0xE0, 0x01, 0xE0, 0xFF, + 0xF1, 0xFF, 0x00, 0xC0, 0xFF, 0xFB, 0xFF, 0x00, 0x80, 0xFF, 0xFB, 0x7F, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x0E, + 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, // 125 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, + 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, + 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0E, // 126 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 127 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 128 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 129 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 130 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 131 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 132 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 133 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 134 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 135 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 136 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 137 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 138 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 139 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 140 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 141 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 142 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 143 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 144 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 145 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 146 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 147 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 148 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 149 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 150 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 151 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 152 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 153 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 154 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 155 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 156 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 157 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 158 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, + 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, + 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, + 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x80, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, // 159 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, + 0xF8, 0xFF, 0x03, 0x00, 0xF0, 0xF8, 0xFF, 0x03, 0x00, 0xF0, 0xF8, 0xFF, 0x03, // 161 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, + 0x80, 0xFF, 0x01, 0x00, 0x00, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0x81, 0x07, 0x00, 0x00, 0xF0, 0x00, 0x0F, 0x00, 0x00, 0x70, + 0x00, 0x0E, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, + 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0xE0, 0x00, 0x07, // 162 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0E, 0x00, 0x00, + 0x00, 0x07, 0x0E, 0x00, 0x00, 0x00, 0x07, 0x0E, 0x00, 0x00, 0xFC, 0xFF, 0x0F, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x00, 0x80, 0xFF, + 0xFF, 0x0F, 0x00, 0x80, 0x07, 0x07, 0x0E, 0x00, 0xC0, 0x03, 0x07, 0x0E, 0x00, 0xC0, 0x01, 0x07, 0x0E, 0x00, 0xC0, 0x01, 0x07, + 0x0E, 0x00, 0xC0, 0x01, 0x07, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0x80, 0x03, 0x00, + 0x0E, // 163 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, + 0x70, 0x80, 0x03, 0x00, 0x00, 0xE0, 0xDE, 0x01, 0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, 0x00, 0x80, 0x61, 0x00, 0x00, 0x00, 0xC0, + 0xC0, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x80, 0x61, + 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, 0x00, 0xE0, 0xDE, 0x01, 0x00, 0x00, 0x70, 0x80, 0x03, 0x00, 0x00, 0x20, 0x00, + 0x01, // 164 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC1, 0x18, 0x00, 0x00, 0xC0, 0xC3, 0x18, 0x00, 0x00, 0xC0, + 0xCF, 0x18, 0x00, 0x00, 0x00, 0xFF, 0x18, 0x00, 0x00, 0x00, 0xFC, 0x18, 0x00, 0x00, 0x00, 0xF8, 0x1B, 0x00, 0x00, 0x00, 0xE0, + 0xFF, 0x0F, 0x00, 0x00, 0x80, 0xFF, 0x0F, 0x00, 0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0xF8, 0x1B, 0x00, 0x00, 0x00, 0xFC, 0x18, + 0x00, 0x00, 0x00, 0xFF, 0x18, 0x00, 0x00, 0xC0, 0xCF, 0x18, 0x00, 0x00, 0xC0, 0xC3, 0x18, 0x00, 0x00, 0xC0, 0xC1, 0x18, 0x00, + 0x00, 0x40, // 165 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, + 0xC3, 0xFF, 0x01, 0x80, 0xFF, 0xC3, 0xFF, 0x01, // 166 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x8F, 0x1F, 0x38, 0x00, 0x80, 0xDF, 0x1F, 0x70, 0x00, 0x80, 0xFF, 0x38, 0x60, 0x00, 0xC0, 0x71, 0x30, 0x60, 0x00, 0xC0, 0xE0, + 0x60, 0x60, 0x00, 0xC0, 0xC0, 0xE0, 0x60, 0x00, 0xC0, 0xC0, 0xC1, 0x71, 0x00, 0xC0, 0x80, 0xE3, 0x3F, 0x00, 0xC0, 0x81, 0xBF, + 0x3F, 0x00, 0x80, 0x03, 0x3F, 0x0E, 0x00, 0x00, 0x00, 0x1E, // 167 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, + 0x00, 0x00, 0xE0, // 168 + 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x38, 0x70, 0x00, 0x00, 0x00, 0x1C, 0xE0, 0x00, 0x00, 0x00, + 0x8E, 0xCF, 0x01, 0x00, 0x00, 0xE6, 0x9F, 0x01, 0x00, 0x00, 0x63, 0x38, 0x03, 0x00, 0x00, 0x33, 0x30, 0x03, 0x00, 0x00, 0x33, + 0x30, 0x03, 0x00, 0x00, 0x33, 0x30, 0x03, 0x00, 0x00, 0x33, 0x30, 0x03, 0x00, 0x00, 0x63, 0x18, 0x03, 0x00, 0x00, 0x06, 0x80, + 0x01, 0x00, 0x00, 0x0E, 0xC0, 0x01, 0x00, 0x00, 0x1C, 0xE0, 0x00, 0x00, 0x00, 0x38, 0x70, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, + 0x00, 0x00, 0xC0, 0x0F, // 169 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xF0, 0x30, 0x00, 0x00, 0x80, 0xF9, 0x31, 0x00, 0x00, 0xC0, 0x98, 0x33, 0x00, 0x00, 0xC0, 0x0C, 0x33, 0x00, 0x00, 0xC0, 0x0C, + 0x33, 0x00, 0x00, 0xC0, 0x0C, 0x33, 0x00, 0x00, 0xC0, 0x0C, 0x33, 0x00, 0x00, 0xC0, 0x8C, 0x31, 0x00, 0x00, 0x80, 0xCD, 0x30, + 0x00, 0x00, 0x80, 0xFF, 0x33, 0x00, 0x00, 0x00, 0xFF, 0x33, // 170 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, + 0x00, 0x1F, 0x00, 0x00, 0x00, 0x80, 0x3B, 0x00, 0x00, 0x00, 0xC0, 0x71, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x70, + 0xC0, 0x01, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x80, 0x3B, + 0x00, 0x00, 0x00, 0xC0, 0x71, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x70, 0xC0, 0x01, // 171 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, + 0x80, 0x01, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x80, + 0x01, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x80, 0x01, + 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0x80, 0x3F, // 172 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x18, // 173 + 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x38, 0x70, 0x00, 0x00, 0x00, 0x1C, 0xE0, 0x00, 0x00, 0x00, + 0x0E, 0xC0, 0x01, 0x00, 0x00, 0x06, 0x80, 0x01, 0x00, 0x00, 0xF3, 0x3F, 0x03, 0x00, 0x00, 0xF3, 0x3F, 0x03, 0x00, 0x00, 0x33, + 0x07, 0x03, 0x00, 0x00, 0x33, 0x1F, 0x03, 0x00, 0x00, 0xF3, 0x3D, 0x03, 0x00, 0x00, 0xE3, 0x30, 0x03, 0x00, 0x00, 0x06, 0xA0, + 0x01, 0x00, 0x00, 0x0E, 0xC0, 0x01, 0x00, 0x00, 0x1C, 0xE0, 0x00, 0x00, 0x00, 0x38, 0x70, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, + 0x00, 0x00, 0xC0, 0x0F, // 174 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, + 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, + 0x00, 0x00, 0xC0, 0x01, // 175 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1F, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0xC0, 0x71, 0x00, 0x00, 0x00, 0xC0, 0x60, 0x00, 0x00, 0x00, 0xC0, 0x60, + 0x00, 0x00, 0x00, 0xC0, 0x60, 0x00, 0x00, 0x00, 0xC0, 0x71, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x1F, // 176 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x00, 0x00, + 0x00, 0x03, 0x0C, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x00, 0x00, 0xF8, + 0x7F, 0x0C, 0x00, 0x00, 0xF8, 0x7F, 0x0C, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x00, 0x00, 0x00, 0x03, + 0x0C, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x00, 0x00, 0x00, 0x03, 0x0C, // 177 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x03, 0x00, 0x00, 0xC0, 0x80, 0x03, 0x00, 0x00, 0xC0, 0xC0, 0x03, 0x00, 0x00, 0xC0, 0xE0, + 0x03, 0x00, 0x00, 0xC0, 0x70, 0x03, 0x00, 0x00, 0xC0, 0x39, 0x03, 0x00, 0x00, 0x80, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x07, + 0x03, // 178 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x81, 0x01, 0x00, 0x00, 0xC0, 0x00, 0x03, 0x00, 0x00, 0xC0, 0x0C, 0x03, 0x00, 0x00, 0xC0, 0x0C, + 0x03, 0x00, 0x00, 0xC0, 0x0C, 0x03, 0x00, 0x00, 0xC0, 0x0C, 0x03, 0x00, 0x00, 0xC0, 0x9C, 0x03, 0x00, 0x00, 0x80, 0xFF, 0x01, + 0x00, 0x00, 0x80, 0xF3, // 179 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, + 0x00, 0x00, 0x10, // 180 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0x03, 0x00, + 0xF0, 0xFF, 0xFF, 0x03, 0x00, 0xF0, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x80, + 0x07, 0x00, 0x00, 0xF0, 0xFF, 0x01, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0E, + 0x00, 0x00, 0x00, 0x00, 0x0E, // 181 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x80, + 0xFF, 0x01, 0x00, 0x00, 0x80, 0xFF, 0x01, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0xC0, 0xFF, + 0x03, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x7F, 0x00, 0xC0, 0xFF, 0xFF, 0x7F, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, + 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x7F, 0x00, 0xC0, 0xFF, 0xFF, 0x7F, // 182 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x00, 0x00, 0x80, + 0x0F, 0x00, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x00, 0x00, 0x80, 0x0F, // 183 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x30, 0x03, 0x00, 0x00, 0x00, 0xF0, 0x03, 0x00, 0x00, 0x00, 0xC0, 0x01, // 184 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x03, 0x00, 0x00, 0x80, 0x01, 0x03, 0x00, 0x00, 0xC0, 0x00, 0x03, 0x00, 0x00, 0xC0, 0xFF, + 0x03, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x03, // 185 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7E, 0x30, 0x00, 0x00, 0x00, 0xFF, 0x30, 0x00, 0x00, 0x80, 0xC3, 0x31, 0x00, 0x00, 0xC0, 0x81, 0x33, 0x00, 0x00, 0xC0, 0x00, + 0x33, 0x00, 0x00, 0xC0, 0x00, 0x33, 0x00, 0x00, 0xC0, 0x00, 0x33, 0x00, 0x00, 0xC0, 0x81, 0x33, 0x00, 0x00, 0x80, 0xC3, 0x31, + 0x00, 0x00, 0x00, 0xFF, 0x30, 0x00, 0x00, 0x00, 0x7E, 0x30, // 186 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xC0, 0x01, 0x00, 0x00, + 0xE0, 0xE0, 0x00, 0x00, 0x00, 0xC0, 0x71, 0x00, 0x00, 0x00, 0x80, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, + 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x70, 0xC0, 0x01, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0xC0, 0x71, + 0x00, 0x00, 0x00, 0x80, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, // 187 + 0x00, 0x00, 0x18, 0x00, 0x00, 0x60, 0xC0, 0x18, 0x00, 0x00, 0x60, 0xC0, 0x0C, 0x00, 0x00, 0x30, 0xC0, 0x0C, 0x00, 0x00, 0xF0, + 0xFF, 0x0C, 0x00, 0x00, 0xF0, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0xC0, 0x06, 0x00, 0x00, 0x00, 0xC0, 0x06, 0x18, 0x00, 0x00, 0xC0, + 0x06, 0x1E, 0x00, 0x00, 0x00, 0x06, 0x1B, 0x00, 0x00, 0x00, 0x83, 0x19, 0x00, 0x00, 0x00, 0xE3, 0x18, 0x00, 0x00, 0x00, 0x33, + 0x18, 0x00, 0x00, 0x00, 0xF3, 0xFF, 0x00, 0x00, 0x80, 0xF1, 0xFF, 0x00, 0x00, 0x80, 0x01, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x18, // 188 + 0x00, 0x00, 0x18, 0x00, 0x00, 0x60, 0xC0, 0x18, 0x00, 0x00, 0x60, 0xC0, 0x0C, 0x00, 0x00, 0x30, 0xC0, 0x0C, 0x00, 0x00, 0xF0, + 0xFF, 0x0C, 0x00, 0x00, 0xF0, 0xFF, 0x0C, 0x00, 0x00, 0x00, 0xC0, 0x06, 0x00, 0x00, 0x00, 0xC0, 0x06, 0x00, 0x00, 0x00, 0xC0, + 0x66, 0xC0, 0x00, 0x00, 0x00, 0x36, 0xE0, 0x00, 0x00, 0x00, 0x33, 0xF0, 0x00, 0x00, 0x00, 0x33, 0xF8, 0x00, 0x00, 0x00, 0x33, + 0xDC, 0x00, 0x00, 0x00, 0x73, 0xCE, 0x00, 0x00, 0x80, 0xE1, 0xC7, 0x00, 0x00, 0x80, 0xC1, 0xC1, // 189 + 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x60, 0x60, 0x0C, 0x00, 0x00, 0x30, 0xC0, 0x0C, 0x00, 0x00, 0x30, + 0xC3, 0x0C, 0x00, 0x00, 0x30, 0xC3, 0x0C, 0x00, 0x00, 0x30, 0xC3, 0x06, 0x00, 0x00, 0x30, 0xC3, 0x06, 0x18, 0x00, 0x30, 0xE7, + 0x06, 0x1E, 0x00, 0xE0, 0x7F, 0x06, 0x1B, 0x00, 0xE0, 0x3C, 0x83, 0x19, 0x00, 0x00, 0x00, 0xE3, 0x18, 0x00, 0x00, 0x00, 0x33, + 0x18, 0x00, 0x00, 0x00, 0xF3, 0xFF, 0x00, 0x00, 0x80, 0xF1, 0xFF, 0x00, 0x00, 0x80, 0x01, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x18, // 190 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, + 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x80, 0xCF, 0x03, 0x00, 0x00, 0xC0, 0x83, 0x03, 0x00, 0xF0, + 0xFC, 0x81, 0x03, 0x00, 0xF0, 0xFC, 0x80, 0x03, 0x00, 0xF0, 0x7C, 0x80, 0x03, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, + 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xE0, // 191 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, + 0x00, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x02, 0xFC, 0x7F, 0x00, 0x00, 0x86, 0xFF, 0x71, 0x00, 0x00, 0xCE, 0x3F, + 0x70, 0x00, 0x00, 0xDC, 0x03, 0x70, 0x00, 0x00, 0xD8, 0x3F, 0x70, 0x00, 0x00, 0x90, 0xFF, 0x71, 0x00, 0x00, 0x00, 0xFC, 0x7F, + 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0x80, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x0C, // 192 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, + 0x00, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0xFC, 0x7F, 0x00, 0x00, 0x90, 0xFF, 0x71, 0x00, 0x00, 0xD8, 0x3F, + 0x70, 0x00, 0x00, 0xDC, 0x03, 0x70, 0x00, 0x00, 0xCE, 0x3F, 0x70, 0x00, 0x00, 0x86, 0xFF, 0x71, 0x00, 0x00, 0x02, 0xFC, 0x7F, + 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0x80, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x0C, // 193 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, + 0x00, 0xFF, 0x07, 0x00, 0x10, 0xE0, 0xFF, 0x00, 0x00, 0x18, 0xFC, 0x7F, 0x00, 0x00, 0x9C, 0xFF, 0x71, 0x00, 0x00, 0xC6, 0x3F, + 0x70, 0x00, 0x00, 0xC2, 0x03, 0x70, 0x00, 0x00, 0xC6, 0x3F, 0x70, 0x00, 0x00, 0x9C, 0xFF, 0x71, 0x00, 0x00, 0x18, 0xFC, 0x7F, + 0x00, 0x00, 0x10, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0x80, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x0C, // 194 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, + 0x00, 0xFF, 0x07, 0x00, 0x0C, 0xE0, 0xFF, 0x00, 0x00, 0x0E, 0xFC, 0x7F, 0x00, 0x00, 0x86, 0xFF, 0x71, 0x00, 0x00, 0xC6, 0x3F, + 0x70, 0x00, 0x00, 0xCE, 0x03, 0x70, 0x00, 0x00, 0xCC, 0x3F, 0x70, 0x00, 0x00, 0x8C, 0xFF, 0x71, 0x00, 0x00, 0x0E, 0xFC, 0x7F, + 0x00, 0x00, 0x06, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0x80, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x0C, // 195 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, + 0x00, 0xFF, 0x07, 0x00, 0x0E, 0xE0, 0xFF, 0x00, 0x00, 0x0E, 0xFC, 0x7F, 0x00, 0x00, 0x8E, 0xFF, 0x71, 0x00, 0x00, 0xC0, 0x3F, + 0x70, 0x00, 0x00, 0xC0, 0x03, 0x70, 0x00, 0x00, 0xC0, 0x3F, 0x70, 0x00, 0x00, 0x8E, 0xFF, 0x71, 0x00, 0x00, 0x0E, 0xFC, 0x7F, + 0x00, 0x00, 0x0E, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0x80, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x0C, // 196 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x80, 0x0F, 0x00, 0x00, 0x00, 0xF8, 0x0F, 0x00, 0x00, + 0x00, 0xFF, 0x07, 0x00, 0x3C, 0xF0, 0x7F, 0x00, 0x00, 0x7E, 0xFE, 0x7F, 0x00, 0x00, 0xE7, 0xFF, 0x70, 0x00, 0x00, 0xC3, 0x1F, + 0x70, 0x00, 0x00, 0xC3, 0x01, 0x70, 0x00, 0x00, 0xC3, 0x1F, 0x70, 0x00, 0x00, 0xE7, 0xFF, 0x70, 0x00, 0x00, 0x7E, 0xFE, 0x7F, + 0x00, 0x00, 0x3C, 0xF0, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, 0xF8, 0x0F, 0x00, 0x00, 0x00, 0x80, 0x0F, + 0x00, 0x00, 0x00, 0x00, 0x0C, // 197 + 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0x80, 0xFF, 0x03, 0x00, 0x00, + 0xF8, 0x7F, 0x00, 0x00, 0x80, 0xFF, 0x77, 0x00, 0x00, 0xC0, 0x7F, 0x70, 0x00, 0x00, 0xC0, 0x07, 0x70, 0x00, 0x00, 0xC0, 0x01, + 0x70, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0x81, 0x03, + 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x01, 0x00, + 0x0E, // 198 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x1F, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0x00, 0x00, 0x00, + 0xFE, 0xFF, 0x01, 0x00, 0x00, 0x1F, 0xE0, 0x03, 0x00, 0x80, 0x07, 0x80, 0x07, 0x00, 0x80, 0x03, 0x00, 0x07, 0x03, 0xC0, 0x01, + 0x00, 0x0E, 0x03, 0xC0, 0x01, 0x00, 0x0E, 0x03, 0xC0, 0x01, 0x00, 0x3E, 0x03, 0xC0, 0x01, 0x00, 0xFE, 0x03, 0xC0, 0x01, 0x00, + 0xCE, 0x01, 0xC0, 0x03, 0x00, 0x0E, 0x00, 0x80, 0x03, 0x00, 0x07, 0x00, 0x00, 0x07, 0x80, 0x03, // 199 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC2, 0x81, 0x03, 0x0E, 0x00, 0xC6, 0x81, 0x03, 0x0E, 0x00, 0xCE, 0x81, + 0x03, 0x0E, 0x00, 0xDC, 0x81, 0x03, 0x0E, 0x00, 0xD8, 0x81, 0x03, 0x0E, 0x00, 0xD0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, + 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, // 200 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xD0, 0x81, 0x03, 0x0E, 0x00, 0xD8, 0x81, + 0x03, 0x0E, 0x00, 0xDC, 0x81, 0x03, 0x0E, 0x00, 0xCE, 0x81, 0x03, 0x0E, 0x00, 0xC6, 0x81, 0x03, 0x0E, 0x00, 0xC2, 0x81, 0x03, + 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, // 201 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0xD0, 0xFF, 0xFF, 0x0F, 0x00, 0xD8, 0x81, 0x03, 0x0E, 0x00, 0xDC, 0x81, 0x03, 0x0E, 0x00, 0xC6, 0x81, + 0x03, 0x0E, 0x00, 0xC2, 0x81, 0x03, 0x0E, 0x00, 0xC6, 0x81, 0x03, 0x0E, 0x00, 0xDC, 0x81, 0x03, 0x0E, 0x00, 0xD8, 0x81, 0x03, + 0x0E, 0x00, 0xD0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, // 202 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0xCE, 0xFF, 0xFF, 0x0F, 0x00, 0xCE, 0x81, 0x03, 0x0E, 0x00, 0xCE, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, + 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xCE, 0x81, 0x03, 0x0E, 0x00, 0xCE, 0x81, 0x03, + 0x0E, 0x00, 0xCE, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, // 203 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, + 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC2, 0x01, 0x00, 0x0E, 0x00, 0xC6, 0x01, 0x00, 0x0E, 0x00, 0xCE, 0xFF, + 0xFF, 0x0F, 0x00, 0xDC, 0xFF, 0xFF, 0x0F, 0x00, 0xD8, 0xFF, 0xFF, 0x0F, 0x00, 0xD0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, + 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, // 204 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, + 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xD0, 0x01, 0x00, 0x0E, 0x00, 0xD8, 0xFF, + 0xFF, 0x0F, 0x00, 0xDC, 0xFF, 0xFF, 0x0F, 0x00, 0xCE, 0xFF, 0xFF, 0x0F, 0x00, 0xC6, 0x01, 0x00, 0x0E, 0x00, 0xC2, 0x01, 0x00, + 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, // 205 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, + 0x01, 0x00, 0x0E, 0x00, 0xD0, 0x01, 0x00, 0x0E, 0x00, 0xD8, 0x01, 0x00, 0x0E, 0x00, 0xDC, 0x01, 0x00, 0x0E, 0x00, 0xC6, 0xFF, + 0xFF, 0x0F, 0x00, 0xC2, 0xFF, 0xFF, 0x0F, 0x00, 0xC6, 0xFF, 0xFF, 0x0F, 0x00, 0xDC, 0x01, 0x00, 0x0E, 0x00, 0xD8, 0x01, 0x00, + 0x0E, 0x00, 0xD0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, // 206 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, + 0x01, 0x00, 0x0E, 0x00, 0xCE, 0x01, 0x00, 0x0E, 0x00, 0xCE, 0x01, 0x00, 0x0E, 0x00, 0xCE, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0xFF, + 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xCE, 0x01, 0x00, 0x0E, 0x00, 0xCE, 0x01, 0x00, + 0x0E, 0x00, 0xCE, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, // 207 + 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0x81, + 0x03, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0x80, 0x03, 0x00, 0x07, 0x00, 0x80, 0x07, 0x80, 0x07, 0x00, 0x00, 0x1F, 0xE0, + 0x03, 0x00, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0xFC, 0xFF, 0x00, 0x00, 0x00, 0xF0, 0x3F, // 208 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC6, + 0xFF, 0xFF, 0x0F, 0x00, 0xC7, 0x07, 0x00, 0x00, 0x00, 0x03, 0x3F, 0x00, 0x00, 0x00, 0x03, 0xFC, 0x00, 0x00, 0x00, 0x03, 0xE0, + 0x07, 0x00, 0x00, 0x06, 0x80, 0x1F, 0x00, 0x00, 0x06, 0x00, 0xFC, 0x00, 0x00, 0x06, 0x00, 0xF0, 0x03, 0x00, 0x07, 0x00, 0x80, + 0x0F, 0x00, 0xC3, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, // 209 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, + 0xFF, 0xFF, 0x03, 0x00, 0x80, 0x0F, 0xC0, 0x07, 0x00, 0x82, 0x03, 0x00, 0x07, 0x00, 0xC6, 0x01, 0x00, 0x0E, 0x00, 0xCE, 0x01, + 0x00, 0x0E, 0x00, 0xDC, 0x01, 0x00, 0x0E, 0x00, 0xD8, 0x01, 0x00, 0x0E, 0x00, 0xD0, 0x01, 0x00, 0x0E, 0x00, 0x80, 0x03, 0x00, + 0x07, 0x00, 0x80, 0x0F, 0xC0, 0x07, 0x00, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, 0xF0, 0x3F, // 210 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, + 0xFF, 0xFF, 0x03, 0x00, 0x80, 0x0F, 0xC0, 0x07, 0x00, 0x80, 0x03, 0x00, 0x07, 0x00, 0xD0, 0x01, 0x00, 0x0E, 0x00, 0xD8, 0x01, + 0x00, 0x0E, 0x00, 0xDC, 0x01, 0x00, 0x0E, 0x00, 0xCE, 0x01, 0x00, 0x0E, 0x00, 0xC6, 0x01, 0x00, 0x0E, 0x00, 0x82, 0x03, 0x00, + 0x07, 0x00, 0x80, 0x0F, 0xC0, 0x07, 0x00, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, 0xF0, 0x3F, // 211 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, + 0xFF, 0xFF, 0x03, 0x00, 0x90, 0x0F, 0xC0, 0x07, 0x00, 0x98, 0x03, 0x00, 0x07, 0x00, 0xDC, 0x01, 0x00, 0x0E, 0x00, 0xC6, 0x01, + 0x00, 0x0E, 0x00, 0xC2, 0x01, 0x00, 0x0E, 0x00, 0xC6, 0x01, 0x00, 0x0E, 0x00, 0xDC, 0x01, 0x00, 0x0E, 0x00, 0x98, 0x03, 0x00, + 0x07, 0x00, 0x90, 0x0F, 0xC0, 0x07, 0x00, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, 0xF0, 0x3F, // 212 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, + 0xFF, 0xFF, 0x03, 0x00, 0x8C, 0x0F, 0xC0, 0x07, 0x00, 0x8E, 0x03, 0x00, 0x07, 0x00, 0xC6, 0x01, 0x00, 0x0E, 0x00, 0xC6, 0x01, + 0x00, 0x0E, 0x00, 0xCE, 0x01, 0x00, 0x0E, 0x00, 0xCC, 0x01, 0x00, 0x0E, 0x00, 0xCC, 0x01, 0x00, 0x0E, 0x00, 0x8E, 0x03, 0x00, + 0x07, 0x00, 0x86, 0x0F, 0xC0, 0x07, 0x00, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, 0xF0, 0x3F, // 213 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, + 0xFF, 0xFF, 0x03, 0x00, 0x8E, 0x0F, 0xC0, 0x07, 0x00, 0x8E, 0x03, 0x00, 0x07, 0x00, 0xCE, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, + 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xCE, 0x01, 0x00, 0x0E, 0x00, 0x8E, 0x03, 0x00, + 0x07, 0x00, 0x8E, 0x0F, 0xC0, 0x07, 0x00, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0xFE, 0xFF, 0x01, 0x00, 0x00, 0xF0, 0x3F, // 214 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, 0x70, 0x80, 0x03, 0x00, 0x00, + 0xE0, 0xC0, 0x01, 0x00, 0x00, 0xC0, 0xE1, 0x00, 0x00, 0x00, 0x80, 0x73, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, + 0x1E, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x80, 0x73, 0x00, 0x00, 0x00, 0xC0, 0xE1, + 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x01, 0x00, 0x00, 0x70, 0x80, 0x03, 0x00, 0x00, 0x20, 0x00, 0x01, // 215 + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0xF0, 0x3F, 0x0F, 0x00, 0x00, 0xFE, 0xFF, 0x03, 0x00, 0x00, + 0xFF, 0xFF, 0x03, 0x00, 0x80, 0x0F, 0xF0, 0x07, 0x00, 0x80, 0x03, 0x38, 0x07, 0x00, 0xC0, 0x01, 0x1C, 0x0E, 0x00, 0xC0, 0x01, + 0x06, 0x0E, 0x00, 0xC0, 0x81, 0x03, 0x0E, 0x00, 0xC0, 0xC1, 0x01, 0x0E, 0x00, 0xC0, 0xE1, 0x00, 0x0E, 0x00, 0x80, 0x73, 0x00, + 0x07, 0x00, 0x80, 0x1F, 0xC0, 0x07, 0x00, 0x00, 0xFE, 0xFF, 0x03, 0x00, 0x00, 0xFF, 0xFF, 0x01, 0x00, 0xC0, 0xF1, 0x3F, 0x00, + 0x00, 0xC0, // 216 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x03, 0x00, 0xC0, + 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x02, 0x00, 0x00, 0x0F, 0x00, 0x06, 0x00, 0x00, 0x0E, 0x00, 0x0E, 0x00, + 0x00, 0x0E, 0x00, 0x1C, 0x00, 0x00, 0x0E, 0x00, 0x18, 0x00, 0x00, 0x0E, 0x00, 0x10, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x80, + 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0x03, 0x00, 0xC0, 0xFF, 0xFF, // 217 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x03, 0x00, 0xC0, + 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x10, 0x00, 0x00, 0x0E, 0x00, 0x18, 0x00, + 0x00, 0x0E, 0x00, 0x1C, 0x00, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x00, 0x0E, 0x00, 0x06, 0x00, 0x00, 0x0F, 0x00, 0x02, 0x00, 0x80, + 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0x03, 0x00, 0xC0, 0xFF, 0xFF, // 218 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x03, 0x00, 0xC0, + 0xFF, 0xFF, 0x07, 0x00, 0x10, 0x00, 0x80, 0x07, 0x00, 0x18, 0x00, 0x00, 0x0F, 0x00, 0x0E, 0x00, 0x00, 0x0E, 0x00, 0x06, 0x00, + 0x00, 0x0E, 0x00, 0x06, 0x00, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x00, 0x0E, 0x00, 0x18, 0x00, 0x00, 0x0F, 0x00, 0x10, 0x00, 0x80, + 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0x03, 0x00, 0xC0, 0xFF, 0xFF, // 219 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x03, 0x00, 0xC0, + 0xFF, 0xFF, 0x07, 0x00, 0x0E, 0x00, 0x80, 0x07, 0x00, 0x0E, 0x00, 0x00, 0x0F, 0x00, 0x0E, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, + 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x00, 0x0E, 0x00, 0x0E, 0x00, 0x00, 0x0F, 0x00, 0x0E, 0x00, 0x80, + 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0x03, 0x00, 0xC0, 0xFF, 0xFF, // 220 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x00, 0xC0, + 0x0F, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x10, 0xF8, 0x01, 0x00, 0x00, 0x18, 0xE0, + 0xFF, 0x0F, 0x00, 0x1C, 0x80, 0xFF, 0x0F, 0x00, 0x0E, 0xE0, 0xFF, 0x0F, 0x00, 0x06, 0xF8, 0x01, 0x00, 0x00, 0x02, 0xFC, 0x00, + 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, + 0x00, 0x40, // 221 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xC0, + 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x1C, 0x70, 0x00, 0x00, 0x00, 0x1C, 0x70, 0x00, 0x00, 0x00, 0x1C, + 0x70, 0x00, 0x00, 0x00, 0x1C, 0x70, 0x00, 0x00, 0x00, 0x1C, 0x70, 0x00, 0x00, 0x00, 0x1C, 0x70, 0x00, 0x00, 0x00, 0x3C, 0x78, + 0x00, 0x00, 0x00, 0x78, 0x3C, 0x00, 0x00, 0x00, 0xF8, 0x3F, 0x00, 0x00, 0x00, 0xF0, 0x1F, 0x00, 0x00, 0x00, 0xE0, 0x0F, // 222 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x0F, 0x00, 0x80, + 0xFF, 0xFF, 0x0F, 0x00, 0xC0, 0xFF, 0xFF, 0x0F, 0x00, 0xE0, 0x01, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x07, 0x00, 0xE0, 0xE0, + 0x01, 0x0E, 0x00, 0xE0, 0xF0, 0x03, 0x0E, 0x00, 0xE0, 0xF8, 0x07, 0x0E, 0x00, 0xE0, 0x19, 0x06, 0x0E, 0x00, 0xC0, 0x0F, 0x0E, + 0x0E, 0x00, 0x80, 0x0F, 0x1C, 0x0F, 0x00, 0x00, 0x0E, 0xF8, 0x07, 0x00, 0x00, 0x00, 0xF0, 0x07, 0x00, 0x00, 0x00, 0xE0, + 0x01, // 223 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0xC0, 0xF1, 0x07, 0x00, 0x10, + 0xE0, 0xF8, 0x07, 0x00, 0x30, 0xE0, 0x38, 0x0F, 0x00, 0x70, 0x70, 0x1C, 0x0E, 0x00, 0xE0, 0x70, 0x1C, 0x0E, 0x00, 0xC0, 0x73, + 0x1C, 0x0E, 0x00, 0x00, 0x73, 0x1C, 0x0E, 0x00, 0x00, 0x72, 0x1C, 0x06, 0x00, 0x00, 0x70, 0x1C, 0x07, 0x00, 0x00, 0xE0, 0x9C, + 0x01, 0x00, 0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0xC0, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0xFF, 0x0F, // 224 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0xC0, 0xF1, 0x07, 0x00, 0x00, + 0xE0, 0xF8, 0x07, 0x00, 0x00, 0xE0, 0x38, 0x0F, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0x72, 0x1C, 0x0E, 0x00, 0x00, 0x73, + 0x1C, 0x0E, 0x00, 0xC0, 0x73, 0x1C, 0x0E, 0x00, 0xE0, 0x70, 0x1C, 0x06, 0x00, 0x70, 0x70, 0x1C, 0x07, 0x00, 0x30, 0xE0, 0x9C, + 0x01, 0x00, 0x10, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0xC0, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0xFF, 0x0F, // 225 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0xC0, 0xF1, 0x07, 0x00, 0x00, + 0xE2, 0xF8, 0x07, 0x00, 0x80, 0xE3, 0x38, 0x0F, 0x00, 0xC0, 0x71, 0x1C, 0x0E, 0x00, 0xF0, 0x70, 0x1C, 0x0E, 0x00, 0x30, 0x70, + 0x1C, 0x0E, 0x00, 0xF0, 0x70, 0x1C, 0x0E, 0x00, 0xC0, 0x71, 0x1C, 0x06, 0x00, 0x80, 0x73, 0x1C, 0x07, 0x00, 0x00, 0xE2, 0x9C, + 0x01, 0x00, 0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0xC0, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0xFF, 0x0F, // 226 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0xC0, 0xF1, 0x07, 0x00, 0xC0, + 0xE1, 0xF8, 0x07, 0x00, 0xE0, 0xE1, 0x38, 0x0F, 0x00, 0x60, 0x70, 0x1C, 0x0E, 0x00, 0x60, 0x70, 0x1C, 0x0E, 0x00, 0xE0, 0x70, + 0x1C, 0x0E, 0x00, 0xC0, 0x71, 0x1C, 0x0E, 0x00, 0x80, 0x71, 0x1C, 0x06, 0x00, 0x80, 0x71, 0x1C, 0x07, 0x00, 0xE0, 0xE1, 0x9C, + 0x01, 0x00, 0x60, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0xC0, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0xFF, 0x0F, // 227 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0xC0, 0xF1, 0x07, 0x00, 0x00, + 0xE0, 0xF8, 0x07, 0x00, 0xE0, 0xE0, 0x38, 0x0F, 0x00, 0xE0, 0x70, 0x1C, 0x0E, 0x00, 0xE0, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0x70, + 0x1C, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x06, 0x00, 0xE0, 0x70, 0x1C, 0x07, 0x00, 0xE0, 0xE0, 0x9C, + 0x01, 0x00, 0xE0, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0xC0, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0xFF, 0x0F, // 228 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0xC0, 0xF1, 0x07, 0x00, 0x00, + 0xE0, 0xF8, 0x07, 0x00, 0xF0, 0xE0, 0x38, 0x0F, 0x00, 0xF8, 0x71, 0x1C, 0x0E, 0x00, 0x9C, 0x73, 0x1C, 0x0E, 0x00, 0x0C, 0x73, + 0x1C, 0x0E, 0x00, 0x0C, 0x73, 0x1C, 0x0E, 0x00, 0x9C, 0x73, 0x1C, 0x06, 0x00, 0xF8, 0x71, 0x1C, 0x07, 0x00, 0xF0, 0xE0, 0x9C, + 0x01, 0x00, 0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0xC0, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0xFF, 0x0F, // 229 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x03, 0x00, 0x00, 0xE0, 0xF8, 0x07, 0x00, 0x00, 0x70, 0xF8, 0x0F, 0x00, 0x00, + 0x70, 0x3C, 0x0F, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0xF0, 0x1C, 0x0F, 0x00, 0x00, 0xE0, + 0xFF, 0x07, 0x00, 0x00, 0xC0, 0xFF, 0x01, 0x00, 0x00, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xF0, 0x1C, 0x07, 0x00, 0x00, 0x70, 0x1C, + 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0xF0, 0x1C, 0x0E, 0x00, 0x00, 0xF0, 0x1F, 0x0E, 0x00, 0x00, 0xE0, 0x1F, 0x07, + 0x00, 0x00, 0x80, 0x1F, 0x07, // 230 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, + 0x80, 0xFF, 0x01, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0xE0, 0xC3, 0x07, 0x00, 0x00, 0xE0, 0x00, 0x07, 0x00, 0x00, 0xF0, + 0x00, 0x0F, 0x03, 0x00, 0x70, 0x00, 0x0E, 0x03, 0x00, 0x70, 0x00, 0x0E, 0x03, 0x00, 0x70, 0x00, 0x3E, 0x03, 0x00, 0x70, 0x00, + 0xFE, 0x03, 0x00, 0x70, 0x00, 0xCE, 0x01, 0x00, 0xE0, 0x00, 0x07, 0x00, 0x00, 0xC0, 0x81, 0x03, // 231 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x01, 0x00, 0x10, + 0xC0, 0xFF, 0x03, 0x00, 0x30, 0xE0, 0x9D, 0x07, 0x00, 0x70, 0xE0, 0x1C, 0x07, 0x00, 0xE0, 0x70, 0x1C, 0x0E, 0x00, 0xC0, 0x73, + 0x1C, 0x0E, 0x00, 0x00, 0x73, 0x1C, 0x0E, 0x00, 0x00, 0x72, 0x1C, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0xF0, 0x1C, + 0x0E, 0x00, 0x00, 0xE0, 0x1C, 0x07, 0x00, 0x00, 0xE0, 0x1F, 0x07, 0x00, 0x00, 0xC0, 0x9F, 0x03, 0x00, 0x00, 0x00, 0x1F, // 232 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x01, 0x00, 0x00, + 0xC0, 0xFF, 0x03, 0x00, 0x00, 0xE0, 0x9D, 0x07, 0x00, 0x00, 0xE0, 0x1C, 0x07, 0x00, 0x00, 0x72, 0x1C, 0x0E, 0x00, 0x00, 0x73, + 0x1C, 0x0E, 0x00, 0xC0, 0x73, 0x1C, 0x0E, 0x00, 0xE0, 0x70, 0x1C, 0x0E, 0x00, 0x70, 0x70, 0x1C, 0x0E, 0x00, 0x30, 0xF0, 0x1C, + 0x0E, 0x00, 0x10, 0xE0, 0x1C, 0x07, 0x00, 0x00, 0xE0, 0x1F, 0x07, 0x00, 0x00, 0xC0, 0x9F, 0x03, 0x00, 0x00, 0x00, 0x1F, // 233 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x01, 0x00, 0x00, + 0xC2, 0xFF, 0x03, 0x00, 0x80, 0xE3, 0x9D, 0x07, 0x00, 0xC0, 0xE1, 0x1C, 0x07, 0x00, 0xF0, 0x70, 0x1C, 0x0E, 0x00, 0x30, 0x70, + 0x1C, 0x0E, 0x00, 0xF0, 0x70, 0x1C, 0x0E, 0x00, 0xC0, 0x71, 0x1C, 0x0E, 0x00, 0x80, 0x73, 0x1C, 0x0E, 0x00, 0x00, 0xF2, 0x1C, + 0x0E, 0x00, 0x00, 0xE0, 0x1C, 0x07, 0x00, 0x00, 0xE0, 0x1F, 0x07, 0x00, 0x00, 0xC0, 0x9F, 0x03, 0x00, 0x00, 0x00, 0x1F, // 234 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x01, 0x00, 0x00, + 0xC0, 0xFF, 0x03, 0x00, 0xE0, 0xE0, 0x9D, 0x07, 0x00, 0xE0, 0xE0, 0x1C, 0x07, 0x00, 0xE0, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0x70, + 0x1C, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0xE0, 0x70, 0x1C, 0x0E, 0x00, 0xE0, 0xF0, 0x1C, + 0x0E, 0x00, 0xE0, 0xE0, 0x1C, 0x07, 0x00, 0x00, 0xE0, 0x1F, 0x07, 0x00, 0x00, 0xC0, 0x9F, 0x03, 0x00, 0x00, 0x00, 0x1F, // 235 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x10, + 0x70, 0x00, 0x0E, 0x00, 0x30, 0x70, 0x00, 0x0E, 0x00, 0x70, 0x70, 0x00, 0x0E, 0x00, 0xE0, 0x70, 0x00, 0x0E, 0x00, 0xC0, 0xF3, + 0xFF, 0x0F, 0x00, 0x00, 0xF3, 0xFF, 0x0F, 0x00, 0x00, 0xF2, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, + 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, // 236 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, + 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x72, 0x00, 0x0E, 0x00, 0x00, 0xF3, + 0xFF, 0x0F, 0x00, 0xC0, 0xF3, 0xFF, 0x0F, 0x00, 0xE0, 0xF0, 0xFF, 0x0F, 0x00, 0x70, 0x00, 0x00, 0x0E, 0x00, 0x30, 0x00, 0x00, + 0x0E, 0x00, 0x10, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, // 237 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, + 0x72, 0x00, 0x0E, 0x00, 0x80, 0x73, 0x00, 0x0E, 0x00, 0xC0, 0x71, 0x00, 0x0E, 0x00, 0xF0, 0x70, 0x00, 0x0E, 0x00, 0x30, 0xF0, + 0xFF, 0x0F, 0x00, 0xF0, 0xF0, 0xFF, 0x0F, 0x00, 0xC0, 0xF1, 0xFF, 0x0F, 0x00, 0x80, 0x03, 0x00, 0x0E, 0x00, 0x00, 0x02, 0x00, + 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, // 238 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, + 0x70, 0x00, 0x0E, 0x00, 0xE0, 0x70, 0x00, 0x0E, 0x00, 0xE0, 0x70, 0x00, 0x0E, 0x00, 0xE0, 0x70, 0x00, 0x0E, 0x00, 0x00, 0xF0, + 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0xE0, 0x00, 0x00, 0x0E, 0x00, 0xE0, 0x00, 0x00, + 0x0E, 0x00, 0xE0, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, // 239 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x20, + 0xE6, 0xFF, 0x07, 0x00, 0x60, 0xE2, 0x81, 0x07, 0x00, 0xE0, 0xF3, 0x00, 0x0F, 0x00, 0xE0, 0x73, 0x00, 0x0E, 0x00, 0xC0, 0x77, + 0x00, 0x0E, 0x00, 0x80, 0x7F, 0x00, 0x0E, 0x00, 0x80, 0x7E, 0x00, 0x0E, 0x00, 0xC0, 0x7C, 0x00, 0x0F, 0x00, 0xC0, 0xF8, 0x81, + 0x07, 0x00, 0x40, 0xF0, 0xFF, 0x07, 0x00, 0x00, 0xC0, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x7F, // 240 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0xC0, + 0xF1, 0xFF, 0x0F, 0x00, 0xE0, 0xF1, 0xFF, 0x0F, 0x00, 0x60, 0xC0, 0x01, 0x00, 0x00, 0x60, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0x60, + 0x00, 0x00, 0x00, 0xC0, 0x71, 0x00, 0x00, 0x00, 0x80, 0x71, 0x00, 0x00, 0x00, 0x80, 0x71, 0x00, 0x00, 0x00, 0xE0, 0xF1, 0x00, + 0x00, 0x00, 0x60, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0x80, 0xFF, 0x0F, // 241 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x10, + 0xE0, 0xFF, 0x07, 0x00, 0x30, 0xE0, 0x81, 0x07, 0x00, 0x70, 0xF0, 0x00, 0x0F, 0x00, 0xE0, 0x70, 0x00, 0x0E, 0x00, 0xC0, 0x73, + 0x00, 0x0E, 0x00, 0x00, 0x73, 0x00, 0x0E, 0x00, 0x00, 0x72, 0x00, 0x0E, 0x00, 0x00, 0xF0, 0x00, 0x0F, 0x00, 0x00, 0xE0, 0x81, + 0x07, 0x00, 0x00, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFF, // 242 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, + 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0x81, 0x07, 0x00, 0x00, 0xF0, 0x00, 0x0F, 0x00, 0x00, 0x72, 0x00, 0x0E, 0x00, 0x00, 0x73, + 0x00, 0x0E, 0x00, 0xC0, 0x73, 0x00, 0x0E, 0x00, 0xE0, 0x70, 0x00, 0x0E, 0x00, 0x70, 0xF0, 0x00, 0x0F, 0x00, 0x30, 0xE0, 0x81, + 0x07, 0x00, 0x10, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFF, // 243 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, + 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xE2, 0x81, 0x07, 0x00, 0x80, 0xF3, 0x00, 0x0F, 0x00, 0xE0, 0x71, 0x00, 0x0E, 0x00, 0x70, 0x70, + 0x00, 0x0E, 0x00, 0x70, 0x70, 0x00, 0x0E, 0x00, 0xE0, 0x71, 0x00, 0x0E, 0x00, 0x80, 0xF3, 0x00, 0x0F, 0x00, 0x00, 0xE2, 0x81, + 0x07, 0x00, 0x00, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFF, // 244 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0xC0, + 0xE1, 0xFF, 0x07, 0x00, 0xE0, 0xE1, 0x81, 0x07, 0x00, 0x60, 0xF0, 0x00, 0x0F, 0x00, 0x60, 0x70, 0x00, 0x0E, 0x00, 0xE0, 0x70, + 0x00, 0x0E, 0x00, 0xC0, 0x71, 0x00, 0x0E, 0x00, 0x80, 0x71, 0x00, 0x0E, 0x00, 0x80, 0xF1, 0x00, 0x0F, 0x00, 0xE0, 0xE1, 0x81, + 0x07, 0x00, 0x60, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFF, // 245 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0xE0, + 0xE0, 0xFF, 0x07, 0x00, 0xE0, 0xE0, 0x81, 0x07, 0x00, 0xE0, 0xF0, 0x00, 0x0F, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, + 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0xE0, 0xF0, 0x00, 0x0F, 0x00, 0xE0, 0xE0, 0x81, + 0x07, 0x00, 0xE0, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFF, // 246 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, + 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0xF0, 0xCC, 0x03, 0x00, 0x00, 0xF0, + 0xCC, 0x03, 0x00, 0x00, 0xF0, 0xCC, 0x03, 0x00, 0x00, 0xF0, 0xCC, 0x03, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, + 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, // 247 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x7F, 0x0E, 0x00, 0x00, 0xC0, 0xFF, 0x07, 0x00, 0x00, + 0xE0, 0xFF, 0x03, 0x00, 0x00, 0xE0, 0xC1, 0x07, 0x00, 0x00, 0xF0, 0xE0, 0x07, 0x00, 0x00, 0x70, 0x70, 0x0E, 0x00, 0x00, 0x70, + 0x38, 0x0E, 0x00, 0x00, 0x70, 0x1C, 0x0E, 0x00, 0x00, 0x70, 0x0E, 0x0E, 0x00, 0x00, 0xE0, 0x07, 0x0F, 0x00, 0x00, 0xE0, 0x83, + 0x07, 0x00, 0x00, 0xC0, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0x03, 0x00, 0x00, 0x38, 0xFE, 0x00, 0x00, 0x00, 0x10, // 248 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x01, 0x00, 0x10, + 0xF0, 0xFF, 0x07, 0x00, 0x30, 0xF0, 0xFF, 0x07, 0x00, 0x70, 0x00, 0x00, 0x0F, 0x00, 0xE0, 0x00, 0x00, 0x0E, 0x00, 0xC0, 0x03, + 0x00, 0x0E, 0x00, 0x00, 0x03, 0x00, 0x0E, 0x00, 0x00, 0x02, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x80, + 0x01, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, // 249 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x01, 0x00, 0x00, + 0xF0, 0xFF, 0x07, 0x00, 0x00, 0xF0, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x02, 0x00, 0x0E, 0x00, 0x00, 0x03, + 0x00, 0x0E, 0x00, 0xC0, 0x03, 0x00, 0x0E, 0x00, 0xE0, 0x00, 0x00, 0x06, 0x00, 0x70, 0x00, 0x00, 0x07, 0x00, 0x30, 0x00, 0x80, + 0x01, 0x00, 0x10, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, // 250 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x01, 0x00, 0x00, + 0xF0, 0xFF, 0x07, 0x00, 0x00, 0xF2, 0xFF, 0x07, 0x00, 0x80, 0x03, 0x00, 0x0F, 0x00, 0xC0, 0x01, 0x00, 0x0E, 0x00, 0xF0, 0x00, + 0x00, 0x0E, 0x00, 0x30, 0x00, 0x00, 0x0E, 0x00, 0xF0, 0x00, 0x00, 0x06, 0x00, 0xC0, 0x01, 0x00, 0x07, 0x00, 0x80, 0x03, 0x80, + 0x01, 0x00, 0x00, 0xF2, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, // 251 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x01, 0x00, 0x00, + 0xF0, 0xFF, 0x07, 0x00, 0xE0, 0xF0, 0xFF, 0x07, 0x00, 0xE0, 0x00, 0x00, 0x0F, 0x00, 0xE0, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, + 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0xE0, 0x00, 0x00, 0x07, 0x00, 0xE0, 0x00, 0x80, + 0x01, 0x00, 0xE0, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0x0F, // 252 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x80, 0x03, 0x00, + 0xF0, 0x03, 0x80, 0x03, 0x00, 0xE0, 0x1F, 0x80, 0x03, 0x00, 0x80, 0x7F, 0xC0, 0x03, 0x00, 0x02, 0xFC, 0xF3, 0x01, 0x00, 0x03, + 0xF0, 0xFF, 0x01, 0xC0, 0x03, 0xC0, 0x7F, 0x00, 0xE0, 0x00, 0xF0, 0x0F, 0x00, 0x70, 0x00, 0xFE, 0x03, 0x00, 0x30, 0x80, 0x7F, + 0x00, 0x00, 0x10, 0xE0, 0x1F, 0x00, 0x00, 0x00, 0xF0, 0x03, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x10, // 253 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x03, 0xE0, + 0xFF, 0xFF, 0xFF, 0x03, 0xE0, 0xFF, 0xFF, 0xFF, 0x03, 0x00, 0xC0, 0x81, 0x03, 0x00, 0x00, 0xE0, 0x00, 0x07, 0x00, 0x00, 0x70, + 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0x70, 0x00, 0x0E, 0x00, 0x00, 0xF0, 0x00, + 0x0F, 0x00, 0x00, 0xE0, 0x81, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0x07, 0x00, 0x00, 0xC0, 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFF, // 254 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x80, 0x03, 0x00, + 0xF0, 0x03, 0x80, 0x03, 0xE0, 0xE0, 0x1F, 0x80, 0x03, 0xE0, 0x80, 0x7F, 0xC0, 0x03, 0xE0, 0x00, 0xFC, 0xF3, 0x01, 0x00, 0x00, + 0xF0, 0xFF, 0x01, 0x00, 0x00, 0xC0, 0x7F, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0xE0, 0x00, 0xFE, 0x03, 0x00, 0xE0, 0x80, 0x7F, + 0x00, 0x00, 0xE0, 0xE0, 0x1F, 0x00, 0x00, 0x00, 0xF0, 0x03, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x10 // 255 +}; diff --git a/src/graphics/fonts/EinkDisplayFonts.h b/src/graphics/fonts/EinkDisplayFonts.h new file mode 100644 index 000000000..342525a19 --- /dev/null +++ b/src/graphics/fonts/EinkDisplayFonts.h @@ -0,0 +1,14 @@ +#ifndef EINKDISPLAYFONTS_h +#define EINKDISPLAYFONTS_h + +#ifdef ARDUINO +#include +#elif __MBED__ +#define PROGMEM +#endif + +/** + * Monospaced Plain 30 + */ +extern const uint8_t Monospaced_plain_30[] PROGMEM; +#endif diff --git a/src/graphics/niche/Drivers/Backlight/LatchingBacklight.cpp b/src/graphics/niche/Drivers/Backlight/LatchingBacklight.cpp index 7e4f0b709..6d9b709b1 100644 --- a/src/graphics/niche/Drivers/Backlight/LatchingBacklight.cpp +++ b/src/graphics/niche/Drivers/Backlight/LatchingBacklight.cpp @@ -40,13 +40,11 @@ void LatchingBacklight::setPin(uint8_t pin, bool activeWhen) // Ensures the backlight is off int LatchingBacklight::beforeDeepSleep(void *unused) { - // We shouldn't need to guard the block like this - // Contingency for: - // - settings corruption: settings.optionalMenuItems.backlight guards backlight code in MenuApplet - // - improper use in the future + // Contingency only + // - pin wasn't set if (pin != (uint8_t)-1) { off(); - pinMode(pin, INPUT); // High impedence - unnecessary? + pinMode(pin, INPUT); // High impedance - unnecessary? } else LOG_WARN("LatchingBacklight instantiated, but pin not set"); return 0; // Continue with deep sleep diff --git a/src/graphics/niche/Drivers/EInk/EInk.cpp b/src/graphics/niche/Drivers/EInk/EInk.cpp index 0abe20bf9..cd2e9dc98 100644 --- a/src/graphics/niche/Drivers/EInk/EInk.cpp +++ b/src/graphics/niche/Drivers/EInk/EInk.cpp @@ -6,13 +6,13 @@ using namespace NicheGraphics::Drivers; // Separate from EInk::begin method, as derived class constructors can probably supply these parameters as constants EInk::EInk(uint16_t width, uint16_t height, UpdateTypes supported) - : concurrency::OSThread("E-Ink Driver"), width(width), height(height), supportedUpdateTypes(supported) + : concurrency::OSThread("EInkDriver"), width(width), height(height), supportedUpdateTypes(supported) { OSThread::disable(); } // Used by NicheGraphics implementations to check if a display supports a specific refresh operation. -// Whether or the update type is supported is specified in the constructor +// Whether or not the update type is supported is specified in the constructor bool EInk::supports(UpdateTypes type) { // The EInkUpdateTypes enum assigns each type a unique bit. We are checking if that bit is set. @@ -31,8 +31,8 @@ bool EInk::supports(UpdateTypes type) void EInk::beginPolling(uint32_t interval, uint32_t expectedDuration) { updateRunning = true; - updateBegunAt = millis(); pollingInterval = interval; + pollingBegunAt = millis(); // To minimize load, we can choose to delay polling for a few seconds, if we know roughly how long the update will take // By default, expectedDuration is 0, and we'll start polling immediately @@ -45,10 +45,26 @@ void EInk::beginPolling(uint32_t interval, uint32_t expectedDuration) // This is what allows us to update the display asynchronously int32_t EInk::runOnce() { + // Check for polling timeout + // Manually set at 10 seconds, in case some big task holds up the firmware's cooperative multitasking + if (millis() - pollingBegunAt > 10000) + failed = true; + + // Handle failure + // - polling timeout + // - other error (derived classes) + if (failed) { + LOG_WARN("Display update failed. Check wiring & power supply."); + updateRunning = false; + failed = false; + return disable(); + } + + // If update not yet done if (!isUpdateDone()) return pollingInterval; // Poll again in a few ms - // If update done: + // If update done finalizeUpdate(); // Any post-update code: power down panel hardware, hibernate, etc updateRunning = false; // Change what we report via EInk::busy() return disable(); // Stop polling diff --git a/src/graphics/niche/Drivers/EInk/EInk.h b/src/graphics/niche/Drivers/EInk/EInk.h index 1fbc25a14..3c51d4f1d 100644 --- a/src/graphics/niche/Drivers/EInk/EInk.h +++ b/src/graphics/niche/Drivers/EInk/EInk.h @@ -24,14 +24,14 @@ class EInk : private concurrency::OSThread enum UpdateTypes : uint8_t { UNSPECIFIED = 0, FULL = 1 << 0, - FAST = 1 << 1, + FAST = 1 << 1, // "Partial Refresh" }; EInk(uint16_t width, uint16_t height, UpdateTypes supported); virtual void begin(SPIClass *spi, uint8_t pin_dc, uint8_t pin_cs, uint8_t pin_busy, uint8_t pin_rst = -1) = 0; virtual void update(uint8_t *imageData, UpdateTypes type) = 0; // Change the display image void await(); // Wait for an in-progress update to complete before proceeding - bool supports(UpdateTypes type); // Can display perfom a certain update type + bool supports(UpdateTypes type); // Can display perform a certain update type bool busy() { return updateRunning; } // Display able to update right now? const uint16_t width; // Public so that NicheGraphics implementations can access. Safe because const. @@ -41,14 +41,15 @@ class EInk : private concurrency::OSThread void beginPolling(uint32_t interval, uint32_t expectedDuration); // Begin checking repeatedly if update finished virtual bool isUpdateDone() = 0; // Check once if update finished virtual void finalizeUpdate() {} // Run any post-update code + bool failed = false; // If an error occurred during update private: int32_t runOnce() override; // Repeated checking if update finished const UpdateTypes supportedUpdateTypes; // Capabilities of a derived display class bool updateRunning = false; // see EInk::busy() - uint32_t updateBegunAt; // For initial pause before polling for update completion - uint32_t pollingInterval; // How often to check if update complete (ms) + uint32_t pollingInterval = 0; // How often to check if update complete (ms) + uint32_t pollingBegunAt = 0; // To timeout during polling }; } // namespace NicheGraphics::Drivers diff --git a/src/graphics/niche/Drivers/EInk/GDEY0154D67.cpp b/src/graphics/niche/Drivers/EInk/GDEY0154D67.cpp index bfc5ac681..2cab179b9 100644 --- a/src/graphics/niche/Drivers/EInk/GDEY0154D67.cpp +++ b/src/graphics/niche/Drivers/EInk/GDEY0154D67.cpp @@ -4,7 +4,7 @@ using namespace NicheGraphics::Drivers; -// Map the display controller IC's output to the conected panel +// Map the display controller IC's output to the connected panel void GDEY0154D67::configScanning() { // "Driver output control" diff --git a/src/graphics/niche/Drivers/EInk/HINK_E042A87.cpp b/src/graphics/niche/Drivers/EInk/HINK_E042A87.cpp new file mode 100644 index 000000000..1b72bc4a9 --- /dev/null +++ b/src/graphics/niche/Drivers/EInk/HINK_E042A87.cpp @@ -0,0 +1,58 @@ +#include "./HINK_E042A87.h" + +#ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS + +using namespace NicheGraphics::Drivers; + +// Load settings about how the pixels are moved from old state to new state during a refresh +// - manually specified, +// - or with stored values from displays OTP memory +void HINK_E042A87::configWaveform() +{ + sendCommand(0x3C); // Border waveform: + sendData(0x01); // Follow LUT for VSH1 + + sendCommand(0x18); // Temperature sensor: + sendData(0x80); // Use internal temperature sensor to select an appropriate refresh waveform +} + +// Describes the sequence of events performed by the displays controller IC during a refresh +// Includes "power up", "load settings from memory", "update the pixels", etc +void HINK_E042A87::configUpdateSequence() +{ + switch (updateType) { + case FAST: + sendCommand(0x21); // Use both "old" and "new" image memory (differential) + sendData(0x00); + sendData(0x00); + + sendCommand(0x22); // Set "update sequence" + sendData(0xFF); // Differential, load waveform from OTP + break; + + case FULL: + default: + sendCommand(0x21); // Bypass "old" image memory (non-differential) + sendData(0x40); + sendData(0x00); + + sendCommand(0x22); // Set "update sequence": + sendData(0xF7); // Non-differential, load waveform from OTP + break; + } +} + +// Once the refresh operation has been started, +// begin periodically polling the display to check for completion, using the normal Meshtastic threading code +// Only used when refresh is "async" +void HINK_E042A87::detachFromUpdate() +{ + switch (updateType) { + case FAST: + return beginPolling(50, 1000); // At least 1 second, then check every 50ms + case FULL: + default: + return beginPolling(100, 3500); // At least 3.5 seconds, then check every 100ms + } +} +#endif // MESHTASTIC_INCLUDE_NICHE_GRAPHICS \ No newline at end of file diff --git a/src/graphics/niche/Drivers/EInk/HINK_E042A87.h b/src/graphics/niche/Drivers/EInk/HINK_E042A87.h new file mode 100644 index 000000000..ac03b65ef --- /dev/null +++ b/src/graphics/niche/Drivers/EInk/HINK_E042A87.h @@ -0,0 +1,43 @@ +/* + +E-Ink display driver + - HINK-E042A87 + - Manufacturer: Holitech + - Size: 4.2 inch + - Resolution: 400px x 300px + - Flex connector marking: HINK-E042A07-FPC-A1 + - Silver sticker with QR code, marked: HE042A87 + + Note: as of Feb. 2025, these panels are used for "WeActStudio 4.2in B&W" display modules + +*/ + +#pragma once + +#ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS + +#include "configuration.h" + +#include "./SSD16XX.h" + +namespace NicheGraphics::Drivers +{ +class HINK_E042A87 : public SSD16XX +{ + // Display properties + private: + static constexpr uint32_t width = 400; + static constexpr uint32_t height = 300; + static constexpr UpdateTypes supported = (UpdateTypes)(FULL | FAST); + + public: + HINK_E042A87() : SSD16XX(width, height, supported) {} + + protected: + void configWaveform() override; + void configUpdateSequence() override; + void detachFromUpdate() override; +}; + +} // namespace NicheGraphics::Drivers +#endif // MESHTASTIC_INCLUDE_NICHE_GRAPHICS \ No newline at end of file diff --git a/src/graphics/niche/Drivers/EInk/LCMEN2R13EFC1.cpp b/src/graphics/niche/Drivers/EInk/LCMEN2R13EFC1.cpp index c54769fc2..c843c4694 100644 --- a/src/graphics/niche/Drivers/EInk/LCMEN2R13EFC1.cpp +++ b/src/graphics/niche/Drivers/EInk/LCMEN2R13EFC1.cpp @@ -98,6 +98,7 @@ void LCMEN213EFC1::begin(SPIClass *spi, uint8_t pin_dc, uint8_t pin_cs, uint8_t reset(); } +// Display an image on the display void LCMEN213EFC1::update(uint8_t *imageData, UpdateTypes type) { this->updateType = type; @@ -161,13 +162,6 @@ void LCMEN213EFC1::sendCommand(const uint8_t command) void LCMEN213EFC1::sendData(uint8_t data) { - // spi->beginTransaction(spiSettings); - // digitalWrite(pin_dc, HIGH); // DC pin HIGH indicates data, instead of command - // digitalWrite(pin_cs, LOW); - // spi->transfer(data); - // digitalWrite(pin_cs, HIGH); - // digitalWrite(pin_dc, HIGH); - // spi->endTransaction(); sendData(&data, 1); } diff --git a/src/graphics/niche/Drivers/EInk/LCMEN2R13EFC1.h b/src/graphics/niche/Drivers/EInk/LCMEN2R13EFC1.h index 5c801c014..f9da202aa 100644 --- a/src/graphics/niche/Drivers/EInk/LCMEN2R13EFC1.h +++ b/src/graphics/niche/Drivers/EInk/LCMEN2R13EFC1.h @@ -45,21 +45,24 @@ class LCMEN213EFC1 : public EInk void configFull(); // Configure display for FULL refresh void configFast(); // Configure display for FAST refresh void writeNewImage(); - void writeOldImage(); + void writeOldImage(); // Used for "differential update", aka FAST refresh void detachFromUpdate(); bool isUpdateDone(); void finalizeUpdate(); protected: - uint8_t bufferOffsetX; // In bytes. Panel x=0 does not always align with controller x=0. Quirky internal wiring? - uint8_t bufferRowSize; // In bytes. Rows store 8 pixels per byte. Rounded up to fit (e.g. 122px would require 16 bytes) - uint32_t bufferSize; // In bytes. Rows * Columns - uint8_t *buffer; - UpdateTypes updateType; + uint8_t bufferOffsetX = 0; // In bytes. Panel x=0 does not always align with controller x=0. Quirky internal wiring? + uint8_t bufferRowSize = 0; // In bytes. Rows store 8 pixels per byte. Rounded up to fit (e.g. 122px would require 16 bytes) + uint32_t bufferSize = 0; // In bytes. Rows * Columns + uint8_t *buffer = nullptr; + UpdateTypes updateType = UpdateTypes::UNSPECIFIED; - uint8_t pin_dc, pin_cs, pin_busy, pin_rst; - SPIClass *spi; + uint8_t pin_dc = -1; + uint8_t pin_cs = -1; + uint8_t pin_busy = -1; + uint8_t pin_rst = -1; + SPIClass *spi = nullptr; SPISettings spiSettings = SPISettings(6000000, MSBFIRST, SPI_MODE0); }; diff --git a/src/graphics/niche/Drivers/EInk/README.md b/src/graphics/niche/Drivers/EInk/README.md index ffe21e507..eca91c6a8 100644 --- a/src/graphics/niche/Drivers/EInk/README.md +++ b/src/graphics/niche/Drivers/EInk/README.md @@ -3,7 +3,7 @@ A driver for E-Ink SPI displays. Suitable for re-use by various NicheGraphics UIs. Your UI should use the class `NicheGraphics::Drivers::EInk` . -When you set up a hardware variant, you will use one of specific display model classes, which extend the EInk class. +When you set up a hardware variant, you will use one of the specific display model classes, which extend the EInk class. An example setup might look like this: @@ -28,18 +28,28 @@ void setupNicheGraphics() } ``` +- [Methods](#methods) + - [`update(uint8_t *imageData, UpdateTypes type)`](#updateuint8_t-imagedata-updatetypes-type) + - [`await()`](#await) + - [`supports(UpdateTypes type)`](#supportsupdatetypes-type) + - [`busy()`](#busy) + - [`width()`](#width) + - [`height()`](#height) +- [Supporting New Displays](#supporting-new-displays) + - [Controller IC](#controller-ic) + - [Finding Information](#finding-information) + ## Methods -### `update(uint8_t *imageData, UpdateTypes type, bool async=true)` +### `update(uint8_t *imageData, UpdateTypes type)` Update the image on the display - _`imageData`_ to draw to the display. - _`type`_ which type of update to perform. - `FULL` - - `FAST` + - `FAST` (partial refresh) - (Other custom types may be possible) -- _`async`_ whether to wait for update to complete, or continue code execution The imageData is a 1-bit image. X-Pixels are 8-per byte, with the MSB being the leftmost pixel. This was not an InkHUD design decision; it is the raw format accepted by the E-Ink display controllers ICs. @@ -63,6 +73,10 @@ uint8_t xBits = (7-x) % 8; image[yByte + xByte] |= (1 << xBits); // Set pixel x=12, y=2 ``` +### `await()` + +Wait for an in-progress update to complete before continuing + ### `supports(UpdateTypes type)` Check if display supports a specific update type. `true` if supported. @@ -75,8 +89,44 @@ Check if display is already performing an `update()`. `true` if already updating ### `width()` -Width of the display, in pixels. Note: most displays are portait. Your UI will need to implement rotation in software. +Width of the display, in pixels. Note: most displays are portrait. Your UI will need to implement rotation in software. ### `height()` Height of the display, in pixels. Note: most displays are portrait. Your UI will need to implement rotation in software. + +## Supporting New Displays + +_This topic is not covered in depth, but these notes may be helpful._ + +The `InkHUD::Drivers::EInk` class contains only the mechanism for implementing an E-Ink driver on-top of Meshtastic's `OSThread`. A driver for a specific display needs to extend this class. + +### Controller IC + +If your display uses a controller IC from Solomon Systech, you can probably extend the existing `Drivers::SSD16XX` class, making only minor modifications. + +At this stage, displays using controller ICS from other manufacturers (UltraChip, Fitipower, etc) need to manually implemented. See `Drivers::LCMEN2R13EFC1` for an example. + +Generic base classes for manufacturers other than Solomon Systech might be added here in future. + +### Finding Information + +#### Flex-Connector Labels + +The orange flex-connector attached to E-Ink displays is often printed with an identifying label. This is not a _totally_ unique identifier, but does give a very strong clue as to the true model of the display, which can be used to search out further information. + +#### Datasheets + +The manufacturer of a DIY display module may publish a datasheet. These are often incomplete, but might reveal the true model of the display, or the controller IC. + +If you can determine the true model name of the display, you can likely find a more complete datasheet on the display manufacturer's website. This will often provide a "typical operating sequence"; a general overview of the code used to drive the display + +#### Example Code + +The manufacturer of a DIY module may publish example code. You may have more luck finding example code published by the display manufacturer themselves, if you can determine the true model of the panel. These examples are a very valuable reference. + +#### Other E-Ink drivers + +Libraries like ZinggJM's GxEPD2 can be valuable sources of information, although your panel may not be _specifically_ supported, and only _compatible_ with a driver there, so some caution is advised. + +The display selection file in GxEPD2's Hello World example is also a useful resource for matching "flex connector labels" with display models, but the flex connector label is _not_ a unique identifier, so this is only another clue. diff --git a/src/graphics/niche/Drivers/EInk/SSD16XX.cpp b/src/graphics/niche/Drivers/EInk/SSD16XX.cpp index d58e5b37a..5a5397dbd 100644 --- a/src/graphics/niche/Drivers/EInk/SSD16XX.cpp +++ b/src/graphics/niche/Drivers/EInk/SSD16XX.cpp @@ -30,18 +30,33 @@ void SSD16XX::begin(SPIClass *spi, uint8_t pin_dc, uint8_t pin_cs, uint8_t pin_b pinMode(pin_busy, INPUT); // If using a reset pin, hold high - // Reset is active low for solmon systech ICs + // Reset is active low for Solomon Systech ICs if (pin_rst != 0xFF) pinMode(pin_rst, INPUT_PULLUP); reset(); } -void SSD16XX::wait() +// Poll the displays busy pin until an operation is complete +// Timeout and set fail flag if something went wrong and the display got stuck +void SSD16XX::wait(uint32_t timeout) { + // Don't bother waiting if part of the update sequence failed + // In that situation, we're now just failing-through the process, until we can try again with next update. + if (failed) + return; + + uint32_t startMs = millis(); + // Busy when HIGH - while (digitalRead(pin_busy) == HIGH) + while (digitalRead(pin_busy) == HIGH) { + // Check for timeout + if (millis() - startMs > timeout) { + failed = true; + break; + } yield(); + } } void SSD16XX::reset() @@ -50,8 +65,9 @@ void SSD16XX::reset() if (pin_rst != 0xFF) { pinMode(pin_rst, OUTPUT); digitalWrite(pin_rst, LOW); - delay(50); - pinMode(pin_rst, INPUT_PULLUP); + delay(10); + digitalWrite(pin_rst, HIGH); + delay(10); wait(); } @@ -61,6 +77,11 @@ void SSD16XX::reset() void SSD16XX::sendCommand(const uint8_t command) { + // Abort if part of the update sequence failed + // This will unlock again once we have failed-through the entire process + if (failed) + return; + spi->beginTransaction(spiSettings); digitalWrite(pin_dc, LOW); // DC pin low indicates command digitalWrite(pin_cs, LOW); @@ -72,18 +93,16 @@ void SSD16XX::sendCommand(const uint8_t command) void SSD16XX::sendData(uint8_t data) { - // spi->beginTransaction(spiSettings); - // digitalWrite(pin_dc, HIGH); // DC pin HIGH indicates data, instead of command - // digitalWrite(pin_cs, LOW); - // spi->transfer(data); - // digitalWrite(pin_cs, HIGH); - // digitalWrite(pin_dc, HIGH); - // spi->endTransaction(); sendData(&data, 1); } void SSD16XX::sendData(const uint8_t *data, uint32_t size) { + // Abort if part of the update sequence failed + // This will unlock again once we have failed-through the entire process + if (failed) + return; + spi->beginTransaction(spiSettings); digitalWrite(pin_dc, HIGH); // DC pin HIGH indicates data, instead of command digitalWrite(pin_cs, LOW); diff --git a/src/graphics/niche/Drivers/EInk/SSD16XX.h b/src/graphics/niche/Drivers/EInk/SSD16XX.h index f9077f188..799a378c0 100644 --- a/src/graphics/niche/Drivers/EInk/SSD16XX.h +++ b/src/graphics/niche/Drivers/EInk/SSD16XX.h @@ -27,7 +27,7 @@ class SSD16XX : public EInk virtual void update(uint8_t *imageData, UpdateTypes type) override; protected: - virtual void wait(); + virtual void wait(uint32_t timeout = 1000); virtual void reset(); virtual void sendCommand(const uint8_t command); virtual void sendData(const uint8_t data); @@ -39,21 +39,24 @@ class SSD16XX : public EInk virtual void configUpdateSequence(); // Tell controller IC which operations to run virtual void writeNewImage(); - virtual void writeOldImage(); + virtual void writeOldImage(); // Image which can be used at *next* update for "differential refresh" virtual void detachFromUpdate(); virtual bool isUpdateDone() override; virtual void finalizeUpdate() override; protected: - uint8_t bufferOffsetX; // In bytes. Panel x=0 does not always align with controller x=0. Quirky internal wiring? - uint8_t bufferRowSize; // In bytes. Rows store 8 pixels per byte. Rounded up to fit (e.g. 122px would require 16 bytes) - uint32_t bufferSize; // In bytes. Rows * Columns - uint8_t *buffer; - UpdateTypes updateType; + uint8_t bufferOffsetX = 0; // In bytes. Panel x=0 does not always align with controller x=0. Quirky internal wiring? + uint8_t bufferRowSize = 0; // In bytes. Rows store 8 pixels per byte. Rounded up to fit (e.g. 122px would require 16 bytes) + uint32_t bufferSize = 0; // In bytes. Rows * Columns + uint8_t *buffer = nullptr; + UpdateTypes updateType = UpdateTypes::UNSPECIFIED; - uint8_t pin_dc, pin_cs, pin_busy, pin_rst; - SPIClass *spi; + uint8_t pin_dc = -1; + uint8_t pin_cs = -1; + uint8_t pin_busy = -1; + uint8_t pin_rst = -1; + SPIClass *spi = nullptr; SPISettings spiSettings = SPISettings(4000000, MSBFIRST, SPI_MODE0); }; diff --git a/src/graphics/niche/Drivers/README.md b/src/graphics/niche/Drivers/README.md index 566558658..14a9edd0b 100644 --- a/src/graphics/niche/Drivers/README.md +++ b/src/graphics/niche/Drivers/README.md @@ -1,3 +1,3 @@ # NicheGraphics - Drivers -Common drivers which can be used by various NicheGrapihcs UIs +Common drivers which can be used by various NicheGraphics UIs diff --git a/src/graphics/niche/FlashData.h b/src/graphics/niche/FlashData.h index 4a436d387..8a63c6108 100644 --- a/src/graphics/niche/FlashData.h +++ b/src/graphics/niche/FlashData.h @@ -119,7 +119,7 @@ template class FlashData // Calculate a hash of the data uint32_t hash = getHash(data); - f.write((uint8_t *)data, sizeof(T)); // Write the actualy data + f.write((uint8_t *)data, sizeof(T)); // Write the actual data f.write((uint8_t *)&hash, sizeof(hash)); // Append the hash // f.flush(); diff --git a/src/graphics/niche/Fonts/FreeSans6pt8bCyrillic.h b/src/graphics/niche/Fonts/FreeSans6pt8bCyrillic.h index 49f03d4e1..d222cd1c3 100644 --- a/src/graphics/niche/Fonts/FreeSans6pt8bCyrillic.h +++ b/src/graphics/niche/Fonts/FreeSans6pt8bCyrillic.h @@ -4,7 +4,7 @@ Uses Windows-1251 encoding to map translingual Cyrillic characters to range betw https://en.wikipedia.org/wiki/Windows-1251 Cyrillic characters present to the firmware as UTF8. -A Niche Graphics implementation needs to identify these, and subsitute the appropriate Windows-1251 char value. +A NicheGraphics implementation needs to identify these, and substitute the appropriate Windows-1251 char value. */ diff --git a/src/graphics/niche/InkHUD/Applet.cpp b/src/graphics/niche/InkHUD/Applet.cpp index ebd0acc78..6c6245ec3 100644 --- a/src/graphics/niche/InkHUD/Applet.cpp +++ b/src/graphics/niche/InkHUD/Applet.cpp @@ -2,6 +2,8 @@ #include "./Applet.h" +#include "main.h" + #include "RTC.h" using namespace NicheGraphics; @@ -16,10 +18,15 @@ InkHUD::Applet::Applet() : GFX(0, 0) // The width and height will change dynamically, depending on Applet tiling // If you're getting a "divide by zero error", consider it an assert: // WindowManager should be the only one controlling the rendering + + inkhud = InkHUD::getInstance(); + settings = &inkhud->persistence->settings; + latestMessage = &inkhud->persistence->latestMessage; } -// The raw pixel output generated by AdafruitGFX drawing -// Hand off to the applet's tile, which will in-turn pass to the window manager +// Draw a single pixel +// The raw pixel output generated by AdafruitGFX drawing all passes through here +// Hand off to the applet's tile, which will in-turn pass to the renderer void InkHUD::Applet::drawPixel(int16_t x, int16_t y, uint16_t color) { // Only render pixels if they fall within user's cropped region @@ -27,9 +34,10 @@ void InkHUD::Applet::drawPixel(int16_t x, int16_t y, uint16_t color) assignedTile->handleAppletPixel(x, y, (Color)color); } -// Sets which tile the applet renders for +// Link our applet to a tile +// This can only be called by Tile::assignApplet +// The tile determines the applets dimensions // Pixel output is passed to tile during render() -// This should only be called by Tile::assignApplet void InkHUD::Applet::setTile(Tile *t) { // If we're setting (not clearing), make sure the link is "reciprocal" @@ -39,25 +47,32 @@ void InkHUD::Applet::setTile(Tile *t) assignedTile = t; } -// Which tile will the applet render() to? +// The tile to which our applet is assigned InkHUD::Tile *InkHUD::Applet::getTile() { return assignedTile; } +// Draw the applet void InkHUD::Applet::render() { assert(assignedTile); // Ensure that we have a tile assert(assignedTile->getAssignedApplet() == this); // Ensure that we have a reciprocal link with the tile - wantRender = false; // Clear the flag set by requestUpdate - wantAutoshow = false; // If we're rendering now, it means our request was considered. It may or may not have been granted. - wantUpdateType = Drivers::EInk::UpdateTypes::UNSPECIFIED; // Our requested type has been considered by now. Tidy up. + // WindowManager::update has now consumed the info about our update request + // Clear everything for future requests + wantRender = false; // Flag set by requestUpdate + wantAutoshow = false; // Flag set by requestAutoShow. May or may not have been honored. + wantUpdateType = Drivers::EInk::UpdateTypes::UNSPECIFIED; // Update type we wanted. May on may not have been granted. updateDimensions(); resetDrawingSpace(); onRender(); // Derived applet's drawing takes place here + // Handle "Tile Highlighting" + // Some devices may use an auxiliary button to switch between tiles + // When this happens, we temporarily highlight the newly focused tile with a border + // If our tile is (or was) highlighted, to indicate a change in focus if (Tile::highlightTarget == assignedTile) { // Draw the highlight @@ -77,7 +92,8 @@ void InkHUD::Applet::render() } // Does the applet want to render now? -// Checks whether the applet called requestUpdate() recently, in response to an event +// Checks whether the applet called requestUpdate recently, in response to an event +// Used by WindowManager::update bool InkHUD::Applet::wantsToRender() { return wantRender; @@ -85,18 +101,21 @@ bool InkHUD::Applet::wantsToRender() // Does the applet want to be moved to foreground before next render, to show new data? // User specifies whether an applet has permission for this, using the on-screen menu +// Used by WindowManager::update bool InkHUD::Applet::wantsToAutoshow() { return wantAutoshow; } // Which technique would this applet prefer that the display use to change the image? +// Used by WindowManager::update Drivers::EInk::UpdateTypes InkHUD::Applet::wantsUpdateType() { return wantUpdateType; } // Get size of the applet's drawing space from its tile +// Performed immediately before derived applet's drawing code runs void InkHUD::Applet::updateDimensions() { assert(assignedTile); @@ -113,19 +132,20 @@ void InkHUD::Applet::resetDrawingSpace() setTextColor(BLACK); // Reset text params setCursor(0, 0); setTextWrap(false); - setFont(AppletFont()); // Restore the default AdafruitGFX font + setFont(fontSmall); } -// Tell the window manager that we want to render now +// Tell InkHUD::Renderer that we want to render now // Applets should internally listen for events they are interested in, via MeshModule, CallbackObserver etc // When an applet decides it has heard something important, and wants to redraw, it calls this method -// Once the window manager has given other applets a chance to process whatever event we just detected, -// it will run Applet::render(), which may draw our applet to screen, if it is shown (forgeround) +// Once the renderer has given other applets a chance to process whatever event we just detected, +// it will run Applet::render(), which may draw our applet to screen, if it is shown (foreground) +// We should requestUpdate even if our applet is currently background, because this might be changed by autoshow void InkHUD::Applet::requestUpdate(Drivers::EInk::UpdateTypes type) { wantRender = true; wantUpdateType = type; - WindowManager::getInstance()->requestUpdate(); + inkhud->requestUpdate(); } // Ask window manager to move this applet to foreground at start of next render @@ -138,7 +158,7 @@ void InkHUD::Applet::requestAutoshow() // Called when an Applet begins running // Active applets are considered "enabled" // They should now listen for events, and request their own updates -// They may also be force rendered by the window manager at any time +// They may also be unexpectedly renderer at any time by other InkHUD components // Applets can be activated at run-time through the on-screen menu void InkHUD::Applet::activate() { @@ -146,7 +166,7 @@ void InkHUD::Applet::activate() active = true; } -// Called when an Applet stop running +// Called when an Applet stops running // Inactive applets are considered "disabled" // They should not listen for events, process data // They will not be rendered @@ -173,7 +193,7 @@ bool InkHUD::Applet::isActive() // Begin showing the Applet // It will be rendered immediately to whichever tile it is assigned -// The window manager will also now honor requestUpdate() calls from this applet +// The Renderer will also now honor requestUpdate() calls from this applet void InkHUD::Applet::bringToForeground() { if (!foreground) { @@ -186,7 +206,7 @@ void InkHUD::Applet::bringToForeground() // Stop showing the Applet // Calls to requestUpdate() will no longer be honored -// When one applet moves to background, another should move to foreground +// When one applet moves to background, another should move to foreground (exception: some system applets) void InkHUD::Applet::sendToBackground() { if (foreground) { @@ -196,6 +216,10 @@ void InkHUD::Applet::sendToBackground() } // Is the applet currently displayed on a tile +// Note: in some uncommon situations, an applet may be "foreground", and still not visible. +// This can occur when a system applet is covering the screen (e.g. during BLE pairing) +// This is not our applets responsibility to handle, +// as in those situations, the system applet will have "locked" rendering bool InkHUD::Applet::isForeground() { return foreground; @@ -248,7 +272,7 @@ void InkHUD::Applet::printAt(int16_t x, int16_t y, std::string text, HorizontalA // Custom font // - set with AppletFont::addSubstitution // - find certain UTF8 chars - // - replace with glpyh from custom font (or suitable ASCII addSubstitution?) + // - replace with glyph from custom font (or suitable ASCII addSubstitution?) getFont().applySubstitutions(&text); // We do still have to run getTextBounds to find the width @@ -271,8 +295,7 @@ void InkHUD::Applet::printAt(int16_t x, int16_t y, std::string text, HorizontalA break; } - // We're using a fixed line height (getFontDimensions), rather than sizing to text (getTextBounds) - // Note: the FontDimensions values for this are unsigned + // We're using a fixed line height, rather than sizing to text (getTextBounds) switch (va) { case TOP: @@ -291,7 +314,7 @@ void InkHUD::Applet::printAt(int16_t x, int16_t y, std::string text, HorizontalA } // Set which font should be used for subsequent drawing -// This is AppletFont type, which is a wrapper for AdfruitGFX font, with some precalculated dimension data +// This is AppletFont type, which is a wrapper for AdafruitGFX font, with some precalculated dimension data void InkHUD::Applet::setFont(AppletFont f) { GFX::setFont(f.gfxFont); @@ -299,20 +322,12 @@ void InkHUD::Applet::setFont(AppletFont f) } // Get which font is currently being used for drawing -// This is AppletFont type, which is a wrapper for AdfruitGFX font, with some precalculated dimension data +// This is AppletFont type, which is a wrapper for AdafruitGFX font, with some precalculated dimension data InkHUD::AppletFont InkHUD::Applet::getFont() { return currentFont; } -// Set two general-purpose fonts, which are reused by many applets -// Applets are also permitted to use other fonts, if they can justify the flash usage -void InkHUD::Applet::setDefaultFonts(AppletFont large, AppletFont small) -{ - Applet::fontSmall = small; - Applet::fontLarge = large; -} - // Gets rendered width of a string // Wrapper for getTextBounds uint16_t InkHUD::Applet::getTextWidth(const char *text) @@ -327,7 +342,7 @@ uint16_t InkHUD::Applet::getTextWidth(const char *text) } // Gets rendered width of a string -// Wrappe for getTextBounds +// Wrapper for getTextBounds uint16_t InkHUD::Applet::getTextWidth(std::string text) { getFont().applySubstitutions(&text); @@ -338,7 +353,7 @@ uint16_t InkHUD::Applet::getTextWidth(std::string text) // Evaluate SNR and RSSI to qualify signal strength at one of four discrete levels // Roughly comparable to values used by the iOS app; // I didn't actually go look up the code, just fit to a sample graphic I have of the iOS signal indicator -InkHUD::SignalStrength InkHUD::Applet::getSignalStrength(float snr, float rssi) +InkHUD::Applet::SignalStrength InkHUD::Applet::getSignalStrength(float snr, float rssi) { uint8_t score = 0; @@ -376,12 +391,14 @@ std::string InkHUD::Applet::hexifyNodeNum(NodeNum num) return std::string(nodeIdHex); } +// Print text, with word wrapping +// Avoids splitting words in half, instead moving the entire word to a new line wherever possible void InkHUD::Applet::printWrapped(int16_t left, int16_t top, uint16_t width, std::string text) { // Custom font glyphs // - set with AppletFont::addSubstitution // - find certain UTF8 chars - // - replace with glpyh from custom font (or suitable ASCII addSubstitution?) + // - replace with glyph from custom font (or suitable ASCII addSubstitution?) getFont().applySubstitutions(&text); // Place the AdafruitGFX cursor to suit our "top" coord @@ -528,7 +545,7 @@ std::string InkHUD::Applet::getTimeString(uint32_t epochSeconds) #ifdef BUILD_EPOCH constexpr uint32_t validAfterEpoch = BUILD_EPOCH - (SEC_PER_DAY * 30 * 6); // 6 Months prior to build #else - constexpr uint32_t validAfterEpoch = 1727740800 - (SEC_PER_DAY * 30 * 6); // 6 Months prior to October 1, 2024 12:00:00 AM GMT + constexpr uint32_t validAfterEpoch = 1738368000 - (SEC_PER_DAY * 30 * 6); // 6 Months prior to Feb 1, 2025 12:00:00 AM GMT #endif uint32_t epochNow = getValidTime(RTCQuality::RTCQualityDevice, true); @@ -538,23 +555,17 @@ std::string InkHUD::Applet::getTimeString(uint32_t epochSeconds) // Times are invalid: rtc is much older than when code was built // Don't give any human readable string - if (epochNow <= validAfterEpoch) { - LOG_DEBUG("RTC prior to buildtime"); + if (epochNow <= validAfterEpoch) return ""; - } // Times are invalid: argument time is significantly ahead of RTC // Don't give any human readable string - if (daysAgo < -2) { - LOG_DEBUG("RTC in future"); + if (daysAgo < -2) return ""; - } // Times are probably invalid: more than 6 months ago - if (daysAgo > 6 * 30) { - LOG_DEBUG("RTC val > 6 months old"); + if (daysAgo > 6 * 30) return ""; - } if (daysAgo > 1) return to_string(daysAgo) + " days ago"; @@ -571,9 +582,12 @@ std::string InkHUD::Applet::getTimeString(uint32_t epochSeconds) uint32_t hour = hms / SEC_PER_HOUR; uint32_t min = (hms % SEC_PER_HOUR) / SEC_PER_MIN; - // Format the clock string + // Format the clock string, either 12 hour or 24 hour char clockStr[11]; - sprintf(clockStr, "%u:%02u %s", (hour % 12 == 0 ? 12 : hour % 12), min, hour > 11 ? "PM" : "AM"); + if (config.display.use_12h_clock) + sprintf(clockStr, "%u:%02u %s", (hour % 12 == 0 ? 12 : hour % 12), min, hour > 11 ? "PM" : "AM"); + else + sprintf(clockStr, "%02u:%02u", hour, min); return clockStr; } @@ -602,7 +616,7 @@ uint16_t InkHUD::Applet::getActiveNodeCount() meshtastic_NodeInfoLite *node = nodeDB->getMeshNodeByIndex(i); // Check if heard recently, and not our own node - if (sinceLastSeen(node) < settings.recentlyActiveSeconds && node->num != nodeDB->getNodeNum()) + if (sinceLastSeen(node) < settings->recentlyActiveSeconds && node->num != nodeDB->getNodeNum()) count++; } @@ -619,7 +633,7 @@ std::string InkHUD::Applet::localizeDistance(uint32_t meters) // Resulting string std::string localized; - // Imeperial + // Imperial if (config.display.units == meshtastic_Config_DisplayConfig_DisplayUnits_IMPERIAL) { uint32_t feet = meters * FEET_PER_METER; // Distant (miles, rounded) @@ -651,6 +665,7 @@ std::string InkHUD::Applet::localizeDistance(uint32_t meters) return localized; } +// Print text with a "faux bold" effect, by drawing it multiple times, offsetting slightly void InkHUD::Applet::printThick(int16_t xCenter, int16_t yCenter, std::string text, uint8_t thicknessX, uint8_t thicknessY) { // How many times to draw along x axis @@ -703,17 +718,24 @@ void InkHUD::Applet::printThick(int16_t xCenter, int16_t yCenter, std::string te // Asked before a notification is shown via the NotificationApplet // An applet might want to suppress a notification if the applet itself already displays this info // Example: AllMessageApplet should not approve notifications for messages, if it is in foreground -bool InkHUD::Applet::approveNotification(InkHUD::Notification &n) +bool InkHUD::Applet::approveNotification(NicheGraphics::InkHUD::Notification &n) { // By default, no objection return true; } // Draw the standard header, used by most Applets +/* +┌───────────────────────────────┐ +│ Applet::name here │ +│ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │ +│ │ +│ │ +│ │ +└───────────────────────────────┘ +*/ void InkHUD::Applet::drawHeader(std::string text) { - setFont(fontSmall); - // Y position for divider // - between header text and messages constexpr int16_t padDivH = 2; @@ -771,7 +793,16 @@ uint16_t InkHUD::Applet::getLogoHeight(uint16_t limitWidth, uint16_t limitHeight // Draw a scalable Meshtastic logo // Make sure to provide dimensions which have the correct aspect ratio (~2) // Three paths, drawn thick using quads, with one corner "radiused" -void InkHUD::Applet::drawLogo(int16_t centerX, int16_t centerY, uint16_t width, uint16_t height) +/* + - ^ + /- /-\ + // // \\ + // // \\ + // // \\ + // // \\ + +*/ +void InkHUD::Applet::drawLogo(int16_t centerX, int16_t centerY, uint16_t width, uint16_t height, Color color) { struct Point { int x; @@ -788,6 +819,17 @@ void InkHUD::Applet::drawLogo(int16_t centerX, int16_t centerY, uint16_t width, int16_t logoB = logoT + logoH - 1; // Points for paths (a, b, and c) + /* + +-----------------------------+ + --| a2 b2/c1 | + | | + | | + | | + --| a1 b1 c2 | + +-----------------------------+ + | | | | + */ + Point a1 = {map(0, 0, 3, logoL, logoR), logoB}; Point a2 = {map(1, 0, 3, logoL, logoR), logoT}; Point b1 = {map(1, 0, 3, logoL, logoR), logoB}; @@ -795,48 +837,114 @@ void InkHUD::Applet::drawLogo(int16_t centerX, int16_t centerY, uint16_t width, Point c1 = {map(2, 0, 3, logoL, logoR), logoT}; Point c2 = {map(3, 0, 3, logoL, logoR), logoB}; - // Find right-angle to the path + // Find angle of the path(s) // Used to thicken the single pixel paths + /* + +-------------------------------+ + | a2 | + | -| | + | -/ | | + | -/ | | + | -/# | | + | -/ # | | + | / # | | + | a1---------- | + +-------------------------------+ + */ + Distance deltaA = {abs(a2.x - a1.x), abs(a2.y - a1.y)}; float angle = tanh((float)deltaA.y / deltaA.x); - // Distance {at right angle from the paths), which will give corners for our "quads" + // Distance (at right angle to the paths), which will give corners for our "quads" // The distance is unsigned. We will vary the signedness of the x and y components to suit the path and corner + /* + | a2 + | . + | .. + | aq1 .. + | # .. + | | # .. + |fromPath.y | # .. + | +----a1 + | + | fromPath.x + +-------------------------------- + */ + Distance fromPath; fromPath.x = cos(radians(90) - angle) * logoTh * 0.5; fromPath.y = sin(radians(90) - angle) * logoTh * 0.5; + // Make the paths thick + // Corner points for the rectangles (quads): + /* + + aq2 + a2 + / aq3 + / + / + aq1 / + a1 + aq3 + */ + + // Filled as two triangles per quad: + /* + aq2 # + # ### + ## # aq3 + ## ### - + ## #### -/ + ## ### -/ + ## #### -/ + aq1 ## -/ + --- -/ + \---aq4 + */ + // Make the path thick: path a becomes quad a Point aq1{a1.x - fromPath.x, a1.y - fromPath.y}; Point aq2{a2.x - fromPath.x, a2.y - fromPath.y}; Point aq3{a2.x + fromPath.x, a2.y + fromPath.y}; Point aq4{a1.x + fromPath.x, a1.y + fromPath.y}; - fillTriangle(aq1.x, aq1.y, aq2.x, aq2.y, aq3.x, aq3.y, BLACK); - fillTriangle(aq1.x, aq1.y, aq3.x, aq3.y, aq4.x, aq4.y, BLACK); + fillTriangle(aq1.x, aq1.y, aq2.x, aq2.y, aq3.x, aq3.y, color); + fillTriangle(aq1.x, aq1.y, aq3.x, aq3.y, aq4.x, aq4.y, color); // Make the path thick: path b becomes quad b Point bq1{b1.x - fromPath.x, b1.y - fromPath.y}; Point bq2{b2.x - fromPath.x, b2.y - fromPath.y}; Point bq3{b2.x + fromPath.x, b2.y + fromPath.y}; Point bq4{b1.x + fromPath.x, b1.y + fromPath.y}; - fillTriangle(bq1.x, bq1.y, bq2.x, bq2.y, bq3.x, bq3.y, BLACK); - fillTriangle(bq1.x, bq1.y, bq3.x, bq3.y, bq4.x, bq4.y, BLACK); + fillTriangle(bq1.x, bq1.y, bq2.x, bq2.y, bq3.x, bq3.y, color); + fillTriangle(bq1.x, bq1.y, bq3.x, bq3.y, bq4.x, bq4.y, color); - // Make the path hick: path c becomes quad c + // Make the path thick: path c becomes quad c Point cq1{c1.x - fromPath.x, c1.y + fromPath.y}; Point cq2{c2.x - fromPath.x, c2.y + fromPath.y}; Point cq3{c2.x + fromPath.x, c2.y - fromPath.y}; Point cq4{c1.x + fromPath.x, c1.y - fromPath.y}; - fillTriangle(cq1.x, cq1.y, cq2.x, cq2.y, cq3.x, cq3.y, BLACK); - fillTriangle(cq1.x, cq1.y, cq3.x, cq3.y, cq4.x, cq4.y, BLACK); + fillTriangle(cq1.x, cq1.y, cq2.x, cq2.y, cq3.x, cq3.y, color); + fillTriangle(cq1.x, cq1.y, cq3.x, cq3.y, cq4.x, cq4.y, color); // Radius the intersection of quad b and quad c + /* + b2 / c1 + #### + ## ## + / \ + / \/ \ + / /\ \ + / / \ \ + + */ + // Don't attempt if logo is tiny if (logoTh > 3) { // The radius for the cap *should* be the same as logoTh, but it's not, due to accumulated rounding - // We get better results just rederiving it + // We get better results just re-deriving it int16_t capRad = sqrt(pow(fromPath.x, 2) + pow(fromPath.y, 2)); - fillCircle(b2.x, b2.y, capRad, BLACK); + fillCircle(b2.x, b2.y, capRad, color); } } diff --git a/src/graphics/niche/InkHUD/Applet.h b/src/graphics/niche/InkHUD/Applet.h index 30c1bdcdc..8f4466647 100644 --- a/src/graphics/niche/InkHUD/Applet.h +++ b/src/graphics/niche/InkHUD/Applet.h @@ -7,103 +7,21 @@ An applet is one "program" which may show info on the display. - =================================== - Preliminary notes, for the curious - =================================== - - (This info to be streamlined, and moved to a more official documentation) - - User Applets vs System Applets - ------------------------------- - - There are either "User Applets", or "System Applets". - This concept is only for our understanding; as far at the code is concerned, both are just "Applets" - - User applets are the "normal" applets. - User applets are applets like "AllMessageApplet", or "MapApplet". - User applets may be enabled / disabled by user, via the on-screen menu. - Incorporating new UserApplets is easy: just add them during setupNicheGraphics - If a UserApplet is not added during setupNicheGraphics, it will not be built. - The set of available UserApplets is allowed to vary from device to device. - - - Examples of system applets include "NotificationApplet" and "MenuApplet". - For their own reasons, system applets each require some amount of special handling. - - Drawing - -------- - - *All* drawing must be performed by an Applet. - Applets implement the onRender() method, where all drawing takes place. - Applets are told how wide and tall they are, and are expected to draw to suit this size. - When an applet draws, it uses co-ordinates in "Applet Space": between 0 and applet width/height. - - Event-driven rendering - ----------------------- - - Applets don't render unless something on the display needs to change. - An applet is expected to determine for itself when it has new info to display. - It should interact with the firmware via the MeshModule API, via Observables, etc. - Please don't directly add hooks throughout the existing firmware code. - - When an applet decides it would like to update the display, it should call requestUpdate() - The WindowManager will shortly call the onRender() method for all affected applets - - An Applet may be unexpectedly asked to render at any point in time. - - Applets should cache their data, but not their pixel output: they should re-render when onRender runs. - An Applet's dimensions are not know until onRender is called, so pre-rendering of UI elements is prohibited. - - Tiles - ----- - - Applets are assigned to "Tiles". - Assigning an applet to a tile creates a reciprocal link between the two. - When an applet renders, it passes pixels to its tile. - The tile translates these to the correct position, to be placed into the fullscreen framebuffer. - User applets don't get to choose their own tile; the multiplexing is handled by the WindowManager. - System applets might do strange things though. - - Foreground and Background - ------------------------- - - The user can cycle between applets by short-pressing the user button. - Any applets which are currently displayed on the display are "foreground". - When the user button is short pressed, and an applet is hidden, it becomes "background". - - Although the WindowManager will not render background applets, they should still collect data, - so they are ready to display when they are brought to foreground again. - Even if they are in background, Applets should still request updates when an event affects them, - as the user may have given them permission to "autoshow"; bringing themselves foreground automatically - - Applets can implement the onForeground and onBackground methods to handle this change in state. - They can also check their state by calling isForeground() at any time. - - Active and Inactive - ------------------- - - The user can select which applets are available, using the onscreen applet selection menu. - Applets which are enabled in this menu are "active"; otherwise they are "inactive". - - An inactive applet is expected not collect data; not to consume resources. - Applets are activated at boot, or when enabled via the menu. - They are deactivated at shutdown, or when disabled via the menu. - - Applets can implement the onActivation and onDeactivation methods to handle this change in state. - */ #pragma once #include "configuration.h" -#include +#include // GFXRoot drawing lib + +#include "mesh/MeshTypes.h" #include "./AppletFont.h" -#include "./Applets/System/Notification/Notification.h" +#include "./Applets/System/Notification/Notification.h" // The notification object, not the applet +#include "./InkHUD.h" +#include "./Persistence.h" #include "./Tile.h" -#include "./Types.h" -#include "./WindowManager.h" #include "graphics/niche/Drivers/EInk/EInk.h" namespace NicheGraphics::InkHUD @@ -112,37 +30,57 @@ namespace NicheGraphics::InkHUD using NicheGraphics::Drivers::EInk; using std::to_string; -class Tile; -class WindowManager; - class Applet : public GFX { public: + // Which edge Applet::printAt will place on the Y parameter + enum VerticalAlignment : uint8_t { + TOP, + MIDDLE, + BOTTOM, + }; + + // Which edge Applet::printAt will place on the X parameter + enum HorizontalAlignment : uint8_t { + LEFT, + RIGHT, + CENTER, + }; + + // An easy-to-understand interpretation of SNR and RSSI + // Calculate with Applet::getSignalStrength + enum SignalStrength : int8_t { + SIGNAL_UNKNOWN = -1, + SIGNAL_NONE, + SIGNAL_BAD, + SIGNAL_FAIR, + SIGNAL_GOOD, + }; + Applet(); - void setTile(Tile *t); // Applets draw via a tile (for multiplexing) - Tile *getTile(); + void setTile(Tile *t); // Should only be called via Tile::setApplet + Tile *getTile(); // Tile with which this applet is linked - void render(); - bool wantsToRender(); // Check whether applet wants to render - bool wantsToAutoshow(); // Check whether applets wants to become foreground, to show new data, if permitted + // Rendering + + void render(); // Draw the applet + bool wantsToRender(); // Check whether applet wants to render + bool wantsToAutoshow(); // Check whether applet wants to become foreground Drivers::EInk::UpdateTypes wantsUpdateType(); // Check which display update type the applet would prefer void updateDimensions(); // Get current size from tile void resetDrawingSpace(); // Makes sure every render starts with same parameters - // Change the applet's state - - void activate(); - void deactivate(); - void bringToForeground(); - void sendToBackground(); - - // Info about applet's state + // State of the applet + void activate(); // Begin running + void deactivate(); // Stop running + void bringToForeground(); // Show + void sendToBackground(); // Hide bool isActive(); bool isForeground(); - // Allow derived applets to handle changes in state + // Event handlers virtual void onRender() = 0; // All drawing happens here virtual void onActivate() {} @@ -150,62 +88,63 @@ class Applet : public GFX virtual void onForeground() {} virtual void onBackground() {} virtual void onShutdown() {} - virtual void onButtonShortPress() {} // For use by System Applets only - virtual void onButtonLongPress() {} // For use by System Applets only - virtual void onLockAvailable() {} // For use by System Applets only + virtual void onButtonShortPress() {} // (System Applets only) + virtual void onButtonLongPress() {} // (System Applets only) virtual bool approveNotification(Notification &n); // Allow an applet to veto a notification - static void setDefaultFonts(AppletFont large, AppletFont small); // Set the general purpose fonts - static uint16_t getHeaderHeight(); // How tall is the "standard" applet header + static uint16_t getHeaderHeight(); // How tall the "standard" applet header is - const char *name = nullptr; // Shown in applet selection menu + static AppletFont fontSmall, fontLarge; // The general purpose fonts, used by all applets + + const char *name = nullptr; // Shown in applet selection menu. Also used as an identifier by InkHUD::getSystemApplet protected: - // Place a single pixel. All drawing methods output through here - void drawPixel(int16_t x, int16_t y, uint16_t color) override; + void drawPixel(int16_t x, int16_t y, uint16_t color) override; // Place a single pixel. All drawing output passes through here - // Tell WindowManager to update display - void requestUpdate(EInk::UpdateTypes type = EInk::UpdateTypes::UNSPECIFIED); - - // Ask for applet to be moved to foreground - void requestAutoshow(); + void requestUpdate(EInk::UpdateTypes type = EInk::UpdateTypes::UNSPECIFIED); // Ask WindowManager to schedule a display update + void requestAutoshow(); // Ask for applet to be moved to foreground uint16_t X(float f); // Map applet width, mapped from 0 to 1.0 uint16_t Y(float f); // Map applet height, mapped from 0 to 1.0 void setCrop(int16_t left, int16_t top, uint16_t width, uint16_t height); // Ignore pixels drawn outside a certain region void resetCrop(); // Removes setCrop() + // Text + void setFont(AppletFont f); AppletFont getFont(); - uint16_t getTextWidth(std::string text); uint16_t getTextWidth(const char *text); - + uint32_t getWrappedTextHeight(int16_t left, uint16_t width, std::string text); // Result of printWrapped void printAt(int16_t x, int16_t y, const char *text, HorizontalAlignment ha = LEFT, VerticalAlignment va = TOP); void printAt(int16_t x, int16_t y, std::string text, HorizontalAlignment ha = LEFT, VerticalAlignment va = TOP); - void printThick(int16_t xCenter, int16_t yCenter, std::string text, uint8_t thicknessX, uint8_t thicknessY); - - // Print text, with per-word line wrapping - void printWrapped(int16_t left, int16_t top, uint16_t width, std::string text); - uint32_t getWrappedTextHeight(int16_t left, uint16_t width, std::string text); + void printThick(int16_t xCenter, int16_t yCenter, std::string text, uint8_t thicknessX, uint8_t thicknessY); // Faux bold + void printWrapped(int16_t left, int16_t top, uint16_t width, std::string text); // Per-word line wrapping void hatchRegion(int16_t x, int16_t y, uint16_t w, uint16_t h, uint8_t spacing, Color color); // Fill with sparse lines void drawHeader(std::string text); // Draw the standard applet header + // Meshtastic Logo + static constexpr float LOGO_ASPECT_RATIO = 1.9; // Width:Height for drawing the Meshtastic logo uint16_t getLogoWidth(uint16_t limitWidth, uint16_t limitHeight); // Size Meshtastic logo to fit within region uint16_t getLogoHeight(uint16_t limitWidth, uint16_t limitHeight); // Size Meshtastic logo to fit within region - void drawLogo(int16_t centerX, int16_t centerY, uint16_t width, uint16_t height); // Draw the meshtastic logo + void drawLogo(int16_t centerX, int16_t centerY, uint16_t width, uint16_t height, + Color color = BLACK); // Draw the Meshtastic logo - std::string hexifyNodeNum(NodeNum num); + std::string hexifyNodeNum(NodeNum num); // Style as !0123abdc SignalStrength getSignalStrength(float snr, float rssi); // Interpret SNR and RSSI, as an easy to understand value std::string getTimeString(uint32_t epochSeconds); // Human readable std::string getTimeString(); // Current time, human readable uint16_t getActiveNodeCount(); // Duration determined by user, in onscreen menu std::string localizeDistance(uint32_t meters); // Human readable distance, imperial or metric - static AppletFont fontSmall, fontLarge; // General purpose fonts, used cross-applet + // Convenient references + + InkHUD *inkhud = nullptr; + Persistence::Settings *settings = nullptr; + Persistence::LatestMessage *latestMessage = nullptr; private: Tile *assignedTile = nullptr; // Rendered pixels are fed into a Tile object, which translates them, then passes to WM @@ -223,10 +162,10 @@ class Applet : public GFX AppletFont currentFont; // As passed to setFont // As set by setCrop - int16_t cropLeft; - int16_t cropTop; - uint16_t cropWidth; - uint16_t cropHeight; + int16_t cropLeft = 0; + int16_t cropTop = 0; + uint16_t cropWidth = 0; + uint16_t cropHeight = 0; }; }; // namespace NicheGraphics::InkHUD diff --git a/src/graphics/niche/InkHUD/AppletFont.cpp b/src/graphics/niche/InkHUD/AppletFont.cpp index bee9d33e6..25597c9b9 100644 --- a/src/graphics/niche/InkHUD/AppletFont.cpp +++ b/src/graphics/niche/InkHUD/AppletFont.cpp @@ -12,7 +12,7 @@ InkHUD::AppletFont::AppletFont() InkHUD::AppletFont::AppletFont(const GFXfont &adafruitGFXFont) : gfxFont(&adafruitGFXFont) { // AdafruitGFX fonts are drawn relative to a "cursor line"; - // they print as if the glyphs resting on the line of piece of ruled paper. + // they print as if the glyphs are resting on the line of piece of ruled paper. // The glyphs also each have a different height. // To simplify drawing, we will scan the entire font now, and determine an appropriate height for a line of text @@ -42,6 +42,19 @@ InkHUD::AppletFont::AppletFont(const GFXfont &adafruitGFXFont) : gfxFont(&adafru spaceCharWidth = gfxFont->glyph[(uint8_t)' ' - gfxFont->first].xAdvance; } +/* + + ▲ ##### # ▲ + │ # # │ + lineHeight │ ### # │ + │ # # # # │ heightAboveCursor + │ # # # # │ + │ # # #### │ + │ -----------------#---- + │ # │ heightBelowCursor + ▼ ### ▼ +*/ + uint8_t InkHUD::AppletFont::lineHeight() { return this->height; @@ -78,7 +91,7 @@ void InkHUD::AppletFont::addSubstitution(const char *from, const char *to) substitutions.push_back({.from = from, .to = to}); } -// Run all registered subtitutions on a string +// Run all registered substitutions on a string // Used to swap out UTF8 special chars void InkHUD::AppletFont::applySubstitutions(std::string *text) { @@ -87,7 +100,7 @@ void InkHUD::AppletFont::applySubstitutions(std::string *text) // Find and replace // - search for Substitution::from - // - replace with Subsitution::to + // - replace with Substitution::to size_t i = text->find(s.from); while (i != std::string::npos) { text->replace(i, strlen(s.from), s.to); @@ -97,7 +110,7 @@ void InkHUD::AppletFont::applySubstitutions(std::string *text) } // Apply a set of substitutions which remap UTF8 for a Windows-1251 font -// Windows-1251 is an 8-bit character encoding, designed to cover languages that use the Cyrillic script +// Windows-1251 is an 8-bit character encoding, suitable for several languages which use the Cyrillic script void InkHUD::AppletFont::addSubstitutionsWin1251() { addSubstitution("Ђ", "\x80"); diff --git a/src/graphics/niche/InkHUD/AppletFont.h b/src/graphics/niche/InkHUD/AppletFont.h index 89f901c94..504bd12b3 100644 --- a/src/graphics/niche/InkHUD/AppletFont.h +++ b/src/graphics/niche/InkHUD/AppletFont.h @@ -15,7 +15,7 @@ #include "configuration.h" -#include +#include // GFXRoot drawing lib namespace NicheGraphics::InkHUD { @@ -25,11 +25,12 @@ class AppletFont { public: AppletFont(); - AppletFont(const GFXfont &adafruitGFXFont); + explicit AppletFont(const GFXfont &adafruitGFXFont); + uint8_t lineHeight(); uint8_t heightAboveCursor(); uint8_t heightBelowCursor(); - uint8_t widthBetweenWords(); + uint8_t widthBetweenWords(); // Width of the space character void applySubstitutions(std::string *text); // Run all char-substitution operations, prior to printing void addSubstitution(const char *from, const char *to); // Register a find-replace action, for remapping UTF8 chars @@ -50,8 +51,7 @@ class AppletFont const char *to; }; - // List of all character substitutions to run, prior to printing a string - std::vector substitutions; + std::vector substitutions; // List of all character substitutions to run, prior to printing a string }; } // namespace NicheGraphics::InkHUD diff --git a/src/graphics/niche/InkHUD/Applets/Bases/Map/MapApplet.cpp b/src/graphics/niche/InkHUD/Applets/Bases/Map/MapApplet.cpp index 21f404349..ea7b74262 100644 --- a/src/graphics/niche/InkHUD/Applets/Bases/Map/MapApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/Bases/Map/MapApplet.cpp @@ -6,8 +6,6 @@ using namespace NicheGraphics; void InkHUD::MapApplet::onRender() { - setFont(fontSmall); - // Abort if no markers to render if (!enoughMarkers()) { printAt(X(0.5), Y(0.5) - (getFont().lineHeight() / 2), "Node positions", CENTER, MIDDLE); @@ -27,6 +25,7 @@ void InkHUD::MapApplet::onRender() // Set the region shown on the map // - default: fit all nodes, plus padding // - maybe overriden by derived applet + // - getMapSize *sets* passed parameters (C-style) getMapSize(&widthMeters, &heightMeters); // Set the metersToPx conversion value @@ -71,7 +70,7 @@ void InkHUD::MapApplet::getMapCenter(float *lat, float *lng) // - uses tan to find angles for lat / long degrees // - longitude: triangle formed by x and y (on plane of the equator) // - latitude: triangle formed by z (north south), - // and the line along plane of equator which stetches from earth's axis to where point xyz intersects planet's surface + // and the line along plane of equator which stretches from earth's axis to where point xyz intersects planet's surface // Working totals, averaged after nodeDB processed uint32_t positionCount = 0; @@ -134,7 +133,7 @@ void InkHUD::MapApplet::getMapCenter(float *lat, float *lng) *lng = atan2(yAvg, xAvg) * RAD_TO_DEG; - // Latitude from cartesian cooods + // Latitude from cartesian coords // (Angle from 3D coords describing a point on the globe's surface) // As latitude increases, distance from the Earth's north-south axis out to our surface point decreases. // Means we need to first find the hypotenuse which becomes base of our triangle in the second step @@ -191,8 +190,8 @@ void InkHUD::MapApplet::getMapCenter(float *lat, float *lng) // Longitude is trickier float lng = node->position.longitude_i * 1e-7; - float degEastward = fmod(((lng - lngCenter) + 360), 360); // Degrees travelled east from lngCenter to reach node - float degWestward = abs(fmod(((lng - lngCenter) - 360), 360)); // Degrees travelled west from lngCenter to reach node + float degEastward = fmod(((lng - lngCenter) + 360), 360); // Degrees traveled east from lngCenter to reach node + float degWestward = abs(fmod(((lng - lngCenter) - 360), 360)); // Degrees traveled west from lngCenter to reach node if (degEastward < degWestward) easternmost = max(easternmost, lngCenter + degEastward); else @@ -258,7 +257,7 @@ void InkHUD::MapApplet::drawLabeledMarker(meshtastic_NodeInfoLite *node) // Find x and y position based on node's position in nodeDB assert(nodeDB->hasValidPosition(node)); Marker m = calculateMarker(node->position.latitude_i * 1e-7, // Lat, converted from Meshtastic's internal int32 style - node->position.longitude_i * 1e-7, // Long, convered from Meshtastic's internal int32 style + node->position.longitude_i * 1e-7, // Long, converted from Meshtastic's internal int32 style node->has_hops_away, // Is the hopsAway number valid node->hops_away // Hops away ); @@ -288,7 +287,7 @@ void InkHUD::MapApplet::drawLabeledMarker(meshtastic_NodeInfoLite *node) bool unknownHops = !node->has_hops_away && !isOurNode; // We will draw a left or right hand variant, to place text towards screen center - // Hopfully avoid text spilling off screen + // Hopefully avoid text spilling off screen // Most values are the same, regardless of left-right handedness // Pick emblem style @@ -388,7 +387,7 @@ void InkHUD::MapApplet::calculateAllMarkers() // Calculate marker and store it markers.push_back( calculateMarker(node->position.latitude_i * 1e-7, // Lat, converted from Meshtastic's internal int32 style - node->position.longitude_i * 1e-7, // Long, convered from Meshtastic's internal int32 style + node->position.longitude_i * 1e-7, // Long, converted from Meshtastic's internal int32 style node->has_hops_away, // Is the hopsAway number valid node->hops_away // Hops away )); diff --git a/src/graphics/niche/InkHUD/Applets/Bases/Map/MapApplet.h b/src/graphics/niche/InkHUD/Applets/Bases/Map/MapApplet.h index fd5245631..f45a36071 100644 --- a/src/graphics/niche/InkHUD/Applets/Bases/Map/MapApplet.h +++ b/src/graphics/niche/InkHUD/Applets/Bases/Map/MapApplet.h @@ -38,13 +38,12 @@ class MapApplet : public Applet void drawLabeledMarker(meshtastic_NodeInfoLite *node); // Highlight a specific marker private: - // Position of markers to be drawn, relative to map center - // HopsAway info used to determine marker size + // Position and size of a marker to be drawn struct Marker { - float eastMeters = 0; // Meters east of mapCenter. Negative if west. - float northMeters = 0; // Meters north of mapCenter. Negative if south. + float eastMeters = 0; // Meters east of map center. Negative if west. + float northMeters = 0; // Meters north of map center. Negative if south. bool hasHopsAway = false; - uint8_t hopsAway = 0; + uint8_t hopsAway = 0; // Determines marker size }; Marker calculateMarker(float lat, float lng, bool hasHopsAway, uint8_t hopsAway); diff --git a/src/graphics/niche/InkHUD/Applets/Bases/NodeList/NodeListApplet.cpp b/src/graphics/niche/InkHUD/Applets/Bases/NodeList/NodeListApplet.cpp index 5d60e6800..8ede40780 100644 --- a/src/graphics/niche/InkHUD/Applets/Bases/NodeList/NodeListApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/Bases/NodeList/NodeListApplet.cpp @@ -12,7 +12,7 @@ using namespace NicheGraphics; InkHUD::NodeListApplet::NodeListApplet(const char *name) : MeshModule(name) { // We only need to be promiscuous in order to hear NodeInfo, apparently. See NodeInfoModule - // For all other packets, we manually reimplement isPromiscuous=false in wantPacket + // For all other packets, we manually act as if isPromiscuous=false, in wantPacket MeshModule::isPromiscuous = true; } @@ -25,17 +25,17 @@ bool InkHUD::NodeListApplet::wantPacket(const meshtastic_MeshPacket *p) && (isToUs(p) || isBroadcast(p->to) || // Either: intended for us, p->decoded.portnum == meshtastic_PortNum_NODEINFO_APP); // or nodeinfo - // Note: special handling of NodeInfo is to match NodeInfoModule // To match the behavior seen in the client apps: // - NodeInfoModule's ProtoBufModule base is "promiscuous" // - All other activity is *not* promiscuous - // To achieve this, our MeshModule *is* promiscious, and we're manually reimplementing non-promiscuous behavior here, + + // To achieve this, our MeshModule *is* promiscuous, and we're manually reimplementing non-promiscuous behavior here, // to match the code in MeshModule::callModules } // MeshModule packets arrive here // Extract the info and pass it to the derived applet -// Derived applet will store the CardInfo and perform any required sorting of the CardInfo collection +// Derived applet will store the CardInfo, and perform any required sorting of the CardInfo collection // Derived applet might also need to keep other tallies (active nodes count?) ProcessMessage InkHUD::NodeListApplet::handleReceived(const meshtastic_MeshPacket &mp) { @@ -76,8 +76,8 @@ ProcessMessage InkHUD::NodeListApplet::handleReceived(const meshtastic_MeshPacke return ProcessMessage::CONTINUE; // Let others look at this message also if they want } -// Maximum number of cards we may ever need to render, in our tallest layout config -// May be slightly in excess of the true value: header not accounted for +// Calculate maximum number of cards we may ever need to render, in our tallest layout config +// Number might be slightly in excess of the true value: applet header text not accounted for uint8_t InkHUD::NodeListApplet::maxCards() { // Cache result. Shouldn't change during execution @@ -87,7 +87,7 @@ uint8_t InkHUD::NodeListApplet::maxCards() const uint16_t height = Tile::maxDisplayDimension(); // Use a loop instead of arithmetic, because it's easier for my brain to follow - // Add cards one by one, until the latest card (without margin) extends below screen + // Add cards one by one, until the latest card extends below screen uint16_t y = cardH; // First card: no margin above cards = 1; @@ -102,7 +102,7 @@ uint8_t InkHUD::NodeListApplet::maxCards() return cards; } -// Draw using info which derived applet placed into NodeListApplet::cards for us +// Draw, using info which derived applet placed into NodeListApplet::cards for us void InkHUD::NodeListApplet::onRender() { @@ -120,9 +120,6 @@ void InkHUD::NodeListApplet::onRender() // Draw the main node list // ======================== - // const uint8_t cardMarginH = fontSmall.lineHeight() / 2; // Gap between cards - // const uint16_t cardH = fontLarge.lineHeight() + fontSmall.lineHeight() + cardMarginH; - // Imaginary vertical line dividing left-side and right-side info // Long-name will crop here const uint16_t dividerX = (width() - 1) - getTextWidth("X Hops"); @@ -215,9 +212,8 @@ void InkHUD::NodeListApplet::onRender() // Once we've run out of screen, stop drawing cards // Depending on tiles / rotation, this may be before we hit maxCards - if (cardTopY > height()) { + if (cardTopY > height()) break; - } } } @@ -246,20 +242,20 @@ void InkHUD::NodeListApplet::drawSignalIndicator(int16_t x, int16_t y, uint16_t constexpr float paddingW = 0.1; // Either side constexpr float paddingH = 0.1; // Above and below - constexpr float gutterX = 0.1; // Between bars + constexpr float gutterW = 0.1; // Between bars - constexpr float barHRel[] = {0.3, 0.5, 0.7, 1.0}; // Heights of the signal bars, relative to the talleest + constexpr float barHRel[] = {0.3, 0.5, 0.7, 1.0}; // Heights of the signal bars, relative to the tallest constexpr uint8_t barCount = 4; // How many bars we draw. Reference only: changing value won't change the count. // Dynamically calculate the width of the bars, and height of the rightmost, relative to other dimensions - float barW = (1.0 - (paddingW + ((barCount - 1) * gutterX) + paddingW)) / barCount; + float barW = (1.0 - (paddingW + ((barCount - 1) * gutterW) + paddingW)) / barCount; float barHMax = 1.0 - (paddingH + paddingH); // Draw signal bar rectangles, then placeholder lines once strength reached for (uint8_t i = 0; i < barCount; i++) { - // Co-ords for this specific bar + // Coords for this specific bar float barH = barHMax * barHRel[i]; - float barX = paddingW + (i * (gutterX + barW)); + float barX = paddingW + (i * (gutterW + barW)); float barY = paddingH + (barHMax - barH); // Rasterize to px coords at the last moment diff --git a/src/graphics/niche/InkHUD/Applets/Bases/NodeList/NodeListApplet.h b/src/graphics/niche/InkHUD/Applets/Bases/NodeList/NodeListApplet.h index 670dd9e9a..0abcad824 100644 --- a/src/graphics/niche/InkHUD/Applets/Bases/NodeList/NodeListApplet.h +++ b/src/graphics/niche/InkHUD/Applets/Bases/NodeList/NodeListApplet.h @@ -23,13 +23,16 @@ Used by the "Recents" and "Heard" applets. Possibly more in future? #include "graphics/niche/InkHUD/Applet.h" +#include "main.h" + namespace NicheGraphics::InkHUD { class NodeListApplet : public Applet, public MeshModule { protected: - // Info used to draw one card to the node list + // Info needed to draw a node card to the list + // - generated each time we hear a node struct CardInfo { static constexpr uint8_t HOPS_UNKNOWN = -1; static constexpr uint32_t DISTANCE_UNKNOWN = -1; @@ -37,31 +40,31 @@ class NodeListApplet : public Applet, public MeshModule NodeNum nodeNum = 0; SignalStrength signal = SignalStrength::SIGNAL_UNKNOWN; uint32_t distanceMeters = DISTANCE_UNKNOWN; - uint8_t hopsAway = HOPS_UNKNOWN; // Unknown + uint8_t hopsAway = HOPS_UNKNOWN; }; public: NodeListApplet(const char *name); + void onRender() override; - // MeshModule overrides - virtual bool wantPacket(const meshtastic_MeshPacket *p) override; - virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override; + bool wantPacket(const meshtastic_MeshPacket *p) override; + ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override; protected: - virtual void handleParsed(CardInfo c) = 0; // Pass extracted info from a new packet to derived class, for sorting and storage - virtual std::string getHeaderText() = 0; // Title for the applet's header. Todo: get this info another way? + virtual void handleParsed(CardInfo c) = 0; // Tell derived applet that we heard a node + virtual std::string getHeaderText() = 0; // Ask derived class what the applet's title should be - uint8_t maxCards(); // Calculate the maximum number of cards an applet could ever display + uint8_t maxCards(); // Max number of cards which could ever fit on screen - std::deque cards; // Derived applet places cards here, for this base applet to render + std::deque cards; // Cards to be rendered. Derived applet fills this. private: - // UI element: a "mobile phone" style signal indicator - void drawSignalIndicator(int16_t x, int16_t y, uint16_t w, uint16_t h, SignalStrength signal); + void drawSignalIndicator(int16_t x, int16_t y, uint16_t w, uint16_t h, + SignalStrength signal); // Draw a "mobile phone" style signal indicator - // Dimensions for drawing - // Used for render, and also for maxCards calc + // Card Dimensions + // - for rendering and for maxCards calc const uint8_t cardMarginH = fontSmall.lineHeight() / 2; // Gap between cards const uint16_t cardH = fontLarge.lineHeight() + fontSmall.lineHeight() + cardMarginH; // Height of card }; diff --git a/src/graphics/niche/InkHUD/Applets/Examples/BasicExample/BasicExampleApplet.cpp b/src/graphics/niche/InkHUD/Applets/Examples/BasicExample/BasicExampleApplet.cpp index 17458ab96..b12ea4809 100644 --- a/src/graphics/niche/InkHUD/Applets/Examples/BasicExample/BasicExampleApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/Examples/BasicExample/BasicExampleApplet.cpp @@ -8,7 +8,7 @@ using namespace NicheGraphics; // Our basic example doesn't do anything useful. It just passively prints some text. void InkHUD::BasicExampleApplet::onRender() { - print("Hello, World!"); + printAt(0, 0, "Hello, World!"); } #endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/Applets/Examples/NewMsgExample/NewMsgExampleApplet.cpp b/src/graphics/niche/InkHUD/Applets/Examples/NewMsgExample/NewMsgExampleApplet.cpp index e0b2a4238..6b02f4c92 100644 --- a/src/graphics/niche/InkHUD/Applets/Examples/NewMsgExample/NewMsgExampleApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/Examples/NewMsgExample/NewMsgExampleApplet.cpp @@ -4,11 +4,12 @@ using namespace NicheGraphics; -// We configured MeshModule API to call this method when we receive a new text message +// We configured the Module API to call this method when we receive a new text message ProcessMessage InkHUD::NewMsgExampleApplet::handleReceived(const meshtastic_MeshPacket &mp) { // Abort if applet fully deactivated + // Don't waste time: we wouldn't be rendered anyway if (!isActive()) return ProcessMessage::CONTINUE; @@ -25,7 +26,7 @@ ProcessMessage InkHUD::NewMsgExampleApplet::handleReceived(const meshtastic_Mesh requestUpdate(); } - // Tell MeshModule API to continue informing other firmware components about this message + // Tell Module API to continue informing other firmware components about this message // We're not the only component which is interested in new text messages return ProcessMessage::CONTINUE; } @@ -36,8 +37,6 @@ ProcessMessage InkHUD::NewMsgExampleApplet::handleReceived(const meshtastic_Mesh // We should always be ready to draw void InkHUD::NewMsgExampleApplet::onRender() { - setFont(fontSmall); - printAt(0, 0, "Example: NewMsg", LEFT, TOP); // Print top-left corner of text at (0,0) int16_t centerX = X(0.5); // Same as width() / 2 diff --git a/src/graphics/niche/InkHUD/Applets/Examples/NewMsgExample/NewMsgExampleApplet.h b/src/graphics/niche/InkHUD/Applets/Examples/NewMsgExample/NewMsgExampleApplet.h index edfb211d7..f280afcda 100644 --- a/src/graphics/niche/InkHUD/Applets/Examples/NewMsgExample/NewMsgExampleApplet.h +++ b/src/graphics/niche/InkHUD/Applets/Examples/NewMsgExample/NewMsgExampleApplet.h @@ -53,7 +53,7 @@ class NewMsgExampleApplet : public Applet, public SinglePortModule // Store info from handleReceived bool haveMessage = false; - NodeNum fromWho; + NodeNum fromWho = 0; }; } // namespace NicheGraphics::InkHUD diff --git a/src/graphics/niche/InkHUD/Applets/System/BatteryIcon/BatteryIconApplet.cpp b/src/graphics/niche/InkHUD/Applets/System/BatteryIcon/BatteryIconApplet.cpp index e4432a7c2..4f99d99ee 100644 --- a/src/graphics/niche/InkHUD/Applets/System/BatteryIcon/BatteryIconApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/System/BatteryIcon/BatteryIconApplet.cpp @@ -4,10 +4,10 @@ using namespace NicheGraphics; -void InkHUD::BatteryIconApplet::onActivate() +InkHUD::BatteryIconApplet::BatteryIconApplet() { // Show at boot, if user has previously enabled the feature - if (settings.optionalFeatures.batteryIcon) + if (settings->optionalFeatures.batteryIcon) bringToForeground(); // Register to our have BatteryIconApplet::onPowerStatusUpdate method called when new power info is available @@ -15,12 +15,6 @@ void InkHUD::BatteryIconApplet::onActivate() powerStatusObserver.observe(&powerStatus->onNewStatus); } -void InkHUD::BatteryIconApplet::onDeactivate() -{ - // Stop having onPowerStatusUpdate called - powerStatusObserver.unobserve(&powerStatus->onNewStatus); -} - // We handle power status' even when the feature is disabled, // so that we have up to date data ready if the feature is enabled later. // Otherwise could be 30s before new status update, with weird battery value displayed @@ -41,7 +35,7 @@ int InkHUD::BatteryIconApplet::onPowerStatusUpdate(const meshtastic::Status *sta // If rounded value has changed, trigger a display update // It's okay to requestUpdate before we store the new value, as the update won't run until next loop() // Don't trigger an update if the feature is disabled - if (this->socRounded != newSocRounded && settings.optionalFeatures.batteryIcon) + if (this->socRounded != newSocRounded && settings->optionalFeatures.batteryIcon) requestUpdate(); // Store the new value diff --git a/src/graphics/niche/InkHUD/Applets/System/BatteryIcon/BatteryIconApplet.h b/src/graphics/niche/InkHUD/Applets/System/BatteryIcon/BatteryIconApplet.h index 765ca073f..e5b4172be 100644 --- a/src/graphics/niche/InkHUD/Applets/System/BatteryIcon/BatteryIconApplet.h +++ b/src/graphics/niche/InkHUD/Applets/System/BatteryIcon/BatteryIconApplet.h @@ -11,24 +11,22 @@ It should be optional, enabled by the on-screen menu #include "configuration.h" -#include "graphics/niche/InkHUD/Applet.h" +#include "graphics/niche/InkHUD/SystemApplet.h" #include "PowerStatus.h" namespace NicheGraphics::InkHUD { -class BatteryIconApplet : public Applet +class BatteryIconApplet : public SystemApplet { public: + BatteryIconApplet(); + void onRender() override; - - void onActivate() override; - void onDeactivate() override; - int onPowerStatusUpdate(const meshtastic::Status *status); // Called when new info about battery is available - protected: + private: // Get informed when new information about the battery is available (via onPowerStatusUpdate method) CallbackObserver powerStatusObserver = CallbackObserver(this, &BatteryIconApplet::onPowerStatusUpdate); diff --git a/src/graphics/niche/InkHUD/Applets/System/Logo/LogoApplet.cpp b/src/graphics/niche/InkHUD/Applets/System/Logo/LogoApplet.cpp index cc24417ab..520b3ef65 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Logo/LogoApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/System/Logo/LogoApplet.cpp @@ -2,15 +2,22 @@ #include "./LogoApplet.h" +#include "mesh/NodeDB.h" + using namespace NicheGraphics; InkHUD::LogoApplet::LogoApplet() : concurrency::OSThread("LogoApplet") { - // Don't autostart the runOnce() timer - OSThread::disable(); + OSThread::setIntervalFromNow(8 * 1000UL); + OSThread::enabled = true; - // Grab the WindowManager singleton, for convenience - windowManager = WindowManager::getInstance(); + textLeft = ""; + textRight = ""; + textTitle = xstr(APP_VERSION_SHORT); + fontTitle = fontSmall; + + bringToForeground(); + // This is then drawn with a FULL refresh by Renderer::begin } void InkHUD::LogoApplet::onRender() @@ -27,7 +34,15 @@ void InkHUD::LogoApplet::onRender() int16_t logoCX = X(0.5); int16_t logoCY = Y(0.5 - 0.05); - drawLogo(logoCX, logoCY, logoW, logoH); + // Invert colors if black-on-white + // Used during shutdown, to resport display health + // Todo: handle this in InkHUD::Renderer instead + if (inverted) { + fillScreen(BLACK); + setTextColor(WHITE); + } + + drawLogo(logoCX, logoCY, logoW, logoH, inverted ? WHITE : BLACK); if (!textLeft.empty()) { setFont(fontSmall); @@ -48,61 +63,70 @@ void InkHUD::LogoApplet::onRender() void InkHUD::LogoApplet::onForeground() { - // If another applet has locked the display, ask it to exit - Applet *other = windowManager->whoLocked(); - if (other != nullptr) - other->sendToBackground(); - - windowManager->claimFullscreen(this); // Take ownership of fullscreen tile - windowManager->lock(this); // Prevent other applets from requesting updates + SystemApplet::lockRendering = true; + SystemApplet::lockRequests = true; + SystemApplet::handleInput = true; // We don't actually use this input. Just blocking other applets from using it. } void InkHUD::LogoApplet::onBackground() { - OSThread::disable(); // Disable auto-dismiss timer, in case applet was dismissed early (sendToBackground from outside class) - - windowManager->releaseFullscreen(); // Relinquish ownership of fullscreen tile - windowManager->unlock(this); // Allow normal user applet update requests to resume + SystemApplet::lockRendering = false; + SystemApplet::lockRequests = false; + SystemApplet::handleInput = false; // Need to force an update, as a polite request wouldn't be honored, seeing how we are now in the background // Usually, onBackground is followed by another applet's onForeground (which requests update), but not in this case - windowManager->forceUpdate(EInk::UpdateTypes::FULL); -} - -int32_t InkHUD::LogoApplet::runOnce() -{ - LOG_DEBUG("Sent to background by timer"); - sendToBackground(); - return OSThread::disable(); -} - -// Begin displaying the screen which is shown at startup -// Suggest EInk::await after calling this method -void InkHUD::LogoApplet::showBootScreen() -{ - OSThread::setIntervalFromNow(8 * 1000UL); - OSThread::enabled = true; - - textLeft = ""; - textRight = ""; - textTitle = xstr(APP_VERSION_SHORT); - fontTitle = fontSmall; - - bringToForeground(); - requestUpdate(Drivers::EInk::UpdateTypes::FULL); // Already requested, just upgrading to FULL + inkhud->forceUpdate(EInk::UpdateTypes::FULL); } // Begin displaying the screen which is shown at shutdown -// Needs EInk::await after calling this method, to ensure display updates before shutdown -void InkHUD::LogoApplet::showShutdownScreen() +void InkHUD::LogoApplet::onShutdown() { + bringToForeground(); + + textLeft = ""; + textRight = ""; + textTitle = "Shutting Down..."; + fontTitle = fontSmall; + + // Draw a shutting down screen, twice. + // Once white on black, once black on white. + // Intention is to restore display health. + + inverted = true; + inkhud->forceUpdate(Drivers::EInk::FULL, false); + delay(1000); // Cooldown. Back to back updates aren't great for health. + inverted = false; + inkhud->forceUpdate(Drivers::EInk::FULL, false); + delay(1000); // Cooldown + + // Prepare for the powered-off screen now + // We can change these values because the initial "shutting down" screen has already rendered at this point textLeft = ""; textRight = ""; textTitle = owner.short_name; fontTitle = fontLarge; + // This is then drawn by InkHUD::Events::onShutdown, with a blocking FULL update, after InkHUD's flash write is complete +} + +void InkHUD::LogoApplet::onReboot() +{ bringToForeground(); - requestUpdate(Drivers::EInk::UpdateTypes::FULL); // Already requested, just upgrading to FULL + + textLeft = ""; + textRight = ""; + textTitle = "Rebooting..."; + fontTitle = fontSmall; + + inkhud->forceUpdate(Drivers::EInk::FULL, false); + // Perform the update right now, waiting here until complete +} + +int32_t InkHUD::LogoApplet::runOnce() +{ + sendToBackground(); + return OSThread::disable(); } #endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/Applets/System/Logo/LogoApplet.h b/src/graphics/niche/InkHUD/Applets/System/Logo/LogoApplet.h index aa1bf8b2c..3f604baed 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Logo/LogoApplet.h +++ b/src/graphics/niche/InkHUD/Applets/System/Logo/LogoApplet.h @@ -12,24 +12,20 @@ #include "configuration.h" #include "concurrency/OSThread.h" -#include "graphics/niche/InkHUD/Applet.h" +#include "graphics/niche/InkHUD/SystemApplet.h" namespace NicheGraphics::InkHUD { -class LogoApplet : public Applet, public concurrency::OSThread +class LogoApplet : public SystemApplet, public concurrency::OSThread { public: LogoApplet(); void onRender() override; void onForeground() override; void onBackground() override; - - // Note: interacting directly with an applet like this is non-standard - // Only permitted because this is a "system applet", which has special behavior and interacts directly with WindowManager - - void showBootScreen(); - void showShutdownScreen(); + void onShutdown() override; + void onReboot() override; protected: int32_t runOnce() override; @@ -38,8 +34,7 @@ class LogoApplet : public Applet, public concurrency::OSThread std::string textRight; std::string textTitle; AppletFont fontTitle; - - WindowManager *windowManager = nullptr; // For convenience + bool inverted = false; // Invert colors. Used during shutdown, to restore display health. }; } // namespace NicheGraphics::InkHUD diff --git a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuAction.h b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuAction.h index 6950bb110..4f8205647 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuAction.h +++ b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuAction.h @@ -22,15 +22,17 @@ enum MenuAction { SEND_POSITION, SHUTDOWN, NEXT_TILE, + TOGGLE_BACKLIGHT, + TOGGLE_GPS, + ENABLE_BLUETOOTH, TOGGLE_APPLET, - ACTIVATE_APPLETS, // Todo: remove? Possible redundant, handled by TOGGLE_APPLET? TOGGLE_AUTOSHOW_APPLET, SET_RECENTS, ROTATE, LAYOUT, TOGGLE_BATTERY_ICON, TOGGLE_NOTIFICATIONS, - TOGGLE_BACKLIGHT, + TOGGLE_12H_CLOCK, }; } // namespace NicheGraphics::InkHUD diff --git a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.cpp b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.cpp index d24ae59a5..f59579230 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.cpp @@ -2,9 +2,16 @@ #include "./MenuApplet.h" -#include "PowerStatus.h" #include "RTC.h" +#include "airtime.h" +#include "main.h" +#include "power.h" + +#if !MESHTASTIC_EXCLUDE_GPS +#include "GPS.h" +#endif + using namespace NicheGraphics; static constexpr uint8_t MENU_TIMEOUT_SEC = 60; // How many seconds before menu auto-closes @@ -17,19 +24,10 @@ InkHUD::MenuApplet::MenuApplet() : concurrency::OSThread("MenuApplet") { // No timer tasks at boot OSThread::disable(); -} - -void InkHUD::MenuApplet::onActivate() -{ - // Grab pointers to some singleton components which the menu interacts with - // We could do this every time we needed them, in place, - // but this just makes the code tidier - - this->windowManager = WindowManager::getInstance(); // Note: don't get instance if we're not actually using the backlight, // or else you will unintentionally instantiate it - if (settings.optionalMenuItems.backlight) { + if (settings->optionalMenuItems.backlight) { backlight = Drivers::LatchingBacklight::getInstance(); } } @@ -45,21 +43,23 @@ void InkHUD::MenuApplet::onForeground() // If device has a backlight which isn't controlled by aux button: // backlight on always when menu opens. // Courtesy to T-Echo users who removed the capacitive touch button - if (settings.optionalMenuItems.backlight) { + if (settings->optionalMenuItems.backlight) { assert(backlight); if (!backlight->isOn()) backlight->peek(); } - // Prevent user applets requested update while menu is open - windowManager->lock(this); + // Prevent user applets requesting update while menu is open + // Handle button input with this applet + SystemApplet::lockRequests = true; + SystemApplet::handleInput = true; // Begin the auto-close timeout OSThread::setIntervalFromNow(MENU_TIMEOUT_SEC * 1000UL); OSThread::enabled = true; // Upgrade the refresh to FAST, for guaranteed responsiveness - windowManager->forceUpdate(EInk::UpdateTypes::FAST); + inkhud->forceUpdate(EInk::UpdateTypes::FAST); } void InkHUD::MenuApplet::onBackground() @@ -67,7 +67,7 @@ void InkHUD::MenuApplet::onBackground() // If device has a backlight which isn't controlled by aux button: // Item in options submenu allows keeping backlight on after menu is closed // If this item is deselected we will turn backlight off again, now that menu is closing - if (settings.optionalMenuItems.backlight) { + if (settings->optionalMenuItems.backlight) { assert(backlight); if (!backlight->isLatched()) backlight->off(); @@ -77,7 +77,8 @@ void InkHUD::MenuApplet::onBackground() OSThread::disable(); // Resume normal rendering and button behavior of user applets - windowManager->unlock(this); + SystemApplet::lockRequests = false; + SystemApplet::handleInput = false; // Restore the user applet whose tile we borrowed if (borrowedTileOwner) @@ -87,8 +88,8 @@ void InkHUD::MenuApplet::onBackground() borrowedTileOwner = nullptr; // Need to force an update, as a polite request wouldn't be honored, seeing how we are now in the background - // We're only updating here to ugrade from UNSPECIFIED to FAST, to ensure responsiveness when exiting menu - windowManager->forceUpdate(EInk::UpdateTypes::FAST); + // We're only updating here to upgrade from UNSPECIFIED to FAST, to ensure responsiveness when exiting menu + inkhud->forceUpdate(EInk::UpdateTypes::FAST); } // Open the menu @@ -140,43 +141,29 @@ void InkHUD::MenuApplet::execute(MenuItem item) break; case NEXT_TILE: - // Note performed manually; - // WindowManager::nextTile is raised by aux button press only, and will interact poorly with the menu - settings.userTiles.focused = (settings.userTiles.focused + 1) % settings.userTiles.count; - windowManager->changeLayout(); - cursor = 0; // No menu item selected, for quick exit after tile swap - cursorShown = false; + inkhud->nextTile(); break; case ROTATE: - settings.rotation = (settings.rotation + 1) % 4; - windowManager->changeLayout(); - // requestUpdate(Drivers::EInk::UpdateTypes::FULL); // Would update regardless; just selecting FULL + inkhud->rotate(); break; case LAYOUT: // Todo: smarter incrementing of tile count - settings.userTiles.count++; + settings->userTiles.count++; - if (settings.userTiles.count == 3) // Skip 3 tiles: not done yet - settings.userTiles.count++; + if (settings->userTiles.count == 3) // Skip 3 tiles: not done yet + settings->userTiles.count++; - if (settings.userTiles.count > settings.userTiles.maxCount) // Loop around if tile count now too high - settings.userTiles.count = 1; + if (settings->userTiles.count > settings->userTiles.maxCount) // Loop around if tile count now too high + settings->userTiles.count = 1; - windowManager->changeLayout(); - // requestUpdate(Drivers::EInk::UpdateTypes::FULL); // Would update regardless; just selecting FULL + inkhud->updateLayout(); break; case TOGGLE_APPLET: - settings.userApplets.active[cursor] = !settings.userApplets.active[cursor]; - windowManager->changeActivatedApplets(); - // requestUpdate(Drivers::EInk::UpdateTypes::FULL); // Select FULL, seeing how this action doesn't auto exit - break; - - case ACTIVATE_APPLETS: - // Todo: remove this action? Already handled by TOGGLE_APPLET? - windowManager->changeActivatedApplets(); + settings->userApplets.active[cursor] = !settings->userApplets.active[cursor]; + inkhud->updateAppletSelection(); break; case TOGGLE_AUTOSHOW_APPLET: @@ -185,14 +172,14 @@ void InkHUD::MenuApplet::execute(MenuItem item) break; case TOGGLE_NOTIFICATIONS: - settings.optionalFeatures.notifications = !settings.optionalFeatures.notifications; + settings->optionalFeatures.notifications = !settings->optionalFeatures.notifications; break; case SET_RECENTS: // Set value of settings.recentlyActiveSeconds // Uses menu cursor to read RECENTS_OPTIONS_MINUTES array (defined at top of this file) assert(cursor < sizeof(RECENTS_OPTIONS_MINUTES) / sizeof(RECENTS_OPTIONS_MINUTES[0])); - settings.recentlyActiveSeconds = RECENTS_OPTIONS_MINUTES[cursor] * 60; // Menu items are in minutes + settings->recentlyActiveSeconds = RECENTS_OPTIONS_MINUTES[cursor] * 60; // Menu items are in minutes break; case SHUTDOWN: @@ -202,7 +189,7 @@ void InkHUD::MenuApplet::execute(MenuItem item) break; case TOGGLE_BATTERY_ICON: - windowManager->toggleBatteryIcon(); + inkhud->toggleBatteryIcon(); break; case TOGGLE_BACKLIGHT: @@ -215,6 +202,25 @@ void InkHUD::MenuApplet::execute(MenuItem item) backlight->latch(); break; + case TOGGLE_12H_CLOCK: + config.display.use_12h_clock = !config.display.use_12h_clock; + nodeDB->saveToDisk(SEGMENT_CONFIG); + break; + + case TOGGLE_GPS: + gps->toggleGpsMode(); + nodeDB->saveToDisk(SEGMENT_CONFIG); + break; + + case ENABLE_BLUETOOTH: + // This helps users recover from a bad wifi config + LOG_INFO("Enabling Bluetooth"); + config.network.wifi_enabled = false; + config.bluetooth.enabled = true; + nodeDB->saveToDisk(); + rebootAtMsec = millis() + 2000; + break; + default: LOG_WARN("Action not implemented"); } @@ -233,13 +239,13 @@ void InkHUD::MenuApplet::showPage(MenuPage page) switch (page) { case ROOT: // Optional: next applet - if (settings.optionalMenuItems.nextTile && settings.userTiles.count > 1) + if (settings->optionalMenuItems.nextTile && settings->userTiles.count > 1) items.push_back(MenuItem("Next Tile", MenuAction::NEXT_TILE, MenuPage::ROOT)); // Only if multiple applets shown // items.push_back(MenuItem("Send", MenuPage::SEND)); // TODO items.push_back(MenuItem("Options", MenuPage::OPTIONS)); // items.push_back(MenuItem("Display Off", MenuPage::EXIT)); // TODO - items.push_back(MenuItem("Save & Shutdown", MenuAction::SHUTDOWN)); + items.push_back(MenuItem("Save & Shut Down", MenuAction::SHUTDOWN)); items.push_back(MenuItem("Exit", MenuPage::EXIT)); break; @@ -252,44 +258,40 @@ void InkHUD::MenuApplet::showPage(MenuPage page) case OPTIONS: // Optional: backlight - if (settings.optionalMenuItems.backlight) { - assert(backlight); + if (settings->optionalMenuItems.backlight) items.push_back(MenuItem(backlight->isLatched() ? "Backlight Off" : "Keep Backlight On", // Label MenuAction::TOGGLE_BACKLIGHT, // Action MenuPage::EXIT // Exit once complete )); - } + + // Optional: GPS + if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_DISABLED) + items.push_back(MenuItem("Enable GPS", MenuAction::TOGGLE_GPS, MenuPage::EXIT)); + if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED) + items.push_back(MenuItem("Disable GPS", MenuAction::TOGGLE_GPS, MenuPage::EXIT)); + + // Optional: Enable Bluetooth, in case of lost wifi connection + if (!config.bluetooth.enabled || config.network.wifi_enabled) + items.push_back(MenuItem("Enable Bluetooth", MenuAction::ENABLE_BLUETOOTH, MenuPage::EXIT)); items.push_back(MenuItem("Applets", MenuPage::APPLETS)); items.push_back(MenuItem("Auto-show", MenuPage::AUTOSHOW)); items.push_back(MenuItem("Recents Duration", MenuPage::RECENTS)); - if (settings.userTiles.maxCount > 1) + if (settings->userTiles.maxCount > 1) items.push_back(MenuItem("Layout", MenuAction::LAYOUT, MenuPage::OPTIONS)); items.push_back(MenuItem("Rotate", MenuAction::ROTATE, MenuPage::OPTIONS)); items.push_back(MenuItem("Notifications", MenuAction::TOGGLE_NOTIFICATIONS, MenuPage::OPTIONS, - &settings.optionalFeatures.notifications)); + &settings->optionalFeatures.notifications)); + items.push_back(MenuItem("Battery Icon", MenuAction::TOGGLE_BATTERY_ICON, MenuPage::OPTIONS, + &settings->optionalFeatures.batteryIcon)); items.push_back( - MenuItem("Battery Icon", MenuAction::TOGGLE_BATTERY_ICON, MenuPage::OPTIONS, &settings.optionalFeatures.batteryIcon)); - - // TODO - GPS and Wifi switches - /* - // Optional: has GPS - if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_DISABLED) - items.push_back(MenuItem("Enable GPS", MenuPage::EXIT)); // TODO - if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED) - items.push_back(MenuItem("Disable GPS", MenuPage::EXIT)); // TODO - - // Optional: using wifi - if (!config.bluetooth.enabled) - items.push_back(MenuItem("Enable Bluetooth", MenuPage::EXIT)); // TODO: escape hatch if wifi configured wrong - */ - + MenuItem("12-Hour Clock", MenuAction::TOGGLE_12H_CLOCK, MenuPage::OPTIONS, &config.display.use_12h_clock)); items.push_back(MenuItem("Exit", MenuPage::EXIT)); break; case APPLETS: populateAppletPage(); - items.push_back(MenuItem("Exit", MenuAction::ACTIVATE_APPLETS)); + items.push_back(MenuItem("Exit", MenuPage::EXIT)); break; case AUTOSHOW: @@ -303,7 +305,6 @@ void InkHUD::MenuApplet::showPage(MenuPage page) case EXIT: sendToBackground(); // Menu applet dismissed, allow normal behavior to resume - // requestUpdate(Drivers::EInk::UpdateTypes::FULL); break; default: @@ -329,9 +330,6 @@ void InkHUD::MenuApplet::onRender() if (items.size() == 0) LOG_ERROR("Empty Menu"); - // Testing only - setFont(fontSmall); - // Dimensions for the slots where we will draw menuItems const float padding = 0.05; const uint16_t itemH = fontSmall.lineHeight() * 2; @@ -397,7 +395,7 @@ void InkHUD::MenuApplet::onRender() // Testing only: circle instead of check box if (item.checkState) { - const uint16_t cbWH = fontSmall.lineHeight(); // Checbox: width / height + const uint16_t cbWH = fontSmall.lineHeight(); // Checkbox: width / height const int16_t cbL = itemR - X(padding) - cbWH; // Checkbox: left const int16_t cbT = center - (cbWH / 2); // Checkbox : top // Checkbox ticked @@ -463,9 +461,9 @@ void InkHUD::MenuApplet::populateAppletPage() { assert(items.size() == 0); - for (uint8_t i = 0; i < windowManager->getAppletCount(); i++) { - const char *name = windowManager->getAppletName(i); - bool *isActive = &(settings.userApplets.active[i]); + for (uint8_t i = 0; i < inkhud->userApplets.size(); i++) { + const char *name = inkhud->userApplets.at(i)->name; + bool *isActive = &(settings->userApplets.active[i]); items.push_back(MenuItem(name, MenuAction::TOGGLE_APPLET, MenuPage::APPLETS, isActive)); } } @@ -477,11 +475,11 @@ void InkHUD::MenuApplet::populateAutoshowPage() { assert(items.size() == 0); - for (uint8_t i = 0; i < windowManager->getAppletCount(); i++) { + for (uint8_t i = 0; i < inkhud->userApplets.size(); i++) { // Only add a menu item if applet is active - if (settings.userApplets.active[i]) { - const char *name = windowManager->getAppletName(i); - bool *isActive = &(settings.userApplets.autoshow[i]); + if (settings->userApplets.active[i]) { + const char *name = inkhud->userApplets.at(i)->name; + bool *isActive = &(settings->userApplets.autoshow[i]); items.push_back(MenuItem(name, MenuAction::TOGGLE_AUTOSHOW_APPLET, MenuPage::AUTOSHOW, isActive)); } } @@ -599,10 +597,10 @@ void InkHUD::MenuApplet::drawSystemInfoPanel(int16_t left, int16_t top, uint16_t // Get the height of the the panel drawn at the top of the menu // This is inefficient, as we do actually have to render the panel to determine the height -// It solves a catch-22 situtation, where slotCount needs to know panel height, and panel height needs to know slotCount +// It solves a catch-22 situation, where slotCount needs to know panel height, and panel height needs to know slotCount uint16_t InkHUD::MenuApplet::getSystemInfoPanelHeight() { - // Render *waay* off screen + // Render *far* off screen uint16_t height = 0; drawSystemInfoPanel(INT16_MIN, INT16_MIN, 1, &height); diff --git a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.h b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.h index f2e9b3947..d9297c8ed 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.h +++ b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.h @@ -3,8 +3,9 @@ #include "configuration.h" #include "graphics/niche/Drivers/Backlight/LatchingBacklight.h" -#include "graphics/niche/InkHUD/Applet.h" -#include "graphics/niche/InkHUD/WindowManager.h" +#include "graphics/niche/InkHUD/InkHUD.h" +#include "graphics/niche/InkHUD/Persistence.h" +#include "graphics/niche/InkHUD/SystemApplet.h" #include "./MenuItem.h" #include "./MenuPage.h" @@ -16,11 +17,10 @@ namespace NicheGraphics::InkHUD class Applet; -class MenuApplet : public Applet, public concurrency::OSThread +class MenuApplet : public SystemApplet, public concurrency::OSThread { public: MenuApplet(); - void onActivate() override; void onForeground() override; void onBackground() override; void onButtonShortPress() override; @@ -30,6 +30,8 @@ class MenuApplet : public Applet, public concurrency::OSThread void show(Tile *t); // Open the menu, onto a user tile protected: + Drivers::LatchingBacklight *backlight = nullptr; // Convenient access to the backlight singleton + int32_t runOnce() override; void execute(MenuItem item); // Perform the MenuAction associated with a MenuItem, if any @@ -41,7 +43,7 @@ class MenuApplet : public Applet, public concurrency::OSThread void drawSystemInfoPanel(int16_t left, int16_t top, uint16_t width, uint16_t *height = nullptr); // Info panel at top of root menu - MenuPage currentPage; + MenuPage currentPage = MenuPage::ROOT; uint8_t cursor = 0; // Which menu item is currently highlighted bool cursorShown = false; // Is *any* item highlighted? (Root menu: no initial selection) @@ -50,9 +52,6 @@ class MenuApplet : public Applet, public concurrency::OSThread std::vector items; // MenuItems for the current page. Filled by ShowPage Applet *borrowedTileOwner = nullptr; // Which applet we have temporarily replaced while displaying menu - - WindowManager *windowManager = nullptr; // Convenient access to the InkHUD::WindowManager singleton - Drivers::LatchingBacklight *backlight = nullptr; // Convenient access to the backlight singleton }; } // namespace NicheGraphics::InkHUD diff --git a/src/graphics/niche/InkHUD/Applets/System/Notification/NotificationApplet.cpp b/src/graphics/niche/InkHUD/Applets/System/Notification/NotificationApplet.cpp index 886be84b5..aa702c032 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Notification/NotificationApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/System/Notification/NotificationApplet.cpp @@ -3,22 +3,20 @@ #include "./NotificationApplet.h" #include "./Notification.h" +#include "graphics/niche/InkHUD/Persistence.h" + +#include "meshUtils.h" +#include "modules/TextMessageModule.h" #include "RTC.h" using namespace NicheGraphics; -void InkHUD::NotificationApplet::onActivate() +InkHUD::NotificationApplet::NotificationApplet() { textMessageObserver.observe(textMessageModule); } -// Note: This applet probably won't ever be deactivated -void InkHUD::NotificationApplet::onDeactivate() -{ - textMessageObserver.unobserve(textMessageModule); -} - // Collect meta-info about the text message, and ask for approval for the notification // No need to save the message itself; we can use the cached InkHUD::latestMessage data during render() int InkHUD::NotificationApplet::onReceiveTextMessage(const meshtastic_MeshPacket *p) @@ -28,7 +26,7 @@ int InkHUD::NotificationApplet::onReceiveTextMessage(const meshtastic_MeshPacket // Abort if feature disabled // This is a bit clumsy, but avoids complicated handling when the feature is enabled / disabled - if (!settings.optionalFeatures.notifications) + if (!settings->optionalFeatures.notifications) return 0; // Abort if this is an outgoing message @@ -36,7 +34,7 @@ int InkHUD::NotificationApplet::onReceiveTextMessage(const meshtastic_MeshPacket return 0; // Abort if message was only an "emoji reaction" - // Possibly some implemetation of this in future? + // Possibly some implementation of this in future? if (p->decoded.emoji) return 0; @@ -55,13 +53,16 @@ int InkHUD::NotificationApplet::onReceiveTextMessage(const meshtastic_MeshPacket n.sender = p->from; } + // Close an old notification, if shown + dismiss(); + // Check if we should display the notification // A foreground applet might already be displaying this info hasNotification = true; currentNotification = n; if (isApproved()) { bringToForeground(); - WindowManager::getInstance()->forceUpdate(); + inkhud->forceUpdate(); } else hasNotification = false; // Clear the pending notification: it was rejected @@ -76,8 +77,6 @@ void InkHUD::NotificationApplet::onRender() // We do need to do this with the battery though, as it is an "overlay" fillRect(0, 0, width(), height(), WHITE); - setFont(fontSmall); - // Padding (horizontal) const uint16_t padW = 4; @@ -137,6 +136,28 @@ void InkHUD::NotificationApplet::onRender() printThick(textM, height() / 2, text, 2, 1); } +void InkHUD::NotificationApplet::onForeground() +{ + handleInput = true; // Intercept the button input for our applet, so we can dismiss the notification +} + +void InkHUD::NotificationApplet::onBackground() +{ + handleInput = false; +} + +void InkHUD::NotificationApplet::onButtonShortPress() +{ + dismiss(); + inkhud->forceUpdate(EInk::UpdateTypes::FULL); +} + +void InkHUD::NotificationApplet::onButtonLongPress() +{ + dismiss(); + inkhud->forceUpdate(EInk::UpdateTypes::FULL); +} + // Ask the WindowManager to check whether any displayed applets are already displaying the info from this notification // Called internally when we first get a "notifiable event", and then again before render, // in case autoshow swapped which applet was displayed @@ -148,7 +169,13 @@ bool InkHUD::NotificationApplet::isApproved() return false; } - return WindowManager::getInstance()->approveNotification(currentNotification); + // Ask all visible user applets for approval + for (Applet *ua : inkhud->userApplets) { + if (ua->isForeground() && !ua->approveNotification(currentNotification)) + return false; + } + + return true; } // Mark that the notification should no-longer be rendered @@ -180,7 +207,8 @@ std::string InkHUD::NotificationApplet::getNotificationText(uint16_t widthAvaila bool isBroadcast = currentNotification.type == Notification::Type::NOTIFICATION_MESSAGE_BROADCAST; // Pick source of message - MessageStore::Message *message = isBroadcast ? &latestMessage.broadcast : &latestMessage.dm; + MessageStore::Message *message = + isBroadcast ? &inkhud->persistence->latestMessage.broadcast : &inkhud->persistence->latestMessage.dm; // Find info about the sender meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(message->sender); diff --git a/src/graphics/niche/InkHUD/Applets/System/Notification/NotificationApplet.h b/src/graphics/niche/InkHUD/Applets/System/Notification/NotificationApplet.h index c4d36a4fd..66df784b4 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Notification/NotificationApplet.h +++ b/src/graphics/niche/InkHUD/Applets/System/Notification/NotificationApplet.h @@ -3,7 +3,7 @@ /* Pop-up notification bar, on screen top edge -Displays information we feel is important, but which is not shown on currently focussed applet(s) +Displays information we feel is important, but which is not shown on currently focused applet(s) E.g.: messages, while viewing map, etc Feature should be optional; enable disable via on-screen menu @@ -16,17 +16,21 @@ Feature should be optional; enable disable via on-screen menu #include "concurrency/OSThread.h" -#include "graphics/niche/InkHUD/Applet.h" +#include "graphics/niche/InkHUD/SystemApplet.h" namespace NicheGraphics::InkHUD { -class NotificationApplet : public Applet +class NotificationApplet : public SystemApplet { public: + NotificationApplet(); + void onRender() override; - void onActivate() override; - void onDeactivate() override; + void onForeground() override; + void onBackground() override; + void onButtonShortPress() override; + void onButtonLongPress() override; int onReceiveTextMessage(const meshtastic_MeshPacket *p); @@ -40,8 +44,8 @@ class NotificationApplet : public Applet std::string getNotificationText(uint16_t widthAvailable); // Get text for notification, to suit screen width - bool hasNotification = false; // Only used for assert. Todo: remove? - Notification currentNotification; // Set when something notification-worthy happens. Used by render() + bool hasNotification = false; // Only used for assert. Todo: remove? + Notification currentNotification = Notification(); // Set when something notification-worthy happens. Used by render() }; } // namespace NicheGraphics::InkHUD diff --git a/src/graphics/niche/InkHUD/Applets/System/Pairing/PairingApplet.cpp b/src/graphics/niche/InkHUD/Applets/System/Pairing/PairingApplet.cpp index 457fa0f3f..81de05b30 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Pairing/PairingApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/System/Pairing/PairingApplet.cpp @@ -6,8 +6,7 @@ using namespace NicheGraphics; InkHUD::PairingApplet::PairingApplet() { - // Grab the window manager singleton, for convenience - windowManager = WindowManager::getInstance(); + bluetoothStatusObserver.observe(&bluetoothStatus->onNewStatus); } void InkHUD::PairingApplet::onRender() @@ -31,34 +30,22 @@ void InkHUD::PairingApplet::onRender() printAt(X(0.5), Y(0.75), name, CENTER, MIDDLE); } -void InkHUD::PairingApplet::onActivate() -{ - bluetoothStatusObserver.observe(&bluetoothStatus->onNewStatus); -} - -void InkHUD::PairingApplet::onDeactivate() -{ - bluetoothStatusObserver.unobserve(&bluetoothStatus->onNewStatus); -} - void InkHUD::PairingApplet::onForeground() { - // If another applet has locked the display, ask it to exit - Applet *other = windowManager->whoLocked(); - if (other != nullptr) - other->sendToBackground(); - - windowManager->claimFullscreen(this); // Take ownership of the fullscreen tile - windowManager->lock(this); // Prevent user applets from requesting update + // Prevent most other applets from requesting update, and skip their rendering entirely + // Another system applet with a higher precedence can potentially ignore this + SystemApplet::lockRendering = true; + SystemApplet::lockRequests = true; } void InkHUD::PairingApplet::onBackground() { - windowManager->releaseFullscreen(); // Relinquish ownership of the fullscreen tile - windowManager->unlock(this); // Allow normal user applet update requests to resume + // Allow normal update behavior to resume + SystemApplet::lockRendering = false; + SystemApplet::lockRequests = false; // Need to force an update, as a polite request wouldn't be honored, seeing how we are now in the background // Usually, onBackground is followed by another applet's onForeground (which requests update), but not in this case - windowManager->forceUpdate(EInk::UpdateTypes::FULL); + inkhud->forceUpdate(EInk::UpdateTypes::FULL); } int InkHUD::PairingApplet::onBluetoothStatusUpdate(const meshtastic::Status *status) @@ -75,12 +62,6 @@ int InkHUD::PairingApplet::onBluetoothStatusUpdate(const meshtastic::Status *sta // Store the passkey for rendering passkey = bluetoothStatus->getPasskey(); - // Make sure no other system applets have a lock on the display - // Boot screen, menu, etc - Applet *lockOwner = windowManager->whoLocked(); - if (lockOwner) - lockOwner->sendToBackground(); - // Show pairing screen bringToForeground(); } diff --git a/src/graphics/niche/InkHUD/Applets/System/Pairing/PairingApplet.h b/src/graphics/niche/InkHUD/Applets/System/Pairing/PairingApplet.h index ce420e68b..b89783a25 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Pairing/PairingApplet.h +++ b/src/graphics/niche/InkHUD/Applets/System/Pairing/PairingApplet.h @@ -10,19 +10,19 @@ #include "configuration.h" -#include "graphics/niche/InkHUD/Applet.h" +#include "graphics/niche/InkHUD/SystemApplet.h" + +#include "main.h" namespace NicheGraphics::InkHUD { -class PairingApplet : public Applet +class PairingApplet : public SystemApplet { public: PairingApplet(); void onRender() override; - void onActivate() override; - void onDeactivate() override; void onForeground() override; void onBackground() override; @@ -34,8 +34,6 @@ class PairingApplet : public Applet CallbackObserver(this, &PairingApplet::onBluetoothStatusUpdate); std::string passkey = ""; // Passkey. Six digits, possibly with leading zeros - - WindowManager *windowManager = nullptr; // For convenience. Set in constructor. }; } // namespace NicheGraphics::InkHUD diff --git a/src/graphics/niche/InkHUD/Applets/System/Placeholder/PlaceholderApplet.cpp b/src/graphics/niche/InkHUD/Applets/System/Placeholder/PlaceholderApplet.cpp index 4f66593b9..99cdeb0ac 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Placeholder/PlaceholderApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/System/Placeholder/PlaceholderApplet.cpp @@ -4,14 +4,6 @@ using namespace NicheGraphics; -InkHUD::PlaceholderApplet::PlaceholderApplet() -{ - // Because this applet sometimes gets processed as if it were a bonafide user applet, - // it's probably better that we do give it a human readable name, just in case it comes up later. - // For genuine user applets, this is set by WindowManager::addApplet - Applet::name = "Placeholder"; -} - void InkHUD::PlaceholderApplet::onRender() { // This placeholder applet fills its area with sparse diagonal lines diff --git a/src/graphics/niche/InkHUD/Applets/System/Placeholder/PlaceholderApplet.h b/src/graphics/niche/InkHUD/Applets/System/Placeholder/PlaceholderApplet.h index e5106105c..78ba5cd89 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Placeholder/PlaceholderApplet.h +++ b/src/graphics/niche/InkHUD/Applets/System/Placeholder/PlaceholderApplet.h @@ -9,20 +9,19 @@ Fills the area with diagonal lines #include "configuration.h" -#include "graphics/niche/InkHUD/Applet.h" +#include "graphics/niche/InkHUD/SystemApplet.h" namespace NicheGraphics::InkHUD { -class PlaceholderApplet : public Applet +class PlaceholderApplet : public SystemApplet { public: - PlaceholderApplet(); void onRender() override; // Note: onForeground, onBackground, and wantsToRender are not meaningful for this applet. // The window manager decides when and where it should be rendered - // It may be drawn to several different tiles during on WindowManager::render call + // It may be drawn to several different tiles during an Renderer::render call }; } // namespace NicheGraphics::InkHUD diff --git a/src/graphics/niche/InkHUD/Applets/System/Tips/TipsApplet.cpp b/src/graphics/niche/InkHUD/Applets/System/Tips/TipsApplet.cpp index e6b5b5dc9..82a196cb1 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Tips/TipsApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/System/Tips/TipsApplet.cpp @@ -2,12 +2,44 @@ #include "./TipsApplet.h" +#include "graphics/niche/InkHUD/Persistence.h" + +#include "main.h" + using namespace NicheGraphics; InkHUD::TipsApplet::TipsApplet() { - // Grab the window manager singleton, for convenience - windowManager = WindowManager::getInstance(); + // Decide which tips (if any) should be shown to user after the boot screen + + // Welcome screen + if (settings->tips.firstBoot) + tipQueue.push_back(Tip::WELCOME); + + // Antenna, region, timezone + // Shown at boot if region not yet set + if (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET) + tipQueue.push_back(Tip::FINISH_SETUP); + + // Shutdown info + // Shown until user performs one valid shutdown + if (!settings->tips.safeShutdownSeen) + tipQueue.push_back(Tip::SAFE_SHUTDOWN); + + // Using the UI + if (settings->tips.firstBoot) { + tipQueue.push_back(Tip::CUSTOMIZATION); + tipQueue.push_back(Tip::BUTTONS); + } + + // Catch an incorrect attempt at rotating display + if (config.display.flip_screen) + tipQueue.push_back(Tip::ROTATION); + + // Applet is foreground immediately at boot, but is obscured by LogoApplet, which is also foreground + // LogoApplet can be considered to have a higher Z-index, because it is placed before TipsApplet in the systemApplets vector + if (!tipQueue.empty()) + bringToForeground(); } void InkHUD::TipsApplet::onRender() @@ -53,7 +85,7 @@ void InkHUD::TipsApplet::onRender() setFont(fontSmall); std::string shutdown; - shutdown += "Before removing power, please shutdown from InkHUD menu, or a client app. \n"; + shutdown += "Before removing power, please shut down from InkHUD menu, or a client app. \n"; shutdown += "\n"; shutdown += "This ensures data is saved."; printWrapped(0, fontLarge.lineHeight() * 1.5, width(), shutdown); @@ -153,51 +185,29 @@ void InkHUD::TipsApplet::renderWelcome() printAt(X(0.5), Y(1), "Press button to continue", CENTER, BOTTOM); } -// Grab fullscreen tile, and lock the window manager, when applet is shown void InkHUD::TipsApplet::onForeground() { - windowManager->lock(this); - windowManager->claimFullscreen(this); + // Prevent most other applets from requesting update, and skip their rendering entirely + // Another system applet with a higher precedence can potentially ignore this + SystemApplet::lockRendering = true; + SystemApplet::lockRequests = true; + + SystemApplet::handleInput = true; // Our applet should handle button input (unless another system applet grabs it first) } void InkHUD::TipsApplet::onBackground() { - windowManager->releaseFullscreen(); - windowManager->unlock(this); + // Allow normal update behavior to resume + SystemApplet::lockRendering = false; + SystemApplet::lockRequests = false; + SystemApplet::handleInput = false; + + // Need to force an update, as a polite request wouldn't be honored, seeing how we are now in the background + // Usually, onBackground is followed by another applet's onForeground (which requests update), but not in this case + inkhud->forceUpdate(EInk::UpdateTypes::FULL); } -void InkHUD::TipsApplet::onActivate() -{ - // Decide which tips (if any) should be shown to user after the boot screen - - // Welcome screen - if (settings.tips.firstBoot) - tipQueue.push_back(Tip::WELCOME); - - // Antenna, region, timezone - // Shown at boot if region not yet set - if (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET) - tipQueue.push_back(Tip::FINISH_SETUP); - - // Shutdown info - // Shown until user performs one valid shutdown - if (!settings.tips.safeShutdownSeen) - tipQueue.push_back(Tip::SAFE_SHUTDOWN); - - // Using the UI - if (settings.tips.firstBoot) { - tipQueue.push_back(Tip::CUSTOMIZATION); - tipQueue.push_back(Tip::BUTTONS); - } - - // Catch an incorrect attempt at rotating display - if (config.display.flip_screen) - tipQueue.push_back(Tip::ROTATION); - - // Applet will be brought to foreground when boot screen closes, via TipsApplet::onLockAvailable -} - -// While our applet has the window manager locked, we will receive the button input +// While our SystemApplet::handleInput flag is true void InkHUD::TipsApplet::onButtonShortPress() { tipQueue.pop_front(); @@ -206,15 +216,15 @@ void InkHUD::TipsApplet::onButtonShortPress() if (tipQueue.empty()) { // Record that user has now seen the "tutorial" set of tips // Don't show them on subsequent boots - if (settings.tips.firstBoot) { - settings.tips.firstBoot = false; - saveDataToFlash(); + if (settings->tips.firstBoot) { + settings->tips.firstBoot = false; + inkhud->persistence->saveSettings(); } // Close applet, and full refresh to clean the screen // Need to force update, because our request would be ignored otherwise, as we are now background sendToBackground(); - windowManager->forceUpdate(EInk::UpdateTypes::FULL); + inkhud->forceUpdate(EInk::UpdateTypes::FULL); } // More tips left @@ -222,13 +232,4 @@ void InkHUD::TipsApplet::onButtonShortPress() requestUpdate(); } -// If the wm lock has just become availale (rendering, input), and we've still got tips, grab it! -// This situation would arise if bluetooth pairing occurs while TipsApplet was already shown (after pairing) -// Note: this event is only raised when *other* applets unlock the window manager -void InkHUD::TipsApplet::onLockAvailable() -{ - if (!tipQueue.empty()) - bringToForeground(); -} - #endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/Applets/System/Tips/TipsApplet.h b/src/graphics/niche/InkHUD/Applets/System/Tips/TipsApplet.h index 29bcdfa8b..db88585e9 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Tips/TipsApplet.h +++ b/src/graphics/niche/InkHUD/Applets/System/Tips/TipsApplet.h @@ -12,12 +12,12 @@ #include "configuration.h" -#include "graphics/niche/InkHUD/Applet.h" +#include "graphics/niche/InkHUD/SystemApplet.h" namespace NicheGraphics::InkHUD { -class TipsApplet : public Applet +class TipsApplet : public SystemApplet { protected: enum class Tip { @@ -33,11 +33,9 @@ class TipsApplet : public Applet TipsApplet(); void onRender() override; - void onActivate() override; void onForeground() override; void onBackground() override; void onButtonShortPress() override; - void onLockAvailable() override; // Reopen if interrupted by bluetooth pairing protected: void renderWelcome(); // Very first screen of tutorial diff --git a/src/graphics/niche/InkHUD/Applets/User/AllMessage/AllMessageApplet.cpp b/src/graphics/niche/InkHUD/Applets/User/AllMessage/AllMessageApplet.cpp index 1ae313d8a..f7e2a8e9d 100644 --- a/src/graphics/niche/InkHUD/Applets/User/AllMessage/AllMessageApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/User/AllMessage/AllMessageApplet.cpp @@ -41,14 +41,12 @@ int InkHUD::AllMessageApplet::onReceiveTextMessage(const meshtastic_MeshPacket * void InkHUD::AllMessageApplet::onRender() { - setFont(fontSmall); - // Find newest message, regardless of whether DM or broadcast MessageStore::Message *message; - if (latestMessage.wasBroadcast) - message = &latestMessage.broadcast; + if (latestMessage->wasBroadcast) + message = &latestMessage->broadcast; else - message = &latestMessage.dm; + message = &latestMessage->dm; // Short circuit: no text message if (!message->sender) { diff --git a/src/graphics/niche/InkHUD/Applets/User/DM/DMApplet.cpp b/src/graphics/niche/InkHUD/Applets/User/DM/DMApplet.cpp index 526b86901..7a1d14f32 100644 --- a/src/graphics/niche/InkHUD/Applets/User/DM/DMApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/User/DM/DMApplet.cpp @@ -44,10 +44,8 @@ int InkHUD::DMApplet::onReceiveTextMessage(const meshtastic_MeshPacket *p) void InkHUD::DMApplet::onRender() { - setFont(fontSmall); - // Abort if no text message - if (!latestMessage.dm.sender) { + if (!latestMessage->dm.sender) { printAt(X(0.5), Y(0.5), "No DMs", CENTER, MIDDLE); return; } @@ -63,7 +61,7 @@ void InkHUD::DMApplet::onRender() // RX Time // - if valid - std::string timeString = getTimeString(latestMessage.dm.timestamp); + std::string timeString = getTimeString(latestMessage->dm.timestamp); if (timeString.length() > 0) { header += timeString; header += ": "; @@ -72,14 +70,14 @@ void InkHUD::DMApplet::onRender() // Sender's id // - shortname, if available, or // - node id - meshtastic_NodeInfoLite *sender = nodeDB->getMeshNode(latestMessage.dm.sender); + meshtastic_NodeInfoLite *sender = nodeDB->getMeshNode(latestMessage->dm.sender); if (sender && sender->has_user) { header += sender->user.short_name; header += " ("; header += sender->user.long_name; header += ")"; } else - header += hexifyNodeNum(latestMessage.dm.sender); + header += hexifyNodeNum(latestMessage->dm.sender); // Draw a "standard" applet header drawHeader(header); @@ -103,14 +101,14 @@ void InkHUD::DMApplet::onRender() // Determine size if printed large setFont(fontLarge); - uint32_t textHeight = getWrappedTextHeight(0, width(), latestMessage.dm.text); + uint32_t textHeight = getWrappedTextHeight(0, width(), latestMessage->dm.text); // If too large, swap to small font if (textHeight + textTop > (uint32_t)height()) // (compare signed and unsigned) setFont(fontSmall); // Print text - printWrapped(0, textTop, width(), latestMessage.dm.text); + printWrapped(0, textTop, width(), latestMessage->dm.text); } // Don't show notifications for direct messages when our applet is displayed diff --git a/src/graphics/niche/InkHUD/Applets/User/Positions/PositionsApplet.h b/src/graphics/niche/InkHUD/Applets/User/Positions/PositionsApplet.h index 5bcec339d..28a53cb0f 100644 --- a/src/graphics/niche/InkHUD/Applets/User/Positions/PositionsApplet.h +++ b/src/graphics/niche/InkHUD/Applets/User/Positions/PositionsApplet.h @@ -29,13 +29,13 @@ class PositionsApplet : public MapApplet, public SinglePortModule protected: ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) override; - NodeNum lastFrom; // Sender of most recent (non-local) position packet - float lastLat; - float lastLng; - float lastHopsAway; + NodeNum lastFrom = 0; // Sender of most recent (non-local) position packet + float lastLat = 0.0; + float lastLng = 0.0; + float lastHopsAway = 0; - float ourLastLat; // Info about the most recent (non-local) position packet - float ourLastLng; // Info about most recent *local* position + float ourLastLat = 0.0; // Info about the most recent (non-local) position packet + float ourLastLng = 0.0; // Info about most recent *local* position }; } // namespace NicheGraphics::InkHUD diff --git a/src/graphics/niche/InkHUD/Applets/User/RecentsList/RecentsListApplet.cpp b/src/graphics/niche/InkHUD/Applets/User/RecentsList/RecentsListApplet.cpp index 54e67efef..02aa4a721 100644 --- a/src/graphics/niche/InkHUD/Applets/User/RecentsList/RecentsListApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/User/RecentsList/RecentsListApplet.cpp @@ -122,7 +122,7 @@ bool InkHUD::RecentsListApplet::isActive(uint32_t seenAtMs) uint32_t now = millis(); uint32_t secsAgo = (now - seenAtMs) / 1000UL; // millis() overflow safe - return (secsAgo < settings.recentlyActiveSeconds); + return (secsAgo < settings->recentlyActiveSeconds); } // Text to be shown at top of applet @@ -134,7 +134,7 @@ std::string InkHUD::RecentsListApplet::getHeaderText() // Print the length of our "Recents" time-window text += "Last "; - text += to_string(settings.recentlyActiveSeconds / 60); + text += to_string(settings->recentlyActiveSeconds / 60); text += " mins"; // Print the node count diff --git a/src/graphics/niche/InkHUD/Applets/User/ThreadedMessage/ThreadedMessageApplet.cpp b/src/graphics/niche/InkHUD/Applets/User/ThreadedMessage/ThreadedMessageApplet.cpp index d81dd020c..d7d2e79c8 100644 --- a/src/graphics/niche/InkHUD/Applets/User/ThreadedMessage/ThreadedMessageApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/User/ThreadedMessage/ThreadedMessageApplet.cpp @@ -23,8 +23,6 @@ InkHUD::ThreadedMessageApplet::ThreadedMessageApplet(uint8_t channelIndex) : cha void InkHUD::ThreadedMessageApplet::onRender() { - setFont(fontSmall); - // ============= // Draw a header // ============= diff --git a/src/graphics/niche/InkHUD/Applets/User/ThreadedMessage/ThreadedMessageApplet.h b/src/graphics/niche/InkHUD/Applets/User/ThreadedMessage/ThreadedMessageApplet.h index 5bb8bf96e..3e11a25f2 100644 --- a/src/graphics/niche/InkHUD/Applets/User/ThreadedMessage/ThreadedMessageApplet.h +++ b/src/graphics/niche/InkHUD/Applets/User/ThreadedMessage/ThreadedMessageApplet.h @@ -33,7 +33,7 @@ class Applet; class ThreadedMessageApplet : public Applet { public: - ThreadedMessageApplet(uint8_t channelIndex); + explicit ThreadedMessageApplet(uint8_t channelIndex); ThreadedMessageApplet() = delete; void onRender() override; diff --git a/src/graphics/niche/InkHUD/UpdateMediator.cpp b/src/graphics/niche/InkHUD/DisplayHealth.cpp similarity index 61% rename from src/graphics/niche/InkHUD/UpdateMediator.cpp rename to src/graphics/niche/InkHUD/DisplayHealth.cpp index 16fc21cef..e8849b72e 100644 --- a/src/graphics/niche/InkHUD/UpdateMediator.cpp +++ b/src/graphics/niche/InkHUD/DisplayHealth.cpp @@ -1,46 +1,73 @@ #ifdef MESHTASTIC_INCLUDE_INKHUD -#include "./UpdateMediator.h" - -#include "./WindowManager.h" +#include "./DisplayHealth.h" +#include "DisplayHealth.h" using namespace NicheGraphics; +// Timing for "maintenance" +// Paying off full-refresh debt with unprovoked updates, if the display is not very active static constexpr uint32_t MAINTENANCE_MS_INITIAL = 60 * 1000UL; static constexpr uint32_t MAINTENANCE_MS = 60 * 60 * 1000UL; -InkHUD::UpdateMediator::UpdateMediator() : concurrency::OSThread("Mediator") +InkHUD::DisplayHealth::DisplayHealth() : concurrency::OSThread("Mediator") { // Timer disabled by default OSThread::disable(); } -// Ask which type of update operation we should perform -// Even if we explicitly want a FAST or FULL update, we should pass it through this method, -// as it allows UpdateMediator to count the refreshes. -// Internal "maintenance" refreshes are not passed through evaluate, however. -Drivers::EInk::UpdateTypes InkHUD::UpdateMediator::evaluate(Drivers::EInk::UpdateTypes requested) +// Request which update type we would prefer, when the display image next changes +// DisplayHealth class will consider our suggestion, and weigh it against other requests +void InkHUD::DisplayHealth::requestUpdateType(Drivers::EInk::UpdateTypes type) +{ + // Update our "working decision", to decide if this request is important enough to change our plan + if (!forced) + workingDecision = prioritize(workingDecision, type); +} + +// Demand that a specific update type be used, when the display image next changes +// Note: multiple DisplayHealth::force calls should not be made, +// but if they are, the importance of the type will be weighed the same as if both calls were to DisplayHealth::request +void InkHUD::DisplayHealth::forceUpdateType(Drivers::EInk::UpdateTypes type) +{ + if (!forced) + workingDecision = type; + else + workingDecision = prioritize(workingDecision, type); + + forced = true; +} + +// Find out which update type the DisplayHealth has chosen for us +// Calling this method consumes the result, and resets for the next update +Drivers::EInk::UpdateTypes InkHUD::DisplayHealth::decideUpdateType() { LOG_DEBUG("FULL-update debt:%f", debt); - // For conveninece + // For convenience typedef Drivers::EInk::UpdateTypes UpdateTypes; + // Grab our final decision for the update type, so we can reset now, for the next update + // We do this at top of the method, so we can return early + UpdateTypes finalDecision = workingDecision; + workingDecision = UpdateTypes::UNSPECIFIED; + forced = false; + // Check whether we've paid off enough debt to stop unprovoked refreshing (if in progress) - // This maintenance behavior will also halt itself when the timer next fires, + // This maintenance behavior will also have opportunity to halt itself when the timer next fires, // but that could be an hour away, so we can stop it early here and free up resources if (OSThread::enabled && debt == 0.0) endMaintenance(); // Explicitly requested FULL - if (requested == UpdateTypes::FULL) { + if (finalDecision == UpdateTypes::FULL) { LOG_DEBUG("Explicit FULL"); debt = max(debt - 1.0, 0.0); // Record that we have paid back (some of) the FULL refresh debt return UpdateTypes::FULL; } // Explicitly requested FAST - if (requested == UpdateTypes::FAST) { + if (finalDecision == UpdateTypes::FAST) { LOG_DEBUG("Explicit FAST"); // Add to the FULL refresh debt if (debt < 1.0) @@ -49,7 +76,8 @@ Drivers::EInk::UpdateTypes InkHUD::UpdateMediator::evaluate(Drivers::EInk::Updat debt += stressMultiplier * (1.0 / fastPerFull); // More debt if too many consecutive FAST refreshes // If *significant debt*, begin occasionally refreshing *unprovoked* - // This maintenance behavior is only triggered here, during periods of user interaction + // This maintenance behavior is only triggered here, by periods of user interaction + // Debt would otherwise not be able to climb above 1.0 if (debt >= 2.0) beginMaintenance(); @@ -75,10 +103,8 @@ Drivers::EInk::UpdateTypes InkHUD::UpdateMediator::evaluate(Drivers::EInk::Updat // When maintenance begins, the first refresh happens shortly after user interaction ceases (a minute or so) // If we *are* given an opportunity to refresh before that, we'll skip that initial maintenance refresh // We were intending to use that initial refresh to redraw the screen as FULL, but we're doing that now, organically - if (OSThread::enabled && OSThread::interval == MAINTENANCE_MS_INITIAL) { - LOG_DEBUG("Initial maintenance skipped"); + if (OSThread::enabled && OSThread::interval == MAINTENANCE_MS_INITIAL) OSThread::setInterval(MAINTENANCE_MS); // Note: not intervalFromNow - } return UpdateTypes::FULL; } @@ -86,8 +112,9 @@ Drivers::EInk::UpdateTypes InkHUD::UpdateMediator::evaluate(Drivers::EInk::Updat // Determine which of two update types is more important to honor // Explicit FAST is more important than UNSPECIFIED - prioritize responsiveness -// Explicit FULL is more important than explicint FAST - prioritize image quality: explicit FULL is rare -Drivers::EInk::UpdateTypes InkHUD::UpdateMediator::prioritize(Drivers::EInk::UpdateTypes type1, Drivers::EInk::UpdateTypes type2) +// Explicit FULL is more important than explicit FAST - prioritize image quality: explicit FULL is rare +// Used when multiple applets have all requested update simultaneously, each with their own preferred UpdateType +Drivers::EInk::UpdateTypes InkHUD::DisplayHealth::prioritize(Drivers::EInk::UpdateTypes type1, Drivers::EInk::UpdateTypes type2) { switch (type1) { case Drivers::EInk::UpdateTypes::UNSPECIFIED: @@ -104,20 +131,20 @@ Drivers::EInk::UpdateTypes InkHUD::UpdateMediator::prioritize(Drivers::EInk::Upd } // We're using the timer to perform "maintenance" -// If signifcant FULL-refresh debt has accumulated, we will occasionally run FULL refreshes unprovoked. +// If significant FULL-refresh debt has accumulated, we will occasionally run FULL refreshes unprovoked. // This prevents gradual build-up of debt, -// in case we don't have enough UNSPECIFIED refreshes to pay the debt back organically. +// in case we aren't doing enough UNSPECIFIED refreshes to pay the debt back organically. // The first refresh takes place shortly after user finishes interacting with the device; this does the bulk of the restoration // Subsequent refreshes take place *much* less frequently. // Hopefully an applet will want to render before this, meaning we can cancel the maintenance. -int32_t InkHUD::UpdateMediator::runOnce() +int32_t InkHUD::DisplayHealth::runOnce() { if (debt > 0.0) { LOG_DEBUG("debt=%f: performing maintenance", debt); // Ask WindowManager to redraw everything, purely for the refresh // Todo: optimize? Could update without re-rendering - WindowManager::getInstance()->forceUpdate(EInk::UpdateTypes::FULL); + InkHUD::getInstance()->forceUpdate(Drivers::EInk::UpdateTypes::FULL); // Record that we have paid back (some of) the FULL refresh debt debt = max(debt - 1.0, 0.0); @@ -134,17 +161,15 @@ int32_t InkHUD::UpdateMediator::runOnce() // We do this in case user doesn't have enough activity to repay it organically, with UpdateTypes::UNSPECIFIED // After an initial refresh, to redraw as FULL, we only perform these maintenance refreshes very infrequently // This gives the display a chance to heal by evaluating UNSPECIFIED as FULL, which is preferable -void InkHUD::UpdateMediator::beginMaintenance() +void InkHUD::DisplayHealth::beginMaintenance() { - LOG_DEBUG("Maintenance enabled"); OSThread::setIntervalFromNow(MAINTENANCE_MS_INITIAL); OSThread::enabled = true; } // FULL-refresh debt is low enough that we no longer need to pay it back with periodic updates -int32_t InkHUD::UpdateMediator::endMaintenance() +int32_t InkHUD::DisplayHealth::endMaintenance() { - LOG_DEBUG("Maintenance disabled"); return OSThread::disable(); } diff --git a/src/graphics/niche/InkHUD/UpdateMediator.h b/src/graphics/niche/InkHUD/DisplayHealth.h similarity index 56% rename from src/graphics/niche/InkHUD/UpdateMediator.h rename to src/graphics/niche/InkHUD/DisplayHealth.h index e4c7c6786..2bd887f9d 100644 --- a/src/graphics/niche/InkHUD/UpdateMediator.h +++ b/src/graphics/niche/InkHUD/DisplayHealth.h @@ -2,7 +2,8 @@ /* -Responsible for display health +Responsible for maintaining display health, by optimizing the ratio of FAST vs FULL refreshes + - counts number of FULL vs FAST refresh - suggests whether to use FAST or FULL, when not explicitly specified - periodically requests update unprovoked, if required for display health @@ -13,21 +14,21 @@ Responsible for display health #include "configuration.h" +#include "InkHUD.h" + #include "graphics/niche/Drivers/EInk/EInk.h" namespace NicheGraphics::InkHUD { -class UpdateMediator : protected concurrency::OSThread +class DisplayHealth : protected concurrency::OSThread { public: - UpdateMediator(); + DisplayHealth(); - // Tell the mediator what we want, get told what we can have - Drivers::EInk::UpdateTypes evaluate(Drivers::EInk::UpdateTypes requested); - - // Determine which of two update types is more important to honor - Drivers::EInk::UpdateTypes prioritize(Drivers::EInk::UpdateTypes type1, Drivers::EInk::UpdateTypes type2); + void requestUpdateType(Drivers::EInk::UpdateTypes type); + void forceUpdateType(Drivers::EInk::UpdateTypes type); + Drivers::EInk::UpdateTypes decideUpdateType(); uint8_t fastPerFull = 5; // Ideal number of fast refreshes between full refreshes float stressMultiplier = 2.0; // How bad for the display are extra fast refreshes beyond fastPerFull? @@ -37,6 +38,13 @@ class UpdateMediator : protected concurrency::OSThread void beginMaintenance(); // Excessive debt: begin unprovoked refreshing of display, for health int32_t endMaintenance(); // End unprovoked refreshing: debt paid + Drivers::EInk::UpdateTypes + prioritize(Drivers::EInk::UpdateTypes type1, + Drivers::EInk::UpdateTypes type2); // Determine which of two update types is more important to honor + + bool forced = false; + Drivers::EInk::UpdateTypes workingDecision = Drivers::EInk::UpdateTypes::UNSPECIFIED; + float debt = 0.0; // How many full refreshes are due }; diff --git a/src/graphics/niche/InkHUD/Events.cpp b/src/graphics/niche/InkHUD/Events.cpp new file mode 100644 index 000000000..ddd01b7e1 --- /dev/null +++ b/src/graphics/niche/InkHUD/Events.cpp @@ -0,0 +1,185 @@ +#ifdef MESHTASTIC_INCLUDE_INKHUD + +#include "./Events.h" + +#include "RTC.h" +#include "modules/TextMessageModule.h" +#include "sleep.h" + +#include "./Applet.h" +#include "./SystemApplet.h" + +using namespace NicheGraphics; + +InkHUD::Events::Events() +{ + // Get convenient references + inkhud = InkHUD::getInstance(); + settings = &inkhud->persistence->settings; +} + +void InkHUD::Events::begin() +{ + // Register our callbacks for the various events + + deepSleepObserver.observe(¬ifyDeepSleep); + rebootObserver.observe(¬ifyReboot); + textMessageObserver.observe(textMessageModule); +#ifdef ARCH_ESP32 + lightSleepObserver.observe(¬ifyLightSleep); +#endif +} + +void InkHUD::Events::onButtonShort() +{ + // Check which system applet wants to handle the button press (if any) + SystemApplet *consumer = nullptr; + for (SystemApplet *sa : inkhud->systemApplets) { + if (sa->handleInput) { + consumer = sa; + break; + } + } + + // If no system applet is handling input, default behavior instead is to cycle applets + if (consumer) + consumer->onButtonShortPress(); + else + inkhud->nextApplet(); +} + +void InkHUD::Events::onButtonLong() +{ + // Check which system applet wants to handle the button press (if any) + SystemApplet *consumer = nullptr; + for (SystemApplet *sa : inkhud->systemApplets) { + if (sa->handleInput) { + consumer = sa; + break; + } + } + + // If no system applet is handling input, default behavior instead is to open the menu + if (consumer) + consumer->onButtonLongPress(); + else + inkhud->openMenu(); +} + +// Callback for deepSleepObserver +// Returns 0 to signal that we agree to sleep now +int InkHUD::Events::beforeDeepSleep(void *unused) +{ + // If a previous display update is in progress, wait for it to complete. + inkhud->awaitUpdate(); + + // Notify all applets that we're shutting down + for (Applet *ua : inkhud->userApplets) { + ua->onDeactivate(); + ua->onShutdown(); + } + for (SystemApplet *sa : inkhud->systemApplets) { + // Note: no onDeactivate. System applets are always active. + sa->onShutdown(); + } + + // User has successful executed a safe shutdown + // We don't need to nag at boot anymore + settings->tips.safeShutdownSeen = true; + + inkhud->persistence->saveSettings(); + inkhud->persistence->saveLatestMessage(); + + // LogoApplet::onShutdown attempted to heal the display by drawing a "shutting down" screen twice, + // then prepared a final powered-off screen for us, which shows device shortname. + // We're updating to show that one now. + + inkhud->forceUpdate(Drivers::EInk::UpdateTypes::FULL, false); + delay(1000); // Cooldown, before potentially yanking display power + + return 0; // We agree: deep sleep now +} + +// Callback for rebootObserver +// Same as shutdown, without drawing the logoApplet +// Makes sure we don't lose message history / InkHUD config +int InkHUD::Events::beforeReboot(void *unused) +{ + + // Notify all applets that we're "shutting down" + // They don't need to know that it's really a reboot + for (Applet *a : inkhud->userApplets) { + a->onDeactivate(); + a->onShutdown(); + } + for (SystemApplet *sa : inkhud->systemApplets) { + // Note: no onDeactivate. System applets are always active. + sa->onReboot(); + } + + inkhud->persistence->saveSettings(); + inkhud->persistence->saveLatestMessage(); + + // Note: no forceUpdate call here + // We don't have any final screen to draw, although LogoApplet::onReboot did already display a "rebooting" screen + + return 0; // No special status to report. Ignored anyway by this Observable +} + +// Callback when a new text message is received +// Caches the most recently received message, for use by applets +// Rx does not trigger a save to flash, however the data *will* be saved alongside other during shutdown, etc. +// Note: this is different from devicestate.rx_text_message, which may contain an *outgoing* message +int InkHUD::Events::onReceiveTextMessage(const meshtastic_MeshPacket *packet) +{ + // Short circuit: don't store outgoing messages + if (getFrom(packet) == nodeDB->getNodeNum()) + return 0; + + // Short circuit: don't store "emoji reactions" + // Possibly some implementation of this in future? + if (packet->decoded.emoji) + return 0; + + // Determine whether the message is broadcast or a DM + // Store this info to prevent confusion after a reboot + // Avoids need to compare timestamps, because of situation where "future" messages block newly received, if time not set + inkhud->persistence->latestMessage.wasBroadcast = isBroadcast(packet->to); + + // Pick the appropriate variable to store the message in + MessageStore::Message *storedMessage = inkhud->persistence->latestMessage.wasBroadcast + ? &inkhud->persistence->latestMessage.broadcast + : &inkhud->persistence->latestMessage.dm; + + // Store nodenum of the sender + // Applets can use this to fetch user data from nodedb, if they want + storedMessage->sender = packet->from; + + // Store the time (epoch seconds) when message received + storedMessage->timestamp = getValidTime(RTCQuality::RTCQualityDevice, true); // Current RTC time + + // Store the channel + // - (potentially) used to determine whether notification shows + // - (potentially) used to determine which applet to focus + storedMessage->channelIndex = packet->channel; + + // Store the text + // Need to specify manually how many bytes, because source not null-terminated + storedMessage->text = + std::string(&packet->decoded.payload.bytes[0], &packet->decoded.payload.bytes[packet->decoded.payload.size]); + + return 0; // Tell caller to continue notifying other observers. (No reason to abort this event) +} + +#ifdef ARCH_ESP32 +// Callback for lightSleepObserver +// Make sure the display is not partway through an update when we begin light sleep +// This is because some displays require active input from us to terminate the update process, and protect the panel hardware +int InkHUD::Events::beforeLightSleep(void *unused) +{ + inkhud->awaitUpdate(); + return 0; // No special status to report. Ignored anyway by this Observable +} +#endif + +#endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/Events.h b/src/graphics/niche/InkHUD/Events.h new file mode 100644 index 000000000..6a6e9d7a2 --- /dev/null +++ b/src/graphics/niche/InkHUD/Events.h @@ -0,0 +1,63 @@ +#ifdef MESHTASTIC_INCLUDE_INKHUD + +#pragma once + +/* + +Handles non-specific events for InkHUD + +Individual applets are responsible for listening for their own events via the module api etc, +however this class handles general events which concern InkHUD as a whole, e.g. shutdown + +*/ + +#include "configuration.h" + +#include "Observer.h" + +#include "./InkHUD.h" +#include "./Persistence.h" + +namespace NicheGraphics::InkHUD +{ + +class Events +{ + public: + Events(); + void begin(); + + void onButtonShort(); // User button: short press + void onButtonLong(); // User button: long press + + int beforeDeepSleep(void *unused); // Prepare for shutdown + int beforeReboot(void *unused); // Prepare for reboot + int onReceiveTextMessage(const meshtastic_MeshPacket *packet); // Store most recent text message +#ifdef ARCH_ESP32 + int beforeLightSleep(void *unused); // Prepare for light sleep +#endif + + private: + // For convenience + InkHUD *inkhud = nullptr; + Persistence::Settings *settings = nullptr; + + // Get notified when the system is shutting down + CallbackObserver deepSleepObserver = CallbackObserver(this, &Events::beforeDeepSleep); + + // Get notified when the system is rebooting + CallbackObserver rebootObserver = CallbackObserver(this, &Events::beforeReboot); + + // Cache *incoming* text messages, for use by applets + CallbackObserver textMessageObserver = + CallbackObserver(this, &Events::onReceiveTextMessage); + +#ifdef ARCH_ESP32 + // Get notified when the system is entering light sleep + CallbackObserver lightSleepObserver = CallbackObserver(this, &Events::beforeLightSleep); +#endif +}; + +} // namespace NicheGraphics::InkHUD + +#endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/InkHUD.cpp b/src/graphics/niche/InkHUD/InkHUD.cpp new file mode 100644 index 000000000..90b6718e0 --- /dev/null +++ b/src/graphics/niche/InkHUD/InkHUD.cpp @@ -0,0 +1,218 @@ +#ifdef MESHTASTIC_INCLUDE_INKHUD + +#include "./InkHUD.h" + +#include "./Applet.h" +#include "./Events.h" +#include "./Persistence.h" +#include "./Renderer.h" +#include "./SystemApplet.h" +#include "./Tile.h" +#include "./WindowManager.h" + +using namespace NicheGraphics; + +// Get or create the singleton +InkHUD::InkHUD *InkHUD::InkHUD::getInstance() +{ + // Create the singleton instance of our class, if not yet done + static InkHUD *instance = nullptr; + if (!instance) { + instance = new InkHUD; + + instance->persistence = new Persistence; + instance->windowManager = new WindowManager; + instance->renderer = new Renderer; + instance->events = new Events; + } + + return instance; +} + +// Connect the (fully set-up) E-Ink driver to InkHUD +// Should happen in your variant's nicheGraphics.h file, before InkHUD::begin is called +void InkHUD::InkHUD::setDriver(Drivers::EInk *driver) +{ + renderer->setDriver(driver); +} + +// Set the target number of FAST display updates in a row, before a FULL update is used for display health +// This value applies only to updates with an UNSPECIFIED update type +// If explicitly requested FAST updates exceed this target, the stressMultiplier parameter determines how many +// subsequent FULL updates will be performed, in an attempt to restore the display's health +void InkHUD::InkHUD::setDisplayResilience(uint8_t fastPerFull, float stressMultiplier) +{ + renderer->setDisplayResilience(fastPerFull, stressMultiplier); +} + +// Register a user applet with InkHUD +// A variant's nicheGraphics.h file should instantiate your chosen applets, then pass them to this method +// Passing an applet to this method is all that is required to make it available to the user in your InkHUD build +void InkHUD::InkHUD::addApplet(const char *name, Applet *a, bool defaultActive, bool defaultAutoshow, uint8_t onTile) +{ + windowManager->addApplet(name, a, defaultActive, defaultAutoshow, onTile); +} + +// Start InkHUD! +// Call this only after you have configured InkHUD +void InkHUD::InkHUD::begin() +{ + persistence->loadSettings(); + persistence->loadLatestMessage(); + + windowManager->begin(); + events->begin(); + renderer->begin(); + // LogoApplet shows boot screen here +} + +// Call this when your user button gets a short press +// Should be connected to an input source in nicheGraphics.h (NicheGraphics::Inputs::TwoButton?) +void InkHUD::InkHUD::shortpress() +{ + events->onButtonShort(); +} + +// Call this when your user button gets a long press +// Should be connected to an input source in nicheGraphics.h (NicheGraphics::Inputs::TwoButton?) +void InkHUD::InkHUD::longpress() +{ + events->onButtonLong(); +} + +// Cycle the next user applet to the foreground +// Only activated applets are cycled +// If user has a multi-applet layout, the applets will cycle on the "focused tile" +void InkHUD::InkHUD::nextApplet() +{ + windowManager->nextApplet(); +} + +// Show the menu (on the the focused tile) +// The applet previously displayed there will be restored once the menu closes +void InkHUD::InkHUD::openMenu() +{ + windowManager->openMenu(); +} + +// In layouts where multiple applets are shown at once, change which tile is focused +// The focused tile in the one which cycles applets on button short press, and displays menu on long press +void InkHUD::InkHUD::nextTile() +{ + windowManager->nextTile(); +} + +// Rotate the display image by 90 degrees +void InkHUD::InkHUD::rotate() +{ + windowManager->rotate(); +} + +// Show / hide the battery indicator in top-right +void InkHUD::InkHUD::toggleBatteryIcon() +{ + windowManager->toggleBatteryIcon(); +} + +// An applet asking for the display to be updated +// This does not occur immediately +// Instead, rendering is scheduled ASAP, for the next Renderer::runOnce call +// This allows multiple applets to observe the same event, and then share the same opportunity to update +// Applets should requestUpdate, whether or not they are currently displayed ("foreground") +// This is because they *might* be automatically brought to foreground by WindowManager::autoshow +void InkHUD::InkHUD::requestUpdate() +{ + renderer->requestUpdate(); +} + +// Demand that the display be updated +// Ignores all diplomacy: +// - the display *will* update +// - the specified update type *will* be used +// If the async parameter is false, code flow is blocked while the update takes place +void InkHUD::InkHUD::forceUpdate(EInk::UpdateTypes type, bool async) +{ + renderer->forceUpdate(type, async); +} + +// Wait for any in-progress display update to complete before continuing +void InkHUD::InkHUD::awaitUpdate() +{ + renderer->awaitUpdate(); +} + +// Ask the window manager to potentially bring a different user applet to foreground +// An applet will be brought to foreground if it has just received new and relevant info +// For Example: AllMessagesApplet has just received a new text message +// Permission for this autoshow behavior is granted by the user, on an applet-by-applet basis +// If autoshow brings an applet to foreground, an InkHUD notification will not be generated for the same event +void InkHUD::InkHUD::autoshow() +{ + windowManager->autoshow(); +} + +// Tell the window manager that the Persistence::Settings value for applet activation has changed, +// and that it should reconfigure accordingly. +// This is triggered at boot, or when the user enables / disabled applets via the on-screen menu +void InkHUD::InkHUD::updateAppletSelection() +{ + windowManager->changeActivatedApplets(); +} + +// Tell the window manager that the Persistence::Settings value for layout or rotation has changed, +// and that it should reconfigure accordingly. +// This is triggered at boot, or by rotate / layout options in the on-screen menu +void InkHUD::InkHUD::updateLayout() +{ + windowManager->changeLayout(); +} + +// Width of the display, in the context of the current rotation +uint16_t InkHUD::InkHUD::width() +{ + return renderer->width(); +} + +// Height of the display, in the context of the current rotation +uint16_t InkHUD::InkHUD::height() +{ + return renderer->height(); +} + +// A collection of any user tiles which do not have a valid user applet +// This can occur in various situations, such as when a user enables fewer applets than their layout has tiles +// The tiles (and which regions the occupy) are private information of the window manager +// The renderer needs to know which regions (if any) are empty, +// in order to fill them with a "placeholder" pattern. +// -- There may be a tidier way to accomplish this -- +std::vector InkHUD::InkHUD::getEmptyTiles() +{ + return windowManager->getEmptyTiles(); +} + +// Get a system applet by its name +// This isn't particularly elegant, but it does avoid: +// - passing around a big set of references +// - having two sets of references (systemApplet vector for iteration) +InkHUD::SystemApplet *InkHUD::InkHUD::getSystemApplet(const char *name) +{ + for (SystemApplet *sa : systemApplets) { + if (strcmp(name, sa->name) == 0) + return sa; + } + + assert(false); // Invalid name +} + +// Place a pixel into the image buffer +// The x and y coordinates are in the context of the current display rotation +// - Applets pass "relative" pixels to tiles +// - Tiles pass translated pixels to this method +// - this methods (Renderer) places rotated pixels into the image buffer +// This method provides the final formatting step required. The image buffer is suitable for writing to display +void InkHUD::InkHUD::drawPixel(int16_t x, int16_t y, Color c) +{ + renderer->handlePixel(x, y, c); +} + +#endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/InkHUD.h b/src/graphics/niche/InkHUD/InkHUD.h new file mode 100644 index 000000000..13839ea22 --- /dev/null +++ b/src/graphics/niche/InkHUD/InkHUD.h @@ -0,0 +1,110 @@ +#ifdef MESHTASTIC_INCLUDE_INKHUD + +/* + + InkHUD's main class + - singleton + - mediator between the various components + +*/ + +#pragma once + +#include "configuration.h" + +#include "graphics/niche/Drivers/EInk/EInk.h" + +#include "./AppletFont.h" + +#include + +namespace NicheGraphics::InkHUD +{ + +// Color, understood by display controller IC (as bit values) +// Also suitable for use as AdafruitGFX colors +enum Color : uint8_t { + BLACK = 0, + WHITE = 1, +}; + +class Applet; +class Events; +class Persistence; +class Renderer; +class SystemApplet; +class Tile; +class WindowManager; + +class InkHUD +{ + public: + static InkHUD *getInstance(); // Access to this singleton class + + // Configuration + // - before InkHUD::begin, in variant nicheGraphics.h, + + void setDriver(Drivers::EInk *driver); + void setDisplayResilience(uint8_t fastPerFull = 5, float stressMultiplier = 2.0); + void addApplet(const char *name, Applet *a, bool defaultActive = false, bool defaultAutoshow = false, uint8_t onTile = -1); + + void begin(); + + // Handle user-button press + // - connected to an input source, in variant nicheGraphics.h + + void shortpress(); + void longpress(); + + // Trigger UI changes + // - called by various InkHUD components + // - suitable(?) for use by aux button, connected in variant nicheGraphics.h + + void nextApplet(); + void openMenu(); + void nextTile(); + void rotate(); + void toggleBatteryIcon(); + + // Updating the display + // - called by various InkHUD components + + void requestUpdate(); + void forceUpdate(Drivers::EInk::UpdateTypes type = Drivers::EInk::UpdateTypes::UNSPECIFIED, bool async = true); + void awaitUpdate(); + + // (Re)configuring WindowManager + + void autoshow(); // Bring an applet to foreground + void updateAppletSelection(); // Change which applets are active + void updateLayout(); // Change multiplexing (count, rotation) + + // Information passed between components + + uint16_t width(); // From E-Ink driver + uint16_t height(); // From E-Ink driver + std::vector getEmptyTiles(); // From WindowManager + + // Applets + + SystemApplet *getSystemApplet(const char *name); + std::vector userApplets; + std::vector systemApplets; + + // Pass drawing output to Renderer + void drawPixel(int16_t x, int16_t y, Color c); + + // Shared data which persists between boots + Persistence *persistence = nullptr; + + private: + InkHUD() {} // Constructor made private to force use of InkHUD::getInstance + + Events *events = nullptr; // Handle non-specific firmware events + Renderer *renderer = nullptr; // Co-ordinate display updates + WindowManager *windowManager = nullptr; // Multiplexing of applets +}; + +} // namespace NicheGraphics::InkHUD + +#endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/MessageStore.h b/src/graphics/niche/InkHUD/MessageStore.h index 3cf7d0f68..745c3b2eb 100644 --- a/src/graphics/niche/InkHUD/MessageStore.h +++ b/src/graphics/niche/InkHUD/MessageStore.h @@ -31,7 +31,7 @@ class MessageStore }; MessageStore() = delete; - MessageStore(std::string label); // Label determines filename in flash + explicit MessageStore(std::string label); // Label determines filename in flash void saveToFlash(); void loadFromFlash(); diff --git a/src/graphics/niche/InkHUD/Persistence.cpp b/src/graphics/niche/InkHUD/Persistence.cpp index 6e8ac0458..20909f2dc 100644 --- a/src/graphics/niche/InkHUD/Persistence.cpp +++ b/src/graphics/niche/InkHUD/Persistence.cpp @@ -5,17 +5,21 @@ using namespace NicheGraphics; // Load settings and latestMessage data -void InkHUD::loadDataFromFlash() +void InkHUD::Persistence::loadSettings() { // Load the InkHUD settings from flash, and check version number // We should only consider the version number if the InkHUD flashdata component reports that we *did* actually load flash data - InkHUD::Settings loadedSettings; + Settings loadedSettings; bool loadSucceeded = FlashData::load(&loadedSettings, "settings"); if (loadSucceeded && loadedSettings.meta.version == SETTINGS_VERSION && loadedSettings.meta.version != 0) settings = loadedSettings; // Version matched, replace the defaults with the loaded values else LOG_WARN("Settings version changed. Using defaults"); +} +// Load settings and latestMessage data +void InkHUD::Persistence::loadLatestMessage() +{ // Load previous "latestMessages" data from flash MessageStore store("latest"); store.loadFromFlash(); @@ -32,12 +36,15 @@ void InkHUD::loadDataFromFlash() } } -// Save settings and latestMessage data -void InkHUD::saveDataToFlash() +// Save the InkHUD settings to flash +void InkHUD::Persistence::saveSettings() { - // Save the InkHUD settings to flash FlashData::save(&settings, "settings"); +} +// Save latestMessage data to flash +void InkHUD::Persistence::saveLatestMessage() +{ // Number of strings saved determines whether last message was broadcast or dm MessageStore store("latest"); store.messages.push_back(latestMessage.dm); @@ -46,14 +53,31 @@ void InkHUD::saveDataToFlash() store.saveToFlash(); } -// Holds InkHUD settings while running -// Saved back to Flash at shutdown -// Accessed by including persistence.h -InkHUD::Settings InkHUD::settings; +/* +void InkHUD::Persistence::printSettings(Settings *settings) +{ + if (SETTINGS_VERSION != 2) + LOG_WARN("Persistence::printSettings was written for SETTINGS_VERSION=2, current is %d", SETTINGS_VERSION); -// Holds copies of the most recent broadcast and DM messages while running -// Saved to Flash at shutdown -// Accessed by including persistence.h -InkHUD::LatestMessage InkHUD::latestMessage; + LOG_DEBUG("meta.version=%d", settings->meta.version); + LOG_DEBUG("userTiles.count=%d", settings->userTiles.count); + LOG_DEBUG("userTiles.maxCount=%d", settings->userTiles.maxCount); + LOG_DEBUG("userTiles.focused=%d", settings->userTiles.focused); + for (uint8_t i = 0; i < MAX_TILES_GLOBAL; i++) + LOG_DEBUG("userTiles.displayedUserApplet[%d]=%d", i, settings->userTiles.displayedUserApplet[i]); + for (uint8_t i = 0; i < MAX_USERAPPLETS_GLOBAL; i++) + LOG_DEBUG("userApplets.active[%d]=%d", i, settings->userApplets.active[i]); + for (uint8_t i = 0; i < MAX_USERAPPLETS_GLOBAL; i++) + LOG_DEBUG("userApplets.autoshow[%d]=%d", i, settings->userApplets.autoshow[i]); + LOG_DEBUG("optionalFeatures.notifications=%d", settings->optionalFeatures.notifications); + LOG_DEBUG("optionalFeatures.batteryIcon=%d", settings->optionalFeatures.batteryIcon); + LOG_DEBUG("optionalMenuItems.nextTile=%d", settings->optionalMenuItems.nextTile); + LOG_DEBUG("optionalMenuItems.backlight=%d", settings->optionalMenuItems.backlight); + LOG_DEBUG("tips.firstBoot=%d", settings->tips.firstBoot); + LOG_DEBUG("tips.safeShutdownSeen=%d", settings->tips.safeShutdownSeen); + LOG_DEBUG("rotation=%d", settings->rotation); + LOG_DEBUG("recentlyActiveSeconds=%d", settings->recentlyActiveSeconds); +} +*/ #endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/Persistence.h b/src/graphics/niche/InkHUD/Persistence.h index e2daa02d9..40f1dd521 100644 --- a/src/graphics/niche/InkHUD/Persistence.h +++ b/src/graphics/niche/InkHUD/Persistence.h @@ -14,110 +14,119 @@ The save / load mechanism is a shared NicheGraphics feature. #include "configuration.h" +#include "./InkHUD.h" #include "graphics/niche/FlashData.h" #include "graphics/niche/InkHUD/MessageStore.h" namespace NicheGraphics::InkHUD { -constexpr uint8_t MAX_TILES_GLOBAL = 4; -constexpr uint8_t MAX_USERAPPLETS_GLOBAL = 16; +class Persistence +{ + public: + static constexpr uint8_t MAX_TILES_GLOBAL = 4; + static constexpr uint8_t MAX_USERAPPLETS_GLOBAL = 16; -// Used to invalidate old settings, if needed -// Version 0 is reserved for testing, and will always load defaults -constexpr uint32_t SETTINGS_VERSION = 2; + // Used to invalidate old settings, if needed + // Version 0 is reserved for testing, and will always load defaults + static constexpr uint32_t SETTINGS_VERSION = 2; -struct Settings { - struct Meta { - // Used to invalidate old savefiles, if we make breaking changes - uint32_t version = SETTINGS_VERSION; - } meta; + struct Settings { + struct Meta { + // Used to invalidate old savefiles, if we make breaking changes + uint32_t version = SETTINGS_VERSION; + } meta; - struct UserTiles { - // How many tiles are shown - uint8_t count = 1; + struct UserTiles { + // How many tiles are shown + uint8_t count = 1; - // Maximum amount of tiles for this display - uint8_t maxCount = 4; + // Maximum amount of tiles for this display + uint8_t maxCount = 4; - // Which tile is focused (responding to user button input) - uint8_t focused = 0; + // Which tile is focused (responding to user button input) + uint8_t focused = 0; - // Which applet is displayed on which tile - // Index of array: which tile, as indexed in WindowManager::tiles - // Value of array: which applet, as indexed in WindowManager::activeApplets - uint8_t displayedUserApplet[MAX_TILES_GLOBAL] = {0, 1, 2, 3}; - } userTiles; + // Which applet is displayed on which tile + // Index of array: which tile, as indexed in WindowManager::userTiles + // Value of array: which applet, as indexed in InkHUD::userApplets + uint8_t displayedUserApplet[MAX_TILES_GLOBAL] = {0, 1, 2, 3}; + } userTiles; - struct UserApplets { - // Which applets are running (either displayed, or in the background) - // Index of array: which applet, as indexed in WindowManager::applets - // Initial value is set by the "activeByDefault" parameter of WindowManager::addApplet, in setupNicheGraphics() - bool active[MAX_USERAPPLETS_GLOBAL]; + struct UserApplets { + // Which applets are running (either displayed, or in the background) + // Index of array: which applet, as indexed in InkHUD::userApplets + // Initial value is set by the "activeByDefault" parameter of InkHUD::addApplet, in setupNicheGraphics method + bool active[MAX_USERAPPLETS_GLOBAL]{false}; - // Which user applets should be automatically shown when they have important data to show - // If none set, foreground applets should remain foreground without manual user input - // If multiple applets request this at once, - // priority is the order which they were passed to WindowManager::addApplets, in setupNicheGraphics() - bool autoshow[MAX_USERAPPLETS_GLOBAL]{false}; - } userApplets; + // Which user applets should be automatically shown when they have important data to show + // If none set, foreground applets should remain foreground without manual user input + // If multiple applets request this at once, + // priority is the order which they were passed to InkHUD::addApplets, in setupNicheGraphics method + bool autoshow[MAX_USERAPPLETS_GLOBAL]{false}; + } userApplets; - // Features which the use can enable / disable via the on-screen menu - struct OptionalFeatures { - bool notifications = true; - bool batteryIcon = false; - } optionalFeatures; + // Features which the user can enable / disable via the on-screen menu + struct OptionalFeatures { + bool notifications = true; + bool batteryIcon = false; + } optionalFeatures; - // Some menu items may not be required, based on device / configuration - // We can enable them only when needed, to de-clutter the menu - struct OptionalMenuItems { - // If aux button is used to swap between tiles, we have to need for this menu item - bool nextTile = true; + // Some menu items may not be required, based on device / configuration + // We can enable them only when needed, to de-clutter the menu + struct OptionalMenuItems { + // If aux button is used to swap between tiles, we have no need for this menu item + bool nextTile = true; - // Used if backlight present, and not controlled by AUX button - // If this item is added to menu: backlight is always active when menu is open - // The added menu items then allows the user to "Keep Backlight On", globally. - bool backlight = false; - } optionalMenuItems; + // Used if backlight present, and not controlled by AUX button + // If this item is added to menu: backlight is always active when menu is open + // The added menu items then allows the user to "Keep Backlight On", globally. + bool backlight = false; + } optionalMenuItems; - // Allows tips to be run once only - struct Tips { - // Enables the longer "tutorial" shown only on first boot - // Once tutorial has been completed, it is no longer shown - bool firstBoot = true; + // Allows tips to be run once only + struct Tips { + // Enables the longer "tutorial" shown only on first boot + // Once tutorial has been completed, it is no longer shown + bool firstBoot = true; - // User is advised to shutdown before removing device power - // Once user executes a shutdown (either via menu or client app), - // this tip is no longer shown - bool safeShutdownSeen = false; - } tips; + // User is advised to shut down before removing device power + // Once user executes a shutdown (either via menu or client app), + // this tip is no longer shown + bool safeShutdownSeen = false; + } tips; - // Rotation of the display - // Multiples of 90 degrees clockwise - // Most commonly: rotation is 0 when flex connector is oriented below display - uint8_t rotation = 1; + // Rotation of the display + // Multiples of 90 degrees clockwise + // Most commonly: rotation is 0 when flex connector is oriented below display + uint8_t rotation = 0; - // How long do we consider another node to be "active"? - // Used when applets want to filter for "active nodes" only - uint32_t recentlyActiveSeconds = 2 * 60; + // How long do we consider another node to be "active"? + // Used when applets want to filter for "active nodes" only + uint32_t recentlyActiveSeconds = 2 * 60; + }; + + // Most recently received text message + // Value is updated by InkHUD::WindowManager, as a courtesy to applets + // Note: different from devicestate.rx_text_message, + // which may contain an *outgoing message* to broadcast + struct LatestMessage { + MessageStore::Message broadcast; // Most recent message received broadcast + MessageStore::Message dm; // Most recent received DM + bool wasBroadcast; // True if most recent broadcast is newer than most recent dm + }; + + void loadSettings(); + void saveSettings(); + void loadLatestMessage(); + void saveLatestMessage(); + + // void printSettings(Settings *settings); // Debugging use only + + Settings settings; + LatestMessage latestMessage; }; -// Most recently received text message -// Value is updated by InkHUD::WindowManager, as a courtesty to applets -// Note: different from devicestate.rx_text_message, -// which may contain an *outgoing message* to broadcast -struct LatestMessage { - MessageStore::Message broadcast; // Most recent message received broadcast - MessageStore::Message dm; // Most recent received DM - bool wasBroadcast; // True if most recent broadcast is newer than most recent dm -}; - -extern Settings settings; -extern LatestMessage latestMessage; - -void loadDataFromFlash(); -void saveDataToFlash(); - } // namespace NicheGraphics::InkHUD #endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/PlatformioConfig.ini b/src/graphics/niche/InkHUD/PlatformioConfig.ini index 7eb1d34e9..cab0ea7bc 100644 --- a/src/graphics/niche/InkHUD/PlatformioConfig.ini +++ b/src/graphics/niche/InkHUD/PlatformioConfig.ini @@ -1,6 +1,7 @@ [inkhud] -board_level = extra -build_src_filter = +<../variants/$PIOENV> ; Include nicheGraphics.h +build_src_filter = + +; Include the nicheGraphics directory + +<../variants/$PIOENV>; Include nicheGraphics.h from our variant folder build_flags = -D MESHTASTIC_INCLUDE_NICHE_GRAPHICS ; Use NicheGraphics -D MESHTASTIC_INCLUDE_INKHUD ; Use InkHUD (a NicheGraphics UI) diff --git a/src/graphics/niche/InkHUD/README.md b/src/graphics/niche/InkHUD/README.md deleted file mode 100644 index 8d788ffa8..000000000 --- a/src/graphics/niche/InkHUD/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# InkHUD - -A heads-up-display for E-Ink devices, intended to supplement a connected phone / client. Implemented as a "NicheGraphics" UI. - -Supported devices (as of 1st Feb. 2025): - -- Heltec Vision Master E213 -- Heltec Vision Master E290 -- Heltec Wireless Paper V1.1 -- LILYGO T-Echo - -More to follow diff --git a/src/graphics/niche/InkHUD/Renderer.cpp b/src/graphics/niche/InkHUD/Renderer.cpp new file mode 100644 index 000000000..c058c4126 --- /dev/null +++ b/src/graphics/niche/InkHUD/Renderer.cpp @@ -0,0 +1,412 @@ +#ifdef MESHTASTIC_INCLUDE_INKHUD + +#include "./Renderer.h" + +#include "main.h" + +#include "./Applet.h" +#include "./SystemApplet.h" +#include "./Tile.h" + +using namespace NicheGraphics; + +InkHUD::Renderer::Renderer() : concurrency::OSThread("Renderer") +{ + // Nothing for the timer to do just yet + OSThread::disable(); + + // Convenient references + inkhud = InkHUD::getInstance(); + settings = &inkhud->persistence->settings; +} + +// Connect the (fully set-up) E-Ink driver to InkHUD +// Should happen in your variant's nicheGraphics.h file, before InkHUD::begin is called +void InkHUD::Renderer::setDriver(Drivers::EInk *driver) +{ + // Make sure not already set + if (this->driver) { + LOG_ERROR("Driver already set"); + delay(2000); // Wait for native serial.. + assert(false); + } + + // Store the driver which was created in setupNicheGraphics() + this->driver = driver; + + // Determine the dimensions of the image buffer, in bytes. + // Along rows, pixels are stored 8 per byte. + // Not all display widths are divisible by 8. Need to make sure bytecount accommodates padding for these. + imageBufferWidth = ((driver->width - 1) / 8) + 1; + imageBufferHeight = driver->height; + + // Allocate the image buffer + imageBuffer = new uint8_t[imageBufferWidth * imageBufferHeight]; +} + +// Set the target number of FAST display updates in a row, before a FULL update is used for display health +// This value applies only to updates with an UNSPECIFIED update type +// If explicitly requested FAST updates exceed this target, the stressMultiplier parameter determines how many +// subsequent FULL updates will be performed, in an attempt to restore the display's health +void InkHUD::Renderer::setDisplayResilience(uint8_t fastPerFull, float stressMultiplier) +{ + displayHealth.fastPerFull = fastPerFull; + displayHealth.stressMultiplier = stressMultiplier; +} + +void InkHUD::Renderer::begin() +{ + forceUpdate(Drivers::EInk::UpdateTypes::FULL, false); +} + +// Set a flag, which will be picked up by runOnce, ASAP. +// Quite likely, multiple applets will all want to respond to one event (Observable, etc) +// Each affected applet can independently call requestUpdate(), and all share the one opportunity to render, at next runOnce +void InkHUD::Renderer::requestUpdate() +{ + requested = true; + + // We will run the thread as soon as we loop(), + // after all Applets have had a chance to observe whatever event set this off + OSThread::setIntervalFromNow(0); + OSThread::enabled = true; + runASAP = true; +} + +// requestUpdate will not actually update if no requests were made by applets which are actually visible +// This can occur, because applets requestUpdate even from the background, +// in case the user's autoshow settings permit them to be moved to foreground. +// Sometimes, however, we will want to trigger a display update manually, in the absence of any sort of applet event +// Display health, for example. +// In these situations, we use forceUpdate +void InkHUD::Renderer::forceUpdate(Drivers::EInk::UpdateTypes type, bool async) +{ + requested = true; + forced = true; + displayHealth.forceUpdateType(type); + + // Normally, we need to start the timer, in case the display is busy and we briefly defer the update + if (async) { + // We will run the thread as soon as we loop(), + // after all Applets have had a chance to observe whatever event set this off + OSThread::setIntervalFromNow(0); + OSThread::enabled = true; + runASAP = true; + } + + // If the update is *not* asynchronous, we begin the render process directly here + // so that it can block code flow while running + else + render(false); +} + +// Wait for any in-progress display update to complete before continuing +void InkHUD::Renderer::awaitUpdate() +{ + if (driver->busy()) { + LOG_INFO("Waiting for display"); + driver->await(); // Wait here for update to complete + } +} + +// Set a ready-to-draw pixel into the image buffer +// All rotations / translations have already taken place: this buffer data is formatted ready for the driver +void InkHUD::Renderer::handlePixel(int16_t x, int16_t y, Color c) +{ + rotatePixelCoords(&x, &y); + + uint32_t byteNum = (y * imageBufferWidth) + (x / 8); // X data is 8 pixels per byte + uint8_t bitNum = 7 - (x % 8); // Invert order: leftmost bit (most significant) is leftmost pixel of byte. + + bitWrite(imageBuffer[byteNum], bitNum, c); +} + +// Width of the display, relative to rotation +uint16_t InkHUD::Renderer::width() +{ + if (settings->rotation % 2) + return driver->height; + else + return driver->width; +} + +// Height of the display, relative to rotation +uint16_t InkHUD::Renderer::height() +{ + if (settings->rotation % 2) + return driver->width; + else + return driver->height; +} + +// Runs at regular intervals +// - postponing render: until next loop(), allowing all applets to be notified of some Mesh event before render +// - queuing another render: while one is already is progress +int32_t InkHUD::Renderer::runOnce() +{ + // If an applet asked to render, and hardware is able, lets try now + if (requested && !driver->busy()) { + render(); + } + + // If our render() call failed, try again shortly + // otherwise, stop our thread until next update due + if (requested) + return 250UL; + else + return OSThread::disable(); +} + +// Applies the system-wide rotation to pixel positions +// This step is applied to image data which has already been translated by a Tile object +// This is the final step before the pixel is placed into the image buffer +// No return: values of the *x and *y parameters are modified by the method +void InkHUD::Renderer::rotatePixelCoords(int16_t *x, int16_t *y) +{ + // Apply a global rotation to pixel locations + int16_t x1 = 0; + int16_t y1 = 0; + switch (settings->rotation) { + case 0: + x1 = *x; + y1 = *y; + break; + case 1: + x1 = (driver->width - 1) - *y; + y1 = *x; + break; + case 2: + x1 = (driver->width - 1) - *x; + y1 = (driver->height - 1) - *y; + break; + case 3: + x1 = *y; + y1 = (driver->height - 1) - *x; + break; + } + *x = x1; + *y = y1; +} + +// Make an attempt to gather image data from some / all applets, and update the display +// Might not be possible right now, if update already is progress. +void InkHUD::Renderer::render(bool async) +{ + // Make sure the display is ready for a new update + if (async) { + // Previous update still running, Will try again shortly, via runOnce() + if (driver->busy()) + return; + } else { + // Wait here for previous update to complete + driver->await(); + } + + // Determine if a system applet has requested exclusive rights to request an update, + // or exclusive rights to render + checkLocks(); + + // (Potentially) change applet to display new info, + // then check if this newly displayed applet makes a pending notification redundant + inkhud->autoshow(); + + // If an update is justified. + // We don't know this until after autoshow has run, as new applets may now be in foreground + if (shouldUpdate()) { + + // Decide which technique the display will use to change image + // Done early, as rendering resets the Applets' requested types + Drivers::EInk::UpdateTypes updateType = decideUpdateType(); + + // Render the new image + clearBuffer(); + renderUserApplets(); + renderPlaceholders(); + renderSystemApplets(); + + // Tell display to begin process of drawing new image + LOG_INFO("Updating display"); + driver->update(imageBuffer, updateType); + + // If not async, wait here until the update is complete + if (!async) + driver->await(); + } + + // Our part is done now. + // If update is async, the display hardware is still performing the update process, + // but that's all handled by NicheGraphics::Drivers::EInk + + // Tidy up, ready for a new request + requested = false; + forced = false; +} + +// Manually fill the image buffer with WHITE +// Clears any old drawing +// Note: benchmarking revealed that this is *much* faster than setting pixels individually +// So much so that it's more efficient to re-render all applets, +// rather than rendering selectively, and manually blanking a portion of the display +void InkHUD::Renderer::clearBuffer() +{ + memset(imageBuffer, 0xFF, imageBufferHeight * imageBufferWidth); +} + +void InkHUD::Renderer::checkLocks() +{ + lockRendering = nullptr; + lockRequests = nullptr; + + for (SystemApplet *sa : inkhud->systemApplets) { + if (!lockRendering && sa->lockRendering && sa->isForeground()) { + lockRendering = sa; + } + if (!lockRequests && sa->lockRequests && sa->isForeground()) { + lockRequests = sa; + } + } +} + +bool InkHUD::Renderer::shouldUpdate() +{ + bool should = false; + + // via forceUpdate + should |= forced; + + // via a system applet (which has locked update requests) + if (lockRequests) { + should |= lockRequests->wantsToRender(); + return should; // Early exit - no other requests considered + } + + // via system applet (not locked) + for (SystemApplet *sa : inkhud->systemApplets) { + if (sa->wantsToRender() // This applet requested + && sa->isForeground()) // This applet is currently shown + { + should = true; + break; + } + } + + // via user applet + for (Applet *ua : inkhud->userApplets) { + if (ua // Tile has valid applet + && ua->wantsToRender() // This applet requested display update + && ua->isForeground()) // This applet is currently shown + { + should = true; + break; + } + } + + return should; +} + +// Determine which type of E-Ink update the display will perform, to change the image. +// Considers the needs of the various applets, then weighs against display health. +// An update type specified by forceUpdate will be granted with no further questioning. +Drivers::EInk::UpdateTypes InkHUD::Renderer::decideUpdateType() +{ + // Ask applets which update type they would prefer + // Some update types take priority over others + + // No need to consider the "requests" if somebody already forced an update + if (!forced) { + // User applets + for (Applet *ua : inkhud->userApplets) { + if (ua && ua->isForeground()) + displayHealth.requestUpdateType(ua->wantsUpdateType()); + } + // System Applets + for (SystemApplet *sa : inkhud->systemApplets) { + if (sa && sa->isForeground()) + displayHealth.requestUpdateType(sa->wantsUpdateType()); + } + } + + return displayHealth.decideUpdateType(); +} + +// Run the drawing operations of any user applets which are currently displayed +// Pixel output is placed into the framebuffer, ready for handoff to the EInk driver +void InkHUD::Renderer::renderUserApplets() +{ + // Don't render user applets if a system applet has demanded the whole display to itself + if (lockRendering) + return; + + // Render any user applets which are currently visible + for (Applet *ua : inkhud->userApplets) { + if (ua && ua->isActive() && ua->isForeground()) { + uint32_t start = millis(); + ua->render(); // Draw! + uint32_t stop = millis(); + LOG_DEBUG("%s took %dms to render", ua->name, stop - start); + } + } +} + +// Run the drawing operations of any system applets which are currently displayed +// Pixel output is placed into the framebuffer, ready for handoff to the EInk driver +void InkHUD::Renderer::renderSystemApplets() +{ + SystemApplet *battery = inkhud->getSystemApplet("BatteryIcon"); + SystemApplet *menu = inkhud->getSystemApplet("Menu"); + SystemApplet *notifications = inkhud->getSystemApplet("Notification"); + + // Each system applet + for (SystemApplet *sa : inkhud->systemApplets) { + + // Skip if not shown + if (!sa->isForeground()) + continue; + + // Skip if locked by another applet + if (lockRendering && lockRendering != sa) + continue; + + // Don't draw the battery or notifications overtop the menu + // Todo: smarter way to handle this + if (menu->isForeground() && (sa == battery || sa == notifications)) + continue; + + assert(sa->getTile()); + + // uint32_t start = millis(); + sa->render(); // Draw! + // uint32_t stop = millis(); + // LOG_DEBUG("%s took %dms to render", sa->name, stop - start); + } +} + +// In some situations (e.g. layout or applet selection changes), +// a user tile can end up without an assigned applet. +// In this case, we will fill the empty space with diagonal lines. +void InkHUD::Renderer::renderPlaceholders() +{ + // Don't fill empty space with placeholders if a system applet wants exclusive use of the display + if (lockRendering) + return; + + // Ask the window manager which tiles are empty + std::vector emptyTiles = inkhud->getEmptyTiles(); + + // No empty tiles + if (emptyTiles.size() == 0) + return; + + SystemApplet *placeholder = inkhud->getSystemApplet("Placeholder"); + + // uint32_t start = millis(); + for (Tile *t : emptyTiles) { + t->assignApplet(placeholder); + placeholder->render(); + t->assignApplet(nullptr); + } + // uint32_t stop = millis(); + // LOG_DEBUG("Placeholders took %dms to render", stop - start); +} + +#endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/Renderer.h b/src/graphics/niche/InkHUD/Renderer.h new file mode 100644 index 000000000..b6cf9e215 --- /dev/null +++ b/src/graphics/niche/InkHUD/Renderer.h @@ -0,0 +1,96 @@ +#ifdef MESHTASTIC_INCLUDE_INKHUD + +/* + +Orchestrates updating of the display image + +- takes requests (or demands) for display update +- performs the various steps of the rendering operation +- interfaces with the E-Ink driver + +*/ + +#pragma once + +#include "configuration.h" + +#include "./DisplayHealth.h" +#include "./InkHUD.h" +#include "./Persistence.h" +#include "graphics/niche/Drivers/EInk/EInk.h" + +namespace NicheGraphics::InkHUD +{ + +class Renderer : protected concurrency::OSThread +{ + + public: + Renderer(); + + // Configuration, before begin + + void setDriver(Drivers::EInk *driver); + void setDisplayResilience(uint8_t fastPerFull, float stressMultiplier); + + void begin(); + + // Call these to make the image change + + void requestUpdate(); // Update display, if a foreground applet has info it wants to show + void forceUpdate(Drivers::EInk::UpdateTypes type = Drivers::EInk::UpdateTypes::UNSPECIFIED, + bool async = true); // Update display, regardless of whether any applets requested this + + // Wait for an update to complete + void awaitUpdate(); + + // Receives pixel output from an applet (via a tile, which translates the coordinates) + void handlePixel(int16_t x, int16_t y, Color c); + + // Size of display, in context of current rotation + + uint16_t width(); + uint16_t height(); + + private: + // Make attemps to render / update, once triggered by requestUpdate or forceUpdate + int32_t runOnce() override; + + // Apply the display rotation to handled pixels + void rotatePixelCoords(int16_t *x, int16_t *y); + + // Execute the render process now, then hand off to driver for display update + void render(bool async = true); + + // Steps of the rendering process + + void clearBuffer(); + void checkLocks(); + bool shouldUpdate(); + Drivers::EInk::UpdateTypes decideUpdateType(); + void renderUserApplets(); + void renderSystemApplets(); + void renderPlaceholders(); + + Drivers::EInk *driver = nullptr; // Interacts with your variants display hardware + DisplayHealth displayHealth; // Manages display health by controlling type of update + + uint8_t *imageBuffer = nullptr; // Fed into driver + uint16_t imageBufferHeight = 0; + uint16_t imageBufferWidth = 0; + uint32_t imageBufferSize = 0; // Bytes + + SystemApplet *lockRendering = nullptr; // Render this applet *only* + SystemApplet *lockRequests = nullptr; // Honor update requests from this applet *only* + + bool requested = false; + bool forced = false; + + // For convenience + InkHUD *inkhud = nullptr; + Persistence::Settings *settings = nullptr; +}; + +} // namespace NicheGraphics::InkHUD + +#endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/SystemApplet.h b/src/graphics/niche/InkHUD/SystemApplet.h new file mode 100644 index 000000000..7ee47eeb9 --- /dev/null +++ b/src/graphics/niche/InkHUD/SystemApplet.h @@ -0,0 +1,43 @@ +#ifdef MESHTASTIC_INCLUDE_INKHUD + +/* + +An applet with nonstandard behavior, which will require special handling + +For features like the menu, and the battery icon. + +*/ + +#pragma once + +#include "configuration.h" + +#include "./Applet.h" + +namespace NicheGraphics::InkHUD +{ + +class SystemApplet : public Applet +{ + public: + // System applets have the right to: + + bool handleInput = false; // - respond to input from the user button + bool lockRendering = false; // - prevent other applets from being rendered during an update + bool lockRequests = false; // - prevent other applets from triggering display updates + + virtual void onReboot() { onShutdown(); } // - handle reboot specially + + // Other system applets may take precedence over our own system applet though + // The order an applet is passed to WindowManager::addSystemApplet determines this hierarchy (added earlier = higher rank) + + private: + // System applets are always running (active), but may not be visible (foreground) + + void onActivate() override {} + void onDeactivate() override {} +}; + +}; // namespace NicheGraphics::InkHUD + +#endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/Tile.cpp b/src/graphics/niche/InkHUD/Tile.cpp index e65835801..5e548de74 100644 --- a/src/graphics/niche/InkHUD/Tile.cpp +++ b/src/graphics/niche/InkHUD/Tile.cpp @@ -18,7 +18,7 @@ static int32_t runtaskHighlight() LOG_DEBUG("Dismissing Highlight"); InkHUD::Tile::highlightShown = false; InkHUD::Tile::highlightTarget = nullptr; - InkHUD::WindowManager::getInstance()->forceUpdate(Drivers::EInk::UpdateTypes::FAST); // Re-render, clearing the highlighting + InkHUD::InkHUD::getInstance()->forceUpdate(Drivers::EInk::UpdateTypes::FAST); // Re-render, clearing the highlighting return taskHighlight->disable(); } static void inittaskHighlight() @@ -33,21 +33,30 @@ static void inittaskHighlight() InkHUD::Tile::Tile() { - // For convenince - windowManager = InkHUD::WindowManager::getInstance(); + inkhud = InkHUD::getInstance(); inittaskHighlight(); Tile::highlightTarget = nullptr; Tile::highlightShown = false; } +InkHUD::Tile::Tile(int16_t left, int16_t top, uint16_t width, uint16_t height) +{ + assert(width > 0 && height > 0); + + this->left = left; + this->top = top; + this->width = width; + this->height = height; +} + // Set the region of the tile automatically, based on the user's chosen layout // This method places tiles which will host user applets // The WindowManager multiplexes the applets to these tiles automatically -void InkHUD::Tile::placeUserTile(uint8_t userTileCount, uint8_t tileIndex) +void InkHUD::Tile::setRegion(uint8_t userTileCount, uint8_t tileIndex) { - uint16_t displayWidth = windowManager->getWidth(); - uint16_t displayHeight = windowManager->getHeight(); + uint16_t displayWidth = inkhud->width(); + uint16_t displayHeight = inkhud->height(); bool landscape = displayWidth > displayHeight; @@ -62,10 +71,9 @@ void InkHUD::Tile::placeUserTile(uint8_t userTileCount, uint8_t tileIndex) return; } - // Todo: special handling for the notification area // Todo: special handling for 3 tile layout - // Gap between tiles + // Gutters between tiles const uint16_t spacing = 4; switch (userTileCount) { @@ -124,17 +132,12 @@ void InkHUD::Tile::placeUserTile(uint8_t userTileCount, uint8_t tileIndex) } assert(width > 0 && height > 0); - - this->left = left; - this->top = top; - this->width = width; - this->height = height; } // Manually set the region for a tile // This is only done for tiles which will host certain "System Applets", which have unique position / sizes: // Things like the NotificationApplet, BatteryIconApplet, etc -void InkHUD::Tile::placeSystemTile(int16_t left, int16_t top, uint16_t width, uint16_t height) +void InkHUD::Tile::setRegion(int16_t left, int16_t top, uint16_t width, uint16_t height) { assert(width > 0 && height > 0); @@ -182,31 +185,32 @@ void InkHUD::Tile::handleAppletPixel(int16_t x, int16_t y, Color c) // Crop to tile borders if (x >= left && x < (left + width) && y >= top && y < (top + height)) { - // Pass to the window manager - windowManager->handleTilePixel(x, y, c); + // Pass to the renderer + inkhud->drawPixel(x, y, c); } } -// Called by Applet base class, when learning of its dimensions +// Called by Applet base class, when setting applet dimensions, immediately before render uint16_t InkHUD::Tile::getWidth() { return width; } -// Called by Applet base class, when learning of its dimensions +// Called by Applet base class, when setting applet dimensions, immediately before render uint16_t InkHUD::Tile::getHeight() { return height; } // Longest edge of the display, in pixels +// A 296px x 250px display will return 296, for example // Maximum possible size of any tile's width / height -// Used by some components to allocate resources for the "worst possible situtation" +// Used by some components to allocate resources for the "worst possible situation" // "Sizing the cathedral for christmas eve" uint16_t InkHUD::Tile::maxDisplayDimension() { - WindowManager *wm = WindowManager::getInstance(); - return max(wm->getHeight(), wm->getWidth()); + InkHUD *inkhud = InkHUD::getInstance(); + return max(inkhud->height(), inkhud->width()); } // Ask for this tile to be highlighted @@ -216,7 +220,7 @@ void InkHUD::Tile::requestHighlight() { Tile::highlightTarget = this; Tile::highlightShown = false; - windowManager->forceUpdate(Drivers::EInk::UpdateTypes::FAST); + inkhud->forceUpdate(Drivers::EInk::UpdateTypes::FAST); } // Starts the timer which will automatically dismiss the highlighting, if the tile doesn't organically redraw first diff --git a/src/graphics/niche/InkHUD/Tile.h b/src/graphics/niche/InkHUD/Tile.h index e41536e53..0f5444f17 100644 --- a/src/graphics/niche/InkHUD/Tile.h +++ b/src/graphics/niche/InkHUD/Tile.h @@ -14,47 +14,44 @@ #include "configuration.h" #include "./Applet.h" -#include "./Types.h" -#include "./WindowManager.h" -#include +#include "./InkHUD.h" namespace NicheGraphics::InkHUD { -class Applet; -class WindowManager; - class Tile { public: Tile(); - void placeUserTile(uint8_t layoutSize, uint8_t tileIndex); // Assign region automatically, based on layout - void placeSystemTile(int16_t left, int16_t top, uint16_t width, uint16_t height); // Assign region manually - void handleAppletPixel(int16_t x, int16_t y, Color c); // Receive px output from assigned applet - uint16_t getWidth(); // Used to set the assigned applet's width before render - uint16_t getHeight(); // Used to set the assigned applet's height before render + Tile(int16_t left, int16_t top, uint16_t width, uint16_t height); + + void setRegion(uint8_t layoutSize, uint8_t tileIndex); // Assign region automatically, based on layout + void setRegion(int16_t left, int16_t top, uint16_t width, uint16_t height); // Assign region manually + void handleAppletPixel(int16_t x, int16_t y, Color c); // Receive px output from assigned applet + uint16_t getWidth(); + uint16_t getHeight(); static uint16_t maxDisplayDimension(); // Largest possible width / height any tile may ever encounter - void assignApplet(Applet *a); // Place an applet onto a tile - Applet *getAssignedApplet(); // Applet which is on a tile + void assignApplet(Applet *a); // Link an applet with this tile + Applet *getAssignedApplet(); // Applet which is currently linked with this tile void requestHighlight(); // Ask for this tile to be highlighted static void startHighlightTimeout(); // Start the auto-dismissal timer static void cancelHighlightTimeout(); // Cancel the auto-dismissal timer early; already dismissed static Tile *highlightTarget; // Which tile are we highlighting? (Intending to highlight?) - static bool highlightShown; // Is the tile highlighted yet? Controlls highlight vs dismiss + static bool highlightShown; // Is the tile highlighted yet? Controls highlight vs dismiss - protected: - int16_t left; - int16_t top; - uint16_t width; - uint16_t height; + private: + InkHUD *inkhud = nullptr; + + int16_t left = 0; + int16_t top = 0; + uint16_t width = 0; + uint16_t height = 0; Applet *assignedApplet = nullptr; // Pointer to the applet which is currently linked with the tile - - WindowManager *windowManager; // Convenient access to the WindowManager singleton }; } // namespace NicheGraphics::InkHUD diff --git a/src/graphics/niche/InkHUD/Types.h b/src/graphics/niche/InkHUD/Types.h deleted file mode 100644 index f4ab9ed4e..000000000 --- a/src/graphics/niche/InkHUD/Types.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifdef MESHTASTIC_INCLUDE_INKHUD - -/* - -Custom data types for InkHUD - -Only "general purpose" data-types should be defined here. -If your applet has its own structs or enums, which won't be useful to other applets, -please define them inside (or in the same folder as) your applet. - -*/ - -#pragma once - -#include "configuration.h" - -#include "graphics/niche/Drivers/EInk/EInk.h" - -namespace NicheGraphics::InkHUD -{ - -// Color, understood by display controller IC (as bit values) -// Also suitable for use as AdafruitGFX colors -enum Color : uint8_t { - BLACK = 0, - WHITE = 1, -}; - -// Info contained within AppletFont -struct FontDimensions { - uint8_t height; - uint8_t ascenderHeight; - uint8_t descenderHeight; -}; - -// Which edge Applet::printAt will place on the X parameter -enum HorizontalAlignment : uint8_t { - LEFT, - RIGHT, - CENTER, -}; - -// Which edge Applet::printAt will place on the Y parameter -enum VerticalAlignment : uint8_t { - TOP, - MIDDLE, - BOTTOM, -}; - -// An easy-to-understand intepretation of SNR and RSSI -// Calculate with Applet::getSignalStringth -enum SignalStrength : int8_t { - SIGNAL_UNKNOWN = -1, - SIGNAL_NONE, - SIGNAL_BAD, - SIGNAL_FAIR, - SIGNAL_GOOD, -}; - -} // namespace NicheGraphics::InkHUD - -#endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/WindowManager.cpp b/src/graphics/niche/InkHUD/WindowManager.cpp index f987a3646..c883e9a29 100644 --- a/src/graphics/niche/InkHUD/WindowManager.cpp +++ b/src/graphics/niche/InkHUD/WindowManager.cpp @@ -2,11 +2,6 @@ #include "./WindowManager.h" -#include "RTC.h" -#include "mesh/NodeDB.h" - -// System applets -// Must be defined in .cpp to prevent a circular dependency with Applet base class #include "./Applets/System/BatteryIcon/BatteryIconApplet.h" #include "./Applets/System/Logo/LogoApplet.h" #include "./Applets/System/Menu/MenuApplet.h" @@ -14,479 +9,108 @@ #include "./Applets/System/Pairing/PairingApplet.h" #include "./Applets/System/Placeholder/PlaceholderApplet.h" #include "./Applets/System/Tips/TipsApplet.h" +#include "./SystemApplet.h" using namespace NicheGraphics; -InkHUD::WindowManager::WindowManager() : concurrency::OSThread("InkHUD WM") +InkHUD::WindowManager::WindowManager() { - // Nothing for the timer to do just yet - OSThread::disable(); + // Convenient references + inkhud = InkHUD::getInstance(); + settings = &inkhud->persistence->settings; } -// Get or create the WindowManager singleton -InkHUD::WindowManager *InkHUD::WindowManager::getInstance() -{ - // Create the singleton instance of our class, if not yet done - static InkHUD::WindowManager *instance = new InkHUD::WindowManager(); - return instance; -} - -// Connect the driver, which is created independently is setupNicheGraphics() -void InkHUD::WindowManager::setDriver(Drivers::EInk *driver) -{ - // Make sure not already set - if (this->driver) { - LOG_ERROR("Driver already set"); - delay(2000); // Wait for native serial.. - assert(false); - } - - // Store the driver which was created in setupNicheGraphics() - this->driver = driver; - - // Determine the dimensions of the image buffer, in bytes. - // Along rows, pixels are stored 8 per byte. - // Not all display widths are divisible by 8. Need to make sure bytecount accommodates padding for these. - imageBufferWidth = ((driver->width - 1) / 8) + 1; - imageBufferHeight = driver->height; - - // Allocate the image buffer - imageBuffer = new uint8_t[imageBufferWidth * imageBufferHeight]; -} - -// Sets the ideal ratio of FAST updates to FULL updates -// We want as many FAST updates as possible, without causing gradual degradation of the display -// If explicitly requested, number of FAST updates may exceed fastPerFull value. -// In this case, the stressMultiplier is applied, causing the "FULL update debt" to increase by more than normal -// The stressMultplier helps the display recover from particularly taxing periods of use -// (Default arguments of 5,2 are very conservative values) -void InkHUD::WindowManager::setDisplayResilience(uint8_t fastPerFull = 5, float stressMultiplier = 2.0) -{ - mediator.fastPerFull = fastPerFull; - mediator.stressMultiplier = stressMultiplier; -} - -// Register a user applet with the WindowManager +// Register a user applet with InkHUD // This is called in setupNicheGraphics() // This should be the only time that specific user applets are mentioned in the code // If a user applet is not added with this method, its code should not be built +// Call before begin void InkHUD::WindowManager::addApplet(const char *name, Applet *a, bool defaultActive, bool defaultAutoshow, uint8_t onTile) { - userApplets.push_back(a); + inkhud->userApplets.push_back(a); // If requested, mark in settings that this applet should be active by default // This means that it will be available for the user to cycle to with short-press of the button - // This is the default state only: user can activate or deactive applets through the menu. + // This is the default state only: user can activate or deactivate applets through the menu. // User's choice of active applets is stored in settings, and will be honored instead of these defaults, if present if (defaultActive) - settings.userApplets.active[userApplets.size() - 1] = true; + settings->userApplets.active[inkhud->userApplets.size() - 1] = true; // If requested, mark in settings that this applet should "autoshow" by default // This means that the applet will be automatically brought to foreground when it has new data to show // This is the default state only: user can select which applets have this behavior through the menu // User's selection is stored in settings, and will be honored instead of these defaults, if present if (defaultAutoshow) - settings.userApplets.autoshow[userApplets.size() - 1] = true; + settings->userApplets.autoshow[inkhud->userApplets.size() - 1] = true; // If specified, mark this as the default applet for a given tile index // Used only to avoid placeholder applet "out of the box", when default settings have more than one tile if (onTile != (uint8_t)-1) - settings.userTiles.displayedUserApplet[onTile] = userApplets.size() - 1; + settings->userTiles.displayedUserApplet[onTile] = inkhud->userApplets.size() - 1; // The label that will be show in the applet selection menu, on the device a->name = name; } -// Perform initial setup, and begin responding to incoming events -// First task once init is to show the boot screen +// Initial configuration at startup void InkHUD::WindowManager::begin() { - // Make sure we have set a driver - if (!this->driver) { - LOG_ERROR("Driver not set"); - delay(2000); // Wait for native serial.. - assert(false); - } - - loadDataFromFlash(); + assert(inkhud); createSystemApplets(); - createSystemTiles(); placeSystemTiles(); - assignSystemAppletsToTiles(); createUserApplets(); createUserTiles(); placeUserTiles(); assignUserAppletsToTiles(); refocusTile(); - - logoApplet->showBootScreen(); - forceUpdate(Drivers::EInk::FULL, false); // Update now, and wait here until complete - - deepSleepObserver.observe(¬ifyDeepSleep); - rebootObserver.observe(¬ifyReboot); - textMessageObserver.observe(textMessageModule); -#ifdef ARCH_ESP32 - lightSleepObserver.observe(¬ifyLightSleep); -#endif } -// Set-up special "system applets" -// These handle things like bootscreen, pop-up notifications etc -// They are processed separately from the user applets, because they might need to do "weird things" -// They also won't be activated or deactivated -void InkHUD::WindowManager::createSystemApplets() +// Focus on a different tile +// The "focused tile" is the one which cycles applets on user button press, +// and the one where the menu will be displayed +void InkHUD::WindowManager::nextTile() { - logoApplet = new LogoApplet; - pairingApplet = new PairingApplet; - tipsApplet = new TipsApplet; - notificationApplet = new NotificationApplet; - batteryIconApplet = new BatteryIconApplet; - menuApplet = new MenuApplet; - placeholderApplet = new PlaceholderApplet; - - // System applets are always active - logoApplet->activate(); - pairingApplet->activate(); - tipsApplet->activate(); - notificationApplet->activate(); - batteryIconApplet->activate(); - menuApplet->activate(); - placeholderApplet->activate(); - - // Add to the systemApplets vector - // Although system applets often need special handling, sometimes we can process them en-masse with this vector - // e.g. rendering, raising events - // Order of these entries determines Z-Index when rendering - systemApplets.push_back(logoApplet); - systemApplets.push_back(pairingApplet); - systemApplets.push_back(tipsApplet); - systemApplets.push_back(batteryIconApplet); - systemApplets.push_back(menuApplet); - systemApplets.push_back(notificationApplet); - // Note: placeholder applet is technically a system applet, but it renders in WindowManager::renderPlaceholders -} - -void InkHUD::WindowManager::createSystemTiles() -{ - fullscreenTile = new Tile; - notificationTile = new Tile; - batteryIconTile = new Tile; -} - -void InkHUD::WindowManager::placeSystemTiles() -{ - fullscreenTile->placeSystemTile(0, 0, getWidth(), getHeight()); - notificationTile->placeSystemTile(0, 0, getWidth(), 20); // Testing only: constant value - - // Todo: appropriate sizing for the battery icon - const uint16_t batteryIconHeight = Applet::getHeaderHeight() - (2 * 2); - uint16_t batteryIconWidth = batteryIconHeight * 1.8; - - batteryIconTile->placeSystemTile(getWidth() - batteryIconWidth, 2, batteryIconWidth, batteryIconHeight); -} - -// Assign a system applet to the fullscreen tile -// Rendering of user tiles is suspended when the fullscreen tile is occupied -void InkHUD::WindowManager::claimFullscreen(InkHUD::Applet *a) -{ - // Make sure that only system applets use the fullscreen tile - bool isSystemApplet = false; - for (Applet *sa : systemApplets) { - if (sa == a) { - isSystemApplet = true; - break; - } - } - assert(isSystemApplet); - - fullscreenTile->assignApplet(a); -} - -// Clear the fullscreen tile, unlinking whichever system applet is assigned -// This allows the normal rendering of user tiles to resume -void InkHUD::WindowManager::releaseFullscreen() -{ - // Make sure the applet is ready to release the tile - assert(!fullscreenTile->getAssignedApplet()->isForeground()); - - // Break the link between the applet and the fullscreen tile - fullscreenTile->assignApplet(nullptr); -} - -// Some system applets can be assigned to a tile at boot -// These are applets which do have their own tile, and whose assignment never changes -// Applets which: -// - share the fullscreen tile (e.g. logoApplet, pairingApplet), -// - render on user tiles (e.g. menuApplet, placeholderApplet), -// are assigned to the tile only when needed -void InkHUD::WindowManager::assignSystemAppletsToTiles() -{ - notificationTile->assignApplet(notificationApplet); - batteryIconTile->assignApplet(batteryIconApplet); -} - -// Activate or deactivate user applets, to match settings -// Called at boot, or after run-time config changes via menu -// Note: this method does not instantiate the applets; -// this is done in setupNicheGraphics, with WindowManager::addApplet -void InkHUD::WindowManager::createUserApplets() -{ - // Deactivate and remove any no-longer-needed applets - for (uint8_t i = 0; i < userApplets.size(); i++) { - Applet *a = userApplets.at(i); - - // If the applet is active, but settings say it shouldn't be: - // - run applet's custom deactivation code - // - mark applet as inactive (internally) - if (a->isActive() && !settings.userApplets.active[i]) - a->deactivate(); + // Close the menu applet if open + // We don't *really* want to do this, but it simplifies handling *a lot* + MenuApplet *menu = (MenuApplet *)inkhud->getSystemApplet("Menu"); + bool menuWasOpen = false; + if (menu->isForeground()) { + menu->sendToBackground(); + menuWasOpen = true; } - // Activate and add any new applets - for (uint8_t i = 0; i < userApplets.size() && i < MAX_USERAPPLETS_GLOBAL; i++) { + // Swap to next tile + settings->userTiles.focused = (settings->userTiles.focused + 1) % settings->userTiles.count; - // If not activated, but it now should be: - // - run applet's custom activation code - // - mark applet as active (internally) - if (!userApplets.at(i)->isActive() && settings.userApplets.active[i]) - userApplets.at(i)->activate(); - } + // Make sure that we don't get stuck on the placeholder tile + refocusTile(); + + if (menuWasOpen) + menu->show(userTiles.at(settings->userTiles.focused)); + + // Ask the tile to draw an indicator showing which tile is now focused + // Requests a render + // We only draw this indicator if the device uses an aux button to switch tiles. + // Assume aux button is used to switch tiles if the "next tile" menu item is hidden + if (!settings->optionalMenuItems.nextTile) + userTiles.at(settings->userTiles.focused)->requestHighlight(); } -void InkHUD::WindowManager::createUserTiles() +// Show the menu (on the the focused tile) +// The applet previously displayed there will be restored once the menu closes +void InkHUD::WindowManager::openMenu() { - // Delete any tiles which currently exist - for (Tile *t : userTiles) - delete t; - userTiles.clear(); - - // Create new tiles - for (uint8_t i = 0; i < settings.userTiles.count; i++) { - Tile *t = new Tile; - userTiles.push_back(t); - } -} - -void InkHUD::WindowManager::placeUserTiles() -{ - // Calculate the display region occupied by each tile - // This determines how pixels are translated from applet-space to windowmanager-space - for (uint8_t i = 0; i < userTiles.size(); i++) - userTiles.at(i)->placeUserTile(settings.userTiles.count, i); -} - -void InkHUD::WindowManager::assignUserAppletsToTiles() -{ - // Set "assignedApplet" property - // Which applet should be initially shown on a tile? - // This is preserved between reboots, but the value needs validating at startup - for (uint8_t i = 0; i < userTiles.size(); i++) { - Tile *t = userTiles.at(i); - - // Check whether tile can display the previously shown applet again - uint8_t oldIndex = settings.userTiles.displayedUserApplet[i]; // Previous index in WindowManager::userApplets - bool canRestore = true; - if (oldIndex > userApplets.size() - 1) // Check if old index is now out of bounds - canRestore = false; - else if (!settings.userApplets.active[oldIndex]) // Check that old applet is still activated - canRestore = false; - else { // Check that the old applet isn't now shown already on a different tile - for (uint8_t i2 = 0; i2 < i; i2++) { - if (settings.userTiles.displayedUserApplet[i2] == oldIndex) { - canRestore = false; - break; - } - } - } - - // Restore previously shown applet if possible, - // otherwise assign nullptr, which will render specially using placeholderApplet - if (canRestore) { - Applet *a = userApplets.at(oldIndex); - t->assignApplet(a); - a->bringToForeground(); - } else { - t->assignApplet(nullptr); - settings.userTiles.displayedUserApplet[i] = -1; // Update settings: current tile has no valid applet - } - } -} - -void InkHUD::WindowManager::refocusTile() -{ - // Validate "focused tile" setting - // - info: focused tile responds to button presses: applet cycling, menu, etc - // - if number of tiles changed, might now be out of index - if (settings.userTiles.focused >= userTiles.size()) - settings.userTiles.focused = 0; - - // Give "focused tile" a valid applet - // - scan for another valid applet, which we can addSubstitution - // - reason: nextApplet() won't cycle if no applet is assigned - Tile *focusedTile = userTiles.at(settings.userTiles.focused); - if (!focusedTile->getAssignedApplet()) { - // Search for available applets - for (uint8_t i = 0; i < userApplets.size(); i++) { - Applet *a = userApplets.at(i); - if (a->isActive() && !a->isForeground()) { - // Found a suitable applet - // Assign it to the focused tile - focusedTile->assignApplet(a); - a->bringToForeground(); - settings.userTiles.displayedUserApplet[settings.userTiles.focused] = i; // Record change: persist after reboot - break; - } - } - } -} - -// Callback for deepSleepObserver -// Returns 0 to signal that we agree to sleep now -int InkHUD::WindowManager::beforeDeepSleep(void *unused) -{ - // Notify all applets that we're shutting down - for (Applet *ua : userApplets) { - ua->onDeactivate(); - ua->onShutdown(); - } - for (Applet *sa : userApplets) { - // Note: no onDeactivate. System applets are always active. - sa->onShutdown(); - } - - // User has successfull executed a safe shutdown - // We don't need to nag at boot anymore - settings.tips.safeShutdownSeen = true; - - saveDataToFlash(); - - // Display the shutdown screen, and wait here until the update is complete - logoApplet->showShutdownScreen(); - forceUpdate(Drivers::EInk::UpdateTypes::FULL, false); - - return 0; // We agree: deep sleep now -} - -// Callback for rebootObserver -// Same as shutdown, without drawing the logoApplet -// Makes sure we don't lose message history / InkHUD config -int InkHUD::WindowManager::beforeReboot(void *unused) -{ - - // Notify all applets that we're "shutting down" - // They don't need to know that it's really a reboot - for (Applet *a : userApplets) { - a->onDeactivate(); - a->onShutdown(); - } - for (Applet *sa : userApplets) { - // Note: no onDeactivate. System applets are always active. - sa->onShutdown(); - } - - saveDataToFlash(); - - return 0; // No special status to report. Ignored anyway by this Observable -} - -#ifdef ARCH_ESP32 -// Callback for lightSleepObserver -// Make sure the display is not partway through an update when we begin light sleep -// This is because some displays require active input from us to terminate the update process, and protect the panel hardware -int InkHUD::WindowManager::beforeLightSleep(void *unused) -{ - if (driver->busy()) { - LOG_INFO("Waiting for display"); - driver->await(); // Wait here for update to complete - } - - return 0; // No special status to report. Ignored anyway by this Observable -} -#endif - -// Callback when a new text message is received -// Caches the most recently received message, for use by applets -// Rx does not trigger a save to flash, however the data *will* be saved alongside other during shutdown, etc. -// Note: this is different from devicestate.rx_text_message, which may contain an *outgoing* message -int InkHUD::WindowManager::onReceiveTextMessage(const meshtastic_MeshPacket *packet) -{ - // Short circuit: don't store outgoing messages - if (getFrom(packet) == nodeDB->getNodeNum()) - return 0; - - // Short circuit: don't store "emoji reactions" - // Possibly some implemetation of this in future? - if (packet->decoded.emoji) - return 0; - - // Determine whether the message is broadcast or a DM - // Store this info to prevent confusion after a reboot - // Avoids need to compare timestamps, because of situation where "future" messages block newly received, if time not set - latestMessage.wasBroadcast = isBroadcast(packet->to); - - // Pick the appropriate variable to store the message in - MessageStore::Message *storedMessage = latestMessage.wasBroadcast ? &latestMessage.broadcast : &latestMessage.dm; - - // Store nodenum of the sender - // Applets can use this to fetch user data from nodedb, if they want - storedMessage->sender = packet->from; - - // Store the time (epoch seconds) when message received - storedMessage->timestamp = getValidTime(RTCQuality::RTCQualityDevice, true); // Current RTC time - - // Store the channel - // - (potentially) used to determine whether notification shows - // - (potentially) used to determine which applet to focus - storedMessage->channelIndex = packet->channel; - - // Store the text - // Need to specify manually how many bytes, because source not null-terminated - storedMessage->text = - std::string(&packet->decoded.payload.bytes[0], &packet->decoded.payload.bytes[packet->decoded.payload.size]); - - return 0; // Tell caller to continue notifying other observers. (No reason to abort this event) -} - -// Triggered by an input source when a short-press fires -// The input source is a separate component; not part of InkHUD -// It is connected in setupNicheGraphics() -void InkHUD::WindowManager::handleButtonShort() -{ - // If notification is open: close it - if (notificationApplet->isForeground()) { - notificationApplet->dismiss(); - forceUpdate(EInk::UpdateTypes::FULL); // Redraw everything, to clear the notification - } - - // If window manager is locked: lock owner handles button - else if (lockOwner) - lockOwner->onButtonShortPress(); - - // Normally: next applet - else - nextApplet(); -} - -// Triggered by an input source when a long-press fires -// The input source is a separate component; not part of InkHUD -// It is connected in setupNicheGraphics() -// Note: input source should raise this while button still held -void InkHUD::WindowManager::handleButtonLong() -{ - if (lockOwner) - lockOwner->onButtonLongPress(); - - else - menuApplet->show(userTiles.at(settings.userTiles.focused)); + MenuApplet *menu = (MenuApplet *)inkhud->getSystemApplet("Menu"); + menu->show(userTiles.at(settings->userTiles.focused)); } // On the currently focussed tile: cycle to the next available user applet // Applets available for this must be activated, and not already displayed on another tile void InkHUD::WindowManager::nextApplet() { - Tile *t = userTiles.at(settings.userTiles.focused); + Tile *t = userTiles.at(settings->userTiles.focused); // Abort if zero applets available // nullptr means WindowManager::refocusTile determined that there were no available applets @@ -495,8 +119,8 @@ void InkHUD::WindowManager::nextApplet() // Find the index of the applet currently shown on the tile uint8_t appletIndex = -1; - for (uint8_t i = 0; i < userApplets.size(); i++) { - if (userApplets.at(i) == t->getAssignedApplet()) { + for (uint8_t i = 0; i < inkhud->userApplets.size(); i++) { + if (inkhud->userApplets.at(i) == t->getAssignedApplet()) { appletIndex = i; break; } @@ -507,15 +131,14 @@ void InkHUD::WindowManager::nextApplet() // Iterate forward through the WindowManager::applets, looking for the next valid applet Applet *nextValidApplet = nullptr; - // for (uint8_t i = (appletIndex + 1) % applets.size(); i != appletIndex; i = (i + 1) % applets.size()) { - for (uint8_t i = 1; i < userApplets.size(); i++) { - uint8_t newAppletIndex = (appletIndex + i) % userApplets.size(); - Applet *a = userApplets.at(newAppletIndex); + for (uint8_t i = 1; i < inkhud->userApplets.size(); i++) { + uint8_t newAppletIndex = (appletIndex + i) % inkhud->userApplets.size(); + Applet *a = inkhud->userApplets.at(newAppletIndex); // Looking for an applet which is active (enabled by user), but currently in background if (a->isActive() && !a->isForeground()) { nextValidApplet = a; - settings.userTiles.displayedUserApplet[settings.userTiles.focused] = + settings->userTiles.displayedUserApplet[settings->userTiles.focused] = newAppletIndex; // Remember this setting between boots! break; } @@ -529,35 +152,33 @@ void InkHUD::WindowManager::nextApplet() t->getAssignedApplet()->sendToBackground(); t->assignApplet(nextValidApplet); nextValidApplet->bringToForeground(); - forceUpdate(EInk::UpdateTypes::FAST); // bringToForeground already requested, but we're manually forcing FAST + inkhud->forceUpdate(EInk::UpdateTypes::FAST); // bringToForeground already requested, but we're manually forcing FAST } -// Focus on a different tile -// The "focused tile" is the one which cycles applets on user button press, -// and the one where the menu will be displayed -// Note: this method is only used by an aux button -// The menuApplet manually performs a subset of these actions, to avoid disturbing the stale image on adjacent tiles -void InkHUD::WindowManager::nextTile() +// Rotate the display image by 90 degrees +void InkHUD::WindowManager::rotate() { - // Close the menu applet if open - // We done *really* want to do this, but it simplifies handling *a lot* - if (menuApplet->isForeground()) - menuApplet->sendToBackground(); - - // Seems like some system applet other than menu is open. Pairing? Booting? - if (!canRequestUpdate()) - return; - - // Swap to next tile - settings.userTiles.focused = (settings.userTiles.focused + 1) % settings.userTiles.count; - - // Make sure that we don't get stuck on the placeholder tile - // changeLayout reassigns applets to tiles + settings->rotation = (settings->rotation + 1) % 4; changeLayout(); +} - // Ask the tile to draw an indicator showing which tile is now focused - // Requests a render - userTiles.at(settings.userTiles.focused)->requestHighlight(); +// Change whether the battery icon is displayed (top right corner) +// Don't toggle the OptionalFeatures value before calling this, our method handles it internally +void InkHUD::WindowManager::toggleBatteryIcon() +{ + BatteryIconApplet *batteryIcon = (BatteryIconApplet *)inkhud->getSystemApplet("BatteryIcon"); + + settings->optionalFeatures.batteryIcon = !settings->optionalFeatures.batteryIcon; // Preserve the change between boots + + // Show or hide the applet + if (settings->optionalFeatures.batteryIcon) + batteryIcon->bringToForeground(); + else + batteryIcon->sendToBackground(); + + // Force-render + // - redraw all applets + inkhud->forceUpdate(EInk::UpdateTypes::FAST); } // Perform necessary reconfiguration when user changes number of tiles (or rotation) at run-time @@ -589,21 +210,24 @@ void InkHUD::WindowManager::changeLayout() // Restore menu // - its tile was just destroyed and recreated (createUserTiles) // - its assignment was cleared (assignUserAppletsToTiles) - if (menuApplet->isForeground()) { - Tile *ft = userTiles.at(settings.userTiles.focused); - menuApplet->show(ft); + MenuApplet *menu = (MenuApplet *)inkhud->getSystemApplet("Menu"); + if (menu->isForeground()) { + Tile *ft = userTiles.at(settings->userTiles.focused); + menu->show(ft); } // Force-render // - redraw all applets - forceUpdate(EInk::UpdateTypes::FAST); + inkhud->forceUpdate(EInk::UpdateTypes::FAST); } // Perform necessary reconfiguration when user activates or deactivates applets at run-time // Call after changing settings.userApplets.active void InkHUD::WindowManager::changeActivatedApplets() { - assert(menuApplet->isForeground()); + MenuApplet *menu = (MenuApplet *)inkhud->getSystemApplet("Menu"); + + assert(menu->isForeground()); // Activate or deactivate applets // - to match value of settings.userApplets.active @@ -621,223 +245,41 @@ void InkHUD::WindowManager::changeActivatedApplets() // Restore menu // - its assignment was cleared (assignUserAppletsToTiles) - if (menuApplet->isForeground()) { - Tile *ft = userTiles.at(settings.userTiles.focused); - menuApplet->show(ft); + if (menu->isForeground()) { + Tile *ft = userTiles.at(settings->userTiles.focused); + menu->show(ft); } // Force-render // - redraw all applets - forceUpdate(EInk::UpdateTypes::FAST); + inkhud->forceUpdate(EInk::UpdateTypes::FAST); } -// Change whether the battery icon is displayed (top left corner) -// Don't toggle the OptionalFeatures value before calling this, our method handles it internally -void InkHUD::WindowManager::toggleBatteryIcon() -{ - assert(batteryIconApplet->isActive()); - settings.optionalFeatures.batteryIcon = !settings.optionalFeatures.batteryIcon; // Preserve the change between boots - - // Show or hide the applet - if (settings.optionalFeatures.batteryIcon) - batteryIconApplet->bringToForeground(); - else - batteryIconApplet->sendToBackground(); - - // Force-render - // - redraw all applets - forceUpdate(EInk::UpdateTypes::FAST); -} - -// Allow applets to suppress notifications -// Applets will be asked whether they approve, before a notification is shown via the NotificationApplet -// An applet might want to suppress a notification if the applet itself already displays this info -// Example: AllMessageApplet should not approve notifications for messages, if it is in foreground -bool InkHUD::WindowManager::approveNotification(InkHUD::Notification &n) -{ - // Ask all currently displayed applets - for (Tile *ut : userTiles) { - Applet *ua = ut->getAssignedApplet(); - if (ua && !ua->approveNotification(n)) - return false; - } - - // Nobody objected - return true; -} - -// Set a flag, which will be picked up by runOnce, ASAP. -// Quite likely, multiple applets will all want to respond to one event (Observable, etc) -// Each affected applet can independently call requestUpdate(), and all share the one opportunity to render, at next runOnce -void InkHUD::WindowManager::requestUpdate() -{ - requestingUpdate = true; - - // We will run the thread as soon as we loop(), - // after all Applets have had a chance to observe whatever event set this off - OSThread::setIntervalFromNow(0); - OSThread::enabled = true; - runASAP = true; -} - -// requestUpdate will not actually update if no requests were made by applets which are actually visible -// This can occur, because applets requestUpdate even from the background, -// in case the user's autoshow settings permit them to be moved to foreground. -// Sometimes, however, we will want to trigger a display update manually, in the absense of any sort of applet event -// Display health, for example. -// In these situations, we use forceUpdate -void InkHUD::WindowManager::forceUpdate(EInk::UpdateTypes type, bool async) -{ - requestingUpdate = true; - forcingUpdate = true; - forcedUpdateType = type; - - // Normally, we need to start the timer, in case the display is busy and we briefly defer the update - if (async) { - // We will run the thread as soon as we loop(), - // after all Applets have had a chance to observe whatever event set this off - OSThread::setIntervalFromNow(0); - OSThread::enabled = true; - runASAP = true; - } - - // If the update is *not* asynchronous, we begin the render process directly here - // so that it can block code flow while running - else - render(false); -} - -// Receives rendered image data from an Applet, via a tile -// When applets render, they output pixel data relative to their own left / top edges -// They pass this pixel data to tile, which offsets the pixels, making them relative to the display left / top edges -// That data is then passed to this method, which applies any rotation, then places the pixels into the image buffer -// That image buffer is the fully-formatted data handed off to the driver -void InkHUD::WindowManager::handleTilePixel(int16_t x, int16_t y, Color c) -{ - rotatePixelCoords(&x, &y); - setBufferPixel(x, y, c); -} - -// Width of the display, relative to rotation -uint16_t InkHUD::WindowManager::getWidth() -{ - if (settings.rotation % 2) - return driver->height; - else - return driver->width; -} - -// Height of the display, relative to rotation -uint16_t InkHUD::WindowManager::getHeight() -{ - if (settings.rotation % 2) - return driver->width; - else - return driver->height; -} - -// How many user applets have been built? Includes applets which have been inactivated by user config -uint8_t InkHUD::WindowManager::getAppletCount() -{ - return userApplets.size(); -} - -// A tidy title for applets: used on-display in some situations -// Index is the order in the WindowManager::userApplets vector -// This is the same order that applets were added in setupNicheGraphics -const char *InkHUD::WindowManager::getAppletName(uint8_t index) -{ - return userApplets.at(index)->name; -} - -// Allows a system applet to prevent other applets from temporarily requesting updates -// All user applets will honor this. Some system applets might not, although they probably should -// WindowManager::forceUpdate will ignore this lock -void InkHUD::WindowManager::lock(Applet *owner) -{ - // Only one system applet may lock render at once - assert(!lockOwner); - - // Only system applets may lock rendering - for (Applet *a : userApplets) - assert(owner != a); - - lockOwner = owner; -} - -// Remove a lock placed by a system applet, which prevents other applets from rendering -void InkHUD::WindowManager::unlock(Applet *owner) -{ - assert(lockOwner = owner); - lockOwner = nullptr; - - // Raise this as an event (system applets only) - // - in case applet waiting for lock - // - in case applet relinquished its lock earlier, and wants it back - for (Applet *sa : systemApplets) { - // Don't raise event for the applet which is calling unlock - // - avoid loop of unlock->lock (some implementations of Applet::onLockAvailable) - if (sa != owner) - sa->onLockAvailable(); - } -} - -// Is an applet blocked from requesting update by a current lock? -// Applets are allowed to request updates if there is no lock, or if they are the owner of the lock -// If a == nullptr, checks permission "for everyone and anyone" -bool InkHUD::WindowManager::canRequestUpdate(Applet *a) -{ - if (!lockOwner) - return true; - else if (lockOwner == a) - return true; - else - return false; -} - -// Get the applet which is currently locking rendering -// We might be able to convince it release its lock, if we want it instead -InkHUD::Applet *InkHUD::WindowManager::whoLocked() -{ - return WindowManager::lockOwner; -} - -// Runs at regular intervals -// WindowManager's uses of this include: -// - postponing render: until next loop(), allowing all applets to be notified of some Mesh event before render -// - queuing another render: while one is already is progress -int32_t InkHUD::WindowManager::runOnce() -{ - // If an applet asked to render, and hardware is able, lets try now - if (requestingUpdate && !driver->busy()) { - render(); - } - - // If our render() call failed, try again shortly - // otherwise, stop our thread until next update due - if (requestingUpdate) - return 250UL; - else - return OSThread::disable(); -} - -// Some applets may be permitted to bring themselved to foreground, to show new data +// Some applets may be permitted to bring themselves to foreground, to show new data // User selects which applets have this permission via on-screen menu // Priority is determined by the order which applets were added to WindowManager in setupNicheGraphics // We will only autoshow one applet void InkHUD::WindowManager::autoshow() { - for (uint8_t i = 0; i < userApplets.size(); i++) { - Applet *a = userApplets.at(i); - if (a->wantsToAutoshow() // Applet wants to become foreground - && !a->isForeground() // Not yet foreground - && settings.userApplets.autoshow[i] // User permits this applet to autoshow - && canRequestUpdate()) // Updates not currently blocked by system applet + // Don't perform autoshow if a system applet has exclusive use of the display right now + // Note: lockRequests prevents autoshow attempting to hide menuApplet + for (SystemApplet *sa : inkhud->systemApplets) { + if (sa->lockRendering || sa->lockRequests) + return; + } + + NotificationApplet *notificationApplet = (NotificationApplet *)inkhud->getSystemApplet("Notification"); + + for (uint8_t i = 0; i < inkhud->userApplets.size(); i++) { + Applet *a = inkhud->userApplets.at(i); + if (a->wantsToAutoshow() // Applet wants to become foreground + && !a->isForeground() // Not yet foreground + && settings->userApplets.autoshow[i]) // User permits this applet to autoshow { - Tile *t = userTiles.at(settings.userTiles.focused); // Get focused tile - t->getAssignedApplet()->sendToBackground(); // Background whichever applet is already on the tile - t->assignApplet(a); // Assign our new applet to tile - a->bringToForeground(); // Foreground our new applet + Tile *t = userTiles.at(settings->userTiles.focused); // Get focused tile + t->getAssignedApplet()->sendToBackground(); // Background whichever applet is already on the tile + t->assignApplet(a); // Assign our new applet to tile + a->bringToForeground(); // Foreground our new applet // Check if autoshown applet shows the same information as notification intended to // In this case, we can dismiss the notification before it is shown @@ -850,257 +292,220 @@ void InkHUD::WindowManager::autoshow() } } -// Check whether an update is justified -// We usually require that a foreground applet requested the update, -// but forceUpdate call will bypass these checks. -// Abstraction for WindowManager::render only -bool InkHUD::WindowManager::shouldUpdate() +// A collection of any user tiles which do not have a valid user applet +// This can occur in various situations, such as when a user enables fewer applets than their layout has tiles +// The tiles (and which regions the occupy) are private information of the window manager +// The renderer needs to know which regions (if any) are empty, +// in order to fill them with a "placeholder" pattern. +// -- There may be a tidier way to accomplish this -- +std::vector InkHUD::WindowManager::getEmptyTiles() { - bool should = false; + std::vector empty; - // via forceUpdate - should |= forcingUpdate; - - // via user applet - for (Tile *ut : userTiles) { - Applet *ua = ut->getAssignedApplet(); - if (ua // Tile has valid applet - && ua->wantsToRender() // This applet requested display update - && ua->isForeground() // This applet is currently shown - && canRequestUpdate()) // Requests are not currently locked - { - should = true; - break; - } + for (Tile *t : userTiles) { + Applet *a = t->getAssignedApplet(); + if (!a || !a->isActive()) + empty.push_back(t); } - // via system applet - for (Applet *sa : systemApplets) { - if (sa->wantsToRender() // This applet requested - && sa->isForeground() // This applet is currently shown - && canRequestUpdate(sa)) // Requests are not currently locked, or this applet owns the lock - { - should = true; - break; - } - } - - return should; + return empty; } -// Determine which type of E-Ink update the display will perform, to change the image. -// Considers the needs of the various applets, then weighs against display health. -// An update type specified by forceUpdate will be granted with no further questioning. -// Abstraction for WindowManager::render only -Drivers::EInk::UpdateTypes InkHUD::WindowManager::selectUpdateType() +// Complete the configuration of one newly instantiated system applet +// - link it with its tile +// Unlike user applets, most system applets have their own unique tile; +// the only reference to this tile is held by the system applet itself. +// - give it a name +// A system applet's name is its unique identifier. +// The name is our only reference to specific system applets, via InkHUD->getSystemApplet +// - add it to the list of system applets + +void InkHUD::WindowManager::addSystemApplet(const char *name, SystemApplet *applet, Tile *tile) { - // Ask applets which update type they would prefer - // Some update types take priority over others - EInk::UpdateTypes type = EInk::UpdateTypes::UNSPECIFIED; - if (forcingUpdate) { - // Update type was manually specified via forceUpdate - type = forcedUpdateType; - } else { - // User applets - for (Tile *ut : userTiles) { - Applet *ua = ut->getAssignedApplet(); - if (ua && ua->isForeground() && canRequestUpdate()) - type = mediator.prioritize(type, ua->wantsUpdateType()); - } - // System Applets - for (Applet *sa : systemApplets) { - if (sa->isForeground() && canRequestUpdate(sa)) - type = mediator.prioritize(type, sa->wantsUpdateType()); - } - } + // Some system applets might not have their own tile (e.g. menu, placeholder) + if (tile) + tile->assignApplet(applet); - // Tell the mediator what update type the applets deciced on, - // find out what update type the mediator will actually allow us to have - type = mediator.evaluate(type); - - return type; + applet->name = name; + inkhud->systemApplets.push_back(applet); } -// Run the drawing operations of any user applets which are currently displayed -// Pixel output is placed into the framebuffer, ready for handoff to the EInk driver -// Abstraction for WindowManager::render only -void InkHUD::WindowManager::renderUserApplets() +// Create the "system applets" +// These handle things like bootscreen, pop-up notifications etc +// They are processed separately from the user applets, because they might need to do "weird things" +void InkHUD::WindowManager::createSystemApplets() { - // Don't render any user applets if the screen is covered by a system applet using the fullscreen tile - if (fullscreenTile->getAssignedApplet()) - return; + addSystemApplet("Logo", new LogoApplet, new Tile); + addSystemApplet("Pairing", new PairingApplet, new Tile); + addSystemApplet("Tips", new TipsApplet, new Tile); - // For each tile - for (Tile *ut : userTiles) { - Applet *ua = ut->getAssignedApplet(); // Get the applet on the tile + addSystemApplet("Menu", new MenuApplet, nullptr); - // Don't render if tile has no applet. Handled in renderPlaceholders - if (!ua) - continue; + // Battery and notifications *behind* the menu + addSystemApplet("Notification", new NotificationApplet, new Tile); + addSystemApplet("BatteryIcon", new BatteryIconApplet, new Tile); - // Don't render the menu applet, Handled by renderSystemApplets - if (ua == menuApplet) - continue; + // Special handling only, via Rendering::renderPlaceholders + addSystemApplet("Placeholder", new PlaceholderApplet, nullptr); - uint32_t start = millis(); - ua->render(); // Draw! - uint32_t stop = millis(); - LOG_DEBUG("%s took %dms to render", ua->name, stop - start); + // System applets are always active + for (SystemApplet *sa : inkhud->systemApplets) + sa->activate(); +} + +// Set the position and size of most system applets +// Most system applets have their own tile. We manually set the region this tile occupies +void InkHUD::WindowManager::placeSystemTiles() +{ + inkhud->getSystemApplet("Logo")->getTile()->setRegion(0, 0, inkhud->width(), inkhud->height()); + inkhud->getSystemApplet("Pairing")->getTile()->setRegion(0, 0, inkhud->width(), inkhud->height()); + inkhud->getSystemApplet("Tips")->getTile()->setRegion(0, 0, inkhud->width(), inkhud->height()); + + inkhud->getSystemApplet("Notification")->getTile()->setRegion(0, 0, inkhud->width(), 20); + + const uint16_t batteryIconHeight = Applet::getHeaderHeight() - 2 - 2; + const uint16_t batteryIconWidth = batteryIconHeight * 1.8; + inkhud->getSystemApplet("BatteryIcon") + ->getTile() + ->setRegion(inkhud->width() - batteryIconWidth, // x + 2, // y + batteryIconWidth, // width + batteryIconHeight); // height + + // Note: the tiles of placeholder and menu applets are manipulated specially + // - menuApplet borrows user tiles + // - placeholder applet is temporarily assigned to each user tile of WindowManager::getEmptyTiles +} + +// Activate or deactivate user applets, to match settings +// Called at boot, or after run-time config changes via menu +// Note: this method does not instantiate the applets; +// this is done in setupNicheGraphics, when passing to InkHUD::addApplet +void InkHUD::WindowManager::createUserApplets() +{ + // Deactivate and remove any no-longer-needed applets + for (uint8_t i = 0; i < inkhud->userApplets.size(); i++) { + Applet *a = inkhud->userApplets.at(i); + + // If the applet is active, but settings say it shouldn't be: + // - run applet's custom deactivation code + // - mark applet as inactive (internally) + if (a->isActive() && !settings->userApplets.active[i]) + a->deactivate(); + } + + // Activate and add any new applets + for (uint8_t i = 0; i < inkhud->userApplets.size(); i++) { + + // If not activated, but it now should be: + // - run applet's custom activation code + // - mark applet as active (internally) + if (!inkhud->userApplets.at(i)->isActive() && settings->userApplets.active[i]) + inkhud->userApplets.at(i)->activate(); } } -// Run the drawing operations of any system applets which are currently displayed -// Pixel output is placed into the framebuffer, ready for handoff to the EInk driver -// Abstraction for WindowManager::render only -void InkHUD::WindowManager::renderSystemApplets() +// Creates the tiles which will host user applets +// The amount of these is controlled by the user, via "layout" option in the InkHUD menu +void InkHUD::WindowManager::createUserTiles() { - // Each system applet - for (Applet *sa : systemApplets) { - // Skip if not shown - if (!sa->isForeground()) - continue; + // Delete any tiles which currently exist + for (Tile *t : userTiles) + delete t; + userTiles.clear(); - // Don't draw the battery overtop the menu - // Todo: smarter way to handle this - if (sa == batteryIconApplet && menuApplet->isForeground()) - continue; - - // Skip applet if fullscreen tile is in use, but not used by this applet - // Applet is "obscured" - if (fullscreenTile->getAssignedApplet() && fullscreenTile->getAssignedApplet() != sa) - continue; - - // uint32_t start = millis(); // Debugging only: runtime - sa->render(); // Draw! - // uint32_t stop = millis(); // Debugging only: runtime - // LOG_DEBUG("%s (system) took %dms to render", (sa->name == nullptr) ? "Unnamed" : sa->name, stop - start); + // Create new tiles + for (uint8_t i = 0; i < settings->userTiles.count; i++) { + Tile *t = new Tile; + userTiles.push_back(t); } } -// In some situations (e.g. layout or applet selection changes), -// a user tile can end up without an assigned applet. -// In this case, we will fill the empty space with diagonal lines. -void InkHUD::WindowManager::renderPlaceholders() +// Calculate the display region occupied by each tile +// This determines how pixels are translated from "relative" applet-space to "absolute" windowmanager-space +// The size and position depend on the amount of tiles the user prefers, set by the "layout" option +void InkHUD::WindowManager::placeUserTiles() { - // Don't draw if obscured by the fullscreen tile - if (fullscreenTile->getAssignedApplet()) - return; + for (uint8_t i = 0; i < userTiles.size(); i++) + userTiles.at(i)->setRegion(settings->userTiles.count, i); +} - for (Tile *ut : userTiles) { - // If no applet assigned - if (!ut->getAssignedApplet()) { - ut->assignApplet(placeholderApplet); - placeholderApplet->render(); - ut->assignApplet(nullptr); +// Link "foreground" user applets with tiles +// Which applet should be *initially* shown on a tile? +// This initial state changes once WindowManager::nextApplet is called. +// Performed at startup, or during certain run-time reconfigurations (e.g number of tiles) +// This state of "which applets are foreground" is preserved between reboots, but the value needs validating at startup. +void InkHUD::WindowManager::assignUserAppletsToTiles() +{ + // Each user tile + for (uint8_t i = 0; i < userTiles.size(); i++) { + Tile *t = userTiles.at(i); + + // Check whether tile can display the previously shown applet again + uint8_t oldIndex = settings->userTiles.displayedUserApplet[i]; // Previous index in WindowManager::userApplets + bool canRestore = true; + if (oldIndex > inkhud->userApplets.size() - 1) // Check if old index is now out of bounds + canRestore = false; + else if (!settings->userApplets.active[oldIndex]) // Check that old applet is still activated + canRestore = false; + else { // Check that the old applet isn't now shown already on a different tile + for (uint8_t i2 = 0; i2 < i; i2++) { + if (settings->userTiles.displayedUserApplet[i2] == oldIndex) { + canRestore = false; + break; + } + } + } + + // Restore previously shown applet if possible, + // otherwise assign nullptr, which will render specially using placeholderApplet + if (canRestore) { + Applet *a = inkhud->userApplets.at(oldIndex); + t->assignApplet(a); + a->bringToForeground(); + } else { + t->assignApplet(nullptr); + settings->userTiles.displayedUserApplet[i] = -1; // Update settings: current tile has no valid applet } } } -// Make an attempt to gather image data from some / all applets, and update the display -// Might not be possible right now, if update already is progress. -void InkHUD::WindowManager::render(bool async) +// During layout changes, our focused tile setting can become invalid +// This method identifies that situation and corrects for it +void InkHUD::WindowManager::refocusTile() { - // Make sure the display is ready for a new update - if (async) { - // Previous update still running, Will try again shortly, via runOnce() - if (driver->busy()) - return; - } else { - // Wait here for previous update to complete - driver->await(); + // Validate "focused tile" setting + // - info: focused tile responds to button presses: applet cycling, menu, etc + // - if number of tiles changed, might now be out of index + if (settings->userTiles.focused >= userTiles.size()) + settings->userTiles.focused = 0; + + // Give "focused tile" a valid applet + // - scan for another valid applet, which we can addSubstitution + // - reason: nextApplet() won't cycle if no applet is assigned + Tile *focusedTile = userTiles.at(settings->userTiles.focused); + if (!focusedTile->getAssignedApplet()) { + // Search for available applets + for (uint8_t i = 0; i < inkhud->userApplets.size(); i++) { + Applet *a = inkhud->userApplets.at(i); + if (a->isActive() && !a->isForeground()) { + // Found a suitable applet + // Assign it to the focused tile + focusedTile->assignApplet(a); + a->bringToForeground(); + settings->userTiles.displayedUserApplet[settings->userTiles.focused] = i; // Record change: persist after reboot + break; + } + } } - - // (Potentially) change applet to display new info, - // then check if this newly displayed applet makes a pending notification redundant - autoshow(); - - // If an update is justified. - // We don't know this until after autoshow has run, as new applets may now be in foreground - if (shouldUpdate()) { - - // Decide which technique the display will use to change image - EInk::UpdateTypes updateType = selectUpdateType(); - - // Render the new image - clearBuffer(); - renderUserApplets(); - renderSystemApplets(); - renderPlaceholders(); - - // Tell display to begin process of drawing new image - LOG_INFO("Updating display"); - driver->update(imageBuffer, updateType); - - // If not async, wait here until the update is complete - if (!async) - driver->await(); - } else - LOG_DEBUG("Not updating display"); - - // Our part is done now. - // If update is async, the display hardware is still performing the update process, - // but that's all handled by NicheGraphics::Drivers::EInk - - // Tidy up, ready for a new request - requestingUpdate = false; - forcingUpdate = false; - forcedUpdateType = EInk::UpdateTypes::UNSPECIFIED; -} - -// Set a ready-to-draw pixel into the image buffer -// All rotations / translations have already taken place: this buffer data is formatted ready for the driver -void InkHUD::WindowManager::setBufferPixel(int16_t x, int16_t y, Color c) -{ - uint32_t byteNum = (y * imageBufferWidth) + (x / 8); // X data is 8 pixels per byte - uint8_t bitNum = 7 - (x % 8); // Invert order: leftmost bit (most significant) is leftmost pixel of byte. - - bitWrite(imageBuffer[byteNum], bitNum, c); -} - -// Applies the system-wide rotation to pixel positions -// This step is applied to image data which has already been translated by a Tile object -// This is the final step before the pixel is placed into the image buffer -// No return: values of the *x and *y parameters are modified by the method -void InkHUD::WindowManager::rotatePixelCoords(int16_t *x, int16_t *y) -{ - // Apply a global rotation to pixel locations - int16_t x1 = 0; - int16_t y1 = 0; - switch (settings.rotation) { - case 0: - x1 = *x; - y1 = *y; - break; - case 1: - x1 = (driver->width - 1) - *y; - y1 = *x; - break; - case 2: - x1 = (driver->width - 1) - *x; - y1 = (driver->height - 1) - *y; - break; - case 3: - x1 = *y; - y1 = (driver->height - 1) - *x; - break; - } - *x = x1; - *y = y1; -} - -// Manually fill the image buffer with WHITE -// Clears any old drawing -void InkHUD::WindowManager::clearBuffer() -{ - memset(imageBuffer, 0xFF, imageBufferHeight * imageBufferWidth); } // Seach for any applets which believe they are foreground, but no longer have a valid tile // Tidies up after layout changes at runtime void InkHUD::WindowManager::findOrphanApplets() { - for (uint8_t ia = 0; ia < userApplets.size(); ia++) { - Applet *a = userApplets.at(ia); + for (uint8_t ia = 0; ia < inkhud->userApplets.size(); ia++) { + Applet *a = inkhud->userApplets.at(ia); // Applet doesn't believe it is displayed: not orphaned if (!a->isForeground()) diff --git a/src/graphics/niche/InkHUD/WindowManager.h b/src/graphics/niche/InkHUD/WindowManager.h index f701233e2..4d1aedf1b 100644 --- a/src/graphics/niche/InkHUD/WindowManager.h +++ b/src/graphics/niche/InkHUD/WindowManager.h @@ -2,13 +2,7 @@ /* - Singleton class, which manages the broadest InkHUD behaviors - - Tasks include: - - containing instances of Tiles and Applets - - co-ordinating display updates - - interacting with other NicheGraphics componets, such as the driver, and input sources - - handling system-wide events (e.g. shutdown) +Responsible for managing which applets are shown, and their sizes / positions */ @@ -16,48 +10,47 @@ #include "configuration.h" -#include - -#include "main.h" -#include "modules/TextMessageModule.h" -#include "power.h" -#include "sleep.h" - -#include "./Applet.h" -#include "./Applets/System/Notification/Notification.h" +#include "./Applets/System/Notification/Notification.h" // The notification object, not the applet +#include "./InkHUD.h" #include "./Persistence.h" #include "./Tile.h" -#include "./Types.h" -#include "./UpdateMediator.h" -#include "graphics/niche/Drivers/EInk/EInk.h" namespace NicheGraphics::InkHUD { -class Applet; -class Tile; - -class LogoApplet; -class MenuApplet; -class NotificationApplet; - -class WindowManager : protected concurrency::OSThread +class WindowManager { public: - static WindowManager *getInstance(); // Get or create singleton instance + WindowManager(); + void addApplet(const char *name, Applet *a, bool defaultActive, bool defaultAutoshow, uint8_t onTile); + void begin(); - void setDriver(NicheGraphics::Drivers::EInk *driver); // Assign a driver class - void setDisplayResilience(uint8_t fastPerFull, float stressMultiplier); // How many FAST updates before FULL - void addApplet(const char *name, Applet *a, bool defaultActive = false, bool defaultAutoshow = false, - uint8_t onTile = -1); // Select which applets are used with InkHUD - void begin(); // Start running the window manager (provisioning done) + // - call these to make stuff change - void createSystemApplets(); // Instantiate and activate system applets - void createSystemTiles(); // Instantiate tiles which host system applets - void assignSystemAppletsToTiles(); - void placeSystemTiles(); // Set position and size - void claimFullscreen(Applet *sa); // Assign a system applet to the fullscreen tile - void releaseFullscreen(); // Remove any system applet from the fullscreen tile + void nextTile(); + void openMenu(); + void nextApplet(); + void rotate(); + void toggleBatteryIcon(); + + // - call these to manifest changes already made to the relevant Persistence::Settings values + + void changeLayout(); // Change tile layout or count + void changeActivatedApplets(); // Change which applets are activated + + // - called during the rendering operation + + void autoshow(); // Show a different applet, to display new info + std::vector getEmptyTiles(); // Any user tiles without a valid applet + + private: + // Steps for configuring (or reconfiguring) the window manager + // - all steps required at startup + // - various combinations of steps required for on-the-fly reconfiguration (by user, via menu) + + void addSystemApplet(const char *name, SystemApplet *applet, Tile *tile); + void createSystemApplets(); // Instantiate the system applets + void placeSystemTiles(); // Assign manual positions to (most) system applets void createUserApplets(); // Activate user's selected applets void createUserTiles(); // Instantiate enough tiles for user's selected layout @@ -65,113 +58,15 @@ class WindowManager : protected concurrency::OSThread void placeUserTiles(); // Automatically place tiles, according to user's layout void refocusTile(); // Ensure focused tile has a valid applet - int beforeDeepSleep(void *unused); // Prepare for shutdown - int beforeReboot(void *unused); // Prepare for reboot - int onReceiveTextMessage(const meshtastic_MeshPacket *packet); // Store most recent text message -#ifdef ARCH_ESP32 - int beforeLightSleep(void *unused); // Prepare for light sleep -#endif - - void handleButtonShort(); // User button: short press - void handleButtonLong(); // User button: long press - - void nextApplet(); // Cycle through user applets - void nextTile(); // Focus the next tile (when showing multiple applets at once) - - void changeLayout(); // Change tile layout or count - void changeActivatedApplets(); // Change which applets are activated - void toggleBatteryIcon(); // Change whether the battery icon is shown - bool approveNotification(Notification &n); // Ask applets if a notification is worth showing - - void handleTilePixel(int16_t x, int16_t y, Color c); // Apply rotation, then store the pixel in framebuffer - void requestUpdate(); // Update display, if a foreground applet has info it wants to show - void forceUpdate(Drivers::EInk::UpdateTypes type = Drivers::EInk::UpdateTypes::UNSPECIFIED, - bool async = true); // Update display, regardless of whether any applets requested this - - uint16_t getWidth(); // Display width, relative to rotation - uint16_t getHeight(); // Display height, relative to rotation - uint8_t getAppletCount(); // How many user applets are available, including inactivated - const char *getAppletName(uint8_t index); // By order in userApplets - - void lock(Applet *owner); // Allows system applets to prevent other applets triggering a refresh - void unlock(Applet *owner); // Allows normal updating of user applets to continue - bool canRequestUpdate(Applet *a = nullptr); // Checks if allowed to request an update (not locked by other applet) - Applet *whoLocked(); // Find which applet is blocking update requests, if any - - protected: - WindowManager(); // Private constructor for singleton - - int32_t runOnce() override; - - void clearBuffer(); // Empty the framebuffer - void autoshow(); // Show a different applet, to display new info - bool shouldUpdate(); // Check if reason to change display image - Drivers::EInk::UpdateTypes selectUpdateType(); // Determine how the display hardware will perform the image update - void renderUserApplets(); // Draw all currently displayed user applets to the frame buffer - void renderSystemApplets(); // Draw all currently displayed system applets to the frame buffer - void renderPlaceholders(); // Draw diagonal lines on user tiles which have no assigned applet - void render(bool async = true); // Attempt to update the display - - void setBufferPixel(int16_t x, int16_t y, Color c); // Place pixels into the frame buffer. All translation / rotation done. - void rotatePixelCoords(int16_t *x, int16_t *y); // Apply the display rotation - void findOrphanApplets(); // Find any applets left-behind when layout changes - // Get notified when the system is shutting down - CallbackObserver deepSleepObserver = - CallbackObserver(this, &WindowManager::beforeDeepSleep); + std::vector userTiles; // Tiles which can host user applets - // Get notified when the system is rebooting - CallbackObserver rebootObserver = - CallbackObserver(this, &WindowManager::beforeReboot); - - // Cache *incoming* text messages, for use by applets - CallbackObserver textMessageObserver = - CallbackObserver(this, &WindowManager::onReceiveTextMessage); - -#ifdef ARCH_ESP32 - // Get notified when the system is entering light sleep - CallbackObserver lightSleepObserver = - CallbackObserver(this, &WindowManager::beforeLightSleep); -#endif - - NicheGraphics::Drivers::EInk *driver = nullptr; - uint8_t *imageBuffer; // Fed into driver - uint16_t imageBufferHeight; - uint16_t imageBufferWidth; - uint32_t imageBufferSize; // Bytes - - // Encapsulates decision making about E-Ink update types - // Responsible for display health - UpdateMediator mediator; - - // User Applets - std::vector userApplets; - std::vector userTiles; - - // System Applets - std::vector systemApplets; - Tile *fullscreenTile = nullptr; - Tile *notificationTile = nullptr; - Tile *batteryIconTile = nullptr; - LogoApplet *logoApplet; - Applet *pairingApplet; - Applet *tipsApplet; - NotificationApplet *notificationApplet; - Applet *batteryIconApplet; - MenuApplet *menuApplet; - Applet *placeholderApplet; - - // requestUpdate - bool requestingUpdate = false; // WindowManager::render run pending - - // forceUpdate - bool forcingUpdate = false; // WindowManager::render run pending, guaranteed no skip of update - Drivers::EInk::UpdateTypes forcedUpdateType = Drivers::EInk::UpdateTypes::UNSPECIFIED; // guaranteed update using this type - - Applet *lockOwner = nullptr; // Which system applet (if any) is preventing other applets from requesting update + // For convenience + InkHUD *inkhud = nullptr; + Persistence::Settings *settings = nullptr; }; -}; // namespace NicheGraphics::InkHUD +} // namespace NicheGraphics::InkHUD #endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/docs/README.md b/src/graphics/niche/InkHUD/docs/README.md new file mode 100644 index 000000000..07fe6c942 --- /dev/null +++ b/src/graphics/niche/InkHUD/docs/README.md @@ -0,0 +1,640 @@ +# InkHUD + +This document is intended as a reference for maintainers. A haphazard collection of notes which _might_ be helpful. + +self deprecating meme + +--- + +- [Purpose](#purpose) +- [Design Principles](#design-principles) + - [Self-Contained](#self-contained) + - [Static](#static) + - [Non-interactive](#non-interactive) + - [Customizable](#customizable) + - [Event-Driven Rendering](#event-driven-rendering) + - [No `#ifdef` spaghetti](#no-ifdef-spaghetti) +- [The Implementation](#the-implementation) +- [The Rendering Process](#the-rendering-process) +- [Concepts](#concepts) + - [NicheGraphics Framework](#nichegraphics-framework) + - [NicheGraphics E-Ink Drivers](#nichegraphics-e-ink-drivers) + - [InkHUD Applets](#inkhud-applets) +- [Adding a Variant](#adding-a-variant) + - [platformio.ini](#platformioini) + - [nicheGraphics.h](#nichegraphicsh) +- [Class Notes](#class-notes) + - [`InkHUD::InkHUD`](#inkhudinkhud) + - [`InkHUD::Persistence`](#inkhudpersistence) + - [`InkHUD::Persistence::Settings`](#inkhudpersistencesettings) + - [`InkHUD::Persistence::LatestMessage`](#inkhudpersistencelatestmessage) + - [`InkHUD::WindowManager`](#inkhudwindowmanager) + - [`InkHUD::Renderer`](#inkhudrenderer) + - [`InkHUD::Renderer::DisplayHealth`](#inkhudrendererdisplayhealth) + - [`InkHUD::Events`](#inkhudevents) + - [`InkHUD::Applet`](#inkhudapplet) + - [`InkHUD::SystemApplet`](#inkhudsystemapplet) + - [`InkHUD::Tile`](#inkhudtile) + - [`InkHUD::AppletFont`](#inkhudappletfont) + +## Purpose + +InkHUD is a minimal UI for E-Ink devices. It displays the user's choice of info, as statically as possible, to minimize the amount of display refreshing. + +It is intended to supplement a connected client app. + +## Design Principles + +### Self-Contained + +- Keep InkHUD code within `/src/graphics/niche/InkHUD`. +- Place reusable components within `/src/graphics/niche`, for other UIs to take advantage of. +- Interact with the firmware code using the **Module API**, **Observables**, and other similarly non-intrusive hooks. + +### Static + +Information should be displayed as statically as possible. Unnecessary updates should be avoided. + +As as example, fixed timestamps are used instead of `X seconds ago` labels, as these need to be constantly updated to remain current. + +### Non-interactive + +InkHUD aims to be a "heads up display". The intention is for the user to glance at the display. The intention is _not_ for the user to frequently interact with the display. + +Some interactivity is tolerated as a means to an end: the display _should_ be customizable, but this should be minimized as much as possible. + +_Edit: there's significant demand for keyboard support, so some sort of free-text feature will need to be added eventually, although it does go against the original design principles._ + +### Customizable + +The user should be given the choice to decide which information they would like to receive, and how they would like to receive it. + +### Event-Driven Rendering + +The display image does not update "automatically". Individual applets are responsible for deciding when they have new information to show, and then requesting a display update. + +### No `#ifdef` spaghetti + +**Don't** use preprocessor macros for device-specific configuration. This should be achieved with config methods, in [`nicheGraphics.h`](#nichegraphicsh). + +**Do** use preprocessor macros to guard all files + +- `#ifdef MESHTASTIC_INCLUDE_INKHUD` for InkHUD files +- `#ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS` for reusable components (drivers, etc) + +## The Implementation + +- Variant's platformio.ini file extends `inkhud` (defined in InkHUD/PlatformioConfig.ini) + - original screen class suppressed: `MESHTASTIC_EXCLUDE_SCREEN` + - ButtonThread suppressed: `HAS_BUTTON=0` + - NicheGraphics components included: `MESHTASTIC_INCLUDE_NICHE_GRAPHICS` + - InkHUD components included: `MESHTASTIC_INCLUDE_INKHUD` +- `main.cpp` + - includes `nicheGraphics.h` (from variant folder) + - calls `setupNicheGraphics`, (from nicheGraphics.h) +- `nicheGraphics.h` + - includes InkHUD components + - includes shared NicheGraphics components + - `setupNicheGraphics` + - configures and connects components + - `inkhud->begin` + +## The Rendering Process + +(animated diagram) + +animated process diagram of InkHUD rendering + +An overview: + +- A component calls `requestUpdate` (applets only) or `InkHUD::forceUpdate` +- `Renderer` schedules a render cycle for the next loop(), using `Renderer::runOnce` +- `Renderer` determines whether the update request is valid +- `Renderer` asks relevant applets to render +- Applet dimensions are updated (by Applet's `Tile`) +- Applets generate pixel output, and pass this to their `Tile` +- Tiles shift these "relative" pixels to their true region, for multiplexing +- Tiles pass the pixels to `Renderer` +- `Renderer` applies any global display rotation to the pixels +- `Renderer` combines the pixels into the finished image +- The finished image is passed to the display driver, starting the physical update process + +## Concepts + +### NicheGraphics Framework + +InkHUD is implemented as a _NicheGraphics_ UI. + +Intended as a pattern / philosophy for implementing self-contained UIs, to suit various niche devices, which are best served by their own custom user interface. + +Hypothetical examples: E-Ink, 1602 LCDs, tiny OLEDs, smart watches, etc + +A NicheGraphics UI: + +- Is self-contained +- Makes use of the loose collection of resources (drivers, input methods, etc) gathered in the `/src/graphics/niche` folder. +- Implements a `setupNicheGraphics()` method. + +### NicheGraphics E-Ink Drivers + +InkHUD uses a set of custom E-Ink drivers. These are not based on GxEPD2, or any other code base. They are written directly on-top of the Meshtastic firmware, to make use of the OSThread class for asynchronous display updates. + +Interacting with the drivers is straightforward. InkHUD generates a frame of 1-bit image data. This image data is passed to the driver, along with the type of refresh to use (FULL or FAST). + +`driver->update(uint8_t* buffer, EInk::UpdateTypes::FULL)` + +For more information, see the documentation in `src/graphics/niche/Drivers/EInk` + +### InkHUD Applets + +An InkHUD applet is a class which generates a screen of info for the display. + +Consider: `DMApplet.h` (displays most recent direct message) and `RecentsList.h` (displays a list of recently heard nodes) + +- Applets are modular: they are easy to write, and easy to implement. Users select which applets they want, using the menu. +- Applets use responsive design. They should scale for different screens / layouts / fonts. +- Applets decide when to update. They use the Module API, Observers, etc, to retrieve information, and request a display update when they have something interesting to show. + +See `src/graphics/niche/InkHUD/Applets/Examples` for example code. + +#### Writing an Applet + +Your new applet class will inherit `InkHUD::Applet`. + +```cpp +class BasicExampleApplet : public Applet +{ + public: + // You must have an onRender() method + // All drawing happens here + + void onRender() override; +}; +``` + +The `onRender` method is called when the display image is redrawn. This can happen at any time, so be ready! + +```cpp +// All drawing happens here +// Our basic example doesn't do anything useful. It just passively prints some text. +void InkHUD::BasicExampleApplet::onRender() +{ + printAt(0, 0, "Hello, world!"); +} +``` + +Your applet will need to scale automatically, to suit a variety of screens / layouts / fonts. Make sure you draw relative to applet's size. + +| edge | coordinate | shorthand | +| ------ | ---------- | --------- | +| left | 0 | `X(0.0)` | +| top | 0 | `Y(0.0)` | +| right | `width()` | `X(1.0)` | +| bottom | `height()` | `Y(1.0)` | + +The same principles apply for drawing text. Methods like `AppletFont::lineHeight` and `getTextWidth` are useful here. + +```cpp +std::string line1 = "Line 1"; +printAt(0, Y(0.5), line1); +drawRect(0, Y(0.5), getTextWidth(line1), fontSmall.lineHeight(), BLACK); +``` + +Your applet will only be redrawn when _something_ requests a display update. Your applet is welcome to request a display update, when it determines that it has new info to display, by calling `requestUpdate`. + +Exactly how you determine this, depends on what your applet actually does. Here's a code snippet from one of the example applets. The applet is requesting an update when a new message is received. + +```cpp +// We configured the Module API to call this method when we receive a new text message +ProcessMessage InkHUD::NewMsgExampleApplet::handleReceived(const meshtastic_MeshPacket &mp) +{ + + // Abort if applet fully deactivated + // Don't waste time: we wouldn't be rendered anyway + if (!isActive()) + return ProcessMessage::CONTINUE; + + // Check that this is an incoming message + // Outgoing messages (sent by us) will also call handleReceived + + if (!isFromUs(&mp)) { + // Store the sender's nodenum + // We need to keep this information, so we can re-use it anytime render() is called + haveMessage = true; + fromWho = mp.from; + + // Tell InkHUD that we have something new to show on the screen + requestUpdate(); + } + + // Tell Module API to continue informing other firmware components about this message + // We're not the only component which is interested in new text messages + return ProcessMessage::CONTINUE; +} +``` + +#### Implementing an Applet + +Incorporating your new applet into InkHUD is easy. + +In a variant's `nicheGraphics.h`: + +- `#include` your applet +- `inkhud->addApplet("My Applet", new InkHUD::MyApplet);` + +You will need to add these lines to any variants which will use your applet. + +#### Applet Bases + +If you need to create several similar applets, it might make sense to create a reusable base class. Several of these already exist in `src/graphics/niche/InkHUD/Applets/Bases`, but use these with caution, as they may be modified in future. + +#### System Applets + +So far, we have been talking about "user applets". We also recognize a separate category of "system applets". These handle things like the menu, and the boot screen. These often need special handling, and need to be implemented manually. + +## Adding a Variant + +In `/variants//`: + +### platformio.ini + +Extend `inkhud`, then combine with any other platformio config your hardware variant requires. + +_(Example shows only config required by InkHUD. This is not a complete `env` definition.)_ + +```ini +[env:YOUR_VARIANT-inkhud] +extends = esp32s3_base, inkhud ; or nrf52840_base, etc + +build_src_filter = +${esp32_base.build_src_filter} +${inkhud.build_src_filter} + +build_flags = +${esp32s3_base.build_flags} +${inkhud.build_flags} + +lib_deps = +${inkhud.lib_deps} ; InkHUD libs first, so we get GFXRoot instead of AdafruitGFX +${esp32s3_base.lib_deps} +``` + +### nicheGraphics.h + +⚠ Wrap this file in `#ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS` + +`nicheGraphics.h` should be placed in the same folder as your variant's `platformio.ini`. If this is not possible, modify `build_src_filter`. + +`nicheGraphics.h` should contain a `setupNicheGraphics` method, which creates and configures the various components for InkHUD. + +- Display + - Start SPI + - Create display driver +- InkHUD + - Create InkHUD instance + - Set E-Ink fast refresh limit (`setDisplayResilience`) + - Set fonts + - Set default user-settings + - Select applets to build (`addApplet`) + - Start InkHUD +- Buttons + - Setup `TwoButton` driver (user button, optional "auxiliary" button) + - Connect to InkHUD handlers (use lambdas) + +For well commented examples, see: + +- `variants/heltec_vision_master_e290/nicheGraphics.h` (ESP32) +- `variants/t-echo/nicheGraphics.h` (NRF52) + +## Class Notes + +### `InkHUD::InkHUD` + +_`src/graphics/niche/InkHUD/InkHUD.h`_ + +- singleton +- mediator between other InkHUD components + +#### `getInstance()` + +Gets access to the class. +First `getInstance` call instantiates the class, and the subclasses: + +- `InkHUD::Persistence` +- `InkHUD::WindowManager` +- `InkHUD::Renderer` +- `InkHUD::Events` + +For convenience, many InkHUD components call this on `begin`, and store it as `InkHUD* inkhud`. + +--- + +### `InkHUD::Persistence` + +_`src/graphics/niche/InkHUD/Persistence.h`_ + +Stores InkHUD data in flash + +- settings +- most recent text message received (both for broadcast and DM) + +In rare cases, applets may store their own specific data separately (e.g. `ThreadedMessageApplet`) + +Data saved only on shutdown / reboot. Not saved if power is removed unexpectedly. + +--- + +### `InkHUD::Persistence::Settings` + +_`src/graphics/niche/InkHUD/Persistence.h`_ + +Settings which relate to InkHUD. Mostly user's customization, but some values record the UI's state (e.g. `tips.safeShutdownSeen`) + +- stored using `FlashData.h` (a shared Niche Graphics tool) +- not encoded as protobufs +- serialized directly as bytes of struct + +#### Defaults + +Global default values are set when the struct is defined (Persistence.h). +Per-variant defaults are set by modifying the values of the settings instance during `setupNicheGraphics()`, before `inkhud->begin` is called. + +```cpp +inkhud->persistence->settings.userTiles.count = 2; +inkhud->persistence->settings.userTiles.maxCount = 4; +inkhud->persistence->settings.rotation = 3; +``` + +By modifying the values at this point, they will be used if we fail to load previous settings from flash (not yet saved, old version, etc) + +--- + +### `InkHUD::Persistence::LatestMessage` + +_`src/graphics/niche/InkHUD/Persistence.h`_ + +Most recently received text message + +- most recent DM +- most recent broadcast + +Collected here, so various user applets don't all have to store their own copy of this info. + +We are unable to use `devicestate.rx_text_message` for this purpose, because: + +- it is cleared by an outgoing text message +- we want to store both a recent broadcast and a recent DM + +#### Saving / Loading + +_A bit of a hack.._ +Stored to flash using `InkHUD::MessageStore`, which is really intended for storing a thread of messages (see `ThreadedMessageApplet`). Used because it stores strings more efficiently than `FlashData.h`. + +The hack is: + +- If most recent message was a DM, we only store the DM. +- If most recent message was a broadcast, we store both a DM and a broadcast. The DM may be 0-length string. + +--- + +### `InkHUD::WindowManager` + +_`src/graphics/niche/InkHUD/WindowManager.h`_ + +Manages which applets are shown, and their size / position (by manipulating the "tiles") + +- owns the `Tile` instances +- creates and destroys tiles; sets size and position: + - at startup + - at runtime, when config changes (layout, rotation, etc) +- activates (or deactivates) applets +- cycling through applets (e.g. on button press) + +The window manager doesn't process pixels; that is handled by the `InkHUD::Tile` objects. + +Note: Some of the methods (incl. `changeLayout`, `changeActivatedApplets`) don't trigger changes themselves. They should be called _after_ the relevant values in `inkhud->persistence->settings` have been modified. + +--- + +### `InkHUD::Renderer` + +_`src/graphics/niche/InkHUD/Renderer.h`_ + +Get pixel output from applets (via a tile), combine, and pass to the driver. + +- triggered by `requestUpdate` or `forceUpdate` +- not run immediately: allows multiple applets to share one render cycle +- calls `Applet::onRender` for relevant applets +- applies global rotation +- passes finalized image to driver + +`requestUpdate` is for applets (user or system). Renderer will honor the request if the applet is visible. `forceUpdate` can be used anywhere, but not from user applets, please. + +#### Asynchronous updates + +`requestUpdate` and `forceUpdate` do not block code execution. They schedule rendering for "ASAP", using `Renderer::runOnce`. Renderer then gets pixel output from relevant applets, and hands the assembled image to the driver. Driver's update process is also asynchronous. If the driver is busy when `requestUpdate` or `forceUpdate` is called, another rendering will run as soon as possible. This is handled by `Renderer::runOnce` + +#### Blocking updates + +If needed, call `forceUpdate` with the optional argument `async=false` to wait while an update runs (> 1 second). Additionally, the `awaitUpdate` method can be used to block until any previous update has completed. An example usage of this is waiting to draw the shutdown screen. + +#### Global rotation + +The exact size / position / rotation of InkHUD applets is configurable by the user. To achieve this, applets draw pixels between 0,0 and `Applet::width()`, `Applet::height()` + +- **Scaling**: Applet's `width()` and `height()` are set by `Tile` before rendering starts +- **Translation**: `Tile` shifts applet pixels up/down/left/right +- **Rotation**: `Renderer` rotates all pixels it receives, before placing them into the final image buffer + +--- + +### `InkHUD::Renderer::DisplayHealth` + +_`src/graphics/niche/InkHUD/DisplayHealth.h`_ + +Responsible for maintaining display health, by optimizing the ratio of FAST vs FULL refreshes + +- count number of FAST vs FULL refreshes (debt) +- suggest either FAST or FULL type +- periodically FULL refresh the display unprovoked, if needed + +#### Background Info + +When the image on an E-Ink display is updated, different procedures can be used to move the pixels to their new states. We have defined two procedures: `FAST` and `FULL`. + +A `FAST` update moves pixels directly from their old position, to their new position. This is aesthetically pleasing, and quick, _but_ it is challenging for the display hardware. If used excessively, pixels can build up residual charge, which negatively impacts the display's lifespan and image quality. + +A `FULL` update first moves all pixels between black and white, before letting them eventually settle at their final position. This causes an unpleasant flashing of the display image, but is best for the display health and image quality. + +Most displays readily tolerate `FAST` updates, so long as a `FULL` update is occasionally performed. How often this `FULL` update is required depends on the display model. + +#### Debt + +`InkHUD::DisplayHealth` records how many `FAST` refreshes have occurred since the previous `FULL` refresh. + +This is referred to as the "full refresh debt". + +If an update of a specific type (`FULL` / `FAST`) is requested / forced, this will be granted. + +If an update is requested / forced _without_ a specified type (`UpdateTypes::UNSPECIFIED`), `DisplayHealth` will select either `FAST` or `FULL`, in an attempt to maintain a target ratio of fast to full updates. + +This target is set by `InkHUD::setDisplayResilience`, when setting up in `nichegraphics.h` + +If an _excessive_ amount of `FAST` refreshes are performed back-to-back, `DisplayHealth` will begin artificially inflating the full refresh debt. This will cause the next few `UNSPECIFIED` updates to _all_ be performed as `FULL`, while the debt is paid down. + +This system of "full refresh debt" allows us to increase perceived responsiveness by tolerating additional strain on the display during periods of user interaction, and attempting to "repair the damage" later, once user interaction ceases. + +#### Maintenance + +The system of "full refresh debt" assumes that the display will perform many updates of `UNSPECIFIED` type between periods of user interaction. Depending on the amount of mesh traffic / applet selection, this may not be the case. + +If debt is particularly high, and no updates are taking place organically, `DisplayHealth` will begin infrequently performing `FULL` updates, purely to pay down the full refresh debt. + +--- + +### `InkHUD::Events` + +Handles events which impact the InkHUD system generally (e.g. shutdown, button press). + +Applets themselves do also listen separately for various events, but for the purpose of gathering information which they would like to display. + +#### Buttons + +Button input is sometimes handled by a system applet. `InkHUD::Events` determines whether the button should be handled by a specific system applet, or should instead trigger a default behavior + +--- + +### `InkHUD::Applet` + +A base class for applets. An applet is one "program", which may show info on the display. + +To oversimplify, all of the InkHUD code "under the hood" only exists to support applets. Applets are what actually shows useful information to the user. This base class exposes the functionality needed to write an applet. + +#### Drawing Methods + +`Applet` implements most AdafruitGFX drawing methods. Exception is the text handling. `printAt`, `printWrapped`, and `printThick` should be used instead. These are intended to be more convenient, but they also implement the character substitution system which powers the foreign alphabet support. + +`Applet` also adds methods for drawing several design elements which are re-used commonly though-out InkHUD. + +#### InkHUD Events + +Applets undergo a number of state changes: activated / deactivated by user, brought to foreground / hidden to background by user button press, etc. The `Applet` class provides a set of virtual methods, which an applet can override to appropriately handle these events. + +The `onRender` virtual method is one example. This is called when an applet is rendered, and should execute all drawing code. An applet _must_ implement this method. + +#### Responsive Design + +An applet's size will vary depending on the screen size, and the user's layout (multiplexing). Immediately before `onRender` is called, an applet's dimensions are updated, so that `width()` and `height()` will give the required size. The applet should draw its graphical elements relative to these values. The methods `X(float)` and `Y(float)` are also provided for convenience. + +| edge | coordinate | shorthand | +| ------ | ---------- | --------- | +| left | 0 | `X(0.0)` | +| top | 0 | `Y(0.0)` | +| right | `width()` | `X(1.0)` | +| bottom | `height()` | `Y(1.0)` | + +The same principles apply for drawing text. Methods like `AppletFont::lineHeight` and `getTextWidth` are useful here. + +Applets should always draw relative to their top left corner, at _x=0, y=0._ The applet's pixels are automatically moved to the correct position on-screen by an InkHUD::Tile. + +#### User Applets + +User applets are the "normal" applets, each one displaying a specific set of information to the user. They can be activated / deactivated at run-time using the on-screen menu. Examples include `DMApplet.h` and `PositionsApplet.h`. User applets are not expected to interact with lower layers of the InkHUD code. + +Users applets are instantiated in a variant's `setupNicheGraphics` method, and passed to `InkHUD::addApplet`. Their class should not be mentioned elsewhere, so that its code can be stripped away during compilation if a variant does not implement the specific applet. Internal processing of user applets treats them all as the generic `Applet` type only. + +#### Activated / Deactivated + +User applets can be activated or deactivated. This changes at run-time: the user selects which applets should be active using the on-screen menu. An applet should not process data while it is deactivated. It can unobserve any observables, ignore `handleReceived` calls, etc. + +An applet can implement the virtual `onActivate` and `onDeactivate` methods to handle this change in state. It can check this state internally by calling `isActive`. + +System applets cannot be deactivated. + +#### Foreground / Background + +An activated applet can either be _foreground_ or _background_. A foreground applet is one which will be rendered to a tile when the screen updates. A background applet will not be drawn. The applet cycling which takes place when the user button is pressed is implemented using foreground / background. + +Regardless of whether it is foreground or background, an activated applet should continue to collect / process data, and request update when it has new info to display. This is because of the _autoshow_ mechanic, which might bring a background applet to foreground in order to display its data. If an applet remains background, its update requests will be safely ignored. + +#### Autoshow + +Autoshow is a feature which allows the user to select which applets (if any) they would like to be shown automatically. If autoshow is enabled for an applet, it will be brought to foreground when it has new information to display. The user grants this privilege on a per-applet basis, using the on-screen menu. If an event causes an applet to be autoshown, NotificationApplet should not be shown for the same event. + +An applet needs to decide when it has information worthy of autoshowing. It signals this by calling `requestAutoshow`, in addition to the usual `requestUpdate` call. + +--- + +### `InkHUD::SystemApplet` + +_System applets_ are applets with special roles, which require special handling. Examples include `BatteryIconApplet.h` and `LogoApplet.h`. These are manually implemented, one-by-one, in `WindowManager.h`. + +This class is a slight extension of `Applet`. It adds extra flags for some special features which are restricted to system applets: exclusive use of the display, and the handling of user input. Having a separate system applet class also allows us to make it clear within the code when system applets are being handled, rather than user applets + +We store reference to these as a `vector`. This parallels how we treat user applets, and makes rendering convenient. +Because system applets do have unique roles, there are times when we will need to interact with a specific applet. Rather than keeping an extra set of references, we access them from the `vector`. Use `InkHUD::getSystemApplet` to access the applet by its `Applet::name` value, and then typecast. + +--- + +### `InkHUD::Tile` + +A tile represents a region of the display. A tile controls the size and position of an applet. + +For an applet to render, it must be assigned to a tile. When an applet is assigned to a tile, the two become linked. The applet is aware of the tile; the tile is aware of the applet. Applets cannot share a tile; assigning a different applet will remove any existing link. + +Before an applet renders, its width and height are set to the dimensions of the tile. During `onRender`, an applet's drawing methods generate pixels between _x=0, y=0_ and _x=Applet::width(), y=Applet::height()_. These pixels are passed to its tile's `Tile::handleAppletPixel` method. The tile then applies x and y offset, "translating" these pixels to the tile's region of the display. These translated pixels are then passed on to the `InkHUD::Renderer`. + +![depiction of a tile translating applet pixels](./tile_translation.png) + +#### User Tiles + +_User applets_ are the "normal" applets. They can be activated / deactivated at run-time using the on-screen menu. User applets are rendered to one of the **user tiles**. + +The user can customize the "layout", using the on-screen menu. Depending on their selected layout, a certain number of _user tiles_ are created. These tiles are automatically positioned and sized so that they fill the entire screen. + +Often, a user will have enabled more applets than they have tiles. Pressing the user-button will cycle through these applets. The old applet is sent to _background_, the new applet is brought to _foreground_. When a user applet is brought to foreground, it becomes assigned to a user tile (the focused tile). When it renders, its size will be set by this tile, and its pixels will be translated to this tile's region. The user applet which was sent to background loses its assignment; it no longer has an assigned tile. + +#### Focused Tile + +The focused tile is one of the user tiles. This is tile whose applet will change when the user button is pressed. This also the tile where the menu will appear on longpress. The focused tile is identified by its index in `vector userTiles`. + +#### Highlighting + +In addition to the user button, some devices have a second "auxiliary button". The function of this button can vary from device to device, but it is sometimes used to focus a different tile. When this happens, the newly focused tile is temporarily "highlighted", by drawing it with a border. This border is automatically removed after several seconds. As drawing code may only be executed by applets, this highlighting is a collaborative effort between a `Tile` and an `Applet`: performed in `Applet::render`, after the virtual `onRender` method has already run. + +Highlighting is only used when `nextTile` is fired by an aux button. It does not occur if performed via the on-screen menu. + +#### System Tiles + +_System applets_ are applets with special roles, which require special handling. Examples include `BatteryIconApplet.h` and `LogoApplet.h`. _Mostly_, these applets do not render to user tiles. Instead, they are given their own unique tile, which is positioned / dimensioned manually. The only reference we keep to these special tiles is stored within the linked system applet. They can be accessed with `Applet::getTile`. + +--- + +### `InkHUD::AppletFont` + +Wrapper which extends the functionality of an AdafruitGFX font. + +#### Dimension Info + +The AppletFont class pre-calculates some info about a font's dimensions, which is useful for design (`AppletFont::lineHeight`), and is used to power InkHUD's custom text handling. + +The default AdafruitGFX text handling places characters "upon a line", as if hand-written on a sheet of ruled paper. `InkHUD::AppletFont` measures the character set of the font, so that we instead draw fixed-height lines of text, positioned by the bounding box, with optional horizontal and vertical alignment. + +![text origins in InkHUD vs AdafruitGFX](./appletfont.png) + +The height of this box is `AppletFont::lineHeight`, which is the height of the tallest character in the font. This gives us a fixed-height for text, which is much tighter than with AdafruitGFX's default line spacing. + +#### UTF-8 Substitutions + +To enable non-English text, the `AppletFont` class includes a mechanism to detect specific UTF-8 characters, and replace them with alternative glyphs from the AdafruitGFX font. This can be used to remap characters for a custom font, or to offer a suitable ASCII replacement. + +```cpp +// With a custom font +// ї is ASCII 0xBF, in Windows-1251 encoding +addSubstitution("ї", "\xBF"); + +// Substitution (with a default font) +addSubstitution("ö", "oe"); +``` + +These substitutions should be performed in a variant's `setupNicheGraphics` method. For convenience, some common ASCII encodings have ready-to-go sets of substitutions you can apply, for example `AppletFont::addSubstitutionsWin1251` diff --git a/src/graphics/niche/InkHUD/docs/appletfont.png b/src/graphics/niche/InkHUD/docs/appletfont.png new file mode 100644 index 000000000..f0b11d323 Binary files /dev/null and b/src/graphics/niche/InkHUD/docs/appletfont.png differ diff --git a/src/graphics/niche/InkHUD/docs/disclaimer.jpg b/src/graphics/niche/InkHUD/docs/disclaimer.jpg new file mode 100644 index 000000000..d4c2c890e Binary files /dev/null and b/src/graphics/niche/InkHUD/docs/disclaimer.jpg differ diff --git a/src/graphics/niche/InkHUD/docs/rendering.gif b/src/graphics/niche/InkHUD/docs/rendering.gif new file mode 100644 index 000000000..cb712381b Binary files /dev/null and b/src/graphics/niche/InkHUD/docs/rendering.gif differ diff --git a/src/graphics/niche/InkHUD/docs/tile_translation.png b/src/graphics/niche/InkHUD/docs/tile_translation.png new file mode 100644 index 000000000..7bbf63643 Binary files /dev/null and b/src/graphics/niche/InkHUD/docs/tile_translation.png differ diff --git a/src/graphics/niche/Inputs/TwoButton.cpp b/src/graphics/niche/Inputs/TwoButton.cpp index e478364cc..10d89ef41 100644 --- a/src/graphics/niche/Inputs/TwoButton.cpp +++ b/src/graphics/niche/Inputs/TwoButton.cpp @@ -18,6 +18,10 @@ TwoButton::TwoButton() : concurrency::OSThread("TwoButton") lsObserver.observe(¬ifyLightSleep); lsEndObserver.observe(¬ifyLightSleepEnd); #endif + + // Explicitly initialize these, just to keep cppcheck quiet.. + buttons[0] = Button(); + buttons[1] = Button(); } // Get access to (or create) the singleton instance of this class @@ -185,7 +189,7 @@ int32_t TwoButton::runOnce() // New press detected by interrupt case IRQ: powerFSM.trigger(EVENT_PRESS); // Tell PowerFSM that press occurred (resets sleep timer) - buttons[i].onDown(); // Inform that press has begun (possible hold behavior) + buttons[i].onDown(); // Run callback: press has begun (possible hold behavior) buttons[i].state = State::POLLING_UNFIRED; // Mark that button-down has been handled awaitingRelease = true; // Mark that polling-for-release should continue break; @@ -197,17 +201,17 @@ int32_t TwoButton::runOnce() // If button released since last thread tick, if (digitalRead(buttons[i].pin) != buttons[i].activeLogic) { - buttons[i].onUp(); // Inform that press has ended (possible release of a hold) + buttons[i].onUp(); // Run callback: press has ended (possible release of a hold) buttons[i].state = State::REST; // Mark that the button has reset - if (length > buttons[i].debounceLength && length < buttons[i].longpressLength) - buttons[i].onShortPress(); + if (length > buttons[i].debounceLength && length < buttons[i].longpressLength) // If too short for longpress, + buttons[i].onShortPress(); // Run callback: short press } // If button not yet released else { awaitingRelease = true; // Mark that polling-for-release should continue if (length >= buttons[i].longpressLength) { - // Raise a long press event, once + // Run callback: long press (once) // Then continue waiting for release, to rearm buttons[i].state = State::POLLING_FIRED; buttons[i].onLongPress(); @@ -222,7 +226,7 @@ int32_t TwoButton::runOnce() // Release detected if (digitalRead(buttons[i].pin) != buttons[i].activeLogic) { buttons[i].state = State::REST; - buttons[i].onUp(); // Possible release of hold (in this case: *after* longpress has fired) + buttons[i].onUp(); // Callback: release of hold (in this case: *after* longpress has fired) } // Not yet released, keep polling else diff --git a/src/graphics/tftSetup.cpp b/src/graphics/tftSetup.cpp index c31659c62..cacb02694 100644 --- a/src/graphics/tftSetup.cpp +++ b/src/graphics/tftSetup.cpp @@ -119,7 +119,7 @@ void tftSetup(void) #ifdef ARCH_ESP32 tftSleepObserver.observe(¬ifyLightSleep); endSleepObserver.observe(¬ifyLightSleepEnd); - xTaskCreatePinnedToCore(tft_task_handler, "tft", 8192, NULL, 1, NULL, 0); + xTaskCreatePinnedToCore(tft_task_handler, "tft", 10240, NULL, 1, NULL, 0); #endif } diff --git a/src/main.cpp b/src/main.cpp index f13941d96..a0fe3308a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -55,12 +55,12 @@ NimbleBluetooth *nimbleBluetooth = nullptr; NRF52Bluetooth *nrf52Bluetooth = nullptr; #endif -#if HAS_WIFI +#if HAS_WIFI || defined(USE_WS5500) #include "mesh/api/WiFiServerAPI.h" #include "mesh/wifi/WiFiAPClient.h" #endif -#if HAS_ETHERNET +#if HAS_ETHERNET && !defined(USE_WS5500) #include "mesh/api/ethServerAPI.h" #include "mesh/eth/ethClient.h" #endif @@ -264,6 +264,32 @@ void printInfo() #ifndef PIO_UNIT_TESTING void setup() { + +#ifdef POWER_CHRG + pinMode(POWER_CHRG, OUTPUT); + digitalWrite(POWER_CHRG, HIGH); +#endif + +#if defined(PIN_POWER_EN) + pinMode(PIN_POWER_EN, OUTPUT); + digitalWrite(PIN_POWER_EN, HIGH); +#endif + +#ifdef LED_POWER + pinMode(LED_POWER, OUTPUT); + digitalWrite(LED_POWER, HIGH); +#endif + +#ifdef POWER_LED + pinMode(POWER_LED, OUTPUT); + digitalWrite(POWER_LED, HIGH); +#endif + +#ifdef USER_LED + pinMode(USER_LED, OUTPUT); + digitalWrite(USER_LED, LOW); +#endif + #if defined(T_DECK) // GPIO10 manages all peripheral power supplies // Turn on peripheral power immediately after MUC starts. @@ -327,13 +353,6 @@ void setup() initDeepSleep(); - // power on peripherals -#if defined(PIN_POWER_EN) - pinMode(PIN_POWER_EN, OUTPUT); - digitalWrite(PIN_POWER_EN, HIGH); - // digitalWrite(PIN_POWER_EN1, INPUT); -#endif - #if defined(LORA_TCXO_GPIO) pinMode(LORA_TCXO_GPIO, OUTPUT); digitalWrite(LORA_TCXO_GPIO, HIGH); @@ -643,6 +662,8 @@ void setup() scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::MAX30102, meshtastic_TelemetrySensorType_MAX30102); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::CGRADSENS, meshtastic_TelemetrySensorType_RADSENS); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::DFROBOT_RAIN, meshtastic_TelemetrySensorType_DFROBOT_RAIN); + scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::LTR390UV, meshtastic_TelemetrySensorType_LTR390UV); + scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::DPS310, meshtastic_TelemetrySensorType_DPS310); i2cScanner.reset(); #endif @@ -822,6 +843,13 @@ void setup() #ifdef HAS_UDP_MULTICAST LOG_DEBUG("Start multicast thread"); udpThread = new UdpMulticastThread(); +#ifdef ARCH_PORTDUINO + // FIXME: portduino does not ever call onNetworkConnected so call it here because I don't know what happen if I call + // onNetworkConnected there + if (config.network.enabled_protocols & meshtastic_Config_NetworkConfig_ProtocolFlags_UDP_BROADCAST) { + udpThread->start(); + } +#endif #endif service = new MeshService(); service->init(); @@ -1018,6 +1046,22 @@ void setup() #endif #if defined(USE_SX1268) +#if defined(SX126X_DIO3_TCXO_VOLTAGE) && defined(TCXO_OPTIONAL) + if ((!rIf) && (config.lora.region != meshtastic_Config_LoRaConfig_RegionCode_LORA_24)) { + // try using the specified TCXO voltage + auto *sxIf = new SX1268Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY); + sxIf->setTCXOVoltage(SX126X_DIO3_TCXO_VOLTAGE); + if (!sxIf->init()) { + LOG_WARN("No SX1268 radio with TCXO, Vref %fV", SX126X_DIO3_TCXO_VOLTAGE); + delete sxIf; + rIf = NULL; + } else { + LOG_INFO("SX1268 init success, TCXO, Vref %fV", SX126X_DIO3_TCXO_VOLTAGE); + rIf = sxIf; + radioType = SX1268_RADIO; + } + } +#endif if ((!rIf) && (config.lora.region != meshtastic_Config_LoRaConfig_RegionCode_LORA_24)) { rIf = new SX1268Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY); if (!rIf->init()) { @@ -1229,8 +1273,12 @@ extern meshtastic_DeviceMetadata getDeviceMetadata() #if MESHTASTIC_EXCLUDE_AUDIO deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_AUDIO_CONFIG; #endif -#if !HAS_SCREEN || NO_EXT_GPIO - deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_CANNEDMSG_CONFIG | meshtastic_ExcludedModules_EXTNOTIF_CONFIG; +// Option to explicitly include canned messages for edge cases, e.g. niche graphics +#if (!HAS_SCREEN && NO_EXT_GPIO) && !MESHTASTIC_INCLUDE_CANNEDMSG + deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_CANNEDMSG_CONFIG; +#endif +#if NO_EXT_GPIO + deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_EXTNOTIF_CONFIG; #endif // Only edge case here is if we apply this a device with built in Accelerometer and want to detect interrupts // We'll have to macro guard against those targets potentially @@ -1296,5 +1344,4 @@ void loop() mainDelay.delay(delayMsec); } } - -#endif \ No newline at end of file +#endif diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index f1d4926db..4d061f80f 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -347,7 +347,7 @@ bool Channels::anyMqttEnabled() { #if USERPREFS_EVENT_MODE // Don't publish messages on the public MQTT broker if we are in event mode - if (mqtt && mqtt.isUsingDefaultServer()) { + if (mqtt && mqtt->isUsingDefaultServer()) { return false; } #endif diff --git a/src/mesh/CryptoEngine.cpp b/src/mesh/CryptoEngine.cpp index 4613a6218..d32b73855 100644 --- a/src/mesh/CryptoEngine.cpp +++ b/src/mesh/CryptoEngine.cpp @@ -161,10 +161,8 @@ void CryptoEngine::hash(uint8_t *bytes, size_t numBytes) void CryptoEngine::aesSetKey(const uint8_t *key_bytes, size_t key_len) { - if (aes) { - delete aes; - aes = nullptr; - } + delete aes; + aes = nullptr; if (key_len != 0) { aes = new AESSmall256(); aes->setKey(key_bytes, key_len); @@ -225,10 +223,8 @@ void CryptoEngine::decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes // Generic implementation of AES-CTR encryption. void CryptoEngine::encryptAESCtr(CryptoKey _key, uint8_t *_nonce, size_t numBytes, uint8_t *bytes) { - if (ctr) { - delete ctr; - ctr = nullptr; - } + delete ctr; + ctr = nullptr; if (_key.length == 16) ctr = new CTR(); else diff --git a/src/mesh/InterfacesTemplates.cpp b/src/mesh/InterfacesTemplates.cpp index 2720e8525..57abbf0ee 100644 --- a/src/mesh/InterfacesTemplates.cpp +++ b/src/mesh/InterfacesTemplates.cpp @@ -25,7 +25,7 @@ template class LR11x0Interface; template class SX126xInterface; #endif -#if HAS_ETHERNET +#if HAS_ETHERNET && !defined(USE_WS5500) #include "api/ethServerAPI.h" template class ServerAPI; template class APIServerPort; diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 0ef21d4ca..297c7b2ed 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -88,8 +88,16 @@ int MeshService::handleFromRadio(const meshtastic_MeshPacket *mp) } else if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag && !nodeDB->getMeshNode(mp->from)->has_user && nodeInfoModule && !isPreferredRebroadcaster && !nodeDB->isFull()) { if (airTime->isTxAllowedChannelUtil(true)) { - LOG_INFO("Heard new node on ch. %d, send NodeInfo and ask for response", mp->channel); - nodeInfoModule->sendOurNodeInfo(mp->from, true, mp->channel); + // Hops used by the request. If somebody in between running modified firmware modified it, ignore it + auto hopStart = mp->hop_start; + auto hopLimit = mp->hop_limit; + uint8_t hopsUsed = hopStart < hopLimit ? config.lora.hop_limit : hopStart - hopLimit; + if (hopsUsed > config.lora.hop_limit + 2) { + LOG_DEBUG("Skip send NodeInfo: %d hops away is too far away", hopsUsed); + } else { + LOG_INFO("Heard new node on ch. %d, send NodeInfo and ask for response", mp->channel); + nodeInfoModule->sendOurNodeInfo(mp->from, true, mp->channel); + } } else { LOG_DEBUG("Skip sending NodeInfo > 25%% ch. util"); } @@ -117,17 +125,15 @@ void MeshService::loop() } /// The radioConfig object just changed, call this to force the hw to change to the new settings -bool MeshService::reloadConfig(int saveWhat) +void MeshService::reloadConfig(int saveWhat) { // If we can successfully set this radio to these settings, save them to disk // This will also update the region as needed - bool didReset = nodeDB->resetRadioConfig(); // Don't let the phone send us fatally bad settings + nodeDB->resetRadioConfig(); // Don't let the phone send us fatally bad settings configChanged.notifyObservers(NULL); // This will cause radio hardware to change freqs etc nodeDB->saveToDisk(saveWhat); - - return didReset; } /// The owner User record just got updated, update our node DB and broadcast the info into the mesh @@ -303,7 +309,10 @@ void MeshService::sendToPhone(meshtastic_MeshPacket *p) } } - assert(toPhoneQueue.enqueue(p, 0)); + if (toPhoneQueue.enqueue(p, 0) == false) { + LOG_CRIT("Failed to queue a packet into toPhoneQueue!"); + abort(); + } fromNum++; } @@ -317,7 +326,10 @@ void MeshService::sendMqttMessageToClientProxy(meshtastic_MqttClientProxyMessage releaseMqttClientProxyMessageToPool(d); } - assert(toPhoneMqttProxyQueue.enqueue(m, 0)); + if (toPhoneMqttProxyQueue.enqueue(m, 0) == false) { + LOG_CRIT("Failed to queue a packet into toPhoneMqttProxyQueue!"); + abort(); + } fromNum++; } @@ -331,7 +343,10 @@ void MeshService::sendClientNotification(meshtastic_ClientNotification *n) releaseClientNotificationToPool(d); } - assert(toPhoneClientNotificationQueue.enqueue(n, 0)); + if (toPhoneClientNotificationQueue.enqueue(n, 0) == false) { + LOG_CRIT("Failed to queue a notification into toPhoneClientNotificationQueue!"); + abort(); + } fromNum++; } diff --git a/src/mesh/MeshService.h b/src/mesh/MeshService.h index 42f701d5c..e2e430c03 100644 --- a/src/mesh/MeshService.h +++ b/src/mesh/MeshService.h @@ -118,7 +118,7 @@ class MeshService /** The radioConfig object just changed, call this to force the hw to change to the new settings * @return true if client devices should be sent a new set of radio configs */ - bool reloadConfig(int saveWhat = SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); + void reloadConfig(int saveWhat = SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); /// The owner User record just got updated, update our node DB and broadcast the info into the mesh void reloadOwner(bool shouldSave = true); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 62ab675bc..3f79d18e6 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -51,6 +51,10 @@ #include #endif +#if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_WIFI +#include +#endif + NodeDB *nodeDB = nullptr; // we have plenty of ram so statically alloc this tempbuf (for now) @@ -400,18 +404,12 @@ bool isBroadcast(uint32_t dest) return dest == NODENUM_BROADCAST || dest == NODENUM_BROADCAST_NO_LORA; } -bool NodeDB::resetRadioConfig(bool factory_reset, bool is_fresh_install) +void NodeDB::resetRadioConfig(bool is_fresh_install) { - bool didFactoryReset = false; - if (is_fresh_install) { radioGeneration++; } - if (factory_reset) { - didFactoryReset = factoryReset(); - } - if (channelFile.channels_count != MAX_NUM_CHANNELS) { LOG_INFO("Set default channel and radio preferences!"); @@ -422,14 +420,6 @@ bool NodeDB::resetRadioConfig(bool factory_reset, bool is_fresh_install) // Update the global myRegion initRegion(); - - if (didFactoryReset) { - LOG_INFO("Reboot due to factory reset"); - screen->startAlert("Rebooting..."); - rebootAtMsec = millis() + (5 * 1000); - } - - return didFactoryReset; } bool NodeDB::factoryReset(bool eraseBleBonds) @@ -591,7 +581,7 @@ void NodeDB::installDefaultConfig(bool preserveKey = false) config.device.node_info_broadcast_secs = default_node_info_broadcast_secs; config.security.serial_enabled = true; config.security.admin_channel_enabled = false; - resetRadioConfig(false, true); // This also triggers NodeInfo/Position requests since we're fresh + resetRadioConfig(true); // This also triggers NodeInfo/Position requests since we're fresh strncpy(config.network.ntp_server, "meshtastic.pool.ntp.org", 32); #if (defined(T_DECK) || defined(T_WATCH_S3) || defined(UNPHONE) || defined(PICOMPUTER_S3) || defined(SENSECAP_INDICATOR)) && \ @@ -638,6 +628,27 @@ void NodeDB::installDefaultConfig(bool preserveKey = false) meshtastic_Config_PositionConfig_PositionFlags_SPEED | meshtastic_Config_PositionConfig_PositionFlags_HEADING | meshtastic_Config_PositionConfig_PositionFlags_DOP | meshtastic_Config_PositionConfig_PositionFlags_SATINVIEW); +// Set default value for 'Mesh via UDP' +#if HAS_UDP_MULTICAST +#ifdef USERPREFS_NETWORK_ENABLED_PROTOCOLS + config.network.enabled_protocols = USERPREFS_NETWORK_ENABLED_PROTOCOLS; +#else + config.network.enabled_protocols = 1; +#endif +#endif + +#ifdef USERPREFS_NETWORK_WIFI_ENABLED + config.network.wifi_enabled = USERPREFS_NETWORK_WIFI_ENABLED; +#endif + +#ifdef USERPREFS_NETWORK_WIFI_SSID + strncpy(config.network.wifi_ssid, USERPREFS_NETWORK_WIFI_SSID, sizeof(config.network.wifi_ssid)); +#endif + +#ifdef USERPREFS_NETWORK_WIFI_PSK + strncpy(config.network.wifi_psk, USERPREFS_NETWORK_WIFI_PSK, sizeof(config.network.wifi_psk)); +#endif + #ifdef DISPLAY_FLIP_SCREEN config.display.flip_screen = true; #endif @@ -649,6 +660,12 @@ void NodeDB::installDefaultConfig(bool preserveKey = false) config.display.wake_on_tap_or_motion = true; #endif +#if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_WIFI + if (WiFiOTA::isUpdated()) { + WiFiOTA::recoverConfig(&config.network); + } +#endif + initConfigIntervals(); } @@ -1044,8 +1061,8 @@ void NodeDB::loadFromDisk() // if (state != LoadFileResult::LOAD_SUCCESS) { // installDefaultDeviceState(); // Our in RAM copy might now be corrupt //} else { - if (devicestate.version < DEVICESTATE_MIN_VER) { - LOG_WARN("Devicestate %d is old, discard", devicestate.version); + if ((state != LoadFileResult::LOAD_SUCCESS) || (devicestate.version < DEVICESTATE_MIN_VER)) { + LOG_WARN("Devicestate %d is old or invalid, discard", devicestate.version); installDefaultDeviceState(); } else { LOG_INFO("Loaded saved devicestate version %d", devicestate.version); @@ -1441,13 +1458,14 @@ bool NodeDB::updateUser(uint32_t nodeId, meshtastic_User &p, uint8_t channelInde #if !(MESHTASTIC_EXCLUDE_PKI) if (p.public_key.size > 0) { printBytes("Incoming Pubkey: ", p.public_key.bytes, 32); - if (info->user.public_key.size > 0) { // if we have a key for this user already, don't overwrite with a new one - LOG_INFO("Public Key set for node, not updating!"); - // we copy the key into the incoming packet, to prevent overwrite - memcpy(p.public_key.bytes, info->user.public_key.bytes, 32); - } else { - LOG_INFO("Update Node Pubkey!"); - } + } + if (info->user.public_key.size > 0) { // if we have a key for this user already, don't overwrite with a new one + LOG_INFO("Public Key set for node, not updating!"); + // we copy the key into the incoming packet, to prevent overwrite + p.public_key.size = 32; + memcpy(p.public_key.bytes, info->user.public_key.bytes, 32); + } else if (p.public_key.size > 0) { + LOG_INFO("Update Node Pubkey!"); } #endif @@ -1612,6 +1630,94 @@ UserLicenseStatus NodeDB::getLicenseStatus(uint32_t nodeNum) return info->user.is_licensed ? UserLicenseStatus::Licensed : UserLicenseStatus::NotLicensed; } +bool NodeDB::backupPreferences(meshtastic_AdminMessage_BackupLocation location) +{ + bool success = false; + lastBackupAttempt = millis(); +#ifdef FSCom + if (location == meshtastic_AdminMessage_BackupLocation_FLASH) { + meshtastic_BackupPreferences backup = meshtastic_BackupPreferences_init_zero; + backup.version = DEVICESTATE_CUR_VER; + backup.timestamp = getValidTime(RTCQuality::RTCQualityDevice, false); + backup.has_config = true; + backup.config = config; + backup.has_module_config = true; + backup.module_config = moduleConfig; + backup.has_channels = true; + backup.channels = channelFile; + backup.has_owner = true; + backup.owner = owner; + + size_t backupSize; + pb_get_encoded_size(&backupSize, meshtastic_BackupPreferences_fields, &backup); + + spiLock->lock(); + FSCom.mkdir("/backups"); + spiLock->unlock(); + success = saveProto(backupFileName, backupSize, &meshtastic_BackupPreferences_msg, &backup); + + if (success) { + LOG_INFO("Saved backup preferences"); + } else { + LOG_ERROR("Failed to save backup preferences to file"); + } + } else if (location == meshtastic_AdminMessage_BackupLocation_SD) { + // TODO: After more mainline SD card support + } +#endif + return success; +} + +bool NodeDB::restorePreferences(meshtastic_AdminMessage_BackupLocation location, int restoreWhat) +{ + bool success = false; +#ifdef FSCom + if (location == meshtastic_AdminMessage_BackupLocation_FLASH) { + spiLock->lock(); + if (!FSCom.exists(backupFileName)) { + spiLock->unlock(); + LOG_WARN("Could not restore. No backup file found"); + return false; + } else { + spiLock->unlock(); + } + meshtastic_BackupPreferences backup = meshtastic_BackupPreferences_init_zero; + success = loadProto(backupFileName, meshtastic_BackupPreferences_size, sizeof(meshtastic_BackupPreferences), + &meshtastic_BackupPreferences_msg, &backup); + if (success) { + if (restoreWhat & SEGMENT_CONFIG) { + config = backup.config; + LOG_DEBUG("Restored config"); + } + if (restoreWhat & SEGMENT_MODULECONFIG) { + moduleConfig = backup.module_config; + LOG_DEBUG("Restored module config"); + } + if (restoreWhat & SEGMENT_DEVICESTATE) { + devicestate.owner = backup.owner; + LOG_DEBUG("Restored device state"); + } + if (restoreWhat & SEGMENT_CHANNELS) { + channelFile = backup.channels; + LOG_DEBUG("Restored channels"); + } + + success = saveToDisk(restoreWhat); + if (success) { + LOG_INFO("Restored preferences from backup"); + } else { + LOG_ERROR("Failed to save restored preferences to flash"); + } + } else { + LOG_ERROR("Failed to restore preferences from backup file"); + } + } else if (location == meshtastic_AdminMessage_BackupLocation_SD) { + // TODO: After more mainline SD card support + } + return success; +#endif +} + /// Record an error that should be reported via analytics void recordCriticalError(meshtastic_CriticalErrorCode code, uint32_t address, const char *filename) { diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index 25f1e9083..291c3804b 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -48,6 +48,7 @@ static constexpr const char *configFileName = "/prefs/config.proto"; static constexpr const char *uiconfigFileName = "/prefs/uiconfig.proto"; static constexpr const char *moduleConfigFileName = "/prefs/module.proto"; static constexpr const char *channelFileName = "/prefs/channels.proto"; +static constexpr const char *backupFileName = "/backups/backup.proto"; /// Given a node, return how many seconds in the past (vs now) that we last heard from it uint32_t sinceLastSeen(const meshtastic_NodeInfoLite *n); @@ -103,7 +104,7 @@ class NodeDB * @param is_fresh_install set to true after a fresh install, to trigger NodeInfo/Position requests * @return true if the config was completely reset, in that case, we should send it back to the client */ - bool resetRadioConfig(bool factory_reset = false, bool is_fresh_install = false); + void resetRadioConfig(bool is_fresh_install = false); /// given a subpacket sniffed from the network, update our DB state /// we updateGUI and updateGUIforNode if we think our this change is big enough for a redraw @@ -202,8 +203,13 @@ class NodeDB bool hasValidPosition(const meshtastic_NodeInfoLite *n); + bool backupPreferences(meshtastic_AdminMessage_BackupLocation location); + bool restorePreferences(meshtastic_AdminMessage_BackupLocation location, + int restoreWhat = SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); + private: - uint32_t lastNodeDbSave = 0; // when we last saved our db to flash + uint32_t lastNodeDbSave = 0; // when we last saved our db to flash + uint32_t lastBackupAttempt = 0; // when we last tried a backup automatically or manually /// Find a node in our DB, create an empty NodeInfoLite if missing meshtastic_NodeInfoLite *getOrCreateMeshNode(NodeNum n); diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 695c5be77..2e50c0168 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -73,9 +73,10 @@ const RegionInfo regions[] = { RDEF(RU, 868.7f, 869.2f, 100, 0, 20, true, false, false), /* - ??? + https://www.law.go.kr/LSW/admRulLsInfoP.do?admRulId=53943&efYd=0 + https://resources.lora-alliance.org/technical-specifications/rp002-1-0-4-regional-parameters */ - RDEF(KR, 920.0f, 923.0f, 100, 0, 0, true, false, false), + RDEF(KR, 920.0f, 923.0f, 100, 0, 23, true, false, false), /* Taiwan, 920-925Mhz, limited to 0.5W indoor or coastal, 1.0W outdoor. @@ -655,7 +656,7 @@ size_t RadioInterface::beginSending(meshtastic_MeshPacket *p) // if the sender nodenum is zero, that means uninitialized assert(radioBuffer.header.from); - + assert(p->encrypted.size <= sizeof(radioBuffer.payload)); memcpy(radioBuffer.payload, p->encrypted.bytes, p->encrypted.size); sendingPacket = p; diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 9e1e41d53..b8b7ee610 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -188,7 +188,7 @@ ErrorCode Router::sendLocal(meshtastic_MeshPacket *p, RxSource src) // don't override if a channel was requested and no need to set it when PKI is enforced if (!p->channel && !p->pki_encrypted && !isBroadcast(p->to)) { - meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(p->to); + meshtastic_NodeInfoLite const *node = nodeDB->getMeshNode(p->to); if (node) { p->channel = node->channel; LOG_DEBUG("localSend to channel %d", p->channel); @@ -198,6 +198,14 @@ ErrorCode Router::sendLocal(meshtastic_MeshPacket *p, RxSource src) return send(p); } } +/** + * Send a packet on a suitable interface. + */ +ErrorCode Router::rawSend(meshtastic_MeshPacket *p) +{ + assert(iface); // This should have been detected already in sendLocal (or we just received a packet from outside) + return iface->send(p); +} /** * Send a packet on a suitable interface. This routine will @@ -319,27 +327,27 @@ void Router::sniffReceived(const meshtastic_MeshPacket *p, const meshtastic_Rout // FIXME, update nodedb here for any packet that passes through us } -bool perhapsDecode(meshtastic_MeshPacket *p) +DecodeState perhapsDecode(meshtastic_MeshPacket *p) { concurrency::LockGuard g(cryptLock); if (config.device.role == meshtastic_Config_DeviceConfig_Role_REPEATER && config.device.rebroadcast_mode == meshtastic_Config_DeviceConfig_RebroadcastMode_ALL_SKIP_DECODING) - return false; + return DecodeState::DECODE_FAILURE; if (config.device.rebroadcast_mode == meshtastic_Config_DeviceConfig_RebroadcastMode_KNOWN_ONLY && (nodeDB->getMeshNode(p->from) == NULL || !nodeDB->getMeshNode(p->from)->has_user)) { LOG_DEBUG("Node 0x%x not in nodeDB-> Rebroadcast mode KNOWN_ONLY will ignore packet", p->from); - return false; + return DecodeState::DECODE_FAILURE; } if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) - return true; // If packet was already decoded just return + return DecodeState::DECODE_SUCCESS; // If packet was already decoded just return size_t rawSize = p->encrypted.size; if (rawSize > sizeof(bytes)) { LOG_ERROR("Packet too large to attempt decryption! (rawSize=%d > 256)", rawSize); - return false; + return DecodeState::DECODE_FATAL; } bool decrypted = false; ChannelIndex chIndex = 0; @@ -353,18 +361,22 @@ bool perhapsDecode(meshtastic_MeshPacket *p) if (crypto->decryptCurve25519(p->from, nodeDB->getMeshNode(p->from)->user.public_key, p->id, rawSize, p->encrypted.bytes, bytes)) { LOG_INFO("PKI Decryption worked!"); - memset(&p->decoded, 0, sizeof(p->decoded)); + + meshtastic_Data decodedtmp; + memset(&decodedtmp, 0, sizeof(decodedtmp)); rawSize -= MESHTASTIC_PKC_OVERHEAD; - if (pb_decode_from_bytes(bytes, rawSize, &meshtastic_Data_msg, &p->decoded) && - p->decoded.portnum != meshtastic_PortNum_UNKNOWN_APP) { + if (pb_decode_from_bytes(bytes, rawSize, &meshtastic_Data_msg, &decodedtmp) && + decodedtmp.portnum != meshtastic_PortNum_UNKNOWN_APP) { decrypted = true; LOG_INFO("Packet decrypted using PKI!"); p->pki_encrypted = true; memcpy(&p->public_key.bytes, nodeDB->getMeshNode(p->from)->user.public_key.bytes, 32); p->public_key.size = 32; + p->decoded = decodedtmp; + p->which_payload_variant = meshtastic_MeshPacket_decoded_tag; // change type to decoded } else { LOG_ERROR("PKC Decrypted, but pb_decode failed!"); - return false; + return DecodeState::DECODE_FAILURE; } } else { LOG_WARN("PKC decrypt attempted but failed!"); @@ -387,12 +399,15 @@ bool perhapsDecode(meshtastic_MeshPacket *p) // printBytes("plaintext", bytes, p->encrypted.size); // Take those raw bytes and convert them back into a well structured protobuf we can understand - memset(&p->decoded, 0, sizeof(p->decoded)); - if (!pb_decode_from_bytes(bytes, rawSize, &meshtastic_Data_msg, &p->decoded)) { + meshtastic_Data decodedtmp; + memset(&decodedtmp, 0, sizeof(decodedtmp)); + if (!pb_decode_from_bytes(bytes, rawSize, &meshtastic_Data_msg, &decodedtmp)) { LOG_ERROR("Invalid protobufs in received mesh packet id=0x%08x (bad psk?)!", p->id); - } else if (p->decoded.portnum == meshtastic_PortNum_UNKNOWN_APP) { + } else if (decodedtmp.portnum == meshtastic_PortNum_UNKNOWN_APP) { LOG_ERROR("Invalid portnum (bad psk?)!"); } else { + p->decoded = decodedtmp; + p->which_payload_variant = meshtastic_MeshPacket_decoded_tag; // change type to decoded decrypted = true; break; } @@ -401,8 +416,7 @@ bool perhapsDecode(meshtastic_MeshPacket *p) } if (decrypted) { // parsing was successful - p->which_payload_variant = meshtastic_MeshPacket_decoded_tag; // change type to decoded - p->channel = chIndex; // change to store the index instead of the hash + p->channel = chIndex; // change to store the index instead of the hash if (p->decoded.has_bitfield) p->decoded.want_response |= p->decoded.bitfield & BITFIELD_WANT_RESPONSE_MASK; @@ -434,10 +448,10 @@ bool perhapsDecode(meshtastic_MeshPacket *p) LOG_TRACE("%s", MeshPacketSerializer::JsonSerialize(p, false).c_str()); } #endif - return true; + return DecodeState::DECODE_SUCCESS; } else { LOG_WARN("No suitable channel found for decoding, hash was 0x%x!", p->channel); - return false; + return DecodeState::DECODE_FAILURE; } } @@ -592,8 +606,13 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) meshtastic_MeshPacket *p_encrypted = packetPool.allocCopy(*p); // Take those raw bytes and convert them back into a well structured protobuf we can understand - bool decoded = perhapsDecode(p); - if (decoded) { + auto decodedState = perhapsDecode(p); + if (decodedState == DecodeState::DECODE_FATAL) { + // Fatal decoding error, we can't do anything with this packet + LOG_WARN("Fatal decode error, dropping packet"); + cancelSending(p->from, p->id); + skipHandle = true; + } else if (decodedState == DecodeState::DECODE_SUCCESS) { // parsing was successful, queue for our recipient if (src == RX_SRC_LOCAL) printPacket("handleReceived(LOCAL)", p); @@ -636,10 +655,12 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) #if !MESHTASTIC_EXCLUDE_MQTT // Mark as pki_encrypted if it is not yet decoded and MQTT encryption is also enabled, hash matches and it's a DM not to // us (because we would be able to decrypt it) - if (!decoded && moduleConfig.mqtt.encryption_enabled && p->channel == 0x00 && !isBroadcast(p->to) && !isToUs(p)) + if (decodedState == DecodeState::DECODE_FAILURE && moduleConfig.mqtt.encryption_enabled && p->channel == 0x00 && + !isBroadcast(p->to) && !isToUs(p)) p_encrypted->pki_encrypted = true; // After potentially altering it, publish received message to MQTT if we're not the original transmitter of the packet - if ((decoded || p_encrypted->pki_encrypted) && moduleConfig.mqtt.enabled && !isFromUs(p) && mqtt) + if ((decodedState == DecodeState::DECODE_SUCCESS || p_encrypted->pki_encrypted) && moduleConfig.mqtt.enabled && + !isFromUs(p) && mqtt) mqtt->onSend(*p_encrypted, *p, p->channel); #endif } @@ -667,7 +688,7 @@ void Router::perhapsHandleReceived(meshtastic_MeshPacket *p) return; } - meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(p->from); + meshtastic_NodeInfoLite const *node = nodeDB->getMeshNode(p->from); if (node != NULL && node->is_ignored) { LOG_DEBUG("Ignore msg, 0x%x is ignored", p->from); packetPool.release(p); diff --git a/src/mesh/Router.h b/src/mesh/Router.h index bf6b77226..58ca50f3d 100644 --- a/src/mesh/Router.h +++ b/src/mesh/Router.h @@ -85,6 +85,7 @@ class Router : protected concurrency::OSThread, protected PacketHistory * NOTE: This method will free the provided packet (even if we return an error code) */ virtual ErrorCode send(meshtastic_MeshPacket *p); + virtual ErrorCode rawSend(meshtastic_MeshPacket *p); /* Statistics for the amount of duplicate received packets and the amount of times we cancel a relay because someone did it before us */ @@ -139,12 +140,14 @@ class Router : protected concurrency::OSThread, protected PacketHistory void abortSendAndNak(meshtastic_Routing_Error err, meshtastic_MeshPacket *p); }; +enum DecodeState { DECODE_SUCCESS, DECODE_FAILURE, DECODE_FATAL }; + /** FIXME - move this into a mesh packet class * Remove any encryption and decode the protobufs inside this packet (if necessary). * * @return true for success, false for corrupt packet. */ -bool perhapsDecode(meshtastic_MeshPacket *p); +DecodeState perhapsDecode(meshtastic_MeshPacket *p); /** Return 0 for success or a Routing_Error code for failure */ diff --git a/src/mesh/STM32WLE5JCInterface.cpp b/src/mesh/STM32WLE5JCInterface.cpp index ad1f675b6..6a340dd28 100644 --- a/src/mesh/STM32WLE5JCInterface.cpp +++ b/src/mesh/STM32WLE5JCInterface.cpp @@ -18,8 +18,10 @@ bool STM32WLE5JCInterface::init() { RadioLibInterface::init(); - // https://github.com/Seeed-Studio/LoRaWan-E5-Node/blob/main/Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver/radio_driver.c +// https://github.com/Seeed-Studio/LoRaWan-E5-Node/blob/main/Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver/radio_driver.c +#if (!defined(_VARIANT_RAK3172_)) setTCXOVoltage(1.7); +#endif lora.setRfSwitchTable(rfswitch_pins, rfswitch_table); @@ -42,4 +44,4 @@ bool STM32WLE5JCInterface::init() return res == RADIOLIB_ERR_NONE; } -#endif // ARCH_STM32WL \ No newline at end of file +#endif // ARCH_STM32WL diff --git a/src/mesh/api/PacketAPI.cpp b/src/mesh/api/PacketAPI.cpp index 45bbe19d3..4f0fbaf97 100644 --- a/src/mesh/api/PacketAPI.cpp +++ b/src/mesh/api/PacketAPI.cpp @@ -89,18 +89,20 @@ bool PacketAPI::receivePacket(void) bool PacketAPI::sendPacket(void) { - // fill dummy buffer; we don't use it, we directly send the fromRadio structure - uint32_t len = getFromRadio(txBuf); - if (len != 0) { - static uint32_t id = 0; - fromRadioScratch.id = ++id; - bool result = server->sendPacket(DataPacket(id, fromRadioScratch)); - if (!result) { - LOG_ERROR("send queue full"); + if (server->available()) { + // fill dummy buffer; we don't use it, we directly send the fromRadio structure + uint32_t len = getFromRadio(txBuf); + if (len != 0) { + static uint32_t id = 0; + fromRadioScratch.id = ++id; + bool result = server->sendPacket(DataPacket(id, fromRadioScratch)); + if (!result) { + LOG_ERROR("send queue full"); + } + return result; } - return result; - } else - return false; + } + return false; } bool PacketAPI::notifyProgrammingMode(void) diff --git a/src/mesh/api/WiFiServerAPI.h b/src/mesh/api/WiFiServerAPI.h index 6e60bb678..5f2019983 100644 --- a/src/mesh/api/WiFiServerAPI.h +++ b/src/mesh/api/WiFiServerAPI.h @@ -3,6 +3,11 @@ #include "ServerAPI.h" #include +#if HAS_ETHERNET && defined(USE_WS5500) +#include +#define ETH ETH2 +#endif // HAS_ETHERNET + /** * Provides both debug printing and, if the client starts sending protobufs to us, switches to send/receive protobufs * (and starts dropping debug printing - FIXME, eventually those prints should be encapsulated in protobufs). diff --git a/src/mesh/api/ethServerAPI.cpp b/src/mesh/api/ethServerAPI.cpp index a8701848a..0ccf92df7 100644 --- a/src/mesh/api/ethServerAPI.cpp +++ b/src/mesh/api/ethServerAPI.cpp @@ -1,7 +1,7 @@ #include "configuration.h" #include -#if HAS_ETHERNET +#if HAS_ETHERNET && !defined(USE_WS5500) #include "ethServerAPI.h" diff --git a/src/mesh/api/ethServerAPI.h b/src/mesh/api/ethServerAPI.h index 9d25a2fc1..c616c87be 100644 --- a/src/mesh/api/ethServerAPI.h +++ b/src/mesh/api/ethServerAPI.h @@ -1,6 +1,7 @@ #pragma once #include "ServerAPI.h" +#ifndef USE_WS5500 #include /** @@ -23,3 +24,4 @@ class ethServerPort : public APIServerPort }; void initApiServer(int port = SERVER_API_DEFAULT_PORT); +#endif diff --git a/src/mesh/generated/meshtastic/admin.pb.h b/src/mesh/generated/meshtastic/admin.pb.h index 02d50127e..efe60f493 100644 --- a/src/mesh/generated/meshtastic/admin.pb.h +++ b/src/mesh/generated/meshtastic/admin.pb.h @@ -34,7 +34,7 @@ typedef enum _meshtastic_AdminMessage_ConfigType { meshtastic_AdminMessage_ConfigType_BLUETOOTH_CONFIG = 6, /* TODO: REPLACE */ meshtastic_AdminMessage_ConfigType_SECURITY_CONFIG = 7, - /* */ + /* Session key config */ meshtastic_AdminMessage_ConfigType_SESSIONKEY_CONFIG = 8, /* device-ui config */ meshtastic_AdminMessage_ConfigType_DEVICEUI_CONFIG = 9 diff --git a/src/mesh/generated/meshtastic/config.pb.h b/src/mesh/generated/meshtastic/config.pb.h index 4747ddb5a..848f8df86 100644 --- a/src/mesh/generated/meshtastic/config.pb.h +++ b/src/mesh/generated/meshtastic/config.pb.h @@ -374,7 +374,7 @@ typedef struct _meshtastic_Config_PositionConfig { /* Power Config\ See [Power Config](/docs/settings/config/power) for additional power config details. */ typedef struct _meshtastic_Config_PowerConfig { - /* Description: Will sleep everything as much as possible, for the tracker and sensor role this will also include the lora radio. + /* Description: Will sleep everything as much as possible, for the tracker and sensor role this will also include the lora radio. Don't use this setting if you want to use your device with the phone apps or are using a device without a user button. Technical Details: Works for ESP32 devices and NRF52 devices in the Sensor or Tracker roles */ bool is_power_saving; @@ -426,7 +426,7 @@ typedef struct _meshtastic_Config_NetworkConfig { char wifi_ssid[33]; /* If set, will be use to authenticate to the named wifi */ char wifi_psk[65]; - /* NTP server to use if WiFi is conneced, defaults to `0.pool.ntp.org` */ + /* NTP server to use if WiFi is conneced, defaults to `meshtastic.pool.ntp.org` */ char ntp_server[33]; /* Enable Ethernet */ bool eth_enabled; diff --git a/src/mesh/generated/meshtastic/device_ui.pb.h b/src/mesh/generated/meshtastic/device_ui.pb.h index 8cfc0b8cd..5692a2749 100644 --- a/src/mesh/generated/meshtastic/device_ui.pb.h +++ b/src/mesh/generated/meshtastic/device_ui.pb.h @@ -53,6 +53,8 @@ typedef enum _meshtastic_Language { meshtastic_Language_NORWEGIAN = 14, /* Slovenian */ meshtastic_Language_SLOVENIAN = 15, + /* Ukrainian */ + meshtastic_Language_UKRAINIAN = 16, /* Simplified Chinese (experimental) */ meshtastic_Language_SIMPLIFIED_CHINESE = 30, /* Traditional Chinese (experimental) */ diff --git a/src/mesh/generated/meshtastic/interdevice.pb.cpp b/src/mesh/generated/meshtastic/interdevice.pb.cpp new file mode 100644 index 000000000..e3913f78c --- /dev/null +++ b/src/mesh/generated/meshtastic/interdevice.pb.cpp @@ -0,0 +1,17 @@ +/* Automatically generated nanopb constant definitions */ +/* Generated by nanopb-0.4.9.1 */ + +#include "meshtastic/interdevice.pb.h" +#if PB_PROTO_HEADER_VERSION != 40 +#error Regenerate this file with the current version of nanopb generator. +#endif + +PB_BIND(meshtastic_SensorData, meshtastic_SensorData, AUTO) + + +PB_BIND(meshtastic_InterdeviceMessage, meshtastic_InterdeviceMessage, 2) + + + + + diff --git a/src/mesh/generated/meshtastic/interdevice.pb.h b/src/mesh/generated/meshtastic/interdevice.pb.h new file mode 100644 index 000000000..c381438eb --- /dev/null +++ b/src/mesh/generated/meshtastic/interdevice.pb.h @@ -0,0 +1,105 @@ +/* Automatically generated nanopb header */ +/* Generated by nanopb-0.4.9.1 */ + +#ifndef PB_MESHTASTIC_MESHTASTIC_INTERDEVICE_PB_H_INCLUDED +#define PB_MESHTASTIC_MESHTASTIC_INTERDEVICE_PB_H_INCLUDED +#include + +#if PB_PROTO_HEADER_VERSION != 40 +#error Regenerate this file with the current version of nanopb generator. +#endif + +/* Enum definitions */ +typedef enum _meshtastic_MessageType { + meshtastic_MessageType_ACK = 0, + meshtastic_MessageType_COLLECT_INTERVAL = 160, /* in ms */ + meshtastic_MessageType_BEEP_ON = 161, /* duration ms */ + meshtastic_MessageType_BEEP_OFF = 162, /* cancel prematurely */ + meshtastic_MessageType_SHUTDOWN = 163, + meshtastic_MessageType_POWER_ON = 164, + meshtastic_MessageType_SCD41_TEMP = 176, + meshtastic_MessageType_SCD41_HUMIDITY = 177, + meshtastic_MessageType_SCD41_CO2 = 178, + meshtastic_MessageType_AHT20_TEMP = 179, + meshtastic_MessageType_AHT20_HUMIDITY = 180, + meshtastic_MessageType_TVOC_INDEX = 181 +} meshtastic_MessageType; + +/* Struct definitions */ +typedef struct _meshtastic_SensorData { + /* The message type */ + meshtastic_MessageType type; + pb_size_t which_data; + union { + float float_value; + uint32_t uint32_value; + } data; +} meshtastic_SensorData; + +typedef struct _meshtastic_InterdeviceMessage { + pb_size_t which_data; + union { + char nmea[1024]; + meshtastic_SensorData sensor; + } data; +} meshtastic_InterdeviceMessage; + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Helper constants for enums */ +#define _meshtastic_MessageType_MIN meshtastic_MessageType_ACK +#define _meshtastic_MessageType_MAX meshtastic_MessageType_TVOC_INDEX +#define _meshtastic_MessageType_ARRAYSIZE ((meshtastic_MessageType)(meshtastic_MessageType_TVOC_INDEX+1)) + +#define meshtastic_SensorData_type_ENUMTYPE meshtastic_MessageType + + + +/* Initializer values for message structs */ +#define meshtastic_SensorData_init_default {_meshtastic_MessageType_MIN, 0, {0}} +#define meshtastic_InterdeviceMessage_init_default {0, {""}} +#define meshtastic_SensorData_init_zero {_meshtastic_MessageType_MIN, 0, {0}} +#define meshtastic_InterdeviceMessage_init_zero {0, {""}} + +/* Field tags (for use in manual encoding/decoding) */ +#define meshtastic_SensorData_type_tag 1 +#define meshtastic_SensorData_float_value_tag 2 +#define meshtastic_SensorData_uint32_value_tag 3 +#define meshtastic_InterdeviceMessage_nmea_tag 1 +#define meshtastic_InterdeviceMessage_sensor_tag 2 + +/* Struct field encoding specification for nanopb */ +#define meshtastic_SensorData_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, UENUM, type, 1) \ +X(a, STATIC, ONEOF, FLOAT, (data,float_value,data.float_value), 2) \ +X(a, STATIC, ONEOF, UINT32, (data,uint32_value,data.uint32_value), 3) +#define meshtastic_SensorData_CALLBACK NULL +#define meshtastic_SensorData_DEFAULT NULL + +#define meshtastic_InterdeviceMessage_FIELDLIST(X, a) \ +X(a, STATIC, ONEOF, STRING, (data,nmea,data.nmea), 1) \ +X(a, STATIC, ONEOF, MESSAGE, (data,sensor,data.sensor), 2) +#define meshtastic_InterdeviceMessage_CALLBACK NULL +#define meshtastic_InterdeviceMessage_DEFAULT NULL +#define meshtastic_InterdeviceMessage_data_sensor_MSGTYPE meshtastic_SensorData + +extern const pb_msgdesc_t meshtastic_SensorData_msg; +extern const pb_msgdesc_t meshtastic_InterdeviceMessage_msg; + +/* Defines for backwards compatibility with code written before nanopb-0.4.0 */ +#define meshtastic_SensorData_fields &meshtastic_SensorData_msg +#define meshtastic_InterdeviceMessage_fields &meshtastic_InterdeviceMessage_msg + +/* Maximum encoded size of messages (where known) */ +#define MESHTASTIC_MESHTASTIC_INTERDEVICE_PB_H_MAX_SIZE meshtastic_InterdeviceMessage_size +#define meshtastic_InterdeviceMessage_size 1026 +#define meshtastic_SensorData_size 9 + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/src/mesh/generated/meshtastic/mesh.pb.h b/src/mesh/generated/meshtastic/mesh.pb.h index 3353a020f..defaaad28 100644 --- a/src/mesh/generated/meshtastic/mesh.pb.h +++ b/src/mesh/generated/meshtastic/mesh.pb.h @@ -159,7 +159,7 @@ typedef enum _meshtastic_HardwareModel { meshtastic_HardwareModel_TD_LORAC = 60, /* CDEBYTE EoRa-S3 board using their own MM modules, clone of LILYGO T3S3 */ meshtastic_HardwareModel_CDEBYTE_EORA_S3 = 61, - /* TWC_MESH_V4 + /* TWC_MESH_V4 Adafruit NRF52840 feather express with SX1262, SSD1306 OLED and NEO6M GPS */ meshtastic_HardwareModel_TWC_MESH_V4 = 62, /* NRF52_PROMICRO_DIY @@ -226,6 +226,17 @@ typedef enum _meshtastic_HardwareModel { /* MeshLink board developed by LoraItalia. NRF52840, eByte E22900M22S (Will also come with other frequencies), 25w MPPT solar charger (5v,12v,18v selectable), support for gps, buzzer, oled or e-ink display, 10 gpios, hardware watchdog https://www.loraitalia.it */ meshtastic_HardwareModel_MESHLINK = 87, + /* Seeed XIAO nRF52840 + Wio SX1262 kit */ + meshtastic_HardwareModel_XIAO_NRF52_KIT = 88, + /* Elecrow ThinkNode M1 & M2 + https://www.elecrow.com/wiki/ThinkNode-M1_Transceiver_Device(Meshtastic)_Power_By_nRF52840.html + https://www.elecrow.com/wiki/ThinkNode-M2_Transceiver_Device(Meshtastic)_Power_By_NRF52840.html (this actually uses ESP32-S3) */ + meshtastic_HardwareModel_THINKNODE_M1 = 89, + meshtastic_HardwareModel_THINKNODE_M2 = 90, + /* Lilygo T-ETH-Elite */ + meshtastic_HardwareModel_T_ETH_ELITE = 91, + /* Heltec HRI-3621 industrial probe */ + meshtastic_HardwareModel_HELTEC_SENSOR_HUB = 92, /* ------------------------------------------------------------------------------------------------------------------------------------------ Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits. ------------------------------------------------------------------------------------------------------------------------------------------ */ @@ -315,7 +326,11 @@ typedef enum _meshtastic_ExcludedModules { /* Detection Sensor module */ meshtastic_ExcludedModules_DETECTIONSENSOR_CONFIG = 2048, /* Paxcounter module */ - meshtastic_ExcludedModules_PAXCOUNTER_CONFIG = 4096 + meshtastic_ExcludedModules_PAXCOUNTER_CONFIG = 4096, + /* Bluetooth config (not technically a module, but used to indicate bluetooth capabilities) */ + meshtastic_ExcludedModules_BLUETOOTH_CONFIG = 8192, + /* Network config (not technically a module, but used to indicate network capabilities) */ + meshtastic_ExcludedModules_NETWORK_CONFIG = 16384 } meshtastic_ExcludedModules; /* How the location was acquired: manual, onboard GPS, external (EUD) GPS */ @@ -767,7 +782,7 @@ typedef struct _meshtastic_MeshPacket { meshtastic_MeshPacket_public_key_t public_key; /* Indicates whether the packet was en/decrypted using PKI */ bool pki_encrypted; - /* Last byte of the node number of the node that should be used as the next hop in routing. + /* Last byte of the node number of the node that should be used as the next hop in routing. Set by the firmware internally, clients are not supposed to set this. */ uint8_t next_hop; /* Last byte of the node number of the node that will relay/relayed this packet. @@ -1111,8 +1126,8 @@ extern "C" { #define _meshtastic_CriticalErrorCode_ARRAYSIZE ((meshtastic_CriticalErrorCode)(meshtastic_CriticalErrorCode_FLASH_CORRUPTION_UNRECOVERABLE+1)) #define _meshtastic_ExcludedModules_MIN meshtastic_ExcludedModules_EXCLUDED_NONE -#define _meshtastic_ExcludedModules_MAX meshtastic_ExcludedModules_PAXCOUNTER_CONFIG -#define _meshtastic_ExcludedModules_ARRAYSIZE ((meshtastic_ExcludedModules)(meshtastic_ExcludedModules_PAXCOUNTER_CONFIG+1)) +#define _meshtastic_ExcludedModules_MAX meshtastic_ExcludedModules_NETWORK_CONFIG +#define _meshtastic_ExcludedModules_ARRAYSIZE ((meshtastic_ExcludedModules)(meshtastic_ExcludedModules_NETWORK_CONFIG+1)) #define _meshtastic_Position_LocSource_MIN meshtastic_Position_LocSource_LOC_UNSET #define _meshtastic_Position_LocSource_MAX meshtastic_Position_LocSource_LOC_EXTERNAL diff --git a/src/mesh/generated/meshtastic/portnums.pb.h b/src/mesh/generated/meshtastic/portnums.pb.h index d7dc47785..4e7c43e58 100644 --- a/src/mesh/generated/meshtastic/portnums.pb.h +++ b/src/mesh/generated/meshtastic/portnums.pb.h @@ -128,6 +128,9 @@ typedef enum _meshtastic_PortNum { meshtastic_PortNum_MAP_REPORT_APP = 73, /* PowerStress based monitoring support (for automated power consumption testing) */ meshtastic_PortNum_POWERSTRESS_APP = 74, + /* Reticulum Network Stack Tunnel App + ENCODING: Fragmented RNS Packet. Handled by Meshtastic RNS interface */ + meshtastic_PortNum_RETICULUM_TUNNEL_APP = 76, /* Private applications should use portnums >= 256. To simplify initial development and testing you can use "PRIVATE_APP" in your code without needing to rebuild protobuf files (via [regen-protos.sh](https://github.com/meshtastic/firmware/blob/master/bin/regen-protos.sh)) */ diff --git a/src/mesh/generated/meshtastic/telemetry.pb.h b/src/mesh/generated/meshtastic/telemetry.pb.h index bb612d870..69cdd33fe 100644 --- a/src/mesh/generated/meshtastic/telemetry.pb.h +++ b/src/mesh/generated/meshtastic/telemetry.pb.h @@ -83,7 +83,11 @@ typedef enum _meshtastic_TelemetrySensorType { /* High accuracy current and voltage */ meshtastic_TelemetrySensorType_INA226 = 34, /* DFRobot Gravity tipping bucket rain gauge */ - meshtastic_TelemetrySensorType_DFROBOT_RAIN = 35 + meshtastic_TelemetrySensorType_DFROBOT_RAIN = 35, + /* Infineon DPS310 High accuracy pressure and temperature */ + meshtastic_TelemetrySensorType_DPS310 = 36, + /* RAKWireless RAK12035 Soil Moisture Sensor Module */ + meshtastic_TelemetrySensorType_RAK12035 = 37 } meshtastic_TelemetrySensorType; /* Struct definitions */ @@ -170,6 +174,12 @@ typedef struct _meshtastic_EnvironmentMetrics { /* Rainfall in the last 24 hours in mm */ bool has_rainfall_24h; float rainfall_24h; + /* Soil moisture measured (% 1-100) */ + bool has_soil_moisture; + uint8_t soil_moisture; + /* Soil temperature measured (*C) */ + bool has_soil_temperature; + float soil_temperature; } meshtastic_EnvironmentMetrics; /* Power Metrics (voltage / current / etc) */ @@ -314,8 +324,8 @@ extern "C" { /* Helper constants for enums */ #define _meshtastic_TelemetrySensorType_MIN meshtastic_TelemetrySensorType_SENSOR_UNSET -#define _meshtastic_TelemetrySensorType_MAX meshtastic_TelemetrySensorType_DFROBOT_RAIN -#define _meshtastic_TelemetrySensorType_ARRAYSIZE ((meshtastic_TelemetrySensorType)(meshtastic_TelemetrySensorType_DFROBOT_RAIN+1)) +#define _meshtastic_TelemetrySensorType_MAX meshtastic_TelemetrySensorType_RAK12035 +#define _meshtastic_TelemetrySensorType_ARRAYSIZE ((meshtastic_TelemetrySensorType)(meshtastic_TelemetrySensorType_RAK12035+1)) @@ -328,7 +338,7 @@ extern "C" { /* Initializer values for message structs */ #define meshtastic_DeviceMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0} -#define meshtastic_EnvironmentMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} +#define meshtastic_EnvironmentMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_PowerMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_AirQualityMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_LocalStats_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} @@ -336,7 +346,7 @@ extern "C" { #define meshtastic_Telemetry_init_default {0, 0, {meshtastic_DeviceMetrics_init_default}} #define meshtastic_Nau7802Config_init_default {0, 0} #define meshtastic_DeviceMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0} -#define meshtastic_EnvironmentMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} +#define meshtastic_EnvironmentMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_PowerMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_AirQualityMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_LocalStats_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} @@ -370,6 +380,8 @@ extern "C" { #define meshtastic_EnvironmentMetrics_radiation_tag 18 #define meshtastic_EnvironmentMetrics_rainfall_1h_tag 19 #define meshtastic_EnvironmentMetrics_rainfall_24h_tag 20 +#define meshtastic_EnvironmentMetrics_soil_moisture_tag 21 +#define meshtastic_EnvironmentMetrics_soil_temperature_tag 22 #define meshtastic_PowerMetrics_ch1_voltage_tag 1 #define meshtastic_PowerMetrics_ch1_current_tag 2 #define meshtastic_PowerMetrics_ch2_voltage_tag 3 @@ -443,7 +455,9 @@ X(a, STATIC, OPTIONAL, FLOAT, wind_gust, 16) \ X(a, STATIC, OPTIONAL, FLOAT, wind_lull, 17) \ X(a, STATIC, OPTIONAL, FLOAT, radiation, 18) \ X(a, STATIC, OPTIONAL, FLOAT, rainfall_1h, 19) \ -X(a, STATIC, OPTIONAL, FLOAT, rainfall_24h, 20) +X(a, STATIC, OPTIONAL, FLOAT, rainfall_24h, 20) \ +X(a, STATIC, OPTIONAL, UINT32, soil_moisture, 21) \ +X(a, STATIC, OPTIONAL, FLOAT, soil_temperature, 22) #define meshtastic_EnvironmentMetrics_CALLBACK NULL #define meshtastic_EnvironmentMetrics_DEFAULT NULL @@ -542,12 +556,12 @@ extern const pb_msgdesc_t meshtastic_Nau7802Config_msg; #define MESHTASTIC_MESHTASTIC_TELEMETRY_PB_H_MAX_SIZE meshtastic_Telemetry_size #define meshtastic_AirQualityMetrics_size 78 #define meshtastic_DeviceMetrics_size 27 -#define meshtastic_EnvironmentMetrics_size 103 +#define meshtastic_EnvironmentMetrics_size 113 #define meshtastic_HealthMetrics_size 11 #define meshtastic_LocalStats_size 60 #define meshtastic_Nau7802Config_size 16 #define meshtastic_PowerMetrics_size 30 -#define meshtastic_Telemetry_size 110 +#define meshtastic_Telemetry_size 120 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index d9856e157..5f6ad9eb3 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -12,6 +12,11 @@ #include #include +#if HAS_ETHERNET && defined(USE_WS5500) +#include +#define ETH ETH2 +#endif // HAS_ETHERNET + #ifdef ARCH_ESP32 #include "esp_task_wdt.h" #endif @@ -166,14 +171,14 @@ WebServerThread *webServerThread; WebServerThread::WebServerThread() : concurrency::OSThread("WebServer") { - if (!config.network.wifi_enabled) { + if (!config.network.wifi_enabled && !config.network.eth_enabled) { disable(); } } int32_t WebServerThread::runOnce() { - if (!config.network.wifi_enabled) { + if (!config.network.wifi_enabled && !config.network.eth_enabled) { disable(); } diff --git a/src/mesh/mesh-pb-constants.h b/src/mesh/mesh-pb-constants.h index f91c48560..f748d295e 100644 --- a/src/mesh/mesh-pb-constants.h +++ b/src/mesh/mesh-pb-constants.h @@ -18,10 +18,34 @@ #define MAX_RX_TOPHONE 32 #endif -/// max number of nodes allowed in the mesh +/// Verify baseline assumption of node size. If it increases, we need to reevaluate +/// the impact of its memory footprint, notably on MAX_NUM_NODES. +static_assert(sizeof(meshtastic_NodeInfoLite) <= 192, "NodeInfoLite size increased. Reconsider impact on MAX_NUM_NODES."); + +/// max number of nodes allowed in the nodeDB #ifndef MAX_NUM_NODES +#if defined(ARCH_STM32WL) +#define MAX_NUM_NODES 10 +#elif defined(ARCH_NRF52) +#define MAX_NUM_NODES 80 +#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#include "Esp.h" +static inline int get_max_num_nodes() +{ + uint32_t flash_size = ESP.getFlashChipSize() / (1024 * 1024); // Convert Bytes to MB + if (flash_size >= 15) { + return 250; + } else if (flash_size >= 7) { + return 200; + } else { + return 100; + } +} +#define MAX_NUM_NODES get_max_num_nodes() +#else #define MAX_NUM_NODES 100 #endif +#endif /// Max number of channels allowed #define MAX_NUM_CHANNELS (member_size(meshtastic_ChannelFile, channels) / member_size(meshtastic_ChannelFile, channels[0])) diff --git a/src/mesh/udp/UdpMulticastThread.h b/src/mesh/udp/UdpMulticastThread.h index 9128d3b5c..88824dc4d 100644 --- a/src/mesh/udp/UdpMulticastThread.h +++ b/src/mesh/udp/UdpMulticastThread.h @@ -7,6 +7,11 @@ #include #include +#if HAS_ETHERNET && defined(USE_WS5500) +#include +#define ETH ETH2 +#endif // HAS_ETHERNET + #define UDP_MULTICAST_DEFAUL_PORT 4403 // Default port for UDP multicast is same as TCP api server #define UDP_MULTICAST_THREAD_INTERVAL_MS 15000 @@ -17,8 +22,13 @@ class UdpMulticastThread : public concurrency::OSThread void start() { - if (udp.listenMulticast(udpIpAddress, UDP_MULTICAST_DEFAUL_PORT)) { + if (udp.listenMulticast(udpIpAddress, UDP_MULTICAST_DEFAUL_PORT, 64)) { +#ifndef ARCH_PORTDUINO + // FIXME(PORTDUINO): arduino lacks IPAddress::toString() LOG_DEBUG("UDP Listening on IP: %s", WiFi.localIP().toString().c_str()); +#else + LOG_DEBUG("UDP Listening"); +#endif udp.onPacket([this](AsyncUDPPacket packet) { onReceive(packet); }); } else { LOG_DEBUG("Failed to listen on UDP"); @@ -28,12 +38,13 @@ class UdpMulticastThread : public concurrency::OSThread void onReceive(AsyncUDPPacket packet) { size_t packetLength = packet.length(); +#ifndef ARCH_PORTDUINO + // FIXME(PORTDUINO): arduino lacks IPAddress::toString() LOG_DEBUG("UDP broadcast from: %s, len=%u", packet.remoteIP().toString().c_str(), packetLength); +#endif meshtastic_MeshPacket mp; - uint8_t bytes[meshtastic_MeshPacket_size]; // Allocate buffer for the data - size_t packetSize = packet.readBytes(bytes, packet.length()); - LOG_DEBUG("Decoding MeshPacket from UDP len=%u", packetSize); - bool isPacketDecoded = pb_decode_from_bytes(bytes, packetLength, &meshtastic_MeshPacket_msg, &mp); + LOG_DEBUG("Decoding MeshPacket from UDP len=%u", packetLength); + bool isPacketDecoded = pb_decode_from_bytes(packet.data(), packetLength, &meshtastic_MeshPacket_msg, &mp); if (isPacketDecoded && router) { UniquePacketPoolPacket p = packetPool.allocUniqueCopy(mp); // Unset received SNR/RSSI @@ -45,13 +56,18 @@ class UdpMulticastThread : public concurrency::OSThread bool onSend(const meshtastic_MeshPacket *mp) { - if (!mp || WiFi.status() != WL_CONNECTED) { + if (!mp || !udp) { return false; } +#ifndef ARCH_PORTDUINO + if (WiFi.status() != WL_CONNECTED) { + return false; + } +#endif LOG_DEBUG("Broadcasting packet over UDP (id=%u)", mp->id); uint8_t buffer[meshtastic_MeshPacket_size]; size_t encodedLength = pb_encode_to_bytes(buffer, sizeof(buffer), &meshtastic_MeshPacket_msg, mp); - udp.broadcastTo(buffer, encodedLength, UDP_MULTICAST_DEFAUL_PORT); + udp.writeTo(buffer, encodedLength, udpIpAddress, UDP_MULTICAST_DEFAUL_PORT); return true; } @@ -67,4 +83,4 @@ class UdpMulticastThread : public concurrency::OSThread IPAddress udpIpAddress; AsyncUDP udp; }; -#endif // ARCH_ESP32 \ No newline at end of file +#endif // HAS_UDP_MULTICAST \ No newline at end of file diff --git a/src/mesh/wifi/WiFiAPClient.cpp b/src/mesh/wifi/WiFiAPClient.cpp index ee50ee56f..e050c2057 100644 --- a/src/mesh/wifi/WiFiAPClient.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -9,6 +9,12 @@ #include "mesh/api/WiFiServerAPI.h" #include "target_specific.h" #include + +#if HAS_ETHERNET && defined(USE_WS5500) +#include +#define ETH ETH2 +#endif // HAS_ETHERNET + #include #ifdef ARCH_ESP32 #if !MESHTASTIC_EXCLUDE_WEBSERVER @@ -52,11 +58,28 @@ Syslog syslog(syslogClient); Periodic *wifiReconnect; +#ifdef USE_WS5500 +// Startup Ethernet +bool initEthernet() +{ + if ((config.network.eth_enabled) && (ETH.begin(ETH_PHY_W5500, 1, ETH_CS_PIN, ETH_INT_PIN, ETH_RST_PIN, SPI3_HOST, + ETH_SCLK_PIN, ETH_MISO_PIN, ETH_MOSI_PIN))) { + WiFi.onEvent(WiFiEvent); +#if !MESHTASTIC_EXCLUDE_WEBSERVER + createSSLCert(); // For WebServer +#endif + return true; + } + + return false; +} +#endif + static void onNetworkConnected() { if (!APStartupComplete) { // Start web server - LOG_INFO("Start WiFi network services"); + LOG_INFO("Start network services"); // start mdns if (!MDNS.begin("Meshtastic")) { @@ -110,7 +133,7 @@ static void onNetworkConnected() } #if HAS_UDP_MULTICAST - if (udpThread) { + if (udpThread && config.network.enabled_protocols & meshtastic_Config_NetworkConfig_ProtocolFlags_UDP_BROADCAST) { udpThread->start(); } #endif @@ -140,7 +163,7 @@ static int32_t reconnectWiFi() delay(5000); if (!WiFi.isConnected()) { -#ifdef CONFIG_IDF_TARGET_ESP32C3 +#ifdef ARCH_ESP32 WiFi.mode(WIFI_MODE_NULL); WiFi.useStaticBuffers(true); WiFi.mode(WIFI_STA); @@ -188,6 +211,10 @@ bool isWifiAvailable() if (config.network.wifi_enabled && (config.network.wifi_ssid[0])) { return true; +#ifdef USE_WS5500 + } else if (config.network.eth_enabled) { + return true; +#endif } else { return false; } @@ -282,7 +309,7 @@ bool initWifi() // Called by the Espressif SDK to static void WiFiEvent(WiFiEvent_t event) { - LOG_DEBUG("WiFi-Event %d: ", event); + LOG_DEBUG("Network-Event %d: ", event); switch (event) { case ARDUINO_EVENT_WIFI_READY: @@ -377,19 +404,32 @@ static void WiFiEvent(WiFiEvent_t event) LOG_INFO("Ethernet started"); break; case ARDUINO_EVENT_ETH_STOP: + syslog.disable(); LOG_INFO("Ethernet stopped"); break; case ARDUINO_EVENT_ETH_CONNECTED: LOG_INFO("Ethernet connected"); break; case ARDUINO_EVENT_ETH_DISCONNECTED: + syslog.disable(); LOG_INFO("Ethernet disconnected"); break; case ARDUINO_EVENT_ETH_GOT_IP: - LOG_INFO("Obtained IP address (ARDUINO_EVENT_ETH_GOT_IP)"); +#ifdef USE_WS5500 + LOG_INFO("Obtained IP address: %s, %u Mbps, %s", ETH.localIP().toString().c_str(), ETH.linkSpeed(), + ETH.fullDuplex() ? "FULL_DUPLEX" : "HALF_DUPLEX"); + onNetworkConnected(); +#endif break; case ARDUINO_EVENT_ETH_GOT_IP6: - LOG_INFO("Obtained IP6 address (ARDUINO_EVENT_ETH_GOT_IP6)"); +#ifdef USE_WS5500 +#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0) + LOG_INFO("Obtained Local IP6 address: %s", ETH.linkLocalIPv6().toString().c_str()); + LOG_INFO("Obtained GlobalIP6 address: %s", ETH.globalIPv6().toString().c_str()); +#else + LOG_INFO("Obtained IP6 address: %s", ETH.localIPv6().toString().c_str()); +#endif +#endif break; case ARDUINO_EVENT_SC_SCAN_DONE: LOG_INFO("SmartConfig: Scan done"); diff --git a/src/mesh/wifi/WiFiAPClient.h b/src/mesh/wifi/WiFiAPClient.h index 5f4e2f5c9..078c40193 100644 --- a/src/mesh/wifi/WiFiAPClient.h +++ b/src/mesh/wifi/WiFiAPClient.h @@ -9,6 +9,11 @@ #include #endif +#if HAS_ETHERNET && defined(USE_WS5500) +#include +#define ETH ETH2 +#endif // HAS_ETHERNET + extern bool needReconnect; extern concurrency::Periodic *wifiReconnect; @@ -19,4 +24,9 @@ void deinitWifi(); bool isWifiAvailable(); -uint8_t getWifiDisconnectReason(); \ No newline at end of file +uint8_t getWifiDisconnectReason(); + +#ifdef USE_WS5500 +// Startup Ethernet +bool initEthernet(); +#endif \ No newline at end of file diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 913374bbc..052aec66a 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -10,6 +10,9 @@ #if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_BLUETOOTH #include "BleOta.h" #endif +#if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_WIFI +#include "WiFiOTA.h" +#endif #include "Router.h" #include "configuration.h" #include "main.h" @@ -194,19 +197,23 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } case meshtastic_AdminMessage_reboot_ota_seconds_tag: { int32_t s = r->reboot_ota_seconds; -#if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_BLUETOOTH - if (BleOta::getOtaAppVersion().isEmpty()) { - LOG_INFO("No OTA firmware available, scheduling regular reboot in %d seconds", s); - screen->startAlert("Rebooting..."); - } else { +#if defined(ARCH_ESP32) +#if !MESHTASTIC_EXCLUDE_BLUETOOTH + if (!BleOta::getOtaAppVersion().isEmpty()) { screen->startFirmwareUpdateScreen(); BleOta::switchToOtaApp(); - LOG_INFO("Reboot to OTA in %d seconds", s); + LOG_INFO("Rebooting to BLE OTA"); } -#else - LOG_INFO("Not on ESP32, scheduling regular reboot in %d seconds", s); - screen->startAlert("Rebooting..."); #endif +#if !MESHTASTIC_EXCLUDE_WIFI + if (WiFiOTA::trySwitchToOTA()) { + screen->startFirmwareUpdateScreen(); + WiFiOTA::saveConfig(&config.network); + LOG_INFO("Rebooting to WiFi OTA"); + } +#endif +#endif + LOG_INFO("Reboot in %d seconds", s); rebootAtMsec = (s < 0) ? 0 : (millis() + s * 1000); break; } @@ -258,7 +265,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta disableBluetooth(); LOG_INFO("Commit transaction for edited settings"); hasOpenEditTransaction = false; - saveChanges(SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS); + saveChanges(SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS | SEGMENT_NODEDATABASE); break; } case meshtastic_AdminMessage_get_device_connection_status_request_tag: { @@ -327,7 +334,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta node->position = TypeConversions::ConvertToPositionLite(r->set_fixed_position); nodeDB->setLocalPosition(r->set_fixed_position); config.position.fixed_position = true; - saveChanges(SEGMENT_DEVICESTATE | SEGMENT_NODEDATABASE | SEGMENT_CONFIG, false); + saveChanges(SEGMENT_NODEDATABASE | SEGMENT_CONFIG, false); #if !MESHTASTIC_EXCLUDE_GPS if (gps != nullptr) gps->enable(); @@ -340,7 +347,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta LOG_INFO("Client received remove_fixed_position command"); nodeDB->clearLocalPosition(); config.position.fixed_position = false; - saveChanges(SEGMENT_DEVICESTATE | SEGMENT_NODEDATABASE | SEGMENT_CONFIG, false); + saveChanges(SEGMENT_NODEDATABASE | SEGMENT_CONFIG, false); break; } case meshtastic_AdminMessage_set_time_only_tag: { @@ -370,6 +377,42 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta LOG_DEBUG("Failed to delete file"); } spiLock->unlock(); +#endif + break; + } + case meshtastic_AdminMessage_backup_preferences_tag: { + LOG_INFO("Client requesting to backup preferences"); + if (nodeDB->backupPreferences(r->backup_preferences)) { + myReply = allocErrorResponse(meshtastic_Routing_Error_NONE, &mp); + } else { + myReply = allocErrorResponse(meshtastic_Routing_Error_BAD_REQUEST, &mp); + } + break; + } + case meshtastic_AdminMessage_restore_preferences_tag: { + LOG_INFO("Client requesting to restore preferences"); + if (nodeDB->restorePreferences(r->backup_preferences, + SEGMENT_DEVICESTATE | SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_CHANNELS)) { + myReply = allocErrorResponse(meshtastic_Routing_Error_NONE, &mp); + LOG_DEBUG("Rebooting after successful restore of preferences"); + reboot(1000); + disableBluetooth(); + } else { + myReply = allocErrorResponse(meshtastic_Routing_Error_BAD_REQUEST, &mp); + } + break; + } + case meshtastic_AdminMessage_remove_backup_preferences_tag: { + LOG_INFO("Client requesting to remove backup preferences"); +#ifdef FSCom + if (r->remove_backup_preferences == meshtastic_AdminMessage_BackupLocation_FLASH) { + spiLock->lock(); + FSCom.remove(backupFileName); + spiLock->unlock(); + } else if (r->remove_backup_preferences == meshtastic_AdminMessage_BackupLocation_SD) { + // TODO: After more mainline SD card support + LOG_ERROR("SD backup removal not implemented yet"); + } #endif break; } @@ -531,7 +574,6 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) config.has_position = true; config.position = c.payload_variant.position; // Save nodedb as well in case we got a fixed position packet - saveChanges(SEGMENT_DEVICESTATE, false); break; case meshtastic_Config_power_tag: LOG_INFO("Set config: Power"); @@ -645,6 +687,14 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) #if !MESHTASTIC_EXCLUDE_PKI crypto->setDHPrivateKey(config.security.private_key.bytes); #endif + if (config.security.is_managed && !(config.security.admin_key[0].size == 32 || config.security.admin_key[1].size == 32 || + config.security.admin_key[2].size == 32)) { + config.security.is_managed = false; + const char *warning = "You must provide at least one admin public key to enable managed mode"; + LOG_WARN(warning); + sendWarning(warning); + } + if (config.security.debug_log_api_enabled == c.payload_variant.security.debug_log_api_enabled && config.security.serial_enabled == c.payload_variant.security.serial_enabled) requiresReboot = false; @@ -988,7 +1038,7 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r } #endif -#if HAS_ETHERNET +#if HAS_ETHERNET && !defined(USE_WS5500) conn.has_ethernet = true; conn.ethernet.has_status = true; if (Ethernet.linkStatus() == LinkON) { diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 5fb32fff5..2a5ec00ab 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -1057,6 +1057,11 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st display->drawString(10 + x, 0 + y + FONT_HEIGHT_SMALL, "Canned Message\nModule disabled."); } else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) { requestFocus(); // Tell Screen::setFrames to move to our module's frame +#if defined(USE_EINK) && defined(USE_EINK_DYNAMICDISPLAY) + EInkDynamicDisplay *einkDisplay = static_cast(display); + einkDisplay->enableUnlimitedFastMode(); // Enable unlimited fast refresh while typing +#endif + #if defined(USE_VIRTUAL_KEYBOARD) drawKeyboard(display, state, 0, 0); #else diff --git a/src/modules/Modules.cpp b/src/modules/Modules.cpp index f386147d0..e2a4a970c 100644 --- a/src/modules/Modules.cpp +++ b/src/modules/Modules.cpp @@ -7,7 +7,9 @@ #include "input/SerialKeyboardImpl.h" #include "input/TrackballInterruptImpl1.h" #include "input/UpDownInterruptImpl1.h" +#if !MESHTASTIC_EXCLUDE_I2C #include "input/cardKbI2cImpl.h" +#endif #include "input/kbMatrixImpl.h" #endif #if !MESHTASTIC_EXCLUDE_ADMIN diff --git a/src/modules/RangeTestModule.cpp b/src/modules/RangeTestModule.cpp index cad1d51f1..6f3d69acf 100644 --- a/src/modules/RangeTestModule.cpp +++ b/src/modules/RangeTestModule.cpp @@ -31,7 +31,7 @@ uint32_t packetSequence = 0; int32_t RangeTestModule::runOnce() { -#if defined(ARCH_ESP32) || defined(ARCH_NRF52) +#if defined(ARCH_ESP32) || defined(ARCH_NRF52) || defined(ARCH_PORTDUINO) /* Uncomment the preferences below if you want to use the module @@ -130,7 +130,7 @@ void RangeTestModuleRadio::sendPayload(NodeNum dest, bool wantReplies) ProcessMessage RangeTestModuleRadio::handleReceived(const meshtastic_MeshPacket &mp) { -#if defined(ARCH_ESP32) || defined(ARCH_NRF52) +#if defined(ARCH_ESP32) || defined(ARCH_NRF52) || defined(ARCH_PORTDUINO) if (moduleConfig.range_test.enabled) { diff --git a/src/modules/RoutingModule.cpp b/src/modules/RoutingModule.cpp index 34ef2ddd1..e7e92c79a 100644 --- a/src/modules/RoutingModule.cpp +++ b/src/modules/RoutingModule.cpp @@ -46,11 +46,6 @@ meshtastic_MeshPacket *RoutingModule::allocReply() return NULL; assert(currentRequest); - // We only consider making replies if the request was a legit routing packet (not just something we were sniffing) - if (currentRequest->decoded.portnum == meshtastic_PortNum_ROUTING_APP) { - assert(0); // 1.2 refactoring fixme, Not sure if anything needs this yet? - // return allocDataProtobuf(u); - } return NULL; } diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index c6a95912b..e088b4612 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -60,7 +60,7 @@ SerialModule *serialModule; SerialModuleRadio *serialModuleRadio; -#if defined(TTGO_T_ECHO) || defined(CANARYONE) || defined(MESHLINK) +#if defined(TTGO_T_ECHO) || defined(CANARYONE) || defined(MESHLINK) || defined(ELECROW_ThinkNode_M1) SerialModule::SerialModule() : StreamAPI(&Serial), concurrency::OSThread("Serial") {} static Print *serialPrint = &Serial; #elif defined(CONFIG_IDF_TARGET_ESP32C6) @@ -158,7 +158,7 @@ int32_t SerialModule::runOnce() Serial.begin(baud); Serial.setTimeout(moduleConfig.serial.timeout > 0 ? moduleConfig.serial.timeout : TIMEOUT); } -#elif !defined(TTGO_T_ECHO) && !defined(CANARYONE) && !defined(MESHLINK) +#elif !defined(TTGO_T_ECHO) && !defined(CANARYONE) && !defined(MESHLINK) && !defined(ELECROW_ThinkNode_M1) if (moduleConfig.serial.rxd && moduleConfig.serial.txd) { #ifdef ARCH_RP2040 Serial2.setFIFOSize(RX_BUFFER); @@ -214,7 +214,7 @@ int32_t SerialModule::runOnce() } } -#if !defined(TTGO_T_ECHO) && !defined(CANARYONE) && !defined(MESHLINK) +#if !defined(TTGO_T_ECHO) && !defined(CANARYONE) && !defined(MESHLINK) && !defined(ELECROW_ThinkNode_M1) else if ((moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_WS85)) { processWXSerial(); @@ -408,6 +408,49 @@ uint32_t SerialModule::getBaudRate() return BAUD; } +// Add this structure to help with parsing WindGust = 24.4 serial lines. +struct ParsedLine { + String name; + String value; +}; + +/** + * Parse a line of format "Name = Value" into name/value pair + * @param line Input line to parse + * @return ParsedLine containing name and value, or empty strings if parse failed + */ +ParsedLine parseLine(const char *line) +{ + ParsedLine result = {"", ""}; + + // Find equals sign + const char *equals = strchr(line, '='); + if (!equals) { + return result; + } + + // Extract name by copying substring + char nameBuf[64]; // Temporary buffer + size_t nameLen = equals - line; + if (nameLen >= sizeof(nameBuf)) { + nameLen = sizeof(nameBuf) - 1; + } + strncpy(nameBuf, line, nameLen); + nameBuf[nameLen] = '\0'; + + // Create trimmed name string + String name = String(nameBuf); + name.trim(); + + // Extract value after equals sign + String value = String(equals + 1); + value.trim(); + + result.name = name; + result.value = value; + return result; +} + /** * Process the received weather station serial data, extract wind, voltage, and temperature information, * calculate averages and send telemetry data over the mesh network. @@ -416,7 +459,8 @@ uint32_t SerialModule::getBaudRate() */ void SerialModule::processWXSerial() { -#if !defined(TTGO_T_ECHO) && !defined(CANARYONE) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(MESHLINK) +#if !defined(TTGO_T_ECHO) && !defined(CANARYONE) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(MESHLINK) && \ + !defined(ELECROW_ThinkNode_M1) static unsigned int lastAveraged = 0; static unsigned int averageIntervalMillis = 300000; // 5 minutes hard coded. static double dir_sum_sin = 0; @@ -435,6 +479,10 @@ void SerialModule::processWXSerial() static float batVoltageF = 0; static float capVoltageF = 0; static float temperatureF = 0; + + static char rainStr[] = "5780860000"; + static int rainSum = 0; + static float rain = 0; bool gotwind = false; while (Serial2.available()) { @@ -448,6 +496,10 @@ void SerialModule::processWXSerial() // WindSpeed = 0.5 // WindGust = 0.6 // GXTS04Temp = 24.4 + // Temperature = 23.4 // WS80 + + // RainIntSum = 0 + // Rain = 0.0 if (serialPayloadSize > 0) { // Define variables for line processing int lineStart = 0; @@ -461,64 +513,56 @@ void SerialModule::processWXSerial() // Extract the current line char line[meshtastic_Constants_DATA_PAYLOAD_LEN]; memset(line, '\0', sizeof(line)); - memcpy(line, &serialBytes[lineStart], lineEnd - lineStart); + if (lineEnd - lineStart < sizeof(line) - 1) { + memcpy(line, &serialBytes[lineStart], lineEnd - lineStart); - if (strstr(line, "Wind") != NULL) // we have a wind line - { - gotwind = true; - // Find the positions of "=" signs in the line - char *windDirPos = strstr(line, "WindDir = "); - char *windSpeedPos = strstr(line, "WindSpeed = "); - char *windGustPos = strstr(line, "WindGust = "); - - if (windDirPos != NULL) { - // Extract data after "=" for WindDir - strcpy(windDir, windDirPos + 15); // Add 15 to skip "WindDir = " - double radians = GeoCoord::toRadians(strtof(windDir, nullptr)); - dir_sum_sin += sin(radians); - dir_sum_cos += cos(radians); - dirCount++; - } else if (windSpeedPos != NULL) { - // Extract data after "=" for WindSpeed - strcpy(windVel, windSpeedPos + 15); // Add 15 to skip "WindSpeed = " - float newv = strtof(windVel, nullptr); - velSum += newv; - velCount++; - if (newv < lull || lull == -1) - lull = newv; - - } else if (windGustPos != NULL) { - strcpy(windGust, windGustPos + 15); // Add 15 to skip "WindSpeed = " - float newg = strtof(windGust, nullptr); - if (newg > gust) - gust = newg; + ParsedLine parsed = parseLine(line); + if (parsed.name.length() > 0) { + if (parsed.name == "WindDir") { + strlcpy(windDir, parsed.value.c_str(), sizeof(windDir)); + double radians = GeoCoord::toRadians(strtof(windDir, nullptr)); + dir_sum_sin += sin(radians); + dir_sum_cos += cos(radians); + dirCount++; + gotwind = true; + } else if (parsed.name == "WindSpeed") { + strlcpy(windVel, parsed.value.c_str(), sizeof(windVel)); + float newv = strtof(windVel, nullptr); + velSum += newv; + velCount++; + if (newv < lull || lull == -1) { + lull = newv; + } + gotwind = true; + } else if (parsed.name == "WindGust") { + strlcpy(windGust, parsed.value.c_str(), sizeof(windGust)); + float newg = strtof(windGust, nullptr); + if (newg > gust) { + gust = newg; + } + gotwind = true; + } else if (parsed.name == "BatVoltage") { + strlcpy(batVoltage, parsed.value.c_str(), sizeof(batVoltage)); + batVoltageF = strtof(batVoltage, nullptr); + break; // last possible data we want so break + } else if (parsed.name == "CapVoltage") { + strlcpy(capVoltage, parsed.value.c_str(), sizeof(capVoltage)); + capVoltageF = strtof(capVoltage, nullptr); + } else if (parsed.name == "GXTS04Temp" || parsed.name == "Temperature") { + strlcpy(temperature, parsed.value.c_str(), sizeof(temperature)); + temperatureF = strtof(temperature, nullptr); + } else if (parsed.name == "RainIntSum") { + strlcpy(rainStr, parsed.value.c_str(), sizeof(rainStr)); + rainSum = int(strtof(rainStr, nullptr)); + } else if (parsed.name == "Rain") { + strlcpy(rainStr, parsed.value.c_str(), sizeof(rainStr)); + rain = strtof(rainStr, nullptr); + } } - // these are also voltage data we care about possibly - } else if (strstr(line, "BatVoltage") != NULL) { // we have a battVoltage line - char *batVoltagePos = strstr(line, "BatVoltage = "); - if (batVoltagePos != NULL) { - strcpy(batVoltage, batVoltagePos + 17); // 18 for ws 80, 17 for ws85 - batVoltageF = strtof(batVoltage, nullptr); - break; // last possible data we want so break - } - } else if (strstr(line, "CapVoltage") != NULL) { // we have a cappVoltage line - char *capVoltagePos = strstr(line, "CapVoltage = "); - if (capVoltagePos != NULL) { - strcpy(capVoltage, capVoltagePos + 17); // 18 for ws 80, 17 for ws85 - capVoltageF = strtof(capVoltage, nullptr); - } - // GXTS04Temp = 24.4 - } else if (strstr(line, "GXTS04Temp") != NULL) { // we have a temperature line - char *tempPos = strstr(line, "GXTS04Temp = "); - if (tempPos != NULL) { - strcpy(temperature, tempPos + 15); // 15 spaces for ws85 - temperatureF = strtof(temperature, nullptr); - } + // Update lineStart for the next line + lineStart = lineEnd + 1; } - - // Update lineStart for the next line - lineStart = lineEnd + 1; } } break; @@ -530,8 +574,8 @@ void SerialModule::processWXSerial() } if (gotwind) { - LOG_INFO("WS85 : %i %.1fg%.1f %.1fv %.1fv %.1fC", atoi(windDir), strtof(windVel, nullptr), strtof(windGust, nullptr), - batVoltageF, capVoltageF, temperatureF); + LOG_INFO("WS8X : %i %.1fg%.1f %.1fv %.1fv %.1fC rain: %.1f, %i sum", atoi(windDir), strtof(windVel, nullptr), + strtof(windGust, nullptr), batVoltageF, capVoltageF, temperatureF, rain, rainSum); } if (gotwind && !Throttle::isWithinTimespanMs(lastAveraged, averageIntervalMillis)) { // calculate averages and send to the mesh @@ -568,12 +612,19 @@ void SerialModule::processWXSerial() m.variant.environment_metrics.wind_gust = gust; m.variant.environment_metrics.has_wind_gust = true; + m.variant.environment_metrics.rainfall_24h = rainSum; + m.variant.environment_metrics.has_rainfall_24h = true; + + // not sure if this value is actually the 1hr sum so needs to do some testing + m.variant.environment_metrics.rainfall_1h = rain; + m.variant.environment_metrics.has_rainfall_1h = true; + if (lull == -1) lull = 0; m.variant.environment_metrics.wind_lull = lull; m.variant.environment_metrics.has_wind_lull = true; - LOG_INFO("WS85 Transmit speed=%fm/s, direction=%d , lull=%f, gust=%f, voltage=%f temperature=%f", + LOG_INFO("WS8X Transmit speed=%fm/s, direction=%d , lull=%f, gust=%f, voltage=%f temperature=%f", m.variant.environment_metrics.wind_speed, m.variant.environment_metrics.wind_direction, m.variant.environment_metrics.wind_lull, m.variant.environment_metrics.wind_gust, m.variant.environment_metrics.voltage, m.variant.environment_metrics.temperature); diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 3fa3e848a..8c0507e77 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -29,6 +29,7 @@ #include "Sensor/CGRadSensSensor.h" #include "Sensor/DFRobotGravitySensor.h" #include "Sensor/DFRobotLarkSensor.h" +#include "Sensor/DPS310Sensor.h" #include "Sensor/LPS22HBSensor.h" #include "Sensor/MCP9808Sensor.h" #include "Sensor/MLX90632Sensor.h" @@ -45,6 +46,7 @@ BMP085Sensor bmp085Sensor; BMP280Sensor bmp280Sensor; BME280Sensor bme280Sensor; BME680Sensor bme680Sensor; +DPS310Sensor dps310Sensor; MCP9808Sensor mcp9808Sensor; SHTC3Sensor shtc3Sensor; LPS22HBSensor lps22hbSensor; @@ -96,7 +98,8 @@ int32_t EnvironmentTelemetryModule::runOnce() // moduleConfig.telemetry.environment_screen_enabled = 1; // moduleConfig.telemetry.environment_update_interval = 15; - if (!(moduleConfig.telemetry.environment_measurement_enabled || moduleConfig.telemetry.environment_screen_enabled)) { + if (!(moduleConfig.telemetry.environment_measurement_enabled || moduleConfig.telemetry.environment_screen_enabled || + ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE)) { // If this module is not enabled, and the user doesn't want the display screen don't waste any OSThread time on it return disable(); } @@ -105,7 +108,7 @@ int32_t EnvironmentTelemetryModule::runOnce() // This is the first time the OSThread library has called this function, so do some setup firstTime = 0; - if (moduleConfig.telemetry.environment_measurement_enabled) { + if (moduleConfig.telemetry.environment_measurement_enabled || ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE) { LOG_INFO("Environment Telemetry: init"); #ifdef SENSECAP_INDICATOR result = indicatorSensor.runOnce(); @@ -127,6 +130,8 @@ int32_t EnvironmentTelemetryModule::runOnce() result = bmp3xxSensor.runOnce(); if (bme680Sensor.hasSensor()) result = bme680Sensor.runOnce(); + if (dps310Sensor.hasSensor()) + result = dps310Sensor.runOnce(); if (mcp9808Sensor.hasSensor()) result = mcp9808Sensor.runOnce(); if (shtc3Sensor.hasSensor()) @@ -174,7 +179,7 @@ int32_t EnvironmentTelemetryModule::runOnce() return result == UINT32_MAX ? disable() : setStartDelay(); } else { // if we somehow got to a second run of this module with measurement disabled, then just wait forever - if (!moduleConfig.telemetry.environment_measurement_enabled) { + if (!moduleConfig.telemetry.environment_measurement_enabled && !ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE) { return disable(); } else { #if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR_EXTERNAL @@ -418,6 +423,10 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m valid = valid && bme680Sensor.getMetrics(m); hasSensor = true; } + if (dps310Sensor.hasSensor()) { + valid = valid && dps310Sensor.getMetrics(m); + hasSensor = true; + } if (mcp9808Sensor.hasSensor()) { valid = valid && mcp9808Sensor.getMetrics(m); hasSensor = true; @@ -632,6 +641,11 @@ AdminMessageHandleResult EnvironmentTelemetryModule::handleAdminMessageForModule if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } + if (dps310Sensor.hasSensor()) { + result = dps310Sensor.handleAdminMessage(mp, request, response); + if (result != AdminMessageHandleResult::NOT_HANDLED) + return result; + } if (mcp9808Sensor.hasSensor()) { result = mcp9808Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.h b/src/modules/Telemetry/EnvironmentTelemetry.h index 6e0f850ef..d70c063fc 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.h +++ b/src/modules/Telemetry/EnvironmentTelemetry.h @@ -3,6 +3,11 @@ #if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR #pragma once + +#ifndef ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE +#define ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE 0 +#endif + #include "../mesh/generated/meshtastic/telemetry.pb.h" #include "NodeDB.h" #include "ProtobufModule.h" diff --git a/src/modules/Telemetry/Sensor/DPS310Sensor.cpp b/src/modules/Telemetry/Sensor/DPS310Sensor.cpp new file mode 100644 index 000000000..dc5dc4fdf --- /dev/null +++ b/src/modules/Telemetry/Sensor/DPS310Sensor.cpp @@ -0,0 +1,45 @@ +#include "configuration.h" + +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "DPS310Sensor.h" +#include "TelemetrySensor.h" +#include + +DPS310Sensor::DPS310Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_DPS310, "DPS310") {} + +int32_t DPS310Sensor::runOnce() +{ + LOG_INFO("Init sensor: %s", sensorName); + if (!hasSensor()) { + return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; + } + status = dps310.begin_I2C(nodeTelemetrySensorsMap[sensorType].first, nodeTelemetrySensorsMap[sensorType].second); + + dps310.configurePressure(DPS310_1HZ, DPS310_4SAMPLES); + dps310.configureTemperature(DPS310_1HZ, DPS310_4SAMPLES); + dps310.setMode(DPS310_CONT_PRESTEMP); + + return initI2CSensor(); +} + +void DPS310Sensor::setup() {} + +bool DPS310Sensor::getMetrics(meshtastic_Telemetry *measurement) +{ + sensors_event_t temp, press; + + if (!dps310.getEvents(&temp, &press)) { + LOG_DEBUG("DPS310 getEvents no data"); + return false; + } + + measurement->variant.environment_metrics.has_temperature = true; + measurement->variant.environment_metrics.has_barometric_pressure = true; + measurement->variant.environment_metrics.temperature = temp.temperature; + measurement->variant.environment_metrics.barometric_pressure = press.pressure; + + return true; +} +#endif \ No newline at end of file diff --git a/src/modules/Telemetry/Sensor/DPS310Sensor.h b/src/modules/Telemetry/Sensor/DPS310Sensor.h new file mode 100644 index 000000000..452975806 --- /dev/null +++ b/src/modules/Telemetry/Sensor/DPS310Sensor.h @@ -0,0 +1,23 @@ +#include "configuration.h" + +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "TelemetrySensor.h" +#include + +class DPS310Sensor : public TelemetrySensor +{ + private: + Adafruit_DPS310 dps310; + + protected: + virtual void setup() override; + + public: + DPS310Sensor(); + virtual int32_t runOnce() override; + virtual bool getMetrics(meshtastic_Telemetry *measurement) override; +}; + +#endif \ No newline at end of file diff --git a/src/motion/AccelerometerThread.h b/src/motion/AccelerometerThread.h index 6e517d6b0..dd6413d64 100755 --- a/src/motion/AccelerometerThread.h +++ b/src/motion/AccelerometerThread.h @@ -160,13 +160,11 @@ class AccelerometerThread : public concurrency::OSThread void clean() { isInitialised = false; - if (sensor != nullptr) { - delete sensor; - sensor = nullptr; - } + delete sensor; + sensor = nullptr; } }; #endif -#endif \ No newline at end of file +#endif diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 5f16f909f..799f953b4 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -19,6 +19,10 @@ #include "mesh/wifi/WiFiAPClient.h" #include #endif +#if HAS_ETHERNET && defined(USE_WS5500) +#include +#define ETH ETH2 +#endif // HAS_ETHERNET #include "Default.h" #if !defined(ARCH_NRF52) || NRF52_USE_JSON #include "serialization/JSON.h" @@ -113,7 +117,8 @@ inline void onReceiveProto(char *topic, byte *payload, size_t length) // likely they discovered each other via a channel we have downlink enabled for if (isToUs(p.get()) || (tx && tx->has_user && rx && rx->has_user)) router->enqueueReceivedMessage(p.release()); - } else if (router && perhapsDecode(p.get())) // ignore messages if we don't have the channel key + } else if (router && + perhapsDecode(p.get()) == DecodeState::DECODE_SUCCESS) // ignore messages if we don't have the channel key router->enqueueReceivedMessage(p.release()); } @@ -295,6 +300,11 @@ bool connectPubSub(const PubSubConfig &config, PubSubClient &pubSub, Client &cli inline bool isConnectedToNetwork() { +#ifdef USE_WS5500 + if (ETH.connected()) + return true; +#endif + #if HAS_WIFI return WiFi.isConnected(); #elif HAS_ETHERNET diff --git a/src/mqtt/MQTT.h b/src/mqtt/MQTT.h index 5cda90218..0c260dc9c 100644 --- a/src/mqtt/MQTT.h +++ b/src/mqtt/MQTT.h @@ -14,7 +14,7 @@ #include #endif #endif -#if HAS_ETHERNET +#if HAS_ETHERNET && !defined(USE_WS5500) #include #endif diff --git a/src/platform/esp32/WiFiOTA.cpp b/src/platform/esp32/WiFiOTA.cpp new file mode 100644 index 000000000..eac124dda --- /dev/null +++ b/src/platform/esp32/WiFiOTA.cpp @@ -0,0 +1,92 @@ +#include "WiFiOTA.h" +#include "configuration.h" +#include +#include + +namespace WiFiOTA +{ + +static const char *nvsNamespace = "ota-wifi"; +static const char *appProjectName = "OTA-WiFi"; + +static bool updated = false; + +bool isUpdated() +{ + return updated; +} + +void initialize() +{ + Preferences prefs; + prefs.begin(nvsNamespace); + if (prefs.getBool("updated")) { + LOG_INFO("First boot after OTA update"); + updated = true; + prefs.putBool("updated", false); + } + prefs.end(); +} + +void recoverConfig(meshtastic_Config_NetworkConfig *network) +{ + LOG_INFO("Recovering WiFi settings after OTA update"); + + Preferences prefs; + prefs.begin(nvsNamespace, true); + String ssid = prefs.getString("ssid"); + String psk = prefs.getString("psk"); + prefs.end(); + + network->wifi_enabled = true; + strncpy(network->wifi_ssid, ssid.c_str(), sizeof(network->wifi_ssid)); + strncpy(network->wifi_psk, psk.c_str(), sizeof(network->wifi_psk)); +} + +void saveConfig(meshtastic_Config_NetworkConfig *network) +{ + LOG_INFO("Saving WiFi settings for upcoming OTA update"); + + Preferences prefs; + prefs.begin(nvsNamespace); + prefs.putString("ssid", network->wifi_ssid); + prefs.putString("psk", network->wifi_psk); + prefs.putBool("updated", false); + prefs.end(); +} + +const esp_partition_t *getAppPartition() +{ + return esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL); +} + +bool getAppDesc(const esp_partition_t *part, esp_app_desc_t *app_desc) +{ + if (esp_ota_get_partition_description(part, app_desc) != ESP_OK) + return false; + if (strcmp(app_desc->project_name, appProjectName) != 0) + return false; + return true; +} + +bool trySwitchToOTA() +{ + const esp_partition_t *part = getAppPartition(); + esp_app_desc_t app_desc; + if (!getAppDesc(part, &app_desc)) + return false; + if (esp_ota_set_boot_partition(part) != ESP_OK) + return false; + return true; +} + +String getVersion() +{ + const esp_partition_t *part = getAppPartition(); + esp_app_desc_t app_desc; + if (!getAppDesc(part, &app_desc)) + return String(); + return String(app_desc.version); +} + +} // namespace WiFiOTA diff --git a/src/platform/esp32/WiFiOTA.h b/src/platform/esp32/WiFiOTA.h new file mode 100644 index 000000000..61860ed5e --- /dev/null +++ b/src/platform/esp32/WiFiOTA.h @@ -0,0 +1,18 @@ +#ifndef WIFIOTA_H +#define WIFIOTA_H + +#include "mesh-pb-constants.h" +#include + +namespace WiFiOTA +{ +void initialize(); +bool isUpdated(); + +void recoverConfig(meshtastic_Config_NetworkConfig *network); +void saveConfig(meshtastic_Config_NetworkConfig *network); +bool trySwitchToOTA(); +String getVersion(); +} // namespace WiFiOTA + +#endif // WIFIOTA_H diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index 742b295b5..0af6d4d04 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -144,6 +144,8 @@ #define HW_VENDOR meshtastic_HardwareModel_HELTEC_HT62 #elif defined(EBYTE_ESP32_S3) #define HW_VENDOR meshtastic_HardwareModel_EBYTE_ESP32_S3 +#elif defined(ELECROW_ThinkNode_M2) +#define HW_VENDOR meshtastic_HardwareModel_THINKNODE_M2 #elif defined(ESP32_S3_PICO) #define HW_VENDOR meshtastic_HardwareModel_ESP32_S3_PICO #elif defined(SENSELORA_S3) @@ -176,6 +178,10 @@ #define HW_VENDOR meshtastic_HardwareModel_SEEED_XIAO_S3 #elif defined(MESH_TAB) #define HW_VENDOR meshtastic_HardwareModel_MESH_TAB +#elif defined(T_ETH_ELITE) +#define HW_VENDOR meshtastic_HardwareModel_T_ETH_ELITE +#elif defined(HELTEC_SENSOR_HUB) +#define HW_VENDOR meshtastic_HardwareModel_HELTEC_SENSOR_HUB #endif // ----------------------------------------------------------------------------- diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index 679222af5..ab1e5c922 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -9,6 +9,8 @@ #include "nimble/NimbleBluetooth.h" #endif +#include + #if HAS_WIFI #include "mesh/wifi/WiFiAPClient.h" #endif @@ -26,7 +28,9 @@ #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !MESHTASTIC_EXCLUDE_BLUETOOTH void setBluetoothEnable(bool enable) { -#if HAS_WIFI +#ifdef USE_WS5500 + if ((config.bluetooth.enabled == true) && (config.network.wifi_enabled == false)) +#elif HAS_WIFI if (!isWifiAvailable() && config.bluetooth.enabled == true) #else if (config.bluetooth.enabled == true) @@ -105,6 +109,11 @@ void esp32Setup() randomSeed(seed); */ +#ifdef POWER_FULL + pinMode(POWER_FULL, INPUT); + pinMode(7, INPUT); +#endif + LOG_DEBUG("Total heap: %d", ESP.getHeapSize()); LOG_DEBUG("Free heap: %d", ESP.getFreeHeap()); LOG_DEBUG("Total PSRAM: %d", ESP.getPsramSize()); @@ -137,12 +146,19 @@ void esp32Setup() #if !MESHTASTIC_EXCLUDE_BLUETOOTH String BLEOTA = BleOta::getOtaAppVersion(); if (BLEOTA.isEmpty()) { - LOG_INFO("No OTA firmware available"); + LOG_INFO("No BLE OTA firmware available"); } else { - LOG_INFO("OTA firmware version %s", BLEOTA.c_str()); + LOG_INFO("BLE OTA firmware version %s", BLEOTA.c_str()); } -#else - LOG_INFO("No OTA firmware available"); +#endif +#if !MESHTASTIC_EXCLUDE_WIFI + String version = WiFiOTA::getVersion(); + if (version.isEmpty()) { + LOG_INFO("No WiFi OTA firmware available"); + } else { + LOG_INFO("WiFi OTA firmware version %s", version.c_str()); + } + WiFiOTA::initialize(); #endif // enableModemSleep(); diff --git a/src/platform/nrf52/architecture.h b/src/platform/nrf52/architecture.h index 3e4397686..4e8823063 100644 --- a/src/platform/nrf52/architecture.h +++ b/src/platform/nrf52/architecture.h @@ -53,6 +53,8 @@ #define HW_VENDOR meshtastic_HardwareModel_RAK4631 #elif defined(TTGO_T_ECHO) #define HW_VENDOR meshtastic_HardwareModel_T_ECHO +#elif defined(ELECROW_ThinkNode_M1) +#define HW_VENDOR meshtastic_HardwareModel_THINKNODE_M1 #elif defined(NANO_G2_ULTRA) #define HW_VENDOR meshtastic_HardwareModel_NANO_G2_ULTRA #elif defined(CANARYONE) @@ -75,6 +77,10 @@ #define HW_VENDOR meshtastic_HardwareModel_PRIVATE_HW #elif defined(HELTEC_T114) #define HW_VENDOR meshtastic_HardwareModel_HELTEC_MESH_NODE_T114 +#elif defined(MESHLINK) +#define HW_VENDOR meshtastic_HardwareModel_MESHLINK +#elif defined(SEEED_XIAO_NRF52840_KIT) +#define HW_VENDOR meshtastic_HardwareModel_XIAO_NRF52_KIT #else #define HW_VENDOR meshtastic_HardwareModel_NRF52_UNKNOWN #endif @@ -127,4 +133,4 @@ #if !defined(PIN_SERIAL_RX) && !defined(NRF52840_XXAA) // No serial ports on this board - ONLY use segger in memory console #define USE_SEGGER -#endif \ No newline at end of file +#endif diff --git a/src/platform/nrf52/main-nrf52.cpp b/src/platform/nrf52/main-nrf52.cpp index 8483d21c6..53971e95a 100644 --- a/src/platform/nrf52/main-nrf52.cpp +++ b/src/platform/nrf52/main-nrf52.cpp @@ -235,6 +235,14 @@ void nrf52InitSemiHosting() void nrf52Setup() { +#ifdef USB_CHECK + pinMode(USB_CHECK, INPUT); +#endif + +#ifdef ADC_V + pinMode(ADC_V, INPUT); +#endif + uint32_t why = NRF_POWER->RESETREAS; // per // https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpower.html @@ -275,9 +283,11 @@ void cpuDeepSleep(uint32_t msecToWake) Wire.end(); #endif SPI.end(); +#if SPI_INTERFACES_COUNT > 1 + SPI1.end(); +#endif // This may cause crashes as debug messages continue to flow. Serial.end(); - #ifdef PIN_SERIAL_RX1 Serial1.end(); #endif @@ -315,6 +325,31 @@ void cpuDeepSleep(uint32_t msecToWake) detachInterrupt(PIN_GPS_PPS); detachInterrupt(PIN_BUTTON1); #endif + +#ifdef ELECROW_ThinkNode_M1 + for (int pin = 0; pin < 48; pin++) { + if (pin == 17 || pin == 19 || pin == 20 || pin == 22 || pin == 23 || pin == 24 || pin == 25 || pin == 9 || pin == 10 || + pin == PIN_BUTTON1 || pin == PIN_BUTTON2) { + continue; + } + pinMode(pin, OUTPUT); + } + for (int pin = 0; pin < 48; pin++) { + if (pin == 17 || pin == 19 || pin == 20 || pin == 22 || pin == 23 || pin == 24 || pin == 25 || pin == 9 || pin == 10 || + pin == PIN_BUTTON1 || pin == PIN_BUTTON2) { + continue; + } + digitalWrite(pin, LOW); + } + for (int pin = 0; pin < 48; pin++) { + if (pin == 17 || pin == 19 || pin == 20 || pin == 22 || pin == 23 || pin == 24 || pin == 25 || pin == 9 || pin == 10 || + pin == PIN_BUTTON1 || pin == PIN_BUTTON2) { + continue; + } + NRF_GPIO->DIRCLR = (1 << pin); + } +#endif + // Sleepy trackers or sensors can low power "sleep" // Don't enter this if we're sleeping portMAX_DELAY, since that's a shutdown event if (msecToWake != portMAX_DELAY && @@ -333,6 +368,17 @@ void cpuDeepSleep(uint32_t msecToWake) // FIXME, use system off mode with ram retention for key state? // FIXME, use non-init RAM per // https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled + +#ifdef ELECROW_ThinkNode_M1 + nrf_gpio_cfg_input(PIN_BUTTON1, NRF_GPIO_PIN_PULLUP); // Configure the pin to be woken up as an input + nrf_gpio_pin_sense_t sense = NRF_GPIO_PIN_SENSE_LOW; + nrf_gpio_cfg_sense_set(PIN_BUTTON1, sense); + + nrf_gpio_cfg_input(PIN_BUTTON2, NRF_GPIO_PIN_PULLUP); + nrf_gpio_pin_sense_t sense1 = NRF_GPIO_PIN_SENSE_LOW; + nrf_gpio_cfg_sense_set(PIN_BUTTON2, sense1); +#endif + auto ok = sd_power_system_off(); if (ok != NRF_SUCCESS) { LOG_ERROR("FIXME: Ignoring soft device (EasyDMA pending?) and forcing system-off!"); diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index 9da65c92c..a4050e702 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -33,6 +33,7 @@ std::ofstream traceFile; Ch341Hal *ch341Hal = nullptr; char *configPath = nullptr; char *optionMac = nullptr; +bool forceSimulated = false; // FIXME - move setBluetoothEnable into a HALPlatform class void setBluetoothEnable(bool enable) @@ -61,6 +62,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) case 'c': configPath = arg; break; + case 's': + forceSimulated = true; + break; case 'h': optionMac = arg; break; @@ -78,6 +82,7 @@ void portduinoCustomInit() static struct argp_option options[] = {{"port", 'p', "PORT", 0, "The TCP port to use."}, {"config", 'c', "CONFIG_PATH", 0, "Full path of the .yaml config file to use."}, {"hwid", 'h', "HWID", 0, "The mac address to assign to this virtual machine"}, + {"sim", 's', 0, 0, "Run in Simulated radio mode"}, {0}}; static void *childArguments; static char doc[] = "Meshtastic native build."; @@ -157,7 +162,9 @@ void portduinoSetup() YAML::Node yamlConfig; - if (configPath != nullptr) { + if (forceSimulated == true) { + settingsMap[use_simradio] = true; + } else if (configPath != nullptr) { if (loadConfig(configPath)) { std::cout << "Using " << configPath << " as config file" << std::endl; } else { @@ -179,7 +186,12 @@ void portduinoSetup() exit(EXIT_FAILURE); } } else { - std::cout << "No 'config.yaml' found, running simulated." << std::endl; + std::cout << "No 'config.yaml' found..." << std::endl; + settingsMap[use_simradio] = true; + } + + if (settingsMap[use_simradio] == true) { + std::cout << "Running in simulated mode." << std::endl; settingsMap[maxnodes] = 200; // Default to 200 nodes settingsMap[logoutputlevel] = level_debug; // Default to debug // Set the random seed equal to TCPPort to have a different seed per instance @@ -197,6 +209,56 @@ void portduinoSetup() } } } + + // If LoRa `Module: auto` (default in config.yaml), + // attempt to auto config based on Product Strings + if (settingsMap[use_autoconf] == true) { + char autoconf_product[96] = {0}; + // Try CH341 + try { + std::cout << "autoconf: Looking for CH341 device..." << std::endl; + ch341Hal = + new Ch341Hal(0, settingsStrings[lora_usb_serial_num], settingsMap[lora_usb_vid], settingsMap[lora_usb_pid]); + ch341Hal->getProductString(autoconf_product, 95); + delete ch341Hal; + std::cout << "autoconf: Found CH341 device " << autoconf_product << std::endl; + } catch (...) { + std::cout << "autoconf: Could not locate CH341 device" << std::endl; + } + // Try Pi HAT+ + std::cout << "autoconf: Looking for Pi HAT+..." << std::endl; + if (access("/proc/device-tree/hat/product", R_OK) == 0) { + std::ifstream hatProductFile("/proc/device-tree/hat/product"); + if (hatProductFile.is_open()) { + hatProductFile.read(autoconf_product, 95); + hatProductFile.close(); + } + std::cout << "autoconf: Found Pi HAT+ " << autoconf_product << " at /proc/device-tree/hat/product" << std::endl; + } else { + std::cout << "autoconf: Could not locate Pi HAT+ at /proc/device-tree/hat/product" << std::endl; + } + // Load the config file based on the product string + if (strlen(autoconf_product) > 0) { + // From configProducts map in PortduinoGlue.h + std::string product_config = ""; + try { + product_config = configProducts.at(autoconf_product); + } catch (std::out_of_range &e) { + std::cerr << "autoconf: Unable to find config for " << autoconf_product << std::endl; + exit(EXIT_FAILURE); + } + if (loadConfig(("/etc/meshtasticd/available.d/" + product_config).c_str())) { + std::cout << "autoconf: Using " << product_config << " as config file for " << autoconf_product << std::endl; + } else { + std::cerr << "autoconf: Unable to use " << product_config << " as config file for " << autoconf_product + << std::endl; + exit(EXIT_FAILURE); + } + } else { + std::cerr << "autoconf: Could not locate any devices" << std::endl; + } + } + // if we're using a usermode driver, we need to initialize it here, to get a serial number back for mac address uint8_t dmac[6] = {0}; if (settingsStrings[spidev] == "ch341") { @@ -210,7 +272,10 @@ void portduinoSetup() } char serial[9] = {0}; ch341Hal->getSerialString(serial, 8); - std::cout << "Serial " << serial << std::endl; + std::cout << "CH341 Serial " << serial << std::endl; + char product_string[96] = {0}; + ch341Hal->getProductString(product_string, 95); + std::cout << "CH341 Product " << product_string << std::endl; if (strlen(serial) == 8 && settingsStrings[mac_address].length() < 12) { uint8_t hash[32] = {0}; memcpy(hash, serial, 8); @@ -355,8 +420,9 @@ bool loadConfig(const char *configPath) const struct { configNames cfgName; std::string strName; - } loraModules[] = {{use_rf95, "RF95"}, {use_sx1262, "sx1262"}, {use_sx1268, "sx1268"}, {use_sx1280, "sx1280"}, - {use_lr1110, "lr1110"}, {use_lr1120, "lr1120"}, {use_lr1121, "lr1121"}, {use_llcc68, "LLCC68"}}; + } loraModules[] = {{use_simradio, "sim"}, {use_autoconf, "auto"}, {use_rf95, "RF95"}, {use_sx1262, "sx1262"}, + {use_sx1268, "sx1268"}, {use_sx1280, "sx1280"}, {use_lr1110, "lr1110"}, {use_lr1120, "lr1120"}, + {use_lr1121, "lr1121"}, {use_llcc68, "LLCC68"}}; for (auto &loraModule : loraModules) { settingsMap[loraModule.cfgName] = false; } diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h index a52ca88f8..a7aea1c3e 100644 --- a/src/platform/portduino/PortduinoGlue.h +++ b/src/platform/portduino/PortduinoGlue.h @@ -1,9 +1,18 @@ #pragma once #include #include +#include #include "platform/portduino/USBHal.h" +// Product strings for auto-configuration +// {"PRODUCT_STRING", "CONFIG.YAML"} +// YAML paths are relative to `meshtastic/available.d` +inline const std::unordered_map configProducts = {{"MESHTOAD", "lora-usb-meshtoad-e22.yaml"}, + {"MESHSTICK", "lora-meshstick-1262.yaml"}, + {"MESHADV-PI", "lora-MeshAdv-900M30S.yaml"}, + {"POWERPI", "lora-MeshAdv-900M30S.yaml"}}; + enum configNames { default_gpiochip, cs_pin, @@ -34,6 +43,8 @@ enum configNames { rf95_max_power, dio2_as_rf_switch, dio3_tcxo_voltage, + use_simradio, + use_autoconf, use_rf95, use_sx1262, use_sx1268, diff --git a/src/platform/portduino/USBHal.h b/src/platform/portduino/USBHal.h index 0d6b361f4..ce2a5cfd3 100644 --- a/src/platform/portduino/USBHal.h +++ b/src/platform/portduino/USBHal.h @@ -61,6 +61,12 @@ class Ch341Hal : public RadioLibHal strncpy(_serial, pinedio.serial_number, len); } + void getProductString(char *_product_string, size_t len) + { + len = len > 95 ? 95 : len; + strncpy(_product_string, pinedio.product_string, len); + } + void init() override {} void term() override {} diff --git a/src/platform/stm32wl/LittleFS.cpp b/src/platform/stm32wl/LittleFS.cpp new file mode 100644 index 000000000..40f32eca8 --- /dev/null +++ b/src/platform/stm32wl/LittleFS.cpp @@ -0,0 +1,198 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 hathach for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "LittleFS.h" +#include "stm32wlxx_hal_flash.h" + +/********************************************************************************************************************** + * Macro definitions + **********************************************************************************************************************/ +/** This macro is used to suppress compiler messages about a parameter not being used in a function. */ +#define LFS_UNUSED(p) (void)((p)) + +#define STM32WL_PAGE_SIZE (FLASH_PAGE_SIZE) +#define STM32WL_PAGE_COUNT (FLASH_PAGE_NB) +#define STM32WL_FLASH_BASE (FLASH_BASE) + +/* + * FLASH_SIZE from stm32wle5xx.h will read the actual FLASH size from the chip. + * FLASH_END_ADDR is calculated from FLASH_SIZE. + * Use the last 28 KiB of the FLASH + */ +#define LFS_FLASH_TOTAL_SIZE (14 * 2048) /* needs to be a multiple of LFS_BLOCK_SIZE */ +#define LFS_BLOCK_SIZE (2048) +#define LFS_FLASH_ADDR_END (FLASH_END_ADDR) +#define LFS_FLASH_ADDR_BASE (LFS_FLASH_ADDR_END - LFS_FLASH_TOTAL_SIZE + 1) + +#if !CFG_DEBUG +#define _LFS_DBG(fmt, ...) +#else +#define _LFS_DBG(fmt, ...) printf("%s:%d (%s): " fmt "\n", __FILE__, __LINE__, __func__, __VA_ARGS__) +#endif + +//--------------------------------------------------------------------+ +// LFS Disk IO +//--------------------------------------------------------------------+ + +static int _internal_flash_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) +{ + LFS_UNUSED(c); + + if (!buffer || !size) { + _LFS_DBG("%s Invalid parameter!\r\n", __func__); + return LFS_ERR_INVAL; + } + + lfs_block_t address = LFS_FLASH_ADDR_BASE + (block * STM32WL_PAGE_SIZE + off); + + memcpy(buffer, (void *)address, size); + + return LFS_ERR_OK; +} + +// Program a region in a block. The block must have previously +// been erased. Negative error codes are propogated to the user. +// May return LFS_ERR_CORRUPT if the block should be considered bad. +static int _internal_flash_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) +{ + lfs_block_t address = LFS_FLASH_ADDR_BASE + (block * STM32WL_PAGE_SIZE + off); + HAL_StatusTypeDef hal_rc = HAL_OK; + uint32_t dw_count = size / 8; + uint64_t *bufp = (uint64_t *)buffer; + + LFS_UNUSED(c); + + _LFS_DBG("Programming %d bytes/%d doublewords at address 0x%08x/block %d, offset %d.", size, dw_count, address, block, off); + if (HAL_FLASH_Unlock() != HAL_OK) { + return LFS_ERR_IO; + } + for (uint32_t i = 0; i < dw_count; i++) { + if ((address < LFS_FLASH_ADDR_BASE) || (address > LFS_FLASH_ADDR_END)) { + _LFS_DBG("Wanted to program out of bound of FLASH: 0x%08x.\n", address); + HAL_FLASH_Lock(); + return LFS_ERR_INVAL; + } + hal_rc = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, *bufp); + if (hal_rc != HAL_OK) { + /* Error occurred while writing data in Flash memory. + * User can add here some code to deal with this error. + */ + _LFS_DBG("Program error at (0x%08x), 0x%X, error: 0x%08x\n", address, hal_rc, HAL_FLASH_GetError()); + } + address += 8; + bufp += 1; + } + if (HAL_FLASH_Lock() != HAL_OK) { + return LFS_ERR_IO; + } + + return hal_rc == HAL_OK ? LFS_ERR_OK : LFS_ERR_IO; // If HAL_OK, return LFS_ERR_OK, else return LFS_ERR_IO +} + +// Erase a block. A block must be erased before being programmed. +// The state of an erased block is undefined. Negative error codes +// are propogated to the user. +// May return LFS_ERR_CORRUPT if the block should be considered bad. +static int _internal_flash_erase(const struct lfs_config *c, lfs_block_t block) +{ + lfs_block_t address = LFS_FLASH_ADDR_BASE + (block * STM32WL_PAGE_SIZE); + HAL_StatusTypeDef hal_rc; + FLASH_EraseInitTypeDef EraseInitStruct = {.TypeErase = FLASH_TYPEERASE_PAGES, .Page = 0, .NbPages = 1}; + uint32_t PAGEError = 0; + + LFS_UNUSED(c); + + if ((address < LFS_FLASH_ADDR_BASE) || (address > LFS_FLASH_ADDR_END)) { + _LFS_DBG("Wanted to erase out of bound of FLASH: 0x%08x.\n", address); + return LFS_ERR_INVAL; + } + /* calculate the absolute page, i.e. what the ST wants */ + EraseInitStruct.Page = (address - STM32WL_FLASH_BASE) / STM32WL_PAGE_SIZE; + _LFS_DBG("Erasing block %d at 0x%08x... ", block, address); + HAL_FLASH_Unlock(); + hal_rc = HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError); + HAL_FLASH_Lock(); + + return hal_rc == HAL_OK ? LFS_ERR_OK : LFS_ERR_IO; // If HAL_OK, return LFS_ERR_OK, else return LFS_ERR_IO +} + +// Sync the state of the underlying block device. Negative error codes +// are propogated to the user. +static int _internal_flash_sync(const struct lfs_config *c) +{ + LFS_UNUSED(c); + // write function performs no caching. No need for sync. + + return LFS_ERR_OK; +} + +static struct lfs_config _InternalFSConfig = {.context = NULL, + + .read = _internal_flash_read, + .prog = _internal_flash_prog, + .erase = _internal_flash_erase, + .sync = _internal_flash_sync, + + .read_size = LFS_BLOCK_SIZE, + .prog_size = LFS_BLOCK_SIZE, + .block_size = LFS_BLOCK_SIZE, + .block_count = LFS_FLASH_TOTAL_SIZE / LFS_BLOCK_SIZE, + .lookahead = 128, + + .read_buffer = NULL, + .prog_buffer = NULL, + .lookahead_buffer = NULL, + .file_buffer = NULL}; + +LittleFS InternalFS; + +//--------------------------------------------------------------------+ +// +//--------------------------------------------------------------------+ + +LittleFS::LittleFS(void) : STM32_LittleFS(&_InternalFSConfig) {} + +bool LittleFS::begin(void) +{ + if (FLASH_BASE >= LFS_FLASH_ADDR_BASE) { + /* There is not enough space on this device for a filesystem. */ + return false; + } + // failed to mount, erase all pages then format and mount again + if (!STM32_LittleFS::begin()) { + // Erase all pages of internal flash region for Filesystem. + for (uint32_t addr = LFS_FLASH_ADDR_BASE; addr < (LFS_FLASH_ADDR_END + 1); addr += STM32WL_PAGE_SIZE) { + _internal_flash_erase(&_InternalFSConfig, (addr - LFS_FLASH_ADDR_BASE) / STM32WL_PAGE_SIZE); + } + + // lfs format + this->format(); + + // mount again if still failed, give up + if (!STM32_LittleFS::begin()) + return false; + } + + return true; +} diff --git a/src/platform/stm32wl/LittleFS.h b/src/platform/stm32wl/LittleFS.h new file mode 100644 index 000000000..6c3c47f91 --- /dev/null +++ b/src/platform/stm32wl/LittleFS.h @@ -0,0 +1,41 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 hathach for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef INTERNALFILESYSTEM_H_ +#define INTERNALFILESYSTEM_H_ + +#include "STM32_LittleFS.h" + +class LittleFS : public STM32_LittleFS +{ + public: + LittleFS(void); + + // overwrite to also perform low level format (sector erase of whole flash region) + bool begin(void); +}; + +extern LittleFS InternalFS; + +#endif /* INTERNALFILESYSTEM_H_ */ diff --git a/src/platform/stm32wl/STM32_LittleFS.cpp b/src/platform/stm32wl/STM32_LittleFS.cpp new file mode 100644 index 000000000..97e79e61e --- /dev/null +++ b/src/platform/stm32wl/STM32_LittleFS.cpp @@ -0,0 +1,283 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "STM32_LittleFS.h" +#include +#include + +#define memclr(buffer, size) memset(buffer, 0, size) +#define varclr(_var) memclr(_var, sizeof(*(_var))) + +using namespace STM32_LittleFS_Namespace; + +//--------------------------------------------------------------------+ +// Implementation +//--------------------------------------------------------------------+ + +STM32_LittleFS::STM32_LittleFS(void) : STM32_LittleFS(NULL) {} + +STM32_LittleFS::STM32_LittleFS(struct lfs_config *cfg) +{ + varclr(&_lfs); + _lfs_cfg = cfg; + _mounted = false; +} + +STM32_LittleFS::~STM32_LittleFS() {} + +// Initialize and mount the file system +// Return true if mounted successfully else probably corrupted. +// User should format the disk and try again +bool STM32_LittleFS::begin(struct lfs_config *cfg) +{ + _lockFS(); + + bool ret; + // not a loop, just an quick way to short-circuit on error + do { + if (_mounted) { + ret = true; + break; + } + if (cfg) { + _lfs_cfg = cfg; + } + if (nullptr == _lfs_cfg) { + ret = false; + break; + } + // actually attempt to mount, and log error if one occurs + int err = lfs_mount(&_lfs, _lfs_cfg); + PRINT_LFS_ERR(err); + _mounted = (err == LFS_ERR_OK); + ret = _mounted; + } while (0); + + _unlockFS(); + return ret; +} + +// Tear down and unmount file system +void STM32_LittleFS::end(void) +{ + _lockFS(); + + if (_mounted) { + _mounted = false; + int err = lfs_unmount(&_lfs); + PRINT_LFS_ERR(err); + (void)err; + } + + _unlockFS(); +} + +bool STM32_LittleFS::format(void) +{ + _lockFS(); + + int err = LFS_ERR_OK; + bool attemptMount = _mounted; + // not a loop, just an quick way to short-circuit on error + do { + // if already mounted: umount first -> format -> remount + if (_mounted) { + _mounted = false; + err = lfs_unmount(&_lfs); + if (LFS_ERR_OK != err) { + PRINT_LFS_ERR(err); + break; + } + } + err = lfs_format(&_lfs, _lfs_cfg); + if (LFS_ERR_OK != err) { + PRINT_LFS_ERR(err); + break; + } + + if (attemptMount) { + err = lfs_mount(&_lfs, _lfs_cfg); + if (LFS_ERR_OK != err) { + PRINT_LFS_ERR(err); + break; + } + _mounted = true; + } + // success! + } while (0); + + _unlockFS(); + return LFS_ERR_OK == err; +} + +// Open a file or folder +STM32_LittleFS_Namespace::File STM32_LittleFS::open(char const *filepath, uint8_t mode) +{ + // No lock is required here ... the File() object will synchronize with the mutex provided + return STM32_LittleFS_Namespace::File(filepath, mode, *this); +} + +// Check if file or folder exists +bool STM32_LittleFS::exists(char const *filepath) +{ + struct lfs_info info; + _lockFS(); + + bool ret = (0 == lfs_stat(&_lfs, filepath, &info)); + + _unlockFS(); + return ret; +} + +// Create a directory, create intermediate parent if needed +bool STM32_LittleFS::mkdir(char const *filepath) +{ + bool ret = true; + const char *slash = filepath; + if (slash[0] == '/') + slash++; // skip root '/' + + _lockFS(); + + // make intermediate parent directory(ies) + while (NULL != (slash = strchr(slash, '/'))) { + char parent[slash - filepath + 1] = {0}; + memcpy(parent, filepath, slash - filepath); + + int rc = lfs_mkdir(&_lfs, parent); + if (rc != LFS_ERR_OK && rc != LFS_ERR_EXIST) { + PRINT_LFS_ERR(rc); + ret = false; + break; + } + slash++; + } + // make the final requested directory + if (ret) { + int rc = lfs_mkdir(&_lfs, filepath); + if (rc != LFS_ERR_OK && rc != LFS_ERR_EXIST) { + PRINT_LFS_ERR(rc); + ret = false; + } + } + + _unlockFS(); + return ret; +} + +// Remove a file +bool STM32_LittleFS::remove(char const *filepath) +{ + _lockFS(); + + int err = lfs_remove(&_lfs, filepath); + PRINT_LFS_ERR(err); + + _unlockFS(); + return LFS_ERR_OK == err; +} + +// Rename a file +bool STM32_LittleFS::rename(char const *oldfilepath, char const *newfilepath) +{ + _lockFS(); + + int err = lfs_rename(&_lfs, oldfilepath, newfilepath); + PRINT_LFS_ERR(err); + + _unlockFS(); + return LFS_ERR_OK == err; +} + +// Remove a folder +bool STM32_LittleFS::rmdir(char const *filepath) +{ + _lockFS(); + + int err = lfs_remove(&_lfs, filepath); + PRINT_LFS_ERR(err); + + _unlockFS(); + return LFS_ERR_OK == err; +} + +// Remove a folder recursively +bool STM32_LittleFS::rmdir_r(char const *filepath) +{ + /* lfs is modified to remove non-empty folder, + According to below issue, comment these 2 line won't corrupt filesystem + at least when using LFS v1. If moving to LFS v2, see tracked issue + to see if issues (such as the orphans in threaded linked list) are resolved. + https://github.com/ARMmbed/littlefs/issues/43 + */ + _lockFS(); + + int err = lfs_remove(&_lfs, filepath); + PRINT_LFS_ERR(err); + + _unlockFS(); + return LFS_ERR_OK == err; +} + +//------------- Debug -------------// +#if CFG_DEBUG + +const char *dbg_strerr_lfs(int32_t err) +{ + switch (err) { + case LFS_ERR_OK: + return "LFS_ERR_OK"; + case LFS_ERR_IO: + return "LFS_ERR_IO"; + case LFS_ERR_CORRUPT: + return "LFS_ERR_CORRUPT"; + case LFS_ERR_NOENT: + return "LFS_ERR_NOENT"; + case LFS_ERR_EXIST: + return "LFS_ERR_EXIST"; + case LFS_ERR_NOTDIR: + return "LFS_ERR_NOTDIR"; + case LFS_ERR_ISDIR: + return "LFS_ERR_ISDIR"; + case LFS_ERR_NOTEMPTY: + return "LFS_ERR_NOTEMPTY"; + case LFS_ERR_BADF: + return "LFS_ERR_BADF"; + case LFS_ERR_INVAL: + return "LFS_ERR_INVAL"; + case LFS_ERR_NOSPC: + return "LFS_ERR_NOSPC"; + case LFS_ERR_NOMEM: + return "LFS_ERR_NOMEM"; + + default: + static char errcode[10]; + sprintf(errcode, "%ld", err); + return errcode; + } + + return NULL; +} + +#endif diff --git a/src/platform/stm32wl/STM32_LittleFS.h b/src/platform/stm32wl/STM32_LittleFS.h new file mode 100644 index 000000000..9460ffa81 --- /dev/null +++ b/src/platform/stm32wl/STM32_LittleFS.h @@ -0,0 +1,107 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef STM32_LITTLEFS_H_ +#define STM32_LITTLEFS_H_ + +#include + +// Internal Flash uses ARM Little FileSystem +// https://github.com/ARMmbed/littlefs +#include "../../freertosinc.h" // tied to FreeRTOS for serialization +#include "STM32_LittleFS_File.h" +#include "littlefs/lfs.h" + +class STM32_LittleFS +{ + public: + STM32_LittleFS(void); + explicit STM32_LittleFS(struct lfs_config *cfg); + virtual ~STM32_LittleFS(); + + bool begin(struct lfs_config *cfg = NULL); + void end(void); + + // Open the specified file/directory with the supplied mode (e.g. read or + // write, etc). Returns a File object for interacting with the file. + // Note that currently only one file can be open at a time. + STM32_LittleFS_Namespace::File open(char const *filename, uint8_t mode = STM32_LittleFS_Namespace::FILE_O_READ); + + // Methods to determine if the requested file path exists. + bool exists(char const *filepath); + + // Create the requested directory hierarchy--if intermediate directories + // do not exist they will be created. + bool mkdir(char const *filepath); + + // Delete the file. + bool remove(char const *filepath); + + // Rename the file. + bool rename(char const *oldfilepath, char const *newfilepath); + + // Delete a folder (must be empty) + bool rmdir(char const *filepath); + + // Delete a folder (recursively) + bool rmdir_r(char const *filepath); + + // format file system + bool format(void); + + /*------------------------------------------------------------------*/ + /* INTERNAL USAGE ONLY + * Although declare as public, it is meant to be invoked by internal + * code. User should not call these directly + *------------------------------------------------------------------*/ + lfs_t *_getFS(void) { return &_lfs; } + void _lockFS(void) + { /* no-op */ + } + void _unlockFS(void) + { /* no-op */ + } + + protected: + bool _mounted; + struct lfs_config *_lfs_cfg; + lfs_t _lfs; +}; + +#if !CFG_DEBUG +#define VERIFY_LFS(...) _GET_3RD_ARG(__VA_ARGS__, VERIFY_ERR_2ARGS, VERIFY_ERR_1ARGS)(__VA_ARGS__, NULL) +#define PRINT_LFS_ERR(_err) +#else +#define VERIFY_LFS(...) _GET_3RD_ARG(__VA_ARGS__, VERIFY_ERR_2ARGS, VERIFY_ERR_1ARGS)(__VA_ARGS__, dbg_strerr_lfs) +#define PRINT_LFS_ERR(_err) \ + do { \ + if (_err) { \ + printf("%s:%d, LFS error: %d\n", __FILE__, __LINE__, _err); \ + } \ + } while (0) // LFS_ERR are of type int, VERIFY_MESS expects long_int + +const char *dbg_strerr_lfs(int32_t err); +#endif + +#endif /* STM32_LITTLEFS_H_ */ diff --git a/src/platform/stm32wl/STM32_LittleFS_File.cpp b/src/platform/stm32wl/STM32_LittleFS_File.cpp new file mode 100644 index 000000000..349187a02 --- /dev/null +++ b/src/platform/stm32wl/STM32_LittleFS_File.cpp @@ -0,0 +1,393 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "STM32_LittleFS.h" +#include + +#define rtos_malloc malloc +#define rtos_free free + +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM DECLARATION +//--------------------------------------------------------------------+ + +using namespace STM32_LittleFS_Namespace; + +File::File(STM32_LittleFS &fs) +{ + _fs = &fs; + _is_dir = false; + _name[0] = 0; + _name[LFS_NAME_MAX] = 0; + _dir_path = NULL; + + _dir = NULL; + _file = NULL; +} + +File::File(char const *filename, uint8_t mode, STM32_LittleFS &fs) : File(fs) +{ + // public constructor calls public API open(), which will obtain the mutex + this->open(filename, mode); +} + +bool File::_open_file(char const *filepath, uint8_t mode) +{ + int flags = (mode == FILE_O_READ) ? LFS_O_RDONLY : (mode == FILE_O_WRITE) ? (LFS_O_RDWR | LFS_O_CREAT) : 0; + + if (flags) { + _file = (lfs_file_t *)rtos_malloc(sizeof(lfs_file_t)); + if (!_file) + return false; + + int rc = lfs_file_open(_fs->_getFS(), _file, filepath, flags); + + if (rc) { + // failed to open + PRINT_LFS_ERR(rc); + // free memory + rtos_free(_file); + _file = NULL; + return false; + } + + // move to end of file + if (mode == FILE_O_WRITE) + lfs_file_seek(_fs->_getFS(), _file, 0, LFS_SEEK_END); + + _is_dir = false; + } + + return true; +} + +bool File::_open_dir(char const *filepath) +{ + _dir = (lfs_dir_t *)rtos_malloc(sizeof(lfs_dir_t)); + if (!_dir) + return false; + + int rc = lfs_dir_open(_fs->_getFS(), _dir, filepath); + + if (rc) { + // failed to open + PRINT_LFS_ERR(rc); + // free memory + rtos_free(_dir); + _dir = NULL; + return false; + } + + _is_dir = true; + + _dir_path = (char *)rtos_malloc(strlen(filepath) + 1); + strcpy(_dir_path, filepath); + + return true; +} + +bool File::open(char const *filepath, uint8_t mode) +{ + bool ret = false; + _fs->_lockFS(); + + ret = this->_open(filepath, mode); + + _fs->_unlockFS(); + return ret; +} + +bool File::_open(char const *filepath, uint8_t mode) +{ + bool ret = false; + + // close if currently opened + if (this->isOpen()) + _close(); + + struct lfs_info info; + int rc = lfs_stat(_fs->_getFS(), filepath, &info); + + if (LFS_ERR_OK == rc) { + // file existed, open file or directory accordingly + ret = (info.type == LFS_TYPE_REG) ? _open_file(filepath, mode) : _open_dir(filepath); + } else if (LFS_ERR_NOENT == rc) { + // file not existed, only proceed with FILE_O_WRITE mode + if (mode == FILE_O_WRITE) + ret = _open_file(filepath, mode); + } else { + PRINT_LFS_ERR(rc); + } + + // save bare file name + if (ret) { + char const *splash = strrchr(filepath, '/'); + strncpy(_name, splash ? (splash + 1) : filepath, LFS_NAME_MAX); + } + return ret; +} + +size_t File::write(uint8_t ch) +{ + return write(&ch, 1); +} + +size_t File::write(uint8_t const *buf, size_t size) +{ + lfs_ssize_t wrcount = 0; + _fs->_lockFS(); + + if (!this->_is_dir) { + wrcount = lfs_file_write(_fs->_getFS(), _file, buf, size); + if (wrcount < 0) { + wrcount = 0; + } + } + + _fs->_unlockFS(); + return wrcount; +} + +int File::read(void) +{ + // this thin wrapper relies on called function to synchronize + int ret = -1; + uint8_t ch; + if (read(&ch, 1) > 0) { + ret = static_cast(ch); + } + return ret; +} + +int File::read(void *buf, uint16_t nbyte) +{ + int ret = 0; + _fs->_lockFS(); + + if (!this->_is_dir) { + ret = lfs_file_read(_fs->_getFS(), _file, buf, nbyte); + } + + _fs->_unlockFS(); + return ret; +} + +int File::peek(void) +{ + int ret = -1; + _fs->_lockFS(); + + if (!this->_is_dir) { + uint32_t pos = lfs_file_tell(_fs->_getFS(), _file); + uint8_t ch = 0; + if (lfs_file_read(_fs->_getFS(), _file, &ch, 1) > 0) { + ret = static_cast(ch); + } + (void)lfs_file_seek(_fs->_getFS(), _file, pos, LFS_SEEK_SET); + } + + _fs->_unlockFS(); + return ret; +} + +int File::available(void) +{ + int ret = 0; + _fs->_lockFS(); + + if (!this->_is_dir) { + uint32_t file_size = lfs_file_size(_fs->_getFS(), _file); + uint32_t pos = lfs_file_tell(_fs->_getFS(), _file); + ret = file_size - pos; + } + + _fs->_unlockFS(); + return ret; +} + +bool File::seek(uint32_t pos) +{ + bool ret = false; + _fs->_lockFS(); + + if (!this->_is_dir) { + ret = lfs_file_seek(_fs->_getFS(), _file, pos, LFS_SEEK_SET) >= 0; + } + + _fs->_unlockFS(); + return ret; +} + +uint32_t File::position(void) +{ + uint32_t ret = 0; + _fs->_lockFS(); + + if (!this->_is_dir) { + ret = lfs_file_tell(_fs->_getFS(), _file); + } + + _fs->_unlockFS(); + return ret; +} + +uint32_t File::size(void) +{ + uint32_t ret = 0; + _fs->_lockFS(); + + if (!this->_is_dir) { + ret = lfs_file_size(_fs->_getFS(), _file); + } + + _fs->_unlockFS(); + return ret; +} + +bool File::truncate(uint32_t pos) +{ + int32_t ret = LFS_ERR_ISDIR; + _fs->_lockFS(); + if (!this->_is_dir) { + ret = lfs_file_truncate(_fs->_getFS(), _file, pos); + } + _fs->_unlockFS(); + return (ret == 0); +} + +bool File::truncate(void) +{ + int32_t ret = LFS_ERR_ISDIR; + _fs->_lockFS(); + if (!this->_is_dir) { + uint32_t pos = lfs_file_tell(_fs->_getFS(), _file); + ret = lfs_file_truncate(_fs->_getFS(), _file, pos); + } + _fs->_unlockFS(); + return (ret == 0); +} + +void File::flush(void) +{ + _fs->_lockFS(); + + if (!this->_is_dir) { + lfs_file_sync(_fs->_getFS(), _file); + } + + _fs->_unlockFS(); + return; +} + +void File::close(void) +{ + _fs->_lockFS(); + this->_close(); + _fs->_unlockFS(); +} + +void File::_close(void) +{ + if (this->isOpen()) { + if (this->_is_dir) { + lfs_dir_close(_fs->_getFS(), _dir); + rtos_free(_dir); + _dir = NULL; + + if (this->_dir_path) + rtos_free(_dir_path); + _dir_path = NULL; + } else { + lfs_file_close(this->_fs->_getFS(), _file); + rtos_free(_file); + _file = NULL; + } + } +} + +File::operator bool(void) +{ + return isOpen(); +} + +bool File::isOpen(void) +{ + return (_file != NULL) || (_dir != NULL); +} + +// WARNING -- although marked as `const`, the values pointed +// to may change. For example, if the same File +// object has `open()` called with a different +// file or directory name, this same pointer will +// suddenly (unexpectedly?) have different values. +char const *File::name(void) +{ + return this->_name; +} + +bool File::isDirectory(void) +{ + return this->_is_dir; +} + +File File::openNextFile(uint8_t mode) +{ + _fs->_lockFS(); + + File ret(*_fs); + if (this->_is_dir) { + struct lfs_info info; + int rc; + + // lfs_dir_read returns 0 when reaching end of directory, 1 if found an entry + // Skip the "." and ".." entries ... + do { + rc = lfs_dir_read(_fs->_getFS(), _dir, &info); + } while (rc == 1 && (!strcmp(".", info.name) || !strcmp("..", info.name))); + + if (rc == 1) { + // string cat name with current folder + char filepath[strlen(_dir_path) + 1 + strlen(info.name) + 1]; // potential for significant stack usage + strcpy(filepath, _dir_path); + if (!(_dir_path[0] == '/' && _dir_path[1] == 0)) + strcat(filepath, "/"); // only add '/' if cwd is not root + strcat(filepath, info.name); + + (void)ret._open(filepath, mode); // return value is ignored ... caller is expected to check isOpened() + } else if (rc < 0) { + PRINT_LFS_ERR(rc); + } + } + _fs->_unlockFS(); + return ret; +} + +void File::rewindDirectory(void) +{ + _fs->_lockFS(); + if (this->_is_dir) { + lfs_dir_rewind(_fs->_getFS(), _dir); + } + _fs->_unlockFS(); +} diff --git a/src/platform/stm32wl/STM32_LittleFS_File.h b/src/platform/stm32wl/STM32_LittleFS_File.h new file mode 100644 index 000000000..2b48b02e0 --- /dev/null +++ b/src/platform/stm32wl/STM32_LittleFS_File.h @@ -0,0 +1,108 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef STM32_LITTLEFS_FILE_H_ +#define STM32_LITTLEFS_FILE_H_ + +#include "littlefs/lfs.h" + +// Forward declaration +class STM32_LittleFS; + +namespace STM32_LittleFS_Namespace +{ + +// avoid conflict with other FileSystem FILE_READ/FILE_WRITE +enum { + FILE_O_READ = 0, + FILE_O_WRITE = 1, +}; + +class File : public Stream +{ + public: + explicit File(STM32_LittleFS &fs); + File(char const *filename, uint8_t mode, STM32_LittleFS &fs); + + public: + bool open(char const *filename, uint8_t mode); + + //------------- Stream API -------------// + virtual size_t write(uint8_t ch); + virtual size_t write(uint8_t const *buf, size_t size); + size_t write(const char *str) + { + if (str == NULL) + return 0; + return write((const uint8_t *)str, strlen(str)); + } + size_t write(const char *buffer, size_t size) { return write((const uint8_t *)buffer, size); } + + virtual int read(void); + int read(void *buf, uint16_t nbyte); + + virtual int peek(void); + virtual int available(void); + virtual void flush(void); + + bool seek(uint32_t pos); + uint32_t position(void); + uint32_t size(void); + + bool truncate(uint32_t pos); + bool truncate(void); + + void close(void); + + operator bool(void); + + bool isOpen(void); + char const *name(void); + + bool isDirectory(void); + File openNextFile(uint8_t mode = FILE_O_READ); + void rewindDirectory(void); + + private: + STM32_LittleFS *_fs; + + bool _is_dir; + + union { + lfs_file_t *_file; + lfs_dir_t *_dir; + }; + + char *_dir_path; + char _name[LFS_NAME_MAX + 1]; + + bool _open(char const *filepath, uint8_t mode); + bool _open_file(char const *filepath, uint8_t mode); + bool _open_dir(char const *filepath); + void _close(void); +}; + +} // namespace STM32_LittleFS_Namespace + +#endif /* STM32_LITTLEFS_FILE_H_ */ diff --git a/src/platform/stm32wl/littlefs/lfs.c b/src/platform/stm32wl/littlefs/lfs.c new file mode 100644 index 000000000..5dc4c7669 --- /dev/null +++ b/src/platform/stm32wl/littlefs/lfs.c @@ -0,0 +1,2525 @@ +/* + * The little filesystem + * + * Copyright (c) 2017, Arm Limited. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ +#include "lfs.h" +#include "lfs_util.h" + +#include + +/// Caching block device operations /// +static int lfs_cache_read(lfs_t *lfs, lfs_cache_t *rcache, const lfs_cache_t *pcache, lfs_block_t block, lfs_off_t off, + void *buffer, lfs_size_t size) +{ + uint8_t *data = buffer; + LFS_ASSERT(block < lfs->cfg->block_count); + + while (size > 0) { + if (pcache && block == pcache->block && off >= pcache->off && off < pcache->off + lfs->cfg->prog_size) { + // is already in pcache? + lfs_size_t diff = lfs_min(size, lfs->cfg->prog_size - (off - pcache->off)); + memcpy(data, &pcache->buffer[off - pcache->off], diff); + + data += diff; + off += diff; + size -= diff; + continue; + } + + if (block == rcache->block && off >= rcache->off && off < rcache->off + lfs->cfg->read_size) { + // is already in rcache? + lfs_size_t diff = lfs_min(size, lfs->cfg->read_size - (off - rcache->off)); + memcpy(data, &rcache->buffer[off - rcache->off], diff); + + data += diff; + off += diff; + size -= diff; + continue; + } + + if (off % lfs->cfg->read_size == 0 && size >= lfs->cfg->read_size) { + // bypass cache? + lfs_size_t diff = size - (size % lfs->cfg->read_size); + int err = lfs->cfg->read(lfs->cfg, block, off, data, diff); + if (err) { + return err; + } + + data += diff; + off += diff; + size -= diff; + continue; + } + + // load to cache, first condition can no longer fail + rcache->block = block; + rcache->off = off - (off % lfs->cfg->read_size); + int err = lfs->cfg->read(lfs->cfg, rcache->block, rcache->off, rcache->buffer, lfs->cfg->read_size); + if (err) { + return err; + } + } + + return 0; +} + +static int lfs_cache_cmp(lfs_t *lfs, lfs_cache_t *rcache, const lfs_cache_t *pcache, lfs_block_t block, lfs_off_t off, + const void *buffer, lfs_size_t size) +{ + const uint8_t *data = buffer; + + for (lfs_off_t i = 0; i < size; i++) { + uint8_t c; + int err = lfs_cache_read(lfs, rcache, pcache, block, off + i, &c, 1); + if (err) { + return err; + } + + if (c != data[i]) { + return false; + } + } + + return true; +} + +static int lfs_cache_crc(lfs_t *lfs, lfs_cache_t *rcache, const lfs_cache_t *pcache, lfs_block_t block, lfs_off_t off, + lfs_size_t size, uint32_t *crc) +{ + for (lfs_off_t i = 0; i < size; i++) { + uint8_t c; + int err = lfs_cache_read(lfs, rcache, pcache, block, off + i, &c, 1); + if (err) { + return err; + } + + lfs_crc(crc, &c, 1); + } + + return 0; +} + +static inline void lfs_cache_drop(lfs_t *lfs, lfs_cache_t *rcache) +{ + // do not zero, cheaper if cache is readonly or only going to be + // written with identical data (during relocates) + (void)lfs; + rcache->block = 0xffffffff; +} + +static inline void lfs_cache_zero(lfs_t *lfs, lfs_cache_t *pcache) +{ + // zero to avoid information leak + memset(pcache->buffer, 0xff, lfs->cfg->prog_size); + pcache->block = 0xffffffff; +} + +static int lfs_cache_flush(lfs_t *lfs, lfs_cache_t *pcache, lfs_cache_t *rcache) +{ + if (pcache->block != 0xffffffff) { + int err = lfs->cfg->prog(lfs->cfg, pcache->block, pcache->off, pcache->buffer, lfs->cfg->prog_size); + if (err) { + return err; + } + + if (rcache) { + int res = lfs_cache_cmp(lfs, rcache, NULL, pcache->block, pcache->off, pcache->buffer, lfs->cfg->prog_size); + if (res < 0) { + return res; + } + + if (!res) { + return LFS_ERR_CORRUPT; + } + } + + lfs_cache_zero(lfs, pcache); + } + + return 0; +} + +static int lfs_cache_prog(lfs_t *lfs, lfs_cache_t *pcache, lfs_cache_t *rcache, lfs_block_t block, lfs_off_t off, + const void *buffer, lfs_size_t size) +{ + const uint8_t *data = buffer; + LFS_ASSERT(block < lfs->cfg->block_count); + + while (size > 0) { + if (block == pcache->block && off >= pcache->off && off < pcache->off + lfs->cfg->prog_size) { + // is already in pcache? + lfs_size_t diff = lfs_min(size, lfs->cfg->prog_size - (off - pcache->off)); + memcpy(&pcache->buffer[off - pcache->off], data, diff); + + data += diff; + off += diff; + size -= diff; + + if (off % lfs->cfg->prog_size == 0) { + // eagerly flush out pcache if we fill up + int err = lfs_cache_flush(lfs, pcache, rcache); + if (err) { + return err; + } + } + + continue; + } + + // pcache must have been flushed, either by programming and + // entire block or manually flushing the pcache + LFS_ASSERT(pcache->block == 0xffffffff); + + if (off % lfs->cfg->prog_size == 0 && size >= lfs->cfg->prog_size) { + // bypass pcache? + lfs_size_t diff = size - (size % lfs->cfg->prog_size); + int err = lfs->cfg->prog(lfs->cfg, block, off, data, diff); + if (err) { + return err; + } + + if (rcache) { + int res = lfs_cache_cmp(lfs, rcache, NULL, block, off, data, diff); + if (res < 0) { + return res; + } + + if (!res) { + return LFS_ERR_CORRUPT; + } + } + + data += diff; + off += diff; + size -= diff; + continue; + } + + // prepare pcache, first condition can no longer fail + pcache->block = block; + pcache->off = off - (off % lfs->cfg->prog_size); + } + + return 0; +} + +/// General lfs block device operations /// +static int lfs_bd_read(lfs_t *lfs, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) +{ + // if we ever do more than writes to alternating pairs, + // this may need to consider pcache + return lfs_cache_read(lfs, &lfs->rcache, NULL, block, off, buffer, size); +} + +static int lfs_bd_prog(lfs_t *lfs, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) +{ + return lfs_cache_prog(lfs, &lfs->pcache, NULL, block, off, buffer, size); +} + +static int lfs_bd_cmp(lfs_t *lfs, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) +{ + return lfs_cache_cmp(lfs, &lfs->rcache, NULL, block, off, buffer, size); +} + +static int lfs_bd_crc(lfs_t *lfs, lfs_block_t block, lfs_off_t off, lfs_size_t size, uint32_t *crc) +{ + return lfs_cache_crc(lfs, &lfs->rcache, NULL, block, off, size, crc); +} + +static int lfs_bd_erase(lfs_t *lfs, lfs_block_t block) +{ + return lfs->cfg->erase(lfs->cfg, block); +} + +static int lfs_bd_sync(lfs_t *lfs) +{ + lfs_cache_drop(lfs, &lfs->rcache); + + int err = lfs_cache_flush(lfs, &lfs->pcache, NULL); + if (err) { + return err; + } + + return lfs->cfg->sync(lfs->cfg); +} + +/// Internal operations predeclared here /// +int lfs_traverse(lfs_t *lfs, int (*cb)(void *, lfs_block_t), void *data); +static int lfs_pred(lfs_t *lfs, const lfs_block_t dir[2], lfs_dir_t *pdir); +static int lfs_parent(lfs_t *lfs, const lfs_block_t dir[2], lfs_dir_t *parent, lfs_entry_t *entry); +static int lfs_moved(lfs_t *lfs, const void *e); +static int lfs_relocate(lfs_t *lfs, const lfs_block_t oldpair[2], const lfs_block_t newpair[2]); +int lfs_deorphan(lfs_t *lfs); + +/// Block allocator /// +static int lfs_alloc_lookahead(void *p, lfs_block_t block) +{ + lfs_t *lfs = p; + + lfs_block_t off = ((block - lfs->free.off) + lfs->cfg->block_count) % lfs->cfg->block_count; + + if (off < lfs->free.size) { + lfs->free.buffer[off / 32] |= 1U << (off % 32); + } + + return 0; +} + +static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) +{ + while (true) { + while (lfs->free.i != lfs->free.size) { + lfs_block_t off = lfs->free.i; + lfs->free.i += 1; + lfs->free.ack -= 1; + + if (!(lfs->free.buffer[off / 32] & (1U << (off % 32)))) { + // found a free block + *block = (lfs->free.off + off) % lfs->cfg->block_count; + + // eagerly find next off so an alloc ack can + // discredit old lookahead blocks + while (lfs->free.i != lfs->free.size && (lfs->free.buffer[lfs->free.i / 32] & (1U << (lfs->free.i % 32)))) { + lfs->free.i += 1; + lfs->free.ack -= 1; + } + + return 0; + } + } + + // check if we have looked at all blocks since last ack + if (lfs->free.ack == 0) { + LFS_WARN("No more free space %" PRIu32, lfs->free.i + lfs->free.off); + return LFS_ERR_NOSPC; + } + + lfs->free.off = (lfs->free.off + lfs->free.size) % lfs->cfg->block_count; + lfs->free.size = lfs_min(lfs->cfg->lookahead, lfs->free.ack); + lfs->free.i = 0; + + // find mask of free blocks from tree + memset(lfs->free.buffer, 0, lfs->cfg->lookahead / 8); + int err = lfs_traverse(lfs, lfs_alloc_lookahead, lfs); + if (err) { + return err; + } + } +} + +static void lfs_alloc_ack(lfs_t *lfs) +{ + lfs->free.ack = lfs->cfg->block_count; +} + +/// Endian swapping functions /// +static void lfs_dir_fromle32(struct lfs_disk_dir *d) +{ + d->rev = lfs_fromle32(d->rev); + d->size = lfs_fromle32(d->size); + d->tail[0] = lfs_fromle32(d->tail[0]); + d->tail[1] = lfs_fromle32(d->tail[1]); +} + +static void lfs_dir_tole32(struct lfs_disk_dir *d) +{ + d->rev = lfs_tole32(d->rev); + d->size = lfs_tole32(d->size); + d->tail[0] = lfs_tole32(d->tail[0]); + d->tail[1] = lfs_tole32(d->tail[1]); +} + +static void lfs_entry_fromle32(struct lfs_disk_entry *d) +{ + d->u.dir[0] = lfs_fromle32(d->u.dir[0]); + d->u.dir[1] = lfs_fromle32(d->u.dir[1]); +} + +static void lfs_entry_tole32(struct lfs_disk_entry *d) +{ + d->u.dir[0] = lfs_tole32(d->u.dir[0]); + d->u.dir[1] = lfs_tole32(d->u.dir[1]); +} + +static void lfs_superblock_fromle32(struct lfs_disk_superblock *d) +{ + d->root[0] = lfs_fromle32(d->root[0]); + d->root[1] = lfs_fromle32(d->root[1]); + d->block_size = lfs_fromle32(d->block_size); + d->block_count = lfs_fromle32(d->block_count); + d->version = lfs_fromle32(d->version); +} + +static void lfs_superblock_tole32(struct lfs_disk_superblock *d) +{ + d->root[0] = lfs_tole32(d->root[0]); + d->root[1] = lfs_tole32(d->root[1]); + d->block_size = lfs_tole32(d->block_size); + d->block_count = lfs_tole32(d->block_count); + d->version = lfs_tole32(d->version); +} + +/// Metadata pair and directory operations /// +static inline void lfs_pairswap(lfs_block_t pair[2]) +{ + lfs_block_t t = pair[0]; + pair[0] = pair[1]; + pair[1] = t; +} + +static inline bool lfs_pairisnull(const lfs_block_t pair[2]) +{ + return pair[0] == 0xffffffff || pair[1] == 0xffffffff; +} + +static inline int lfs_paircmp(const lfs_block_t paira[2], const lfs_block_t pairb[2]) +{ + return !(paira[0] == pairb[0] || paira[1] == pairb[1] || paira[0] == pairb[1] || paira[1] == pairb[0]); +} + +static inline bool lfs_pairsync(const lfs_block_t paira[2], const lfs_block_t pairb[2]) +{ + return (paira[0] == pairb[0] && paira[1] == pairb[1]) || (paira[0] == pairb[1] && paira[1] == pairb[0]); +} + +static inline lfs_size_t lfs_entry_size(const lfs_entry_t *entry) +{ + return 4 + entry->d.elen + entry->d.alen + entry->d.nlen; +} + +static int lfs_dir_alloc(lfs_t *lfs, lfs_dir_t *dir) +{ + // allocate pair of dir blocks + for (int i = 0; i < 2; i++) { + int err = lfs_alloc(lfs, &dir->pair[i]); + if (err) { + return err; + } + } + + // rather than clobbering one of the blocks we just pretend + // the revision may be valid + int err = lfs_bd_read(lfs, dir->pair[0], 0, &dir->d.rev, 4); + if (err && err != LFS_ERR_CORRUPT) { + return err; + } + + if (err != LFS_ERR_CORRUPT) { + dir->d.rev = lfs_fromle32(dir->d.rev); + } + + // set defaults + dir->d.rev += 1; + dir->d.size = sizeof(dir->d) + 4; + dir->d.tail[0] = 0xffffffff; + dir->d.tail[1] = 0xffffffff; + dir->off = sizeof(dir->d); + + // don't write out yet, let caller take care of that + return 0; +} + +static int lfs_dir_fetch(lfs_t *lfs, lfs_dir_t *dir, const lfs_block_t pair[2]) +{ + // copy out pair, otherwise may be aliasing dir + const lfs_block_t tpair[2] = {pair[0], pair[1]}; + bool valid = false; + + // check both blocks for the most recent revision + for (int i = 0; i < 2; i++) { + struct lfs_disk_dir test; + int err = lfs_bd_read(lfs, tpair[i], 0, &test, sizeof(test)); + lfs_dir_fromle32(&test); + if (err) { + if (err == LFS_ERR_CORRUPT) { + continue; + } + return err; + } + + if (valid && lfs_scmp(test.rev, dir->d.rev) < 0) { + continue; + } + + if ((0x7fffffff & test.size) < sizeof(test) + 4 || (0x7fffffff & test.size) > lfs->cfg->block_size) { + continue; + } + + uint32_t crc = 0xffffffff; + lfs_dir_tole32(&test); + lfs_crc(&crc, &test, sizeof(test)); + lfs_dir_fromle32(&test); + err = lfs_bd_crc(lfs, tpair[i], sizeof(test), (0x7fffffff & test.size) - sizeof(test), &crc); + if (err) { + if (err == LFS_ERR_CORRUPT) { + continue; + } + return err; + } + + if (crc != 0) { + continue; + } + + valid = true; + + // setup dir in case it's valid + dir->pair[0] = tpair[(i + 0) % 2]; + dir->pair[1] = tpair[(i + 1) % 2]; + dir->off = sizeof(dir->d); + dir->d = test; + } + + if (!valid) { + LFS_ERROR("Corrupted dir pair at %" PRIu32 " %" PRIu32, tpair[0], tpair[1]); + return LFS_ERR_CORRUPT; + } + + return 0; +} + +struct lfs_region { + lfs_off_t oldoff; + lfs_size_t oldlen; + const void *newdata; + lfs_size_t newlen; +}; + +static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir, const struct lfs_region *regions, int count) +{ + // increment revision count + dir->d.rev += 1; + + // keep pairs in order such that pair[0] is most recent + lfs_pairswap(dir->pair); + for (int i = 0; i < count; i++) { + dir->d.size += regions[i].newlen - regions[i].oldlen; + } + + const lfs_block_t oldpair[2] = {dir->pair[0], dir->pair[1]}; + bool relocated = false; + + while (true) { + + int err = lfs_bd_erase(lfs, dir->pair[0]); + if (err) { + if (err == LFS_ERR_CORRUPT) { + goto relocate; + } + return err; + } + + uint32_t crc = 0xffffffff; + lfs_dir_tole32(&dir->d); + lfs_crc(&crc, &dir->d, sizeof(dir->d)); + err = lfs_bd_prog(lfs, dir->pair[0], 0, &dir->d, sizeof(dir->d)); + lfs_dir_fromle32(&dir->d); + if (err) { + if (err == LFS_ERR_CORRUPT) { + goto relocate; + } + return err; + } + + int i = 0; + lfs_off_t oldoff = sizeof(dir->d); + lfs_off_t newoff = sizeof(dir->d); + while (newoff < (0x7fffffff & dir->d.size) - 4) { + if (i < count && regions[i].oldoff == oldoff) { + lfs_crc(&crc, regions[i].newdata, regions[i].newlen); + err = lfs_bd_prog(lfs, dir->pair[0], newoff, regions[i].newdata, regions[i].newlen); + if (err) { + if (err == LFS_ERR_CORRUPT) { + goto relocate; + } + return err; + } + + oldoff += regions[i].oldlen; + newoff += regions[i].newlen; + i += 1; + } else { + uint8_t data; + err = lfs_bd_read(lfs, oldpair[1], oldoff, &data, 1); + if (err) { + return err; + } + + lfs_crc(&crc, &data, 1); + err = lfs_bd_prog(lfs, dir->pair[0], newoff, &data, 1); + if (err) { + if (err == LFS_ERR_CORRUPT) { + goto relocate; + } + return err; + } + + oldoff += 1; + newoff += 1; + } + } + + crc = lfs_tole32(crc); + err = lfs_bd_prog(lfs, dir->pair[0], newoff, &crc, 4); + crc = lfs_fromle32(crc); + if (err) { + if (err == LFS_ERR_CORRUPT) { + goto relocate; + } + return err; + } + + err = lfs_bd_sync(lfs); + if (err) { + if (err == LFS_ERR_CORRUPT) { + goto relocate; + } + return err; + } + + // successful commit, check checksum to make sure + uint32_t ncrc = 0xffffffff; + err = lfs_bd_crc(lfs, dir->pair[0], 0, (0x7fffffff & dir->d.size) - 4, &ncrc); + if (err) { + return err; + } + + if (ncrc != crc) { + goto relocate; + } + + break; + relocate: + // commit was corrupted + LFS_DEBUG("Bad block at %" PRIu32, dir->pair[0]); + + // drop caches and prepare to relocate block + relocated = true; + lfs_cache_drop(lfs, &lfs->pcache); + + // can't relocate superblock, filesystem is now frozen + if (lfs_paircmp(oldpair, (const lfs_block_t[2]){0, 1}) == 0) { + LFS_WARN("Superblock %" PRIu32 " has become unwritable", oldpair[0]); + return LFS_ERR_CORRUPT; + } + + // relocate half of pair + err = lfs_alloc(lfs, &dir->pair[0]); + if (err) { + return err; + } + } + + if (relocated) { + // update references if we relocated + LFS_DEBUG("Relocating %" PRIu32 " %" PRIu32 " to %" PRIu32 " %" PRIu32, oldpair[0], oldpair[1], dir->pair[0], + dir->pair[1]); + int err = lfs_relocate(lfs, oldpair, dir->pair); + if (err) { + return err; + } + } + + // shift over any directories that are affected + for (lfs_dir_t *d = lfs->dirs; d; d = d->next) { + if (lfs_paircmp(d->pair, dir->pair) == 0) { + d->pair[0] = dir->pair[0]; + d->pair[1] = dir->pair[1]; + } + } + + return 0; +} + +static int lfs_dir_update(lfs_t *lfs, lfs_dir_t *dir, lfs_entry_t *entry, const void *data) +{ + lfs_entry_tole32(&entry->d); + int err = lfs_dir_commit(lfs, dir, + (struct lfs_region[]){{entry->off, sizeof(entry->d), &entry->d, sizeof(entry->d)}, + {entry->off + sizeof(entry->d), entry->d.nlen, data, entry->d.nlen}}, + data ? 2 : 1); + lfs_entry_fromle32(&entry->d); + return err; +} + +static int lfs_dir_append(lfs_t *lfs, lfs_dir_t *dir, lfs_entry_t *entry, const void *data) +{ + // check if we fit, if top bit is set we do not and move on + while (true) { + if (dir->d.size + lfs_entry_size(entry) <= lfs->cfg->block_size) { + entry->off = dir->d.size - 4; + + lfs_entry_tole32(&entry->d); + int err = lfs_dir_commit( + lfs, dir, + (struct lfs_region[]){{entry->off, 0, &entry->d, sizeof(entry->d)}, {entry->off, 0, data, entry->d.nlen}}, 2); + lfs_entry_fromle32(&entry->d); + return err; + } + + // we need to allocate a new dir block + if (!(0x80000000 & dir->d.size)) { + lfs_dir_t olddir = *dir; + int err = lfs_dir_alloc(lfs, dir); + if (err) { + return err; + } + + dir->d.tail[0] = olddir.d.tail[0]; + dir->d.tail[1] = olddir.d.tail[1]; + entry->off = dir->d.size - 4; + lfs_entry_tole32(&entry->d); + err = lfs_dir_commit( + lfs, dir, + (struct lfs_region[]){{entry->off, 0, &entry->d, sizeof(entry->d)}, {entry->off, 0, data, entry->d.nlen}}, 2); + lfs_entry_fromle32(&entry->d); + if (err) { + return err; + } + + olddir.d.size |= 0x80000000; + olddir.d.tail[0] = dir->pair[0]; + olddir.d.tail[1] = dir->pair[1]; + return lfs_dir_commit(lfs, &olddir, NULL, 0); + } + + int err = lfs_dir_fetch(lfs, dir, dir->d.tail); + if (err) { + return err; + } + } +} + +static int lfs_dir_remove(lfs_t *lfs, lfs_dir_t *dir, lfs_entry_t *entry) +{ + // check if we should just drop the directory block + if ((dir->d.size & 0x7fffffff) == sizeof(dir->d) + 4 + lfs_entry_size(entry)) { + lfs_dir_t pdir; + int res = lfs_pred(lfs, dir->pair, &pdir); + if (res < 0) { + return res; + } + + if (pdir.d.size & 0x80000000) { + pdir.d.size &= dir->d.size | 0x7fffffff; + pdir.d.tail[0] = dir->d.tail[0]; + pdir.d.tail[1] = dir->d.tail[1]; + return lfs_dir_commit(lfs, &pdir, NULL, 0); + } + } + + // shift out the entry + int err = lfs_dir_commit(lfs, dir, + (struct lfs_region[]){ + {entry->off, lfs_entry_size(entry), NULL, 0}, + }, + 1); + if (err) { + return err; + } + + // shift over any files/directories that are affected + for (lfs_file_t *f = lfs->files; f; f = f->next) { + if (lfs_paircmp(f->pair, dir->pair) == 0) { + if (f->poff == entry->off) { + f->pair[0] = 0xffffffff; + f->pair[1] = 0xffffffff; + } else if (f->poff > entry->off) { + f->poff -= lfs_entry_size(entry); + } + } + } + + for (lfs_dir_t *d = lfs->dirs; d; d = d->next) { + if (lfs_paircmp(d->pair, dir->pair) == 0) { + if (d->off > entry->off) { + d->off -= lfs_entry_size(entry); + d->pos -= lfs_entry_size(entry); + } + } + } + + return 0; +} + +static int lfs_dir_next(lfs_t *lfs, lfs_dir_t *dir, lfs_entry_t *entry) +{ + while (dir->off + sizeof(entry->d) > (0x7fffffff & dir->d.size) - 4) { + if (!(0x80000000 & dir->d.size)) { + entry->off = dir->off; + return LFS_ERR_NOENT; + } + + int err = lfs_dir_fetch(lfs, dir, dir->d.tail); + if (err) { + return err; + } + + dir->off = sizeof(dir->d); + dir->pos += sizeof(dir->d) + 4; + } + + int err = lfs_bd_read(lfs, dir->pair[0], dir->off, &entry->d, sizeof(entry->d)); + lfs_entry_fromle32(&entry->d); + if (err) { + return err; + } + + entry->off = dir->off; + dir->off += lfs_entry_size(entry); + dir->pos += lfs_entry_size(entry); + return 0; +} + +static int lfs_dir_find(lfs_t *lfs, lfs_dir_t *dir, lfs_entry_t *entry, const char **path) +{ + const char *pathname = *path; + size_t pathlen; + entry->d.type = LFS_TYPE_DIR; + entry->d.elen = sizeof(entry->d) - 4; + entry->d.alen = 0; + entry->d.nlen = 0; + entry->d.u.dir[0] = lfs->root[0]; + entry->d.u.dir[1] = lfs->root[1]; + + while (true) { + nextname: + // skip slashes + pathname += strspn(pathname, "/"); + pathlen = strcspn(pathname, "/"); + + // skip '.' and root '..' + if ((pathlen == 1 && memcmp(pathname, ".", 1) == 0) || (pathlen == 2 && memcmp(pathname, "..", 2) == 0)) { + pathname += pathlen; + goto nextname; + } + + // skip if matched by '..' in name + const char *suffix = pathname + pathlen; + size_t sufflen; + int depth = 1; + while (true) { + suffix += strspn(suffix, "/"); + sufflen = strcspn(suffix, "/"); + if (sufflen == 0) { + break; + } + + if (sufflen == 2 && memcmp(suffix, "..", 2) == 0) { + depth -= 1; + if (depth == 0) { + pathname = suffix + sufflen; + goto nextname; + } + } else { + depth += 1; + } + + suffix += sufflen; + } + + // found path + if (pathname[0] == '\0') { + return 0; + } + + // update what we've found + *path = pathname; + + // continue on if we hit a directory + if (entry->d.type != LFS_TYPE_DIR) { + return LFS_ERR_NOTDIR; + } + + int err = lfs_dir_fetch(lfs, dir, entry->d.u.dir); + if (err) { + return err; + } + + // find entry matching name + while (true) { + err = lfs_dir_next(lfs, dir, entry); + if (err) { + return err; + } + + if (((0x7f & entry->d.type) != LFS_TYPE_REG && (0x7f & entry->d.type) != LFS_TYPE_DIR) || entry->d.nlen != pathlen) { + continue; + } + + int res = lfs_bd_cmp(lfs, dir->pair[0], entry->off + 4 + entry->d.elen + entry->d.alen, pathname, pathlen); + if (res < 0) { + return res; + } + + // found match + if (res) { + break; + } + } + + // check that entry has not been moved + if (entry->d.type & 0x80) { + int moved = lfs_moved(lfs, &entry->d.u); + if (moved) { + return (moved < 0) ? moved : LFS_ERR_NOENT; + } + + entry->d.type &= ~0x80; + } + + // to next name + pathname += pathlen; + } +} + +/// Top level directory operations /// +int lfs_mkdir(lfs_t *lfs, const char *path) +{ + // deorphan if we haven't yet, needed at most once after poweron + if (!lfs->deorphaned) { + int err = lfs_deorphan(lfs); + if (err) { + return err; + } + } + + // fetch parent directory + lfs_dir_t cwd; + lfs_entry_t entry; + int err = lfs_dir_find(lfs, &cwd, &entry, &path); + if (err != LFS_ERR_NOENT || strchr(path, '/') != NULL) { + return err ? err : LFS_ERR_EXIST; + } + + // build up new directory + lfs_alloc_ack(lfs); + + lfs_dir_t dir; + err = lfs_dir_alloc(lfs, &dir); + if (err) { + return err; + } + dir.d.tail[0] = cwd.d.tail[0]; + dir.d.tail[1] = cwd.d.tail[1]; + + err = lfs_dir_commit(lfs, &dir, NULL, 0); + if (err) { + return err; + } + + entry.d.type = LFS_TYPE_DIR; + entry.d.elen = sizeof(entry.d) - 4; + entry.d.alen = 0; + entry.d.nlen = strlen(path); + entry.d.u.dir[0] = dir.pair[0]; + entry.d.u.dir[1] = dir.pair[1]; + + cwd.d.tail[0] = dir.pair[0]; + cwd.d.tail[1] = dir.pair[1]; + + err = lfs_dir_append(lfs, &cwd, &entry, path); + if (err) { + return err; + } + + lfs_alloc_ack(lfs); + return 0; +} + +int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path) +{ + dir->pair[0] = lfs->root[0]; + dir->pair[1] = lfs->root[1]; + + lfs_entry_t entry; + int err = lfs_dir_find(lfs, dir, &entry, &path); + if (err) { + return err; + } else if (entry.d.type != LFS_TYPE_DIR) { + return LFS_ERR_NOTDIR; + } + + err = lfs_dir_fetch(lfs, dir, entry.d.u.dir); + if (err) { + return err; + } + + // setup head dir + // special offset for '.' and '..' + dir->head[0] = dir->pair[0]; + dir->head[1] = dir->pair[1]; + dir->pos = sizeof(dir->d) - 2; + dir->off = sizeof(dir->d); + + // add to list of directories + dir->next = lfs->dirs; + lfs->dirs = dir; + + return 0; +} + +int lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir) +{ + // remove from list of directories + for (lfs_dir_t **p = &lfs->dirs; *p; p = &(*p)->next) { + if (*p == dir) { + *p = dir->next; + break; + } + } + + return 0; +} + +int lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info) +{ + memset(info, 0, sizeof(*info)); + + // special offset for '.' and '..' + if (dir->pos == sizeof(dir->d) - 2) { + info->type = LFS_TYPE_DIR; + strcpy(info->name, "."); + dir->pos += 1; + return 1; + } else if (dir->pos == sizeof(dir->d) - 1) { + info->type = LFS_TYPE_DIR; + strcpy(info->name, ".."); + dir->pos += 1; + return 1; + } + + lfs_entry_t entry; + while (true) { + int err = lfs_dir_next(lfs, dir, &entry); + if (err) { + return (err == LFS_ERR_NOENT) ? 0 : err; + } + + if ((0x7f & entry.d.type) != LFS_TYPE_REG && (0x7f & entry.d.type) != LFS_TYPE_DIR) { + continue; + } + + // check that entry has not been moved + if (entry.d.type & 0x80) { + int moved = lfs_moved(lfs, &entry.d.u); + if (moved < 0) { + return moved; + } + + if (moved) { + continue; + } + + entry.d.type &= ~0x80; + } + + break; + } + + info->type = entry.d.type; + if (info->type == LFS_TYPE_REG) { + info->size = entry.d.u.file.size; + } + + int err = lfs_bd_read(lfs, dir->pair[0], entry.off + 4 + entry.d.elen + entry.d.alen, info->name, entry.d.nlen); + if (err) { + return err; + } + + return 1; +} + +int lfs_dir_seek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off) +{ + // simply walk from head dir + int err = lfs_dir_rewind(lfs, dir); + if (err) { + return err; + } + dir->pos = off; + + while (off > (0x7fffffff & dir->d.size)) { + off -= 0x7fffffff & dir->d.size; + if (!(0x80000000 & dir->d.size)) { + return LFS_ERR_INVAL; + } + + err = lfs_dir_fetch(lfs, dir, dir->d.tail); + if (err) { + return err; + } + } + + dir->off = off; + return 0; +} + +int lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir) +{ + // reload the head dir + int err = lfs_dir_fetch(lfs, dir, dir->head); + if (err) { + return err; + } + + dir->pair[0] = dir->head[0]; + dir->pair[1] = dir->head[1]; + dir->pos = sizeof(dir->d) - 2; + dir->off = sizeof(dir->d); + return 0; +} + +/// File index list operations /// +static int lfs_ctz_index(lfs_t *lfs, lfs_off_t *off) +{ + lfs_off_t size = *off; + lfs_off_t b = lfs->cfg->block_size - 2 * 4; + lfs_off_t i = size / b; + if (i == 0) { + return 0; + } + + i = (size - 4 * (lfs_popc(i - 1) + 2)) / b; + *off = size - b * i - 4 * lfs_popc(i); + return i; +} + +static int lfs_ctz_find(lfs_t *lfs, lfs_cache_t *rcache, const lfs_cache_t *pcache, lfs_block_t head, lfs_size_t size, + lfs_size_t pos, lfs_block_t *block, lfs_off_t *off) +{ + if (size == 0) { + *block = 0xffffffff; + *off = 0; + return 0; + } + + lfs_off_t current = lfs_ctz_index(lfs, &(lfs_off_t){size - 1}); + lfs_off_t target = lfs_ctz_index(lfs, &pos); + + while (current > target) { + lfs_size_t skip = lfs_min(lfs_npw2(current - target + 1) - 1, lfs_ctz(current)); + + int err = lfs_cache_read(lfs, rcache, pcache, head, 4 * skip, &head, 4); + head = lfs_fromle32(head); + if (err) { + return err; + } + + LFS_ASSERT(head >= 2 && head <= lfs->cfg->block_count); + current -= 1 << skip; + } + + *block = head; + *off = pos; + return 0; +} + +static int lfs_ctz_extend(lfs_t *lfs, lfs_cache_t *rcache, lfs_cache_t *pcache, lfs_block_t head, lfs_size_t size, + lfs_block_t *block, lfs_off_t *off) +{ + while (true) { + // go ahead and grab a block + lfs_block_t nblock; + int err = lfs_alloc(lfs, &nblock); + if (err) { + return err; + } + LFS_ASSERT(nblock >= 2 && nblock <= lfs->cfg->block_count); + + if (true) { + err = lfs_bd_erase(lfs, nblock); + if (err) { + if (err == LFS_ERR_CORRUPT) { + goto relocate; + } + return err; + } + + if (size == 0) { + *block = nblock; + *off = 0; + return 0; + } + + size -= 1; + lfs_off_t index = lfs_ctz_index(lfs, &size); + size += 1; + + // just copy out the last block if it is incomplete + if (size != lfs->cfg->block_size) { + for (lfs_off_t i = 0; i < size; i++) { + uint8_t data; + err = lfs_cache_read(lfs, rcache, NULL, head, i, &data, 1); + if (err) { + return err; + } + + err = lfs_cache_prog(lfs, pcache, rcache, nblock, i, &data, 1); + if (err) { + if (err == LFS_ERR_CORRUPT) { + goto relocate; + } + return err; + } + } + + *block = nblock; + *off = size; + return 0; + } + + // append block + index += 1; + lfs_size_t skips = lfs_ctz(index) + 1; + + for (lfs_off_t i = 0; i < skips; i++) { + head = lfs_tole32(head); + err = lfs_cache_prog(lfs, pcache, rcache, nblock, 4 * i, &head, 4); + head = lfs_fromle32(head); + if (err) { + if (err == LFS_ERR_CORRUPT) { + goto relocate; + } + return err; + } + + if (i != skips - 1) { + err = lfs_cache_read(lfs, rcache, NULL, head, 4 * i, &head, 4); + head = lfs_fromle32(head); + if (err) { + return err; + } + } + + LFS_ASSERT(head >= 2 && head <= lfs->cfg->block_count); + } + + *block = nblock; + *off = 4 * skips; + return 0; + } + + relocate: + LFS_DEBUG("Bad block at %" PRIu32, nblock); + + // just clear cache and try a new block + lfs_cache_drop(lfs, &lfs->pcache); + } +} + +static int lfs_ctz_traverse(lfs_t *lfs, lfs_cache_t *rcache, const lfs_cache_t *pcache, lfs_block_t head, lfs_size_t size, + int (*cb)(void *, lfs_block_t), void *data) +{ + if (size == 0) { + return 0; + } + + lfs_off_t index = lfs_ctz_index(lfs, &(lfs_off_t){size - 1}); + + while (true) { + int err = cb(data, head); + if (err) { + return err; + } + + if (index == 0) { + return 0; + } + + lfs_block_t heads[2]; + int count = 2 - (index & 1); + err = lfs_cache_read(lfs, rcache, pcache, head, 0, &heads, count * 4); + heads[0] = lfs_fromle32(heads[0]); + heads[1] = lfs_fromle32(heads[1]); + if (err) { + return err; + } + + for (int i = 0; i < count - 1; i++) { + err = cb(data, heads[i]); + if (err) { + return err; + } + } + + head = heads[count - 1]; + index -= count; + } +} + +/// Top level file operations /// +int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, const char *path, int flags, const struct lfs_file_config *cfg) +{ + // deorphan if we haven't yet, needed at most once after poweron + if ((flags & 3) != LFS_O_RDONLY && !lfs->deorphaned) { + int err = lfs_deorphan(lfs); + if (err) { + return err; + } + } + + // allocate entry for file if it doesn't exist + lfs_dir_t cwd; + lfs_entry_t entry; + int err = lfs_dir_find(lfs, &cwd, &entry, &path); + if (err && (err != LFS_ERR_NOENT || strchr(path, '/') != NULL)) { + return err; + } + + if (err == LFS_ERR_NOENT) { + if (!(flags & LFS_O_CREAT)) { + return LFS_ERR_NOENT; + } + + // create entry to remember name + entry.d.type = LFS_TYPE_REG; + entry.d.elen = sizeof(entry.d) - 4; + entry.d.alen = 0; + entry.d.nlen = strlen(path); + entry.d.u.file.head = 0xffffffff; + entry.d.u.file.size = 0; + err = lfs_dir_append(lfs, &cwd, &entry, path); + if (err) { + return err; + } + } else if (entry.d.type == LFS_TYPE_DIR) { + return LFS_ERR_ISDIR; + } else if (flags & LFS_O_EXCL) { + return LFS_ERR_EXIST; + } + + // setup file struct + file->cfg = cfg; + file->pair[0] = cwd.pair[0]; + file->pair[1] = cwd.pair[1]; + file->poff = entry.off; + file->head = entry.d.u.file.head; + file->size = entry.d.u.file.size; + file->flags = flags; + file->pos = 0; + + if (flags & LFS_O_TRUNC) { + if (file->size != 0) { + file->flags |= LFS_F_DIRTY; + } + file->head = 0xffffffff; + file->size = 0; + } + + // allocate buffer if needed + file->cache.block = 0xffffffff; + if (file->cfg && file->cfg->buffer) { + file->cache.buffer = file->cfg->buffer; + } else if (lfs->cfg->file_buffer) { + if (lfs->files) { + // already in use + return LFS_ERR_NOMEM; + } + file->cache.buffer = lfs->cfg->file_buffer; + } else if ((file->flags & 3) == LFS_O_RDONLY) { + file->cache.buffer = lfs_malloc(lfs->cfg->read_size); + if (!file->cache.buffer) { + return LFS_ERR_NOMEM; + } + } else { + file->cache.buffer = lfs_malloc(lfs->cfg->prog_size); + if (!file->cache.buffer) { + return LFS_ERR_NOMEM; + } + } + + // zero to avoid information leak + lfs_cache_drop(lfs, &file->cache); + if ((file->flags & 3) != LFS_O_RDONLY) { + lfs_cache_zero(lfs, &file->cache); + } + + // add to list of files + file->next = lfs->files; + lfs->files = file; + + return 0; +} + +int lfs_file_open(lfs_t *lfs, lfs_file_t *file, const char *path, int flags) +{ + return lfs_file_opencfg(lfs, file, path, flags, NULL); +} + +int lfs_file_close(lfs_t *lfs, lfs_file_t *file) +{ + int err = lfs_file_sync(lfs, file); + + // remove from list of files + for (lfs_file_t **p = &lfs->files; *p; p = &(*p)->next) { + if (*p == file) { + *p = file->next; + break; + } + } + + // clean up memory + if (!(file->cfg && file->cfg->buffer) && !lfs->cfg->file_buffer) { + lfs_free(file->cache.buffer); + } + + return err; +} + +static int lfs_file_relocate(lfs_t *lfs, lfs_file_t *file) +{ +relocate: + LFS_DEBUG("Bad block at %" PRIu32, file->block); + + // just relocate what exists into new block + lfs_block_t nblock; + int err = lfs_alloc(lfs, &nblock); + if (err) { + return err; + } + + err = lfs_bd_erase(lfs, nblock); + if (err) { + if (err == LFS_ERR_CORRUPT) { + goto relocate; + } + return err; + } + + // either read from dirty cache or disk + for (lfs_off_t i = 0; i < file->off; i++) { + uint8_t data; + err = lfs_cache_read(lfs, &lfs->rcache, &file->cache, file->block, i, &data, 1); + if (err) { + return err; + } + + err = lfs_cache_prog(lfs, &lfs->pcache, &lfs->rcache, nblock, i, &data, 1); + if (err) { + if (err == LFS_ERR_CORRUPT) { + goto relocate; + } + return err; + } + } + + // copy over new state of file + memcpy(file->cache.buffer, lfs->pcache.buffer, lfs->cfg->prog_size); + file->cache.block = lfs->pcache.block; + file->cache.off = lfs->pcache.off; + lfs_cache_zero(lfs, &lfs->pcache); + + file->block = nblock; + return 0; +} + +static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) +{ + if (file->flags & LFS_F_READING) { + // just drop read cache + lfs_cache_drop(lfs, &file->cache); + file->flags &= ~LFS_F_READING; + } + + if (file->flags & LFS_F_WRITING) { + lfs_off_t pos = file->pos; + + // copy over anything after current branch + lfs_file_t orig = { + .head = file->head, + .size = file->size, + .flags = LFS_O_RDONLY, + .pos = file->pos, + .cache = lfs->rcache, + }; + lfs_cache_drop(lfs, &lfs->rcache); + + while (file->pos < file->size) { + // copy over a byte at a time, leave it up to caching + // to make this efficient + uint8_t data; + lfs_ssize_t res = lfs_file_read(lfs, &orig, &data, 1); + if (res < 0) { + return res; + } + + res = lfs_file_write(lfs, file, &data, 1); + if (res < 0) { + return res; + } + + // keep our reference to the rcache in sync + if (lfs->rcache.block != 0xffffffff) { + lfs_cache_drop(lfs, &orig.cache); + lfs_cache_drop(lfs, &lfs->rcache); + } + } + + // write out what we have + while (true) { + int err = lfs_cache_flush(lfs, &file->cache, &lfs->rcache); + if (err) { + if (err == LFS_ERR_CORRUPT) { + goto relocate; + } + return err; + } + + break; + relocate: + err = lfs_file_relocate(lfs, file); + if (err) { + return err; + } + } + + // actual file updates + file->head = file->block; + file->size = file->pos; + file->flags &= ~LFS_F_WRITING; + file->flags |= LFS_F_DIRTY; + + file->pos = pos; + } + + return 0; +} + +int lfs_file_sync(lfs_t *lfs, lfs_file_t *file) +{ + int err = lfs_file_flush(lfs, file); + if (err) { + return err; + } + + if ((file->flags & LFS_F_DIRTY) && !(file->flags & LFS_F_ERRED) && !lfs_pairisnull(file->pair)) { + // update dir entry + lfs_dir_t cwd; + err = lfs_dir_fetch(lfs, &cwd, file->pair); + if (err) { + return err; + } + + lfs_entry_t entry = {.off = file->poff}; + err = lfs_bd_read(lfs, cwd.pair[0], entry.off, &entry.d, sizeof(entry.d)); + lfs_entry_fromle32(&entry.d); + if (err) { + return err; + } + + LFS_ASSERT(entry.d.type == LFS_TYPE_REG); + entry.d.u.file.head = file->head; + entry.d.u.file.size = file->size; + + err = lfs_dir_update(lfs, &cwd, &entry, NULL); + if (err) { + return err; + } + + file->flags &= ~LFS_F_DIRTY; + } + + return 0; +} + +lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file, void *buffer, lfs_size_t size) +{ + uint8_t *data = buffer; + lfs_size_t nsize = size; + + if ((file->flags & 3) == LFS_O_WRONLY) { + return LFS_ERR_BADF; + } + + if (file->flags & LFS_F_WRITING) { + // flush out any writes + int err = lfs_file_flush(lfs, file); + if (err) { + return err; + } + } + + if (file->pos >= file->size) { + // eof if past end + return 0; + } + + size = lfs_min(size, file->size - file->pos); + nsize = size; + + while (nsize > 0) { + // check if we need a new block + if (!(file->flags & LFS_F_READING) || file->off == lfs->cfg->block_size) { + int err = lfs_ctz_find(lfs, &file->cache, NULL, file->head, file->size, file->pos, &file->block, &file->off); + if (err) { + return err; + } + + file->flags |= LFS_F_READING; + } + + // read as much as we can in current block + lfs_size_t diff = lfs_min(nsize, lfs->cfg->block_size - file->off); + int err = lfs_cache_read(lfs, &file->cache, NULL, file->block, file->off, data, diff); + if (err) { + return err; + } + + file->pos += diff; + file->off += diff; + data += diff; + nsize -= diff; + } + + return size; +} + +lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, const void *buffer, lfs_size_t size) +{ + const uint8_t *data = buffer; + lfs_size_t nsize = size; + + if ((file->flags & 3) == LFS_O_RDONLY) { + return LFS_ERR_BADF; + } + + if (file->flags & LFS_F_READING) { + // drop any reads + int err = lfs_file_flush(lfs, file); + if (err) { + return err; + } + } + + if ((file->flags & LFS_O_APPEND) && file->pos < file->size) { + file->pos = file->size; + } + + if (!(file->flags & LFS_F_WRITING) && file->pos > file->size) { + // fill with zeros + lfs_off_t pos = file->pos; + file->pos = file->size; + + while (file->pos < pos) { + lfs_ssize_t res = lfs_file_write(lfs, file, &(uint8_t){0}, 1); + if (res < 0) { + return res; + } + } + } + + while (nsize > 0) { + // check if we need a new block + if (!(file->flags & LFS_F_WRITING) || file->off == lfs->cfg->block_size) { + if (!(file->flags & LFS_F_WRITING) && file->pos > 0) { + // find out which block we're extending from + int err = lfs_ctz_find(lfs, &file->cache, NULL, file->head, file->size, file->pos - 1, &file->block, &file->off); + if (err) { + file->flags |= LFS_F_ERRED; + return err; + } + + // mark cache as dirty since we may have read data into it + lfs_cache_zero(lfs, &file->cache); + } + + // extend file with new blocks + lfs_alloc_ack(lfs); + int err = lfs_ctz_extend(lfs, &lfs->rcache, &file->cache, file->block, file->pos, &file->block, &file->off); + if (err) { + file->flags |= LFS_F_ERRED; + return err; + } + + file->flags |= LFS_F_WRITING; + } + + // program as much as we can in current block + lfs_size_t diff = lfs_min(nsize, lfs->cfg->block_size - file->off); + while (true) { + int err = lfs_cache_prog(lfs, &file->cache, &lfs->rcache, file->block, file->off, data, diff); + if (err) { + if (err == LFS_ERR_CORRUPT) { + goto relocate; + } + file->flags |= LFS_F_ERRED; + return err; + } + + break; + relocate: + err = lfs_file_relocate(lfs, file); + if (err) { + file->flags |= LFS_F_ERRED; + return err; + } + } + + file->pos += diff; + file->off += diff; + data += diff; + nsize -= diff; + + lfs_alloc_ack(lfs); + } + + file->flags &= ~LFS_F_ERRED; + return size; +} + +lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, lfs_soff_t off, int whence) +{ + // write out everything beforehand, may be noop if rdonly + int err = lfs_file_flush(lfs, file); + if (err) { + return err; + } + + // update pos + if (whence == LFS_SEEK_SET) { + file->pos = off; + } else if (whence == LFS_SEEK_CUR) { + if (off < 0 && (lfs_off_t)-off > file->pos) { + return LFS_ERR_INVAL; + } + + file->pos = file->pos + off; + } else if (whence == LFS_SEEK_END) { + if (off < 0 && (lfs_off_t)-off > file->size) { + return LFS_ERR_INVAL; + } + + file->pos = file->size + off; + } + + return file->pos; +} + +int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) +{ + if ((file->flags & 3) == LFS_O_RDONLY) { + return LFS_ERR_BADF; + } + + lfs_off_t oldsize = lfs_file_size(lfs, file); + if (size < oldsize) { + // need to flush since directly changing metadata + int err = lfs_file_flush(lfs, file); + if (err) { + return err; + } + + // lookup new head in ctz skip list + err = lfs_ctz_find(lfs, &file->cache, NULL, file->head, file->size, size, &file->head, &(lfs_off_t){0}); + if (err) { + return err; + } + + file->size = size; + file->flags |= LFS_F_DIRTY; + } else if (size > oldsize) { + lfs_off_t pos = file->pos; + + // flush+seek if not already at end + if (file->pos != oldsize) { + int err = lfs_file_seek(lfs, file, 0, LFS_SEEK_END); + if (err < 0) { + return err; + } + } + + // fill with zeros + while (file->pos < size) { + lfs_ssize_t res = lfs_file_write(lfs, file, &(uint8_t){0}, 1); + if (res < 0) { + return res; + } + } + + // restore pos + int err = lfs_file_seek(lfs, file, pos, LFS_SEEK_SET); + if (err < 0) { + return err; + } + } + + return 0; +} + +lfs_soff_t lfs_file_tell(lfs_t *lfs, lfs_file_t const *file) +{ + (void)lfs; + return file->pos; +} + +int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file) +{ + lfs_soff_t res = lfs_file_seek(lfs, file, 0, LFS_SEEK_SET); + if (res < 0) { + return res; + } + + return 0; +} + +lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file) +{ + (void)lfs; + if (file->flags & LFS_F_WRITING) { + return lfs_max(file->pos, file->size); + } else { + return file->size; + } +} + +/// General fs operations /// +int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info) +{ + lfs_dir_t cwd; + lfs_entry_t entry; + int err = lfs_dir_find(lfs, &cwd, &entry, &path); + if (err) { + return err; + } + + memset(info, 0, sizeof(*info)); + info->type = entry.d.type; + if (info->type == LFS_TYPE_REG) { + info->size = entry.d.u.file.size; + } + + if (lfs_paircmp(entry.d.u.dir, lfs->root) == 0) { + strcpy(info->name, "/"); + } else { + err = lfs_bd_read(lfs, cwd.pair[0], entry.off + 4 + entry.d.elen + entry.d.alen, info->name, entry.d.nlen); + if (err) { + return err; + } + } + + return 0; +} + +int lfs_remove(lfs_t *lfs, const char *path) +{ + // deorphan if we haven't yet, needed at most once after poweron + if (!lfs->deorphaned) { + int err = lfs_deorphan(lfs); + if (err) { + return err; + } + } + + lfs_dir_t cwd; + lfs_entry_t entry; + int err = lfs_dir_find(lfs, &cwd, &entry, &path); + if (err) { + return err; + } + + lfs_dir_t dir; + if (entry.d.type == LFS_TYPE_DIR) { + // must be empty before removal, checking size + // without masking top bit checks for any case where + // dir is not empty + err = lfs_dir_fetch(lfs, &dir, entry.d.u.dir); + if (err) { + return err; + } /* else if (dir.d.size != sizeof(dir.d)+4) { + return LFS_ERR_NOTEMPTY; + } allow to remove non-empty folder, + According to below issue, comment these 2 line won't corrupt filesystem + https://github.com/ARMmbed/littlefs/issues/43 */ + } + + // remove the entry + err = lfs_dir_remove(lfs, &cwd, &entry); + if (err) { + return err; + } + + // if we were a directory, find pred, replace tail + if (entry.d.type == LFS_TYPE_DIR) { + int res = lfs_pred(lfs, dir.pair, &cwd); + if (res < 0) { + return res; + } + + LFS_ASSERT(res); // must have pred + cwd.d.tail[0] = dir.d.tail[0]; + cwd.d.tail[1] = dir.d.tail[1]; + + err = lfs_dir_commit(lfs, &cwd, NULL, 0); + if (err) { + return err; + } + } + + return 0; +} + +int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) +{ + // deorphan if we haven't yet, needed at most once after poweron + if (!lfs->deorphaned) { + int err = lfs_deorphan(lfs); + if (err) { + return err; + } + } + + // find old entry + lfs_dir_t oldcwd; + lfs_entry_t oldentry; + int err = lfs_dir_find(lfs, &oldcwd, &oldentry, &oldpath); + if (err) { + return err; + } + + // allocate new entry + lfs_dir_t newcwd; + lfs_entry_t preventry; + err = lfs_dir_find(lfs, &newcwd, &preventry, &newpath); + if (err && (err != LFS_ERR_NOENT || strchr(newpath, '/') != NULL)) { + return err; + } + + bool prevexists = (err != LFS_ERR_NOENT); + bool samepair = (lfs_paircmp(oldcwd.pair, newcwd.pair) == 0); + + // must have same type + if (prevexists && preventry.d.type != oldentry.d.type) { + return LFS_ERR_ISDIR; + } + + lfs_dir_t dir; + if (prevexists && preventry.d.type == LFS_TYPE_DIR) { + // must be empty before removal, checking size + // without masking top bit checks for any case where + // dir is not empty + err = lfs_dir_fetch(lfs, &dir, preventry.d.u.dir); + if (err) { + return err; + } else if (dir.d.size != sizeof(dir.d) + 4) { + return LFS_ERR_NOTEMPTY; + } + } + + // mark as moving + oldentry.d.type |= 0x80; + err = lfs_dir_update(lfs, &oldcwd, &oldentry, NULL); + if (err) { + return err; + } + + // update pair if newcwd == oldcwd + if (samepair) { + newcwd = oldcwd; + } + + // move to new location + lfs_entry_t newentry = preventry; + newentry.d = oldentry.d; + newentry.d.type &= ~0x80; + newentry.d.nlen = strlen(newpath); + + if (prevexists) { + err = lfs_dir_update(lfs, &newcwd, &newentry, newpath); + if (err) { + return err; + } + } else { + err = lfs_dir_append(lfs, &newcwd, &newentry, newpath); + if (err) { + return err; + } + } + + // update pair if newcwd == oldcwd + if (samepair) { + oldcwd = newcwd; + } + + // remove old entry + err = lfs_dir_remove(lfs, &oldcwd, &oldentry); + if (err) { + return err; + } + + // if we were a directory, find pred, replace tail + if (prevexists && preventry.d.type == LFS_TYPE_DIR) { + int res = lfs_pred(lfs, dir.pair, &newcwd); + if (res < 0) { + return res; + } + + LFS_ASSERT(res); // must have pred + newcwd.d.tail[0] = dir.d.tail[0]; + newcwd.d.tail[1] = dir.d.tail[1]; + + err = lfs_dir_commit(lfs, &newcwd, NULL, 0); + if (err) { + return err; + } + } + + return 0; +} + +/// Filesystem operations /// +static void lfs_deinit(lfs_t *lfs) +{ + // free allocated memory + if (!lfs->cfg->read_buffer) { + lfs_free(lfs->rcache.buffer); + } + + if (!lfs->cfg->prog_buffer) { + lfs_free(lfs->pcache.buffer); + } + + if (!lfs->cfg->lookahead_buffer) { + lfs_free(lfs->free.buffer); + } +} + +static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) +{ + lfs->cfg = cfg; + + // setup read cache + if (lfs->cfg->read_buffer) { + lfs->rcache.buffer = lfs->cfg->read_buffer; + } else { + lfs->rcache.buffer = lfs_malloc(lfs->cfg->read_size); + if (!lfs->rcache.buffer) { + goto cleanup; + } + } + + // setup program cache + if (lfs->cfg->prog_buffer) { + lfs->pcache.buffer = lfs->cfg->prog_buffer; + } else { + lfs->pcache.buffer = lfs_malloc(lfs->cfg->prog_size); + if (!lfs->pcache.buffer) { + goto cleanup; + } + } + + // zero to avoid information leaks + lfs_cache_zero(lfs, &lfs->pcache); + lfs_cache_drop(lfs, &lfs->rcache); + + // setup lookahead, round down to nearest 32-bits + LFS_ASSERT(lfs->cfg->lookahead % 32 == 0); + LFS_ASSERT(lfs->cfg->lookahead > 0); + if (lfs->cfg->lookahead_buffer) { + lfs->free.buffer = lfs->cfg->lookahead_buffer; + } else { + lfs->free.buffer = lfs_malloc(lfs->cfg->lookahead / 8); + if (!lfs->free.buffer) { + goto cleanup; + } + } + + // check that program and read sizes are multiples of the block size + LFS_ASSERT(lfs->cfg->prog_size % lfs->cfg->read_size == 0); + LFS_ASSERT(lfs->cfg->block_size % lfs->cfg->prog_size == 0); + + // check that the block size is large enough to fit ctz pointers + LFS_ASSERT(4 * lfs_npw2(0xffffffff / (lfs->cfg->block_size - 2 * 4)) <= lfs->cfg->block_size); + + // setup default state + lfs->root[0] = 0xffffffff; + lfs->root[1] = 0xffffffff; + lfs->files = NULL; + lfs->dirs = NULL; + lfs->deorphaned = false; + + return 0; + +cleanup: + lfs_deinit(lfs); + return LFS_ERR_NOMEM; +} + +int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) +{ + int err = 0; + if (true) { + err = lfs_init(lfs, cfg); + if (err) { + return err; + } + + // create free lookahead + memset(lfs->free.buffer, 0, lfs->cfg->lookahead / 8); + lfs->free.off = 0; + lfs->free.size = lfs_min(lfs->cfg->lookahead, lfs->cfg->block_count); + lfs->free.i = 0; + lfs_alloc_ack(lfs); + + // create superblock dir + lfs_dir_t superdir; + err = lfs_dir_alloc(lfs, &superdir); + if (err) { + goto cleanup; + } + + // write root directory + lfs_dir_t root; + err = lfs_dir_alloc(lfs, &root); + if (err) { + goto cleanup; + } + + err = lfs_dir_commit(lfs, &root, NULL, 0); + if (err) { + goto cleanup; + } + + lfs->root[0] = root.pair[0]; + lfs->root[1] = root.pair[1]; + + // write superblocks + lfs_superblock_t superblock = { + .off = sizeof(superdir.d), + .d.type = LFS_TYPE_SUPERBLOCK, + .d.elen = sizeof(superblock.d) - sizeof(superblock.d.magic) - 4, + .d.nlen = sizeof(superblock.d.magic), + .d.version = LFS_DISK_VERSION, + .d.magic = {"littlefs"}, + .d.block_size = lfs->cfg->block_size, + .d.block_count = lfs->cfg->block_count, + .d.root = {lfs->root[0], lfs->root[1]}, + }; + superdir.d.tail[0] = root.pair[0]; + superdir.d.tail[1] = root.pair[1]; + superdir.d.size = sizeof(superdir.d) + sizeof(superblock.d) + 4; + + // write both pairs to be safe + lfs_superblock_tole32(&superblock.d); + bool valid = false; + for (int i = 0; i < 2; i++) { + err = lfs_dir_commit( + lfs, &superdir, + (struct lfs_region[]){{sizeof(superdir.d), sizeof(superblock.d), &superblock.d, sizeof(superblock.d)}}, 1); + if (err && err != LFS_ERR_CORRUPT) { + goto cleanup; + } + + valid = valid || !err; + } + + if (!valid) { + err = LFS_ERR_CORRUPT; + goto cleanup; + } + + // sanity check that fetch works + err = lfs_dir_fetch(lfs, &superdir, (const lfs_block_t[2]){0, 1}); + if (err) { + goto cleanup; + } + + lfs_alloc_ack(lfs); + } + +cleanup: + lfs_deinit(lfs); + return err; +} + +int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) +{ + int err = 0; + if (true) { + err = lfs_init(lfs, cfg); + if (err) { + return err; + } + + // setup free lookahead + lfs->free.off = 0; + lfs->free.size = 0; + lfs->free.i = 0; + lfs_alloc_ack(lfs); + + // load superblock + lfs_dir_t dir; + lfs_superblock_t superblock; + err = lfs_dir_fetch(lfs, &dir, (const lfs_block_t[2]){0, 1}); + if (err && err != LFS_ERR_CORRUPT) { + goto cleanup; + } + + if (!err) { + err = lfs_bd_read(lfs, dir.pair[0], sizeof(dir.d), &superblock.d, sizeof(superblock.d)); + lfs_superblock_fromle32(&superblock.d); + if (err) { + goto cleanup; + } + + lfs->root[0] = superblock.d.root[0]; + lfs->root[1] = superblock.d.root[1]; + } + + if (err || memcmp(superblock.d.magic, "littlefs", 8) != 0) { + LFS_ERROR("Invalid superblock at %d %d", 0, 1); + err = LFS_ERR_CORRUPT; + goto cleanup; + } + + uint16_t major_version = (0xffff & (superblock.d.version >> 16)); + uint16_t minor_version = (0xffff & (superblock.d.version >> 0)); + if ((major_version != LFS_DISK_VERSION_MAJOR || minor_version > LFS_DISK_VERSION_MINOR)) { + LFS_ERROR("Invalid version %d.%d", major_version, minor_version); + err = LFS_ERR_INVAL; + goto cleanup; + } + + return 0; + } + +cleanup: + + lfs_deinit(lfs); + return err; +} + +int lfs_unmount(lfs_t *lfs) +{ + lfs_deinit(lfs); + return 0; +} + +/// Littlefs specific operations /// +int lfs_traverse(lfs_t *lfs, int (*cb)(void *, lfs_block_t), void *data) +{ + if (lfs_pairisnull(lfs->root)) { + return 0; + } + + // iterate over metadata pairs + lfs_dir_t dir; + lfs_entry_t entry; + lfs_block_t cwd[2] = {0, 1}; + + while (true) { + for (int i = 0; i < 2; i++) { + int err = cb(data, cwd[i]); + if (err) { + return err; + } + } + + int err = lfs_dir_fetch(lfs, &dir, cwd); + if (err) { + return err; + } + + // iterate over contents + while (dir.off + sizeof(entry.d) <= (0x7fffffff & dir.d.size) - 4) { + err = lfs_bd_read(lfs, dir.pair[0], dir.off, &entry.d, sizeof(entry.d)); + lfs_entry_fromle32(&entry.d); + if (err) { + return err; + } + + dir.off += lfs_entry_size(&entry); + if ((0x70 & entry.d.type) == (0x70 & LFS_TYPE_REG)) { + err = lfs_ctz_traverse(lfs, &lfs->rcache, NULL, entry.d.u.file.head, entry.d.u.file.size, cb, data); + if (err) { + return err; + } + } + } + + cwd[0] = dir.d.tail[0]; + cwd[1] = dir.d.tail[1]; + + if (lfs_pairisnull(cwd)) { + break; + } + } + + // iterate over any open files + for (lfs_file_t *f = lfs->files; f; f = f->next) { + if (f->flags & LFS_F_DIRTY) { + int err = lfs_ctz_traverse(lfs, &lfs->rcache, &f->cache, f->head, f->size, cb, data); + if (err) { + return err; + } + } + + if (f->flags & LFS_F_WRITING) { + int err = lfs_ctz_traverse(lfs, &lfs->rcache, &f->cache, f->block, f->pos, cb, data); + if (err) { + return err; + } + } + } + + return 0; +} + +static int lfs_pred(lfs_t *lfs, const lfs_block_t dir[2], lfs_dir_t *pdir) +{ + if (lfs_pairisnull(lfs->root)) { + return 0; + } + + // iterate over all directory directory entries + int err = lfs_dir_fetch(lfs, pdir, (const lfs_block_t[2]){0, 1}); + if (err) { + return err; + } + + while (!lfs_pairisnull(pdir->d.tail)) { + if (lfs_paircmp(pdir->d.tail, dir) == 0) { + return true; + } + + err = lfs_dir_fetch(lfs, pdir, pdir->d.tail); + if (err) { + return err; + } + } + + return false; +} + +static int lfs_parent(lfs_t *lfs, const lfs_block_t dir[2], lfs_dir_t *parent, lfs_entry_t *entry) +{ + if (lfs_pairisnull(lfs->root)) { + return 0; + } + + parent->d.tail[0] = 0; + parent->d.tail[1] = 1; + + // iterate over all directory directory entries + while (!lfs_pairisnull(parent->d.tail)) { + int err = lfs_dir_fetch(lfs, parent, parent->d.tail); + if (err) { + return err; + } + + while (true) { + err = lfs_dir_next(lfs, parent, entry); + if (err && err != LFS_ERR_NOENT) { + return err; + } + + if (err == LFS_ERR_NOENT) { + break; + } + + if (((0x70 & entry->d.type) == (0x70 & LFS_TYPE_DIR)) && lfs_paircmp(entry->d.u.dir, dir) == 0) { + return true; + } + } + } + + return false; +} + +static int lfs_moved(lfs_t *lfs, const void *e) +{ + if (lfs_pairisnull(lfs->root)) { + return 0; + } + + // skip superblock + lfs_dir_t cwd; + int err = lfs_dir_fetch(lfs, &cwd, (const lfs_block_t[2]){0, 1}); + if (err) { + return err; + } + + // iterate over all directory directory entries + lfs_entry_t entry; + while (!lfs_pairisnull(cwd.d.tail)) { + err = lfs_dir_fetch(lfs, &cwd, cwd.d.tail); + if (err) { + return err; + } + + while (true) { + err = lfs_dir_next(lfs, &cwd, &entry); + if (err && err != LFS_ERR_NOENT) { + return err; + } + + if (err == LFS_ERR_NOENT) { + break; + } + + if (!(0x80 & entry.d.type) && memcmp(&entry.d.u, e, sizeof(entry.d.u)) == 0) { + return true; + } + } + } + + return false; +} + +static int lfs_relocate(lfs_t *lfs, const lfs_block_t oldpair[2], const lfs_block_t newpair[2]) +{ + // find parent + lfs_dir_t parent; + lfs_entry_t entry; + int res = lfs_parent(lfs, oldpair, &parent, &entry); + if (res < 0) { + return res; + } + + if (res) { + // update disk, this creates a desync + entry.d.u.dir[0] = newpair[0]; + entry.d.u.dir[1] = newpair[1]; + + int err = lfs_dir_update(lfs, &parent, &entry, NULL); + if (err) { + return err; + } + + // update internal root + if (lfs_paircmp(oldpair, lfs->root) == 0) { + LFS_DEBUG("Relocating root %" PRIu32 " %" PRIu32, newpair[0], newpair[1]); + lfs->root[0] = newpair[0]; + lfs->root[1] = newpair[1]; + } + + // clean up bad block, which should now be a desync + return lfs_deorphan(lfs); + } + + // find pred + res = lfs_pred(lfs, oldpair, &parent); + if (res < 0) { + return res; + } + + if (res) { + // just replace bad pair, no desync can occur + parent.d.tail[0] = newpair[0]; + parent.d.tail[1] = newpair[1]; + + return lfs_dir_commit(lfs, &parent, NULL, 0); + } + + // couldn't find dir, must be new + return 0; +} + +int lfs_deorphan(lfs_t *lfs) +{ + lfs->deorphaned = true; + + if (lfs_pairisnull(lfs->root)) { + return 0; + } + + lfs_dir_t pdir = {.d.size = 0x80000000}; + lfs_dir_t cwd = {.d.tail[0] = 0, .d.tail[1] = 1}; + + // iterate over all directory directory entries + for (lfs_size_t i = 0; i < lfs->cfg->block_count; i++) { + if (lfs_pairisnull(cwd.d.tail)) { + return 0; + } + + int err = lfs_dir_fetch(lfs, &cwd, cwd.d.tail); + if (err) { + return err; + } + + // check head blocks for orphans + if (!(0x80000000 & pdir.d.size)) { + // check if we have a parent + lfs_dir_t parent; + lfs_entry_t entry; + int res = lfs_parent(lfs, pdir.d.tail, &parent, &entry); + if (res < 0) { + return res; + } + + if (!res) { + // we are an orphan + LFS_DEBUG("Found orphan %" PRIu32 " %" PRIu32, pdir.d.tail[0], pdir.d.tail[1]); + + pdir.d.tail[0] = cwd.d.tail[0]; + pdir.d.tail[1] = cwd.d.tail[1]; + + err = lfs_dir_commit(lfs, &pdir, NULL, 0); + if (err) { + return err; + } + + return 0; + } + + if (!lfs_pairsync(entry.d.u.dir, pdir.d.tail)) { + // we have desynced + LFS_DEBUG("Found desync %" PRIu32 " %" PRIu32, entry.d.u.dir[0], entry.d.u.dir[1]); + + pdir.d.tail[0] = entry.d.u.dir[0]; + pdir.d.tail[1] = entry.d.u.dir[1]; + + err = lfs_dir_commit(lfs, &pdir, NULL, 0); + if (err) { + return err; + } + + return 0; + } + } + + // check entries for moves + lfs_entry_t entry; + while (true) { + err = lfs_dir_next(lfs, &cwd, &entry); + if (err && err != LFS_ERR_NOENT) { + return err; + } + + if (err == LFS_ERR_NOENT) { + break; + } + + // found moved entry + if (entry.d.type & 0x80) { + int moved = lfs_moved(lfs, &entry.d.u); + if (moved < 0) { + return moved; + } + + if (moved) { + LFS_DEBUG("Found move %" PRIu32 " %" PRIu32, entry.d.u.dir[0], entry.d.u.dir[1]); + err = lfs_dir_remove(lfs, &cwd, &entry); + if (err) { + return err; + } + } else { + LFS_DEBUG("Found partial move %" PRIu32 " %" PRIu32, entry.d.u.dir[0], entry.d.u.dir[1]); + entry.d.type &= ~0x80; + err = lfs_dir_update(lfs, &cwd, &entry, NULL); + if (err) { + return err; + } + } + } + } + + memcpy(&pdir, &cwd, sizeof(pdir)); + } + + // If we reached here, we have more directory pairs than blocks in the + // filesystem... So something must be horribly wrong + return LFS_ERR_CORRUPT; +} diff --git a/src/platform/stm32wl/littlefs/lfs.h b/src/platform/stm32wl/littlefs/lfs.h new file mode 100644 index 000000000..c6ed1d622 --- /dev/null +++ b/src/platform/stm32wl/littlefs/lfs.h @@ -0,0 +1,468 @@ +/* + * The little filesystem + * + * Copyright (c) 2017, Arm Limited. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ +#ifndef LFS_H +#define LFS_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/// Version info /// + +// Software library version +// Major (top-nibble), incremented on backwards incompatible changes +// Minor (bottom-nibble), incremented on feature additions +#define LFS_VERSION 0x00010006 +#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16)) +#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0)) + +// Version of On-disk data structures +// Major (top-nibble), incremented on backwards incompatible changes +// Minor (bottom-nibble), incremented on feature additions +#define LFS_DISK_VERSION 0x00010001 +#define LFS_DISK_VERSION_MAJOR (0xffff & (LFS_DISK_VERSION >> 16)) +#define LFS_DISK_VERSION_MINOR (0xffff & (LFS_DISK_VERSION >> 0)) + +/// Definitions /// + +// Type definitions +typedef uint32_t lfs_size_t; +typedef uint32_t lfs_off_t; + +typedef int32_t lfs_ssize_t; +typedef int32_t lfs_soff_t; + +typedef uint32_t lfs_block_t; + +// Max name size in bytes +#ifndef LFS_NAME_MAX +#define LFS_NAME_MAX 255 +#endif + +// Possible error codes, these are negative to allow +// valid positive return values +enum lfs_error { + LFS_ERR_OK = 0, // No error + LFS_ERR_IO = -5, // Error during device operation + LFS_ERR_CORRUPT = -52, // Corrupted + LFS_ERR_NOENT = -2, // No directory entry + LFS_ERR_EXIST = -17, // Entry already exists + LFS_ERR_NOTDIR = -20, // Entry is not a dir + LFS_ERR_ISDIR = -21, // Entry is a dir + LFS_ERR_NOTEMPTY = -39, // Dir is not empty + LFS_ERR_BADF = -9, // Bad file number + LFS_ERR_INVAL = -22, // Invalid parameter + LFS_ERR_NOSPC = -28, // No space left on device + LFS_ERR_NOMEM = -12, // No more memory available +}; + +// File types +enum lfs_type { + LFS_TYPE_REG = 0x11, + LFS_TYPE_DIR = 0x22, + LFS_TYPE_SUPERBLOCK = 0x2e, +}; + +// File open flags +enum lfs_open_flags { + // open flags + LFS_O_RDONLY = 1, // Open a file as read only + LFS_O_WRONLY = 2, // Open a file as write only + LFS_O_RDWR = 3, // Open a file as read and write + LFS_O_CREAT = 0x0100, // Create a file if it does not exist + LFS_O_EXCL = 0x0200, // Fail if a file already exists + LFS_O_TRUNC = 0x0400, // Truncate the existing file to zero size + LFS_O_APPEND = 0x0800, // Move to end of file on every write + + // internally used flags + LFS_F_DIRTY = 0x10000, // File does not match storage + LFS_F_WRITING = 0x20000, // File has been written since last flush + LFS_F_READING = 0x40000, // File has been read since last flush + LFS_F_ERRED = 0x80000, // An error occured during write +}; + +// File seek flags +enum lfs_whence_flags { + LFS_SEEK_SET = 0, // Seek relative to an absolute position + LFS_SEEK_CUR = 1, // Seek relative to the current file position + LFS_SEEK_END = 2, // Seek relative to the end of the file +}; + +// Configuration provided during initialization of the littlefs +struct lfs_config { + // Opaque user provided context that can be used to pass + // information to the block device operations + void *context; + + // Read a region in a block. Negative error codes are propogated + // to the user. + int (*read)(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size); + + // Program a region in a block. The block must have previously + // been erased. Negative error codes are propogated to the user. + // May return LFS_ERR_CORRUPT if the block should be considered bad. + int (*prog)(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size); + + // Erase a block. A block must be erased before being programmed. + // The state of an erased block is undefined. Negative error codes + // are propogated to the user. + // May return LFS_ERR_CORRUPT if the block should be considered bad. + int (*erase)(const struct lfs_config *c, lfs_block_t block); + + // Sync the state of the underlying block device. Negative error codes + // are propogated to the user. + int (*sync)(const struct lfs_config *c); + + // Minimum size of a block read. This determines the size of read buffers. + // This may be larger than the physical read size to improve performance + // by caching more of the block device. + lfs_size_t read_size; + + // Minimum size of a block program. This determines the size of program + // buffers. This may be larger than the physical program size to improve + // performance by caching more of the block device. + // Must be a multiple of the read size. + lfs_size_t prog_size; + + // Size of an erasable block. This does not impact ram consumption and + // may be larger than the physical erase size. However, this should be + // kept small as each file currently takes up an entire block. + // Must be a multiple of the program size. + lfs_size_t block_size; + + // Number of erasable blocks on the device. + lfs_size_t block_count; + + // Number of blocks to lookahead during block allocation. A larger + // lookahead reduces the number of passes required to allocate a block. + // The lookahead buffer requires only 1 bit per block so it can be quite + // large with little ram impact. Should be a multiple of 32. + lfs_size_t lookahead; + + // Optional, statically allocated read buffer. Must be read sized. + void *read_buffer; + + // Optional, statically allocated program buffer. Must be program sized. + void *prog_buffer; + + // Optional, statically allocated lookahead buffer. Must be 1 bit per + // lookahead block. + void *lookahead_buffer; + + // Optional, statically allocated buffer for files. Must be program sized. + // If enabled, only one file may be opened at a time. + void *file_buffer; +}; + +// Optional configuration provided during lfs_file_opencfg +struct lfs_file_config { + // Optional, statically allocated buffer for files. Must be program sized. + // If NULL, malloc will be used by default. + void *buffer; +}; + +// File info structure +struct lfs_info { + // Type of the file, either LFS_TYPE_REG or LFS_TYPE_DIR + uint8_t type; + + // Size of the file, only valid for REG files + lfs_size_t size; + + // Name of the file stored as a null-terminated string + char name[LFS_NAME_MAX + 1]; +}; + +/// littlefs data structures /// +typedef struct lfs_entry { + lfs_off_t off; + + struct lfs_disk_entry { + uint8_t type; + uint8_t elen; + uint8_t alen; + uint8_t nlen; + union { + struct { + lfs_block_t head; + lfs_size_t size; + } file; + lfs_block_t dir[2]; + } u; + } d; +} lfs_entry_t; + +typedef struct lfs_cache { + lfs_block_t block; + lfs_off_t off; + uint8_t *buffer; +} lfs_cache_t; + +typedef struct lfs_file { + struct lfs_file *next; + lfs_block_t pair[2]; + lfs_off_t poff; + + lfs_block_t head; + lfs_size_t size; + + const struct lfs_file_config *cfg; + uint32_t flags; + lfs_off_t pos; + lfs_block_t block; + lfs_off_t off; + lfs_cache_t cache; +} lfs_file_t; + +typedef struct lfs_dir { + struct lfs_dir *next; + lfs_block_t pair[2]; + lfs_off_t off; + + lfs_block_t head[2]; + lfs_off_t pos; + + struct lfs_disk_dir { + uint32_t rev; + lfs_size_t size; + lfs_block_t tail[2]; + } d; +} lfs_dir_t; + +typedef struct lfs_superblock { + lfs_off_t off; + + struct lfs_disk_superblock { + uint8_t type; + uint8_t elen; + uint8_t alen; + uint8_t nlen; + lfs_block_t root[2]; + uint32_t block_size; + uint32_t block_count; + uint32_t version; + char magic[8]; + } d; +} lfs_superblock_t; + +typedef struct lfs_free { + lfs_block_t off; + lfs_block_t size; + lfs_block_t i; + lfs_block_t ack; + uint32_t *buffer; +} lfs_free_t; + +// The littlefs type +typedef struct lfs { + const struct lfs_config *cfg; + + lfs_block_t root[2]; + lfs_file_t *files; + lfs_dir_t *dirs; + + lfs_cache_t rcache; + lfs_cache_t pcache; + + lfs_free_t free; + bool deorphaned; +} lfs_t; + +/// Filesystem functions /// + +// Format a block device with the littlefs +// +// Requires a littlefs object and config struct. This clobbers the littlefs +// object, and does not leave the filesystem mounted. The config struct must +// be zeroed for defaults and backwards compatibility. +// +// Returns a negative error code on failure. +int lfs_format(lfs_t *lfs, const struct lfs_config *config); + +// Mounts a littlefs +// +// Requires a littlefs object and config struct. Multiple filesystems +// may be mounted simultaneously with multiple littlefs objects. Both +// lfs and config must be allocated while mounted. The config struct must +// be zeroed for defaults and backwards compatibility. +// +// Returns a negative error code on failure. +int lfs_mount(lfs_t *lfs, const struct lfs_config *config); + +// Unmounts a littlefs +// +// Does nothing besides releasing any allocated resources. +// Returns a negative error code on failure. +int lfs_unmount(lfs_t *lfs); + +/// General operations /// + +// Removes a file or directory +// +// If removing a directory, the directory must be empty. +// Returns a negative error code on failure. +int lfs_remove(lfs_t *lfs, const char *path); + +// Rename or move a file or directory +// +// If the destination exists, it must match the source in type. +// If the destination is a directory, the directory must be empty. +// +// Returns a negative error code on failure. +int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath); + +// Find info about a file or directory +// +// Fills out the info structure, based on the specified file or directory. +// Returns a negative error code on failure. +int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info); + +/// File operations /// + +// Open a file +// +// The mode that the file is opened in is determined by the flags, which +// are values from the enum lfs_open_flags that are bitwise-ored together. +// +// Returns a negative error code on failure. +int lfs_file_open(lfs_t *lfs, lfs_file_t *file, const char *path, int flags); + +// Open a file with extra configuration +// +// The mode that the file is opened in is determined by the flags, which +// are values from the enum lfs_open_flags that are bitwise-ored together. +// +// The config struct provides additional config options per file as described +// above. The config struct must be allocated while the file is open, and the +// config struct must be zeroed for defaults and backwards compatibility. +// +// Returns a negative error code on failure. +int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, const char *path, int flags, const struct lfs_file_config *config); + +// Close a file +// +// Any pending writes are written out to storage as though +// sync had been called and releases any allocated resources. +// +// Returns a negative error code on failure. +int lfs_file_close(lfs_t *lfs, lfs_file_t *file); + +// Synchronize a file on storage +// +// Any pending writes are written out to storage. +// Returns a negative error code on failure. +int lfs_file_sync(lfs_t *lfs, lfs_file_t *file); + +// Read data from file +// +// Takes a buffer and size indicating where to store the read data. +// Returns the number of bytes read, or a negative error code on failure. +lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file, void *buffer, lfs_size_t size); + +// Write data to file +// +// Takes a buffer and size indicating the data to write. The file will not +// actually be updated on the storage until either sync or close is called. +// +// Returns the number of bytes written, or a negative error code on failure. +lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, const void *buffer, lfs_size_t size); + +// Change the position of the file +// +// The change in position is determined by the offset and whence flag. +// Returns the old position of the file, or a negative error code on failure. +lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, lfs_soff_t off, int whence); + +// Truncates the size of the file to the specified size +// +// Returns a negative error code on failure. +int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size); + +// Return the position of the file +// +// Equivalent to lfs_file_seek(lfs, file, 0, LFS_SEEK_CUR) +// Returns the position of the file, or a negative error code on failure. +lfs_soff_t lfs_file_tell(lfs_t *lfs, const lfs_file_t *file); + +// Change the position of the file to the beginning of the file +// +// Equivalent to lfs_file_seek(lfs, file, 0, LFS_SEEK_CUR) +// Returns a negative error code on failure. +int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file); + +// Return the size of the file +// +// Similar to lfs_file_seek(lfs, file, 0, LFS_SEEK_END) +// Returns the size of the file, or a negative error code on failure. +lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file); + +/// Directory operations /// + +// Create a directory +// +// Returns a negative error code on failure. +int lfs_mkdir(lfs_t *lfs, const char *path); + +// Open a directory +// +// Once open a directory can be used with read to iterate over files. +// Returns a negative error code on failure. +int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path); + +// Close a directory +// +// Releases any allocated resources. +// Returns a negative error code on failure. +int lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir); + +// Read an entry in the directory +// +// Fills out the info structure, based on the specified file or directory. +// Returns a negative error code on failure. +int lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info); + +// Change the position of the directory +// +// The new off must be a value previous returned from tell and specifies +// an absolute offset in the directory seek. +// +// Returns a negative error code on failure. +int lfs_dir_seek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off); + +// Change the position of the directory to the beginning of the directory +// +// Returns a negative error code on failure. +int lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir); + +/// Miscellaneous littlefs specific operations /// + +// Traverse through all blocks in use by the filesystem +// +// The provided callback will be called with each block address that is +// currently in use by the filesystem. This can be used to determine which +// blocks are in use or how much of the storage is available. +// +// Returns a negative error code on failure. +int lfs_traverse(lfs_t *lfs, int (*cb)(void *, lfs_block_t), void *data); + +// Prunes any recoverable errors that may have occured in the filesystem +// +// Not needed to be called by user unless an operation is interrupted +// but the filesystem is still mounted. This is already called on first +// allocation. +// +// Returns a negative error code on failure. +int lfs_deorphan(lfs_t *lfs); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/src/platform/stm32wl/littlefs/lfs_util.c b/src/platform/stm32wl/littlefs/lfs_util.c new file mode 100644 index 000000000..0b352c51f --- /dev/null +++ b/src/platform/stm32wl/littlefs/lfs_util.c @@ -0,0 +1,28 @@ +/* + * lfs util functions + * + * Copyright (c) 2017, Arm Limited. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ +#include "lfs_util.h" + +// Only compile if user does not provide custom config +#ifndef LFS_CONFIG + +// Software CRC implementation with small lookup table +void lfs_crc(uint32_t *restrict crc, const void *buffer, size_t size) +{ + static const uint32_t rtable[16] = { + 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, + 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c, + }; + + const uint8_t *data = buffer; + + for (size_t i = 0; i < size; i++) { + *crc = (*crc >> 4) ^ rtable[(*crc ^ (data[i] >> 0)) & 0xf]; + *crc = (*crc >> 4) ^ rtable[(*crc ^ (data[i] >> 4)) & 0xf]; + } +} + +#endif diff --git a/src/platform/stm32wl/littlefs/lfs_util.h b/src/platform/stm32wl/littlefs/lfs_util.h new file mode 100644 index 000000000..5c8469f88 --- /dev/null +++ b/src/platform/stm32wl/littlefs/lfs_util.h @@ -0,0 +1,199 @@ +/* + * lfs utility functions + * + * Copyright (c) 2017, Arm Limited. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ +#ifndef LFS_UTIL_H +#define LFS_UTIL_H + +// Users can override lfs_util.h with their own configuration by defining +// LFS_CONFIG as a header file to include (-DLFS_CONFIG=lfs_config.h). +// +// If LFS_CONFIG is used, none of the default utils will be emitted and must be +// provided by the config file. To start I would suggest copying lfs_util.h and +// modifying as needed. +#ifdef LFS_CONFIG +#define LFS_STRINGIZE(x) LFS_STRINGIZE2(x) +#define LFS_STRINGIZE2(x) #x +#include LFS_STRINGIZE(LFS_CONFIG) +#else + +// System includes +#include +#include +#include + +#ifndef LFS_NO_MALLOC +#include +#endif +#ifndef LFS_NO_ASSERT +#include +#endif + +#if !CFG_DEBUG +#define LFS_NO_DEBUG +#define LFS_NO_WARN +#define LFS_NO_ERROR +#endif + +#if !defined(LFS_NO_DEBUG) || !defined(LFS_NO_WARN) || !defined(LFS_NO_ERROR) +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +// Macros, may be replaced by system specific wrappers. Arguments to these +// macros must not have side-effects as the macros can be removed for a smaller +// code footprint + +// Logging functions +#ifndef LFS_NO_DEBUG +#define LFS_DEBUG(fmt, ...) printf("lfs debug:%d: " fmt "\n", __LINE__, __VA_ARGS__) +#else +#define LFS_DEBUG(fmt, ...) +#endif + +#ifndef LFS_NO_WARN +#define LFS_WARN(fmt, ...) printf("lfs warn:%d: " fmt "\n", __LINE__, __VA_ARGS__) +#else +#define LFS_WARN(fmt, ...) +#endif + +#ifndef LFS_NO_ERROR +#define LFS_ERROR(fmt, ...) printf("lfs error:%d: " fmt "\n", __LINE__, __VA_ARGS__) +#else +#define LFS_ERROR(fmt, ...) +#endif + +// Runtime assertions +#ifndef LFS_NO_ASSERT +#define LFS_ASSERT(test) assert(test) +#else +#define LFS_ASSERT(test) +#endif + +// Builtin functions, these may be replaced by more efficient +// toolchain-specific implementations. LFS_NO_INTRINSICS falls back to a more +// expensive basic C implementation for debugging purposes + +// Min/max functions for unsigned 32-bit numbers +static inline uint32_t lfs_max(uint32_t a, uint32_t b) +{ + return (a > b) ? a : b; +} + +static inline uint32_t lfs_min(uint32_t a, uint32_t b) +{ + return (a < b) ? a : b; +} + +// Find the next smallest power of 2 less than or equal to a +static inline uint32_t lfs_npw2(uint32_t a) +{ +#if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM)) + return 32 - __builtin_clz(a - 1); +#else + uint32_t r = 0; + uint32_t s; + a -= 1; + s = (a > 0xffff) << 4; + a >>= s; + r |= s; + s = (a > 0xff) << 3; + a >>= s; + r |= s; + s = (a > 0xf) << 2; + a >>= s; + r |= s; + s = (a > 0x3) << 1; + a >>= s; + r |= s; + return (r | (a >> 1)) + 1; +#endif +} + +// Count the number of trailing binary zeros in a +// lfs_ctz(0) may be undefined +static inline uint32_t lfs_ctz(uint32_t a) +{ +#if !defined(LFS_NO_INTRINSICS) && defined(__GNUC__) + return __builtin_ctz(a); +#else + return lfs_npw2((a & -a) + 1) - 1; +#endif +} + +// Count the number of binary ones in a +static inline uint32_t lfs_popc(uint32_t a) +{ +#if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM)) + return __builtin_popcount(a); +#else + a = a - ((a >> 1) & 0x55555555); + a = (a & 0x33333333) + ((a >> 2) & 0x33333333); + return (((a + (a >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; +#endif +} + +// Find the sequence comparison of a and b, this is the distance +// between a and b ignoring overflow +static inline int lfs_scmp(uint32_t a, uint32_t b) +{ + return (int)(unsigned)(a - b); +} + +// Convert from 32-bit little-endian to native order +static inline uint32_t lfs_fromle32(uint32_t a) +{ +#if !defined(LFS_NO_INTRINSICS) && ((defined(BYTE_ORDER) && BYTE_ORDER == ORDER_LITTLE_ENDIAN) || \ + (defined(__BYTE_ORDER) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN) || \ + (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) + return a; +#elif !defined(LFS_NO_INTRINSICS) && \ + ((defined(BYTE_ORDER) && BYTE_ORDER == ORDER_BIG_ENDIAN) || (defined(__BYTE_ORDER) && __BYTE_ORDER == __ORDER_BIG_ENDIAN) || \ + (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) + return __builtin_bswap32(a); +#else + return (((uint8_t *)&a)[0] << 0) | (((uint8_t *)&a)[1] << 8) | (((uint8_t *)&a)[2] << 16) | (((uint8_t *)&a)[3] << 24); +#endif +} + +// Convert to 32-bit little-endian from native order +static inline uint32_t lfs_tole32(uint32_t a) +{ + return lfs_fromle32(a); +} + +// Calculate CRC-32 with polynomial = 0x04c11db7 +void lfs_crc(uint32_t *crc, const void *buffer, size_t size); + +// Allocate memory, only used if buffers are not provided to littlefs +static inline void *lfs_malloc(size_t size) +{ +#ifndef LFS_NO_MALLOC + return malloc(size); +#else + (void)size; + return NULL; +#endif +} + +// Deallocate memory, only used if buffers are not provided to littlefs +static inline void lfs_free(void *p) +{ +#ifndef LFS_NO_MALLOC + free(p); +#else + (void)p; +#endif +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif +#endif diff --git a/src/power.h b/src/power.h index e9c0deb7c..97944fef7 100644 --- a/src/power.h +++ b/src/power.h @@ -84,6 +84,11 @@ class Power : private concurrency::OSThread void setStatusHandler(meshtastic::PowerStatus *handler) { statusHandler = handler; } const uint16_t OCV[11] = {OCV_ARRAY}; +#if defined(ELECROW_ThinkNode_M1) || defined(POWER_CFG) + uint8_t low_voltage_counter_led3; + int power_num = 0; +#endif + protected: meshtastic::PowerStatus *statusHandler; diff --git a/src/shutdown.h b/src/shutdown.h index c2ba6f670..f02cb7964 100644 --- a/src/shutdown.h +++ b/src/shutdown.h @@ -32,6 +32,8 @@ void powerCommandsCheck() delete screen; LOG_DEBUG("final reboot!"); reboot(); +#elif defined(ARCH_STM32WL) + HAL_NVIC_SystemReset(); #else rebootAtMsec = -1; LOG_WARN("FIXME implement reboot for this platform. Note that some settings require a restart to be applied"); diff --git a/src/sleep.cpp b/src/sleep.cpp index 202b8c354..02fa8d871 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -228,6 +228,7 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false, bool skipSaveN } #ifdef PIN_POWER_EN + digitalWrite(PIN_POWER_EN, LOW); pinMode(PIN_POWER_EN, INPUT); // power off peripherals // pinMode(PIN_POWER_EN1, INPUT_PULLDOWN); #endif diff --git a/userPrefs.jsonc b/userPrefs.jsonc index 6a3fdbb55..d522ad272 100644 --- a/userPrefs.jsonc +++ b/userPrefs.jsonc @@ -40,5 +40,9 @@ // "USERPREFS_OEM_IMAGE_WIDTH": "50", // "USERPREFS_OEM_IMAGE_HEIGHT": "28", // "USERPREFS_OEM_IMAGE_DATA": "{ 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0xC0, 0x07, 0x80, 0x0F, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x18, 0xFF, 0xFF, 0x61, 0x00, 0x00, 0x00, 0x0C, 0xFF, 0xFF, 0xC7, 0x00, 0x00, 0x00, 0x0C, 0xFF, 0xFF, 0xC7, 0x00, 0x00, 0x00, 0x18, 0xFF, 0xFF, 0x67, 0x00, 0x00, 0x00, 0x18, 0x1F, 0xF0, 0x67, 0x00, 0x00, 0x00, 0x30, 0x1F, 0xF8, 0x33, 0x00, 0x00, 0x00, 0x30, 0x00, 0xFC, 0x31, 0x00, 0x00, 0x00, 0x60, 0x00, 0xFE, 0x18, 0x00, 0x00, 0x00, 0x60, 0x00, 0x7E, 0x18, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x3F, 0x0C, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x1F, 0x0C, 0x00, 0x00, 0x00, 0x80, 0x81, 0x1F, 0x06, 0x00, 0x00, 0x00, 0x80, 0xC1, 0x0F, 0x06, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0xE6, 0x8F, 0x01, 0x00, 0x00, 0x00, 0x00, 0xEE, 0xC7, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00}", + // "USERPREFS_NETWORK_ENABLED_PROTOCOLS": "1", // Enable UDP mesh + // "USERPREFS_NETWORK_WIFI_ENABLED": "true", + // "USERPREFS_NETWORK_WIFI_SSID": "wifi_ssid", + // "USERPREFS_NETWORK_WIFI_PSK": "wifi_psk", "USERPREFS_TZ_STRING": "tzplaceholder " } diff --git a/variants/CDEBYTE_E77-MBL/platformio.ini b/variants/CDEBYTE_E77-MBL/platformio.ini new file mode 100644 index 000000000..8a8002086 --- /dev/null +++ b/variants/CDEBYTE_E77-MBL/platformio.ini @@ -0,0 +1,28 @@ +[env:CDEBYTE_E77-MBL] +extends = stm32_base +board = ebyte_e77_dev +board_upload.maximum_size = 233472 ; reserve the last 28KB for filesystem +board_level = extra +build_flags = + ${stm32_base.build_flags} + -Ivariants/CDEBYTE_E77-MBL + -DSERIAL_UART_INSTANCE=1 + -DPIN_SERIAL_RX=PA3 + -DPIN_SERIAL_TX=PA2 + -DHAL_DAC_MODULE_ONLY + -DHAL_RNG_MODULE_ENABLED + -DRADIOLIB_EXCLUDE_SX128X=1 + -DRADIOLIB_EXCLUDE_SX127X=1 + -DRADIOLIB_EXCLUDE_LR11X0=1 + -DMESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR=1 + -DMESHTASTIC_EXCLUDE_I2C=1 + -DMESHTASTIC_EXCLUDE_WIFI=1 + -DMESHTASTIC_EXCLUDE_BLUETOOTH=1 + -DMESHTASTIC_EXCLUDE_GPS=1 + -DMESHTASTIC_EXCLUDE_SCREEN=1 + -DMESHTASTIC_EXCLUDE_MQTT=1 + -DMESHTASTIC_EXCLUDE_POWERMON=1 + ;-DPIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF + ;-DCFG_DEBUG + +upload_port = stlink \ No newline at end of file diff --git a/variants/CDEBYTE_E77-MBL/variant.h b/variants/CDEBYTE_E77-MBL/variant.h new file mode 100644 index 000000000..52801dac7 --- /dev/null +++ b/variants/CDEBYTE_E77-MBL/variant.h @@ -0,0 +1,22 @@ +/* +EByte E77-MBL series +https://www.cdebyte.com/products/E77-900MBL-01 +https://www.cdebyte.com/products/E77-400MBL-01 +https://github.com/olliw42/mLRS-docu/blob/master/docs/EBYTE_E77_MBL.md +*/ + +/* +This variant is a work in progress. +Do not expect a working Meshtastic device with this target. +*/ + +#ifndef _VARIANT_EBYTE_E77_ +#define _VARIANT_EBYTE_E77_ + +#define USE_STM32WLx + +#define LED_PIN PB4 // LED1 +// #define LED_PIN PB3 // LED2 +#define LED_STATE_ON 1 + +#endif diff --git a/variants/ELECROW-ThinkNode-M1/platformio.ini b/variants/ELECROW-ThinkNode-M1/platformio.ini new file mode 100644 index 000000000..f37f6d310 --- /dev/null +++ b/variants/ELECROW-ThinkNode-M1/platformio.ini @@ -0,0 +1,29 @@ +; First prototype eink/nrf52840/sx1262 device +[env:thinknode_m1] +extends = nrf52840_base +board = ThinkNode-M1 +board_check = true +debug_tool = jlink + +# add -DCFG_SYSVIEW if you want to use the Segger systemview tool for OS profiling. +build_flags = ${nrf52840_base.build_flags} -Ivariants/ELECROW-ThinkNode-M1 + -DELECROW_ThinkNode_M1 + -DGPS_POWER_TOGGLE + -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m4/fpv4-sp-d16-hard" + -DEINK_DISPLAY_MODEL=GxEPD2_154_D67 + -DEINK_WIDTH=200 + -DEINK_HEIGHT=200 + -DUSE_EINK_DYNAMICDISPLAY ; Enable Dynamic EInk + -DEINK_LIMIT_FASTREFRESH=10 ; How many consecutive fast-refreshes are permitted //20 + -DEINK_LIMIT_RATE_BACKGROUND_SEC=10 ; Minimum interval between BACKGROUND updates //30 + -DEINK_LIMIT_RATE_RESPONSIVE_SEC=1 ; Minimum interval between RESPONSIVE updates +; -DEINK_LIMIT_GHOSTING_PX=2000 ; (Optional) How much image ghosting is tolerated + -DEINK_BACKGROUND_USES_FAST ; (Optional) Use FAST refresh for both BACKGROUND and RESPONSIVE, until a limit is reached. + +build_src_filter = ${nrf52_base.build_src_filter} +<../variants/ELECROW-ThinkNode-M1> +lib_deps = + ${nrf52840_base.lib_deps} + https://github.com/meshtastic/GxEPD2/archive/33db3fa8ee6fc47d160bdb44f8f127c9a9203a10.zip + lewisxhe/PCF8563_Library@^1.0.1 + khoih-prog/nRF52_PWM@^1.0.1 +;upload_protocol = fs \ No newline at end of file diff --git a/variants/ELECROW-ThinkNode-M1/variant.cpp b/variants/ELECROW-ThinkNode-M1/variant.cpp new file mode 100644 index 000000000..cae079b74 --- /dev/null +++ b/variants/ELECROW-ThinkNode-M1/variant.cpp @@ -0,0 +1,44 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "variant.h" +#include "nrf.h" +#include "wiring_constants.h" +#include "wiring_digital.h" + +const uint32_t g_ADigitalPinMap[] = { + // P0 - pins 0 and 1 are hardwired for xtal and should never be enabled + 0xff, 0xff, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + + // P1 + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47}; + +void initVariant() +{ + // LED1 & LED2 + pinMode(PIN_LED1, OUTPUT); + ledOff(PIN_LED1); + + pinMode(PIN_LED2, OUTPUT); + ledOff(PIN_LED2); + + pinMode(PIN_LED3, OUTPUT); + ledOff(PIN_LED3); +} diff --git a/variants/ELECROW-ThinkNode-M1/variant.h b/variants/ELECROW-ThinkNode-M1/variant.h new file mode 100644 index 000000000..3bfa360f6 --- /dev/null +++ b/variants/ELECROW-ThinkNode-M1/variant.h @@ -0,0 +1,205 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _VARIANT_ELECROW_EINK_V1_0_ +#define _VARIANT_ELECROW_EINK_V1_0_ + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +#define USE_LFXO // Board uses 32khz crystal for LF + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "WVariant.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// Number of pins defined in PinDescription array +// 在PinDescription数组中定义的引脚数 +#define PINS_COUNT (48) +#define NUM_DIGITAL_PINS (48) +#define NUM_ANALOG_INPUTS (1) +#define NUM_ANALOG_OUTPUTS (0) + +#define PIN_LED1 -1 +#define PIN_LED2 -1 +#define PIN_LED3 -1 + +// LED +#define POWER_LED (32 + 6) // red +#define LED_POWER (32 + 4) +#define USER_LED (0 + 13) // green +// USB_CHECK +#define USB_CHECK (32 + 3) +#define ADC_V (0 + 8) + +#define LED_RED PIN_LED3 +#define LED_BLUE PIN_LED1 +#define LED_GREEN PIN_LED2 +#define LED_BUILTIN LED_BLUE +#define LED_CONN PIN_GREEN +#define LED_STATE_ON 0 // State when LED is lit // LED灯亮时的状态 +#define M1_buzzer (0 + 6) +/* + * Buttons + */ +#define PIN_BUTTON2 (32 + 10) +#define PIN_BUTTON1 (32 + 7) + +// #define PIN_BUTTON1 (0 + 11) +// #define PIN_BUTTON1 (32 + 7) + +// #define BUTTON_CLICK_MS 400 +// #define BUTTON_TOUCH_MS 200 + +/* + * Analog pins + */ +#define PIN_A0 (4) // Battery ADC + +#define BATTERY_PIN PIN_A0 + +static const uint8_t A0 = PIN_A0; + +#define ADC_RESOLUTION 14 + +#define PIN_NFC1 (9) +#define PIN_NFC2 (10) + +/*Wire Interfaces*/ +#define WIRE_INTERFACES_COUNT 1 + +#define PIN_WIRE_SDA (26) +#define PIN_WIRE_SCL (27) + +/* touch sensor, active high */ + +#define TP_SER_IO (0 + 11) + +#define PIN_RTC_INT (0 + 16) // Interrupt from the PCF8563 RTC + +/* +External serial flash WP25R1635FZUIL0 +*/ + +// QSPI Pins +#define PIN_QSPI_SCK (32 + 14) +#define PIN_QSPI_CS (32 + 15) +#define PIN_QSPI_IO0 (32 + 12) // MOSI if using two bit interface +#define PIN_QSPI_IO1 (32 + 13) // MISO if using two bit interface +#define PIN_QSPI_IO2 (0 + 7) // WP if using two bit interface (i.e. not used) +#define PIN_QSPI_IO3 (0 + 5) // HOLD if using two bit interface (i.e. not used) + +// On-board QSPI Flash +#define EXTERNAL_FLASH_DEVICES MX25R1635F +#define EXTERNAL_FLASH_USE_QSPI + +/* + * Lora radio + */ +#define SX126X_POWER_EN (0 + 21) +#define USE_SX1262 +#define SX126X_CS (0 + 24) // FIXME - we really should define LORA_CS instead +#define SX126X_DIO1 (0 + 20) +// Note DIO2 is attached internally to the module to an analog switch for TX/RX switching +// #define SX1262_DIO3 (0 + 21) // This is used as an *output* from the sx1262 and connected internally to power the tcxo, do not +// drive from the main +#define SX126X_BUSY (0 + 17) +#define SX126X_RESET (0 + 25) +#define SX126X_DIO2_AS_RF_SWITCH +#define SX126X_DIO3_TCXO_VOLTAGE 3.3 + +#define PIN_EINK_EN (32 + 11) // Note: this is really just backlight power +#define PIN_EINK_CS (0 + 30) +#define PIN_EINK_BUSY (0 + 3) +#define PIN_EINK_DC (0 + 28) +#define PIN_EINK_RES (0 + 2) +#define PIN_EINK_SCLK (0 + 31) +#define PIN_EINK_MOSI (0 + 29) // also called SDI + +// Controls power for all peripherals (eink + GPS + LoRa + Sensor) +#define PIN_POWER_EN (0 + 12) + +#define USE_EINK + +#define PIN_SPI1_MISO (32 + 7) +#define PIN_SPI1_MOSI PIN_EINK_MOSI +#define PIN_SPI1_SCK PIN_EINK_SCLK + +/* + * GPS pins + */ +// #define HAS_GPS 1 +#define GPS_L76K +#define GPS_BAUDRATE 9600 +#define PIN_GPS_REINIT (32 + 5) // An output to reset L76K GPS. As per datasheet, low for > 100ms will reset the L76K +#define PIN_GPS_STANDBY (32 + 2) // An output to wake GPS, low means allow sleep, high means force wake +// Seems to be missing on this new board +// #define PIN_GPS_PPS (32 + 4) // Pulse per second input from the GPS +#define GPS_TX_PIN (32 + 9) // This is for bits going TOWARDS the CPU +#define GPS_RX_PIN (32 + 8) // This is for bits going TOWARDS the GPS + +#define GPS_THREAD_INTERVAL 50 + +#define PIN_GPS_PPS (32 + 1) // GPS开关判断 + +#define PIN_SERIAL1_RX GPS_TX_PIN +#define PIN_SERIAL1_TX GPS_RX_PIN + +// PCF8563 RTC Module +#define PCF8563_RTC 0x51 + +/* + * SPI Interfaces + */ +#define SPI_INTERFACES_COUNT 2 + +// For LORA, spi 0 +#define PIN_SPI_MISO (0 + 23) +#define PIN_SPI_MOSI (0 + 22) +#define PIN_SPI_SCK (0 + 19) + +#define PIN_PWR_EN (0 + 6) + +// To debug via the segger JLINK console rather than the CDC-ACM serial device +// #define USE_SEGGER + +// Battery +// The battery sense is hooked to pin A0 (4) +// it is defined in the anlaolgue pin section of this file +// and has 12 bit resolution +#define BATTERY_SENSE_RESOLUTION_BITS 12 +#define BATTERY_SENSE_RESOLUTION 4096.0 +#undef AREF_VOLTAGE +#define AREF_VOLTAGE 3.0 +#define VBAT_AR_INTERNAL AR_INTERNAL_3_0 +#define ADC_MULTIPLIER (2.02F) + +// #define HAS_RTC 0 +// #define HAS_SCREEN 0 + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/variants/ELECROW-ThinkNode-M2/pins_arduino.h b/variants/ELECROW-ThinkNode-M2/pins_arduino.h new file mode 100644 index 000000000..46415d30f --- /dev/null +++ b/variants/ELECROW-ThinkNode-M2/pins_arduino.h @@ -0,0 +1,28 @@ +// Need this file for ESP32-S3 +// No need to modify this file, changes to pins imported from variant.h +// Most is similar to https://github.com/espressif/arduino-esp32/blob/master/variants/esp32s3/pins_arduino.h + +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include +#include + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +// Serial +static const uint8_t TX = UART_TX; +static const uint8_t RX = UART_RX; + +// Default SPI will be mapped to Radio +static const uint8_t SS = LORA_CS; +static const uint8_t SCK = LORA_SCK; +static const uint8_t MOSI = LORA_MOSI; +static const uint8_t MISO = LORA_MISO; + +// The default Wire will be mapped to PMU and RTC +static const uint8_t SCL = I2C_SCL; +static const uint8_t SDA = I2C_SDA; + +#endif /* Pins_Arduino_h */ diff --git a/variants/ELECROW-ThinkNode-M2/platformio.ini b/variants/ELECROW-ThinkNode-M2/platformio.ini new file mode 100644 index 000000000..c08c94a71 --- /dev/null +++ b/variants/ELECROW-ThinkNode-M2/platformio.ini @@ -0,0 +1,7 @@ +[env:thinknode_m2] +extends = esp32s3_base +board = ESP32-S3-WROOM-1-N4 +build_flags = + ${esp32s3_base.build_flags} + -D ELECROW_ThinkNode_M2 + -I variants/ELECROW-ThinkNode-M2 diff --git a/variants/ELECROW-ThinkNode-M2/variant.h b/variants/ELECROW-ThinkNode-M2/variant.h new file mode 100644 index 000000000..801d5606f --- /dev/null +++ b/variants/ELECROW-ThinkNode-M2/variant.h @@ -0,0 +1,64 @@ +// Status +#define LED_PIN_POWER 1 +#define BIAS_T_ENABLE LED_PIN_POWER +#define BIAS_T_VALUE HIGH + +#define PIN_BUTTON1 47 // 功能键 +#define PIN_BUTTON2 4 // 电源键 + +#define POWER_CFG +#define POWER_CHRG 6 +#define POWER_FULL 42 + +#define PIN_BUZZER 5 + +#define I2C_SCL 15 +#define I2C_SDA 16 + +#define UART_TX 43 +#define UART_RX 44 + +#define VEXT_ENABLE 46 // for OLED +#define VEXT_ON_VALUE HIGH + +#define SX126X_CS 10 +#define LORA_SCK 12 +#define LORA_MOSI 11 +#define LORA_MISO 13 +#define SX126X_RESET 21 +#define SX126X_BUSY 14 +#define SX126X_DIO1 3 +#define SX126X_DIO2_AS_RF_SWITCH +// #define SX126X_DIO3 9 +#define SX126X_DIO3_TCXO_VOLTAGE 3.3 + +#define SX126X_MAX_POWER 22 // SX126xInterface.cpp defaults to 22 if not defined, but here we define it for good practice +#define USE_SX1262 +#define LORA_CS SX126X_CS // FIXME: for some reason both are used in /src +#define LORA_DIO1 SX126X_DIO1 +#define SX126X_POWER_EN 48 + +// Battery +// #define BATTERY_PIN 2 +#define BATTERY_PIN 17 +// #define ADC_CHANNEL ADC1_GPIO2_CHANNEL +#define ADC_CHANNEL ADC2_GPIO17_CHANNEL +#define BATTERY_SENSE_RESOLUTION_BITS 12 +#define BATTERY_SENSE_RESOLUTION 4096.0 +#undef AREF_VOLTAGE +#define AREF_VOLTAGE 3.0 +#define VBAT_AR_INTERNAL AR_INTERNAL_3_0 +#define ADC_MULTIPLIER (1.548F) +#define BAT_MEASURE_ADC_UNIT 2 + +#define HAS_SCREEN 1 +#define USE_SH1106 1 + +// PCF8563 RTC Module +// #define PCF8563_RTC 0x51 +// #define PIN_RTC_INT 48 // Interrupt from the PCF8563 RTC +#define HAS_RTC 0 +#define HAS_GPS 0 + +#define BUTTON_PIN PIN_BUTTON1 +#define BUTTON_PIN_ALT PIN_BUTTON2 diff --git a/variants/ME25LS01-4Y10TD/platformio.ini b/variants/ME25LS01-4Y10TD/platformio.ini index 479a4e79c..bd764e107 100644 --- a/variants/ME25LS01-4Y10TD/platformio.ini +++ b/variants/ME25LS01-4Y10TD/platformio.ini @@ -12,4 +12,4 @@ lib_deps = ${nrf52840_base.lib_deps} ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) upload_protocol = nrfutil -upload_port = /dev/ttyACM1 \ No newline at end of file +;upload_port = /dev/ttyACM1 diff --git a/variants/ME25LS01-4Y10TD_e-ink/platformio.ini b/variants/ME25LS01-4Y10TD_e-ink/platformio.ini index 62314040a..fb9bd27d5 100644 --- a/variants/ME25LS01-4Y10TD_e-ink/platformio.ini +++ b/variants/ME25LS01-4Y10TD_e-ink/platformio.ini @@ -16,4 +16,4 @@ lib_deps = zinggjm/GxEPD2@^1.6.2 ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) upload_protocol = nrfutil -upload_port = /dev/ttyACM1 +;upload_port = /dev/ttyACM1 diff --git a/variants/MS24SF1/platformio.ini b/variants/MS24SF1/platformio.ini index 5cbd078d0..e109a3270 100644 --- a/variants/MS24SF1/platformio.ini +++ b/variants/MS24SF1/platformio.ini @@ -12,4 +12,4 @@ lib_deps = ${nrf52840_base.lib_deps} ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) upload_protocol = nrfutil -upload_port = /dev/ttyACM1 +;upload_port = /dev/ttyACM1 diff --git a/variants/MakePython_nRF52840_eink/platformio.ini b/variants/MakePython_nRF52840_eink/platformio.ini index b7ce97dcb..9e2d5bbf7 100644 --- a/variants/MakePython_nRF52840_eink/platformio.ini +++ b/variants/MakePython_nRF52840_eink/platformio.ini @@ -11,7 +11,7 @@ build_flags = ${nrf52840_base.build_flags} -Ivariants/MakePython_nRF52840_eink - build_src_filter = ${nrf52_base.build_src_filter} +<../variants/MakePython_nRF52840_eink> lib_deps = ${nrf52840_base.lib_deps} - https://github.com/meshtastic/ESP32_Codec2.git#633326c78ac251c059ab3a8c430fcdf25b41672f + https://github.com/meshtastic/ESP32_Codec2/archive/633326c78ac251c059ab3a8c430fcdf25b41672f.zip zinggjm/GxEPD2@^1.6.2 debug_tool = jlink ;upload_port = /dev/ttyACM4 \ No newline at end of file diff --git a/variants/MakePython_nRF52840_oled/platformio.ini b/variants/MakePython_nRF52840_oled/platformio.ini index 0146385e0..25dd36c08 100644 --- a/variants/MakePython_nRF52840_oled/platformio.ini +++ b/variants/MakePython_nRF52840_oled/platformio.ini @@ -7,5 +7,5 @@ build_flags = ${nrf52840_base.build_flags} -Ivariants/MakePython_nRF52840_oled - build_src_filter = ${nrf52_base.build_src_filter} +<../variants/MakePython_nRF52840_oled> lib_deps = ${nrf52840_base.lib_deps} - https://github.com/meshtastic/ESP32_Codec2.git#633326c78ac251c059ab3a8c430fcdf25b41672f + https://github.com/meshtastic/ESP32_Codec2/archive/633326c78ac251c059ab3a8c430fcdf25b41672f.zip debug_tool = jlink diff --git a/variants/crowpanel-esp32s3-5-epaper/pins_arduino.h b/variants/crowpanel-esp32s3-5-epaper/pins_arduino.h new file mode 100644 index 000000000..55a85939b --- /dev/null +++ b/variants/crowpanel-esp32s3-5-epaper/pins_arduino.h @@ -0,0 +1,26 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +// The default Wire will be mapped to PMU and RTC +static const uint8_t SDA = 21; +static const uint8_t SCL = 15; + +// Default SPI will be mapped to Radio +static const uint8_t SS = 14; +static const uint8_t MOSI = 8; +static const uint8_t MISO = 9; +static const uint8_t SCK = 3; + +#define SPI_MOSI (40) +#define SPI_SCK (39) +#define SPI_MISO (13) +#define SPI_CS (10) +// IO42 TF_3V3_CTL +#define SDCARD_CS SPI_CS + +#endif /* Pins_Arduino_h */ diff --git a/variants/crowpanel-esp32s3-5-epaper/platformio.ini b/variants/crowpanel-esp32s3-5-epaper/platformio.ini new file mode 100644 index 000000000..f1257a979 --- /dev/null +++ b/variants/crowpanel-esp32s3-5-epaper/platformio.ini @@ -0,0 +1,83 @@ +[env:crowpanel-esp32s3-5-epaper] +extends = esp32s3_base +board_build.arduino.memory_type = qio_opi +board_build.flash_mode = qio +board_build.psram_type = opi +board_upload.flash_size = 8MB +board_upload.maximum_size = 8388608 +board_build.partitions = default_8MB.csv +board = esp32-s3-devkitc-1 +;upload_port = /dev/ttyUSB0 +board_level = extra +upload_protocol = esptool +build_flags = + ${esp32_base.build_flags} -D CROWPANEL_ESP32S3_5_EPAPER -I variants/crowpanel-esp32s3-5-epaper + -D PRIVATE_HW + -DBOARD_HAS_PSRAM + -DGPS_POWER_TOGGLE + -DEINK_DISPLAY_MODEL=GxEPD2_579_GDEY0579T93 ;https://www.good-display.com/product/439.html + -DEINK_WIDTH=792 + -DEINK_HEIGHT=272 + -DUSE_EINK_DYNAMICDISPLAY ; Enable Dynamic EInk + -DEINK_LIMIT_FASTREFRESH=100 ; How many consecutive fast-refreshes are permitted + ;-DEINK_LIMIT_RATE_BACKGROUND_SEC=30 ; Minimum interval between BACKGROUND updates + ;-DEINK_LIMIT_RATE_RESPONSIVE_SEC=1 +lib_deps = + ${esp32s3_base.lib_deps} + https://github.com/meshtastic/GxEPD2/archive/33db3fa8ee6fc47d160bdb44f8f127c9a9203a10.zip + +[env:crowpanel-esp32s3-4-epaper] +extends = esp32s3_base +board_build.arduino.memory_type = qio_opi +board_build.flash_mode = qio +board_build.psram_type = opi +board_upload.flash_size = 8MB +board_upload.maximum_size = 8388608 +board_build.partitions = default_8MB.csv +board = esp32-s3-devkitc-1 +;upload_port = /dev/ttyUSB0 +board_level = extra +upload_protocol = esptool +build_flags = + ${esp32_base.build_flags} -D CROWPANEL_ESP32S3_4_EPAPER -I variants/crowpanel-esp32s3-5-epaper + -D PRIVATE_HW + -DBOARD_HAS_PSRAM + -DGPS_POWER_TOGGLE + -DEINK_DISPLAY_MODEL=GxEPD2_420_GYE042A87 ; similar Panel: GDEY042T81 : https://www.good-display.com/product/386.html + -DEINK_WIDTH=400 + -DEINK_HEIGHT=300 + -DUSE_EINK_DYNAMICDISPLAY ; Enable Dynamic EInk + -DEINK_LIMIT_FASTREFRESH=100 ; How many consecutive fast-refreshes are permitted + ;-DEINK_LIMIT_RATE_BACKGROUND_SEC=30 ; Minimum interval between BACKGROUND updates + ;-DEINK_LIMIT_RATE_RESPONSIVE_SEC=1 +lib_deps = + ${esp32s3_base.lib_deps} + https://github.com/meshtastic/GxEPD2/archive/33db3fa8ee6fc47d160bdb44f8f127c9a9203a10.zip + +[env:crowpanel-esp32s3-2-epaper] +extends = esp32s3_base +board_build.arduino.memory_type = qio_opi +board_build.flash_mode = qio +board_build.psram_type = opi +board_upload.flash_size = 8MB +board_upload.maximum_size = 8388608 +board_build.partitions = default_8MB.csv +board = esp32-s3-devkitc-1 +;upload_port = /dev/ttyUSB0 +board_level = extra +upload_protocol = esptool +build_flags = + ${esp32_base.build_flags} -D CROWPANEL_ESP32S3_2_EPAPER -I variants/crowpanel-esp32s3-5-epaper + -D PRIVATE_HW + -DBOARD_HAS_PSRAM + -DGPS_POWER_TOGGLE + -DEINK_DISPLAY_MODEL=GxEPD2_290_GDEY029T94 ;https://www.good-display.com/product/389.html + -DEINK_WIDTH=296 + -DEINK_HEIGHT=128 + -DUSE_EINK_DYNAMICDISPLAY ; Enable Dynamic EInk + -DEINK_LIMIT_FASTREFRESH=100 ; How many consecutive fast-refreshes are permitted + ;-DEINK_LIMIT_RATE_BACKGROUND_SEC=30 ; Minimum interval between BACKGROUND updates + ;-DEINK_LIMIT_RATE_RESPONSIVE_SEC=1 +lib_deps = + ${esp32s3_base.lib_deps} + https://github.com/meshtastic/GxEPD2/archive/33db3fa8ee6fc47d160bdb44f8f127c9a9203a10.zip diff --git a/variants/crowpanel-esp32s3-5-epaper/variant.h b/variants/crowpanel-esp32s3-5-epaper/variant.h new file mode 100644 index 000000000..360e33481 --- /dev/null +++ b/variants/crowpanel-esp32s3-5-epaper/variant.h @@ -0,0 +1,77 @@ +#define HAS_SDCARD +#define SDCARD_USE_SPI1 + +// Display (E-Ink) +#define USE_EINK +#define PIN_EINK_CS 45 +#define PIN_EINK_BUSY 48 +#define PIN_EINK_DC 46 +#define PIN_EINK_RES 47 +#define PIN_EINK_SCLK 12 +#define PIN_EINK_MOSI 11 +#define VEXT_ENABLE 7 // e-ink power enable pin +#define VEXT_ON_VALUE HIGH + +#define PIN_POWER_EN 42 // TF/SD Card Power Enable Pin + +// #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to +// measure battery voltage ratio of voltage divider = 2.0 (assumption) +// #define ADC_MULTIPLIER 2.11 // 2.0 + 10% for correction of display undervoltage. +// #define ADC_CHANNEL ADC1_GPIO1_CHANNEL + +#define I2C_SDA SDA // 21 +#define I2C_SCL SCL // 15 + +#define GPS_DEFAULT_NOT_PRESENT 1 +// #define GPS_RX_PIN 44 +// #define GPS_TX_PIN 43 + +#define LED_PIN 41 +#define BUTTON_PIN 2 +#define BUTTON_NEED_PULLUP + +// Buzzer - noisy ? +#define PIN_BUZZER (0 + 18) + +// Wheel +// Up 6 +// Push 5 +// Down 4 +// MENU Top 2 +// EXIT Bottom 1 + +// TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and +// we will probe at runtime for RF95 and if not found then probe for SX1262 +// #define USE_RF95 // RFM95/SX127x +#define USE_SX1262 +// #define USE_SX1280 + +#define LORA_SCK 3 +#define LORA_MISO 9 +#define LORA_MOSI 8 +#define LORA_CS 14 +#define LORA_RESET 38 + +#define LORA_DIO1 16 +#define LORA_DIO2 17 + +// per SX1262_Receive_Interrupt/utilities.h +#ifdef USE_SX1262 +#define SX126X_CS LORA_CS +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_DIO2 +#define SX126X_RESET LORA_RESET +#define SX126X_DIO2_AS_RF_SWITCH +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#endif + +// per SX128x_Receive_Interrupt/utilities.h +#ifdef USE_SX1280 +#define SX128X_CS LORA_CS +#define SX128X_DIO1 LORA_DIO1 +#define SX128X_BUSY LORA_DIO2 +#define SX128X_RESET LORA_RESET +#define SX128X_RXEN 21 +#define SX128X_TXEN 15 +#define SX128X_MAX_POWER 3 +#endif diff --git a/variants/diy/platformio.ini b/variants/diy/platformio.ini index 229f48bbf..825c464a2 100644 --- a/variants/diy/platformio.ini +++ b/variants/diy/platformio.ini @@ -88,6 +88,7 @@ debug_tool = jlink [env:t-energy-s3_e22] extends = esp32s3_base board = esp32-s3-devkitc-1 +board_build.partitions = default_16MB.csv board_level = extra board_upload.flash_size = 16MB ;Specify the FLASH capacity as 16MB board_build.arduino.memory_type = qio_opi ;Enable internal PSRAM @@ -100,4 +101,4 @@ build_flags = -D BOARD_HAS_PSRAM -D ARDUINO_USB_MODE=0 -D ARDUINO_USB_CDC_ON_BOOT=1 - -I variants/diy/t-energy-s3_e22 \ No newline at end of file + -I variants/diy/t-energy-s3_e22 diff --git a/variants/dreamcatcher/platformio.ini b/variants/dreamcatcher/platformio.ini index c57849d96..6527d89be 100644 --- a/variants/dreamcatcher/platformio.ini +++ b/variants/dreamcatcher/platformio.ini @@ -1,6 +1,7 @@ [env:dreamcatcher] ; 2301, latest revision extends = esp32s3_base board = esp32s3box +board_build.partitions = default_16MB.csv board_level = extra build_flags = @@ -8,7 +9,7 @@ build_flags = -D PRIVATE_HW -D OTHERNET_DC_REV=2301 -I variants/dreamcatcher - -DARDUINO_USB_CDC_ON_BOOT=1 + -D ARDUINO_USB_CDC_ON_BOOT=1 lib_deps = ${esp32s3_base.lib_deps} earlephilhower/ESP8266Audio@^1.9.9 @@ -17,6 +18,7 @@ lib_deps = ${esp32s3_base.lib_deps} [env:dreamcatcher-2206] extends = esp32s3_base board = esp32s3box +board_build.partitions = default_16MB.csv board_level = extra build_flags = @@ -24,4 +26,4 @@ build_flags = -D PRIVATE_HW -D OTHERNET_DC_REV=2206 -I variants/dreamcatcher - -DARDUINO_USB_CDC_ON_BOOT=1 \ No newline at end of file + -D ARDUINO_USB_CDC_ON_BOOT=1 diff --git a/variants/esp32-s3-pico/platformio.ini b/variants/esp32-s3-pico/platformio.ini index 20a41ba56..69969c601 100644 --- a/variants/esp32-s3-pico/platformio.ini +++ b/variants/esp32-s3-pico/platformio.ini @@ -4,6 +4,7 @@ board_level = extra extends = esp32s3_base upload_protocol = esptool board = esp32-s3-pico +board_build.partitions = default_16MB.csv board_upload.use_1200bps_touch = yes board_upload.wait_for_upload_port = yes diff --git a/variants/hackerboxes_esp32_io/platformio.ini b/variants/hackerboxes_esp32_io/platformio.ini new file mode 100644 index 000000000..f024dac3e --- /dev/null +++ b/variants/hackerboxes_esp32_io/platformio.ini @@ -0,0 +1,12 @@ +[env:hackerboxes-esp32-io] +extends = esp32_base +board = esp32dev +board_level = extra +build_flags = + ${esp32_base.build_flags} + -D PRIVATE_HW + -I variants/hackerboxes_esp32_io +monitor_speed = 115200 +upload_protocol = esptool +;upload_port = /dev/ttyUSB0 +upload_speed = 921600 \ No newline at end of file diff --git a/variants/hackerboxes_esp32_io/variant.h b/variants/hackerboxes_esp32_io/variant.h new file mode 100644 index 000000000..06f0032ee --- /dev/null +++ b/variants/hackerboxes_esp32_io/variant.h @@ -0,0 +1,30 @@ +#define BUTTON_PIN 0 + +// HACKBOX LoRa IO Kit +// Uses a ESP-32-WROOM and a RA-01SH (SX1262) LoRa Board + +#define LED_PIN 2 // LED +#define LED_STATE_ON 1 // State when LED is lit + +#define HAS_SCREEN 0 +#define HAS_GPS 0 +#undef GPS_RX_PIN +#undef GPS_TX_PIN + +#define USE_SX1262 +#define LORA_SCK 18 +#define LORA_MISO 19 +#define LORA_MOSI 23 +#define LORA_CS 5 +#define LORA_DIO0 RADIOLIB_NC +#define LORA_RESET 27 +#define LORA_DIO1 33 +#define LORA_DIO2 RADIOLIB_NC +#define LORA_BUSY 32 + +#define SX126X_DIO2_AS_RF_SWITCH +#define SX126X_CS LORA_CS +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_BUSY +#define SX126X_RESET LORA_RESET +#define SX126X_MAX_POWER 22 // Max power of the RA-01SH is 22db \ No newline at end of file diff --git a/variants/hackerboxes_esp32c3_oled/platformio.ini b/variants/hackerboxes_esp32c3_oled/platformio.ini new file mode 100644 index 000000000..4fcbf2ade --- /dev/null +++ b/variants/hackerboxes_esp32c3_oled/platformio.ini @@ -0,0 +1,14 @@ +[env:hackerboxes-esp32c3-oled] +extends = esp32c3_base +board = esp32-c3-devkitm-1 +board_level = extra +build_flags = + ${esp32_base.build_flags} + -D PRIVATE_HW + -D ARDUINO_USB_MODE=1 + -D ARDUINO_USB_CDC_ON_BOOT=1 + -I variants/hackerboxes_esp32c3_oled +monitor_speed = 115200 +upload_protocol = esptool +;upload_port = /dev/ttyUSB0 +upload_speed = 921600 \ No newline at end of file diff --git a/variants/hackerboxes_esp32c3_oled/variant.h b/variants/hackerboxes_esp32c3_oled/variant.h new file mode 100644 index 000000000..7432a9941 --- /dev/null +++ b/variants/hackerboxes_esp32c3_oled/variant.h @@ -0,0 +1,36 @@ +#define BUTTON_PIN 9 + +// Hackerboxes LoRa ESP32-C3 OLED Kit +// Uses a ESP32-C3 OLED Board and a RA-01SH (SX1262) LoRa Board + +#define LED_PIN 8 // LED +#define LED_STATE_ON 1 // State when LED is lit + +#define HAS_SCREEN 0 +#define HAS_GPS 0 +#undef GPS_RX_PIN +#undef GPS_TX_PIN + +// #define USE_SSD1306_72_40 +// #define I2C_SDA 5 // I2C pins for this board +// #define I2C_SCL 6 // +// #define TFT_WIDTH 72 +// #define TFT_HEIGHT 40 + +#define USE_SX1262 +#define LORA_SCK 4 +#define LORA_MISO 7 +#define LORA_MOSI 3 +#define LORA_CS 1 +#define LORA_DIO0 RADIOLIB_NC +#define LORA_RESET 0 +#define LORA_DIO1 20 +#define LORA_DIO2 RADIOLIB_NC +#define LORA_BUSY 10 + +#define SX126X_DIO2_AS_RF_SWITCH +#define SX126X_CS LORA_CS +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_BUSY +#define SX126X_RESET LORA_RESET +#define SX126X_MAX_POWER 22 // Max power of the RA-01SH is 22db \ No newline at end of file diff --git a/variants/heltec_capsule_sensor_v3/platformio.ini b/variants/heltec_capsule_sensor_v3/platformio.ini index b5ffb65c2..8d1c039c1 100644 --- a/variants/heltec_capsule_sensor_v3/platformio.ini +++ b/variants/heltec_capsule_sensor_v3/platformio.ini @@ -2,7 +2,7 @@ extends = esp32s3_base board = heltec_wifi_lora_32_V3 board_check = true - +board_build.partitions = default_8MB.csv build_flags = ${esp32s3_base.build_flags} -I variants/heltec_capsule_sensor_v3 -D HELTEC_CAPSULE_SENSOR_V3 diff --git a/variants/heltec_mesh_node_t114/platformio.ini b/variants/heltec_mesh_node_t114/platformio.ini index 1b06c7f5e..4f83d8516 100644 --- a/variants/heltec_mesh_node_t114/platformio.ini +++ b/variants/heltec_mesh_node_t114/platformio.ini @@ -14,4 +14,4 @@ build_src_filter = ${nrf52_base.build_src_filter} +<../variants/heltec_mesh_node lib_deps = ${nrf52840_base.lib_deps} lewisxhe/PCF8563_Library@^1.0.1 - https://github.com/meshtastic/st7789#bd33ea58ddfe4a5e4a66d53300ccbd38d66ac21f \ No newline at end of file + https://github.com/meshtastic/st7789/archive/bd33ea58ddfe4a5e4a66d53300ccbd38d66ac21f.zip \ No newline at end of file diff --git a/variants/heltec_sensor_hub/platformio.ini b/variants/heltec_sensor_hub/platformio.ini new file mode 100644 index 000000000..53f84fab4 --- /dev/null +++ b/variants/heltec_sensor_hub/platformio.ini @@ -0,0 +1,11 @@ +[env:heltec_sensor_hub] +extends = esp32s3_base +board = heltec_wifi_lora_32_V3 +board_check = true + +build_flags = + ${esp32s3_base.build_flags} -I variants/heltec_sensor_hub + -D HELTEC_SENSOR_HUB + +lib_deps = ${esp32s3_base.lib_deps} + adafruit/Adafruit NeoPixel @ ^1.12.0 diff --git a/variants/heltec_sensor_hub/variant.h b/variants/heltec_sensor_hub/variant.h new file mode 100644 index 000000000..771cefee3 --- /dev/null +++ b/variants/heltec_sensor_hub/variant.h @@ -0,0 +1,46 @@ +#define EXT_PWR_DETECT 20 + +#define BUTTON_PIN 17 + +#define BATTERY_PIN 7 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define ADC_CHANNEL ADC1_GPIO7_CHANNEL +#define ADC_ATTENUATION ADC_ATTEN_DB_2_5 // lower dB for high resistance voltage divider +#define ADC_MULTIPLIER (4.9 * 1.045) +#define ADC_CTRL 34 // active HIGH, powers the voltage divider. Only on 1.1 +#define ADC_CTRL_ENABLED HIGH + +#define HAS_NEOPIXEL // Enable the use of neopixels +#define NEOPIXEL_COUNT 1 // How many neopixels are connected +#define NEOPIXEL_DATA 18 // gpio pin used to send data to the neopixels +#define NEOPIXEL_TYPE (NEO_GRB + NEO_KHZ800) // type of neopixels in use + +#define USE_SX1262 +#define LORA_DIO0 RADIOLIB_NC +#define LORA_RESET 12 +#define LORA_DIO1 14 // SX1262 IRQ +#define LORA_DIO2 13 // SX1262 BUSY + +#define LORA_SCK 9 +#define LORA_MISO 11 +#define LORA_MOSI 10 +#define LORA_CS 8 + +#define SX126X_CS LORA_CS +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_DIO2 +#define SX126X_RESET LORA_RESET + +#define SX126X_DIO2_AS_RF_SWITCH +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 + +#define I2C_SDA 1 +#define I2C_SCL 2 +#define HAS_SCREEN 0 +#define SENSOR_POWER_CTRL_PIN 33 +#define SENSOR_POWER_ON 1 + +#define PERIPHERAL_WARMUP_MS 100 + +#define ESP32S3_WAKE_TYPE ESP_EXT1_WAKEUP_ANY_HIGH + +#define ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE 1 \ No newline at end of file diff --git a/variants/heltec_v3/platformio.ini b/variants/heltec_v3/platformio.ini index e8f73e1ef..4be96b019 100644 --- a/variants/heltec_v3/platformio.ini +++ b/variants/heltec_v3/platformio.ini @@ -2,7 +2,7 @@ extends = esp32s3_base board = heltec_wifi_lora_32_V3 board_check = true -# Temporary until espressif creates a release with this new target +board_build.partitions = default_8MB.csv build_flags = ${esp32s3_base.build_flags} -D HELTEC_V3 -I variants/heltec_v3 - -DGPS_POWER_TOGGLE ; comment this line to disable triple press function on the user button to turn off gps entirely. \ No newline at end of file + -D GPS_POWER_TOGGLE ; comment this line to disable triple press function on the user button to turn off gps entirely. diff --git a/variants/heltec_vision_master_e213/nicheGraphics.h b/variants/heltec_vision_master_e213/nicheGraphics.h index f7a37fc61..75e4423be 100644 --- a/variants/heltec_vision_master_e213/nicheGraphics.h +++ b/variants/heltec_vision_master_e213/nicheGraphics.h @@ -6,7 +6,7 @@ // InkHUD-specific components // --------------------------- -#include "graphics/niche/InkHUD/WindowManager.h" +#include "graphics/niche/InkHUD/InkHUD.h" // Applets #include "graphics/niche/InkHUD/Applets/User/AllMessage/AllMessageApplet.h" @@ -49,49 +49,43 @@ void setupNicheGraphics() // InkHUD // ---------------------------- - InkHUD::WindowManager *windowManager = InkHUD::WindowManager::getInstance(); + InkHUD::InkHUD *inkhud = InkHUD::InkHUD::getInstance(); // Set the driver - windowManager->setDriver(driver); + inkhud->setDriver(driver); // Set how many FAST updates per FULL update // Set how unhealthy additional FAST updates beyond this number are - windowManager->setDisplayResilience(10, 1.5); + inkhud->setDisplayResilience(10, 1.5); // Prepare fonts - InkHUD::AppletFont largeFont(FreeSans9pt7b); - InkHUD::AppletFont smallFont(FreeSans6pt7b); + InkHUD::Applet::fontLarge = InkHUD::AppletFont(FreeSans9pt7b); + InkHUD::Applet::fontSmall = InkHUD::AppletFont(FreeSans6pt7b); /* // Font localization demo: Cyrillic - InkHUD::AppletFont smallFont(FreeSans6pt8bCyrillic); - smallFont.addSubstitutionsWin1251(); + InkHUD::Applet::fontSmall = InkHUD::AppletFont(FreeSans6pt8bCyrillic); + InkHUD::Applet::fontSmall.addSubstitutionsWin1251(); */ - InkHUD::Applet::setDefaultFonts(largeFont, smallFont); - // Init settings, and customize defaults - InkHUD::settings.userTiles.maxCount = 2; // How many tiles can the display handle? - InkHUD::settings.rotation = 3; // 270 degrees clockwise - InkHUD::settings.userTiles.count = 1; // One tile only by default, keep things simple for new users - InkHUD::settings.optionalMenuItems.nextTile = false; // Behavior handled by aux button instead + // Customize default settings + inkhud->persistence->settings.userTiles.maxCount = 2; // How many tiles can the display handle? + inkhud->persistence->settings.rotation = 3; // 270 degrees clockwise + inkhud->persistence->settings.userTiles.count = 1; // One tile only by default, keep things simple for new users + inkhud->persistence->settings.optionalMenuItems.nextTile = false; // Behavior handled by aux button instead // Pick applets - // Note: order of applets determines priority of "auto-show" feature - // Optional arguments for defaults: - // - is activated? - // - is autoshown? - // - is foreground on a specific tile (index)? - windowManager->addApplet("All Messages", new InkHUD::AllMessageApplet, true, true); // Activated, autoshown - windowManager->addApplet("DMs", new InkHUD::DMApplet); - windowManager->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0)); - windowManager->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1)); - windowManager->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated - windowManager->addApplet("Recents List", new InkHUD::RecentsListApplet); - windowManager->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, not autoshown, default on tile 0 - // windowManager->addApplet("Basic", new InkHUD::BasicExampleApplet); - // windowManager->addApplet("NewMsg", new InkHUD::NewMsgExampleApplet); + inkhud->addApplet("All Messages", new InkHUD::AllMessageApplet, true, true); // Activated, autoshown + inkhud->addApplet("DMs", new InkHUD::DMApplet); // Inactive + inkhud->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0)); // Inactive + inkhud->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1)); // Inactive + inkhud->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated + inkhud->addApplet("Recents List", new InkHUD::RecentsListApplet); // Inactive + inkhud->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, not autoshown, default on tile 0 + // inkhud->addApplet("Basic", new InkHUD::BasicExampleApplet); + // inkhud->addApplet("NewMsg", new InkHUD::NewMsgExampleApplet); - // Start running window manager - windowManager->begin(); + // Start running InkHUD + inkhud->begin(); // Buttons // -------------------------- @@ -102,13 +96,13 @@ void setupNicheGraphics() // Setup the main user button buttons->setWiring(MAIN_BUTTON, BUTTON_PIN); - buttons->setHandlerShortPress(MAIN_BUTTON, []() { InkHUD::WindowManager::getInstance()->handleButtonShort(); }); - buttons->setHandlerLongPress(MAIN_BUTTON, []() { InkHUD::WindowManager::getInstance()->handleButtonLong(); }); + buttons->setHandlerShortPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->shortpress(); }); + buttons->setHandlerLongPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->longpress(); }); // Setup the aux button // Bonus feature of VME213 buttons->setWiring(AUX_BUTTON, BUTTON_PIN_SECONDARY); - buttons->setHandlerShortPress(AUX_BUTTON, []() { InkHUD::WindowManager::getInstance()->nextTile(); }); + buttons->setHandlerShortPress(AUX_BUTTON, []() { InkHUD::InkHUD::getInstance()->nextTile(); }); buttons->start(); } diff --git a/variants/heltec_vision_master_e213/platformio.ini b/variants/heltec_vision_master_e213/platformio.ini index 3d8f2e7cd..037d10168 100644 --- a/variants/heltec_vision_master_e213/platformio.ini +++ b/variants/heltec_vision_master_e213/platformio.ini @@ -1,8 +1,9 @@ [env:heltec-vision-master-e213] extends = esp32s3_base board = heltec_vision_master_e213 +board_build.partitions = default_8MB.csv build_flags = - ${esp32s3_base.build_flags} + ${esp32s3_base.build_flags} -Ivariants/heltec_vision_master_e213 -DHELTEC_VISION_MASTER_E213 -DUSE_EINK @@ -15,16 +16,14 @@ build_flags = -DEINK_HASQUIRK_GHOSTING ; Display model is identified as "prone to ghosting" lib_deps = ${esp32s3_base.lib_deps} - https://github.com/meshtastic/GxEPD2#b202ebfec6a4821e098cf7a625ba0f6f2400292d + https://github.com/meshtastic/GxEPD2/archive/b202ebfec6a4821e098cf7a625ba0f6f2400292d.zip lewisxhe/PCF8563_Library@^1.0.1 upload_speed = 115200 -; Using experimental InkHUD UI (work in progress) -[platformio] -extra_configs = src/graphics/niche/InkHUD/PlatformioConfig.ini [env:heltec-vision-master-e213-inkhud] extends = esp32s3_base, inkhud board = heltec_vision_master_e213 +board_build.partitions = default_8MB.csv build_src_filter = ${esp32_base.build_src_filter} ${inkhud.build_src_filter} @@ -33,8 +32,8 @@ build_flags = ${inkhud.build_flags} -I variants/heltec_vision_master_e213 -D HELTEC_VISION_MASTER_E213 - -D MAX_THREADS=40 + -D MAX_THREADS=40 ; Required if used with WiFi lib_deps = - ${inkhud.lib_deps} ; InkHUD libs first, so we get GFXRoot intead of AdafruitGFX + ${inkhud.lib_deps} ; InkHUD libs first, so we get GFXRoot instead of AdafruitGFX ${esp32s3_base.lib_deps} -upload_speed = 115200 \ No newline at end of file +upload_speed = 921600 \ No newline at end of file diff --git a/variants/heltec_vision_master_e290/nicheGraphics.h b/variants/heltec_vision_master_e290/nicheGraphics.h index c55a84ec0..2674436b8 100644 --- a/variants/heltec_vision_master_e290/nicheGraphics.h +++ b/variants/heltec_vision_master_e290/nicheGraphics.h @@ -62,66 +62,65 @@ void setupNicheGraphics() // InkHUD // ---------------------------- - InkHUD::WindowManager *windowManager = InkHUD::WindowManager::getInstance(); + InkHUD::InkHUD *inkhud = InkHUD::InkHUD::getInstance(); // Set the driver - windowManager->setDriver(driver); + inkhud->setDriver(driver); // Set how many FAST updates per FULL update // Set how unhealthy additional FAST updates beyond this number are - windowManager->setDisplayResilience(7, 1.5); + inkhud->setDisplayResilience(7, 1.5); // Prepare fonts - InkHUD::AppletFont largeFont(FreeSans9pt7b); - InkHUD::AppletFont smallFont(FreeSans6pt7b); + InkHUD::Applet::fontLarge = InkHUD::AppletFont(FreeSans9pt7b); + InkHUD::Applet::fontSmall = InkHUD::AppletFont(FreeSans6pt7b); /* // Font localization demo: Cyrillic - InkHUD::AppletFont smallFont(FreeSans6pt8bCyrillic); - smallFont.addSubstitutionsWin1251(); + InkHUD::Applet::fontSmall = InkHUD::AppletFont(FreeSans6pt8bCyrillic); + InkHUD::Applet::fontSmall.addSubstitutionsWin1251(); */ - InkHUD::Applet::setDefaultFonts(largeFont, smallFont); - // Init settings, and customize defaults - InkHUD::settings.userTiles.maxCount = 2; // How many tiles can the display handle? - InkHUD::settings.rotation = 1; // 90 degrees clockwise - InkHUD::settings.userTiles.count = 1; // One tile only by default, keep things simple for new users - InkHUD::settings.optionalMenuItems.nextTile = false; // Behavior handled by aux button instead + // Customize default settings + inkhud->persistence->settings.userTiles.maxCount = 2; // How many tiles can the display handle? + inkhud->persistence->settings.rotation = 1; // 90 degrees clockwise + inkhud->persistence->settings.userTiles.count = 1; // One tile only by default, keep things simple for new users + inkhud->persistence->settings.optionalMenuItems.nextTile = false; // Behavior handled by aux button instead // Pick applets - // Note: order of applets determines priority of "auto-show" feature - // Optional arguments for defaults: - // - is activated? - // - is autoshown? - // - is foreground on a specific tile (index)? - windowManager->addApplet("All Messages", new InkHUD::AllMessageApplet, true, true); // Activated, autoshown - windowManager->addApplet("DMs", new InkHUD::DMApplet); - windowManager->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0)); - windowManager->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1)); - windowManager->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated - windowManager->addApplet("Recents List", new InkHUD::RecentsListApplet); - windowManager->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, not autoshown, default on tile 0 - // windowManager->addApplet("Basic", new InkHUD::BasicExampleApplet); - // windowManager->addApplet("NewMsg", new InkHUD::NewMsgExampleApplet); - // Start running window manager - windowManager->begin(); + // Order of applets determines priority of "auto-show" feature. + // Optional arguments for default state: + // - is activated? + // - is autoshown? + // - is foreground on a specific tile (index)? + + inkhud->addApplet("All Messages", new InkHUD::AllMessageApplet, true, true); // Activated, autoshown + inkhud->addApplet("DMs", new InkHUD::DMApplet); // Inactive + inkhud->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0)); // Inactive + inkhud->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1)); // Inactive + inkhud->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated + inkhud->addApplet("Recents List", new InkHUD::RecentsListApplet); // Inactive + inkhud->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, not autoshown, default on tile 0 + // inkhud->addApplet("Basic", new InkHUD::BasicExampleApplet); + // inkhud->addApplet("NewMsg", new InkHUD::NewMsgExampleApplet); + + // Start running InkHUD + inkhud->begin(); // Buttons // -------------------------- - Inputs::TwoButton *buttons = Inputs::TwoButton::getInstance(); // Shared NicheGraphics component - constexpr uint8_t MAIN_BUTTON = 0; - constexpr uint8_t AUX_BUTTON = 1; + Inputs::TwoButton *buttons = Inputs::TwoButton::getInstance(); // A shared NicheGraphics component - // Setup the main user button - buttons->setWiring(MAIN_BUTTON, BUTTON_PIN); - buttons->setHandlerShortPress(MAIN_BUTTON, []() { InkHUD::WindowManager::getInstance()->handleButtonShort(); }); - buttons->setHandlerLongPress(MAIN_BUTTON, []() { InkHUD::WindowManager::getInstance()->handleButtonLong(); }); + // Setup the main user button (0) + buttons->setWiring(0, BUTTON_PIN); + buttons->setHandlerShortPress(0, []() { InkHUD::InkHUD::getInstance()->shortpress(); }); + buttons->setHandlerLongPress(0, []() { InkHUD::InkHUD::getInstance()->longpress(); }); - // Setup the aux button + // Setup the aux button (1) // Bonus feature of VME290 - buttons->setWiring(AUX_BUTTON, BUTTON_PIN_SECONDARY); - buttons->setHandlerShortPress(AUX_BUTTON, []() { InkHUD::WindowManager::getInstance()->nextTile(); }); + buttons->setWiring(1, BUTTON_PIN_SECONDARY); + buttons->setHandlerShortPress(1, []() { InkHUD::InkHUD::getInstance()->nextTile(); }); buttons->start(); } diff --git a/variants/heltec_vision_master_e290/platformio.ini b/variants/heltec_vision_master_e290/platformio.ini index d3aa85d65..6952e9f9e 100644 --- a/variants/heltec_vision_master_e290/platformio.ini +++ b/variants/heltec_vision_master_e290/platformio.ini @@ -2,6 +2,7 @@ [env:heltec-vision-master-e290] extends = esp32s3_base board = heltec_vision_master_e290 +board_build.partitions = default_8MB.csv build_flags = ${esp32s3_base.build_flags} -I variants/heltec_vision_master_e290 @@ -19,16 +20,14 @@ build_flags = lib_deps = ${esp32s3_base.lib_deps} - https://github.com/meshtastic/GxEPD2#448c8538129fde3d02a7cb5e6fc81971ad92547f + https://github.com/meshtastic/GxEPD2/archive/448c8538129fde3d02a7cb5e6fc81971ad92547f.zip lewisxhe/PCF8563_Library@^1.0.1 upload_speed = 115200 -; Using experimental InkHUD UI (work in progress) -[platformio] -extra_configs = src/graphics/niche/InkHUD/PlatformioConfig.ini [env:heltec-vision-master-e290-inkhud] extends = esp32s3_base, inkhud board = heltec_vision_master_e290 +board_build.partitions = default_8MB.csv build_src_filter = ${esp32_base.build_src_filter} ${inkhud.build_src_filter} @@ -37,8 +36,8 @@ build_flags = ${inkhud.build_flags} -I variants/heltec_vision_master_e290 -D HELTEC_VISION_MASTER_E290 - -D MAX_THREADS=40 + -D MAX_THREADS=40 ; Required if used with WiFi lib_deps = - ${inkhud.lib_deps} ; InkHUD libs first, so we get GFXRoot intead of AdafruitGFX + ${inkhud.lib_deps} ; InkHUD libs first, so we get GFXRoot instead of AdafruitGFX ${esp32s3_base.lib_deps} -upload_speed = 115200 \ No newline at end of file +upload_speed = 921600 \ No newline at end of file diff --git a/variants/heltec_vision_master_t190/platformio.ini b/variants/heltec_vision_master_t190/platformio.ini index 0c504d62b..7f55a1be7 100644 --- a/variants/heltec_vision_master_t190/platformio.ini +++ b/variants/heltec_vision_master_t190/platformio.ini @@ -1,13 +1,13 @@ [env:heltec-vision-master-t190] extends = esp32s3_base board = heltec_vision_master_t190 +board_build.partitions = default_8MB.csv build_flags = ${esp32s3_base.build_flags} -Ivariants/heltec_vision_master_t190 - -DHELTEC_VISION_MASTER_T190 - ; -D PRIVATE_HW + -DHELTEC_VISION_MASTER_T190 lib_deps = ${esp32s3_base.lib_deps} lewisxhe/PCF8563_Library@^1.0.1 - https://github.com/meshtastic/st7789#bd33ea58ddfe4a5e4a66d53300ccbd38d66ac21f + https://github.com/meshtastic/st7789/archive/bd33ea58ddfe4a5e4a66d53300ccbd38d66ac21f.zip upload_speed = 921600 \ No newline at end of file diff --git a/variants/heltec_wireless_paper/nicheGraphics.h b/variants/heltec_wireless_paper/nicheGraphics.h index 0c26f453c..ece4225d0 100644 --- a/variants/heltec_wireless_paper/nicheGraphics.h +++ b/variants/heltec_wireless_paper/nicheGraphics.h @@ -6,7 +6,7 @@ // InkHUD-specific components // --------------------------- -#include "graphics/niche/InkHUD/WindowManager.h" +#include "graphics/niche/InkHUD/InkHUD.h" // Applets #include "graphics/niche/InkHUD/Applets/User/AllMessage/AllMessageApplet.h" @@ -49,48 +49,42 @@ void setupNicheGraphics() // InkHUD // ---------------------------- - InkHUD::WindowManager *windowManager = InkHUD::WindowManager::getInstance(); + InkHUD::InkHUD *inkhud = InkHUD::InkHUD::getInstance(); // Set the driver - windowManager->setDriver(driver); + inkhud->setDriver(driver); // Set how many FAST updates per FULL update // Set how unhealthy additional FAST updates beyond this number are - windowManager->setDisplayResilience(10, 1.5); + inkhud->setDisplayResilience(10, 1.5); // Prepare fonts - InkHUD::AppletFont largeFont(FreeSans9pt7b); - InkHUD::AppletFont smallFont(FreeSans6pt7b); + InkHUD::Applet::fontLarge = InkHUD::AppletFont(FreeSans9pt7b); + InkHUD::Applet::fontSmall = InkHUD::AppletFont(FreeSans6pt7b); /* // Font localization demo: Cyrillic - InkHUD::AppletFont smallFont(FreeSans6pt8bCyrillic); - smallFont.addSubstitutionsWin1251(); + InkHUD::Applet::fontSmall = InkHUD::AppletFont(FreeSans6pt8bCyrillic); + InkHUD::Applet::fontSmall.addSubstitutionsWin1251(); */ - InkHUD::Applet::setDefaultFonts(largeFont, smallFont); - // Init settings, and customize defaults - InkHUD::settings.userTiles.maxCount = 2; // How many tiles can the display handle? - InkHUD::settings.rotation = 3; // 270 degrees clockwise - InkHUD::settings.userTiles.count = 1; // One tile only by default, keep things simple for new users + // Customize default settings + inkhud->persistence->settings.userTiles.maxCount = 2; // How many tiles can the display handle? + inkhud->persistence->settings.rotation = 3; // 270 degrees clockwise + inkhud->persistence->settings.userTiles.count = 1; // One tile only by default, keep things simple for new users // Pick applets - // Note: order of applets determines priority of "auto-show" feature - // Optional arguments for defaults: - // - is activated? - // - is autoshown? - // - is foreground on a specific tile (index)? - windowManager->addApplet("All Messages", new InkHUD::AllMessageApplet, true, true); // Activated, autoshown - windowManager->addApplet("DMs", new InkHUD::DMApplet); - windowManager->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0)); - windowManager->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1)); - windowManager->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated - windowManager->addApplet("Recents List", new InkHUD::RecentsListApplet); - windowManager->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, not autoshown, default on tile 0 - // windowManager->addApplet("Basic", new InkHUD::BasicExampleApplet); - // windowManager->addApplet("NewMsg", new InkHUD::NewMsgExampleApplet); + inkhud->addApplet("All Messages", new InkHUD::AllMessageApplet, true, true); // Activated, autoshown + inkhud->addApplet("DMs", new InkHUD::DMApplet); // Inactive + inkhud->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0)); // Inactive + inkhud->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1)); // Inactive + inkhud->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated + inkhud->addApplet("Recents List", new InkHUD::RecentsListApplet); // Inactive + inkhud->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, not autoshown, default on tile 0 + // inkhud->addApplet("Basic", new InkHUD::BasicExampleApplet); + // inkhud->addApplet("NewMsg", new InkHUD::NewMsgExampleApplet); - // Start running window manager - windowManager->begin(); + // Start running InkHUD + inkhud->begin(); // Buttons // -------------------------- @@ -100,8 +94,8 @@ void setupNicheGraphics() // Setup the main user button buttons->setWiring(MAIN_BUTTON, BUTTON_PIN); - buttons->setHandlerShortPress(MAIN_BUTTON, []() { InkHUD::WindowManager::getInstance()->handleButtonShort(); }); - buttons->setHandlerLongPress(MAIN_BUTTON, []() { InkHUD::WindowManager::getInstance()->handleButtonLong(); }); + buttons->setHandlerShortPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->shortpress(); }); + buttons->setHandlerLongPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->longpress(); }); // No aux button on this board diff --git a/variants/heltec_wireless_paper/platformio.ini b/variants/heltec_wireless_paper/platformio.ini index 36dbfd35b..51430ebff 100644 --- a/variants/heltec_wireless_paper/platformio.ini +++ b/variants/heltec_wireless_paper/platformio.ini @@ -2,6 +2,7 @@ [env:heltec-wireless-paper] extends = esp32s3_base board = heltec_wifi_lora_32_V3 +board_build.partitions = default_8MB.csv build_flags = ${esp32s3_base.build_flags} -I variants/heltec_wireless_paper @@ -16,16 +17,14 @@ build_flags = -D EINK_HASQUIRK_GHOSTING ; Display model is identified as "prone to ghosting" lib_deps = ${esp32s3_base.lib_deps} - https://github.com/meshtastic/GxEPD2#b202ebfec6a4821e098cf7a625ba0f6f2400292d + https://github.com/meshtastic/GxEPD2/archive/b202ebfec6a4821e098cf7a625ba0f6f2400292d.zip lewisxhe/PCF8563_Library@^1.0.1 upload_speed = 115200 -; Using experimental InkHUD UI (work in progress) -[platformio] -extra_configs = src/graphics/niche/InkHUD/PlatformioConfig.ini [env:heltec-wireless-paper-inkhud] extends = esp32s3_base, inkhud board = heltec_wifi_lora_32_V3 +board_build.partitions = default_8MB.csv build_src_filter = ${esp32_base.build_src_filter} ${inkhud.build_src_filter} @@ -34,8 +33,8 @@ build_flags = ${inkhud.build_flags} -I variants/heltec_wireless_paper -D HELTEC_WIRELESS_PAPER - -D MAX_THREADS=40 + -D MAX_THREADS=40 ; Required if used with WiFi lib_deps = - ${inkhud.lib_deps} ; InkHUD libs first, so we get GFXRoot intead of AdafruitGFX + ${inkhud.lib_deps} ; InkHUD libs first, so we get GFXRoot instead of AdafruitGFX ${esp32s3_base.lib_deps} -upload_speed = 115200 \ No newline at end of file +upload_speed = 921600 \ No newline at end of file diff --git a/variants/heltec_wireless_paper_v1/platformio.ini b/variants/heltec_wireless_paper_v1/platformio.ini index 2ce7559f9..44b0606af 100644 --- a/variants/heltec_wireless_paper_v1/platformio.ini +++ b/variants/heltec_wireless_paper_v1/platformio.ini @@ -2,6 +2,7 @@ extends = esp32s3_base board_level = extra board = heltec_wifi_lora_32_V3 +board_build.partitions = default_8MB.csv build_flags = ${esp32s3_base.build_flags} -I variants/heltec_wireless_paper_v1 @@ -14,6 +15,6 @@ build_flags = -D EINK_LIMIT_GHOSTING_PX=2000 ; (Optional) How much image ghosting is tolerated lib_deps = ${esp32s3_base.lib_deps} - https://github.com/meshtastic/GxEPD2#55f618961db45a23eff0233546430f1e5a80f63a + https://github.com/meshtastic/GxEPD2/archive/55f618961db45a23eff0233546430f1e5a80f63a.zip lewisxhe/PCF8563_Library@^1.0.1 upload_speed = 115200 \ No newline at end of file diff --git a/variants/heltec_wireless_tracker/platformio.ini b/variants/heltec_wireless_tracker/platformio.ini index 4f686d289..5c19c37e6 100644 --- a/variants/heltec_wireless_tracker/platformio.ini +++ b/variants/heltec_wireless_tracker/platformio.ini @@ -1,6 +1,7 @@ [env:heltec-wireless-tracker] extends = esp32s3_base board = heltec_wireless_tracker +board_build.partitions = default_8MB.csv upload_protocol = esptool build_flags = diff --git a/variants/heltec_wireless_tracker_V1_0/platformio.ini b/variants/heltec_wireless_tracker_V1_0/platformio.ini index 5f512b816..08b0ae95c 100644 --- a/variants/heltec_wireless_tracker_V1_0/platformio.ini +++ b/variants/heltec_wireless_tracker_V1_0/platformio.ini @@ -2,6 +2,7 @@ extends = esp32s3_base board_level = extra board = heltec_wireless_tracker +board_build.partitions = default_8MB.csv upload_protocol = esptool build_flags = ${esp32s3_base.build_flags} -I variants/heltec_wireless_tracker_V1_0 diff --git a/variants/heltec_wsl_v3/platformio.ini b/variants/heltec_wsl_v3/platformio.ini index c95659156..bc3e6ada1 100644 --- a/variants/heltec_wsl_v3/platformio.ini +++ b/variants/heltec_wsl_v3/platformio.ini @@ -1,7 +1,8 @@ [env:heltec-wsl-v3] extends = esp32s3_base board = heltec_wifi_lora_32_V3 +board_build.partitions = default_8MB.csv # Temporary until espressif creates a release with this new target build_flags = ${esp32s3_base.build_flags} -D HELTEC_WSL_V3 -I variants/heltec_wsl_v3 - -DGPS_POWER_TOGGLE ; comment this line to disable triple press function on the user button to turn off gps entirely. \ No newline at end of file + -D GPS_POWER_TOGGLE ; comment this line to disable triple press function on the user button to turn off gps entirely. diff --git a/variants/icarus/platformio.ini b/variants/icarus/platformio.ini index b1dc01fc1..b4ea125cf 100644 --- a/variants/icarus/platformio.ini +++ b/variants/icarus/platformio.ini @@ -4,6 +4,7 @@ board = icarus board_level = extra board_check = true board_build.mcu = esp32s3 +board_build.partitions = default_8MB.csv upload_protocol = esptool upload_speed = 921600 platform_packages = platformio/framework-arduinoespressif32@https://github.com/PowerFeather/powerfeather-meshtastic-arduino-lib/releases/download/2.0.16a/esp32-2.0.16.zip @@ -15,5 +16,4 @@ build_unflags = build_flags = ${esp32s3_base.build_flags} -D PRIVATE_HW -I variants/icarus -DBOARD_HAS_PSRAM - - -DARDUINO_USB_MODE=0 \ No newline at end of file + -DARDUINO_USB_MODE=0 diff --git a/variants/m5stack_cores3/platformio.ini b/variants/m5stack_cores3/platformio.ini index fc73fabae..2253e75e2 100644 --- a/variants/m5stack_cores3/platformio.ini +++ b/variants/m5stack_cores3/platformio.ini @@ -3,6 +3,7 @@ extends = esp32s3_base board = m5stack-cores3 board_check = true +board_build.partitions = default_16MB.csv upload_protocol = esptool build_flags = ${esp32_base.build_flags} diff --git a/variants/mesh-tab/platformio.ini b/variants/mesh-tab/platformio.ini index f76c36bdd..728fa5100 100644 --- a/variants/mesh-tab/platformio.ini +++ b/variants/mesh-tab/platformio.ini @@ -28,7 +28,6 @@ build_flags = ${esp32s3_base.build_flags} -D USE_LOG_DEBUG -D LOG_DEBUG_INC=\"DebugConfiguration.h\" -D RADIOLIB_SPI_PARANOID=0 - -D MAX_NUM_NODES=250 -D MAX_THREADS=40 -D HAS_SCREEN=0 -D HAS_TFT=1 @@ -47,14 +46,11 @@ build_flags = ${esp32s3_base.build_flags} -D LGFX_TOUCH_INT=41 -D VIEW_320x240 -D USE_PACKET_API - -I lib/device-ui/generated/ui_320x240 -I variants/mesh-tab build_src_filter = ${esp32_base.build_src_filter} - +<../lib/device-ui/generated/ui_320x240> - +<../lib/device-ui/resources> - +<../lib/device-ui/locale> - +<../lib/device-ui/source> -lib_deps = ${esp32_base.lib_deps} +lib_deps = + ${esp32_base.lib_deps} + ${device-ui_base.lib_deps} lovyan03/LovyanGFX@^1.2.0 [mesh_tab_xpt2046] diff --git a/variants/meshlink/platformio.ini b/variants/meshlink/platformio.ini index 180dddd49..ec3506b0e 100644 --- a/variants/meshlink/platformio.ini +++ b/variants/meshlink/platformio.ini @@ -23,7 +23,7 @@ build_flags = ${nrf52840_base.build_flags} -I variants/meshlink -D MESHLINK build_src_filter = ${nrf52_base.build_src_filter} +<../variants/meshlink> lib_deps = ${nrf52840_base.lib_deps} - https://github.com/meshtastic/GxEPD2#55f618961db45a23eff0233546430f1e5a80f63a + https://github.com/meshtastic/GxEPD2/archive/55f618961db45a23eff0233546430f1e5a80f63a.zip debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ; Note: as of 6/2013 the serial/bootloader based programming takes approximately 30 seconds diff --git a/variants/meshlink_eink/platformio.ini b/variants/meshlink_eink/platformio.ini index db3647e73..f8ee96fc3 100644 --- a/variants/meshlink_eink/platformio.ini +++ b/variants/meshlink_eink/platformio.ini @@ -23,7 +23,7 @@ build_flags = ${nrf52840_base.build_flags} -I variants/meshlink_eink -D MESHLINK build_src_filter = ${nrf52_base.build_src_filter} +<../variants/meshlink_eink> lib_deps = ${nrf52840_base.lib_deps} - https://github.com/meshtastic/GxEPD2#55f618961db45a23eff0233546430f1e5a80f63a + https://github.com/meshtastic/GxEPD2/archive/55f618961db45a23eff0233546430f1e5a80f63a.zip debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ; Note: as of 6/2013 the serial/bootloader based programming takes approximately 30 seconds diff --git a/variants/monteops_hw1/platformio.ini b/variants/monteops_hw1/platformio.ini index eaa246526..1464ca7e7 100644 --- a/variants/monteops_hw1/platformio.ini +++ b/variants/monteops_hw1/platformio.ini @@ -9,7 +9,7 @@ build_src_filter = ${nrf52_base.build_src_filter} +<../variants/monteops_hw1> +< lib_deps = ${nrf52840_base.lib_deps} ${networking_base.lib_deps} - https://github.com/RAKWireless/RAK13800-W5100S.git#1.0.2 + https://github.com/RAKWireless/RAK13800-W5100S/archive/1.0.2.zip debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/picomputer-s3/platformio.ini b/variants/picomputer-s3/platformio.ini index b8de94f12..df2d0dfdc 100644 --- a/variants/picomputer-s3/platformio.ini +++ b/variants/picomputer-s3/platformio.ini @@ -2,6 +2,7 @@ extends = esp32s3_base board = bpi_picow_esp32_s3 board_check = true +board_build.partitions = default_8MB.csv ;OpenOCD flash method ;upload_protocol = esp-builtin ;Normal method @@ -22,7 +23,6 @@ build_src_filter = [env:picomputer-s3-tft] extends = env:picomputer-s3 -board_build.partitions = default_8MB.csv ; just for test build_flags = ${env:picomputer-s3.build_flags} @@ -35,7 +35,6 @@ build_flags = -D INPUTDRIVER_MATRIX_TYPE=1 -D USE_PIN_BUZZER=PIN_BUZZER -D USE_SX127x - -D MAX_NUM_NODES=200 -D HAS_SCREEN=0 -D HAS_TFT=1 -D RAM_SIZE=1024 @@ -54,11 +53,7 @@ build_flags = -D VIEW_320x240 ; -D USE_DOUBLE_BUFFER -D USE_PACKET_API - -I lib/device-ui/generated/ui_320x240 -build_src_filter = - ${env:picomputer-s3.build_src_filter} - +<../lib/device-ui/generated/ui_320x240> - +<../lib/device-ui/resources> - +<../lib/device-ui/locale> - +<../lib/device-ui/source> \ No newline at end of file +lib_deps = + ${env:picomputer-s3.lib_deps} + ${device-ui_base.lib_deps} diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index f77831ad7..7a3392eb4 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -18,12 +18,16 @@ build_flags = ${native_base.build_flags} [env:native-tft] extends = native_base build_type = release +lib_deps = + ${native_base.lib_deps} + ${device-ui_base.lib_deps} build_flags = ${native_base.build_flags} -Os -lX11 -linput -lxkbcommon -ffunction-sections -fdata-sections -Wl,--gc-sections -D MESHTASTIC_EXCLUDE_CANNEDMESSAGES=1 -D RAM_SIZE=16384 -D USE_X11=1 -D HAS_TFT=1 -D HAS_SCREEN=0 + -D LV_CACHE_DEF_SIZE=6291456 -D LV_BUILD_TEST=0 -D LV_USE_LIBINPUT=1 -D LV_LVGL_H_INCLUDE_SIMPLE @@ -32,21 +36,19 @@ build_flags = ${native_base.build_flags} -Os -lX11 -linput -lxkbcommon -ffunctio -D USE_LOG_DEBUG -D LOG_DEBUG_INC=\"DebugConfiguration.h\" -D USE_PACKET_API - -I lib/device-ui/generated/ui_320x240 + -D VIEW_320x240 !pkg-config --libs libulfius --silence-errors || : !pkg-config --libs openssl --silence-errors || : -build_src_filter = ${native_base.build_src_filter} +build_src_filter = + ${native_base.build_src_filter} - - +<../lib/device-ui/generated/ui_320x240> - +<../lib/device-ui/generated/ui_320x240/fonts> - +<../lib/device-ui/resources> - +<../lib/device-ui/portduino> - +<../lib/device-ui/locale> - +<../lib/device-ui/source> [env:native-tft-debug] extends = native_base build_type = debug +lib_deps = + ${native_base.lib_deps} + ${device-ui_base.lib_deps} board_level = extra build_flags = ${native_base.build_flags} -O0 -fsanitize=address -lX11 -linput -lxkbcommon -D MESHTASTIC_EXCLUDE_CANNEDMESSAGES=1 @@ -55,7 +57,7 @@ build_flags = ${native_base.build_flags} -O0 -fsanitize=address -lX11 -linput -l -D USE_X11=1 -D HAS_TFT=1 -D HAS_SCREEN=0 -; -D CALIBRATE_TOUCH=0 + -D LV_CACHE_DEF_SIZE=6291456 -D LV_BUILD_TEST=0 -D LV_USE_LOG=1 -D LV_USE_SYSMON=1 @@ -69,7 +71,7 @@ build_flags = ${native_base.build_flags} -O0 -fsanitize=address -lX11 -linput -l -D USE_LOG_DEBUG -D LOG_DEBUG_INC=\"DebugConfiguration.h\" -D USE_PACKET_API - -I lib/device-ui/generated/ui_320x240 + -D VIEW_320x240 !pkg-config --libs libulfius --silence-errors || : !pkg-config --libs openssl --silence-errors || : build_src_filter = ${env:native-tft.build_src_filter} diff --git a/variants/radiomaster_900_bandit/platformio.ini b/variants/radiomaster_900_bandit/platformio.ini index 010791d8a..f87025937 100644 --- a/variants/radiomaster_900_bandit/platformio.ini +++ b/variants/radiomaster_900_bandit/platformio.ini @@ -13,4 +13,4 @@ board_build.f_cpu = 240000000L upload_protocol = esptool lib_deps = ${esp32_base.lib_deps} - https://github.com/gjelsoe/STK8xxx-Accelerometer.git#v0.1.1 + https://github.com/gjelsoe/STK8xxx-Accelerometer/archive/v0.1.1.zip diff --git a/variants/rak11310/platformio.ini b/variants/rak11310/platformio.ini index d1da962ca..c87304e61 100644 --- a/variants/rak11310/platformio.ini +++ b/variants/rak11310/platformio.ini @@ -1,21 +1,20 @@ [env:rak11310] extends = rp2040_base -board = wiscore_rak11300 +board = rakwireless_rak11300 upload_protocol = picotool -# keep an old SDK to use less memory. -platform = https://github.com/maxgerhardt/platform-raspberrypi.git#v1.2.0-gcc12 -platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#3.7.2 # add our variants files to the include and src paths build_flags = ${rp2040_base.build_flags} -DRAK11310 -Ivariants/rak11310 -DDEBUG_RP2040_PORT=Serial + -DRV3028_RTC=0x52 -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m0plus" build_src_filter = ${rp2040_base.build_src_filter} +<../variants/rak11310> + + + lib_deps = ${rp2040_base.lib_deps} ${networking_base.lib_deps} - https://github.com/RAKWireless/RAK13800-W5100S.git#1.0.2 + melopero/Melopero RV3028@^1.1.0 + https://github.com/RAKWireless/RAK13800-W5100S/archive/1.0.2.zip debug_build_flags = ${rp2040_base.build_flags}, -g debug_tool = cmsis-dap ; for e.g. Picotool \ No newline at end of file diff --git a/variants/rak11310/variant.h b/variants/rak11310/variant.h index bc8d2d71b..2400d56a7 100644 --- a/variants/rak11310/variant.h +++ b/variants/rak11310/variant.h @@ -4,6 +4,12 @@ #define ARDUINO_ARCH_AVR +// Define I2C pins to ensure correct usage of both ports +#define I2C_SDA 20 +#define I2C_SCL 21 +#define I2C_SDA1 2 +#define I2C_SCL1 3 + #define LED_CONN PIN_LED2 #define LED_PIN LED_BUILTIN #define ledOff(pin) pinMode(pin, INPUT) diff --git a/variants/rak2560/platformio.ini b/variants/rak2560/platformio.ini index 956f573c5..faed231f1 100644 --- a/variants/rak2560/platformio.ini +++ b/variants/rak2560/platformio.ini @@ -15,7 +15,7 @@ lib_deps = ${nrf52840_base.lib_deps} ${networking_base.lib_deps} melopero/Melopero RV3028@^1.1.0 - https://github.com/beegee-tokyo/RAK-OneWireSerial.git#0.0.2 + https://github.com/beegee-tokyo/RAK-OneWireSerial/archive/0.0.2.zip debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak3172/platformio.ini b/variants/rak3172/platformio.ini index 58ea32088..456697aef 100644 --- a/variants/rak3172/platformio.ini +++ b/variants/rak3172/platformio.ini @@ -1,36 +1,23 @@ [env:rak3172] extends = stm32_base board = wiscore_rak3172 +board_upload.maximum_size = 233472 ; reserve the last 28KB for filesystem build_flags = ${stm32_base.build_flags} -Ivariants/rak3172 - -DSERIAL_UART_INSTANCE=1 - -DPIN_SERIAL_RX=PB7 - -DPIN_SERIAL_TX=PB6 -DHAL_DAC_MODULE_ONLY - -DHAL_ADC_MODULE_DISABLED - -DHAL_COMP_MODULE_DISABLED - -DHAL_CRC_MODULE_DISABLED - -DHAL_CRYP_MODULE_DISABLED - -DHAL_GTZC_MODULE_DISABLED - -DHAL_HSEM_MODULE_DISABLED - -DHAL_I2C_MODULE_DISABLED - -DHAL_I2S_MODULE_DISABLED - -DHAL_IPCC_MODULE_DISABLED - -DHAL_IRDA_MODULE_DISABLED - -DHAL_IWDG_MODULE_DISABLED - -DHAL_LPTIM_MODULE_DISABLED - -DHAL_PKA_MODULE_DISABLED - -DHAL_RNG_MODULE_DISABLED - -DHAL_RTC_MODULE_DISABLED - -DHAL_SMARTCARD_MODULE_DISABLED - -DHAL_SMBUS_MODULE_DISABLED - -DHAL_TIM_MODULE_DISABLED - -DHAL_WWDG_MODULE_DISABLED - -DHAL_EXTI_MODULE_DISABLED - -DHAL_SAI_MODULE_DISABLED - -DHAL_ICACHE_MODULE_DISABLED + -DHAL_RNG_MODULE_ENABLED -DRADIOLIB_EXCLUDE_SX128X=1 -DRADIOLIB_EXCLUDE_SX127X=1 -DRADIOLIB_EXCLUDE_LR11X0=1 -upload_port = stlink \ No newline at end of file + -DMESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR=1 + -DMESHTASTIC_EXCLUDE_I2C=1 + -DMESHTASTIC_EXCLUDE_WIFI=1 + -DMESHTASTIC_EXCLUDE_BLUETOOTH=1 + -DMESHTASTIC_EXCLUDE_GPS=1 + -DMESHTASTIC_EXCLUDE_SCREEN=1 + -DMESHTASTIC_EXCLUDE_MQTT=1 + -DMESHTASTIC_EXCLUDE_POWERMON=1 + ;-DPIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF + ;-DCFG_DEBUG +upload_port = stlink diff --git a/variants/rak3172/variant.h b/variants/rak3172/variant.h index 21de65b2c..45752b481 100644 --- a/variants/rak3172/variant.h +++ b/variants/rak3172/variant.h @@ -1,3 +1,8 @@ +/* +STM32WLE5 Core Module for LoRaWAN® RAK3372 +https://store.rakwireless.com/products/wisblock-core-module-rak3372 +*/ + /* This variant is a work in progress. Do not expect a working Meshtastic device with this target. @@ -7,6 +12,8 @@ Do not expect a working Meshtastic device with this target. #define _VARIANT_RAK3172_ #define USE_STM32WLx -#define MAX_NUM_NODES 10 -#endif \ No newline at end of file +#define LED_PIN PA0 // Green LED +#define LED_STATE_ON 1 + +#endif diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index ced93df66..1c6bdabcf 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -17,9 +17,9 @@ lib_deps = ${nrf52840_base.lib_deps} ${networking_base.lib_deps} melopero/Melopero RV3028@^1.1.0 - https://github.com/RAKWireless/RAK13800-W5100S.git#1.0.2 + https://github.com/RAKWireless/RAK13800-W5100S/archive/1.0.2.zip rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 - https://github.com/RAKWireless/RAK12034-BMX160.git#dcead07ffa267d3c906e9ca4a1330ab989e957e2 + https://github.com/RAKWireless/RAK12034-BMX160/archive/dcead07ffa267d3c906e9ca4a1330ab989e957e2.zip ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ; Note: as of 6/2013 the serial/bootloader based programming takes approximately 30 seconds @@ -41,7 +41,7 @@ build_flags = lib_deps = ${env:rak4631.lib_deps} - https://github.com/geeksville/Armduino-Semihosting.git#35b538fdf208c3530c1434cd099a08e486672ee4 + https://github.com/geeksville/Armduino-Semihosting/archive/35b538fdf208c3530c1434cd099a08e486672ee4.zip ; NOTE: the pyocd support for semihosting is buggy. So I switched to using the builtin platformio support for the stlink adapter which worked much better. ; However the built in openocd version in platformio has buggy support for TCP to semihosting. diff --git a/variants/rak4631_eth_gw/platformio.ini b/variants/rak4631_eth_gw/platformio.ini index 62b7e737d..e3da21c55 100644 --- a/variants/rak4631_eth_gw/platformio.ini +++ b/variants/rak4631_eth_gw/platformio.ini @@ -10,7 +10,6 @@ build_flags = ${nrf52840_base.build_flags} -Ivariants/rak4631_eth_gw -D RAK_4631 -DEINK_WIDTH=250 -DEINK_HEIGHT=122 -DNRF52_USE_JSON=1 - -DMESHTASTIC_EXCLUDE_GPS=1 -DMESHTASTIC_EXCLUDE_WIFI=1 -DMESHTASTIC_EXCLUDE_SCREEN=1 ; -DMESHTASTIC_EXCLUDE_PKI=1 @@ -28,9 +27,9 @@ lib_deps = ${nrf52840_base.lib_deps} ${networking_base.lib_deps} melopero/Melopero RV3028@^1.1.0 - https://github.com/RAKWireless/RAK13800-W5100S.git#1.0.2 + https://github.com/RAKWireless/RAK13800-W5100S/archive/1.0.2.zip rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 - https://github.com/meshtastic/RAK12034-BMX160.git#4821355fb10390ba8557dc43ca29a023bcfbb9d9 + https://github.com/meshtastic/RAK12034-BMX160/archive/4821355fb10390ba8557dc43ca29a023bcfbb9d9.zip bblanchon/ArduinoJson @ 6.21.4 ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ; Note: as of 6/2013 the serial/bootloader based programming takes approximately 30 seconds @@ -52,7 +51,7 @@ build_flags = lib_deps = ${env:rak4631_eth_gw.lib_deps} - https://github.com/geeksville/Armduino-Semihosting.git#35b538fdf208c3530c1434cd099a08e486672ee4 + https://github.com/geeksville/Armduino-Semihosting/archive/35b538fdf208c3530c1434cd099a08e486672ee4.zip ; NOTE: the pyocd support for semihosting is buggy. So I switched to using the builtin platformio support for the stlink adapter which worked much better. ; However the built in openocd version in platformio has buggy support for TCP to semihosting. @@ -63,4 +62,4 @@ lib_deps = upload_protocol = stlink ; eventually use platformio/tool-pyocd@^2.3600.0 instad ;upload_protocol = custom -;upload_command = pyocd flash -t nrf52840 $UPLOADERFLAGS $SOURCE \ No newline at end of file +;upload_command = pyocd flash -t nrf52840 $UPLOADERFLAGS $SOURCE diff --git a/variants/rak_wismeshtap/platformio.ini b/variants/rak_wismeshtap/platformio.ini index bcf46b90d..78472783e 100644 --- a/variants/rak_wismeshtap/platformio.ini +++ b/variants/rak_wismeshtap/platformio.ini @@ -18,7 +18,7 @@ lib_deps = ${nrf52840_base.lib_deps} ${networking_base.lib_deps} melopero/Melopero RV3028@^1.1.0 - https://github.com/RAKWireless/RAK13800-W5100S.git#1.0.2 + https://github.com/RAKWireless/RAK13800-W5100S/archive/1.0.2.zip rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 bodmer/TFT_eSPI beegee-tokyo/RAKwireless RAK12034@^1.0.0 diff --git a/variants/rpipico2w/platformio.ini b/variants/rpipico2w/platformio.ini index 351774221..282be1a42 100644 --- a/variants/rpipico2w/platformio.ini +++ b/variants/rpipico2w/platformio.ini @@ -23,8 +23,9 @@ build_flags = ${rp2350_base.build_flags} -DHAS_WIFI=1 -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m33" -fexceptions # for exception handling in MQTT + -DHAS_UDP_MULTICAST=1 build_src_filter = ${rp2350_base.build_src_filter} + lib_deps = ${rp2350_base.lib_deps} ${networking_base.lib_deps} -debug_build_flags = ${rp2350_base.build_flags}, -g \ No newline at end of file +debug_build_flags = ${rp2350_base.build_flags}, -g diff --git a/variants/rpipicow/platformio.ini b/variants/rpipicow/platformio.ini index 7a43ece3b..4b714434a 100644 --- a/variants/rpipicow/platformio.ini +++ b/variants/rpipicow/platformio.ini @@ -10,9 +10,10 @@ build_flags = ${rp2040_base.build_flags} -DHW_SPI1_DEVICE -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m0plus" -fexceptions # for exception handling in MQTT + -DHAS_UDP_MULTICAST=1 build_src_filter = ${rp2040_base.build_src_filter} + lib_deps = ${rp2040_base.lib_deps} ${networking_base.lib_deps} debug_build_flags = ${rp2040_base.build_flags}, -g -debug_tool = cmsis-dap ; for e.g. Picotool \ No newline at end of file +debug_tool = cmsis-dap ; for e.g. Picotool diff --git a/variants/seeed-sensecap-indicator/platformio.ini b/variants/seeed-sensecap-indicator/platformio.ini index 31566edbe..fb51d77c3 100644 --- a/variants/seeed-sensecap-indicator/platformio.ini +++ b/variants/seeed-sensecap-indicator/platformio.ini @@ -2,10 +2,11 @@ [env:seeed-sensecap-indicator] extends = esp32s3_base platform_packages = - platformio/framework-arduinoespressif32 @ https://github.com/mverch67/arduino-esp32.git#aef7fef6de3329ed6f75512d46d63bba12b09bb5 ; add_tca9535 (based on 2.0.16) + platformio/framework-arduinoespressif32 @ https://github.com/mverch67/arduino-esp32/archive/aef7fef6de3329ed6f75512d46d63bba12b09bb5.zip ; add_tca9535 (based on 2.0.16) board = seeed-sensecap-indicator board_check = true +board_build.partitions = default_8MB.csv upload_protocol = esptool build_flags = ${esp32_base.build_flags} @@ -23,7 +24,7 @@ build_flags = ${esp32_base.build_flags} -DUSE_ARDUINO_HAL_GPIO lib_deps = ${esp32s3_base.lib_deps} - https://github.com/mverch67/LovyanGFX#develop + https://github.com/mverch67/LovyanGFX/archive/4c76238c1344162a234ae917b27651af146d6fb2.zip earlephilhower/ESP8266Audio@^1.9.9 earlephilhower/ESP8266SAM@^1.0.1 @@ -32,7 +33,6 @@ lib_deps = ${esp32s3_base.lib_deps} extends = env:seeed-sensecap-indicator board_level = main upload_speed = 460800 -board_build.partitions = default_8MB.csv ; must be here for some reason, board.json is not enough !? build_flags = ${env:seeed-sensecap-indicator.build_flags} @@ -46,11 +46,10 @@ build_flags = -D INPUTDRIVER_BUTTON_TYPE=38 -D HAS_TELEMETRY=0 -D CONFIG_DISABLE_HAL_LOCKS=1 - -D MAX_NUM_NODES=250 -D HAS_SCREEN=0 -D HAS_TFT=1 -D DISPLAY_SET_RESOLUTION - -D USE_I2S_BUZZER + -D USE_PIN_BUZZER -D RAM_SIZE=4096 -D LV_LVGL_H_INCLUDE_SIMPLE -D LV_CONF_INCLUDE_SIMPLE @@ -66,17 +65,9 @@ build_flags = -D LGFX_DRIVER=LGFX_INDICATOR -D GFX_DRIVER_INC=\"graphics/LGFX/LGFX_INDICATOR.h\" -D VIEW_320x240 -; -D USE_DOUBLE_BUFFER -D USE_PACKET_API - -I lib/device-ui/generated/ui_320x240 - -build_src_filter = - ${env:seeed-sensecap-indicator.build_src_filter} - +<../lib/device-ui/generated/ui_320x240> - +<../lib/device-ui/resources> - +<../lib/device-ui/locale> - +<../lib/device-ui/source> lib_deps = ${env:seeed-sensecap-indicator.lib_deps} - https://github.com/bitbank2/bb_captouch.git#8f2f06462ff597847921739376a299db93612417 ; alternative touch library supporting FT6x36 \ No newline at end of file + ${device-ui_base.lib_deps} + https://github.com/mverch67/bb_captouch/archive/8626412fe650d808a267791c0eae6e5860c85a5d.zip ; alternative touch library supporting FT6x36 diff --git a/variants/seeed_xiao_nrf52840_kit/platformio.ini b/variants/seeed_xiao_nrf52840_kit/platformio.ini new file mode 100644 index 000000000..41956249b --- /dev/null +++ b/variants/seeed_xiao_nrf52840_kit/platformio.ini @@ -0,0 +1,13 @@ +; Seeed Xiao BLE: https://www.digikey.com/en/products/detail/seeed-technology-co-ltd/102010448/16652893 +[env:seeed_xiao_nrf52840_kit] +extends = nrf52840_base +board = xiao_ble_sense +build_flags = ${nrf52840_base.build_flags} -Ivariants/seeed_xiao_nrf52840_kit -Isrc/platform/nrf52/softdevice -Isrc/platform/nrf52/softdevice/nrf52 -DSEEED_XIAO_NRF52840_KIT + -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m4/fpv4-sp-d16-hard" +board_build.ldscript = src/platform/nrf52/nrf52840_s140_v7.ld +build_src_filter = ${nrf52_base.build_src_filter} +<../variants/seeed_xiao_nrf52840_kit> +lib_deps = + ${nrf52840_base.lib_deps} +debug_tool = jlink +; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) +;upload_protocol = jlink diff --git a/variants/seeed_xiao_nrf52840_kit/variant.cpp b/variants/seeed_xiao_nrf52840_kit/variant.cpp new file mode 100644 index 000000000..22072312a --- /dev/null +++ b/variants/seeed_xiao_nrf52840_kit/variant.cpp @@ -0,0 +1,92 @@ +#include "variant.h" +#include "configuration.h" +#include "nrf.h" +#include "wiring_constants.h" +#include "wiring_digital.h" +#include +#include +#include +#include +const uint32_t g_ADigitalPinMap[] = { + // D0 .. D13 + 2, // D0 is P0.02 (A0) + 3, // D1 is P0.03 (A1) + 28, // D2 is P0.28 (A2) + 29, // D3 is P0.29 (A3) + 4, // D4 is P0.04 (A4,SDA) + 5, // D5 is P0.05 (A5,SCL) + 43, // D6 is P1.11 (TX) + 44, // D7 is P1.12 (RX) + 45, // D8 is P1.13 (SCK) + 46, // D9 is P1.14 (MISO) + 47, // D10 is P1.15 (MOSI) + + // LEDs + 26, // D11 is P0.26 (LED RED) + 6, // D12 is P0.06 (LED BLUE) + 30, // D13 is P0.30 (LED GREEN) + 14, // D14 is P0.14 (READ_BAT) + + // LSM6DS3TR + 40, // D15 is P1.08 (6D_PWR) + 27, // D16 is P0.27 (6D_I2C_SCL) + 7, // D17 is P0.07 (6D_I2C_SDA) + 11, // D18 is P0.11 (6D_INT1) + + // MIC + 42, // 17,//42, // D19 is P1.10 (MIC_PWR) + 32, // 26,//32, // D20 is P1.00 (PDM_CLK) + 16, // 25,//16, // D21 is P0.16 (PDM_DATA) + + // BQ25100 + 13, // D22 is P0.13 (HICHG) + 17, // D23 is P0.17 (~CHG) + + // + 21, // D24 is P0.21 (QSPI_SCK) + 25, // D25 is P0.25 (QSPI_CSN) + 20, // D26 is P0.20 (QSPI_SIO_0 DI) + 24, // D27 is P0.24 (QSPI_SIO_1 DO) + 22, // D28 is P0.22 (QSPI_SIO_2 WP) + 23, // D29 is P0.23 (QSPI_SIO_3 HOLD) + + // NFC + 9, // D30 is P0.09 (NFC1) + 10, // D31 is P0.10 (NFC2) + + // VBAT + 31, // D32 is P0.10 (VBAT) +}; + +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +void initVariant() +{ + // LED1 & LED2 + pinMode(21, OUTPUT); + digitalWrite(21, LOW); + // LED1 & LED2 + pinMode(22, OUTPUT); + digitalWrite(22, LOW); + + pinMode(PIN_WIRE_SDA, INPUT_PULLUP); + pinMode(PIN_WIRE_SCL, INPUT_PULLUP); +} \ No newline at end of file diff --git a/variants/seeed_xiao_nrf52840_kit/variant.h b/variants/seeed_xiao_nrf52840_kit/variant.h new file mode 100644 index 000000000..20362cb52 --- /dev/null +++ b/variants/seeed_xiao_nrf52840_kit/variant.h @@ -0,0 +1,170 @@ +#ifndef _SEEED_XIAO_NRF52840_SENSE_H_ +#define _SEEED_XIAO_NRF52840_SENSE_H_ + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +#define USE_LFXO // Board uses 32khz crystal for LF +// #define USE_LFRC // Board uses RC for LF + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "WVariant.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +#define PINS_COUNT (33) +#define NUM_DIGITAL_PINS (33) +#define NUM_ANALOG_INPUTS (8) // A6 is used for battery, A7 is analog reference +#define NUM_ANALOG_OUTPUTS (0) + +// LEDs + +#define LED_RED 11 +#define LED_BLUE 12 +#define LED_GREEN 13 + +#define PIN_LED1 LED_GREEN +#define PIN_LED2 LED_BLUE +#define PIN_LED3 LED_RED + +#define PIN_LED PIN_LED1 +#define LED_PWR (PINS_COUNT) + +#define LED_BUILTIN PIN_LED + +#define LED_STATE_ON 1 // State when LED is lit + +/* + * Buttons + */ + +// Digital PINs +#define D0 (0ul) +#define D1 (1ul) +#define D2 (2ul) +#define D3 (3ul) +#define D4 (4ul) +#define D5 (5ul) +#define D6 (6ul) +#define D7 (7ul) +#define D8 (8ul) +#define D9 (9ul) +#define D10 (10ul) + +/*Due to the lack of pins,and have to make sure gps standby work well we have temporarily removed the button. +There are some technical solutions that can solve this problem, +and we are currently exploring and researching them*/ + +// #define BUTTON_PIN D0 // This is the Program Button +// // #define BUTTON_NEED_PULLUP 1 +// #define BUTTON_ACTIVE_LOW true +// #define BUTTON_ACTIVE_PULLUP false + +/* + * Analog pins + */ +#define PIN_A0 (0) +#define PIN_A1 (1) +#define PIN_A2 (32) +#define PIN_A3 (3) +#define PIN_A4 (4) +#define PIN_A5 (5) +#define PIN_VBAT (32) +#define VBAT_ENABLE (14) + +static const uint8_t A0 = PIN_A0; +static const uint8_t A1 = PIN_A1; +static const uint8_t A2 = PIN_A2; +static const uint8_t A3 = PIN_A3; +static const uint8_t A4 = PIN_A4; +static const uint8_t A5 = PIN_A5; +#define ADC_RESOLUTION 12 + +#define PIN_SERIAL2_RX (-1) +#define PIN_SERIAL2_TX (-1) + +/* + * SPI Interfaces + */ +#define SPI_INTERFACES_COUNT 1 + +#define PIN_SPI_MISO (9) +#define PIN_SPI_MOSI (10) +#define PIN_SPI_SCK (8) + +static const uint8_t SS = D4; +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; + +// supported modules list +#define USE_SX1262 + +// common pinouts for SX126X modules + +#define SX126X_CS D4 +#define SX126X_DIO1 D1 +#define SX126X_BUSY D3 +#define SX126X_RESET D2 + +#define SX126X_TXEN RADIOLIB_NC + +#define SX126X_RXEN D4 +#define SX126X_DIO2_AS_RF_SWITCH // DIO2 is used to control the RF switch really necessary!!! +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 + +/* + * Wire Interfaces + */ + +#define I2C_NO_RESCAN // I2C is a bit finicky, don't scan too much +#define WIRE_INTERFACES_COUNT 1 // 2 + +#define PIN_WIRE_SDA (24) // change to use the correct pins if needed +#define PIN_WIRE_SCL (25) // change to use the correct pins if needed + +static const uint8_t SDA = PIN_WIRE_SDA; +static const uint8_t SCL = PIN_WIRE_SCL; + +// GPS L76KB +#define GPS_L76K +#ifdef GPS_L76K +#define PIN_GPS_RX D6 +#define PIN_GPS_TX D7 +#define HAS_GPS 1 +#define GPS_BAUDRATE 9600 +#define GPS_THREAD_INTERVAL 50 +#define PIN_SERIAL1_RX PIN_GPS_TX +#define PIN_SERIAL1_TX PIN_GPS_RX +#define PIN_GPS_STANDBY D0 +#endif + +// Battery + +#define BAT_READ \ + 14 // P0_14 = 14 Reads battery voltage from divider on signal board. (PIN_VBAT is reading voltage divider on XIAO and is + // program pin 32 / or P0.31) +#define BATTERY_SENSE_RESOLUTION_BITS 10 +#define CHARGE_LED 23 // P0_17 = 17 D23 YELLOW CHARGE LED +#define HICHG 22 // P0_13 = 13 D22 Charge-select pin for Lipo for 100 mA instead of default 50mA charge + +// The battery sense is hooked to pin A0 (5) +#define BATTERY_PIN PIN_VBAT // PIN_A0 + +// ratio of voltage divider = 3.0 (R17=1M, R18=510k) +#define ADC_MULTIPLIER 3 // 3.0 + a bit for being optimistic + +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#endif diff --git a/variants/seeed_xiao_s3/platformio.ini b/variants/seeed_xiao_s3/platformio.ini index 3d10d7136..9d935e2e0 100644 --- a/variants/seeed_xiao_s3/platformio.ini +++ b/variants/seeed_xiao_s3/platformio.ini @@ -2,7 +2,7 @@ extends = esp32s3_base board = seeed-xiao-s3 board_check = true -board_build.mcu = esp32s3 +board_build.partitions = default_8MB.csv upload_protocol = esptool upload_speed = 921600 lib_deps = diff --git a/variants/station-g2/platformio.ini b/variants/station-g2/platformio.ini index b674c8bae..4ddd28f1c 100755 --- a/variants/station-g2/platformio.ini +++ b/variants/station-g2/platformio.ini @@ -2,6 +2,7 @@ extends = esp32s3_base board = station-g2 board_check = true +board_build.partitions = default_16MB.csv board_build.mcu = esp32s3 upload_protocol = esptool ;upload_port = /dev/ttyACM0 @@ -13,6 +14,6 @@ build_unflags = -DARDUINO_USB_MODE=1 build_flags = ${esp32s3_base.build_flags} -D STATION_G2 -I variants/station-g2 - -DBOARD_HAS_PSRAM + -DBOARD_HAS_PSRAM -DSTATION_G2 - -DARDUINO_USB_MODE=0 \ No newline at end of file + -DARDUINO_USB_MODE=0 diff --git a/variants/t-deck/platformio.ini b/variants/t-deck/platformio.ini index 1eb8a1abd..14fbee6cf 100644 --- a/variants/t-deck/platformio.ini +++ b/variants/t-deck/platformio.ini @@ -3,6 +3,7 @@ extends = esp32s3_base board = t-deck board_check = true +board_build.partitions = default_16MB.csv upload_protocol = esptool build_flags = ${esp32s3_base.build_flags} @@ -20,7 +21,6 @@ lib_deps = ${esp32s3_base.lib_deps} [env:t-deck-tft] extends = env:t-deck -board_build.partitions = default_16MB.csv build_flags = ${env:t-deck.build_flags} @@ -38,11 +38,11 @@ build_flags = -D INPUTDRIVER_ENCODER_DOWN=15 -D INPUTDRIVER_ENCODER_BTN=0 -D INPUTDRIVER_BUTTON_TYPE=0 - -D MAX_NUM_NODES=250 + -D HAS_SDCARD -D HAS_SCREEN=0 -D HAS_TFT=1 -D USE_I2S_BUZZER - -D RAM_SIZE=4096 + -D RAM_SIZE=5120 -D LV_LVGL_H_INCLUDE_SIMPLE -D LV_CONF_INCLUDE_SIMPLE -D LV_COMP_CONF_INCLUDE_SIMPLE @@ -66,14 +66,8 @@ build_flags = -D VIEW_320x240 ; -D USE_DOUBLE_BUFFER -D USE_PACKET_API - -I lib/device-ui/generated/ui_320x240 - -build_src_filter = - ${env:t-deck.build_src_filter} - +<../lib/device-ui/generated/ui_320x240> - +<../lib/device-ui/resources> - +<../lib/device-ui/locale> - +<../lib/device-ui/source> + -D MAP_FULL_REDRAW lib_deps = ${env:t-deck.lib_deps} + ${device-ui_base.lib_deps} diff --git a/variants/t-deck/variant.h b/variants/t-deck/variant.h index 8ffc4ea44..5b2c13a91 100644 --- a/variants/t-deck/variant.h +++ b/variants/t-deck/variant.h @@ -42,7 +42,7 @@ #define GPS_TX_PIN 43 // Have SPI interface SD card slot -#define HAS_SDCARD 1 +// #define HAS_SDCARD // --> needs to be in platform.ini for device-ui #define SPI_MOSI (41) #define SPI_SCK (40) #define SPI_MISO (38) diff --git a/variants/t-echo/nicheGraphics.h b/variants/t-echo/nicheGraphics.h index 44d8ef4c3..e8a9232f1 100644 --- a/variants/t-echo/nicheGraphics.h +++ b/variants/t-echo/nicheGraphics.h @@ -6,7 +6,7 @@ // InkHUD-specific components // --------------------------- -#include "graphics/niche/InkHUD/WindowManager.h" +#include "graphics/niche/InkHUD/InkHUD.h" // Applets #include "graphics/niche/InkHUD/Applets/User/AllMessage/AllMessageApplet.h" @@ -50,31 +50,29 @@ void setupNicheGraphics() // InkHUD // ---------------------------- - InkHUD::WindowManager *windowManager = InkHUD::WindowManager::getInstance(); + InkHUD::InkHUD *inkhud = InkHUD::InkHUD::getInstance(); // Set the driver - windowManager->setDriver(driver); + inkhud->setDriver(driver); // Set how many FAST updates per FULL update // Set how unhealthy additional FAST updates beyond this number are - windowManager->setDisplayResilience(20, 1.5); + inkhud->setDisplayResilience(20, 1.5); // Prepare fonts - InkHUD::AppletFont largeFont(FreeSans9pt7b); - InkHUD::AppletFont smallFont(FreeSans6pt7b); + InkHUD::Applet::fontLarge = InkHUD::AppletFont(FreeSans9pt7b); + InkHUD::Applet::fontSmall = InkHUD::AppletFont(FreeSans6pt7b); /* // Font localization demo: Cyrillic - InkHUD::AppletFont smallFont(FreeSans6pt8bCyrillic); - smallFont.addSubstitutionsWin1251(); + InkHUD::Applet::fontSmall = InkHUD::AppletFont(FreeSans6pt8bCyrillic); + InkHUD::Applet::fontSmall.addSubstitutionsWin1251(); */ - InkHUD::Applet::setDefaultFonts(largeFont, smallFont); - // Init settings, and customize defaults - // Values ignored individually if found saved to flash - InkHUD::settings.userTiles.maxCount = 2; // Two applets side-by-side - InkHUD::settings.rotation = 3; // 270 degrees clockwise - InkHUD::settings.optionalFeatures.batteryIcon = true; // Device definitely has a battery - InkHUD::settings.optionalMenuItems.backlight = true; // Until proven (by touch) that user still has the capacitive button + // Customize default settings + inkhud->persistence->settings.userTiles.maxCount = 2; // Two applets side-by-side + inkhud->persistence->settings.rotation = 3; // 270 degrees clockwise + inkhud->persistence->settings.optionalFeatures.batteryIcon = true; // Device definitely has a battery + inkhud->persistence->settings.optionalMenuItems.backlight = true; // Until proves capacitive button works by touching it // Setup backlight // Note: AUX button behavior configured further down @@ -83,30 +81,33 @@ void setupNicheGraphics() // Pick applets // Note: order of applets determines priority of "auto-show" feature - windowManager->addApplet("All Messages", new InkHUD::AllMessageApplet, true, true); // Activated, autoshown - windowManager->addApplet("DMs", new InkHUD::DMApplet); - windowManager->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0)); - windowManager->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1)); - windowManager->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated - windowManager->addApplet("Recents List", new InkHUD::RecentsListApplet); - windowManager->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, no autoshow, default on tile 0 - // windowManager->addApplet("Basic", new InkHUD::BasicExampleApplet); - // windowManager->addApplet("NewMsg", new InkHUD::NewMsgExampleApplet); + inkhud->addApplet("All Messages", new InkHUD::AllMessageApplet, true, true); // Activated, autoshown + inkhud->addApplet("DMs", new InkHUD::DMApplet); + inkhud->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0)); + inkhud->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1)); + inkhud->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated + inkhud->addApplet("Recents List", new InkHUD::RecentsListApplet); + inkhud->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, no autoshow, default on tile 0 + // inkhud->addApplet("Basic", new InkHUD::BasicExampleApplet); + // inkhud->addApplet("NewMsg", new InkHUD::NewMsgExampleApplet); - // Start running window manager - windowManager->begin(); + // Start running InkHUD + inkhud->begin(); // Buttons // -------------------------- Inputs::TwoButton *buttons = Inputs::TwoButton::getInstance(); // Shared NicheGraphics component + + // (To improve code readability only) constexpr uint8_t MAIN_BUTTON = 0; constexpr uint8_t TOUCH_BUTTON = 1; // Setup the main user button buttons->setWiring(MAIN_BUTTON, BUTTON_PIN, LOW); - buttons->setHandlerShortPress(MAIN_BUTTON, []() { InkHUD::WindowManager::getInstance()->handleButtonShort(); }); - buttons->setHandlerLongPress(MAIN_BUTTON, []() { InkHUD::WindowManager::getInstance()->handleButtonLong(); }); + buttons->setTiming(MAIN_BUTTON, 75, 500); + buttons->setHandlerShortPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->shortpress(); }); + buttons->setHandlerLongPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->longpress(); }); // Setup the capacitive touch button // - short: momentary backlight @@ -115,7 +116,8 @@ void setupNicheGraphics() buttons->setTiming(TOUCH_BUTTON, 50, 5000); // 5 seconds before latch - limited by T-Echo's capacitive touch IC buttons->setHandlerDown(TOUCH_BUTTON, [backlight]() { backlight->peek(); - InkHUD::settings.optionalMenuItems.backlight = false; // We've proved user still has the button. No need for menu entry. + InkHUD::InkHUD::getInstance()->persistence->settings.optionalMenuItems.backlight = + false; // We've proved user still has the button. No need to make backlight togglable via the menu. }); buttons->setHandlerLongPress(TOUCH_BUTTON, [backlight]() { backlight->latch(); }); buttons->setHandlerShortPress(TOUCH_BUTTON, [backlight]() { backlight->off(); }); diff --git a/variants/t-echo/platformio.ini b/variants/t-echo/platformio.ini index e0e26fe6a..59fd52ccd 100644 --- a/variants/t-echo/platformio.ini +++ b/variants/t-echo/platformio.ini @@ -20,13 +20,10 @@ build_flags = ${nrf52840_base.build_flags} -Ivariants/t-echo build_src_filter = ${nrf52_base.build_src_filter} +<../variants/t-echo> lib_deps = ${nrf52840_base.lib_deps} - https://github.com/meshtastic/GxEPD2#55f618961db45a23eff0233546430f1e5a80f63a + https://github.com/meshtastic/GxEPD2/archive/55f618961db45a23eff0233546430f1e5a80f63a.zip lewisxhe/PCF8563_Library@^1.0.1 ;upload_protocol = fs -; Using experimental InkHUD UI (work in progress) -[platformio] -extra_configs = src/graphics/niche/InkHUD/PlatformioConfig.ini [env:t-echo-inkhud] extends = nrf52840_base, inkhud board = t-echo @@ -42,6 +39,6 @@ build_src_filter = ${inkhud.build_src_filter} +<../variants/t-echo> lib_deps = - ${inkhud.lib_deps} ; InkHUD libs first, so we get GFXRoot intead of AdafruitGFX + ${inkhud.lib_deps} ; InkHUD libs first, so we get GFXRoot instead of AdafruitGFX ${nrf52840_base.lib_deps} lewisxhe/PCF8563_Library@^1.0.1 \ No newline at end of file diff --git a/variants/t-eth-elite/pins_arduino.h b/variants/t-eth-elite/pins_arduino.h new file mode 100644 index 000000000..cddd8d0b9 --- /dev/null +++ b/variants/t-eth-elite/pins_arduino.h @@ -0,0 +1,26 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +// The default Wire will be mapped to PMU and RTC +static const uint8_t SDA = 17; +static const uint8_t SCL = 18; + +// Default SPI will be mapped to Radio +static const uint8_t SS = 40; +static const uint8_t MOSI = 11; +static const uint8_t MISO = 9; +static const uint8_t SCK = 10; + +#define SPI_MOSI (11) +#define SPI_SCK (10) +#define SPI_MISO (9) +#define SPI_CS (12) + +#define SDCARD_CS SPI_CS + +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/variants/t-eth-elite/platformio.ini b/variants/t-eth-elite/platformio.ini new file mode 100644 index 000000000..d6f415f3d --- /dev/null +++ b/variants/t-eth-elite/platformio.ini @@ -0,0 +1,17 @@ +[env:t-eth-elite] +extends = esp32s3_base +board = esp32s3box +board_check = true +board_build.partitions = default_16MB.csv +build_flags = + ${esp32s3_base.build_flags} + -D T_ETH_ELITE + -I variants/t-eth-elite + -D GPS_POWER_TOGGLE ; comment this line to disable triple press function on the user button to turn off gps entirely. + +lib_ignore = + Ethernet + +lib_deps = + ${esp32s3_base.lib_deps} + https://github.com/meshtastic/ETHClass2/archive/v1.0.0.zip diff --git a/variants/t-eth-elite/rfswitch.h b/variants/t-eth-elite/rfswitch.h new file mode 100644 index 000000000..589f24767 --- /dev/null +++ b/variants/t-eth-elite/rfswitch.h @@ -0,0 +1,11 @@ +#include "RadioLib.h" + +static const uint32_t rfswitch_dio_pins[] = {RADIOLIB_LR11X0_DIO5, RADIOLIB_LR11X0_DIO6, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC}; + +static const Module::RfSwitchMode_t rfswitch_table[] = { + // mode DIO5 DIO6 + {LR11x0::MODE_STBY, {LOW, LOW}}, {LR11x0::MODE_RX, {HIGH, LOW}}, + {LR11x0::MODE_TX, {LOW, HIGH}}, {LR11x0::MODE_TX_HP, {LOW, HIGH}}, + {LR11x0::MODE_TX_HF, {LOW, LOW}}, {LR11x0::MODE_GNSS, {LOW, LOW}}, + {LR11x0::MODE_WIFI, {LOW, LOW}}, END_OF_MODE_TABLE, +}; diff --git a/variants/t-eth-elite/variant.h b/variants/t-eth-elite/variant.h new file mode 100644 index 000000000..b7ac05872 --- /dev/null +++ b/variants/t-eth-elite/variant.h @@ -0,0 +1,83 @@ +#define HAS_SDCARD +#define SDCARD_USE_SPI1 + +#define HAS_GPS 1 +#define GPS_RX_PIN 39 +#define GPS_TX_PIN 42 +#define GPS_BAUDRATE_FIXED 1 +#define GPS_BAUDRATE 9600 + +#define I2C_SDA 17 // I2C pins for this board +#define I2C_SCL 18 + +#define HAS_SCREEN 1 // Allow for OLED Screens on I2C Header of shield + +#define LED_PIN 38 // If defined we will blink this LED +#define BUTTON_PIN 0 // If defined, this will be used for user button presses, + +#define BUTTON_NEED_PULLUP + +// TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if +// not found then probe for SX1262 +#define USE_RF95 // RFM95/SX127x +#define USE_SX1262 +#define USE_SX1280 +#define USE_LR1121 + +#define LORA_SCK 10 +#define LORA_MISO 9 +#define LORA_MOSI 11 +#define LORA_CS 40 +#define LORA_RESET 46 + +// per SX1276_Receive_Interrupt/utilities.h +#define LORA_DIO0 8 +#define LORA_DIO1 16 +#define LORA_DIO2 RADIOLIB_NC + +// per SX1262_Receive_Interrupt/utilities.h +#ifdef USE_SX1262 +#define SX126X_CS LORA_CS +#define SX126X_DIO1 8 +#define SX126X_BUSY 16 +#define SX126X_RESET LORA_RESET +#define SX126X_DIO2_AS_RF_SWITCH +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#endif + +// per SX128x_Receive_Interrupt/utilities.h +#ifdef USE_SX1280 +#define SX128X_CS LORA_CS +#define SX128X_DIO1 8 +#define SX128X_DIO2 33 +#define SX128X_DIO3 34 +#define SX128X_BUSY 16 +#define SX128X_RESET LORA_RESET +#define SX128X_RXEN 13 +#define SX128X_TXEN 38 +#define SX128X_MAX_POWER 3 +#endif + +// LR1121 +#ifdef USE_LR1121 +#define LR1121_IRQ_PIN 8 +#define LR1121_NRESET_PIN LORA_RESET +#define LR1121_BUSY_PIN 16 +#define LR1121_SPI_NSS_PIN LORA_CS +#define LR1121_SPI_SCK_PIN LORA_SCK +#define LR1121_SPI_MOSI_PIN LORA_MOSI +#define LR1121_SPI_MISO_PIN LORA_MISO +#define LR11X0_DIO3_TCXO_VOLTAGE 3.0 +#define LR11X0_DIO_AS_RF_SWITCH +#endif + +#define HAS_ETHERNET 1 +#define USE_WS5500 1 // this driver uses the same stack as the ESP32 Wifi driver + +#define ETH_MISO_PIN 47 +#define ETH_MOSI_PIN 21 +#define ETH_SCLK_PIN 48 +#define ETH_CS_PIN 45 +#define ETH_INT_PIN 14 +#define ETH_RST_PIN -1 +#define ETH_ADDR 1 \ No newline at end of file diff --git a/variants/t-watch-s3/platformio.ini b/variants/t-watch-s3/platformio.ini index 8f48cf6c4..d650b1f11 100644 --- a/variants/t-watch-s3/platformio.ini +++ b/variants/t-watch-s3/platformio.ini @@ -3,6 +3,7 @@ extends = esp32s3_base board = t-watch-s3 board_check = true +board_build.partitions = default_8MB.csv upload_protocol = esptool build_flags = ${esp32_base.build_flags} diff --git a/variants/tbeam-s3-core/platformio.ini b/variants/tbeam-s3-core/platformio.ini index e50d506b9..a7bdf963f 100644 --- a/variants/tbeam-s3-core/platformio.ini +++ b/variants/tbeam-s3-core/platformio.ini @@ -2,6 +2,7 @@ [env:tbeam-s3-core] extends = esp32s3_base board = tbeam-s3-core +board_build.partitions = default_8MB.csv board_check = true lib_deps = diff --git a/variants/tlora_t3s3_epaper/platformio.ini b/variants/tlora_t3s3_epaper/platformio.ini index 3f3b3fe50..87351e586 100644 --- a/variants/tlora_t3s3_epaper/platformio.ini +++ b/variants/tlora_t3s3_epaper/platformio.ini @@ -15,4 +15,4 @@ build_flags = lib_deps = ${esp32s3_base.lib_deps} - https://github.com/meshtastic/GxEPD2#b202ebfec6a4821e098cf7a625ba0f6f2400292d + https://github.com/meshtastic/GxEPD2/archive/b202ebfec6a4821e098cf7a625ba0f6f2400292d.zip diff --git a/variants/tlora_v3_3_0_tcxo/platformio.ini b/variants/tlora_v3_3_0_tcxo/platformio.ini index 4066d64b0..8d060a087 100644 --- a/variants/tlora_v3_3_0_tcxo/platformio.ini +++ b/variants/tlora_v3_3_0_tcxo/platformio.ini @@ -1,7 +1,6 @@ [env:tlora-v3-3-0-tcxo] extends = esp32_base board = ttgo-lora32-v21 -board_level = extra build_flags = ${esp32_base.build_flags} -D TLORA_V2_1_16 diff --git a/variants/tracker-t1000-e/platformio.ini b/variants/tracker-t1000-e/platformio.ini index 0bce9fbb5..8c3c97e6c 100644 --- a/variants/tracker-t1000-e/platformio.ini +++ b/variants/tracker-t1000-e/platformio.ini @@ -9,7 +9,7 @@ board_build.ldscript = src/platform/nrf52/nrf52840_s140_v7.ld build_src_filter = ${nrf52_base.build_src_filter} +<../variants/tracker-t1000-e> lib_deps = ${nrf52840_base.lib_deps} - https://github.com/meshtastic/QMA6100P_Arduino_Library.git#14c900b8b2e4feaac5007a7e41e0c1b7f0841136 + https://github.com/meshtastic/QMA6100P_Arduino_Library/archive/14c900b8b2e4feaac5007a7e41e0c1b7f0841136.zip debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) upload_protocol = nrfutil \ No newline at end of file diff --git a/variants/tracksenger/platformio.ini b/variants/tracksenger/platformio.ini index 796a3b7d5..b36b9c45a 100644 --- a/variants/tracksenger/platformio.ini +++ b/variants/tracksenger/platformio.ini @@ -1,6 +1,7 @@ [env:tracksenger] extends = esp32s3_base board = heltec_wireless_tracker +board_build.partitions = default_8MB.csv upload_protocol = esp-builtin build_flags = @@ -16,6 +17,7 @@ lib_deps = [env:tracksenger-lcd] extends = esp32s3_base board = heltec_wireless_tracker +board_build.partitions = default_8MB.csv upload_protocol = esp-builtin build_flags = @@ -31,6 +33,7 @@ lib_deps = [env:tracksenger-oled] extends = esp32s3_base board = heltec_wireless_tracker +board_build.partitions = default_8MB.csv upload_protocol = esp-builtin build_flags = diff --git a/variants/unphone/platformio.ini b/variants/unphone/platformio.ini index e17d3e373..18efbb157 100644 --- a/variants/unphone/platformio.ini +++ b/variants/unphone/platformio.ini @@ -3,6 +3,7 @@ [env:unphone] extends = esp32s3_base board = unphone +board_build.partitions = default_8MB.csv upload_speed = 921600 monitor_speed = 115200 monitor_filters = esp32_exception_decoder @@ -32,7 +33,6 @@ lib_deps = ${esp32s3_base.lib_deps} [env:unphone-tft] extends = env:unphone -board_build.partitions = default_8MB.csv build_flags = ${env:unphone.build_flags} -D MESHTASTIC_EXCLUDE_CANNEDMESSAGES=1 @@ -42,10 +42,10 @@ build_flags = -D MESHTASTIC_EXCLUDE_SERIAL=1 -D MESHTASTIC_EXCLUDE_SOCKETAPI=1 -D INPUTDRIVER_BUTTON_TYPE=21 - -D MAX_NUM_NODES=200 -D MAX_THREADS=40 -D HAS_SCREEN=0 -D HAS_TFT=1 + -D HAS_SDCARD -D DISPLAY_SET_RESOLUTION -D RAM_SIZE=3072 -D LV_LVGL_H_INCLUDE_SIMPLE @@ -63,11 +63,7 @@ build_flags = -D GFX_DRIVER_INC=\"graphics/LGFX/LGFX_UNPHONE.h\" -D VIEW_320x240 -D USE_PACKET_API - -I lib/device-ui/generated/ui_320x240 -build_src_filter = - ${env:unphone.build_src_filter} - +<../lib/device-ui/generated/ui_320x240> - +<../lib/device-ui/resources> - +<../lib/device-ui/locale> - +<../lib/device-ui/source> \ No newline at end of file +lib_deps = + ${env:unphone.lib_deps} + ${device-ui_base.lib_deps} diff --git a/variants/unphone/variant.h b/variants/unphone/variant.h index e846b064a..7b39a5aa5 100644 --- a/variants/unphone/variant.h +++ b/variants/unphone/variant.h @@ -48,7 +48,6 @@ #undef GPS_RX_PIN #undef GPS_TX_PIN -#define HAS_SDCARD 1 #define SD_SPI_FREQUENCY 25000000 #define SDCARD_CS 43 diff --git a/variants/wio-e5/platformio.ini b/variants/wio-e5/platformio.ini index e9d4ca946..e746ae2f0 100644 --- a/variants/wio-e5/platformio.ini +++ b/variants/wio-e5/platformio.ini @@ -1,6 +1,7 @@ [env:wio-e5] extends = stm32_base board = lora_e5_dev_board +board_upload.maximum_size = 233472 ; reserve the last 28KB for filesystem build_flags = ${stm32_base.build_flags} -Ivariants/wio-e5 @@ -8,31 +9,19 @@ build_flags = -DPIN_SERIAL_RX=PB7 -DPIN_SERIAL_TX=PB6 -DHAL_DAC_MODULE_ONLY - -DHAL_ADC_MODULE_DISABLED - -DHAL_COMP_MODULE_DISABLED - -DHAL_CRC_MODULE_DISABLED - -DHAL_CRYP_MODULE_DISABLED - -DHAL_GTZC_MODULE_DISABLED - -DHAL_HSEM_MODULE_DISABLED - -DHAL_I2C_MODULE_DISABLED - -DHAL_I2S_MODULE_DISABLED - -DHAL_IPCC_MODULE_DISABLED - -DHAL_IRDA_MODULE_DISABLED - -DHAL_IWDG_MODULE_DISABLED - -DHAL_LPTIM_MODULE_DISABLED - -DHAL_PKA_MODULE_DISABLED - -DHAL_RNG_MODULE_DISABLED - -DHAL_RTC_MODULE_DISABLED - -DHAL_SMARTCARD_MODULE_DISABLED - -DHAL_SMBUS_MODULE_DISABLED - -DHAL_TIM_MODULE_DISABLED - -DHAL_WWDG_MODULE_DISABLED - -DHAL_EXTI_MODULE_DISABLED - -DHAL_SAI_MODULE_DISABLED - -DHAL_ICACHE_MODULE_DISABLED + -DHAL_RNG_MODULE_ENABLED -DRADIOLIB_EXCLUDE_SX128X=1 -DRADIOLIB_EXCLUDE_SX127X=1 -DRADIOLIB_EXCLUDE_LR11X0=1 -; -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF + -DMESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR=1 + -DMESHTASTIC_EXCLUDE_I2C=1 + -DMESHTASTIC_EXCLUDE_WIFI=1 + -DMESHTASTIC_EXCLUDE_BLUETOOTH=1 + -DMESHTASTIC_EXCLUDE_GPS=1 + -DMESHTASTIC_EXCLUDE_SCREEN=1 + -DMESHTASTIC_EXCLUDE_MQTT=1 + -DMESHTASTIC_EXCLUDE_POWERMON=1 + ;-DPIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF + ;-DCFG_DEBUG upload_port = stlink \ No newline at end of file diff --git a/variants/wio-e5/variant.h b/variants/wio-e5/variant.h index ac92915bb..5421eaeb9 100644 --- a/variants/wio-e5/variant.h +++ b/variants/wio-e5/variant.h @@ -13,9 +13,13 @@ Do not expect a working Meshtastic device with this target. #define _VARIANT_WIOE5_ #define USE_STM32WLx -#define MAX_NUM_NODES 10 #define LED_PIN PB5 #define LED_STATE_ON 1 +#if (defined(LED_BUILTIN) && LED_BUILTIN == PNUM_NOT_DEFINED) +#undef LED_BUILTIN +#define LED_BUILTIN (LED_PIN) +#endif + #endif diff --git a/variants/xiao_ble/variant.h b/variants/xiao_ble/variant.h index a86ddfde2..d00f8be89 100644 --- a/variants/xiao_ble/variant.h +++ b/variants/xiao_ble/variant.h @@ -143,9 +143,10 @@ static const uint8_t SCK = PIN_SPI_SCK; #define SX126X_DIO2_AS_RF_SWITCH #define SX126X_DIO3_TCXO_VOLTAGE 1.8 #ifdef EBYTE_E22_900M30S -// 10dB PA gain and 30dB rated output; based on PA output table from Ebyte Robin -#define REGULATORY_GAIN_LORA 10 -#define SX126X_MAX_POWER 20 +// 10dB PA gain and 30dB rated output; based on measurements from +// https://github.com/S5NC/EBYTE_ESP32-S3/blob/main/E22-900M30S%20power%20output%20testing.txt +#define REGULATORY_GAIN_LORA 7 +#define SX126X_MAX_POWER 22 #endif #ifdef EBYTE_E22_900M33S // 25dB PA gain and 33dB rated output; based on TX Power Curve from E22-900M33S_UserManual_EN_v1.0.pdf diff --git a/version.properties b/version.properties index 4cb750c2c..0b46aeec6 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 6 -build = 0 \ No newline at end of file +build = 5