diff --git a/.github/actions/setup-base/action.yml b/.github/actions/setup-base/action.yml index 45930a94f5..7b97e1753d 100644 --- a/.github/actions/setup-base/action.yml +++ b/.github/actions/setup-base/action.yml @@ -16,6 +16,19 @@ runs: run: | sudo apt-get install -y cppcheck + - name: Install libbluetooth + shell: bash + run: | + sudo apt-get install -y libbluetooth-dev + - name: Install libgpiod + shell: bash + run: | + sudo apt-get install -y libgpiod-dev + - name: Install libyaml-cpp + shell: bash + run: | + sudo apt-get install -y libyaml-cpp-dev + - name: Setup Python uses: actions/setup-python@v4 with: diff --git a/.github/workflows/build_raspbian.yml b/.github/workflows/build_raspbian.yml index 103f43a715..7a25892bc8 100644 --- a/.github/workflows/build_raspbian.yml +++ b/.github/workflows/build_raspbian.yml @@ -41,5 +41,5 @@ jobs: with: name: firmware-raspbian-${{ steps.version.outputs.version }}.zip path: | - release/meshtasticd_linux_arm64 + release/meshtasticd_linux_aarch64 bin/config-dist.yaml diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 8b28090ca5..5c1cf4c21d 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -64,10 +64,10 @@ jobs: - board: tlora-v1 - board: tlora_v1_3 - board: tlora-v2-1-1_6 + - board: tlora-v2-1-1_6-tcxo - board: tlora-v2-1-1_8 - board: tbeam - board: heltec-ht62-esp32c3-sx1262 - - board: heltec-v1 - board: heltec-v2_0 - board: heltec-v2_1 - board: tbeam0_7 @@ -79,6 +79,7 @@ jobs: - board: m5stack-core - board: m5stack-coreink - board: nano-g1-explorer + - board: chatter2 uses: ./.github/workflows/build_esp32.yml with: board: ${{ matrix.board }} @@ -91,6 +92,7 @@ jobs: - board: heltec-v3 - board: heltec-wsl-v3 - board: heltec-wireless-tracker + - board: heltec-wireless-tracker-V1-0 - board: heltec-wireless-paper - board: tbeam-s3-core - board: tlora-t3s3-v1 @@ -110,6 +112,7 @@ jobs: - board: rak4631_eink - board: monteops_hw1 - board: t-echo + - board: canaryone - board: pca10059_diy_eink - board: feather_diy - board: nano-g2-ultra @@ -120,13 +123,13 @@ jobs: build-rpi2040: strategy: fail-fast: false - max-parallel: 2 matrix: include: - board: pico - board: picow - board: rak11310 - board: senselora_rp2040 + - board: rp2040-lora uses: ./.github/workflows/build_rpi2040.yml with: board: ${{ matrix.board }} @@ -246,7 +249,7 @@ jobs: id: version - name: Move files up - run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat ./firmware-raspbian-*/release/meshtasticd_linux_arm64 ./firmware-raspbian-*/bin/config-dist.yaml + run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase_v2.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat ./firmware-raspbian-*/release/meshtasticd_linux_aarch64 ./firmware-raspbian-*/bin/config-dist.yaml - name: Repackage in single firmware zip uses: actions/upload-artifact@v3 diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 61f82e9d77..2f9a99e583 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -40,7 +40,7 @@ jobs: mkdir -p .debpkg/usr/sbin mkdir -p .debpkg/etc/meshtasticd mkdir -p .debpkg/usr/lib/systemd/system/ - cp release/meshtasticd_linux_arm64 .debpkg/usr/sbin/meshtasticd + cp release/meshtasticd_linux_aarch64 .debpkg/usr/sbin/meshtasticd cp bin/config-dist.yaml .debpkg/etc/meshtasticd/config.yaml chmod +x .debpkg/usr/sbin/meshtasticd cp bin/meshtasticd.service .debpkg/usr/lib/systemd/system/meshtasticd.service diff --git a/Dockerfile b/Dockerfile index 8e3cd2154c..21e42ad876 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Install build deps USER root RUN apt-get update && \ - apt-get -y install wget python3 g++ zip python3-venv git vim ca-certificates + apt-get -y install wget python3 g++ zip python3-venv git vim ca-certificates libgpiod-dev libyaml-cpp-dev libbluetooth-dev # create a non-priveleged user & group RUN groupadd -g 1000 mesh && useradd -ml -u 1000 -g 1000 mesh @@ -27,15 +27,15 @@ RUN wget https://raw.githubusercontent.com/platformio/platformio-core-installer/ source ~/.platformio/penv/bin/activate && \ ./bin/build-native.sh -FROM frolvlad/alpine-glibc +FROM frolvlad/alpine-glibc:glibc-2.31 RUN apk --update add --no-cache g++ shadow && \ groupadd -g 1000 mesh && useradd -ml -u 1000 -g 1000 mesh -COPY --from=builder /tmp/firmware/release/meshtasticd_linux_amd64 /home/mesh/ +COPY --from=builder /tmp/firmware/release/meshtasticd_linux_x86_64 /home/mesh/ USER mesh WORKDIR /home/mesh -CMD sh -cx "./meshtasticd_linux_amd64 --hwid '$RANDOM'" +CMD sh -cx "./meshtasticd_linux_x86_64 --hwid '${HWID:-$RANDOM}'" -HEALTHCHECK NONE +HEALTHCHECK NONE \ No newline at end of file diff --git a/arch/esp32/esp32.ini b/arch/esp32/esp32.ini index d79418bee7..b9ce5ec769 100644 --- a/arch/esp32/esp32.ini +++ b/arch/esp32/esp32.ini @@ -36,6 +36,9 @@ build_flags = -DCONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE=5120 -DESP_OPENSSL_SUPPRESS_LEGACY_WARNING -DSERIAL_BUFFER_SIZE=4096 + -DLIBPAX_ARDUINO + -DLIBPAX_WIFI + -DLIBPAX_BLE ;-DDEBUG_HEAP lib_deps = @@ -44,6 +47,7 @@ lib_deps = ${environmental_base.lib_deps} https://github.com/meshtastic/esp32_https_server.git#23665b3adc080a311dcbb586ed5941b5f94d6ea2 h2zero/NimBLE-Arduino@^1.4.1 + https://github.com/dbSuS/libpax.git#7bcd3fcab75037505be9b122ab2b24cc5176b587 https://github.com/lewisxhe/XPowersLib.git#84b7373faea3118b6c37954d52f98b8a337148d6 https://github.com/meshtastic/ESP32_Codec2.git#633326c78ac251c059ab3a8c430fcdf25b41672f diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index 07f13e8fbb..23c591bf06 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -1,6 +1,6 @@ ; The Portduino based sim environment on top of any host OS, all hardware will be simulated [portduino_base] -platform = https://github.com/meshtastic/platform-native.git#05255283879a0c65a7d3eba6c468b9186438bb14 +platform = https://github.com/meshtastic/platform-native.git#a28dd5a9ccd5c48a9bede46037855ff83915d74b framework = arduino build_src_filter = @@ -24,10 +24,14 @@ lib_deps = ${env.lib_deps} ${networking_base.lib_deps} rweather/Crypto@^0.4.0 + lovyan03/LovyanGFX@^1.1.12 build_flags = ${arduino_base.build_flags} -fPIC -Isrc/platform/portduino -DRADIOLIB_EEPROM_UNSUPPORTED - + -DPORTDUINO_LINUX_HARDWARE + -lbluetooth + -lgpiod + -lyaml-cpp \ No newline at end of file diff --git a/bin/Meshtastic_nRF52_factory_erase.uf2 b/bin/Meshtastic_nRF52_factory_erase.uf2 deleted file mode 100644 index fffff13ecd..0000000000 Binary files a/bin/Meshtastic_nRF52_factory_erase.uf2 and /dev/null differ diff --git a/bin/Meshtastic_nRF52_factory_erase_v2.uf2 b/bin/Meshtastic_nRF52_factory_erase_v2.uf2 new file mode 100644 index 0000000000..8a83bc8ecf Binary files /dev/null and b/bin/Meshtastic_nRF52_factory_erase_v2.uf2 differ diff --git a/bin/build-native.sh b/bin/build-native.sh index 64c5adb504..7e9fcb632c 100755 --- a/bin/build-native.sh +++ b/bin/build-native.sh @@ -14,14 +14,7 @@ rm -r $OUTDIR/* || true # Important to pull latest version of libs into all device flavors, otherwise some devices might be stale platformio pkg update - -if command -v raspi-config &>/dev/null; then - pio run --environment raspbian - cp .pio/build/raspbian/program $OUTDIR/meshtasticd_linux_arm64 -else - pio run --environment native - cp .pio/build/native/program $OUTDIR/meshtasticd_linux_amd64 -fi - +pio run --environment native +cp .pio/build/native/program "$OUTDIR/meshtasticd_linux_$(arch)" cp bin/device-install.* $OUTDIR cp bin/device-update.* $OUTDIR diff --git a/bin/check-all.sh b/bin/check-all.sh index 1475ac3ee6..d1b50a8aad 100755 --- a/bin/check-all.sh +++ b/bin/check-all.sh @@ -13,7 +13,7 @@ if [[ $# -gt 0 ]]; then # can override which environment by passing arg BOARDS="$@" else - BOARDS="tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec-v1 heltec-v2.0 heltec-v2.1 tbeam0.7 meshtastic-diy-v1 rak4631 rak4631_eink rak11200 t-echo pca10059_diy_eink" + BOARDS="tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec-v2.0 heltec-v2.1 tbeam0.7 meshtastic-diy-v1 rak4631 rak4631_eink rak11200 t-echo canaryone pca10059_diy_eink" fi echo "BOARDS:${BOARDS}" diff --git a/bin/check-dependencies.sh b/bin/check-dependencies.sh index 27372487fc..4aa0fccc0b 100644 --- a/bin/check-dependencies.sh +++ b/bin/check-dependencies.sh @@ -5,17 +5,17 @@ set -e if [[ $# -gt 0 ]]; then - # can override which environment by passing arg - BOARDS="$@" + # can override which environment by passing arg + BOARDS="$@" else - BOARDS="rak4631 rak4631_eink t-echo pca10059_diy_eink pico rak11200 tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec-v1 heltec-v2.0 heltec-v2.1 tbeam0.7 meshtastic-diy-v1 nano-g1 station-g1 m5stack-core m5stack-coreink tbeam-s3-core" + BOARDS="rak4631 rak4631_eink t-echo canaryone pca10059_diy_eink pico rak11200 tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec-v2.0 heltec-v2.1 tbeam0.7 meshtastic-diy-v1 nano-g1 station-g1 m5stack-core m5stack-coreink tbeam-s3-core" fi echo "BOARDS:${BOARDS}" CHECK="" for BOARD in $BOARDS; do - CHECK="${CHECK} -e ${BOARD}" + CHECK="${CHECK} -e ${BOARD}" done echo $CHECK diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index cde45d1f87..b5b105e4c2 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -1,5 +1,5 @@ -# Define your devices here using Broadcom pin numbering -# Uncomment the block that corresponds to your hardware +### Define your devices here using Broadcom pin numbering +### Uncomment the block that corresponds to your hardware --- Lora: # Module: sx1262 # Waveshare SX126X XXXM @@ -14,6 +14,12 @@ Lora: # IRQ: 17 # Reset: 22 +# Module: sx1262 # pinedio +# CS: 0 +# IRQ: 10 +# Busy: 11 +# spidev: spidev0.1 + # Module: RF95 # Adafruit RFM9x # Reset: 25 # CS: 7 @@ -25,16 +31,89 @@ Lora: # CS: 7 # IRQ: 25 -# Set gpio chip to use in /dev/. Defaults to 0. -# Notably the Raspberry Pi 5 puts the GPIO header on gpiochip4 +# Module: sx1280 # SX1280 +# CS: 21 +# IRQ: 16 +# Busy: 20 +# Reset: 18 + +# DIO3_TCXO_VOLTAGE: true # the Waveshare Core1262 and others are known to need this setting + +# TXen: x # TX and RX enable pins +# RXen: x + +### Set gpio chip to use in /dev/. Defaults to 0. +### Notably the Raspberry Pi 5 puts the GPIO header on gpiochip4 # gpiochip: 4 -# Define GPIO buttons here: +### Specify the SPI device to use in /dev/. Defaults to spidev0.0 +### Some devices, like the pinedio, may require spidev0.1 as a workaround. +# spidev: spidev0.0 + +### Define GPIO buttons here: GPIO: # User: 6 -# Define GPS +### Define GPS GPS: # SerialPath: /dev/ttyS0 + +### Specify I2C device, or leave blank for none + +I2C: +# I2CDevice: /dev/i2c-1 + +### Set up SPI displays here. Note that I2C displays are generally auto-detected. + +Display: + +### Waveshare 2.8inch RPi LCD +# Panel: ST7789 +# CS: 8 +# DC: 22 # Data/Command pin +# Backlight: 18 +# Width: 240 +# Height: 320 +# Reset: 27 +# Rotate: true +# Invert: true + +### Waveshare 1.44inch LCD HAT +# Panel: ST7735S +# CS: 8 #Chip Select +# DC: 25 # Data/Command pin +# Backlight: 24 +# Width: 128 +# Height: 128 +# Reset: 27 +# OffsetX: 0 +# OffsetY: 0 + +### Adafruit PiTFT 2.8 TFT+Touchscreen +# Panel: ILI9341 +# CS: 8 +# DC: 25 +# Backlight: 2 +# Width: 320 +# Height: 240 + +Touchscreen: +# Module: STMPE610 +# CS: 7 +# IRQ: 24 + +# Module: XPT2046 +# CS: 7 +# IRQ: 17 + +### Configure device for direct keyboard input + +Input: +# KeyboardDevice: /dev/input/event0 + +### + +Logging: + LogLevel: info # debug, info, warn, error diff --git a/bin/exception_decoder.py b/bin/exception_decoder.py index 8ef66b9bb7..ec94ce20e3 100755 --- a/bin/exception_decoder.py +++ b/bin/exception_decoder.py @@ -11,19 +11,22 @@ * version that's checked into meshtastic repo is based on: https://github.com/me21/EspArduinoExceptionDecoder which adds in ESP32 Backtrace decoding. * this also updates the defaults to use ESP32, instead of ESP8266 and defaults to the built firmware.bin +* also updated the toolchain name, which will be set according to the platform To use, copy the "Backtrace: 0x...." line to a file, e.g., backtrace.txt, then run: $ bin/exception_decoder.py backtrace.txt +For a platform other than ESP32, use the -p option, e.g.: +$ bin/exception_decoder.py -p ESP32S3 backtrace.txt +To specify a specific .elf file, use the -e option, e.g.: +$ bin/exception_decoder.py -e firmware.elf backtrace.txt """ import argparse +import os import re import subprocess -from collections import namedtuple - import sys - -import os +from collections import namedtuple EXCEPTIONS = [ "Illegal instruction", @@ -55,24 +58,39 @@ "LoadStorePrivilege: A load or store referenced a virtual address at a ring level less than CRING", "reserved", "LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads", - "StoreProhibited: A store referenced a page mapped with an attribute that does not permit stores" + "StoreProhibited: A store referenced a page mapped with an attribute that does not permit stores", ] PLATFORMS = { - "ESP8266": "lx106", - "ESP32": "esp32" + "ESP8266": "xtensa-lx106", + "ESP32": "xtensa-esp32", + "ESP32S3": "xtensa-esp32s3", + "ESP32C3": "riscv32-esp", +} +TOOLS = { + "ESP8266": "xtensa", + "ESP32": "xtensa-esp32", + "ESP32S3": "xtensa-esp32s3", + "ESP32C3": "riscv32-esp", } -BACKTRACE_REGEX = re.compile(r"(?:\s+(0x40[0-2](?:\d|[a-f]|[A-F]){5}):0x(?:\d|[a-f]|[A-F]){8})\b") +BACKTRACE_REGEX = re.compile( + r"(?:\s+(0x40[0-2](?:\d|[a-f]|[A-F]){5}):0x(?:\d|[a-f]|[A-F]){8})\b" +) EXCEPTION_REGEX = re.compile("^Exception \\((?P[0-9]*)\\):$") -COUNTER_REGEX = re.compile('^epc1=(?P0x[0-9a-f]+) epc2=(?P0x[0-9a-f]+) epc3=(?P0x[0-9a-f]+) ' - 'excvaddr=(?P0x[0-9a-f]+) depc=(?P0x[0-9a-f]+)$') +COUNTER_REGEX = re.compile( + "^epc1=(?P0x[0-9a-f]+) epc2=(?P0x[0-9a-f]+) epc3=(?P0x[0-9a-f]+) " + "excvaddr=(?P0x[0-9a-f]+) depc=(?P0x[0-9a-f]+)$" +) CTX_REGEX = re.compile("^ctx: (?P.+)$") -POINTER_REGEX = re.compile('^sp: (?P[0-9a-f]+) end: (?P[0-9a-f]+) offset: (?P[0-9a-f]+)$') -STACK_BEGIN = '>>>stack>>>' -STACK_END = '<<[0-9a-f]+) end: (?P[0-9a-f]+) offset: (?P[0-9a-f]+)$" +) +STACK_BEGIN = ">>>stack>>>" +STACK_END = "<<[0-9a-f]+):\W+(?P[0-9a-f]+) (?P[0-9a-f]+) (?P[0-9a-f]+) (?P[0-9a-f]+)(\W.*)?$') + "^(?P[0-9a-f]+):\W+(?P[0-9a-f]+) (?P[0-9a-f]+) (?P[0-9a-f]+) (?P[0-9a-f]+)(\W.*)?$" +) StackLine = namedtuple("StackLine", ["offset", "content"]) @@ -96,15 +114,18 @@ def __init__(self): self.stack = [] def _parse_backtrace(self, line): - if line.startswith('Backtrace:'): - self.stack = [StackLine(offset=0, content=(addr,)) for addr in BACKTRACE_REGEX.findall(line)] + if line.startswith("Backtrace:"): + self.stack = [ + StackLine(offset=0, content=(addr,)) + for addr in BACKTRACE_REGEX.findall(line) + ] return None return self._parse_backtrace def _parse_exception(self, line): match = EXCEPTION_REGEX.match(line) if match is not None: - self.exception = int(match.group('exc')) + self.exception = int(match.group("exc")) return self._parse_counters return self._parse_exception @@ -144,14 +165,22 @@ def _parse_stack_line(self, line): if line != STACK_END: match = STACK_REGEX.match(line) if match is not None: - self.stack.append(StackLine(offset=match.group("off"), - content=(match.group("c1"), match.group("c2"), match.group("c3"), - match.group("c4")))) + self.stack.append( + StackLine( + offset=match.group("off"), + content=( + match.group("c1"), + match.group("c2"), + match.group("c3"), + match.group("c4"), + ), + ) + ) return self._parse_stack_line return None def parse_file(self, file, platform, stack_only=False): - if platform == 'ESP32': + if platform != "ESP8266": func = self._parse_backtrace else: func = self._parse_exception @@ -175,7 +204,9 @@ def __init__(self, tool_path, elf_path): self._address_map = {} def _lookup(self, addresses): - cmd = [self._tool, "-aipfC", "-e", self._elf] + [addr for addr in addresses if addr is not None] + cmd = [self._tool, "-aipfC", "-e", self._elf] + [ + addr for addr in addresses if addr is not None + ] if sys.version_info[0] < 3: output = subprocess.check_output(cmd) @@ -190,19 +221,27 @@ def _lookup(self, addresses): match = line_regex.match(line) if match is None: - if last is not None and line.startswith('(inlined by)'): - line = line [12:].strip() - self._address_map[last] += ("\n \-> inlined by: " + line) + if last is not None and line.startswith("(inlined by)"): + line = line[12:].strip() + self._address_map[last] += "\n \-> inlined by: " + line continue - if match.group("result") == '?? ??:0': + if match.group("result") == "?? ??:0": continue self._address_map[match.group("addr")] = match.group("result") last = match.group("addr") def fill(self, parser): - addresses = [parser.epc1, parser.epc2, parser.epc3, parser.excvaddr, parser.sp, parser.end, parser.offset] + addresses = [ + parser.epc1, + parser.epc2, + parser.epc3, + parser.excvaddr, + parser.sp, + parser.end, + parser.offset, + ] for line in parser.stack: addresses.extend(line.content) @@ -257,8 +296,10 @@ def print_stack(lines, resolver): def print_result(parser, resolver, platform, full=True, stack_only=False): - if platform == 'ESP8266' and not stack_only: - print('Exception: {} ({})'.format(parser.exception, EXCEPTIONS[parser.exception])) + if platform == "ESP8266" and not stack_only: + print( + "Exception: {} ({})".format(parser.exception, EXCEPTIONS[parser.exception]) + ) print("") print_addr("epc1", parser.epc1, resolver) @@ -285,15 +326,33 @@ def print_result(parser, resolver, platform, full=True, stack_only=False): def parse_args(): parser = argparse.ArgumentParser(description="decode ESP Stacktraces.") - parser.add_argument("-p", "--platform", help="The platform to decode from", choices=PLATFORMS.keys(), - default="ESP32") - parser.add_argument("-t", "--tool", help="Path to the xtensa toolchain", - default="~/.platformio/packages/toolchain-xtensa32/") - parser.add_argument("-e", "--elf", help="path to elf file", - default=".pio/build/esp32/firmware.elf") - parser.add_argument("-f", "--full", help="Print full stack dump", action="store_true") - parser.add_argument("-s", "--stack_only", help="Decode only a stractrace", action="store_true") - parser.add_argument("file", help="The file to read the exception data from ('-' for STDIN)", default="-") + parser.add_argument( + "-p", + "--platform", + help="The platform to decode from", + choices=PLATFORMS.keys(), + default="ESP32", + ) + parser.add_argument( + "-t", + "--tool", + help="Path to the toolchain (without specific platform)", + default="~/.platformio/packages/toolchain-", + ) + parser.add_argument( + "-e", "--elf", help="path to elf file", default=".pio/build/tbeam/firmware.elf" + ) + parser.add_argument( + "-f", "--full", help="Print full stack dump", action="store_true" + ) + parser.add_argument( + "-s", "--stack_only", help="Decode only a stractrace", action="store_true" + ) + parser.add_argument( + "file", + help="The file to read the exception data from ('-' for STDIN)", + default="-", + ) return parser.parse_args() @@ -309,10 +368,12 @@ def parse_args(): sys.exit(1) file = open(args.file, "r") - addr2line = os.path.join(os.path.abspath(os.path.expanduser(args.tool)), - "bin/xtensa-" + PLATFORMS[args.platform] + "-elf-addr2line") - if os.name == 'nt': - addr2line += '.exe' + addr2line = os.path.join( + os.path.abspath(os.path.expanduser(args.tool + TOOLS[args.platform])), + "bin/" + PLATFORMS[args.platform] + "-elf-addr2line", + ) + if os.name == "nt": + addr2line += ".exe" if not os.path.exists(addr2line): print("ERROR: addr2line not found (" + addr2line + ")") diff --git a/bin/lilygo_techo_bootloader-0.6.1.zip b/bin/lilygo_techo_bootloader-0.6.1.zip new file mode 100644 index 0000000000..34bd169f62 Binary files /dev/null and b/bin/lilygo_techo_bootloader-0.6.1.zip differ diff --git a/bin/meshtasticd.service b/bin/meshtasticd.service index 4ed1bfd8fa..f15fdc8714 100644 --- a/bin/meshtasticd.service +++ b/bin/meshtasticd.service @@ -1,9 +1,12 @@ -[unit] -description=Meshtastic Native Daemon +[Unit] +Description=Meshtastic Native Daemon +After=network-online.target [Service] +User=root +Group=root Type=simple ExecStart=/usr/sbin/meshtasticd [Install] -WantedBy=multi-user.target +WantedBy=multi-user.target \ No newline at end of file diff --git a/bin/native-install.sh b/bin/native-install.sh index d1d0c8707b..cc6d968f9b 100755 --- a/bin/native-install.sh +++ b/bin/native-install.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -cp release/meshtasticd_linux_arm64 /usr/sbin/meshtasticd +cp "release/meshtasticd_linux_$(arch)" /usr/sbin/meshtasticd mkdir /etc/meshtasticd if [[ -f "/etc/meshtasticd/config.yaml" ]]; then cp bin/config-dist.yaml /etc/meshtasticd/config-upgrade.yaml diff --git a/bin/update-lilygo_techo_bootloader-0.6.1_nosd.uf2 b/bin/update-lilygo_techo_bootloader-0.6.1_nosd.uf2 new file mode 100644 index 0000000000..ea293e357d Binary files /dev/null and b/bin/update-lilygo_techo_bootloader-0.6.1_nosd.uf2 differ diff --git a/boards/canaryone.json b/boards/canaryone.json new file mode 100644 index 0000000000..d8f966a475 --- /dev/null +++ b/boards/canaryone.json @@ -0,0 +1,49 @@ +{ + "build": { + "arduino": { + "ldscript": "nrf52840_s140_v6.ld" + }, + "core": "nRF5", + "cpu": "cortex-m4", + "extra_flags": "-DARDUINO_NRF52840_CANARY -DNRF52840_XXAA", + "f_cpu": "64000000L", + "hwids": [["0x239A", "0x4405"]], + "usb_product": "CanaryOne", + "mcu": "nrf52840", + "variant": "canaryone", + "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": "Canary (Adafruit BSP)", + "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": "https://canaryradio.io/", + "vendor": "Canary Radio Company" +} diff --git a/boards/eink0.1.json b/boards/eink0.1.json index 28862c5d4d..cb636ea3f8 100644 --- a/boards/eink0.1.json +++ b/boards/eink0.1.json @@ -29,7 +29,8 @@ "debug": { "jlink_device": "nRF52840_xxAA", "onboard_tools": ["jlink"], - "svd_path": "nrf52840.svd" + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" }, "frameworks": ["arduino"], "name": "TTGO eink (Adafruit BSP)", diff --git a/boards/esp32-s3-pico.json b/boards/esp32-s3-pico.json new file mode 100644 index 0000000000..8f8c6fdb7f --- /dev/null +++ b/boards/esp32-s3-pico.json @@ -0,0 +1,40 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default_16MB.csv" + }, + "core": "esp32", + "extra_flags": [ + "-DARDUINO_ESP32S3_DEV", + "-DARDUINO_USB_MODE=1", + "-DARDUINO_RUNNING_CORE=1", + "-DARDUINO_EVENT_RUNNING_CORE=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [["0x303A", "0x1001"]], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": ["wifi", "bluetooth", "lora"], + "debug": { + "default_tool": "esp-builtin", + "onboard_tools": ["esp-builtin"], + "openocd_target": "esp32s3.cfg" + }, + "frameworks": ["arduino", "espidf"], + "name": "Waveshare ESP32-S3-Pico (16 MB FLASH, 2 MB PSRAM)", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://www.waveshare.com/esp32-s3-pico.htm", + "vendor": "Waveshare" +} diff --git a/boards/lora-relay-v1.json b/boards/lora-relay-v1.json index ca4e2f0ab2..b390b84046 100644 --- a/boards/lora-relay-v1.json +++ b/boards/lora-relay-v1.json @@ -29,7 +29,8 @@ "debug": { "jlink_device": "nRF52840_xxAA", "onboard_tools": ["jlink"], - "svd_path": "nrf52840.svd" + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" }, "frameworks": ["arduino"], "name": "Meshtastic Lora Relay V1 (Adafruit BSP)", diff --git a/boards/lora-relay-v2.json b/boards/lora-relay-v2.json index 2cca8ae9ab..52b775e587 100644 --- a/boards/lora-relay-v2.json +++ b/boards/lora-relay-v2.json @@ -29,7 +29,8 @@ "debug": { "jlink_device": "nRF52840_xxAA", "onboard_tools": ["jlink"], - "svd_path": "nrf52840.svd" + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" }, "frameworks": ["arduino"], "name": "Meshtastic Lora Relay V1 (Adafruit BSP)", diff --git a/boards/lora_isp4520.json b/boards/lora_isp4520.json index 971512b281..8125aa666d 100644 --- a/boards/lora_isp4520.json +++ b/boards/lora_isp4520.json @@ -22,7 +22,8 @@ "connectivity": ["bluetooth"], "debug": { "jlink_device": "nRF52832_xxAA", - "svd_path": "nrf52.svd" + "svd_path": "nrf52.svd", + "openocd_target": "nrf52840-mdk-rs" }, "frameworks": ["arduino"], "name": "lora ISP4520", diff --git a/boards/nordic_pca10059.json b/boards/nordic_pca10059.json index 214c2851d8..b99e3c763f 100644 --- a/boards/nordic_pca10059.json +++ b/boards/nordic_pca10059.json @@ -32,7 +32,8 @@ "connectivity": ["bluetooth"], "debug": { "jlink_device": "nRF52840_xxAA", - "svd_path": "nrf52840.svd" + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" }, "frameworks": ["arduino"], "name": "nRF52840 Dongle", diff --git a/boards/nrf52840_dk.json b/boards/nrf52840_dk.json index 8d07575bf6..8a16e854fa 100644 --- a/boards/nrf52840_dk.json +++ b/boards/nrf52840_dk.json @@ -29,7 +29,8 @@ "debug": { "jlink_device": "nRF52840_xxAA", "onboard_tools": ["jlink"], - "svd_path": "nrf52840.svd" + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" }, "frameworks": ["arduino"], "name": "A modified NRF52840-DK devboard (Adafruit BSP)", diff --git a/boards/nrf52840_dk_modified.json b/boards/nrf52840_dk_modified.json index 0462c55f8e..2932cb4b90 100644 --- a/boards/nrf52840_dk_modified.json +++ b/boards/nrf52840_dk_modified.json @@ -29,7 +29,8 @@ "debug": { "jlink_device": "nRF52840_xxAA", "onboard_tools": ["jlink"], - "svd_path": "nrf52840.svd" + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" }, "frameworks": ["arduino"], "name": "A modified NRF52840-DK devboard (Adafruit BSP)", diff --git a/boards/ppr.json b/boards/ppr.json index 5283fdc4e8..15e3025c0d 100644 --- a/boards/ppr.json +++ b/boards/ppr.json @@ -29,7 +29,8 @@ "debug": { "jlink_device": "nRF52840_xxAA", "onboard_tools": ["jlink"], - "svd_path": "nrf52840.svd" + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" }, "frameworks": ["arduino"], "name": "Meshtastic PPR (Adafruit BSP)", diff --git a/boards/ppr1.json b/boards/ppr1.json index 4c05282456..35bf7d1e42 100644 --- a/boards/ppr1.json +++ b/boards/ppr1.json @@ -29,7 +29,8 @@ "debug": { "jlink_device": "nRF52833_xxAA", "onboard_tools": ["jlink"], - "svd_path": "nrf52833.svd" + "svd_path": "nrf52833.svd", + "openocd_target": "nrf52840-mdk-rs" }, "frameworks": ["arduino"], "name": "Meshtastic PPR1 (Adafruit BSP)", diff --git a/boards/t-echo.json b/boards/t-echo.json index 957ba01e3c..fcfc8c50b1 100644 --- a/boards/t-echo.json +++ b/boards/t-echo.json @@ -9,6 +9,7 @@ "f_cpu": "64000000L", "hwids": [ ["0x239A", "0x4405"], + ["0x239A", "0x0029"], ["0x239A", "0x002A"] ], "usb_product": "TTGO_eink", @@ -32,7 +33,8 @@ "debug": { "jlink_device": "nRF52840_xxAA", "onboard_tools": ["jlink"], - "svd_path": "nrf52840.svd" + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" }, "frameworks": ["arduino"], "name": "TTGO eink (Adafruit BSP)", diff --git a/boards/t-watch-s3.json b/boards/t-watch-s3.json index 080389f39e..e6e3633053 100644 --- a/boards/t-watch-s3.json +++ b/boards/t-watch-s3.json @@ -16,7 +16,10 @@ "f_cpu": "240000000L", "f_flash": "80000000L", "flash_mode": "qio", - "hwids": [["0x303A", "0x1001"]], + "hwids": [ + ["0x303A", "0x1001"], + ["0x303A", "0x0002"] + ], "mcu": "esp32s3", "variant": "t-watch-s3" }, diff --git a/boards/wiscore_rak4600.json b/boards/wiscore_rak4600.json index 9969ef26ea..0dec90a79e 100644 --- a/boards/wiscore_rak4600.json +++ b/boards/wiscore_rak4600.json @@ -32,7 +32,8 @@ "connectivity": ["bluetooth"], "debug": { "jlink_device": "nRF52832_xxAA", - "svd_path": "nrf52.svd" + "svd_path": "nrf52.svd", + "openocd_target": "nrf52840-mdk-rs" }, "frameworks": ["arduino", "zephyr"], "name": "Adafruit Bluefruit nRF52832 Feather", diff --git a/boards/wiscore_rak4631.json b/boards/wiscore_rak4631.json index 149492688d..6dec3f7cb4 100644 --- a/boards/wiscore_rak4631.json +++ b/boards/wiscore_rak4631.json @@ -32,7 +32,8 @@ "connectivity": ["bluetooth"], "debug": { "jlink_device": "nRF52840_xxAA", - "svd_path": "nrf52840.svd" + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" }, "frameworks": ["arduino"], "name": "WisCore RAK4631 Board", diff --git a/boards/xiao_ble_sense.json b/boards/xiao_ble_sense.json index 09a28c25df..8e0212b3ef 100644 --- a/boards/xiao_ble_sense.json +++ b/boards/xiao_ble_sense.json @@ -31,7 +31,8 @@ "connectivity": ["bluetooth"], "debug": { "jlink_device": "nRF52840_xxAA", - "svd_path": "nrf52840.svd" + "svd_path": "nrf52840.svd", + "openocd_target": "nrf52840-mdk-rs" }, "frameworks": ["arduino"], "name": "Seeed Xiao BLE Sense", diff --git a/platformio.ini b/platformio.ini index d7ad053370..0033b6e469 100644 --- a/platformio.ini +++ b/platformio.ini @@ -2,7 +2,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -;default_envs = tbeam +default_envs = tbeam ;default_envs = pico ;default_envs = tbeam-s3-core ;default_envs = tbeam0.7 @@ -10,13 +10,16 @@ ;default_envs = heltec-v2_0 ;default_envs = heltec-v2_1 ;default_envs = heltec-wireless-tracker +;default_envs = chatter2 ;default_envs = tlora-v1 ;default_envs = tlora_v1_3 ;default_envs = tlora-v2 ;default_envs = tlora-v2-1-1_6 +;default_envs = tlora-v2-1-1_6-tcxo ;default_envs = tlora-t3s3-v1 ;default_envs = lora-relay-v1 # nrf board ;default_envs = t-echo +;default_envs = canaryone ;default_envs = nrf52840dk-geeksville ;default_envs = native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here ;default_envs = nano-g1 @@ -27,7 +30,7 @@ ;default_envs = m5stack-coreink ;default_envs = rak4631 ;default_envs = rak10701 -default_envs = wio-e5 +;default_envs = wio-e5 extra_configs = arch/*/*.ini @@ -51,9 +54,11 @@ build_flags = -Wno-missing-field-initializers -DRADIOLIB_EXCLUDE_NRF24 -DRADIOLIB_EXCLUDE_RF69 -DRADIOLIB_EXCLUDE_SX1231 + -DRADIOLIB_EXCLUDE_SX1233 -DRADIOLIB_EXCLUDE_SI443X -DRADIOLIB_EXCLUDE_RFM2X -DRADIOLIB_EXCLUDE_AFSK + -DRADIOLIB_EXCLUDE_BELL -DRADIOLIB_EXCLUDE_HELLSCHREIBER -DRADIOLIB_EXCLUDE_MORSE -DRADIOLIB_EXCLUDE_RTTY @@ -68,11 +73,11 @@ build_flags = -Wno-missing-field-initializers monitor_speed = 115200 lib_deps = - jgromes/RadioLib@^6.3.0 - https://github.com/meshtastic/esp8266-oled-ssd1306.git#b38094e03dfa964fbc0e799bc374e91a605c1223 ; ESP8266_SSD1306 + jgromes/RadioLib@^6.4.0 + https://github.com/meshtastic/esp8266-oled-ssd1306.git#ee628ee6c9588d4c56c9e3da35f0fc9448ad54a8 ; ESP8266_SSD1306 mathertel/OneButton@^2.5.0 ; OneButton library for non-blocking button debounce https://github.com/meshtastic/arduino-fsm.git#7db3702bf0cfe97b783d6c72595e3f38e0b19159 - https://github.com/meshtastic/TinyGPSPlus.git#076e8d2c8fb702d9be5b08c55b93ff76f8af7e61 + https://github.com/meshtastic/TinyGPSPlus.git#2044b2c51e91ab4cd8cc93b15e40658cd808dd06 https://github.com/meshtastic/ArduinoThread.git#72921ac222eed6f526ba1682023cee290d9aa1b3 nanopb/Nanopb@^0.4.7 erriez/ErriezCRC32@^1.0.1 @@ -115,7 +120,7 @@ lib_deps = https://github.com/boschsensortec/Bosch-BSEC2-Library#v1.5.2400 boschsensortec/BME68x Sensor Library@^1.1.40407 adafruit/Adafruit MCP9808 Library@^2.0.0 - https://github.com/Tinyu-Zhao/INA3221@^0.0.1 + https://github.com/KodinLanewave/INA3221@^1.0.0 adafruit/Adafruit INA260 Library@^1.5.0 adafruit/Adafruit INA219@^1.2.0 adafruit/Adafruit SHTC3 Library@^1.0.0 diff --git a/protobufs b/protobufs index a34b2c680e..24edea6442 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit a34b2c680e2c1c240643c515e57c5532b29c91a7 +Subproject commit 24edea64429de4474c00d09990ef4c496614dc5d diff --git a/src/AccelerometerThread.h b/src/AccelerometerThread.h index f0167f0104..4bab6c4484 100644 --- a/src/AccelerometerThread.h +++ b/src/AccelerometerThread.h @@ -42,7 +42,7 @@ namespace concurrency class AccelerometerThread : public concurrency::OSThread { public: - AccelerometerThread(ScanI2C::DeviceType type = ScanI2C::DeviceType::NONE) : OSThread("AccelerometerThread") + explicit AccelerometerThread(ScanI2C::DeviceType type) : OSThread("AccelerometerThread") { if (accelerometer_found.port == ScanI2C::I2CPort::NO_I2C) { LOG_DEBUG("AccelerometerThread disabling due to no sensors found\n"); diff --git a/src/AmbientLightingThread.h b/src/AmbientLightingThread.h index 0dd0fdf4ac..98ccedde4b 100644 --- a/src/AmbientLightingThread.h +++ b/src/AmbientLightingThread.h @@ -10,7 +10,7 @@ namespace concurrency class AmbientLightingThread : public concurrency::OSThread { public: - AmbientLightingThread(ScanI2C::DeviceType type) : OSThread("AmbientLightingThread") + explicit AmbientLightingThread(ScanI2C::DeviceType type) : OSThread("AmbientLightingThread") { // Uncomment to test module // moduleConfig.ambient_lighting.led_state = true; diff --git a/src/ButtonThread.cpp b/src/ButtonThread.cpp new file mode 100644 index 0000000000..84d4332852 --- /dev/null +++ b/src/ButtonThread.cpp @@ -0,0 +1,219 @@ +#include "ButtonThread.h" +#include "GPS.h" +#include "MeshService.h" +#include "PowerFSM.h" +#include "RadioLibInterface.h" +#include "buzz.h" +#include "graphics/Screen.h" +#include "main.h" +#include "modules/ExternalNotificationModule.h" +#include "power.h" +#ifdef ARCH_PORTDUINO +#include "platform/portduino/PortduinoGlue.h" +#endif + +#define DEBUG_BUTTONS 0 +#if DEBUG_BUTTONS +#define LOG_BUTTON(...) LOG_DEBUG(__VA_ARGS__) +#else +#define LOG_BUTTON(...) +#endif + +using namespace concurrency; + +volatile ButtonThread::ButtonEventType ButtonThread::btnEvent = ButtonThread::BUTTON_EVENT_NONE; + +ButtonThread::ButtonThread() : OSThread("Button") +{ +#if defined(ARCH_PORTDUINO) || defined(BUTTON_PIN) +#if defined(ARCH_PORTDUINO) + if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) { + userButton = OneButton(settingsMap[user], true, true); + LOG_DEBUG("Using GPIO%02d for button\n", settingsMap[user]); + } +#elif defined(BUTTON_PIN) + int pin = config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN; + this->userButton = OneButton(pin, true, true); + LOG_DEBUG("Using GPIO%02d for button\n", pin); +#endif + +#ifdef INPUT_PULLUP_SENSE + // Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did + pinMode(pin, INPUT_PULLUP_SENSE); +#endif + userButton.attachClick(userButtonPressed); + userButton.setClickMs(250); + userButton.setPressMs(c_longPressTime); + userButton.setDebounceMs(1); + userButton.attachDoubleClick(userButtonDoublePressed); + userButton.attachMultiClick(userButtonMultiPressed); +#ifndef T_DECK // T-Deck immediately wakes up after shutdown, so disable this function + userButton.attachLongPressStart(userButtonPressedLongStart); + userButton.attachLongPressStop(userButtonPressedLongStop); +#endif +#if defined(ARCH_PORTDUINO) + if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) + wakeOnIrq(settingsMap[user], FALLING); +#else + static OneButton *pBtn = &userButton; // only one instance of ButtonThread is created, so static is safe + attachInterrupt( + pin, + []() { + BaseType_t higherWake = 0; + mainDelay.interruptFromISR(&higherWake); + pBtn->tick(); + }, + CHANGE); +#endif +#endif +#ifdef BUTTON_PIN_ALT + userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true); +#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.setClickMs(250); + userButtonAlt.setPressMs(c_longPressTime); + userButtonAlt.setDebounceMs(1); + userButtonAlt.attachDoubleClick(userButtonDoublePressed); + userButtonAlt.attachLongPressStart(userButtonPressedLongStart); + userButtonAlt.attachLongPressStop(userButtonPressedLongStop); + wakeOnIrq(BUTTON_PIN_ALT, FALLING); +#endif + +#ifdef BUTTON_PIN_TOUCH + userButtonTouch = OneButton(BUTTON_PIN_TOUCH, true, true); + userButtonTouch.attachClick(touchPressed); + wakeOnIrq(BUTTON_PIN_TOUCH, FALLING); +#endif +} + +int32_t ButtonThread::runOnce() +{ + // If the button is pressed we suppress CPU sleep until release + canSleep = true; // Assume we should not keep the board awake + +#if defined(BUTTON_PIN) + userButton.tick(); + canSleep &= userButton.isIdle(); +#elif defined(ARCH_PORTDUINO) + if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) { + userButton.tick(); + canSleep &= userButton.isIdle(); + } +#endif +#ifdef BUTTON_PIN_ALT + userButtonAlt.tick(); + canSleep &= userButtonAlt.isIdle(); +#endif +#ifdef BUTTON_PIN_TOUCH + userButtonTouch.tick(); + canSleep &= userButtonTouch.isIdle(); +#endif + + if (btnEvent != BUTTON_EVENT_NONE) { + switch (btnEvent) { + case BUTTON_EVENT_PRESSED: { + LOG_BUTTON("press!\n"); +#ifdef BUTTON_PIN + if (((config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN) != + moduleConfig.canned_message.inputbroker_pin_press) || + !(moduleConfig.canned_message.updown1_enabled || moduleConfig.canned_message.rotary1_enabled) || + !moduleConfig.canned_message.enabled) { + powerFSM.trigger(EVENT_PRESS); + } +#endif +#if defined(ARCH_PORTDUINO) + if ((settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) && + (settingsMap[user] != moduleConfig.canned_message.inputbroker_pin_press) || + !moduleConfig.canned_message.enabled) { + powerFSM.trigger(EVENT_PRESS); + } +#endif + break; + } + + case BUTTON_EVENT_DOUBLE_PRESSED: { + LOG_BUTTON("Double press!\n"); +#if defined(USE_EINK) && defined(PIN_EINK_EN) + digitalWrite(PIN_EINK_EN, digitalRead(PIN_EINK_EN) == LOW); +#endif + service.refreshLocalMeshNode(); + service.sendNetworkPing(NODENUM_BROADCAST, true); + if (screen) + screen->print("Sent ad-hoc ping\n"); + break; + } + + case BUTTON_EVENT_MULTI_PRESSED: { + LOG_BUTTON("Multi press!\n"); + if (!config.device.disable_triple_click && (gps != nullptr)) { + gps->toggleGpsMode(); + if (screen) + screen->forceDisplay(); + } + break; + } + + case BUTTON_EVENT_LONG_PRESSED: { + LOG_BUTTON("Long press!\n"); + powerFSM.trigger(EVENT_PRESS); + if (screen) + screen->startShutdownScreen(); + playBeep(); + break; + } + + // Do actual shutdown when button released, otherwise the button release + // may wake the board immediatedly. + case BUTTON_EVENT_LONG_RELEASED: { + LOG_INFO("Shutdown from long press\n"); + playShutdownMelody(); + delay(3000); + power->shutdown(); + break; + } + case BUTTON_EVENT_TOUCH_PRESSED: { + LOG_BUTTON("Touch press!\n"); + if (screen) + screen->forceDisplay(); + break; + } + default: + break; + } + btnEvent = BUTTON_EVENT_NONE; + } + + return 50; +} + +/** + * Watch a GPIO and if we get an IRQ, wake the main thread. + * Use to add wake on button press + */ +void ButtonThread::wakeOnIrq(int irq, int mode) +{ + attachInterrupt( + irq, + [] { + BaseType_t higherWake = 0; + mainDelay.interruptFromISR(&higherWake); + }, + FALLING); +} + +void ButtonThread::userButtonPressedLongStart() +{ + if (millis() > c_holdOffTime) { + btnEvent = BUTTON_EVENT_LONG_PRESSED; + } +} + +void ButtonThread::userButtonPressedLongStop() +{ + if (millis() > c_holdOffTime) { + btnEvent = BUTTON_EVENT_LONG_RELEASED; + } +} diff --git a/src/ButtonThread.h b/src/ButtonThread.h index 5f68aa5b68..554c1f0c46 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -1,34 +1,29 @@ -#include "PowerFSM.h" -#include "RadioLibInterface.h" -#include "buzz.h" +#pragma once + +#include "OneButton.h" #include "concurrency/OSThread.h" #include "configuration.h" -#include "graphics/Screen.h" -#include "main.h" -#include "modules/ExternalNotificationModule.h" -#include "power.h" -#include - -namespace concurrency -{ -/** - * Watch a GPIO and if we get an IRQ, wake the main thread. - * Use to add wake on button press - */ -void wakeOnIrq(int irq, int mode) -{ - attachInterrupt( - irq, - [] { - BaseType_t higherWake = 0; - mainDelay.interruptFromISR(&higherWake); - }, - FALLING); -} class ButtonThread : public concurrency::OSThread { -// Prepare for button presses + public: + static const uint32_t c_longPressTime = 5000; // shutdown after 5s + static const uint32_t c_holdOffTime = 30000; // hold off 30s after boot + + enum ButtonEventType { + BUTTON_EVENT_NONE, + BUTTON_EVENT_PRESSED, + BUTTON_EVENT_DOUBLE_PRESSED, + BUTTON_EVENT_MULTI_PRESSED, + BUTTON_EVENT_LONG_PRESSED, + BUTTON_EVENT_LONG_RELEASED, + BUTTON_EVENT_TOUCH_PRESSED + }; + + ButtonThread(); + int32_t runOnce() override; + + private: #ifdef BUTTON_PIN OneButton userButton; #endif @@ -38,198 +33,20 @@ class ButtonThread : public concurrency::OSThread #ifdef BUTTON_PIN_TOUCH OneButton userButtonTouch; #endif -#if defined(ARCH_RASPBERRY_PI) +#if defined(ARCH_PORTDUINO) OneButton userButton; #endif - static bool shutdown_on_long_stop; - - public: - static uint32_t longPressTime; - - // callback returns the period for the next callback invocation (or 0 if we should no longer be called) - ButtonThread() : OSThread("Button") - { -#if defined(ARCH_RASPBERRY_PI) || defined(BUTTON_PIN) -#if defined(ARCH_RASPBERRY_PI) - if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) - userButton = OneButton(settingsMap[user], true, true); -#elif defined(BUTTON_PIN) - - userButton = OneButton(config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN, true, true); -#endif -#ifdef INPUT_PULLUP_SENSE - // Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did - pinMode(config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN, INPUT_PULLUP_SENSE); -#endif - userButton.attachClick(userButtonPressed); - userButton.setClickMs(300); - userButton.attachDuringLongPress(userButtonPressedLong); - userButton.attachDoubleClick(userButtonDoublePressed); - userButton.attachMultiClick(userButtonMultiPressed); - userButton.attachLongPressStart(userButtonPressedLongStart); - userButton.attachLongPressStop(userButtonPressedLongStop); -#if defined(ARCH_RASPBERRY_PI) - if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) - wakeOnIrq(settingsMap[user], FALLING); -#else - wakeOnIrq(config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN, FALLING); -#endif -#endif -#ifdef BUTTON_PIN_ALT - userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true); -#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.attachDuringLongPress(userButtonPressedLong); - userButtonAlt.attachDoubleClick(userButtonDoublePressed); - userButtonAlt.attachLongPressStart(userButtonPressedLongStart); - userButtonAlt.attachLongPressStop(userButtonPressedLongStop); - wakeOnIrq(BUTTON_PIN_ALT, FALLING); -#endif - -#ifdef BUTTON_PIN_TOUCH - userButtonTouch = OneButton(BUTTON_PIN_TOUCH, true, true); - userButtonTouch.attachClick(touchPressed); - wakeOnIrq(BUTTON_PIN_TOUCH, FALLING); -#endif - } - - protected: - /// If the button is pressed we suppress CPU sleep until release - int32_t runOnce() override - { - canSleep = true; // Assume we should not keep the board awake - -#if defined(BUTTON_PIN) - userButton.tick(); - canSleep &= userButton.isIdle(); -#elif defined(ARCH_RASPBERRY_PI) - if (settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) { - userButton.tick(); - canSleep &= userButton.isIdle(); - } -#endif -#ifdef BUTTON_PIN_ALT - userButtonAlt.tick(); - canSleep &= userButtonAlt.isIdle(); -#endif -#ifdef BUTTON_PIN_TOUCH - userButtonTouch.tick(); - canSleep &= userButtonTouch.isIdle(); -#endif - // if (!canSleep) LOG_DEBUG("Suppressing sleep!\n"); - // else LOG_DEBUG("sleep ok\n"); - - return 50; - } - - private: - static void touchPressed() - { - screen->forceDisplay(); - LOG_DEBUG("touch press!\n"); - } - - static void userButtonPressed() - { - // LOG_DEBUG("press!\n"); -#ifdef BUTTON_PIN - if (((config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN) != - moduleConfig.canned_message.inputbroker_pin_press) || - !moduleConfig.canned_message.enabled) { - powerFSM.trigger(EVENT_PRESS); - } -#endif -#if defined(ARCH_RASPBERRY_PI) - if ((settingsMap.count(user) != 0 && settingsMap[user] != RADIOLIB_NC) && - (settingsMap[user] != moduleConfig.canned_message.inputbroker_pin_press) || - !moduleConfig.canned_message.enabled) { - powerFSM.trigger(EVENT_PRESS); - } -#endif - } - static void userButtonPressedLong() - { - // LOG_DEBUG("Long press!\n"); - // If user button is held down for 5 seconds, shutdown the device. - if ((millis() - longPressTime > 5000) && (longPressTime > 0)) { -#if defined(ARCH_NRF52) || defined(ARCH_ESP32) - // Do actual shutdown when button released, otherwise the button release - // may wake the board immediatedly. - if ((!shutdown_on_long_stop) && (millis() > 30 * 1000)) { - screen->startShutdownScreen(); - LOG_INFO("Shutdown from long press"); - playBeep(); -#ifdef PIN_LED1 - ledOff(PIN_LED1); -#endif -#ifdef PIN_LED2 - ledOff(PIN_LED2); -#endif -#ifdef PIN_LED3 - ledOff(PIN_LED3); -#endif - shutdown_on_long_stop = true; - } -#endif - } else { - // LOG_DEBUG("Long press %u\n", (millis() - longPressTime)); - } - } - static void userButtonDoublePressed() - { -#if defined(USE_EINK) && defined(PIN_EINK_EN) - digitalWrite(PIN_EINK_EN, digitalRead(PIN_EINK_EN) == LOW); -#endif - screen->print("Sent ad-hoc ping\n"); - service.refreshLocalMeshNode(); - service.sendNetworkPing(NODENUM_BROADCAST, true); - } - - static void userButtonMultiPressed() - { - if (!config.device.disable_triple_click && (gps != nullptr)) { - config.position.gps_enabled = !(config.position.gps_enabled); - if (config.position.gps_enabled) { - LOG_DEBUG("Flag set to true to restore power\n"); - gps->enable(); + // set during IRQ + static volatile ButtonEventType btnEvent; - } else { - LOG_DEBUG("Flag set to false for gps power\n"); - gps->disable(); - } - } - } + static void wakeOnIrq(int irq, int mode); - static void userButtonPressedLongStart() - { -#ifdef T_DECK - // False positive long-press triggered on T-Deck with i2s audio, so short circuit - if (moduleConfig.external_notification.enabled && (externalNotificationModule->nagCycleCutoff != UINT32_MAX)) { - return; - } -#endif - if (millis() > 30 * 1000) { - LOG_DEBUG("Long press start!\n"); - longPressTime = millis(); - } - } - - static void userButtonPressedLongStop() - { - if (millis() > 30 * 1000) { - LOG_DEBUG("Long press stop!\n"); - longPressTime = 0; - if (shutdown_on_long_stop) { - playShutdownMelody(); - delay(3000); - power->shutdown(); - } - } - } + // IRQ callbacks + static void touchPressed() { btnEvent = BUTTON_EVENT_TOUCH_PRESSED; } + static void userButtonPressed() { btnEvent = BUTTON_EVENT_PRESSED; } + static void userButtonDoublePressed() { btnEvent = BUTTON_EVENT_DOUBLE_PRESSED; } + static void userButtonMultiPressed() { btnEvent = BUTTON_EVENT_MULTI_PRESSED; } + static void userButtonPressedLongStart(); + static void userButtonPressedLongStop(); }; - -} // namespace concurrency diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index 59ce043bcb..f0686b811f 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -28,7 +28,7 @@ #define DEBUG_PORT (*console) // Serial debug port #ifdef USE_SEGGER -#define DEBUG_PORT +// #undef DEBUG_PORT #define LOG_DEBUG(...) SEGGER_RTT_printf(0, __VA_ARGS__) #define LOG_INFO(...) SEGGER_RTT_printf(0, __VA_ARGS__) #define LOG_WARN(...) SEGGER_RTT_printf(0, __VA_ARGS__) diff --git a/src/Observer.h b/src/Observer.h index 555dcd1e9a..6e1ec44c81 100644 --- a/src/Observer.h +++ b/src/Observer.h @@ -10,12 +10,12 @@ template class Observable; */ template class Observer { - std::list *> observed; + std::list *> observables; public: virtual ~Observer(); - /// Stop watching the obserable + /// Stop watching the observable void unobserve(Observable *o); /// Start watching a specified observable @@ -86,21 +86,21 @@ template class Observable template Observer::~Observer() { - for (typename std::list *>::const_iterator iterator = observed.begin(); iterator != observed.end(); + for (typename std::list *>::const_iterator iterator = observables.begin(); iterator != observables.end(); ++iterator) { (*iterator)->removeObserver(this); } - observed.clear(); + observables.clear(); } template void Observer::unobserve(Observable *o) { o->removeObserver(this); - observed.remove(o); + observables.remove(o); } template void Observer::observe(Observable *o) { - observed.push_back(o); + observables.push_back(o); o->addObserver(this); -} +} \ No newline at end of file diff --git a/src/Power.cpp b/src/Power.cpp index 173c0ba998..468c58880c 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -127,8 +127,6 @@ class AnalogBatteryLevel : public HasBatteryLevel { /** * Battery state of charge, from 0 to 100 or -1 for unknown - * - * FIXME - use a lipo lookup table, the current % full is super wrong */ virtual int getBatteryPercent() override { @@ -137,13 +135,32 @@ class AnalogBatteryLevel : public HasBatteryLevel if (v < noBatVolt) return -1; // If voltage is super low assume no battery installed -#ifdef ARCH_ESP32 +#ifdef NO_BATTERY_LEVEL_ON_CHARGE // This does not work on a RAK4631 with battery connected if (v > chargingVolt) return 0; // While charging we can't report % full on the battery #endif - - return clamp((int)(100 * (v - emptyVolt) / (fullVolt - emptyVolt)), 0, 100); + /** + * @brief Battery voltage lookup table interpolation to obtain a more + * precise percentage rather than the old proportional one. + * @author Gabriele Russo + * @date 06/02/2024 + */ + float battery_SOC = 0.0; + uint16_t voltage = v / NUM_CELLS; // single cell voltage (average) + for (int i = 0; i < NUM_OCV_POINTS; i++) { + if (OCV[i] <= voltage) { + if (i == 0) { + battery_SOC = 100.0; // 100% full + } else { + // interpolate between OCV[i] and OCV[i-1] + battery_SOC = (float)100.0 / (NUM_OCV_POINTS - 1.0) * + (NUM_OCV_POINTS - 1.0 - i + ((float)voltage - OCV[i]) / (OCV[i - 1] - OCV[i])); + } + break; + } + } + return clamp((int)(battery_SOC), 0, 100); } /** @@ -164,7 +181,8 @@ class AnalogBatteryLevel : public HasBatteryLevel #endif #ifndef BATTERY_SENSE_SAMPLES -#define BATTERY_SENSE_SAMPLES 30 +#define BATTERY_SENSE_SAMPLES \ + 15 // Set the number of samples, it has an effect of increasing sensitivity in complex electromagnetic environment. #endif #ifdef BATTERY_PIN @@ -176,65 +194,109 @@ class AnalogBatteryLevel : public HasBatteryLevel if (millis() - last_read_time_ms > min_read_interval) { last_read_time_ms = millis(); - // Set the number of samples, it has an effect of increasing sensitivity, especially in complex electromagnetic - // environment. uint32_t raw = 0; -#ifdef ARCH_ESP32 -#ifndef BAT_MEASURE_ADC_UNIT // ADC1 -#ifdef ADC_CTRL - if (heltec_version == 5) { - pinMode(ADC_CTRL, OUTPUT); - digitalWrite(ADC_CTRL, HIGH); - delay(10); + float scaled = 0; + +#ifdef ARCH_ESP32 // ADC block for espressif platforms + raw = espAdcRead(); + scaled = esp_adc_cal_raw_to_voltage(raw, adc_characs); + scaled *= operativeAdcMultiplier; +#else // block for all other platforms + for (uint32_t i = 0; i < BATTERY_SENSE_SAMPLES; i++) { + raw += analogRead(BATTERY_PIN); } + raw = raw / BATTERY_SENSE_SAMPLES; + scaled = operativeAdcMultiplier * ((1000 * AREF_VOLTAGE) / pow(2, BATTERY_SENSE_RESOLUTION_BITS)) * raw; #endif - for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { - raw += adc1_get_raw(adc_channel); + last_read_value += (scaled - last_read_value) * 0.5; // Virtual LPF + // LOG_DEBUG("battery gpio %d raw val=%u scaled=%u filtered=%u\n", BATTERY_PIN, raw, (uint32_t)(scaled), (uint32_t) + // (last_read_value)); + } + return last_read_value; +#endif // BATTERY_PIN + return 0; + } + +#if defined(ARCH_ESP32) && !defined(HAS_PMU) && defined(BATTERY_PIN) + /** + * ESP32 specific function for getting calibrated ADC reads + */ + uint32_t espAdcRead() + { + + uint32_t raw = 0; + uint8_t raw_c = 0; // raw reading counter + +#ifndef BAT_MEASURE_ADC_UNIT // ADC1 +#ifdef ADC_CTRL // enable adc voltage divider when we need to read + pinMode(ADC_CTRL, OUTPUT); + digitalWrite(ADC_CTRL, ADC_CTRL_ENABLED); + delay(10); +#endif + for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { + int val_ = adc1_get_raw(adc_channel); + if (val_ >= 0) { // save only valid readings + raw += val_; + raw_c++; } + // delayMicroseconds(100); + } +#ifdef ADC_CTRL // disable adc voltage divider when we need to read + digitalWrite(ADC_CTRL, !ADC_CTRL_ENABLED); +#endif +#else // ADC2 #ifdef ADC_CTRL - if (heltec_version == 5) { - digitalWrite(ADC_CTRL, LOW); - } +#if defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0) + pinMode(ADC_CTRL, OUTPUT); + digitalWrite(ADC_CTRL, LOW); // ACTIVE LOW + delay(10); #endif -#else // ADC2 - int32_t adc_buf = 0; - for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { - // ADC2 wifi bug workaround, see - // https://github.com/espressif/arduino-esp32/issues/102 - WRITE_PERI_REG(SENS_SAR_READ_CTRL2_REG, RTC_reg_b); - SET_PERI_REG_MASK(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_DATA_INV); - adc2_get_raw(adc_channel, ADC_WIDTH_BIT_12, &adc_buf); +#endif // End ADC_CTRL + +#ifdef CONFIG_IDF_TARGET_ESP32S3 // ESP32S3 + // ADC2 wifi bug workaround not required, breaks compile + // On ESP32S3, ADC2 can take turns with Wifi (?) + + int32_t adc_buf; + esp_err_t read_result; + + // Multiple samples + for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { + adc_buf = 0; + read_result = -1; + + read_result = adc2_get_raw(adc_channel, ADC_WIDTH_BIT_12, &adc_buf); + if (read_result == ESP_OK) { raw += adc_buf; + raw_c++; // Count valid samples + } else { + LOG_DEBUG("An attempt to sample ADC2 failed\n"); } + } + +#else // Other ESP32 + int32_t adc_buf = 0; + for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { + // ADC2 wifi bug workaround, see + // https://github.com/espressif/arduino-esp32/issues/102 + WRITE_PERI_REG(SENS_SAR_READ_CTRL2_REG, RTC_reg_b); + SET_PERI_REG_MASK(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_DATA_INV); + adc2_get_raw(adc_channel, ADC_WIDTH_BIT_12, &adc_buf); + raw += adc_buf; + raw_c++; + } #endif // BAT_MEASURE_ADC_UNIT -#else // !ARCH_ESP32 - for (uint32_t i = 0; i < BATTERY_SENSE_SAMPLES; i++) { - raw += analogRead(BATTERY_PIN); - } + +#ifdef ADC_CTRL +#if defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0) + digitalWrite(ADC_CTRL, HIGH); #endif - raw = raw / BATTERY_SENSE_SAMPLES; - float scaled; -#ifdef ARCH_ESP32 - scaled = esp_adc_cal_raw_to_voltage(raw, adc_characs); - scaled *= operativeAdcMultiplier; -#else -#ifndef VBAT_RAW_TO_SCALED - scaled = 1000.0 * operativeAdcMultiplier * (AREF_VOLTAGE / 1024.0) * raw; -#else - scaled = VBAT_RAW_TO_SCALED(raw); // defined in variant.h -#endif // VBAT RAW TO SCALED -#endif // ARCH_ESP32 - // LOG_DEBUG("battery gpio %d raw val=%u scaled=%u\n", BATTERY_PIN, raw, (uint32_t)(scaled)); +#endif // End ADC_CTRL - last_read_value = scaled; - return scaled; - } else { - return last_read_value; - } -#else - return 0; -#endif // BATTERY_PIN +#endif // End BAT_MEASURE_ADC_UNIT + return (raw / (raw_c < 1 ? 1 : raw_c)); } +#endif /** * return true if there is a battery installed in this unit @@ -266,22 +328,14 @@ class AnalogBatteryLevel : public HasBatteryLevel /// If we see a battery voltage higher than physics allows - assume charger is pumping /// in power -#ifndef BAT_FULLVOLT -#define BAT_FULLVOLT 4200 -#endif -#ifndef BAT_EMPTYVOLT -#define BAT_EMPTYVOLT 3270 -#endif -#ifndef BAT_CHARGINGVOLT -#define BAT_CHARGINGVOLT 4210 -#endif -#ifndef BAT_NOBATVOLT -#define BAT_NOBATVOLT 2230 -#endif - - /// For heltecs with no battery connected, the measured voltage is 2204, so raising to 2230 from 2100 - const float fullVolt = BAT_FULLVOLT, emptyVolt = BAT_EMPTYVOLT, chargingVolt = BAT_CHARGINGVOLT, noBatVolt = BAT_NOBATVOLT; - float last_read_value = 0.0; + /// For heltecs with no battery connected, the measured voltage is 2204, so + // need to be higher than that, in this case is 2500mV (3000-500) + const uint16_t OCV[NUM_OCV_POINTS] = {OCV_ARRAY}; + const float chargingVolt = (OCV[0] + 10) * NUM_CELLS; + const float noBatVolt = (OCV[NUM_OCV_POINTS - 1] - 500) * NUM_CELLS; + // Start value from minimum voltage for the filter to not start from 0 + // that could trigger some events. + float last_read_value = (OCV[NUM_OCV_POINTS - 1] * NUM_CELLS); uint32_t last_read_time_ms = 0; #if defined(HAS_TELEMETRY) && (HAS_TELEMETRY == 1) && !defined(ARCH_PORTDUINO) @@ -358,8 +412,11 @@ bool Power::analogInit() adc1_config_channel_atten(adc_channel, atten); #else // ADC2 adc2_config_channel_atten(adc_channel, atten); +#ifndef CONFIG_IDF_TARGET_ESP32S3 // ADC2 wifi bug workaround + // Not required with ESP32S3, breaks compile RTC_reg_b = READ_PERI_REG(SENS_SAR_READ_CTRL2_REG); +#endif #endif // calibrate ADC esp_adc_cal_value_t val_type = esp_adc_cal_characterize(unit, atten, width, DEFAULT_VREF, adc_characs); @@ -368,13 +425,16 @@ bool Power::analogInit() LOG_INFO("ADCmod: ADC characterization based on Two Point values stored in eFuse\n"); } else if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) { LOG_INFO("ADCmod: ADC characterization based on reference voltage stored in eFuse\n"); - } else { - LOG_INFO("ADCmod: ADC characterization based on default reference voltage\n"); } -#if defined(HELTEC_V3) || defined(HELTEC_WSL_V3) - pinMode(37, OUTPUT); // needed for P channel mosfet to work - digitalWrite(37, LOW); +#ifdef CONFIG_IDF_TARGET_ESP32S3 + // ESP32S3 + else if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP_FIT) { + LOG_INFO("ADCmod: ADC Characterization based on Two Point values and fitting curve coefficients stored in eFuse\n"); + } #endif + else { + LOG_INFO("ADCmod: ADC characterization based on default reference voltage\n"); + } #endif // ARCH_ESP32 #ifdef ARCH_NRF52 @@ -383,11 +443,12 @@ bool Power::analogInit() #else analogReference(AR_INTERNAL); // 3.6V #endif - analogReadResolution(BATTERY_SENSE_RESOLUTION_BITS); // Default of 12 is not very linear. Recommended to use 10 or 11 - // depending on needed resolution. - #endif // ARCH_NRF52 +#ifndef ARCH_ESP32 + analogReadResolution(BATTERY_SENSE_RESOLUTION_BITS); +#endif + batteryLevel = &analogLevel; return true; #else @@ -402,11 +463,8 @@ bool Power::analogInit() */ bool Power::setup() { - bool found = axpChipInit(); + bool found = axpChipInit() || analogInit(); - if (!found) { - found = analogInit(); - } enabled = found; low_voltage_counter = 0; @@ -457,11 +515,11 @@ void Power::readPowerStatus() batteryChargePercent = batteryLevel->getBatteryPercent(); } else { // If the AXP192 returns a percentage less than 0, the feature is either not supported or there is an error - // In that case, we compute an estimate of the charge percent based on maximum and minimum voltages defined in - // power.h - batteryChargePercent = - clamp((int)(((batteryVoltageMv - BAT_MILLIVOLTS_EMPTY) * 1e2) / (BAT_MILLIVOLTS_FULL - BAT_MILLIVOLTS_EMPTY)), - 0, 100); + // In that case, we compute an estimate of the charge percent based on open circuite voltage table defined + // in power.h + batteryChargePercent = clamp((int)(((batteryVoltageMv - (OCV[NUM_OCV_POINTS - 1] * NUM_CELLS)) * 1e2) / + ((OCV[0] * NUM_CELLS) - (OCV[NUM_OCV_POINTS - 1] * NUM_CELLS))), + 0, 100); } } @@ -526,10 +584,11 @@ void Power::readPowerStatus() #endif - // If we have a battery at all and it is less than 10% full, force deep sleep if we have more than 10 low readings in - // a row + // 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 (powerStatus2.getHasBattery() && !powerStatus2.getHasUSB()) { - if (batteryLevel->getBattVoltage() < MIN_BAT_MILLIVOLTS) { + if (batteryLevel->getBattVoltage() < OCV[NUM_OCV_POINTS - 1]) { low_voltage_counter++; LOG_DEBUG("Low voltage counter: %d/10\n", low_voltage_counter); if (low_voltage_counter > 10) { diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index c64599ce69..bac3899bba 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -246,6 +246,7 @@ void PowerFSM_setup() { bool isRouter = (config.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER ? 1 : 0); bool isTrackerOrSensor = config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER || + config.device.role == meshtastic_Config_DeviceConfig_Role_TAK_TRACKER || config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR; bool hasPower = isPowered(); diff --git a/src/PowerFSMThread.h b/src/PowerFSMThread.h index b757f3abb8..584c955aa1 100644 --- a/src/PowerFSMThread.h +++ b/src/PowerFSMThread.h @@ -21,7 +21,7 @@ class PowerFSMThread : public OSThread /// If we are in power state we force the CPU to wake every 10ms to check for serial characters (we don't yet wake /// cpu for serial rx - FIXME) - const auto state = powerFSM.getState(); + const State *state = powerFSM.getState(); canSleep = (state != &statePOWER) && (state != &stateSERIAL); if (powerStatus->getHasUSB()) { diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index 7d2280acc0..edea1cb806 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -10,6 +10,10 @@ #include #include +#ifdef ARCH_PORTDUINO +#include "platform/portduino/PortduinoGlue.h" +#endif + /** * A printer that doesn't go anywhere */ @@ -68,7 +72,15 @@ size_t RedirectablePrint::vprintf(const char *format, va_list arg) size_t RedirectablePrint::log(const char *logLevel, const char *format, ...) { - if (moduleConfig.serial.override_console_serial_port && strcmp(logLevel, "DEBUG") == 0) { +#ifdef ARCH_PORTDUINO + if (settingsMap[logoutputlevel] < level_debug && strcmp(logLevel, MESHTASTIC_LOG_LEVEL_DEBUG) == 0) + return 0; + else if (settingsMap[logoutputlevel] < level_info && strcmp(logLevel, MESHTASTIC_LOG_LEVEL_INFO) == 0) + return 0; + else if (settingsMap[logoutputlevel] < level_warn && strcmp(logLevel, MESHTASTIC_LOG_LEVEL_WARN) == 0) + return 0; +#endif + if (moduleConfig.serial.override_console_serial_port && strcmp(logLevel, MESHTASTIC_LOG_LEVEL_DEBUG) == 0) { return 0; } size_t r = 0; @@ -99,10 +111,17 @@ size_t RedirectablePrint::log(const char *logLevel, const char *format, ...) int hour = hms / SEC_PER_HOUR; int min = (hms % SEC_PER_HOUR) / SEC_PER_MIN; int sec = (hms % SEC_PER_HOUR) % SEC_PER_MIN; // or hms % SEC_PER_MIN - +#ifdef ARCH_PORTDUINO + r += ::printf("%s | %02d:%02d:%02d %u ", logLevel, hour, min, sec, millis() / 1000); +#else r += printf("%s | %02d:%02d:%02d %u ", logLevel, hour, min, sec, millis() / 1000); +#endif } else +#ifdef ARCH_PORTDUINO + r += ::printf("%s | ??:??:?? %u ", logLevel, millis() / 1000); +#else r += printf("%s | ??:??:?? %u ", logLevel, millis() / 1000); +#endif auto thread = concurrency::OSThread::currentThread; if (thread) { diff --git a/src/configuration.h b/src/configuration.h index cb7ee218be..d8b0dba5f4 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -142,8 +142,9 @@ along with this program. If not, see . // ----------------------------------------------------------------------------- // GPS // ----------------------------------------------------------------------------- - +#ifndef GPS_BAUDRATE #define GPS_BAUDRATE 9600 +#endif #ifndef GPS_THREAD_INTERVAL #define GPS_THREAD_INTERVAL 200 @@ -161,6 +162,17 @@ along with this program. If not, see . /* Step #3: mop up with disabled values for HAS_ options not handled by the above two */ +// ----------------------------------------------------------------------------- +// GPS +// ----------------------------------------------------------------------------- + +#ifndef GPS_BAUDRATE +#define GPS_BAUDRATE 9600 +#endif +#ifndef GPS_THREAD_INTERVAL +#define GPS_THREAD_INTERVAL 100 +#endif + #ifndef HAS_WIFI #define HAS_WIFI 0 #endif diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 763112fa3b..4a968fcdfd 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -2,7 +2,7 @@ #include "concurrency/LockGuard.h" #include "configuration.h" -#if defined(ARCH_RASPBERRY_PI) +#if defined(ARCH_PORTDUINO) #include "linux/LinuxHardwareI2C.h" #endif #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 68a0818829..03bda2cd95 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -16,7 +16,7 @@ #define GPS_RESET_MODE HIGH #endif -#if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(ARCH_ESP32) || defined(ARCH_RASPBERRY_PI) +#if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(ARCH_ESP32) || defined(ARCH_PORTDUINO) HardwareSerial *GPS::_serial_gps = &Serial1; #else HardwareSerial *GPS::_serial_gps = NULL; @@ -251,17 +251,9 @@ int GPS::getACK(uint8_t *buffer, uint16_t size, uint8_t requestedClass, uint8_t bool GPS::setup() { int msglen = 0; - bool isProblematicGPS = false; if (!didSerialInit) { #if !defined(GPS_UC6580) -#ifdef HAS_PMU - // The T-Beam 1.2 has issues with the GPS - if (HW_VENDOR == meshtastic_HardwareModel_TBEAM && PMU->getChipModel() == XPOWERS_AXP2101) { - gnssModel = GNSS_MODEL_UBLOX; - isProblematicGPS = true; - } -#endif #if defined(RAK4630) && defined(PIN_3V3_EN) // If we are using the RAK4630 and we have no other peripherals on the I2C bus or module interest in 3V3_S, @@ -334,125 +326,269 @@ bool GPS::setup() // Also we need SBAS for better accuracy and extra features // ToDo: Dynamic configure GNSS systems depending of LoRa region - if (strncmp(info.hwVersion, "00040007", 8) != - 0) { // The original ublox 6 is GPS only and doesn't support the UBX-CFG-GNSS message - if (strncmp(info.hwVersion, "00070000", 8) == 0) { // Max7 seems to only support GPS *or* GLONASS - LOG_DEBUG("Setting GPS+SBAS\n"); - msglen = makeUBXPacket(0x06, 0x3e, sizeof(_message_GNSS_7), _message_GNSS_7); - _serial_gps->write(UBXscratch, msglen); - } else { - msglen = makeUBXPacket(0x06, 0x3e, sizeof(_message_GNSS), _message_GNSS); - _serial_gps->write(UBXscratch, msglen); - } + if (strncmp(info.hwVersion, "000A0000", 8) != 0) { + if (strncmp(info.hwVersion, "00040007", 8) != 0) { + // The original ublox Neo-6 is GPS only and doesn't support the UBX-CFG-GNSS message + // Max7 seems to only support GPS *or* GLONASS + // Neo-7 is supposed to support GPS *and* GLONASS but NAKs the CFG-GNSS command to do it + // So treat all the u-blox 7 series as GPS only + // M8 can support 3 constallations at once so turn on GPS, GLONASS and Galileo (or BeiDou) - if (getACK(0x06, 0x3e, 800) == GNSS_RESPONSE_NAK) { - // It's not critical if the module doesn't acknowledge this configuration. - LOG_INFO("Unable to reconfigure GNSS - defaults maintained. Is this module GPS-only?\n"); - } else { if (strncmp(info.hwVersion, "00070000", 8) == 0) { - LOG_INFO("GNSS configured for GPS+SBAS. Pause for 0.75s before sending next command.\n"); + LOG_DEBUG("Setting GPS+SBAS\n"); + msglen = makeUBXPacket(0x06, 0x3e, sizeof(_message_GNSS_7), _message_GNSS_7); + _serial_gps->write(UBXscratch, msglen); } else { - LOG_INFO("GNSS configured for GPS+SBAS+GLONASS. Pause for 0.75s before sending next command.\n"); + msglen = makeUBXPacket(0x06, 0x3e, sizeof(_message_GNSS_8), _message_GNSS_8); + _serial_gps->write(UBXscratch, msglen); } - // Documentation say, we need wait atleast 0.5s after reconfiguration of GNSS module, before sending next - // commands - delay(750); - } - } - - msglen = makeUBXPacket(0x06, 0x39, sizeof(_message_JAM), _message_JAM); - _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x39, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to enable interference resistance.\n"); - } - msglen = makeUBXPacket(0x06, 0x23, sizeof(_message_NAVX5), _message_NAVX5); - _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x23, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to configure extra settings.\n"); - } + if (getACK(0x06, 0x3e, 800) == GNSS_RESPONSE_NAK) { + // It's not critical if the module doesn't acknowledge this configuration. + LOG_INFO("Unable to reconfigure GNSS - defaults maintained. Is this module GPS-only?\n"); + } else { + if (strncmp(info.hwVersion, "00070000", 8) == 0) { + LOG_INFO("GNSS configured for GPS+SBAS. Pause for 0.75s before sending next command.\n"); + } else { + LOG_INFO( + "GNSS configured for GPS+SBAS+GLONASS+Galileo. Pause for 0.75s before sending next command.\n"); + } + // Documentation say, we need wait atleast 0.5s after reconfiguration of GNSS module, before sending next + // commands for the M8 it tends to be more... 1 sec should be enough ;>) + delay(1000); + } + } + // Disable Text Info messages + msglen = makeUBXPacket(0x06, 0x02, sizeof(_message_DISABLE_TXT_INFO), _message_DISABLE_TXT_INFO); + clearBuffer(); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x02, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to disable text info messages.\n"); + } + // ToDo add M10 tests for below + if (strncmp(info.hwVersion, "00080000", 8) == 0) { + msglen = makeUBXPacket(0x06, 0x39, sizeof(_message_JAM_8), _message_JAM_8); + clearBuffer(); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x39, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable interference resistance.\n"); + } - // ublox-M10S can be compatible with UBLOX traditional protocol, so the following sentence settings are also valid + msglen = makeUBXPacket(0x06, 0x23, sizeof(_message_NAVX5_8), _message_NAVX5_8); + clearBuffer(); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x23, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to configure NAVX5_8 settings.\n"); + } + } else { + msglen = makeUBXPacket(0x06, 0x39, sizeof(_message_JAM_6_7), _message_JAM_6_7); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x39, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable interference resistance.\n"); + } - msglen = makeUBXPacket(0x06, 0x08, sizeof(_message_1HZ), _message_1HZ); - _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x08, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to set GPS update rate.\n"); - } + msglen = makeUBXPacket(0x06, 0x23, sizeof(_message_NAVX5), _message_NAVX5); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x23, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to configure NAVX5 settings.\n"); + } + } + // Turn off unwanted NMEA messages, set update rate - msglen = makeUBXPacket(0x06, 0x01, sizeof(_message_GGL), _message_GGL); - _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x01, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to disable NMEA GGL.\n"); - } + msglen = makeUBXPacket(0x06, 0x08, sizeof(_message_1HZ), _message_1HZ); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x08, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to set GPS update rate.\n"); + } - msglen = makeUBXPacket(0x06, 0x01, sizeof(_message_GSA), _message_GSA); - _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x01, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to Enable NMEA GSA.\n"); - } + msglen = makeUBXPacket(0x06, 0x01, sizeof(_message_GLL), _message_GLL); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x01, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to disable NMEA GLL.\n"); + } - msglen = makeUBXPacket(0x06, 0x01, sizeof(_message_GSV), _message_GSV); - _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x01, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to disable NMEA GSV.\n"); - } + msglen = makeUBXPacket(0x06, 0x01, sizeof(_message_GSA), _message_GSA); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x01, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to Enable NMEA GSA.\n"); + } - msglen = makeUBXPacket(0x06, 0x01, sizeof(_message_VTG), _message_VTG); - _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x01, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to disable NMEA VTG.\n"); - } + msglen = makeUBXPacket(0x06, 0x01, sizeof(_message_GSV), _message_GSV); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x01, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to disable NMEA GSV.\n"); + } - msglen = makeUBXPacket(0x06, 0x01, sizeof(_message_RMC), _message_RMC); - _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x01, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to enable NMEA RMC.\n"); - } + msglen = makeUBXPacket(0x06, 0x01, sizeof(_message_VTG), _message_VTG); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x01, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to disable NMEA VTG.\n"); + } - msglen = makeUBXPacket(0x06, 0x01, sizeof(_message_GGA), _message_GGA); - _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x01, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to enable NMEA GGA.\n"); - } + msglen = makeUBXPacket(0x06, 0x01, sizeof(_message_RMC), _message_RMC); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x01, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable NMEA RMC.\n"); + } - if (uBloxProtocolVersion >= 18) { - msglen = makeUBXPacket(0x06, 0x86, sizeof(_message_PMS), _message_PMS); + msglen = makeUBXPacket(0x06, 0x01, sizeof(_message_GGA), _message_GGA); _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x86, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to enable powersaving for GPS.\n"); + if (getACK(0x06, 0x01, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable NMEA GGA.\n"); } - } else { - if (!(isProblematicGPS)) { - if (strncmp(info.hwVersion, "00040007", 8) == 0) { // This PSM mode has only been tested on this hardware - msglen = makeUBXPacket(0x06, 0x11, 0x2, _message_CFG_RXM_PSM); + + if (uBloxProtocolVersion >= 18) { + msglen = makeUBXPacket(0x06, 0x86, sizeof(_message_PMS), _message_PMS); + clearBuffer(); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x86, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable powersaving for GPS.\n"); + } + msglen = makeUBXPacket(0x06, 0x3B, sizeof(_message_CFG_PM2), _message_CFG_PM2); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x3B, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable powersaving details for GPS.\n"); + } + // For M8 we want to enable NMEA vserion 4.10 so we can see the additional sats. + if (strncmp(info.hwVersion, "00080000", 8) == 0) { + msglen = makeUBXPacket(0x06, 0x17, sizeof(_message_NMEA), _message_NMEA); + clearBuffer(); _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x11, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to enable powersaving mode for GPS.\n"); + if (getACK(0x06, 0x17, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable NMEA 4.10.\n"); + } + } + + } else { + if (strncmp(info.hwVersion, "00040007", 8) == 0) { // This PSM mode is only for Neo-6 + msglen = makeUBXPacket(0x06, 0x11, 0x2, _message_CFG_RXM_ECO); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x11, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable powersaving ECO mode for Neo-6.\n"); } - msglen = makeUBXPacket(0x06, 0x3B, 44, _message_CFG_PM2); + msglen = makeUBXPacket(0x06, 0x3B, sizeof(_message_CFG_PM2), _message_CFG_PM2); _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x3B, 300) != GNSS_RESPONSE_OK) { + if (getACK(0x06, 0x3B, 500) != GNSS_RESPONSE_OK) { LOG_WARN("Unable to enable powersaving details for GPS.\n"); } + msglen = makeUBXPacket(0x06, 0x01, sizeof(_message_AID), _message_AID); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x01, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to disable UBX-AID.\n"); + } } else { - msglen = makeUBXPacket(0x06, 0x11, 0x2, _message_CFG_RXM_ECO); + msglen = makeUBXPacket(0x06, 0x11, 0x2, _message_CFG_RXM_PSM); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x11, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable powersaving mode for GPS.\n"); + } + + msglen = makeUBXPacket(0x06, 0x3B, sizeof(_message_CFG_PM2), _message_CFG_PM2); _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x11, 300) != GNSS_RESPONSE_OK) { - LOG_WARN("Unable to enable powersaving ECO mode for GPS.\n"); + if (getACK(0x06, 0x3B, 500) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable powersaving details for GPS.\n"); } } } - } - // The T-beam 1.2 has issues. - if (!(isProblematicGPS)) { + msglen = makeUBXPacket(0x06, 0x09, sizeof(_message_SAVE), _message_SAVE); _serial_gps->write(UBXscratch, msglen); - if (getACK(0x06, 0x09, 300) != GNSS_RESPONSE_OK) { + if (getACK(0x06, 0x09, 2000) != GNSS_RESPONSE_OK) { LOG_WARN("Unable to save GNSS module configuration.\n"); } else { LOG_INFO("GNSS module configuration saved!\n"); } + } else { + // LOG_INFO("u-blox M10 hardware found.\n"); + delay(1000); + // First disable all NMEA messages in RAM layer + msglen = makeUBXPacket(0x06, 0x8A, sizeof(_message_VALSET_DISABLE_NMEA_RAM), _message_VALSET_DISABLE_NMEA_RAM); + clearBuffer(); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x8A, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to disable NMEA messages for M10 GPS RAM.\n"); + } + delay(250); + // Next disable unwanted NMEA messages in BBR layer + msglen = makeUBXPacket(0x06, 0x8A, sizeof(_message_VALSET_DISABLE_NMEA_BBR), _message_VALSET_DISABLE_NMEA_BBR); + clearBuffer(); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x8A, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to disable NMEA messages for M10 GPS BBR.\n"); + } + delay(250); + // Disable Info txt messages in RAM layer + msglen = + makeUBXPacket(0x06, 0x8A, sizeof(_message_VALSET_DISABLE_TXT_INFO_RAM), _message_VALSET_DISABLE_TXT_INFO_RAM); + clearBuffer(); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x8A, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to disable Info messages for M10 GPS RAM.\n"); + } + delay(250); + // Next disable Info txt messages in BBR layer + msglen = + makeUBXPacket(0x06, 0x8A, sizeof(_message_VALSET_DISABLE_TXT_INFO_BBR), _message_VALSET_DISABLE_TXT_INFO_BBR); + clearBuffer(); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x8A, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to disable Info messages for M10 GPS BBR.\n"); + } + // Do M10 configuration for Power Management. + + msglen = makeUBXPacket(0x06, 0x8A, sizeof(_message_VALSET_PM_RAM), _message_VALSET_PM_RAM); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x8A, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable powersaving for M10 GPS RAM.\n"); + } + msglen = makeUBXPacket(0x06, 0x8A, sizeof(_message_VALSET_PM_BBR), _message_VALSET_PM_BBR); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x8A, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable powersaving for M10 GPS BBR.\n"); + } + + delay(250); + msglen = makeUBXPacket(0x06, 0x8A, sizeof(_message_VALSET_ITFM_RAM), _message_VALSET_ITFM_RAM); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x8A, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable Jamming detection M10 GPS RAM.\n"); + } + msglen = makeUBXPacket(0x06, 0x8A, sizeof(_message_VALSET_ITFM_BBR), _message_VALSET_ITFM_BBR); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x8A, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable Jamming detection M10 GPS BBR.\n"); + } + + // Here is where the init commands should go to do further M10 initialization. + delay(250); + msglen = makeUBXPacket(0x06, 0x8A, sizeof(_message_VALSET_DISABLE_SBAS_RAM), _message_VALSET_DISABLE_SBAS_RAM); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x8A, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to disable SBAS M10 GPS RAM.\n"); + } + delay(750); // will cause a receiver restart so wait a bit + msglen = makeUBXPacket(0x06, 0x8A, sizeof(_message_VALSET_DISABLE_SBAS_BBR), _message_VALSET_DISABLE_SBAS_BBR); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x8A, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to disable SBAS M10 GPS BBR.\n"); + } + delay(750); // will cause a receiver restart so wait a bit + // Done with initialization, Now enable wanted NMEA messages in BBR layer so they will survive a periodic sleep. + msglen = makeUBXPacket(0x06, 0x8A, sizeof(_message_VALSET_ENABLE_NMEA_BBR), _message_VALSET_ENABLE_NMEA_BBR); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x8A, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable messages for M10 GPS BBR.\n"); + } + delay(250); + // Next enable wanted NMEA messages in RAM layer + msglen = makeUBXPacket(0x06, 0x8A, sizeof(_message_VALSET_ENABLE_NMEA_RAM), _message_VALSET_ENABLE_NMEA_RAM); + _serial_gps->write(UBXscratch, msglen); + if (getACK(0x06, 0x8A, 300) != GNSS_RESPONSE_OK) { + LOG_WARN("Unable to enable messages for M10 GPS RAM.\n"); + } + // As the M10 has no flash, the best we can do to preserve the config is to set it in RAM and BBR. + // BBR will survive a restart, and power off for a while, but modules with small backup + // batteries or super caps will not retain the config for a long power off time. } } didSerialInit = true; @@ -522,10 +658,17 @@ void GPS::setGPSPower(bool on, bool standbyOnly, uint32_t sleepTime) if (gnssModel == GNSS_MODEL_UBLOX) { uint8_t msglen; LOG_DEBUG("Sleep Time: %i\n", sleepTime); - for (int i = 0; i < 4; i++) { - gps->_message_PMREQ[0 + i] = sleepTime >> (i * 8); // Encode the sleep time in millis into the packet + if (strncmp(info.hwVersion, "000A0000", 8) != 0) { + for (int i = 0; i < 4; i++) { + gps->_message_PMREQ[0 + i] = sleepTime >> (i * 8); // Encode the sleep time in millis into the packet + } + msglen = gps->makeUBXPacket(0x02, 0x41, sizeof(_message_PMREQ), gps->_message_PMREQ); + } else { + for (int i = 0; i < 4; i++) { + gps->_message_PMREQ_10[4 + i] = sleepTime >> (i * 8); // Encode the sleep time in millis into the packet + } + msglen = gps->makeUBXPacket(0x02, 0x41, sizeof(_message_PMREQ_10), gps->_message_PMREQ_10); } - msglen = gps->makeUBXPacket(0x02, 0x41, 0x08, gps->_message_PMREQ); gps->_serial_gps->write(gps->UBXscratch, msglen); } } else { @@ -575,15 +718,20 @@ void GPS::setAwake(bool on) if ((int32_t)getSleepTime() - averageLockTime > 15 * 60 * 1000) { // 15 minutes is probably long enough to make a complete poweroff worth it. setGPSPower(on, false, getSleepTime() - averageLockTime); + return; } else if ((int32_t)getSleepTime() - averageLockTime > 10000) { // 10 seconds is enough for standby #ifdef GPS_UC6580 setGPSPower(on, false, getSleepTime() - averageLockTime); #else setGPSPower(on, true, getSleepTime() - averageLockTime); #endif - } else if (averageLockTime > 20000) { + return; + } + if (averageLockTime > 20000) { averageLockTime -= 1000; // eventually want to sleep again. } + if (on) + setGPSPower(true, true, 0); // make sure we don't have a fallthrough where GPS is stuck off } } @@ -591,11 +739,12 @@ void GPS::setAwake(bool on) */ uint32_t GPS::getWakeTime() const { - uint32_t t = config.position.gps_attempt_time; + uint32_t t = config.position.position_broadcast_secs; if (t == UINT32_MAX) return t; // already maxint - return t * 1000; + + return getConfiguredOrDefaultMs(t, default_broadcast_interval_secs); } /** Get how long we should sleep between aqusition attempts in msecs @@ -605,7 +754,7 @@ uint32_t GPS::getSleepTime() const uint32_t t = config.position.gps_update_interval; // We'll not need the GPS thread to wake up again after first acq. with fixed position. - if (!config.position.gps_enabled || config.position.fixed_position) + if (config.position.gps_mode != meshtastic_Config_PositionConfig_GpsMode_ENABLED || config.position.fixed_position) t = UINT32_MAX; // Sleep forever now if (t == UINT32_MAX) @@ -626,21 +775,24 @@ void GPS::publishUpdate() // Notify any status instances that are observing us const meshtastic::GPSStatus status = meshtastic::GPSStatus(hasValidLocation, isConnected(), isPowerSaving(), p); newStatus.notifyObservers(&status); - if (config.position.gps_enabled) + if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED) { positionModule->handleNewPosition(); + } } } int32_t GPS::runOnce() { if (!GPSInitFinished) { - if (!_serial_gps) + if (!_serial_gps || config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT) { + LOG_INFO("GPS set to not-present. Skipping probe.\n"); return disable(); + } if (!setup()) return 2000; // Setup failed, re-run in two seconds // We have now loaded our saved preferences from flash - if (config.position.gps_enabled == false) { + if (config.position.gps_mode != meshtastic_Config_PositionConfig_GpsMode_ENABLED) { return disable(); } // ONCE we will factory reset the GPS for bug #327 @@ -663,7 +815,7 @@ int32_t GPS::runOnce() // if we have received valid NMEA claim we are connected setConnected(); } else { - if ((config.position.gps_enabled == 1) && (gnssModel == GNSS_MODEL_UBLOX)) { + if ((config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED) && (gnssModel == GNSS_MODEL_UBLOX)) { // reset the GPS on next bootup if (devicestate.did_gps_reset && (millis() - lastWakeStartMsec > 60000) && !hasFlow()) { LOG_DEBUG("GPS is not communicating, trying factory reset on next bootup.\n"); @@ -676,7 +828,8 @@ int32_t GPS::runOnce() // At least one GPS has a bad habit of losing its mind from time to time if (rebootsSeen > 2) { rebootsSeen = 0; - gps->factoryReset(); + LOG_DEBUG("Would normally factoryReset()\n"); + // gps->factoryReset(); } // If we are overdue for an update, turn on the GPS and at least publish the current status @@ -875,9 +1028,9 @@ GnssModel_t GPS::probe(int serialSpeed) strncpy((char *)buffer, &(info.extension[i][4]), sizeof(buffer)); // LOG_DEBUG("GetModel:%s\n", (char *)buffer); if (strlen((char *)buffer)) { - LOG_INFO("UBlox GNSS init succeeded, using UBlox %s GNSS Module\n", (char *)buffer); + LOG_INFO("UBlox GNSS probe succeeded, using UBlox %s GNSS Module\n", (char *)buffer); } else { - LOG_INFO("UBlox GNSS init succeeded, using UBlox GNSS Module\n"); + LOG_INFO("UBlox GNSS probe succeeded, using UBlox GNSS Module\n"); } } else if (!strncmp(info.extension[i], "PROTVER", 7)) { char *ptr = nullptr; @@ -902,7 +1055,7 @@ GPS *GPS::createGps() int8_t _rx_gpio = config.position.rx_gpio; int8_t _tx_gpio = config.position.tx_gpio; int8_t _en_gpio = config.position.gps_en_gpio; -#if defined(HAS_GPS) && !defined(ARCH_ESP32) +#if HAS_GPS && !defined(ARCH_ESP32) _rx_gpio = 1; // We only specify GPS serial ports on ESP32. Otherwise, these are just flags. _tx_gpio = 1; #endif @@ -918,7 +1071,7 @@ GPS *GPS::createGps() if (!_en_gpio) _en_gpio = PIN_GPS_EN; #endif -#ifdef ARCH_RASPBERRY_PI +#ifdef ARCH_PORTDUINO if (!settingsMap[has_gps]) return nullptr; #endif @@ -1098,7 +1251,7 @@ bool GPS::lookForLocation() #ifndef TINYGPS_OPTION_NO_CUSTOM_FIELDS fixType = atoi(gsafixtype.value()); // will set to zero if no data - // LOG_DEBUG("FIX QUAL=%d, TYPE=%d\n", fixQual, fixType); + // LOG_DEBUG("FIX QUAL=%d, TYPE=%d\n", fixQual, fixType); #endif // check if GPS has an acceptable lock @@ -1115,6 +1268,10 @@ bool GPS::lookForLocation() reader.date.age(), reader.time.age()); #endif // GPS_EXTRAVERBOSE + // Is this a new point or are we re-reading the previous one? + if (!reader.location.isUpdated()) + return false; + // check if a complete GPS solution set is available for reading // tinyGPSDatum::age() also includes isValid() test // FIXME @@ -1127,10 +1284,6 @@ bool GPS::lookForLocation() return false; } - // Is this a new point or are we re-reading the previous one? - if (!reader.location.isUpdated()) - return false; - // We know the solution is fresh and valid, so just read the data auto loc = reader.location.value(); @@ -1281,3 +1434,16 @@ int32_t GPS::disable() return INT32_MAX; } + +void GPS::toggleGpsMode() +{ + if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED) { + config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_DISABLED; + LOG_DEBUG("Flag set to false for gps power. GpsMode: DISABLED\n"); + disable(); + } else if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_DISABLED) { + config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_ENABLED; + LOG_DEBUG("Flag set to true to restore power. GpsMode: ENABLED\n"); + enable(); + } +} \ No newline at end of file diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 4cbdae06b8..77e1d80426 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -70,7 +70,7 @@ class GPS : private concurrency::OSThread /** * hasValidLocation - indicates that the position variables contain a complete - * GPS location, valid and fresh (< gps_update_interval + gps_attempt_time) + * GPS location, valid and fresh (< gps_update_interval + position_broadcast_secs) */ bool hasValidLocation = false; // default to false, until we complete our first read @@ -95,23 +95,44 @@ class GPS : private concurrency::OSThread static HardwareSerial *_serial_gps; static uint8_t _message_PMREQ[]; + static uint8_t _message_PMREQ_10[]; static const uint8_t _message_CFG_RXM_PSM[]; static const uint8_t _message_CFG_RXM_ECO[]; static const uint8_t _message_CFG_PM2[]; static const uint8_t _message_GNSS_7[]; - static const uint8_t _message_GNSS[]; - static const uint8_t _message_JAM[]; + static const uint8_t _message_GNSS_8[]; + static const uint8_t _message_JAM_6_7[]; + static const uint8_t _message_JAM_8[]; static const uint8_t _message_NAVX5[]; + static const uint8_t _message_NAVX5_8[]; + static const uint8_t _message_NMEA[]; + static const uint8_t _message_DISABLE_TXT_INFO[]; static const uint8_t _message_1HZ[]; - static const uint8_t _message_GGL[]; + static const uint8_t _message_GLL[]; static const uint8_t _message_GSA[]; static const uint8_t _message_GSV[]; static const uint8_t _message_VTG[]; static const uint8_t _message_RMC[]; + static const uint8_t _message_AID[]; static const uint8_t _message_GGA[]; static const uint8_t _message_PMS[]; static const uint8_t _message_SAVE[]; + // VALSET Commands for M10 + static const uint8_t _message_VALSET_PM[]; + static const uint8_t _message_VALSET_PM_RAM[]; + static const uint8_t _message_VALSET_PM_BBR[]; + static const uint8_t _message_VALSET_ITFM_RAM[]; + static const uint8_t _message_VALSET_ITFM_BBR[]; + static const uint8_t _message_VALSET_DISABLE_NMEA_RAM[]; + static const uint8_t _message_VALSET_DISABLE_NMEA_BBR[]; + static const uint8_t _message_VALSET_DISABLE_TXT_INFO_RAM[]; + static const uint8_t _message_VALSET_DISABLE_TXT_INFO_BBR[]; + static const uint8_t _message_VALSET_ENABLE_NMEA_RAM[]; + static const uint8_t _message_VALSET_ENABLE_NMEA_BBR[]; + static const uint8_t _message_VALSET_DISABLE_SBAS_RAM[]; + static const uint8_t _message_VALSET_DISABLE_SBAS_BBR[]; + meshtastic_Position p = meshtastic_Position_init_default; GPS() : concurrency::OSThread("GPS") {} @@ -132,6 +153,9 @@ class GPS : private concurrency::OSThread // Disable the thread int32_t disable() override; + // toggle between enabled/disabled + void toggleGpsMode(); + void setGPSPower(bool on, bool standbyOnly, uint32_t sleepTime); /// Returns true if we have acquired GPS lock. @@ -143,7 +167,7 @@ class GPS : private concurrency::OSThread /// Return true if we are connected to a GPS bool isConnected() const { return hasGPS; } - bool isPowerSaving() const { return !config.position.gps_enabled; } + bool isPowerSaving() const { return config.position.gps_mode != meshtastic_Config_PositionConfig_GpsMode_ENABLED; } // Empty the input buffer as quickly as possible void clearBuffer(); diff --git a/src/gps/ubx.h b/src/gps/ubx.h index bc839c41e2..5b2cb24ce7 100644 --- a/src/gps/ubx.h +++ b/src/gps/ubx.h @@ -1,8 +1,16 @@ +// Power Management + uint8_t GPS::_message_PMREQ[] PROGMEM = { - 0x00, 0x00, // 4 bytes duration of request task - 0x00, 0x00, // (milliseconds) - 0x02, 0x00, // Task flag bitfield - 0x00, 0x00 // byte index 1 = sleep mode + 0x00, 0x00, 0x00, 0x00, // 4 bytes duration of request task (milliseconds) + 0x02, 0x00, 0x00, 0x00 // Bitfield, set backup = 1 +}; + +uint8_t GPS::_message_PMREQ_10[] PROGMEM = { + 0x00, // version (0 for this version) + 0x00, 0x00, 0x00, // Reserved 1 + 0x00, 0x00, 0x00, 0x00, // 4 bytes duration of request task (milliseconds) + 0x06, 0x00, 0x00, 0x00, // Bitfield, set backup =1 and force =1 + 0x08, 0x00, 0x00, 0x00 // wakeupSources Wake on uartrx }; const uint8_t GPS::_message_CFG_RXM_PSM[] PROGMEM = { @@ -10,26 +18,37 @@ const uint8_t GPS::_message_CFG_RXM_PSM[] PROGMEM = { 0x01 // Power save mode }; +// only for Neo-6 const uint8_t GPS::_message_CFG_RXM_ECO[] PROGMEM = { 0x08, // Reserved 0x04 // eco mode }; const uint8_t GPS::_message_CFG_PM2[] PROGMEM = { - 0x01, 0x06, 0x00, 0x00, // version, Reserved - 0x0E, 0x81, 0x43, 0x01, // flags + 0x01, // version + 0x00, // Reserved 1, set to 0x06 by u-Center + 0x00, // Reserved 2 + 0x00, // Reserved 1 + 0x00, 0x11, 0x03, 0x00, // flags-> cyclic mode, wait for normal fix ok, do not wake to update RTC, doNotEnterOff, + // LimitPeakCurrent 0xE8, 0x03, 0x00, 0x00, // update period 1000 ms 0x10, 0x27, 0x00, 0x00, // search period 10s - 0x00, 0x00, 0x00, 0x00, // Grod offset 0 + 0x00, 0x00, 0x00, 0x00, // Grid offset 0 0x01, 0x00, // onTime 1 second 0x00, 0x00, // min search time 0 - 0x2C, 0x01, // reserved - 0x00, 0x00, 0x4F, 0xC1, // reserved - 0x03, 0x00, 0x87, 0x02, // reserved - 0x00, 0x00, 0xFF, 0x00, // reserved - 0x01, 0x00, 0xD6, 0x4D // reserved + 0x00, 0x00, // 0x2C, 0x01, // reserved 4 + 0x00, 0x00, // 0x00, 0x00, // reserved 5 + 0x00, 0x00, 0x00, 0x00, // 0x4F, 0xC1, 0x03, 0x00, // reserved 6 + 0x00, 0x00, 0x00, 0x00, // 0x87, 0x02, 0x00, 0x00, // reserved 7 + 0x00, // 0xFF, // reserved 8 + 0x00, // 0x00, // reserved 9 + 0x00, 0x00, // 0x00, 0x00, // reserved 10 + 0x00, 0x00, 0x00, 0x00 // 0x64, 0x40, 0x01, 0x00 // reserved 11 }; +// Constallation setup, none required for Neo-6 + +// For Neo-7 GPS & SBAS const uint8_t GPS::_message_GNSS_7[] = { 0x00, // msgVer (0 for this version) 0x00, // numTrkChHw (max number of hardware channels, read only, so it's always 0) @@ -46,123 +65,228 @@ const uint8_t GPS::_message_GNSS_7[] = { // to overwrite a saved state with identical values, no ACK/NAK is received, contrary to // what is specified in the Ublox documentation. // There is also a possibility that the module may be GPS-only. -const uint8_t GPS::_message_GNSS[] = { - 0x00, // msgVer (0 for this version) - 0x00, // numTrkChHw (max number of hardware channels, read only, so it's always 0) - 0xff, // numTrkChUse (max number of channels to use, 0xff = max available) - 0x03, // numConfigBlocks (number of GNSS systems), most modules support maximum 3 GNSS systems - // GNSS config format: gnssId, resTrkCh, maxTrkCh, reserved1, flags + +// For M8 GPS, GLONASS, Galileo, SBAS, QZSS +const uint8_t GPS::_message_GNSS_8[] = { + 0x00, // msgVer (0 for this version) + 0x00, // numTrkChHw (max number of hardware channels, read only, so it's always 0) + 0xff, // numTrkChUse (max number of channels to use, 0xff = max available) + 0x05, // numConfigBlocks (number of GNSS systems) + // GNSS config format: gnssId, resTrkCh, maxTrkCh, reserved1, flags 0x00, 0x08, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, // GPS 0x01, 0x01, 0x03, 0x00, 0x01, 0x00, 0x01, 0x01, // SBAS - 0x06, 0x08, 0x0e, 0x00, 0x01, 0x00, 0x01, 0x01 // GLONASS + 0x02, 0x04, 0x08, 0x00, 0x01, 0x00, 0x01, 0x01, // Galileo + 0x05, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x01, // QZSS + 0x06, 0x08, 0x0E, 0x00, 0x01, 0x00, 0x01, 0x01 // GLONASS +}; +/* +// For M8 GPS, GLONASS, BeiDou, SBAS, QZSS +const uint8_t GPS::_message_GNSS_8_B[] = { + 0x00, // msgVer (0 for this version) + 0x00, // numTrkChHw (max number of hardware channels, read only, so it's always 0) + 0xff, // numTrkChUse (max number of channels to use, 0xff = max available) read only for protocol >23 + 0x05, // numConfigBlocks (number of GNSS systems) + // GNSS config format: gnssId, resTrkCh, maxTrkCh, reserved1, flags + 0x00, 0x08, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, // GPS + 0x01, 0x01, 0x03, 0x00, 0x01, 0x00, 0x01, 0x01, // SBAS + 0x03, 0x08, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, // BeiDou + 0x05, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x01, // QZSS + 0x06, 0x08, 0x0E, 0x00, 0x01, 0x00, 0x01, 0x01 // GLONASS +}; +*/ + +// For M8 we want to enable NMEA version 4.10 messages to allow for Galileo and or BeiDou +const uint8_t GPS::_message_NMEA[]{ + 0x00, // filter flags + 0x41, // NMEA Version + 0x00, // Max number of SVs to report per TaklerId + 0x02, // flags + 0x00, 0x00, 0x00, 0x00, // gnssToFilter + 0x00, // svNumbering + 0x00, // mainTalkerId + 0x00, // gsvTalkerId + 0x01, // Message version + 0x00, 0x00, // bdsTalkerId 2 chars 0=default + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Reserved }; +// Enable jamming/interference monitor -// Enable interference resistance, because we are using LoRa, WiFi and Bluetooth on same board, -// and we need to reduce interference from them -const uint8_t GPS::_message_JAM[] = { - // bbThreshold (Broadband jamming detection threshold) is set to 0x3F (63 in decimal) - // cwThreshold (CW jamming detection threshold) is set to 0x10 (16 in decimal) - // algorithmBits (Reserved algorithm settings) is set to 0x16B156 as recommended - // enable (Enable interference detection) is set to 1 (enabled) - 0x3F, 0x10, 0xB1, 0x56, // config: Interference config word - // generalBits (General settings) is set to 0x31E as recommended - // antSetting (Antenna setting, 0=unknown, 1=passive, 2=active) is set to 0 (unknown) - // ToDo: Set to 1 (passive) or 2 (active) if known, for example from UBX-MON-HW, or from board info - // enable2 (Set to 1 to scan auxiliary bands, u-blox 8 / u-blox M8 only, otherwise ignored) is set to 1 - // (enabled) - 0x1E, 0x03, 0x00, 0x01 // config2: Extra settings for jamming/interference monitor +// For Neo-6, Max-7 and Neo-7 +const uint8_t GPS::_message_JAM_6_7[] = { + 0xf3, 0xac, 0x62, 0xad, // config1 bbThreshold = 3, cwThreshold = 15, enable = 1, reserved bits 0x16B156 + 0x1e, 0x03, 0x00, 0x00 // config2 antennaSetting Unknown = 0, reserved 3, = 0x00,0x00, reserved 2 = 0x31E +}; + +// For M8 +const uint8_t GPS::_message_JAM_8[] = { + 0xf3, 0xac, 0x62, 0xad, // config1 bbThreshold = 3, cwThreshold = 15, enable1 = 1, reserved bits 0x16B156 + 0x1e, 0x43, 0x00, 0x00 // config2 antennaSetting Unknown = 0, enable2 = 1, generalBits = 0x31E }; // Configure navigation engine expert settings: +// there are many variations of what were Reserved fields for the Neo-6 in later versions +// ToDo: check UBX-MON-VER for module type and protocol version + +// For the Neo-6 const uint8_t GPS::_message_NAVX5[] = { - 0x00, 0x00, // msgVer (0 for this version) - // minMax flag = 1: apply min/max SVs settings - // minCno flag = 1: apply minimum C/N0 setting - // initial3dfix flag = 0: apply initial 3D fix settings - // aop flag = 1: apply aopCfg (useAOP flag) settings (AssistNow Autonomous) - 0x1B, 0x00, // mask1 (First parameters bitmask) - // adr flag = 0: apply ADR sensor fusion on/off setting (useAdr flag) - // If firmware is not ADR/UDR, enabling this flag will fail configuration - // ToDo: check this with UBX-MON-VER - 0x00, 0x00, 0x00, 0x00, // mask2 (Second parameters bitmask) - 0x00, 0x00, // Reserved - 0x03, // minSVs (Minimum number of satellites for navigation) = 3 - 0x10, // maxSVs (Maximum number of satellites for navigation) = 16 - 0x06, // minCNO (Minimum satellite signal level for navigation) = 6 dBHz - 0x00, // Reserved - 0x00, // iniFix3D (Initial fix must be 3D) = 0 (disabled) - 0x00, 0x00, // Reserved - 0x00, // ackAiding (Issue acknowledgements for assistance message input) = 0 (disabled) - 0x00, 0x00, // Reserved - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Reserved - 0x00, // Reserved - 0x01, // aopCfg (AssistNow Autonomous configuration) = 1 (enabled) - 0x00, 0x00, // Reserved - 0x00, 0x00, // Reserved - 0x00, 0x00, 0x00, 0x00, // Reserved - 0x00, 0x00, 0x00, // Reserved - 0x01, // useAdr (Enable/disable ADR sensor fusion) = 1 (enabled) + 0x00, 0x00, // msgVer (0 for this version) + 0x4c, 0x66, // mask1 + 0x00, 0x00, 0x00, 0x00, // Reserved 0 + 0x00, // Reserved 1 + 0x00, // Reserved 2 + 0x03, // minSVs (Minimum number of satellites for navigation) = 3 + 0x10, // maxSVs (Maximum number of satellites for navigation) = 16 + 0x06, // minCNO (Minimum satellite signal level for navigation) = 6 dBHz + 0x00, // Reserved 5 + 0x00, // iniFix3D (Initial fix must be 3D) (0 = false 1 = true) + 0x00, // Reserved 6 + 0x00, // Reserved 7 + 0x00, // Reserved 8 + 0x00, 0x00, // wknRollover 0 = firmware default + 0x00, 0x00, 0x00, 0x00, // Reserved 9 + 0x00, // Reserved 10 + 0x00, // Reserved 11 + 0x00, // usePPP (Precice Point Positioning) (0 = false, 1 = true) + 0x01, // useAOP (AssistNow Autonomous configuration) = 1 (enabled) + 0x00, // Reserved 12 + 0x00, // Reserved 13 + 0x00, 0x00, // aopOrbMaxErr = 0 to reset to firmware default + 0x00, // Reserved 14 + 0x00, // Reserved 15 + 0x00, 0x00, // Reserved 3 + 0x00, 0x00, 0x00, 0x00 // Reserved 4 +}; +// For the M8 +const uint8_t GPS::_message_NAVX5_8[] = { + 0x02, 0x00, // msgVer (2 for this version) + 0x4c, 0x66, // mask1 + 0x00, 0x00, 0x00, 0x00, // mask2 + 0x00, 0x00, // Reserved 1 + 0x03, // minSVs (Minimum number of satellites for navigation) = 3 + 0x10, // maxSVs (Maximum number of satellites for navigation) = 16 + 0x06, // minCNO (Minimum satellite signal level for navigation) = 6 dBHz + 0x00, // Reserved 2 + 0x00, // iniFix3D (Initial fix must be 3D) (0 = false 1 = true) + 0x00, 0x00, // Reserved 3 + 0x00, // ackAiding + 0x00, 0x00, // wknRollover 0 = firmware default + 0x00, // sigAttenCompMode + 0x00, // Reserved 4 + 0x00, 0x00, // Reserved 5 + 0x00, 0x00, // Reserved 6 + 0x00, // usePPP (Precice Point Positioning) (0 = false, 1 = true) + 0x01, // aopCfg (AssistNow Autonomous configuration) = 1 (enabled) + 0x00, 0x00, // Reserved 7 + 0x00, 0x00, // aopOrbMaxErr = 0 to reset to firmware default + 0x00, 0x00, 0x00, 0x00, // Reserved 8 + 0x00, 0x00, 0x00, // Reserved 9 + 0x00 // useAdr }; // Set GPS update rate to 1Hz // Lowering the update rate helps to save power. // Additionally, for some new modules like the M9/M10, an update rate lower than 5Hz // is recommended to avoid a known issue with satellites disappearing. +// The module defaults for M8, M9, M10 are the same as we use here so no update is necessary const uint8_t GPS::_message_1HZ[] = { 0xE8, 0x03, // Measurement Rate (1000ms for 1Hz) 0x01, 0x00, // Navigation rate, always 1 in GPS mode - 0x01, 0x00, // Time reference + 0x01, 0x00 // Time reference }; -// Disable GGL. GGL - Geographic position (latitude and longitude), which provides the current geographical +// Disable GLL. GLL - Geographic position (latitude and longitude), which provides the current geographical // coordinates. -const uint8_t GPS::_message_GGL[] = { - 0xF0, 0x01, // NMEA ID for GLL - 0x01, // I/O Target 0=I/O, 1=UART1, 2=UART2, 3=USB, 4=SPI - 0x00, // Disable - 0x01, 0x01, 0x01, 0x01 // Reserved +const uint8_t GPS::_message_GLL[] = { + 0xF0, 0x01, // NMEA ID for GLL + 0x00, // Rate for DDC + 0x00, // Rate for UART1 + 0x00, // Rate for UART2 + 0x00, // Rate for USB + 0x00, // Rate for SPI + 0x00 // Reserved }; // Enable GSA. GSA - GPS DOP and active satellites, used for detailing the satellites used in the positioning and // the DOP (Dilution of Precision) const uint8_t GPS::_message_GSA[] = { - 0xF0, 0x02, // NMEA ID for GSA - 0x01, // I/O Target 0=I/O, 1=UART1, 2=UART2, 3=USB, 4=SPI - 0x01, // Enable - 0x01, 0x01, 0x01, 0x01 // Reserved + 0xF0, 0x02, // NMEA ID for GSA + 0x00, // Rate for DDC + 0x01, // Rate for UART1 + 0x00, // Rate for UART2 + 0x01, // Rate for USB usefull for native linux + 0x00, // Rate for SPI + 0x00 // Reserved }; // Disable GSV. GSV - Satellites in view, details the number and location of satellites in view. const uint8_t GPS::_message_GSV[] = { - 0xF0, 0x03, // NMEA ID for GSV - 0x01, // I/O Target 0=I/O, 1=UART1, 2=UART2, 3=USB, 4=SPI - 0x00, // Disable - 0x01, 0x01, 0x01, 0x01 // Reserved + 0xF0, 0x03, // NMEA ID for GSV + 0x00, // Rate for DDC + 0x00, // Rate for UART1 + 0x00, // Rate for UART2 + 0x00, // Rate for USB + 0x00, // Rate for SPI + 0x00 // Reserved }; // Disable VTG. VTG - Track made good and ground speed, which provides course and speed information relative to // the ground. const uint8_t GPS::_message_VTG[] = { - 0xF0, 0x05, // NMEA ID for VTG - 0x01, // I/O Target 0=I/O, 1=UART1, 2=UART2, 3=USB, 4=SPI - 0x00, // Disable - 0x01, 0x01, 0x01, 0x01 // Reserved + 0xF0, 0x05, // NMEA ID for VTG + 0x00, // Rate for DDC + 0x00, // Rate for UART1 + 0x00, // Rate for UART2 + 0x00, // Rate for USB + 0x00, // Rate for SPI + 0x00 // Reserved }; // Enable RMC. RMC - Recommended Minimum data, the essential gps pvt (position, velocity, time) data. const uint8_t GPS::_message_RMC[] = { - 0xF0, 0x04, // NMEA ID for RMC - 0x01, // I/O Target 0=I/O, 1=UART1, 2=UART2, 3=USB, 4=SPI - 0x01, // Enable - 0x01, 0x01, 0x01, 0x01 // Reserved + 0xF0, 0x04, // NMEA ID for RMC + 0x00, // Rate for DDC + 0x01, // Rate for UART1 + 0x00, // Rate for UART2 + 0x01, // Rate for USB usefull for native linux + 0x00, // Rate for SPI + 0x00 // Reserved }; // Enable GGA. GGA - Global Positioning System Fix Data, which provides 3D location and accuracy data. const uint8_t GPS::_message_GGA[] = { - 0xF0, 0x00, // NMEA ID for GGA - 0x01, // I/O Target 0=I/O, 1=UART1, 2=UART2, 3=USB, 4=SPI - 0x01, // Enable - 0x01, 0x01, 0x01, 0x01 // Reserved + 0xF0, 0x00, // NMEA ID for GGA + 0x00, // Rate for DDC + 0x01, // Rate for UART1 + 0x00, // Rate for UART2 + 0x01, // Rate for USB, usefull for native linux + 0x00, // Rate for SPI + 0x00 // Reserved +}; + +// Disable UBX-AID-ALPSRV as it may confuse TinyGPS. The Neo-6 seems to send this message +// whether the AID Autonomous is enabled or not +const uint8_t GPS::_message_AID[] = { + 0x0B, 0x32, // NMEA ID for UBX-AID-ALPSRV + 0x00, // Rate for DDC + 0x00, // Rate for UART1 + 0x00, // Rate for UART2 + 0x00, // Rate for USB + 0x00, // Rate for SPI + 0x00 // Reserved +}; + +// Turn off TEXT INFO Messages for all but M10 series + +// B5 62 06 02 0A 00 01 00 00 00 03 03 00 03 03 00 1F 20 +const uint8_t GPS::_message_DISABLE_TXT_INFO[] = { + 0x01, // Protocol ID for NMEA + 0x00, 0x00, 0x00, // Reserved + 0x03, // I2C + 0x03, // I/O Port 1 + 0x00, // I/O Port 2 + 0x03, // USB + 0x03, // SPI + 0x00 // Reserved }; // The Power Management configuration allows the GPS module to operate in different power modes for optimized @@ -176,17 +300,154 @@ const uint8_t GPS::_message_GGA[] = { // is set to Interval; otherwise, it must be set to '0'. The 'onTime' field specifies the duration of the ON phase // and must be smaller than the period. It is only valid when the powerSetupValue is set to Interval; otherwise, // it must be set to '0'. +// This command applies to M8 products const uint8_t GPS::_message_PMS[] = { 0x00, // Version (0) - 0x03, // Power setup value + 0x03, // Power setup value 3 = Agresssive 1Hz 0x00, 0x00, // period: not applicable, set to 0 0x00, 0x00, // onTime: not applicable, set to 0 - 0x97, 0x6F // reserved, generated by u-center + 0x00, 0x00 // reserved, generated by u-center }; const uint8_t GPS::_message_SAVE[] = { 0x00, 0x00, 0x00, 0x00, // clearMask: no sections cleared 0xFF, 0xFF, 0x00, 0x00, // saveMask: save all sections 0x00, 0x00, 0x00, 0x00, // loadMask: no sections loaded - 0x0F // deviceMask: BBR, Flash, EEPROM, and SPI Flash + 0x17 // deviceMask: BBR, Flash, EEPROM, and SPI Flash }; + +// As the M10 has no flash, the best we can do to preserve the config is to set it in RAM and BBR. +// BBR will survive a restart, and power off for a while, but modules with small backup +// batteries or super caps will not retain the config for a long power off time. + +// VALSET Commands for M10 +// Please refer to the M10 Protocol Specification: +// https://content.u-blox.com/sites/default/files/u-blox-M10-SPG-5.10_InterfaceDescription_UBX-21035062.pdf +// Where the VALSET/VALGET/VALDEL commands are described in detail. +// and: +// https://content.u-blox.com/sites/default/files/u-blox-M10-ROM-5.10_ReleaseNotes_UBX-22001426.pdf +// for interesting insights. +/* +CFG-PM2 has been replaced by many CFG-PM commands +OPERATEMODE E1 2 (0 | 1 | 2) +POSUPDATEPERIOD U4 1000ms for M10 must be >= 5s try 5 +ACQPERIOD U4 10 seems ok for M10 def ok +GRIDOFFSET U4 0 seems ok for M10 def ok +ONTIME U2 1 will try 1 +MINACQTIME U1 0 will try 0 def ok +MAXACQTIME U1 stick with default of 0 def ok +DONOTENTEROFF L 1 stay at 1 +WAITTIMEFIX L 1 stay with 1 +UPDATEEPH L 1 changed to 1 for gps rework default is 1 +EXTINTWAKE L 0 no ext ints +EXTINTBACKUP L 0 no ext ints +EXTINTINACTIVE L 0 no ext ints +EXTINTACTIVITY U4 0 no ext ints +LIMITPEAKCURRENT L 1 stay with 1 +*/ +// CFG-PMS has been removed + +// Ram layer config message: +// b5 62 06 8a 26 00 00 01 00 00 01 00 d0 20 02 02 00 d0 40 05 00 00 00 05 00 d0 30 01 00 08 00 d0 10 01 09 00 d0 10 01 10 00 d0 +// 10 01 8b de + +// BBR layer config message: +// b5 62 06 8a 26 00 00 02 00 00 01 00 d0 20 02 02 00 d0 40 05 00 00 00 05 00 d0 30 01 00 08 00 d0 10 01 09 00 d0 10 01 10 00 d0 +// 10 01 8c 03 + +const uint8_t GPS::_message_VALSET_PM_RAM[] = {0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0xd0, 0x20, 0x02, 0x02, 0x00, 0xd0, 0x40, + 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0xd0, 0x30, 0x01, 0x00, 0x08, 0x00, 0xd0, + 0x10, 0x01, 0x09, 0x00, 0xd0, 0x10, 0x01, 0x10, 0x00, 0xd0, 0x10, 0x01}; +const uint8_t GPS::_message_VALSET_PM_BBR[] = {0x00, 0x02, 0x00, 0x00, 0x01, 0x00, 0xd0, 0x20, 0x02, 0x02, 0x00, 0xd0, 0x40, + 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0xd0, 0x30, 0x01, 0x00, 0x08, 0x00, 0xd0, + 0x10, 0x01, 0x09, 0x00, 0xd0, 0x10, 0x01, 0x10, 0x00, 0xd0, 0x10, 0x01}; + +/* +CFG-ITFM replaced by 5 valset messages which can be combined into one for RAM and one for BBR + +20410001 bbthreshold U1 3 +20410002 cwthreshold U1 15 +1041000d enable L 0 -> 1 +20410010 ant E1 0 +10410013 enable aux L 0 -> 1 + + +b5 62 06 8a 0e 00 00 01 00 00 0d 00 41 10 01 13 00 41 10 01 63 c6 +*/ +const uint8_t GPS::_message_VALSET_ITFM_RAM[] = {0x00, 0x01, 0x00, 0x00, 0x0d, 0x00, 0x41, + 0x10, 0x01, 0x13, 0x00, 0x41, 0x10, 0x01}; +const uint8_t GPS::_message_VALSET_ITFM_BBR[] = {0x00, 0x02, 0x00, 0x00, 0x0d, 0x00, 0x41, + 0x10, 0x01, 0x13, 0x00, 0x41, 0x10, 0x01}; + +// Turn off all NMEA messages: +// Ram layer config message: +// b5 62 06 8a 22 00 00 01 00 00 c0 00 91 20 00 ca 00 91 20 00 c5 00 91 20 00 ac 00 91 20 00 b1 00 91 20 00 bb 00 91 20 00 40 8f + +// Disable GLL, GSV, VTG messages in BBR layer +// BBR layer config message: +// b5 62 06 8a 13 00 00 02 00 00 ca 00 91 20 00 c5 00 91 20 00 b1 00 91 20 00 f8 4e + +const uint8_t GPS::_message_VALSET_DISABLE_NMEA_RAM[] = { + /*0x00, 0x01, 0x00, 0x00, 0xca, 0x00, 0x91, 0x20, 0x00, 0xc5, 0x00, 0x91, 0x20, 0x00, 0xb1, 0x00, 0x91, 0x20, 0x00 */ + 0x00, 0x01, 0x00, 0x00, 0xc0, 0x00, 0x91, 0x20, 0x00, 0xca, 0x00, 0x91, 0x20, 0x00, 0xc5, 0x00, 0x91, + 0x20, 0x00, 0xac, 0x00, 0x91, 0x20, 0x00, 0xb1, 0x00, 0x91, 0x20, 0x00, 0xbb, 0x00, 0x91, 0x20, 0x00}; + +const uint8_t GPS::_message_VALSET_DISABLE_NMEA_BBR[] = {0x00, 0x02, 0x00, 0x00, 0xca, 0x00, 0x91, 0x20, 0x00, 0xc5, + 0x00, 0x91, 0x20, 0x00, 0xb1, 0x00, 0x91, 0x20, 0x00}; + +// Turn off text info messages: +// Ram layer config message: +// b5 62 06 8a 09 00 00 01 00 00 07 00 92 20 06 59 50 + +// BBR layer config message: +// b5 62 06 8a 09 00 00 02 00 00 07 00 92 20 06 5a 58 + +// Turn NMEA GSA, GGA, RMC messages on: +// Ram layer config message: +// b5 62 06 8a 13 00 00 01 00 00 c0 00 91 20 01 bb 00 91 20 01 ac 00 91 20 01 e1 3b + +// BBR layer config message: +// b5 62 06 8a 13 00 00 02 00 00 c0 00 91 20 01 bb 00 91 20 01 ac 00 91 20 01 e2 4d + +const uint8_t GPS::_message_VALSET_DISABLE_TXT_INFO_RAM[] = {0x00, 0x01, 0x00, 0x00, 0x07, 0x00, 0x92, 0x20, 0x03}; +const uint8_t GPS::_message_VALSET_DISABLE_TXT_INFO_BBR[] = {0x00, 0x02, 0x00, 0x00, 0x07, 0x00, 0x92, 0x20, 0x03}; +const uint8_t GPS::_message_VALSET_ENABLE_NMEA_RAM[] = {0x00, 0x01, 0x00, 0x00, 0xc0, 0x00, 0x91, 0x20, 0x01, 0xbb, + 0x00, 0x91, 0x20, 0x01, 0xac, 0x00, 0x91, 0x20, 0x01}; +const uint8_t GPS::_message_VALSET_ENABLE_NMEA_BBR[] = {0x00, 0x02, 0x00, 0x00, 0xc0, 0x00, 0x91, 0x20, 0x01, 0xbb, + 0x00, 0x91, 0x20, 0x01, 0xac, 0x00, 0x91, 0x20, 0x01}; +const uint8_t GPS::_message_VALSET_DISABLE_SBAS_RAM[] = {0x00, 0x01, 0x00, 0x00, 0x20, 0x00, 0x31, + 0x10, 0x00, 0x05, 0x00, 0x31, 0x10, 0x00}; +const uint8_t GPS::_message_VALSET_DISABLE_SBAS_BBR[] = {0x00, 0x02, 0x00, 0x00, 0x20, 0x00, 0x31, + 0x10, 0x00, 0x05, 0x00, 0x31, 0x10, 0x00}; +/* +Operational issues with the M10: + +PowerSave doesn't work with SBAS, seems like you can have SBAS enabled, but it will never lock +onto the SBAS sats. +PowerSave doesn't work with BDS B1C, u-blox says use B1l instead. +BDS B1l cannot be enabled with BDS B1C or GLONASS L1OF, so GLONASS will work with B1C, but not B1l +So no powersave with GLONASS and BDS B1l enabled. +So disable GLONASS and use BDS B1l, which is part of the default M10 config. + +GNSS configuration: + +Default GNSS configuration is: GPS, Galileo, BDS B1l, with QZSS and SBAS enabled. +The PMREQ puts the receiver to sleep and wakeup re-acquires really fast and seems to not need +the PM config. Lets try without it. +PMREQ sort of works with SBAS, but the awake time is too short to re-acquire any SBAS sats. +The defination of "Got Fix" doesn't seem to include SBAS. Much more too this... +Even if it was, it can take minutes (up to 12.5), +even under good sat visability conditions to re-acquire the SBAS data. + +Another effect fo the quick transition to sleep is that no other sats will be acquired so the +sat count will tend to remain at what the initial fix was. +*/ + +// GNSS disable SBAS as recommended by u-blox if using GNSS defaults and power save mode +/* +Ram layer config message: +b5 62 06 8a 0e 00 00 01 00 00 20 00 31 10 00 05 00 31 10 00 46 87 + +BBR layer config message: +b5 62 06 8a 0e 00 00 02 00 00 20 00 31 10 00 05 00 31 10 00 47 94 +*/ \ No newline at end of file diff --git a/src/graphics/EInkDisplay2.cpp b/src/graphics/EInkDisplay2.cpp index 3b97dd723f..d5e3f52630 100644 --- a/src/graphics/EInkDisplay2.cpp +++ b/src/graphics/EInkDisplay2.cpp @@ -7,9 +7,9 @@ #include "main.h" #include -// #ifdef HELTEC_WIRELESS_PAPER -// SPIClass *hspi = NULL; -// #endif +#if defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0) +SPIClass *hspi = NULL; +#endif #define COLORED GxEPD_BLACK #define UNCOLORED GxEPD_WHITE @@ -47,7 +47,12 @@ #elif defined(HELTEC_WIRELESS_PAPER) // #define TECHO_DISPLAY_MODEL GxEPD2_213_T5D +#define TECHO_DISPLAY_MODEL GxEPD2_213_FC1 + +#elif defined(HELTEC_WIRELESS_PAPER_V1_0) +// 2.13" 122x250 - DEPG0213BNS800 #define TECHO_DISPLAY_MODEL GxEPD2_213_BN + #endif GxEPD2_BW *adafruitDisplay; @@ -55,12 +60,12 @@ GxEPD2_BW *adafruitDisplay; EInkDisplay::EInkDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY geometry, HW_I2C i2cBus) { #if defined(TTGO_T_ECHO) - setGeometry(GEOMETRY_RAWMODE, TECHO_DISPLAY_MODEL::WIDTH, TECHO_DISPLAY_MODEL::HEIGHT); + setGeometry(GEOMETRY_RAWMODE, 200, 200); #elif defined(RAK4630) // GxEPD2_213_BN - RAK14000 2.13 inch b/w 250x122 setGeometry(GEOMETRY_RAWMODE, 250, 122); - + this->displayBufferSize = 250 * (128 / 8); // GxEPD2_420_M01 // setGeometry(GEOMETRY_RAWMODE, 300, 400); @@ -70,8 +75,19 @@ EInkDisplay::EInkDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY // GxEPD2_154_M09 // setGeometry(GEOMETRY_RAWMODE, 200, 200); +#elif defined(HELTEC_WIRELESS_PAPER_V1_0) + + // The display's memory is actually 128px x 250px + // Setting the buffersize manually prevents 122/8 truncating to a 15 byte width + // (Or something like that..) + + this->geometry = GEOMETRY_RAWMODE; + this->displayWidth = 250; + this->displayHeight = 122; + this->displayBufferSize = 250 * (128 / 8); + #elif defined(HELTEC_WIRELESS_PAPER) - // setGeometry(GEOMETRY_RAWMODE, 212, 104); + // GxEPD2_213_BN - 2.13 inch b/w 250x122 setGeometry(GEOMETRY_RAWMODE, 250, 122); #elif defined(MAKERPYTHON) // GxEPD2_290_T5D @@ -93,6 +109,12 @@ EInkDisplay::EInkDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY setGeometry(GEOMETRY_RAWMODE, 296, 128); LOG_DEBUG("GEOMETRY_RAWMODE, 296, 128\n"); +#elif defined(ESP32_S3_PICO) + + // GxEPD2_290_T94_V2 + setGeometry(GEOMETRY_RAWMODE, EPD_WIDTH, EPD_HEIGHT); + LOG_DEBUG("GEOMETRY_RAWMODE, 296, 128\n"); + #endif // setGeometry(GEOMETRY_RAWMODE, 128, 64); // old resolution // setGeometry(GEOMETRY_128_64); // We originally used this because I wasn't sure if rawmode worked - it does @@ -109,60 +131,69 @@ bool EInkDisplay::forceDisplay(uint32_t msecLimit) // No need to grab this lock because we are on our own SPI bus // concurrency::LockGuard g(spiLock); +#if defined(USE_EINK_DYNAMIC_PARTIAL) + // Decide if update is partial or full + bool continueUpdate = determineRefreshMode(); + if (!continueUpdate) + return false; +#else + uint32_t now = millis(); uint32_t sinceLast = now - lastDrawMsec; - if (adafruitDisplay && (sinceLast > msecLimit || lastDrawMsec == 0)) { + if (adafruitDisplay && (sinceLast > msecLimit || lastDrawMsec == 0)) lastDrawMsec = now; + else + return false; - // FIXME - only draw bits have changed (use backbuf similar to the other displays) - // tft.drawBitmap(0, 0, buffer, 128, 64, TFT_YELLOW, TFT_BLACK); - for (uint32_t y = 0; y < displayHeight; y++) { - for (uint32_t x = 0; x < displayWidth; x++) { +#endif - // get src pixel in the page based ordering the OLED lib uses FIXME, super inefficient - auto b = buffer[x + (y / 8) * displayWidth]; - auto isset = b & (1 << (y & 7)); - adafruitDisplay->drawPixel(x, y, isset ? COLORED : UNCOLORED); - } + // FIXME - only draw bits have changed (use backbuf similar to the other displays) + // tft.drawBitmap(0, 0, buffer, 128, 64, TFT_YELLOW, TFT_BLACK); + for (uint32_t y = 0; y < displayHeight; y++) { + for (uint32_t x = 0; x < displayWidth; x++) { + // get src pixel in the page based ordering the OLED lib uses FIXME, super inefficient + auto b = buffer[x + (y / 8) * displayWidth]; + auto isset = b & (1 << (y & 7)); + adafruitDisplay->drawPixel(x, y, isset ? COLORED : UNCOLORED); } + } - LOG_DEBUG("Updating E-Paper... "); + LOG_DEBUG("Updating E-Paper... "); #if defined(TTGO_T_ECHO) - // ePaper.Reset(); // wake the screen from sleep - adafruitDisplay->display(false); // FIXME, use partial update mode + adafruitDisplay->nextPage(); #elif defined(RAK4630) || defined(MAKERPYTHON) - // RAK14000 2.13 inch b/w 250x122 actually now does support partial updates + // RAK14000 2.13 inch b/w 250x122 actually now does support partial updates - // Full update mode (slow) - // adafruitDisplay->display(false); // FIXME, use partial update mode + // Full update mode (slow) + // adafruitDisplay->display(false); // FIXME, use partial update mode - // Only enable for e-Paper with support for partial updates and comment out above adafruitDisplay->display(false); - // 1.54 inch 200x200 - GxEPD2_154_M09 - // 2.13 inch 250x122 - GxEPD2_213_BN - // 2.9 inch 296x128 - GxEPD2_290_T5D - // 4.2 inch 300x400 - GxEPD2_420_M01 - adafruitDisplay->nextPage(); + // Only enable for e-Paper with support for partial updates and comment out above adafruitDisplay->display(false); + // 1.54 inch 200x200 - GxEPD2_154_M09 + // 2.13 inch 250x122 - GxEPD2_213_BN + // 2.9 inch 296x128 - GxEPD2_290_T5D + // 4.2 inch 300x400 - GxEPD2_420_M01 + adafruitDisplay->nextPage(); #elif defined(PCA10059) || defined(M5_COREINK) - adafruitDisplay->nextPage(); - + adafruitDisplay->nextPage(); +#elif defined(HELTEC_WIRELESS_PAPER_V1_0) + adafruitDisplay->nextPage(); +#elif defined(HELTEC_WIRELESS_PAPER) + adafruitDisplay->nextPage(); +#elif defined(ESP32_S3_PICO) + adafruitDisplay->nextPage(); #elif defined(PRIVATE_HW) || defined(my) - adafruitDisplay->nextPage(); - + adafruitDisplay->nextPage(); #endif - // Put screen to sleep to save power (possibly not necessary because we already did poweroff inside of display) - adafruitDisplay->hibernate(); - LOG_DEBUG("done\n"); + // Put screen to sleep to save power (possibly not necessary because we already did poweroff inside of display) + adafruitDisplay->hibernate(); + LOG_DEBUG("done\n"); - return true; - } else { - // LOG_DEBUG("Skipping eink display\n"); - return false; - } + return true; } // Write the buffer to the display memory @@ -171,8 +202,16 @@ void EInkDisplay::display(void) // We don't allow regular 'dumb' display() calls to draw on eink until we've shown // at least one forceDisplay() keyframe. This prevents flashing when we should the critical // bootscreen (that we want to look nice) - if (lastDrawMsec) + +#ifdef USE_EINK_DYNAMIC_PARTIAL + lowPriority(); + forceDisplay(); + highPriority(); +#else + if (lastDrawMsec) { forceDisplay(slowUpdateMsec); // Show the first screen a few seconds after boot, then slower + } +#endif } // Send a command to the display (low level function) @@ -210,16 +249,14 @@ bool EInkDisplay::connect() adafruitDisplay = new GxEPD2_BW(*lowLevel); adafruitDisplay->init(); adafruitDisplay->setRotation(3); + adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight); } #elif defined(RAK4630) || defined(MAKERPYTHON) { if (eink_found) { auto lowLevel = new TECHO_DISPLAY_MODEL(PIN_EINK_CS, PIN_EINK_DC, PIN_EINK_RES, PIN_EINK_BUSY); - adafruitDisplay = new GxEPD2_BW(*lowLevel); - adafruitDisplay->init(115200, true, 10, false, SPI1, SPISettings(4000000, MSBFIRST, SPI_MODE0)); - // RAK14000 2.13 inch b/w 250x122 does actually now support partial updates adafruitDisplay->setRotation(3); // Partial update support for 1.54, 2.13 RAK14000 b/w , 2.9 and 4.2 @@ -229,15 +266,55 @@ bool EInkDisplay::connect() (void)adafruitDisplay; } } + +#elif defined(HELTEC_WIRELESS_PAPER_V1_0) + { + // Is this a normal boot, or a wake from deep sleep? + esp_sleep_wakeup_cause_t wakeReason = esp_sleep_get_wakeup_cause(); + + // If waking from sleep, need to reverse rtc_gpio_isolate(), called in cpuDeepSleep() + // Otherwise, SPI won't work + if (wakeReason != ESP_SLEEP_WAKEUP_UNDEFINED) { + // HSPI + other display pins + rtc_gpio_hold_dis((gpio_num_t)PIN_EINK_SCLK); + rtc_gpio_hold_dis((gpio_num_t)PIN_EINK_DC); + rtc_gpio_hold_dis((gpio_num_t)PIN_EINK_RES); + rtc_gpio_hold_dis((gpio_num_t)PIN_EINK_BUSY); + rtc_gpio_hold_dis((gpio_num_t)PIN_EINK_CS); + rtc_gpio_hold_dis((gpio_num_t)PIN_EINK_MOSI); + } + + // Start HSPI + hspi = new SPIClass(HSPI); + hspi->begin(PIN_EINK_SCLK, -1, PIN_EINK_MOSI, PIN_EINK_CS); // SCLK, MISO, MOSI, SS + + // Enable VExt (ACTIVE LOW) + // Unsure if called elsewhere first? + delay(100); + pinMode(Vext, OUTPUT); + digitalWrite(Vext, LOW); + delay(100); + + // Create GxEPD2 objects + auto lowLevel = new TECHO_DISPLAY_MODEL(PIN_EINK_CS, PIN_EINK_DC, PIN_EINK_RES, PIN_EINK_BUSY, *hspi); + adafruitDisplay = new GxEPD2_BW(*lowLevel); + + // Init GxEPD2 + adafruitDisplay->init(); + adafruitDisplay->setRotation(3); + } #elif defined(HELTEC_WIRELESS_PAPER) { - auto lowLevel = new TECHO_DISPLAY_MODEL(PIN_EINK_CS, PIN_EINK_DC, PIN_EINK_RES, PIN_EINK_BUSY); + hspi = new SPIClass(HSPI); + hspi->begin(PIN_EINK_SCLK, -1, PIN_EINK_MOSI, PIN_EINK_CS); // SCLK, MISO, MOSI, SS + delay(100); + pinMode(Vext, OUTPUT); + digitalWrite(Vext, LOW); + delay(100); + auto lowLevel = new TECHO_DISPLAY_MODEL(PIN_EINK_CS, PIN_EINK_DC, PIN_EINK_RES, PIN_EINK_BUSY, *hspi); adafruitDisplay = new GxEPD2_BW(*lowLevel); - // hspi = new SPIClass(HSPI); - // hspi->begin(PIN_EINK_SCLK, -1, PIN_EINK_MOSI, PIN_EINK_CS); // SCLK, MISO, MOSI, SS - adafruitDisplay->init(115200, true, 10, false, SPI, SPISettings(6000000, MSBFIRST, SPI_MODE0)); + adafruitDisplay->init(); adafruitDisplay->setRotation(3); - adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight); } #elif defined(PCA10059) { @@ -253,7 +330,7 @@ bool EInkDisplay::connect() adafruitDisplay->init(115200, true, 40, false, SPI, SPISettings(4000000, MSBFIRST, SPI_MODE0)); adafruitDisplay->setRotation(0); adafruitDisplay->setPartialWindow(0, 0, EPD_WIDTH, EPD_HEIGHT); -#elif defined(my) +#elif defined(my) || defined(ESP32_S3_PICO) { auto lowLevel = new TECHO_DISPLAY_MODEL(PIN_EINK_CS, PIN_EINK_DC, PIN_EINK_RES, PIN_EINK_BUSY); adafruitDisplay = new GxEPD2_BW(*lowLevel); @@ -267,8 +344,195 @@ bool EInkDisplay::connect() // adafruitDisplay->fillScreen(UNCOLORED); // adafruitDisplay->drawCircle(100, 100, 20, COLORED); // adafruitDisplay->display(false); - return true; } +// Use a mix of full and partial refreshes, to preserve display health +#if defined(USE_EINK_DYNAMIC_PARTIAL) + +// Suggest that subsequent updates should use partial-refresh +void EInkDisplay::highPriority() +{ + isHighPriority = true; +} + +// Suggest that subsequent updates should use full-refresh +void EInkDisplay::lowPriority() +{ + isHighPriority = false; +} + +// Full-refresh is explicitly requested for next one update - no skipping please +void EInkDisplay::demandFullRefresh() +{ + demandingFull = true; +} + +// configure display for partial-refresh +void EInkDisplay::configForPartialRefresh() +{ + // Display-specific code can go here +#if defined(PRIVATE_HW) +#else + // Otherwise: + adafruitDisplay->setPartialWindow(0, 0, adafruitDisplay->width(), adafruitDisplay->height()); +#endif +} + +// Configure display for full-refresh +void EInkDisplay::configForFullRefresh() +{ + // Display-specific code can go here +#if defined(PRIVATE_HW) +#else + // Otherwise: + adafruitDisplay->setFullWindow(); +#endif +} + +#ifdef EINK_PARTIAL_ERASURE_LIMIT +// Count black pixels in an image. Used for "erasure tracking" +int32_t EInkDisplay::countBlackPixels() +{ + int32_t blackCount = 0; // Signed, to avoid underflow when comparing + for (uint16_t b = 0; b < (displayWidth / 8) * displayHeight; b++) { + for (uint8_t i = 0; i < 7; i++) { + // Check if each bit is black or white + blackCount += (buffer[b] >> i) & 1; + } + } + return blackCount; +} + +// Evaluate the (rough) amount of black->white pixel change since last full refresh +bool EInkDisplay::tooManyErasures() +{ + // Ideally, we would compare the new and old buffers, to count *actual* white-to-black pixel changes + // but that would require substantially more "code tampering" + + // Get the black pixel stats for this image + int32_t blackCount = countBlackPixels(); + int32_t blackDifference = blackCount - prevBlackCount; + + // Update the running total of "erasures" - black pixels which have become white, since last full-refresh + if (blackDifference < 0) + erasedSinceFull -= blackDifference; + + // Store black pixel count for next time + prevBlackCount = blackCount; + + // Log the running total - help devs setup new boards + LOG_DEBUG("Dynamic Partial: erasedSinceFull=%hu, EINK_PARTIAL_ERASURE_LIMIT=%hu\n", erasedSinceFull, + EINK_PARTIAL_ERASURE_LIMIT); + + // Check if too many pixels have been erased + if (erasedSinceFull > EINK_PARTIAL_ERASURE_LIMIT) + return true; // Too many + else + return false; // Still okay +} +#endif // ifdef EINK_PARTIAL_BRIGHTEN_LIMIT_PX + +bool EInkDisplay::newImageMatchesOld() +{ + uint32_t newImageHash = 0; + + // Generate hash: sum all bytes in the image buffer + for (uint16_t b = 0; b < (displayWidth / 8) * displayHeight; b++) { + newImageHash += buffer[b]; + } + + // Compare hashes + bool hashMatches = (newImageHash == prevImageHash); + + // Update the cached hash + prevImageHash = newImageHash; + + // Return the comparison result + return hashMatches; +} + +// Change between partial and full refresh config, or skip update, balancing urgency and display health. +bool EInkDisplay::determineRefreshMode() +{ + uint32_t now = millis(); + uint32_t sinceLast = now - lastUpdateMsec; + + // If rate-limiting dropped a high-priority update: + // promote this update, so it runs ASAP + if (missedHighPriorityUpdate) { + isHighPriority = true; + missedHighPriorityUpdate = false; + } + + // Abort: if too soon for a new frame (unless demanding full) + if (!demandingFull && isHighPriority && partialRefreshCount > 0 && sinceLast < highPriorityLimitMsec) { + LOG_DEBUG("Dynamic Partial: update skipped. Exceeded EINK_HIGHPRIORITY_LIMIT_SECONDS\n"); + missedHighPriorityUpdate = true; + return false; + } + if (!demandingFull && !isHighPriority && !demandingFull && sinceLast < lowPriorityLimitMsec) { + return false; + } + + // If demanded full refresh: give it to them + if (demandingFull) + needsFull = true; + + // Check if old image (partial) should be redrawn (as full), for image quality + if (partialRefreshCount > 0 && !isHighPriority) + needsFull = true; + + // If too many partials, require a full-refresh (display health) + if (partialRefreshCount >= partialRefreshLimit) + needsFull = true; + +#ifdef EINK_PARTIAL_ERASURE_LIMIT + // Some displays struggle with erasing black pixels to white, during partial refresh + if (tooManyErasures()) + needsFull = true; +#endif + + // If image matches + // (Block must run, even if full already selected, to store hash for next time) + if (newImageMatchesOld()) { + // If low priority: limit rate + // otherwise, every loop() will run the hash method + if (!isHighPriority) + lastUpdateMsec = now; + + // If update is *not* for display health or image quality, skip it + if (!needsFull) + return false; + } + + // Conditions assessed - not skipping - load the appropriate config + + // If options require a full refresh + if (!isHighPriority || needsFull) { + if (partialRefreshCount > 0) + configForFullRefresh(); + + LOG_DEBUG("Dynamic Partial: conditions met for full-refresh\n"); + partialRefreshCount = 0; + needsFull = false; + demandingFull = false; + erasedSinceFull = 0; // Reset the count for EINK_PARTIAL_ERASURE_LIMIT - tracks ghosting buildup + } + + // If options allow a partial refresh + else { + if (partialRefreshCount == 0) + configForPartialRefresh(); + + LOG_DEBUG("Dynamic Partial: conditions met for partial-refresh\n"); + partialRefreshCount++; + } + + lastUpdateMsec = now; // Mark time for rate limiting + return true; // Instruct calling method to continue with update +} + +#endif // End USE_EINK_DYNAMIC_PARTIAL + #endif diff --git a/src/graphics/EInkDisplay2.h b/src/graphics/EInkDisplay2.h index 2529b1f0e3..aeaddee2d4 100644 --- a/src/graphics/EInkDisplay2.h +++ b/src/graphics/EInkDisplay2.h @@ -2,6 +2,11 @@ #include +#if defined(HELTEC_WIRELESS_PAPER_V1_0) +// Re-enable SPI after deep sleep: rtc_gpio_hold_dis() +#include "driver/rtc_io.h" +#endif + /** * An adapter class that allows using the GxEPD2 library as if it was an OLEDDisplay implementation. * @@ -49,4 +54,81 @@ class EInkDisplay : public OLEDDisplay // Connect to the display virtual bool connect() override; + +#if defined(USE_EINK_DYNAMIC_PARTIAL) + // Full, partial, or skip: balance urgency with display health + + // Use partial refresh if EITHER: + // * highPriority() was set + // * a highPriority() update was previously skipped, for rate-limiting - (EINK_HIGHPRIORITY_LIMIT_SECONDS) + + // Use full refresh if EITHER: + // * lowPriority() was set + // * demandFullRefresh() was called - (single shot) + // * too many partial updates in a row: protect display - (EINK_PARTIAL_REPEAT_LIMIT) + // * no recent updates, and last update was partial: redraw for image quality (EINK_LOWPRIORITY_LIMIT_SECONDS) + // * (optional) too many "erasures" since full-refresh (black pixels cleared to white) + + // Rate limit if: + // * lowPriority() - (EINK_LOWPRIORITY_LIMIT_SECONDS) + // * highPriority(), if multiple partials have run back-to-back - (EINK_HIGHPRIORITY_LIMIT_SECONDS) + + // Skip update entirely if ALL criteria met: + // * new image matches old image + // * lowPriority() + // * no call to demandFullRefresh() + // * not redrawing for image quality + // * not refreshing for display health + + // ------------------------------------ + + // To implement for your E-Ink display: + // * edit configForPartialRefresh() + // * edit configForFullRefresh() + // * add macros to variant.h, and adjust to taste: + + /* + #define USE_EINK_DYNAMIC_PARTIAL + #define EINK_LOWPRIORITY_LIMIT_SECONDS 30 + #define EINK_HIGHPRIORITY_LIMIT_SECONDS 1 + #define EINK_PARTIAL_REPEAT_LIMIT 5 + #define EINK_PARTIAL_ERASURE_LIMIT 300 // optional + */ + + public: + void highPriority(); // Suggest partial refresh + void lowPriority(); // Suggest full refresh + void demandFullRefresh(); // For next update: explicitly request full refresh + + protected: + void configForPartialRefresh(); // Display specific code to select partial refresh mode + void configForFullRefresh(); // Display specific code to return to full refresh mode + bool newImageMatchesOld(); // Is the new update actually different to the last image? + bool determineRefreshMode(); // Called immediately before data written to display - choose refresh mode, or abort update +#ifdef EINK_PARTIAL_ERASURE_LIMIT + int32_t countBlackPixels(); // Calculate the number of black pixels in the new image + bool tooManyErasures(); // Has too much "ghosting" (black pixels erased to white) accumulated since last full-refresh? +#endif + + bool isHighPriority = true; // Does the method calling update believe that this is urgent? + bool needsFull = false; // Is a full refresh forced? (display health) + bool demandingFull = false; // Was full refresh specifically requested? (splash screens, etc) + bool missedHighPriorityUpdate = false; // Was a high priority update skipped for rate-limiting? + uint16_t partialRefreshCount = 0; // How many partials have occurred since last full refresh? + uint32_t lastUpdateMsec = 0; // When did the last update occur? + uint32_t prevImageHash = 0; // Used to check if update will change screen image (skippable or not) + int32_t prevBlackCount = 0; // How many black pixels were in the previous image + uint32_t erasedSinceFull = 0; // How many black pixels have been set back to white since last full-refresh? (roughly) + + // Set in variant.h + const uint32_t lowPriorityLimitMsec = (uint32_t)1000 * EINK_LOWPRIORITY_LIMIT_SECONDS; // Max rate for partial refreshes + const uint32_t highPriorityLimitMsec = (uint32_t)1000 * EINK_HIGHPRIORITY_LIMIT_SECONDS; // Max rate for full refreshes + const uint32_t partialRefreshLimit = EINK_PARTIAL_REPEAT_LIMIT; // Max consecutive partials, before full is triggered + +#else // !USE_EINK_DYNAMIC_PARTIAL + // Tolerate calls to these methods anywhere, just to be safe + void highPriority() {} + void lowPriority() {} + void demandFullRefresh() {} +#endif }; diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 417a6e4544..c0e55ea832 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -43,7 +43,7 @@ along with this program. If not, see . #include "sleep.h" #include "target_specific.h" -#if HAS_WIFI && !defined(ARCH_RASPBERRY_PI) +#if HAS_WIFI && !defined(ARCH_PORTDUINO) #include "mesh/wifi/WiFiAPClient.h" #endif @@ -52,6 +52,10 @@ along with this program. If not, see . #include "modules/esp32/StoreForwardModule.h" #endif +#if ARCH_PORTDUINO +#include "platform/portduino/PortduinoGlue.h" +#endif + #ifdef OLED_RU #include "fonts/OLEDDisplayFontsRU.h" #endif @@ -146,7 +150,7 @@ static void drawIconScreen(const char *upperMsg, OLEDDisplay *display, OLEDDispl // draw centered icon left to right and centered above the one line of app text display->drawXbm(x + (SCREEN_WIDTH - icon_width) / 2, y + (SCREEN_HEIGHT - FONT_HEIGHT_MEDIUM - icon_height) / 2 + 2, - icon_width, icon_height, (const uint8_t *)icon_bits); + icon_width, icon_height, icon_bits); display->setFont(FONT_MEDIUM); display->setTextAlignment(TEXT_ALIGN_LEFT); @@ -554,15 +558,20 @@ static void drawGPS(OLEDDisplay *display, int16_t x, int16_t y, const GPSStatus } } -// Draw status when gps is disabled by PMU +// Draw status when GPS is disabled or not present static void drawGPSpowerstat(OLEDDisplay *display, int16_t x, int16_t y, const GPSStatus *gps) { - String displayLine = "GPS disabled"; - int16_t xPos = display->getStringWidth(displayLine); - - if (!config.position.gps_enabled) { - display->drawString(x + xPos, y, displayLine); + String displayLine; + int pos; + if (y < FONT_HEIGHT_SMALL) { // Line 1: use short string + displayLine = config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT ? "No GPS" : "GPS off"; + pos = SCREEN_WIDTH - display->getStringWidth(displayLine); + } else { + displayLine = config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT ? "GPS not present" + : "GPS is disabled"; + pos = (SCREEN_WIDTH - display->getStringWidth(displayLine)) / 2; } + display->drawString(x + pos, y, displayLine); } static void drawGPSAltitude(OLEDDisplay *display, int16_t x, int16_t y, const GPSStatus *gps) @@ -590,7 +599,7 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const String displayLine = ""; if (!gps->getIsConnected() && !config.position.fixed_position) { - displayLine = "No GPS Module"; + displayLine = "No GPS present"; display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(displayLine))) / 2, y, displayLine); } else if (!gps->getHasLock() && !config.position.fixed_position) { displayLine = "No GPS Lock"; @@ -909,10 +918,40 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ } Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_OledType screenType, OLEDDISPLAY_GEOMETRY geometry) - : concurrency::OSThread("Screen"), address_found(address), model(screenType), geometry(geometry), cmdQueue(32), - dispdev(address.address, -1, -1, geometry, (address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE), - ui(&dispdev) + : concurrency::OSThread("Screen"), address_found(address), model(screenType), geometry(geometry), cmdQueue(32) { +#if defined(USE_SH1106) || defined(USE_SH1107) || defined(USE_SH1107_128_64) + dispdev = new SH1106Wire(address.address, -1, -1, geometry, + (address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE); +#elif defined(USE_SSD1306) + dispdev = new SSD1306Wire(address.address, -1, -1, geometry, + (address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE); +#elif defined(ST7735_CS) || defined(ILI9341_DRIVER) || defined(ST7789_CS) || defined(RAK14014) + dispdev = new TFTDisplay(address.address, -1, -1, geometry, + (address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE); +#elif defined(USE_EINK) + dispdev = new EInkDisplay(address.address, -1, -1, geometry, + (address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE); +#elif defined(USE_ST7567) + dispdev = new ST7567Wire(address.address, -1, -1, geometry, + (address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE); +#elif ARCH_PORTDUINO + if (settingsMap[displayPanel] != no_screen) { + LOG_DEBUG("Making TFTDisplay!\n"); + dispdev = new TFTDisplay(address.address, -1, -1, geometry, + (address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE); + } else { + dispdev = new AutoOLEDWire(address.address, -1, -1, geometry, + (address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE); + isAUTOOled = true; + } +#else + dispdev = new AutoOLEDWire(address.address, -1, -1, geometry, + (address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE); + isAUTOOled = true; +#endif + + ui = new OLEDDisplayUi(dispdev); cmdQueue.setReader(this); } @@ -925,8 +964,8 @@ void Screen::doDeepSleep() #ifdef USE_EINK static FrameCallback sleepFrames[] = {drawSleepScreen}; static const int sleepFrameCount = sizeof(sleepFrames) / sizeof(sleepFrames[0]); - ui.setFrames(sleepFrames, sleepFrameCount); - ui.update(); + ui->setFrames(sleepFrames, sleepFrameCount); + ui->update(); #endif setOn(false); } @@ -942,14 +981,16 @@ void Screen::handleSetOn(bool on) #ifdef T_WATCH_S3 PMU->enablePowerOutput(XPOWERS_ALDO2); #endif - dispdev.displayOn(); - dispdev.displayOn(); +#if !ARCH_PORTDUINO + dispdev->displayOn(); +#endif + dispdev->displayOn(); enabled = true; setInterval(0); // Draw ASAP runASAP = true; } else { LOG_INFO("Turning off screen\n"); - dispdev.displayOff(); + dispdev->displayOff(); #ifdef T_WATCH_S3 PMU->disablePowerOutput(XPOWERS_ALDO2); #endif @@ -966,32 +1007,33 @@ void Screen::setup() useDisplay = true; #ifdef AutoOLEDWire_h - dispdev.setDetected(model); + if (isAUTOOled) + static_cast(dispdev)->setDetected(model); #endif #ifdef USE_SH1107_128_64 - dispdev.setSubtype(7); + static_cast(dispdev)->setSubtype(7); #endif // Initialising the UI will init the display too. - ui.init(); + ui->init(); - displayWidth = dispdev.width(); - displayHeight = dispdev.height(); + displayWidth = dispdev->width(); + displayHeight = dispdev->height(); - ui.setTimePerTransition(0); + ui->setTimePerTransition(0); - ui.setIndicatorPosition(BOTTOM); + ui->setIndicatorPosition(BOTTOM); // Defines where the first frame is located in the bar. - ui.setIndicatorDirection(LEFT_RIGHT); - ui.setFrameAnimation(SLIDE_LEFT); + ui->setIndicatorDirection(LEFT_RIGHT); + ui->setFrameAnimation(SLIDE_LEFT); // Don't show the page swipe dots while in boot screen. - ui.disableAllIndicators(); + ui->disableAllIndicators(); // Store a pointer to Screen so we can get to it from static functions. - ui.getUiState()->userData = this; + ui->getUiState()->userData = this; // Set the utf8 conversion function - dispdev.setFontTableLookupFunction(customFontTableLookup); + dispdev->setFontTableLookupFunction(customFontTableLookup); if (strlen(oemStore.oem_text) > 0) logo_timeout *= 2; @@ -999,23 +1041,27 @@ void Screen::setup() // Add frames. static FrameCallback bootFrames[] = {drawBootScreen}; static const int bootFrameCount = sizeof(bootFrames) / sizeof(bootFrames[0]); - ui.setFrames(bootFrames, bootFrameCount); + ui->setFrames(bootFrames, bootFrameCount); // No overlays. - ui.setOverlays(nullptr, 0); + ui->setOverlays(nullptr, 0); // Require presses to switch between frames. - ui.disableAutoTransition(); + ui->disableAutoTransition(); // Set up a log buffer with 3 lines, 32 chars each. - dispdev.setLogBuffer(3, 32); + dispdev->setLogBuffer(3, 32); #ifdef SCREEN_MIRROR - dispdev.mirrorScreen(); + dispdev->mirrorScreen(); #else // Standard behaviour is to FLIP the screen (needed on T-Beam). If this config item is set, unflip it, and thereby logically // flip it. If you have a headache now, you're welcome. if (!config.display.flip_screen) { - dispdev.flipScreenVertically(); +#if defined(ST7735_CS) || defined(ILI9341_DRIVER) || defined(ST7789_CS) || defined(RAK14014) + static_cast(dispdev)->flipScreenVertically(); +#else + dispdev->flipScreenVertically(); +#endif } #endif @@ -1023,20 +1069,30 @@ void Screen::setup() uint8_t dmac[6]; getMacAddr(dmac); snprintf(ourId, sizeof(ourId), "%02x%02x", dmac[4], dmac[5]); +#if ARCH_PORTDUINO + handleSetOn(false); // force clean init +#endif // Turn on the display. handleSetOn(true); // On some ssd1306 clones, the first draw command is discarded, so draw it // twice initially. Skip this for EINK Displays to save a few seconds during boot - ui.update(); + ui->update(); #ifndef USE_EINK - ui.update(); + ui->update(); #endif serialSinceMsec = millis(); -#if HAS_TOUCHSCREEN - touchScreenImpl1 = new TouchScreenImpl1(dispdev.getWidth(), dispdev.getHeight(), dispdev.getTouch); +#if ARCH_PORTDUINO + if (settingsMap[touchscreenModule]) { + touchScreenImpl1 = + new TouchScreenImpl1(dispdev->getWidth(), dispdev->getHeight(), static_cast(dispdev)->getTouch); + touchScreenImpl1->init(); + } +#elif HAS_TOUCHSCREEN + touchScreenImpl1 = + new TouchScreenImpl1(dispdev->getWidth(), dispdev->getHeight(), static_cast(dispdev)->getTouch); touchScreenImpl1->init(); #endif @@ -1057,7 +1113,7 @@ void Screen::forceDisplay() { // Nasty hack to force epaper updates for 'key' frames. FIXME, cleanup. #ifdef USE_EINK - dispdev.forceDisplay(); + static_cast(dispdev)->forceDisplay(); #endif } @@ -1088,10 +1144,10 @@ int32_t Screen::runOnce() // Change frames. static FrameCallback bootOEMFrames[] = {drawOEMBootScreen}; static const int bootOEMFrameCount = sizeof(bootOEMFrames) / sizeof(bootOEMFrames[0]); - ui.setFrames(bootOEMFrames, bootOEMFrameCount); - ui.update(); + ui->setFrames(bootOEMFrames, bootOEMFrameCount); + ui->update(); #ifndef USE_EINK - ui.update(); + ui->update(); #endif showingOEMBootScreen = false; } @@ -1164,16 +1220,16 @@ int32_t Screen::runOnce() // this must be before the frameState == FIXED check, because we always // want to draw at least one FIXED frame before doing forceDisplay - ui.update(); + ui->update(); // Switch to a low framerate (to save CPU) when we are not in transition // but we should only call setTargetFPS when framestate changes, because // otherwise that breaks animations. - if (targetFramerate != IDLE_FRAMERATE && ui.getUiState()->frameState == FIXED) { - // oldFrameState = ui.getUiState()->frameState; + if (targetFramerate != IDLE_FRAMERATE && ui->getUiState()->frameState == FIXED) { + // oldFrameState = ui->getUiState()->frameState; targetFramerate = IDLE_FRAMERATE; - ui.setTargetFPS(targetFramerate); + ui->setTargetFPS(targetFramerate); forceDisplay(); } @@ -1189,7 +1245,7 @@ int32_t Screen::runOnce() } // LOG_DEBUG("want fps %d, fixed=%d\n", targetFramerate, - // ui.getUiState()->frameState); If we are scrolling we need to be called + // ui->getUiState()->frameState); If we are scrolling we need to be called // soon, otherwise just 1 fps (to save CPU) We also ask to be called twice // as fast as we really need so that any rounding errors still result with // the correct framerate @@ -1221,8 +1277,8 @@ void Screen::setSSLFrames() if (address_found.address) { // LOG_DEBUG("showing SSL frames\n"); static FrameCallback sslFrames[] = {drawSSLScreen}; - ui.setFrames(sslFrames, 1); - ui.update(); + ui->setFrames(sslFrames, 1); + ui->update(); } } @@ -1297,7 +1353,7 @@ void Screen::setFrames() // call a method on debugInfoScreen object (for more details) normalFrames[numframes++] = &Screen::drawDebugInfoSettingsTrampoline; -#if HAS_WIFI && !defined(ARCH_RASPBERRY_PI) +#if HAS_WIFI && !defined(ARCH_PORTDUINO) if (isWifiAvailable()) { // call a method on debugInfoScreen object (for more details) normalFrames[numframes++] = &Screen::drawDebugInfoWiFiTrampoline; @@ -1306,8 +1362,8 @@ void Screen::setFrames() LOG_DEBUG("Finished building frames. numframes: %d\n", numframes); - ui.setFrames(normalFrames, numframes); - ui.enableAllIndicators(); + ui->setFrames(normalFrames, numframes); + ui->enableAllIndicators(); prevFrame = -1; // Force drawNodeInfo to pick a new node (because our list // just changed) @@ -1327,8 +1383,8 @@ void Screen::handleStartBluetoothPinScreen(uint32_t pin) void Screen::setFrameImmediateDraw(FrameCallback *drawFrames) { - ui.disableAllIndicators(); - ui.setFrames(drawFrames, 1); + ui->disableAllIndicators(); + ui->setFrames(drawFrames, 1); setFastFramerate(); } @@ -1370,17 +1426,17 @@ void Screen::blink() { setFastFramerate(); uint8_t count = 10; - dispdev.setBrightness(254); + dispdev->setBrightness(254); while (count > 0) { - dispdev.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); - dispdev.display(); + dispdev->fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); + dispdev->display(); delay(50); - dispdev.clear(); - dispdev.display(); + dispdev->clear(); + dispdev->display(); delay(50); count = count - 1; } - dispdev.setBrightness(brightness); + dispdev->setBrightness(brightness); } std::string Screen::drawTimeDelta(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds) @@ -1408,15 +1464,15 @@ void Screen::handlePrint(const char *text) if (!useDisplay || !showingNormalScreen) return; - dispdev.print(text); + dispdev->print(text); } void Screen::handleOnPress() { // If screen was off, just wake it, otherwise advance to next frame // If we are in a transition, the press must have bounced, drop it. - if (ui.getUiState()->frameState == FIXED) { - ui.nextFrame(); + if (ui->getUiState()->frameState == FIXED) { + ui->nextFrame(); lastScreenTransition = millis(); setFastFramerate(); } @@ -1426,8 +1482,8 @@ void Screen::handleShowPrevFrame() { // If screen was off, just wake it, otherwise go back to previous frame // If we are in a transition, the press must have bounced, drop it. - if (ui.getUiState()->frameState == FIXED) { - ui.previousFrame(); + if (ui->getUiState()->frameState == FIXED) { + ui->previousFrame(); lastScreenTransition = millis(); setFastFramerate(); } @@ -1437,8 +1493,8 @@ void Screen::handleShowNextFrame() { // If screen was off, just wake it, otherwise advance to next frame // If we are in a transition, the press must have bounced, drop it. - if (ui.getUiState()->frameState == FIXED) { - ui.nextFrame(); + if (ui->getUiState()->frameState == FIXED) { + ui->nextFrame(); lastScreenTransition = millis(); setFastFramerate(); } @@ -1453,7 +1509,7 @@ void Screen::setFastFramerate() // We are about to start a transition so speed up fps targetFramerate = SCREEN_TRANSITION_FRAMERATE; - ui.setTargetFPS(targetFramerate); + ui->setTargetFPS(targetFramerate); setInterval(0); // redraw ASAP runASAP = true; } @@ -1498,7 +1554,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 drawNodes(display, x + (SCREEN_WIDTH * 0.25), y + 3, nodeStatus); } // Display GPS status - if (!config.position.gps_enabled) { + if (config.position.gps_mode != meshtastic_Config_PositionConfig_GpsMode_ENABLED) { drawGPSpowerstat(display, x, y + 2, gpsStatus); } else { if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_DEFAULT) { @@ -1540,7 +1596,8 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 } #endif } else { -#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS)) && \ + // TODO: Raspberry Pi supports more than just the one screen size +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || ARCH_PORTDUINO) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8, imgInfoL1); @@ -1567,7 +1624,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 // Jm void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { -#if HAS_WIFI && !defined(ARCH_RASPBERRY_PI) +#if HAS_WIFI && !defined(ARCH_PORTDUINO) const char *wifiName = config.network.wifi_ssid; display->setFont(FONT_SMALL); @@ -1725,7 +1782,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat char chUtil[13]; snprintf(chUtil, sizeof(chUtil), "ChUtil %2.0f%%", airTime->channelUtilizationPercent()); display->drawString(x + SCREEN_WIDTH - display->getStringWidth(chUtil), y + FONT_HEIGHT_SMALL * 1, chUtil); - if (config.position.gps_enabled) { + if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED) { // Line 3 if (config.display.gps_format != meshtastic_Config_DisplayConfig_GpsCoordinateFormat_DMS) // if DMS then don't draw altitude @@ -1734,10 +1791,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat // Line 4 drawGPScoordinates(display, x, y + FONT_HEIGHT_SMALL * 3, gpsStatus); } else { - drawGPSpowerstat(display, x - (SCREEN_WIDTH / 4), y + FONT_HEIGHT_SMALL * 2, gpsStatus); -#ifdef GPS_POWER_TOGGLE - display->drawString(x + 30, (y + FONT_HEIGHT_SMALL * 3), " by button"); -#endif + drawGPSpowerstat(display, x, y + FONT_HEIGHT_SMALL * 2, gpsStatus); } /* Display a heartbeat pixel that blinks every time the frame is redrawn */ #ifdef SHOW_REDRAWS @@ -1780,7 +1834,7 @@ int Screen::handleUIFrameEvent(const UIFrameEvent *event) setFastFramerate(); // TODO: We might also want switch to corresponding frame, // but we don't know the exact frame number. - // ui.switchToFrame(0); + // ui->switchToFrame(0); } } diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index 554fa0aeb6..baee4b1400 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -324,6 +324,8 @@ class Screen : public concurrency::OSThread // Called periodically from the main loop. int32_t runOnce() final; + bool isAUTOOled = false; + private: struct ScreenCmd { Cmd cmd; @@ -385,22 +387,10 @@ class Screen : public concurrency::OSThread DebugInfo debugInfo; /// Display device + OLEDDisplay *dispdev; -#if defined(USE_SH1106) || defined(USE_SH1107) || defined(USE_SH1107_128_64) - SH1106Wire dispdev; -#elif defined(USE_SSD1306) - SSD1306Wire dispdev; -#elif defined(ST7735_CS) || defined(ILI9341_DRIVER) || defined(ST7789_CS) || defined(RAK14014) - TFTDisplay dispdev; -#elif defined(USE_EINK) - EInkDisplay dispdev; -#elif defined(USE_ST7567) - ST7567Wire dispdev; -#else - AutoOLEDWire dispdev; -#endif /// UI helper for rendering to frames and switching between them - OLEDDisplayUi ui; + OLEDDisplayUi *ui; }; } // namespace graphics diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 618880a5cb..9475e0296d 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -1,5 +1,8 @@ #include "configuration.h" #include "main.h" +#if ARCH_PORTDUINO +#include "platform/portduino/PortduinoGlue.h" +#endif #ifndef TFT_BACKLIGHT_ON #define TFT_BACKLIGHT_ON HIGH @@ -16,6 +19,10 @@ #define TFT_BL ST7735_BACKLIGHT_EN #endif +#ifndef TFT_INVERT +#define TFT_INVERT true +#endif + class LGFX : public lgfx::LGFX_Device { lgfx::Panel_ST7735S _panel_instance; @@ -65,7 +72,7 @@ class LGFX : public lgfx::LGFX_Device cfg.dummy_read_pixel = 8; // Number of bits for dummy read before pixel readout cfg.dummy_read_bits = 1; // Number of bits for dummy read before non-pixel data read cfg.readable = true; // Set to true if data can be read - cfg.invert = true; // Set to true if the light/darkness of the panel is reversed + cfg.invert = TFT_INVERT; // Set to true if the light/darkness of the panel is reversed cfg.rgb_order = false; // Set to true if the panel's red and blue are swapped cfg.dlen_16bit = false; // Set to true for panels that transmit data length in 16-bit units with 16-bit parallel or SPI @@ -83,11 +90,9 @@ class LGFX : public lgfx::LGFX_Device auto cfg = _light_instance.config(); // Gets a structure for backlight settings. #ifdef ST7735_BL_V03 - if (heltec_version == 3) { - cfg.pin_bl = ST7735_BL_V03; - } else { - cfg.pin_bl = ST7735_BL_V05; - } + cfg.pin_bl = ST7735_BL_V03; +#elif defined(ST7735_BL_V05) + cfg.pin_bl = ST7735_BL_V05; #else cfg.pin_bl = ST7735_BL; // Pin number to which the backlight is connected #endif @@ -103,11 +108,11 @@ class LGFX : public lgfx::LGFX_Device } }; -static LGFX tft; +static LGFX *tft = nullptr; #elif defined(RAK14014) #include -TFT_eSPI tft = TFT_eSPI(); +TFT_eSPI *tft = nullptr; #elif defined(ST7789_CS) #include // Graphics and font library for ST7735 driver chip @@ -233,7 +238,7 @@ class LGFX : public lgfx::LGFX_Device } }; -static LGFX tft; +static LGFX *tft = nullptr; #elif defined(ILI9341_DRIVER) @@ -322,23 +327,99 @@ class LGFX : public lgfx::LGFX_Device } }; -static LGFX tft; +static LGFX *tft = nullptr; #elif defined(ST7735_CS) #include // Graphics and font library for ILI9341 driver chip -static TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h +static TFT_eSPI *tft = nullptr; // Invoke library, pins defined in User_Setup.h +#elif ARCH_PORTDUINO +#include // Graphics and font library for ST7735 driver chip + +class LGFX : public lgfx::LGFX_Device +{ + lgfx::Panel_LCD *_panel_instance; + lgfx::Bus_SPI _bus_instance; + + lgfx::ITouch *_touch_instance; + public: + LGFX(void) + { + if (settingsMap[displayPanel] == st7789) + _panel_instance = new lgfx::Panel_ST7789; + else if (settingsMap[displayPanel] == st7735) + _panel_instance = new lgfx::Panel_ST7735; + else if (settingsMap[displayPanel] == st7735s) + _panel_instance = new lgfx::Panel_ST7735S; + else if (settingsMap[displayPanel] == ili9341) + _panel_instance = new lgfx::Panel_ILI9341; + auto buscfg = _bus_instance.config(); + buscfg.spi_mode = 0; + + buscfg.pin_dc = settingsMap[displayDC]; // Set SPI DC pin number (-1 = disable) + + _bus_instance.config(buscfg); // applies the set value to the bus. + _panel_instance->setBus(&_bus_instance); // set the bus on the panel. + + auto cfg = _panel_instance->config(); // Gets a structure for display panel settings. + LOG_DEBUG("Height: %d, Width: %d \n", settingsMap[displayHeight], settingsMap[displayWidth]); + cfg.pin_cs = settingsMap[displayCS]; // Pin number where CS is connected (-1 = disable) + cfg.pin_rst = settingsMap[displayReset]; + cfg.panel_width = settingsMap[displayWidth]; // actual displayable width + cfg.panel_height = settingsMap[displayHeight]; // actual displayable height + cfg.offset_x = settingsMap[displayOffsetX]; // Panel offset amount in X direction + cfg.offset_y = settingsMap[displayOffsetY]; // Panel offset amount in Y direction + cfg.offset_rotation = 0; // Rotation direction value offset 0~7 (4~7 is mirrored) + cfg.invert = settingsMap[displayInvert]; // Set to true if the light/darkness of the panel is reversed + + _panel_instance->config(cfg); + + // Configure settings for touch control. + if (settingsMap[touchscreenModule]) { + if (settingsMap[touchscreenModule] == xpt2046) { + _touch_instance = new lgfx::Touch_XPT2046; + } else if (settingsMap[touchscreenModule] == stmpe610) { + _touch_instance = new lgfx::Touch_STMPE610; + } + auto touch_cfg = _touch_instance->config(); + + touch_cfg.pin_cs = settingsMap[touchscreenCS]; + touch_cfg.x_min = 0; + touch_cfg.x_max = settingsMap[displayHeight] - 1; + touch_cfg.y_min = 0; + touch_cfg.y_max = settingsMap[displayWidth] - 1; + touch_cfg.pin_int = settingsMap[touchscreenIRQ]; + touch_cfg.bus_shared = true; + touch_cfg.offset_rotation = 1; + + _touch_instance->config(touch_cfg); + _panel_instance->setTouch(_touch_instance); + } + + setPanel(_panel_instance); // Sets the panel to use. + } +}; + +static LGFX *tft = nullptr; #endif -#if defined(ST7735_CS) || defined(ST7789_CS) || defined(ILI9341_DRIVER) || defined(RAK14014) +#if defined(ST7735_CS) || defined(ST7789_CS) || defined(ILI9341_DRIVER) || defined(RAK14014) || ARCH_PORTDUINO #include "SPILock.h" #include "TFTDisplay.h" #include TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY geometry, HW_I2C i2cBus) { -#ifdef SCREEN_ROTATE + LOG_DEBUG("TFTDisplay!\n"); +#if ARCH_PORTDUINO + if (settingsMap[displayRotate]) { + setGeometry(GEOMETRY_RAWMODE, settingsMap[configNames::displayHeight], settingsMap[configNames::displayWidth]); + } else { + setGeometry(GEOMETRY_RAWMODE, settingsMap[configNames::displayWidth], settingsMap[configNames::displayHeight]); + } + +#elif defined(SCREEN_ROTATE) setGeometry(GEOMETRY_RAWMODE, TFT_HEIGHT, TFT_WIDTH); #else setGeometry(GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT); @@ -346,19 +427,26 @@ TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY g } // Write the buffer to the display memory -void TFTDisplay::display(void) +void TFTDisplay::display(bool fromBlank) { + if (fromBlank) + tft->fillScreen(TFT_BLACK); + // tft->clear(); concurrency::LockGuard g(spiLock); uint16_t x, y; for (y = 0; y < displayHeight; y++) { for (x = 0; x < displayWidth; x++) { - // get src pixel in the page based ordering the OLED lib uses FIXME, super inefficent auto isset = buffer[x + (y / 8) * displayWidth] & (1 << (y & 7)); - auto dblbuf_isset = buffer_back[x + (y / 8) * displayWidth] & (1 << (y & 7)); - if (isset != dblbuf_isset) { - tft.drawPixel(x, y, isset ? TFT_MESH : TFT_BLACK); + if (!fromBlank) { + // get src pixel in the page based ordering the OLED lib uses FIXME, super inefficent + auto dblbuf_isset = buffer_back[x + (y / 8) * displayWidth] & (1 << (y & 7)); + if (isset != dblbuf_isset) { + tft->drawPixel(x, y, isset ? TFT_MESH : TFT_BLACK); + } + } else if (isset) { + tft->drawPixel(x, y, TFT_MESH); } } } @@ -377,57 +465,57 @@ void TFTDisplay::sendCommand(uint8_t com) // handle display on/off directly switch (com) { case DISPLAYON: { -#if defined(ST7735_BACKLIGHT_EN_V03) && defined(TFT_BACKLIGHT_ON) - if (heltec_version == 3) { - digitalWrite(ST7735_BACKLIGHT_EN_V03, TFT_BACKLIGHT_ON); - } else { - digitalWrite(ST7735_BACKLIGHT_EN_V05, TFT_BACKLIGHT_ON); - } +#if ARCH_PORTDUINO + display(true); + if (settingsMap[displayBacklight] > 0) + digitalWrite(settingsMap[displayBacklight], TFT_BACKLIGHT_ON); +#elif defined(ST7735_BL_V03) + digitalWrite(ST7735_BL_V03, TFT_BACKLIGHT_ON); +#elif defined(ST7735_BL_V05) + pinMode(ST7735_BL_V05, OUTPUT); + digitalWrite(ST7735_BL_V05, TFT_BACKLIGHT_ON); #endif #if defined(TFT_BL) && defined(TFT_BACKLIGHT_ON) digitalWrite(TFT_BL, TFT_BACKLIGHT_ON); #endif + #ifdef VTFT_CTRL_V03 - if (heltec_version == 3) { - digitalWrite(VTFT_CTRL_V03, LOW); - } else { - digitalWrite(VTFT_CTRL_V05, LOW); - } + digitalWrite(VTFT_CTRL_V03, LOW); #endif + #ifdef VTFT_CTRL digitalWrite(VTFT_CTRL, LOW); #endif #ifdef RAK14014 #elif !defined(M5STACK) - tft.setBrightness(128); + tft->setBrightness(172); #endif break; } case DISPLAYOFF: { -#if defined(ST7735_BACKLIGHT_EN_V03) && defined(TFT_BACKLIGHT_ON) - if (heltec_version == 3) { - digitalWrite(ST7735_BACKLIGHT_EN_V03, !TFT_BACKLIGHT_ON); - } else { - digitalWrite(ST7735_BACKLIGHT_EN_V05, !TFT_BACKLIGHT_ON); - } +#if ARCH_PORTDUINO + tft->clear(); + if (settingsMap[displayBacklight] > 0) + digitalWrite(settingsMap[displayBacklight], !TFT_BACKLIGHT_ON); +#elif defined(ST7735_BL_V03) + digitalWrite(ST7735_BL_V03, !TFT_BACKLIGHT_ON); +#elif defined(ST7735_BL_V05) + pinMode(ST7735_BL_V05, OUTPUT); + digitalWrite(ST7735_BL_V05, !TFT_BACKLIGHT_ON); #endif #if defined(TFT_BL) && defined(TFT_BACKLIGHT_ON) digitalWrite(TFT_BL, !TFT_BACKLIGHT_ON); #endif #ifdef VTFT_CTRL_V03 - if (heltec_version == 3) { - digitalWrite(VTFT_CTRL_V03, HIGH); - } else { - digitalWrite(VTFT_CTRL_V05, HIGH); - } + digitalWrite(VTFT_CTRL_V03, HIGH); #endif #ifdef VTFT_CTRL digitalWrite(VTFT_CTRL, HIGH); #endif #ifdef RAK14014 #elif !defined(M5STACK) - tft.setBrightness(0); + tft->setBrightness(0); #endif break; } @@ -442,7 +530,7 @@ void TFTDisplay::flipScreenVertically() { #if defined(T_WATCH_S3) LOG_DEBUG("Flip TFT vertically\n"); // T-Watch S3 right-handed orientation - tft.setRotation(0); + tft->setRotation(0); #endif } @@ -450,7 +538,7 @@ bool TFTDisplay::hasTouch(void) { #ifdef RAK14014 #elif !defined(M5STACK) - return tft.touch() != nullptr; + return tft->touch() != nullptr; #else return false; #endif @@ -460,7 +548,7 @@ bool TFTDisplay::getTouch(int16_t *x, int16_t *y) { #ifdef RAK14014 #elif !defined(M5STACK) - return tft.getTouch(x, y); + return tft->getTouch(x, y); #else return false; #endif @@ -476,6 +564,11 @@ bool TFTDisplay::connect() { concurrency::LockGuard g(spiLock); LOG_INFO("Doing TFT init\n"); +#ifdef RAK14014 + tft = new TFT_eSPI; +#else + tft = new LGFX; +#endif #ifdef TFT_BL pinMode(TFT_BL, OUTPUT); @@ -485,34 +578,31 @@ bool TFTDisplay::connect() LOG_INFO("Power to TFT Backlight\n"); #endif -#ifdef ST7735_BACKLIGHT_EN_V03 - if (heltec_version == 3) { - pinMode(ST7735_BACKLIGHT_EN_V03, OUTPUT); - digitalWrite(ST7735_BACKLIGHT_EN_V03, TFT_BACKLIGHT_ON); - } else { - pinMode(ST7735_BACKLIGHT_EN_V05, OUTPUT); - digitalWrite(ST7735_BACKLIGHT_EN_V05, TFT_BACKLIGHT_ON); - } +#ifdef ST7735_BL_V03 + digitalWrite(ST7735_BL_V03, TFT_BACKLIGHT_ON); +#elif defined(ST7735_BL_V05) + pinMode(ST7735_BL_V05, OUTPUT); + digitalWrite(ST7735_BL_V05, TFT_BACKLIGHT_ON); #endif - tft.init(); + tft->init(); #if defined(M5STACK) - tft.setRotation(0); + tft->setRotation(0); #elif defined(RAK14014) - tft.setRotation(1); - tft.setSwapBytes(true); -// tft.fillScreen(TFT_BLACK); -#elif defined(T_DECK) || defined(PICOMPUTER_S3) - tft.setRotation(1); // T-Deck has the TFT in landscape + tft->setRotation(1); + tft->setSwapBytes(true); +// tft->fillScreen(TFT_BLACK); +#elif defined(T_DECK) || defined(PICOMPUTER_S3) || defined(CHATTER_2) + tft->setRotation(1); // T-Deck has the TFT in landscape #elif defined(T_WATCH_S3) - tft.setRotation(2); // T-Watch S3 left-handed orientation + tft->setRotation(2); // T-Watch S3 left-handed orientation #else - tft.setRotation(3); // Orient horizontal and wide underneath the silkscreen name label + tft->setRotation(3); // Orient horizontal and wide underneath the silkscreen name label #endif - tft.fillScreen(TFT_BLACK); + tft->fillScreen(TFT_BLACK); return true; } -#endif +#endif \ No newline at end of file diff --git a/src/graphics/TFTDisplay.h b/src/graphics/TFTDisplay.h index 8c9a9b62e7..3d6ea6cc62 100644 --- a/src/graphics/TFTDisplay.h +++ b/src/graphics/TFTDisplay.h @@ -20,7 +20,8 @@ class TFTDisplay : public OLEDDisplay TFTDisplay(uint8_t, int, int, OLEDDISPLAY_GEOMETRY, HW_I2C); // Write the buffer to the display memory - virtual void display(void) override; + virtual void display() override { display(false); }; + virtual void display(bool fromBlank); // Turn the display upside down virtual void flipScreenVertically(); diff --git a/src/graphics/images.h b/src/graphics/images.h index a1191076bd..207fc3a86c 100644 --- a/src/graphics/images.h +++ b/src/graphics/images.h @@ -14,7 +14,7 @@ const uint8_t imgUser[] PROGMEM = {0x3C, 0x42, 0x99, 0xA5, 0xA5, 0x99, 0x42, 0x3 const uint8_t imgPositionEmpty[] PROGMEM = {0x20, 0x30, 0x28, 0x24, 0x42, 0xFF}; const uint8_t imgPositionSolid[] PROGMEM = {0x20, 0x30, 0x38, 0x3C, 0x7E, 0xFF}; -#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS)) && \ +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || ARCH_PORTDUINO) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) const uint8_t imgQuestionL1[] PROGMEM = {0xff, 0x01, 0x01, 0x32, 0x7b, 0x49, 0x49, 0x6f, 0x26, 0x01, 0x01, 0xff}; const uint8_t imgQuestionL2[] PROGMEM = {0x0f, 0x08, 0x08, 0x08, 0x06, 0x0f, 0x0f, 0x06, 0x08, 0x08, 0x08, 0x0f}; @@ -30,4 +30,4 @@ const uint8_t imgQuestion[] PROGMEM = {0xbf, 0x41, 0xc0, 0x8b, 0xdb, 0x70, 0xa1, const uint8_t imgSF[] PROGMEM = {0xd2, 0xb7, 0xad, 0xbb, 0x92, 0x01, 0xfd, 0xfd, 0x15, 0x85, 0xf5}; #endif -#include "img/icon.xbm" +#include "img/icon.xbm" \ No newline at end of file diff --git a/src/graphics/img/icon.xbm b/src/graphics/img/icon.xbm index 2b698e4c9c..297f31ed6f 100644 --- a/src/graphics/img/icon.xbm +++ b/src/graphics/img/icon.xbm @@ -1,6 +1,6 @@ #define icon_width 50 #define icon_height 28 -static char icon_bits[] = { +static uint8_t icon_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x80, 0x07, 0xC0, 0x07, 0x00, 0x00, 0x00, 0xC0, 0x1F, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0xE0, 0x0F, 0xE0, 0x0F, 0x00, 0x00, 0x00, @@ -17,4 +17,4 @@ static char icon_bits[] = { 0xFE, 0x00, 0x00, 0xFC, 0x01, 0x7E, 0x00, 0x7F, 0x00, 0x00, 0xF8, 0x01, 0x7E, 0x00, 0x3E, 0x00, 0x00, 0xF8, 0x01, 0x38, 0x00, 0x3C, 0x00, 0x00, 0x70, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, }; + 0x00, 0x00, 0x00, 0x00, }; \ No newline at end of file diff --git a/src/input/LinuxInput.cpp b/src/input/LinuxInput.cpp new file mode 100644 index 0000000000..d2a94e94ea --- /dev/null +++ b/src/input/LinuxInput.cpp @@ -0,0 +1,183 @@ +#include "configuration.h" +#if ARCH_PORTDUINO +#include "LinuxInput.h" +#include "platform/portduino/PortduinoGlue.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Inspired by https://github.com/librerpi/rpi-tools/blob/master/keyboard-proxy/main.c which is GPL-v2 + +LinuxInput::LinuxInput(const char *name) : concurrency::OSThread(name) +{ + this->_originName = name; +} + +void LinuxInput::deInit() +{ + close(fd); +} + +int32_t LinuxInput::runOnce() +{ + + if (firstTime) { + if (settingsStrings[keyboardDevice] == "") + return disable(); + fd = open(settingsStrings[keyboardDevice].c_str(), O_RDWR); + if (fd < 0) + return disable(); + ret = ioctl(fd, EVIOCGRAB, (void *)1); + if (ret != 0) + return disable(); + + epollfd = epoll_create1(0); + assert(epollfd >= 0); + + ev.events = EPOLLIN; + ev.data.fd = fd; + if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev)) { + perror("unable to epoll add"); + return disable(); + } + // This is the first time the OSThread library has called this function, so do port setup + firstTime = 0; + } + + int nfds = epoll_wait(epollfd, events, MAX_EVENTS, 1); + if (nfds < 0) { + printf("%d ", nfds); + perror("epoll_wait failed"); + return disable(); + } else if (nfds == 0) { + return 50; + } + + int keys = 0; + memset(report, 0, 8); + for (int i = 0; i < nfds; i++) { + + struct input_event ev[64]; + int rd = read(events[i].data.fd, ev, sizeof(ev)); + assert(rd > ((signed int)sizeof(struct input_event))); + for (int j = 0; j < rd / ((signed int)sizeof(struct input_event)); j++) { + InputEvent e; + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; + e.source = this->_originName; + e.kbchar = 0; + unsigned int type, code; + type = ev[j].type; + code = ev[j].code; + int value = ev[j].value; + // printf("Event: time %ld.%06ld, ", ev[j].time.tv_sec, ev[j].time.tv_usec); + + if (type == EV_KEY) { + uint8_t mod = 0; + + switch (code) { + case KEY_LEFTCTRL: + mod = 0x01; + break; + case KEY_RIGHTCTRL: + mod = 0x10; + break; + case KEY_LEFTSHIFT: + mod = 0x02; + break; + case KEY_RIGHTSHIFT: + mod = 0x20; + break; + case KEY_LEFTALT: + mod = 0x04; + break; + case KEY_RIGHTALT: + mod = 0x40; + break; + case KEY_LEFTMETA: + mod = 0x08; + break; + } + if (value == 1) { + switch (code) { + case KEY_LEFTCTRL: + mod = 0x01; + break; + case KEY_RIGHTCTRL: + mod = 0x10; + break; + case KEY_LEFTSHIFT: + mod = 0x02; + break; + case KEY_RIGHTSHIFT: + mod = 0x20; + break; + case KEY_LEFTALT: + mod = 0x04; + break; + case KEY_RIGHTALT: + mod = 0x40; + break; + case KEY_LEFTMETA: + mod = 0x08; + break; + case KEY_ESC: // ESC + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL; + break; + case KEY_BACK: // Back + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_BACK; + // e.kbchar = key; + break; + + case KEY_UP: // Up + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP; + break; + case KEY_DOWN: // Down + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_DOWN; + break; + case KEY_LEFT: // Left + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT; + break; + e.kbchar = 0xb4; + case KEY_RIGHT: // Right + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT; + break; + e.kbchar = 0xb7; + case KEY_ENTER: // Enter + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT; + break; + default: // all other keys + if (keymap[code]) { + e.inputEvent = ANYKEY; + e.kbchar = keymap[code]; + } + break; + } + } + if (ev[j].value) { + modifiers |= mod; + } else { + modifiers &= ~mod; + } + report[0] = modifiers; + } + if (e.inputEvent != meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE) { + if (e.inputEvent == ANYKEY && (modifiers && 0x22)) + e.kbchar = uppers[e.kbchar]; // doesn't get punctuation. Meh. + this->notifyObservers(&e); + } + } + } + + return 50; // Keyscan every 50msec to avoid key bounce +} + +#endif \ No newline at end of file diff --git a/src/input/LinuxInput.h b/src/input/LinuxInput.h new file mode 100644 index 0000000000..aa1e8e3402 --- /dev/null +++ b/src/input/LinuxInput.h @@ -0,0 +1,65 @@ +#pragma once +#if ARCH_PORTDUINO +#include "InputBroker.h" +#include "concurrency/OSThread.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_EVENTS 10 + +class LinuxInput : public Observable, public concurrency::OSThread +{ + public: + explicit LinuxInput(const char *name); + void deInit(); // Strictly for cleanly "rebooting" the binary on native + + protected: + virtual int32_t runOnce() override; + + private: + const char *_originName; + bool firstTime = 1; + int shift = 0; + char key = 0; + char prevkey = 0; + + InputEvent eventqueue[50]; // The Linux API will return multiple keypresses at a time. Queue them to not miss any. + int queue_length = 0; + int queue_progress = 0; + + struct epoll_event events[MAX_EVENTS]; + int fd; + int ret; + uint8_t report[8]; + int epollfd; + struct epoll_event ev; + uint8_t modifiers = 0; + std::map keymap{ + {KEY_A, 'a'}, {KEY_B, 'b'}, {KEY_C, 'c'}, {KEY_D, 'd'}, {KEY_E, 'e'}, + {KEY_F, 'f'}, {KEY_G, 'g'}, {KEY_H, 'h'}, {KEY_I, 'i'}, {KEY_J, 'j'}, + {KEY_K, 'k'}, {KEY_L, 'l'}, {KEY_M, 'm'}, {KEY_N, 'n'}, {KEY_O, 'o'}, + {KEY_P, 'p'}, {KEY_Q, 'q'}, {KEY_R, 'r'}, {KEY_S, 's'}, {KEY_T, 't'}, + {KEY_U, 'u'}, {KEY_V, 'v'}, {KEY_W, 'w'}, {KEY_X, 'x'}, {KEY_Y, 'y'}, + {KEY_Z, 'z'}, {KEY_BACKSPACE, 0x08}, {KEY_SPACE, ' '}, {KEY_1, '1'}, {KEY_2, '2'}, + {KEY_3, '3'}, {KEY_4, '4'}, {KEY_5, '5'}, {KEY_6, '6'}, {KEY_7, '7'}, + {KEY_8, '8'}, {KEY_9, '9'}, {KEY_0, '0'}, {KEY_DOT, '.'}, {KEY_COMMA, ','}, + {KEY_MINUS, '-'}, {KEY_EQUAL, '='}, {KEY_LEFTBRACE, '['}, {KEY_RIGHTBRACE, ']'}, {KEY_BACKSLASH, '\\'}, + {KEY_SEMICOLON, ';'}, {KEY_APOSTROPHE, '\''}, {KEY_SLASH, '/'}, {KEY_TAB, 0x09}}; + std::map uppers{{'a', 'A'}, {'b', 'B'}, {'c', 'C'}, {'d', 'D'}, {'e', 'E'}, {'f', 'F'}, {'g', 'G'}, {'h', 'H'}, + {'i', 'I'}, {'j', 'J'}, {'k', 'K'}, {'l', 'L'}, {'m', 'M'}, {'n', 'N'}, {'o', 'O'}, {'p', 'P'}, + {'q', 'Q'}, {'r', 'R'}, {'s', 'S'}, {'t', 'T'}, {'u', 'U'}, {'v', 'V'}, {'w', 'W'}, {'x', 'X'}, + {'y', 'Y'}, {'z', 'Z'}, {'1', '!'}, {'2', '@'}, {'3', '#'}, {'4', '$'}, {'5', '%'}, {'6', '^'}, + {'7', '&'}, {'8', '*'}, {'9', '('}, {'0', ')'}, {'.', '>'}, {',', '<'}, {'-', '_'}, {'=', '+'}, + {'[', '{'}, {']', '}'}, {'\\', '|'}, {';', ':'}, {'\'', '"'}, {'/', '?'}}; +}; +#endif \ No newline at end of file diff --git a/src/input/LinuxInputImpl.cpp b/src/input/LinuxInputImpl.cpp new file mode 100644 index 0000000000..4ddda1923b --- /dev/null +++ b/src/input/LinuxInputImpl.cpp @@ -0,0 +1,15 @@ +#include "configuration.h" +#if ARCH_PORTDUINO +#include "InputBroker.h" +#include "LinuxInputImpl.h" + +LinuxInputImpl *aLinuxInputImpl; + +LinuxInputImpl::LinuxInputImpl() : LinuxInput("LinuxInput") {} + +void LinuxInputImpl::init() +{ + inputBroker->registerSource(this); +} + +#endif \ No newline at end of file diff --git a/src/input/LinuxInputImpl.h b/src/input/LinuxInputImpl.h new file mode 100644 index 0000000000..e734b02943 --- /dev/null +++ b/src/input/LinuxInputImpl.h @@ -0,0 +1,21 @@ +#ifdef ARCH_PORTDUINO +#pragma once +#include "LinuxInput.h" +#include "main.h" + +/** + * @brief The idea behind this class to have static methods for the event handlers. + * Check attachInterrupt() at RotaryEncoderInteruptBase.cpp + * Technically you can have as many rotary encoders hardver attached + * to your device as you wish, but you always need to have separate event + * handlers, thus you need to have a RotaryEncoderInterrupt implementation. + */ + +class LinuxInputImpl : public LinuxInput +{ + public: + LinuxInputImpl(); + void init(); +}; +extern LinuxInputImpl *aLinuxInputImpl; +#endif \ No newline at end of file diff --git a/src/input/RotaryEncoderInterruptBase.cpp b/src/input/RotaryEncoderInterruptBase.cpp index 19b507f6c4..0b8e8325d5 100644 --- a/src/input/RotaryEncoderInterruptBase.cpp +++ b/src/input/RotaryEncoderInterruptBase.cpp @@ -104,7 +104,6 @@ RotaryEncoderInterruptBaseStateType RotaryEncoderInterruptBase::intHandler(bool newState = ROTARY_EVENT_OCCURRED; if ((this->action != ROTARY_ACTION_PRESSED) && (this->action != action)) { this->action = action; - LOG_DEBUG("Rotary action\n"); } } } else if (!actualPinRaising && (otherPinLevel == HIGH)) { diff --git a/src/input/TouchScreenImpl1.cpp b/src/input/TouchScreenImpl1.cpp index e38d6c324f..3e4ed4163b 100644 --- a/src/input/TouchScreenImpl1.cpp +++ b/src/input/TouchScreenImpl1.cpp @@ -4,6 +4,10 @@ #include "configuration.h" #include "modules/ExternalNotificationModule.h" +#ifdef ARCH_PORTDUINO +#include "platform/portduino/PortduinoGlue.h" +#endif + TouchScreenImpl1 *touchScreenImpl1; TouchScreenImpl1::TouchScreenImpl1(uint16_t width, uint16_t height, bool (*getTouch)(int16_t *, int16_t *)) @@ -13,7 +17,14 @@ TouchScreenImpl1::TouchScreenImpl1(uint16_t width, uint16_t height, bool (*getTo void TouchScreenImpl1::init() { -#if !HAS_TOUCHSCREEN +#if ARCH_PORTDUINO + if (settingsMap[touchscreenModule]) { + TouchScreenBase::init(true); + inputBroker->registerSource(this); + } else { + TouchScreenBase::init(false); + } +#elif !HAS_TOUCHSCREEN TouchScreenBase::init(false); return; #else diff --git a/src/input/kbI2cBase.cpp b/src/input/kbI2cBase.cpp index 366e7fbb19..1dba4e34dc 100644 --- a/src/input/kbI2cBase.cpp +++ b/src/input/kbI2cBase.cpp @@ -187,7 +187,7 @@ int32_t KbI2cBase::runOnce() i2cBus->requestFrom((int)cardkb_found.address, 1); - while (i2cBus->available()) { + if (i2cBus->available()) { char c = i2cBus->read(); InputEvent e; e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; @@ -222,7 +222,11 @@ int32_t KbI2cBase::runOnce() case 0x00: // nopress e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; break; - default: // all other keys + default: // all other keys + if (c > 127) { // bogus key value + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; + break; + } e.inputEvent = ANYKEY; e.kbchar = c; break; @@ -238,4 +242,4 @@ int32_t KbI2cBase::runOnce() LOG_WARN("Unknown kb_model 0x%02x\n", kb_model); } return 300; -} +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 3693b207ed..fb3700ca63 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -66,7 +66,7 @@ NRF52Bluetooth *nrf52Bluetooth; #include "platform/portduino/SimRadio.h" #endif -#ifdef ARCH_RASPBERRY_PI +#ifdef ARCH_PORTDUINO #include "linux/LinuxHardwareI2C.h" #include "platform/portduino/PortduinoGlue.h" #include @@ -74,7 +74,7 @@ NRF52Bluetooth *nrf52Bluetooth; #include #endif -#if HAS_BUTTON || defined(ARCH_RASPBERRY_PI) +#if HAS_BUTTON || defined(ARCH_PORTDUINO) #include "ButtonThread.h" #endif #include "PowerFSMThread.h" @@ -141,32 +141,12 @@ std::pair nodeTelemetrySensorsMap[_meshtastic_TelemetrySenso Router *router = NULL; // Users of router don't care what sort of subclass implements that API -#ifdef ARCH_RASPBERRY_PI -void getPiMacAddr(uint8_t *dmac) -{ - std::fstream macIdentity; - macIdentity.open("/sys/kernel/debug/bluetooth/hci0/identity", std::ios::in); - std::string macLine; - getline(macIdentity, macLine); - macIdentity.close(); - - dmac[0] = strtol(macLine.substr(0, 2).c_str(), NULL, 16); - dmac[1] = strtol(macLine.substr(3, 2).c_str(), NULL, 16); - dmac[2] = strtol(macLine.substr(6, 2).c_str(), NULL, 16); - dmac[3] = strtol(macLine.substr(9, 2).c_str(), NULL, 16); - dmac[4] = strtol(macLine.substr(12, 2).c_str(), NULL, 16); - dmac[5] = strtol(macLine.substr(15, 2).c_str(), NULL, 16); -} -#endif - const char *getDeviceName() { uint8_t dmac[6]; -#ifdef ARCH_RASPBERRY_PI - getPiMacAddr(dmac); -#else + getMacAddr(dmac); -#endif + // Meshtastic_ab3c or Shortname_abcd static char name[20]; snprintf(name, sizeof(name), "%02x%02x", dmac[4], dmac[5]); @@ -179,25 +159,6 @@ const char *getDeviceName() return name; } -#ifdef VEXT_ENABLE_V03 - -#include - -static uint32_t calibrate_one(rtc_cal_sel_t cal_clk, const char *name) -{ - const uint32_t cal_count = 1000; - uint32_t cali_val; - for (int i = 0; i < 5; ++i) { - cali_val = rtc_clk_cal(cal_clk, cal_count); - } - return cali_val; -} - -int heltec_version = 3; - -#define CALIBRATE_ONE(cali_clk) calibrate_one(cali_clk, #cali_clk) -#endif - static int32_t ledBlinker() { static bool ledOn; @@ -211,15 +172,10 @@ static int32_t ledBlinker() uint32_t timeLastPowered = 0; -#if HAS_BUTTON || defined(ARCH_RASPBERRY_PI) -bool ButtonThread::shutdown_on_long_stop = false; -#endif - static Periodic *ledPeriodic; static OSThread *powerFSMthread; -#if HAS_BUTTON || defined(ARCH_RASPBERRY_PI) +#if HAS_BUTTON || defined(ARCH_PORTDUINO) static OSThread *buttonThread; -uint32_t ButtonThread::longPressTime = 0; #endif static OSThread *accelerometerThread; static OSThread *ambientLightingThread; @@ -268,56 +224,31 @@ void setup() digitalWrite(PIN_EINK_PWR_ON, HIGH); #endif -#ifdef ST7735_BL_V03 // Heltec Wireless Tracker PCB Change Detect/Hack - - rtc_clk_32k_enable(true); - CALIBRATE_ONE(RTC_CAL_RTC_MUX); - if (CALIBRATE_ONE(RTC_CAL_32K_XTAL) != 0) { - rtc_clk_slow_freq_set(RTC_SLOW_FREQ_32K_XTAL); - CALIBRATE_ONE(RTC_CAL_RTC_MUX); - CALIBRATE_ONE(RTC_CAL_32K_XTAL); - } - - if (rtc_clk_slow_freq_get() != RTC_SLOW_FREQ_32K_XTAL) { - heltec_version = 3; - } else { - heltec_version = 5; - } -#endif - #if defined(VEXT_ENABLE_V03) - if (heltec_version == 3) { - pinMode(VEXT_ENABLE_V03, OUTPUT); - digitalWrite(VEXT_ENABLE_V03, 0); // turn on the display power - LOG_DEBUG("HELTEC Detect Tracker V1.0\n"); - } else { - pinMode(VEXT_ENABLE_V05, OUTPUT); - digitalWrite(VEXT_ENABLE_V05, 1); // turn on the display power - LOG_DEBUG("HELTEC Detect Tracker V1.1\n"); - } + pinMode(VEXT_ENABLE_V03, OUTPUT); + pinMode(ST7735_BL_V03, OUTPUT); + digitalWrite(VEXT_ENABLE_V03, 0); // turn on the display power and antenna boost + digitalWrite(ST7735_BL_V03, 1); // display backligth on + LOG_DEBUG("HELTEC Detect Tracker V1.0\n"); +#elif defined(VEXT_ENABLE_V05) + pinMode(VEXT_ENABLE_V05, OUTPUT); + pinMode(ST7735_BL_V05, OUTPUT); + digitalWrite(VEXT_ENABLE_V05, 1); // turn on the lora antenna boost + digitalWrite(ST7735_BL_V05, 1); // turn on display backligth + LOG_DEBUG("HELTEC Detect Tracker V1.1\n"); #elif defined(VEXT_ENABLE) pinMode(VEXT_ENABLE, OUTPUT); digitalWrite(VEXT_ENABLE, 0); // turn on the display power #endif #if defined(VGNSS_CTRL_V03) - if (heltec_version == 3) { - pinMode(VGNSS_CTRL_V03, OUTPUT); - digitalWrite(VGNSS_CTRL_V03, LOW); - } else { - pinMode(VGNSS_CTRL_V05, OUTPUT); - digitalWrite(VGNSS_CTRL_V05, LOW); - } + pinMode(VGNSS_CTRL_V03, OUTPUT); + digitalWrite(VGNSS_CTRL_V03, LOW); #endif #if defined(VTFT_CTRL_V03) - if (heltec_version == 3) { - pinMode(VTFT_CTRL_V03, OUTPUT); - digitalWrite(VTFT_CTRL_V03, LOW); - } else { - pinMode(VTFT_CTRL_V05, OUTPUT); - digitalWrite(VTFT_CTRL_V05, LOW); - } + pinMode(VTFT_CTRL_V03, OUTPUT); + digitalWrite(VTFT_CTRL_V03, LOW); #endif #if defined(VGNSS_CTRL) @@ -369,12 +300,27 @@ void setup() #endif -#ifdef I2C_SDA1 +#if defined(I2C_SDA1) && defined(ARCH_RP2040) + Wire1.setSDA(I2C_SDA1); + Wire1.setSCL(I2C_SCL1); + Wire1.begin(); +#elif defined(I2C_SDA1) && !defined(ARCH_RP2040) Wire1.begin(I2C_SDA1, I2C_SCL1); #endif -#ifdef I2C_SDA +#if defined(I2C_SDA) && defined(ARCH_RP2040) + Wire.setSDA(I2C_SDA); + Wire.setSCL(I2C_SCL); + Wire.begin(); +#elif defined(I2C_SDA) && !defined(ARCH_RP2040) Wire.begin(I2C_SDA, I2C_SCL); +#elif defined(ARCH_PORTDUINO) + if (settingsStrings[i2cdev] != "") { + LOG_INFO("Using %s as I2C device.\n", settingsStrings[i2cdev]); + Wire.begin(settingsStrings[i2cdev].c_str()); + } else { + LOG_INFO("No I2C device configured, skipping.\n"); + } #elif HAS_WIRE Wire.begin(); #endif @@ -420,17 +366,33 @@ void setup() // We need to scan here to decide if we have a screen for nodeDB.init() and because power has been applied to // accessories auto i2cScanner = std::unique_ptr(new ScanI2CTwoWire()); - +#ifdef HAS_WIRE LOG_INFO("Scanning for i2c devices...\n"); +#endif -#ifdef I2C_SDA1 +#if defined(I2C_SDA1) && defined(ARCH_RP2040) + Wire1.setSDA(I2C_SDA1); + Wire1.setSCL(I2C_SCL1); + Wire1.begin(); + i2cScanner->scanPort(ScanI2C::I2CPort::WIRE1); +#elif defined(I2C_SDA1) && !defined(ARCH_RP2040) Wire1.begin(I2C_SDA1, I2C_SCL1); i2cScanner->scanPort(ScanI2C::I2CPort::WIRE1); #endif -#ifdef I2C_SDA +#if defined(I2C_SDA) && defined(ARCH_RP2040) + Wire.setSDA(I2C_SDA); + Wire.setSCL(I2C_SCL); + Wire.begin(); + i2cScanner->scanPort(ScanI2C::I2CPort::WIRE); +#elif defined(I2C_SDA) && !defined(ARCH_RP2040) Wire.begin(I2C_SDA, I2C_SCL); i2cScanner->scanPort(ScanI2C::I2CPort::WIRE); +#elif defined(ARCH_PORTDUINO) + if (settingsStrings[i2cdev] != "") { + LOG_INFO("Scanning for i2c devices...\n"); + i2cScanner->scanPort(ScanI2C::I2CPort::WIRE); + } #elif HAS_WIRE i2cScanner->scanPort(ScanI2C::I2CPort::WIRE); #endif @@ -595,7 +557,7 @@ void setup() } else router = new ReliableRouter(); -#if HAS_BUTTON || defined(ARCH_RASPBERRY_PI) +#if HAS_BUTTON || defined(ARCH_PORTDUINO) // Buttons. Moved here cause we need NodeDB to be initialized buttonThread = new ButtonThread(); #endif @@ -652,10 +614,9 @@ void setup() SPI.setRX(LORA_MISO); SPI.begin(false); #endif // HW_SPI1_DEVICE -#elif defined(ARCH_APOLLO3) - // Apollo3 - SPI.begin(); -#elif !defined(ARCH_ESP32) // ARCH_RP2040 +#elif ARCH_PORTDUINO + SPI.begin(settingsStrings[spidev].c_str()); +#elif !defined(ARCH_ESP32) // ARCH_RP2040 + Apollo3 SPI.begin(); #else // ESP32 @@ -670,7 +631,8 @@ void setup() readFromRTC(); // read the main CPU RTC at first (in case we can't get GPS time) // If we're taking on the repeater role, ignore GPS - if (config.device.role != meshtastic_Config_DeviceConfig_Role_REPEATER) { + if (config.device.role != meshtastic_Config_DeviceConfig_Role_REPEATER && + config.position.gps_mode != meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT) { gps = GPS::createGps(); } if (gps) { @@ -700,6 +662,10 @@ void setup() // the current region name) #if defined(ST7735_CS) || defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7789_CS) screen->setup(); +#elif defined(ARCH_PORTDUINO) + if (screen_found.port != ScanI2C::I2CPort::NO_I2C || settingsMap[displayPanel]) { + screen->setup(); + } #else if (screen_found.port != ScanI2C::I2CPort::NO_I2C) screen->setup(); @@ -713,9 +679,10 @@ void setup() digitalWrite(SX126X_ANT_SW, 1); #endif -#ifdef ARCH_RASPBERRY_PI +#ifdef ARCH_PORTDUINO if (settingsMap[use_sx1262]) { if (!rIf) { + LOG_DEBUG("Attempting to activate sx1262 radio on SPI port %s\n", settingsStrings[spidev].c_str()); LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings); rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset], settingsMap[busy]); @@ -729,6 +696,7 @@ void setup() } } else if (settingsMap[use_rf95]) { if (!rIf) { + LOG_DEBUG("Attempting to activate rf95 radio on SPI port %s\n", settingsStrings[spidev].c_str()); LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings); rIf = new RF95Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset], settingsMap[busy]); @@ -741,6 +709,21 @@ void setup() LOG_INFO("RF95 Radio init succeeded, using RF95 radio\n"); } } + } else if (settingsMap[use_sx1280]) { + if (!rIf) { + LOG_DEBUG("Attempting to activate sx1280 radio on SPI port %s\n", settingsStrings[spidev].c_str()); + LockingArduinoHal *RadioLibHAL = new LockingArduinoHal(SPI, spiSettings); + rIf = new SX1280Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset], + settingsMap[busy]); + if (!rIf->init()) { + LOG_ERROR("Failed to find SX1280 radio\n"); + delete rIf; + rIf = NULL; + exit(EXIT_FAILURE); + } else { + LOG_INFO("SX1280 Radio init succeeded, using SX1280 radio\n"); + } + } } #elif defined(HW_SPI1_DEVICE) @@ -789,7 +772,7 @@ void setup() } #endif -#if defined(USE_SX1262) && !defined(ARCH_RASPBERRY_PI) +#if defined(USE_SX1262) && !defined(ARCH_PORTDUINO) if (!rIf) { rIf = new SX1262Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY); if (!rIf->init()) { diff --git a/src/main.h b/src/main.h index e780516f68..fa70d63243 100644 --- a/src/main.h +++ b/src/main.h @@ -62,7 +62,6 @@ extern graphics::Screen *screen; // Return a human readable string of the form "Meshtastic_ab13" const char *getDeviceName(); -void getPiMacAddr(uint8_t *dmac); extern uint32_t timeLastPowered; @@ -71,13 +70,11 @@ extern uint32_t shutdownAtMsec; extern uint32_t serialSinceMsec; -extern int heltec_version; - // If a thread does something that might need for it to be rescheduled ASAP it can set this flag // This will suppress the current delay and instead try to run ASAP. extern bool runASAP; -void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(), rp2040Setup(), clearBonds(); +void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(), rp2040Setup(), clearBonds(), enterDfuMode(); meshtastic_DeviceMetadata getDeviceMetadata(); diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index 9974297fac..fe1041d3de 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -15,6 +15,7 @@ Channels channels; const char *Channels::adminChannel = "admin"; const char *Channels::gpioChannel = "gpio"; const char *Channels::serialChannel = "serial"; +const char *Channels::mqttChannel = "mqtt"; uint8_t xorHash(const uint8_t *p, size_t len) { @@ -86,6 +87,7 @@ void Channels::initDefaultChannel(ChannelIndex chIndex) channelSettings.psk.bytes[0] = defaultpskIndex; channelSettings.psk.size = 1; strncpy(channelSettings.name, "", sizeof(channelSettings.name)); + channelSettings.module_settings.position_precision = 32; // default to sending location on the primary channel ch.has_settings = true; ch.role = meshtastic_Channel_Role_PRIMARY; @@ -184,7 +186,7 @@ void Channels::onConfigChanged() { // Make sure the phone hasn't mucked anything up for (int i = 0; i < channelFile.channels_count; i++) { - meshtastic_Channel &ch = fixupChannel(i); + const meshtastic_Channel &ch = fixupChannel(i); if (ch.role == meshtastic_Channel_Role_PRIMARY) primaryIndex = i; @@ -313,4 +315,4 @@ bool Channels::decryptForHash(ChannelIndex chIndex, ChannelHash channelHash) int16_t Channels::setActiveByIndex(ChannelIndex channelIndex) { return setCrypto(channelIndex); -} +} \ No newline at end of file diff --git a/src/mesh/Channels.h b/src/mesh/Channels.h index b4bdcbd5ca..87a72e07b1 100644 --- a/src/mesh/Channels.h +++ b/src/mesh/Channels.h @@ -32,7 +32,7 @@ class Channels Channels() {} /// Well known channel names - static const char *adminChannel, *gpioChannel, *serialChannel; + static const char *adminChannel, *gpioChannel, *serialChannel, *mqttChannel; const meshtastic_ChannelSettings &getPrimary() { return getByIndex(getPrimaryIndex()).settings; } @@ -139,4 +139,4 @@ class Channels }; /// Singleton channel table -extern Channels channels; +extern Channels channels; \ No newline at end of file diff --git a/src/mesh/FloodingRouter.cpp b/src/mesh/FloodingRouter.cpp index d27d47e875..db3f3f35e6 100644 --- a/src/mesh/FloodingRouter.cpp +++ b/src/mesh/FloodingRouter.cpp @@ -21,7 +21,7 @@ bool FloodingRouter::shouldFilterReceived(const meshtastic_MeshPacket *p) { if (wasSeenRecently(p)) { // Note: this will also add a recent packet record printPacket("Ignoring incoming msg, because we've already seen it", p); - if (!moduleConfig.mqtt.enabled && config.device.role != meshtastic_Config_DeviceConfig_Role_ROUTER && + if (config.device.role != meshtastic_Config_DeviceConfig_Role_ROUTER && config.device.role != meshtastic_Config_DeviceConfig_Role_ROUTER_CLIENT && config.device.role != meshtastic_Config_DeviceConfig_Role_REPEATER) { // cancel rebroadcast of this message *if* there was already one, unless we're a router/repeater! diff --git a/src/mesh/MeshModule.cpp b/src/mesh/MeshModule.cpp index a1e719721c..9c6ca78ee2 100644 --- a/src/mesh/MeshModule.cpp +++ b/src/mesh/MeshModule.cpp @@ -67,7 +67,7 @@ meshtastic_MeshPacket *MeshModule::allocErrorResponse(meshtastic_Routing_Error e return r; } -void MeshModule::callPlugins(const meshtastic_MeshPacket &mp, RxSource src) +void MeshModule::callPlugins(meshtastic_MeshPacket &mp, RxSource src) { // LOG_DEBUG("In call modules\n"); bool moduleFound = false; @@ -124,9 +124,10 @@ void MeshModule::callPlugins(const meshtastic_MeshPacket &mp, RxSource src) } else printPacket("packet on wrong channel, but can't respond", &mp); } else { - ProcessMessage handled = pi.handleReceived(mp); + pi.alterReceived(mp); + // Possibly send replies (but only if the message was directed to us specifically, i.e. not for promiscious // sniffing) also: we only let the one module send a reply, once that happens, remaining modules are not // considered diff --git a/src/mesh/MeshModule.h b/src/mesh/MeshModule.h index 323cc85959..ebe3af1a0b 100644 --- a/src/mesh/MeshModule.h +++ b/src/mesh/MeshModule.h @@ -64,7 +64,7 @@ class MeshModule /** For use only by MeshService */ - static void callPlugins(const meshtastic_MeshPacket &mp, RxSource src = RX_SRC_RADIO); + static void callPlugins(meshtastic_MeshPacket &mp, RxSource src = RX_SRC_RADIO); static std::vector GetMeshModulesWithUIFrames(); static void observeUIEvents(Observer *observer); @@ -72,10 +72,7 @@ class MeshModule meshtastic_AdminMessage *request, meshtastic_AdminMessage *response); #if HAS_SCREEN - virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) - { - return; - } + virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { return; } #endif protected: const char *name; @@ -135,10 +132,12 @@ class MeshModule @return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for it */ - virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) - { - return ProcessMessage::CONTINUE; - } + virtual ProcessMessage handleReceived(const meshtastic_MeshPacket &mp) { return ProcessMessage::CONTINUE; } + + /** Called to change a particular incoming message + This allows the module to change the message before it is passed through the rest of the call-chain. + */ + virtual void alterReceived(meshtastic_MeshPacket &mp) {} /** Messages can be received that have the want_response bit set. If set, this callback will be invoked * so that subclasses can (optionally) send a response back to the original sender. @@ -151,14 +150,8 @@ class MeshModule /*** * @return true if you want to be alloced a UI screen frame */ - virtual bool wantUIFrame() - { - return false; - } - virtual Observable *getUIFrameObservable() - { - return NULL; - } + virtual bool wantUIFrame() { return false; } + virtual Observable *getUIFrameObservable() { return NULL; } meshtastic_MeshPacket *allocAckNak(meshtastic_Routing_Error err, NodeNum to, PacketId idFrom, ChannelIndex chIndex); diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 4b2bc33fe1..1a09243d28 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -108,8 +108,9 @@ void MeshService::loop() (void)sendQueueStatusToPhone(qs, 0, 0); } if (oldFromNum != fromNum) { // We don't want to generate extra notifies for multiple new packets - fromNumChanged.notifyObservers(fromNum); - oldFromNum = fromNum; + int result = fromNumChanged.notifyObservers(fromNum); + if (result == 0) // If any observer returns non-zero, we will try again + oldFromNum = fromNum; } } diff --git a/src/mesh/MeshService.h b/src/mesh/MeshService.h index 6d73c076a4..68287efc23 100644 --- a/src/mesh/MeshService.h +++ b/src/mesh/MeshService.h @@ -129,6 +129,8 @@ class MeshService bool isToPhoneQueueEmpty(); + ErrorCode sendQueueStatusToPhone(const meshtastic_QueueStatus &qs, ErrorCode res, uint32_t mesh_packet_id); + private: /// Called when our gps position has changed - updates nodedb and sends Location message out into the mesh /// returns 0 to allow further processing @@ -138,8 +140,6 @@ class MeshService /// needs to keep the packet around it makes a copy int handleFromRadio(const meshtastic_MeshPacket *p); friend class RoutingModule; - - ErrorCode sendQueueStatusToPhone(const meshtastic_QueueStatus &qs, ErrorCode res, uint32_t mesh_packet_id); }; extern MeshService service; \ No newline at end of file diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index b30b5756d7..8cac931ae2 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -27,6 +27,10 @@ #include #endif +#ifdef ARCH_PORTDUINO +#include "platform/portduino/PortduinoGlue.h" +#endif + #ifdef ARCH_NRF52 #include #include @@ -169,6 +173,7 @@ void NodeDB::installDefaultConfig() config.lora.region = meshtastic_Config_LoRaConfig_RegionCode_UNSET; config.lora.modem_preset = meshtastic_Config_LoRaConfig_ModemPreset_LONG_FAST; config.lora.hop_limit = HOP_RELIABLE; + config.lora.ignore_mqtt = false; #ifdef PIN_GPS_EN config.position.gps_en_gpio = PIN_GPS_EN; #endif @@ -177,7 +182,16 @@ void NodeDB::installDefaultConfig() #else config.device.disable_triple_click = true; #endif - config.position.gps_enabled = true; +#if !HAS_GPS || defined(T_DECK) + config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT; +#elif !defined(GPS_RX_PIN) + if (config.position.rx_gpio == 0) + config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT; + else + config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_DISABLED; +#else + config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_ENABLED; +#endif config.position.position_broadcast_smart_enabled = true; config.position.broadcast_smart_minimum_distance = 100; config.position.broadcast_smart_minimum_interval_secs = 30; @@ -191,6 +205,12 @@ void NodeDB::installDefaultConfig() config.bluetooth.fixed_pin = defaultBLEPin; #if defined(ST7735_CS) || defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7789_CS) bool hasScreen = true; +#elif ARCH_PORTDUINO + bool hasScreen = false; + if (settingsMap[displayPanel]) + hasScreen = true; + else + hasScreen = screen_found.port != ScanI2C::I2CPort::NO_I2C; #else bool hasScreen = screen_found.port != ScanI2C::I2CPort::NO_I2C; #endif @@ -213,7 +233,6 @@ void NodeDB::installDefaultConfig() void NodeDB::initConfigIntervals() { config.position.gps_update_interval = default_gps_update_interval; - config.position.gps_attempt_time = default_gps_attempt_time; config.position.position_broadcast_secs = default_broadcast_interval_secs; config.power.ls_secs = default_ls_secs; @@ -291,11 +310,12 @@ void NodeDB::installRoleDefaults(meshtastic_Config_DeviceConfig_Role role) initModuleConfigIntervals(); } else if (role == meshtastic_Config_DeviceConfig_Role_REPEATER) { config.display.screen_on_secs = 1; - } else if (role == meshtastic_Config_DeviceConfig_Role_TRACKER) { - config.position.gps_update_interval = 30; } else if (role == meshtastic_Config_DeviceConfig_Role_SENSOR) { moduleConfig.telemetry.environment_measurement_enabled = true; moduleConfig.telemetry.environment_update_interval = 300; + } else if (role == meshtastic_Config_DeviceConfig_Role_LOST_AND_FOUND) { + config.position.position_broadcast_smart_enabled = false; + config.position.position_broadcast_secs = 300; // Every 5 minutes } else if (role == meshtastic_Config_DeviceConfig_Role_TAK) { config.device.node_info_broadcast_secs = ONE_DAY; config.position.position_broadcast_smart_enabled = false; @@ -305,6 +325,17 @@ void NodeDB::installRoleDefaults(meshtastic_Config_DeviceConfig_Role role) (meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE | meshtastic_Config_PositionConfig_PositionFlags_SPEED | meshtastic_Config_PositionConfig_PositionFlags_HEADING | meshtastic_Config_PositionConfig_PositionFlags_DOP); moduleConfig.telemetry.device_update_interval = ONE_DAY; + } else if (role == meshtastic_Config_DeviceConfig_Role_TAK_TRACKER) { + config.device.node_info_broadcast_secs = ONE_DAY; + config.position.position_broadcast_smart_enabled = true; + config.position.position_broadcast_secs = 3 * 60; // Every 3 minutes + config.position.broadcast_smart_minimum_distance = 20; + config.position.broadcast_smart_minimum_interval_secs = 15; + // Remove Altitude MSL from flags since CoTs use HAE (height above ellipsoid) + config.position.position_flags = + (meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE | meshtastic_Config_PositionConfig_PositionFlags_SPEED | + meshtastic_Config_PositionConfig_PositionFlags_HEADING | meshtastic_Config_PositionConfig_PositionFlags_DOP); + moduleConfig.telemetry.device_update_interval = ONE_DAY; } else if (role == meshtastic_Config_DeviceConfig_Role_CLIENT_HIDDEN) { config.device.rebroadcast_mode = meshtastic_Config_DeviceConfig_RebroadcastMode_LOCAL_ONLY; config.device.node_info_broadcast_secs = UINT32_MAX; @@ -443,6 +474,11 @@ void NodeDB::init() memcpy(devicestate.node_remote_hardware_pins, empty, sizeof(empty)); } + if (config.position.gps_enabled) { + config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_ENABLED; + config.position.gps_enabled = 0; + } + saveToDisk(saveWhat); } @@ -454,11 +490,8 @@ void NodeDB::init() */ void NodeDB::pickNewNodeNum() { -#ifdef ARCH_RASPBERRY_PI - getPiMacAddr(ourMacAddr); // Make sure ourMacAddr is set -#else + getMacAddr(ourMacAddr); // Make sure ourMacAddr is set -#endif // Pick an initial nodenum based on the macaddr NodeNum nodeNum = (ourMacAddr[2] << 24) | (ourMacAddr[3] << 16) | (ourMacAddr[4] << 8) | ourMacAddr[5]; @@ -789,22 +822,25 @@ void NodeDB::updateTelemetry(uint32_t nodeId, const meshtastic_Telemetry &t, RxS notifyObservers(true); // Force an update whether or not our node counts have changed } -/** Update user info for this node based on received user data +/** Update user info and channel for this node based on received user data */ -bool NodeDB::updateUser(uint32_t nodeId, const meshtastic_User &p) +bool NodeDB::updateUser(uint32_t nodeId, const meshtastic_User &p, uint8_t channelIndex) { meshtastic_NodeInfoLite *info = getOrCreateMeshNode(nodeId); if (!info) { return false; } - LOG_DEBUG("old user %s/%s/%s\n", info->user.id, info->user.long_name, info->user.short_name); + LOG_DEBUG("old user %s/%s/%s, channel=%d\n", info->user.id, info->user.long_name, info->user.short_name, info->channel); - bool changed = memcmp(&info->user, &p, - sizeof(info->user)); // Both of these blocks start as filled with zero so I think this is okay + // Both of info->user and p start as filled with zero so I think this is okay + bool changed = memcmp(&info->user, &p, sizeof(info->user)) || (info->channel != channelIndex); info->user = p; - LOG_DEBUG("updating changed=%d user %s/%s/%s\n", changed, info->user.id, info->user.long_name, info->user.short_name); + if (nodeId != getNodeNum()) + info->channel = channelIndex; // Set channel we need to use to reach this node (but don't set our own channel) + LOG_DEBUG("updating changed=%d user %s/%s/%s, channel=%d\n", changed, info->user.id, info->user.long_name, + info->user.short_name, info->channel); info->has_user = true; if (changed) { @@ -824,7 +860,7 @@ bool NodeDB::updateUser(uint32_t nodeId, const meshtastic_User &p) void NodeDB::updateFrom(const meshtastic_MeshPacket &mp) { if (mp.which_payload_variant == meshtastic_MeshPacket_decoded_tag && mp.from) { - LOG_DEBUG("Update DB node 0x%x, rx_time=%u, channel=%d\n", mp.from, mp.rx_time, mp.channel); + LOG_DEBUG("Update DB node 0x%x, rx_time=%u\n", mp.from, mp.rx_time); meshtastic_NodeInfoLite *info = getOrCreateMeshNode(getFrom(&mp)); if (!info) { @@ -836,10 +872,6 @@ void NodeDB::updateFrom(const meshtastic_MeshPacket &mp) if (mp.rx_snr) info->snr = mp.rx_snr; // keep the most recent SNR we received for this node. - - if (mp.decoded.portnum == meshtastic_PortNum_NODEINFO_APP) { - info->channel = mp.channel; - } } } @@ -872,10 +904,11 @@ meshtastic_NodeInfoLite *NodeDB::getOrCreateMeshNode(NodeNum n) if ((*numMeshNodes >= MAX_NUM_NODES) || (memGet.getFreeHeap() < meshtastic_NodeInfoLite_size * 3)) { if (screen) screen->print("warning: node_db_lite full! erasing oldest entry\n"); + LOG_INFO("warning: node_db_lite full! erasing oldest entry\n"); // look for oldest node and erase it uint32_t oldest = UINT32_MAX; int oldestIndex = -1; - for (int i = 0; i < *numMeshNodes; i++) { + for (int i = 1; i < *numMeshNodes; i++) { if (meshNodes[i].last_heard < oldest) { oldest = meshNodes[i].last_heard; oldestIndex = i; diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index 5e4dc48858..e24a971c16 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -84,9 +84,9 @@ class NodeDB */ void updateTelemetry(uint32_t nodeId, const meshtastic_Telemetry &t, RxSource src = RX_SRC_RADIO); - /** Update user info for this node based on received user data + /** Update user info and channel for this node based on received user data */ - bool updateUser(uint32_t nodeId, const meshtastic_User &p); + bool updateUser(uint32_t nodeId, const meshtastic_User &p, uint8_t channelIndex = 0); /// @return our node number NodeNum getNodeNum() { return myNodeInfo.my_node_num; } @@ -179,9 +179,6 @@ extern NodeDB nodeDB; prefs.gps_update_interval = oneday prefs.is_power_saving = True - - # allow up to five minutes for each new GPS lock attempt - prefs.gps_attempt_time = 300 */ // Our delay functions check for this for times that should never expire @@ -192,7 +189,6 @@ extern NodeDB nodeDB; #define ONE_DAY 24 * 60 * 60 -#define default_gps_attempt_time IF_ROUTER(5 * 60, 15 * 60) #define default_gps_update_interval IF_ROUTER(ONE_DAY, 2 * 60) #define default_broadcast_interval_secs IF_ROUTER(ONE_DAY / 2, 15 * 60) #define default_wait_bluetooth_secs IF_ROUTER(1, 60) diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 66578f14dc..7b42754fba 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -66,15 +66,17 @@ void PhoneAPI::close() } } -void PhoneAPI::checkConnectionTimeout() +bool PhoneAPI::checkConnectionTimeout() { if (isConnected()) { bool newContact = checkIsConnected(); if (!newContact) { LOG_INFO("Lost phone connection\n"); close(); + return true; } } + return false; } /** @@ -304,6 +306,10 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_ambient_lighting_tag; fromRadioScratch.moduleConfig.payload_variant.ambient_lighting = moduleConfig.ambient_lighting; break; + case meshtastic_ModuleConfig_paxcounter_tag: + fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_paxcounter_tag; + fromRadioScratch.moduleConfig.payload_variant.paxcounter = moduleConfig.paxcounter; + break; default: LOG_ERROR("Unknown module config type %d\n", config_state); } @@ -465,8 +471,8 @@ bool PhoneAPI::handleToRadioPacket(meshtastic_MeshPacket &p) /// If the mesh service tells us fromNum has changed, tell the phone int PhoneAPI::onNotify(uint32_t newValue) { - checkConnectionTimeout(); // a handy place to check if we've heard from the phone (since the BLE version doesn't call this - // from idle) + bool timeout = checkConnectionTimeout(); // a handy place to check if we've heard from the phone (since the BLE version + // doesn't call this from idle) if (state == STATE_SEND_PACKETS) { LOG_INFO("Telling client we have new packets %u\n", newValue); @@ -475,5 +481,5 @@ int PhoneAPI::onNotify(uint32_t newValue) LOG_DEBUG("(Client not yet interested in packets)\n"); } - return 0; + return timeout ? -1 : 0; // If we timed out, MeshService should stop iterating through observers as we just removed one } \ No newline at end of file diff --git a/src/mesh/PhoneAPI.h b/src/mesh/PhoneAPI.h index 65a06bc6be..450649d7bc 100644 --- a/src/mesh/PhoneAPI.h +++ b/src/mesh/PhoneAPI.h @@ -108,8 +108,8 @@ class PhoneAPI /// Hookable to find out when connection changes virtual void onConnectionChanged(bool connected) {} - /// If we haven't heard from the other side in a while then say not connected - void checkConnectionTimeout(); + /// If we haven't heard from the other side in a while then say not connected. Returns true if timeout occurred + bool checkConnectionTimeout(); /// Check the current underlying physical link to see if the client is currently connected virtual bool checkIsConnected() = 0; @@ -142,4 +142,4 @@ class PhoneAPI /// If the mesh service tells us fromNum has changed, tell the phone virtual int onNotify(uint32_t newValue) override; -}; +}; \ No newline at end of file diff --git a/src/mesh/ProtobufModule.h b/src/mesh/ProtobufModule.h index 1771f4322f..d87bb47c34 100644 --- a/src/mesh/ProtobufModule.h +++ b/src/mesh/ProtobufModule.h @@ -30,6 +30,10 @@ template class ProtobufModule : protected SinglePortModule */ virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, T *decoded) = 0; + /** Called to make changes to a particular incoming message + */ + virtual void alterReceivedProtobuf(meshtastic_MeshPacket &mp, T *decoded){}; + /** * Return a mesh packet which has been preinited with a particular protobuf data payload and port number. * You can then send this packet (after customizing any of the payload fields you might need) with @@ -86,4 +90,26 @@ template class ProtobufModule : protected SinglePortModule return handleReceivedProtobuf(mp, decoded) ? ProcessMessage::STOP : ProcessMessage::CONTINUE; } + + /** Called to alter a particular incoming message + */ + virtual void alterReceived(meshtastic_MeshPacket &mp) override + { + auto &p = mp.decoded; + + T scratch; + T *decoded = NULL; + if (mp.which_payload_variant == meshtastic_MeshPacket_decoded_tag && mp.decoded.portnum == ourPortNum) { + memset(&scratch, 0, sizeof(scratch)); + if (pb_decode_from_bytes(p.payload.bytes, p.payload.size, fields, &scratch)) { + decoded = &scratch; + } else { + LOG_ERROR("Error decoding protobuf module!\n"); + // if we can't decode it, nobody can process it! + return; + } + } + + return alterReceivedProtobuf(mp, decoded); + } }; \ No newline at end of file diff --git a/src/mesh/RF95Interface.cpp b/src/mesh/RF95Interface.cpp index d7f319f8ee..72e0f823f9 100644 --- a/src/mesh/RF95Interface.cpp +++ b/src/mesh/RF95Interface.cpp @@ -4,6 +4,10 @@ #include "configuration.h" #include "error.h" +#if ARCH_PORTDUINO +#include "PortduinoGlue.h" +#endif + #define MAX_POWER 20 // if we use 20 we are limited to 1% duty cycle or hw might overheat. For continuous operation set a limit of 17 // In theory up to 27 dBm is possible, but the modules installed in most radios can cope with a max of 20. So BIG WARNING @@ -23,10 +27,18 @@ void RF95Interface::setTransmitEnable(bool txon) { #ifdef RF95_TXEN digitalWrite(RF95_TXEN, txon ? 1 : 0); +#elif ARCH_PORTDUINO + if (settingsMap[txen] != RADIOLIB_NC) { + digitalWrite(settingsMap[txen], txon ? 1 : 0); + } #endif #ifdef RF95_RXEN digitalWrite(RF95_RXEN, txon ? 0 : 1); +#elif ARCH_PORTDUINO + if (settingsMap[rxen] != RADIOLIB_NC) { + digitalWrite(settingsMap[rxen], txon ? 0 : 1); + } #endif } @@ -62,6 +74,16 @@ bool RF95Interface::init() #ifdef RF95_RXEN pinMode(RF95_RXEN, OUTPUT); digitalWrite(RF95_RXEN, 1); +#endif +#if ARCH_PORTDUINO + if (settingsMap[txen] != RADIOLIB_NC) { + pinMode(settingsMap[txen], OUTPUT); + digitalWrite(settingsMap[txen], 0); + } + if (settingsMap[rxen] != RADIOLIB_NC) { + pinMode(settingsMap[rxen], OUTPUT); + digitalWrite(settingsMap[rxen], 0); + } #endif setTransmitEnable(false); @@ -202,4 +224,4 @@ bool RF95Interface::sleep() lora->sleep(); return true; -} +} \ No newline at end of file diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index c66f0e1d32..cea3968ce3 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -108,9 +108,31 @@ const RegionInfo regions[] = { RDEF(UA_868, 868.0f, 868.6f, 1, 0, 14, true, false, false), /* - 2.4 GHZ WLAN Band equivalent. Only for SX128x chips. + Malaysia + 433 - 435 MHz at 100mW, no restrictions. + https://www.mcmc.gov.my/skmmgovmy/media/General/pdf/Short-Range-Devices-Specification.pdf + */ + RDEF(MY_433, 433.0f, 435.0f, 100, 0, 20, true, false, false), + + /* + Malaysia + 919 - 923 Mhz at 500mW, no restrictions. + 923 - 924 MHz at 500mW with 1% duty cycle OR frequency hopping. + Frequency hopping is used for 919 - 923 MHz. + https://www.mcmc.gov.my/skmmgovmy/media/General/pdf/Short-Range-Devices-Specification.pdf + */ + RDEF(MY_919, 919.0f, 924.0f, 100, 0, 27, true, true, false), + + /* + Singapore + SG_923 Band 30d: 917 - 925 MHz at 100mW, no restrictions. + https://www.imda.gov.sg/-/media/imda/files/regulation-licensing-and-consultations/ict-standards/telecommunication-standards/radio-comms/imdatssrd.pdf */ + RDEF(SG_923, 917.0f, 925.0f, 100, 0, 20, true, false, false), + /* + 2.4 GHZ WLAN Band equivalent. Only for SX128x chips. + */ RDEF(LORA_24, 2400.0f, 2483.5f, 100, 0, 10, true, false, true), /* @@ -272,15 +294,14 @@ void printPacket(const char *prefix, const meshtastic_MeshPacket *p) out += " encrypted"; } - if (p->rx_time != 0) { + if (p->rx_time != 0) out += DEBUG_PORT.mt_sprintf(" rxtime=%u", p->rx_time); - } - if (p->rx_snr != 0.0) { + if (p->rx_snr != 0.0) out += DEBUG_PORT.mt_sprintf(" rxSNR=%g", p->rx_snr); - } - if (p->rx_rssi != 0) { + if (p->rx_rssi != 0) out += DEBUG_PORT.mt_sprintf(" rxRSSI=%i", p->rx_rssi); - } + if (p->via_mqtt != 0) + out += DEBUG_PORT.mt_sprintf(" via MQTT"); if (p->priority != 0) out += DEBUG_PORT.mt_sprintf(" priority=%d", p->priority); @@ -328,9 +349,9 @@ int RadioInterface::notifyDeepSleepCb(void *unused) * djb2 by Dan Bernstein. * http://www.cse.yorku.ca/~oz/hash.html */ -unsigned long hash(const char *str) +uint32_t hash(const char *str) { - unsigned long hash = 5381; + uint32_t hash = 5381; int c; while ((c = *str++) != 0) @@ -539,7 +560,7 @@ size_t RadioInterface::beginSending(meshtastic_MeshPacket *p) LOG_WARN("hop limit %d is too high, setting to %d\n", p->hop_limit, HOP_RELIABLE); p->hop_limit = HOP_RELIABLE; } - h->flags = p->hop_limit | (p->want_ack ? PACKET_FLAGS_WANT_ACK_MASK : 0); + h->flags = p->hop_limit | (p->want_ack ? PACKET_FLAGS_WANT_ACK_MASK : 0) | (p->via_mqtt ? PACKET_FLAGS_VIA_MQTT_MASK : 0); // if the sender nodenum is zero, that means uninitialized assert(h->from); diff --git a/src/mesh/RadioInterface.h b/src/mesh/RadioInterface.h index 85ce116dce..83c5dae645 100644 --- a/src/mesh/RadioInterface.h +++ b/src/mesh/RadioInterface.h @@ -12,6 +12,7 @@ #define PACKET_FLAGS_HOP_MASK 0x07 #define PACKET_FLAGS_WANT_ACK_MASK 0x08 +#define PACKET_FLAGS_VIA_MQTT_MASK 0x10 /** * This structure has to exactly match the wire layout when sent over the radio link. Used to keep compatibility @@ -223,4 +224,4 @@ class RadioInterface }; /// Debug printing for packets -void printPacket(const char *prefix, const meshtastic_MeshPacket *p); \ No newline at end of file +void printPacket(const char *prefix, const meshtastic_MeshPacket *p); diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 4f0c52e678..8a2bc53e5a 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -362,6 +362,7 @@ void RadioLibInterface::handleReceiveInterrupt() assert(HOP_MAX <= PACKET_FLAGS_HOP_MASK); // If hopmax changes, carefully check this code mp->hop_limit = h->flags & PACKET_FLAGS_HOP_MASK; mp->want_ack = !!(h->flags & PACKET_FLAGS_WANT_ACK_MASK); + mp->via_mqtt = !!(h->flags & PACKET_FLAGS_VIA_MQTT_MASK); addReceiveMetadata(mp); @@ -406,4 +407,4 @@ void RadioLibInterface::startSend(meshtastic_MeshPacket *txp) // bits enableInterrupt(isrTxLevel0); } -} \ No newline at end of file +} diff --git a/src/mesh/RadioLibRF95.cpp b/src/mesh/RadioLibRF95.cpp index f84ec28b71..1fe7869a37 100644 --- a/src/mesh/RadioLibRF95.cpp +++ b/src/mesh/RadioLibRF95.cpp @@ -21,7 +21,7 @@ int16_t RadioLibRF95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_ LOG_DEBUG("Current limit set result %d\n", state); // configure settings not accessible by API - state = config(); + // state = config(); RADIOLIB_ASSERT(state); #ifdef RF95_TCXO @@ -75,5 +75,6 @@ bool RadioLibRF95::isReceiving() uint8_t RadioLibRF95::readReg(uint8_t addr) { + Module *mod = this->getMod(); return mod->SPIreadRegister(addr); -} +} \ No newline at end of file diff --git a/src/mesh/ReliableRouter.cpp b/src/mesh/ReliableRouter.cpp index 946a669cc0..a1e9f281df 100644 --- a/src/mesh/ReliableRouter.cpp +++ b/src/mesh/ReliableRouter.cpp @@ -168,10 +168,14 @@ bool ReliableRouter::stopRetransmission(GlobalPacketId key) auto p = old->packet; auto numErased = pending.erase(key); assert(numErased == 1); - // remove the 'original' (identified by originator and packet->id) from the txqueue and free it - cancelSending(getFrom(p), p->id); - // now free the pooled copy for retransmission too - packetPool.release(p); + /* Only when we already transmitted a packet via LoRa, we will cancel the packet in the Tx queue + to avoid canceling a transmission if it was ACKed super fast via MQTT */ + if (old->numRetransmissions < NUM_RETRANSMISSIONS - 1) { + // remove the 'original' (identified by originator and packet->id) from the txqueue and free it + cancelSending(getFrom(p), p->id); + // now free the pooled copy for retransmission too + packetPool.release(p); + } return true; } else return false; diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 931642fca0..b8a33432a4 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -248,28 +248,20 @@ ErrorCode Router::send(meshtastic_MeshPacket *p) // If the packet is not yet encrypted, do so now if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { ChannelIndex chIndex = p->channel; // keep as a local because we are about to change it - - if (moduleConfig.mqtt.enabled) { - - LOG_INFO("Should encrypt MQTT?: %d\n", moduleConfig.mqtt.encryption_enabled); - - // the packet is currently in a decrypted state. send it now if they want decrypted packets - if (mqtt && !moduleConfig.mqtt.encryption_enabled) - mqtt->onSend(*p, chIndex); - } + meshtastic_MeshPacket *p_decoded = packetPool.allocCopy(*p); auto encodeResult = perhapsEncode(p); if (encodeResult != meshtastic_Routing_Error_NONE) { + packetPool.release(p_decoded); abortSendAndNak(encodeResult, p); return encodeResult; // FIXME - this isn't a valid ErrorCode } - if (moduleConfig.mqtt.enabled) { - // the packet is now encrypted. - // check if we should send encrypted packets to mqtt - if (mqtt && moduleConfig.mqtt.encryption_enabled) - mqtt->onSend(*p, chIndex); + // Only publish to MQTT if we're the original transmitter of the packet + if (moduleConfig.mqtt.enabled && p->from == nodeDB.getNodeNum() && mqtt) { + mqtt->onSend(*p, *p_decoded, chIndex); } + packetPool.release(p_decoded); } assert(iface); // This should have been detected already in sendLocal (or we just received a packet from outside) @@ -445,6 +437,8 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) { // Also, we should set the time from the ISR and it should have msec level resolution p->rx_time = getValidTime(RTCQualityFromNet); // store the arrival timestamp for the phone + // Store a copy of encrypted packet for MQTT + 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); @@ -456,10 +450,16 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) printPacket("handleReceived(USER)", p); else printPacket("handleReceived(REMOTE)", p); + + // Publish received message to MQTT if we're not the original transmitter of the packet + if (moduleConfig.mqtt.enabled && getFrom(p) != nodeDB.getNodeNum() && mqtt) + mqtt->onSend(*p_encrypted, *p, p->channel); } else { printPacket("packet decoding failed or skipped (no PSK?)", p); } + packetPool.release(p_encrypted); // Release the encrypted packet + // call modules here MeshModule::callPlugins(*p, src); } @@ -467,10 +467,10 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) void Router::perhapsHandleReceived(meshtastic_MeshPacket *p) { // assert(radioConfig.has_preferences); - bool ignore = is_in_repeated(config.lora.ignore_incoming, p->from); + bool ignore = is_in_repeated(config.lora.ignore_incoming, p->from) || (config.lora.ignore_mqtt && p->via_mqtt); if (ignore) { - LOG_DEBUG("Ignoring incoming message, 0x%x is in our ignore list\n", p->from); + LOG_DEBUG("Ignoring incoming message, 0x%x is in our ignore list or came via MQTT\n", p->from); } else if (ignore |= shouldFilterReceived(p)) { LOG_DEBUG("Incoming message was filtered 0x%x\n", p->from); } diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index 0692d1ef1d..7220dd3e5c 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -2,7 +2,7 @@ #include "configuration.h" #include "error.h" #include "mesh/NodeDB.h" -#ifdef ARCH_RASPBERRY_PI +#ifdef ARCH_PORTDUINO #include "PortduinoGlue.h" #endif @@ -30,18 +30,25 @@ template bool SX126xInterface::init() digitalWrite(SX126X_POWER_EN, HIGH); #endif +#if ARCH_PORTDUINO + float tcxoVoltage = 0; + if (settingsMap[dio3_tcxo_voltage]) + tcxoVoltage = 1.8; // FIXME: correct logic to default to not using TCXO if no voltage is specified for SX126X_DIO3_TCXO_VOLTAGE -#if !defined(SX126X_DIO3_TCXO_VOLTAGE) +#elif !defined(SX126X_DIO3_TCXO_VOLTAGE) float tcxoVoltage = 0; // "TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip." per // https://github.com/jgromes/RadioLib/blob/690a050ebb46e6097c5d00c371e961c1caa3b52e/src/modules/SX126x/SX126x.h#L471C26-L471C104 // (DIO3 is free to be used as an IRQ) - LOG_DEBUG("SX126X_DIO3_TCXO_VOLTAGE not defined, not using DIO3 as TCXO reference voltage\n"); #else float tcxoVoltage = SX126X_DIO3_TCXO_VOLTAGE; - LOG_DEBUG("SX126X_DIO3_TCXO_VOLTAGE defined, using DIO3 as TCXO reference voltage at %f V\n", SX126X_DIO3_TCXO_VOLTAGE); // (DIO3 is not free to be used as an IRQ) #endif + if (tcxoVoltage == 0) + LOG_DEBUG("SX126X_DIO3_TCXO_VOLTAGE not defined, not using DIO3 as TCXO reference voltage\n"); + else + LOG_DEBUG("SX126X_DIO3_TCXO_VOLTAGE defined, using DIO3 as TCXO reference voltage at %f V\n", tcxoVoltage); + // FIXME: May want to set depending on a definition, currently all SX126x variant files use the DC-DC regulator option bool useRegulatorLDO = false; // Seems to depend on the connection to pin 9/DCC_SW - if an inductor DCDC? @@ -77,7 +84,7 @@ template bool SX126xInterface::init() #ifdef SX126X_DIO2_AS_RF_SWITCH LOG_DEBUG("Setting DIO2 as RF switch\n"); bool dio2AsRfSwitch = true; -#elif defined(ARCH_RASPBERRY_PI) +#elif defined(ARCH_PORTDUINO) bool dio2AsRfSwitch = false; if (settingsMap[dio2_as_rf_switch]) { LOG_DEBUG("Setting DIO2 as RF switch\n"); @@ -93,6 +100,12 @@ template bool SX126xInterface::init() // If a pin isn't defined, we set it to RADIOLIB_NC, it is safe to always do external RF switching with RADIOLIB_NC as it has // no effect +#if ARCH_PORTDUINO + if (res == RADIOLIB_ERR_NONE) { + LOG_DEBUG("Using MCU pin %i as RXEN and pin %i as TXEN to control RF switching\n", settingsMap[rxen], settingsMap[txen]); + lora.setRfSwitchPins(settingsMap[rxen], settingsMap[txen]); + } +#else #ifndef SX126X_RXEN #define SX126X_RXEN RADIOLIB_NC LOG_DEBUG("SX126X_RXEN not defined, defaulting to RADIOLIB_NC\n"); @@ -105,7 +118,7 @@ template bool SX126xInterface::init() LOG_DEBUG("Using MCU pin %i as RXEN and pin %i as TXEN to control RF switching\n", SX126X_RXEN, SX126X_TXEN); lora.setRfSwitchPins(SX126X_RXEN, SX126X_TXEN); } - +#endif if (config.lora.sx126x_rx_boosted_gain) { uint16_t result = lora.setRxBoostedGainMode(true); LOG_INFO("Set RX gain to boosted mode; result: %d\n", result); @@ -167,11 +180,6 @@ template bool SX126xInterface::reconfigure() if (err != RADIOLIB_ERR_NONE) RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); - // Hmm - seems to lower SNR when the signal levels are high. Leaving off for now... - // TODO: Confirm gain registers are okay now - // err = lora.setRxGain(true); - // assert(err == RADIOLIB_ERR_NONE); - err = lora.setSyncWord(syncWord); assert(err == RADIOLIB_ERR_NONE); diff --git a/src/mesh/SX128xInterface.cpp b/src/mesh/SX128xInterface.cpp index 0c5c4dcfab..d0103ec291 100644 --- a/src/mesh/SX128xInterface.cpp +++ b/src/mesh/SX128xInterface.cpp @@ -3,6 +3,10 @@ #include "error.h" #include "mesh/NodeDB.h" +#if ARCH_PORTDUINO +#include "PortduinoGlue.h" +#endif + // Particular boards might define a different max power based on what their hardware can do #ifndef SX128X_MAX_POWER #define SX128X_MAX_POWER 13 @@ -31,6 +35,16 @@ template bool SX128xInterface::init() digitalWrite(RF95_FAN_EN, 1); #endif +#if ARCH_PORTDUINO + if (settingsMap[rxen] != RADIOLIB_NC) { + pinMode(settingsMap[rxen], OUTPUT); + digitalWrite(settingsMap[rxen], LOW); // Set low before becoming an output + } + if (settingsMap[txen] != RADIOLIB_NC) { + pinMode(settingsMap[txen], OUTPUT); + digitalWrite(settingsMap[txen], LOW); // Set low before becoming an output + } +#else #if defined(SX128X_RXEN) && (SX128X_RXEN != RADIOLIB_NC) // set not rx or tx mode pinMode(SX128X_RXEN, OUTPUT); digitalWrite(SX128X_RXEN, LOW); // Set low before becoming an output @@ -38,6 +52,7 @@ template bool SX128xInterface::init() #if defined(SX128X_TXEN) && (SX128X_TXEN != RADIOLIB_NC) pinMode(SX128X_TXEN, OUTPUT); digitalWrite(SX128X_TXEN, LOW); +#endif #endif RadioLibInterface::init(); @@ -75,6 +90,10 @@ template bool SX128xInterface::init() if (res == RADIOLIB_ERR_NONE) { lora.setRfSwitchPins(SX128X_RXEN, SX128X_TXEN); } +#elif ARCH_PORTDUINO + if (res == RADIOLIB_ERR_NONE && settingsMap[rxen] != RADIOLIB_NC && settingsMap[txen] != RADIOLIB_NC) { + lora.setRfSwitchPins(settingsMap[rxen], settingsMap[txen]); + } #endif if (res == RADIOLIB_ERR_NONE) @@ -106,11 +125,6 @@ template bool SX128xInterface::reconfigure() if (err != RADIOLIB_ERR_NONE) RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_INVALID_RADIO_SETTING); - // Hmm - seems to lower SNR when the signal levels are high. Leaving off for now... - // TODO: Confirm gain registers are okay now - // err = lora.setRxGain(true); - // assert(err == RADIOLIB_ERR_NONE); - err = lora.setSyncWord(syncWord); assert(err == RADIOLIB_ERR_NONE); @@ -153,14 +167,21 @@ template void SX128xInterface::setStandby() } assert(err == RADIOLIB_ERR_NONE); - +#if ARCH_PORTDUINO + if (settingsMap[rxen] != RADIOLIB_NC) { + digitalWrite(settingsMap[rxen], LOW); + } + if (settingsMap[txen] != RADIOLIB_NC) { + digitalWrite(settingsMap[txen], LOW); + } +#else #if defined(SX128X_RXEN) && (SX128X_RXEN != RADIOLIB_NC) // we have RXEN/TXEN control - turn off RX and TX power digitalWrite(SX128X_RXEN, LOW); #endif #if defined(SX128X_TXEN) && (SX128X_TXEN != RADIOLIB_NC) digitalWrite(SX128X_TXEN, LOW); #endif - +#endif isReceiving = false; // If we were receiving, not any more activeReceiveStart = 0; disableInterrupt(); @@ -181,11 +202,21 @@ template void SX128xInterface::addReceiveMetadata(meshtastic_Mes */ template void SX128xInterface::configHardwareForSend() { +#if ARCH_PORTDUINO + if (settingsMap[txen] != RADIOLIB_NC) { + digitalWrite(settingsMap[txen], HIGH); + } + if (settingsMap[rxen] != RADIOLIB_NC) { + digitalWrite(settingsMap[rxen], LOW); + } + +#else #if defined(SX128X_TXEN) && (SX128X_TXEN != RADIOLIB_NC) // we have RXEN/TXEN control - turn on TX power / off RX power digitalWrite(SX128X_TXEN, HIGH); #endif #if defined(SX128X_RXEN) && (SX128X_RXEN != RADIOLIB_NC) digitalWrite(SX128X_RXEN, LOW); +#endif #endif RadioLibInterface::configHardwareForSend(); @@ -202,16 +233,26 @@ template void SX128xInterface::startReceive() setStandby(); +#if ARCH_PORTDUINO + if (settingsMap[rxen] != RADIOLIB_NC) { + digitalWrite(settingsMap[rxen], HIGH); + } + if (settingsMap[txen] != RADIOLIB_NC) { + digitalWrite(settingsMap[txen], LOW); + } + +#else #if defined(SX128X_RXEN) && (SX128X_RXEN != RADIOLIB_NC) // we have RXEN/TXEN control - turn on RX power / off TX power digitalWrite(SX128X_RXEN, HIGH); #endif #if defined(SX128X_TXEN) && (SX128X_TXEN != RADIOLIB_NC) digitalWrite(SX128X_TXEN, LOW); +#endif #endif // We use the PREAMBLE_DETECTED and HEADER_VALID IRQ flag to detect whether we are actively receiving int err = lora.startReceive(RADIOLIB_SX128X_RX_TIMEOUT_INF, RADIOLIB_SX128X_IRQ_RX_DEFAULT | - RADIOLIB_SX128X_IRQ_RADIOLIB_PREAMBLE_DETECTED | + RADIOLIB_SX128X_IRQ_PREAMBLE_DETECTED | RADIOLIB_SX128X_IRQ_HEADER_VALID); assert(err == RADIOLIB_ERR_NONE); @@ -243,7 +284,7 @@ template bool SX128xInterface::isChannelActive() template bool SX128xInterface::isActivelyReceiving() { uint16_t irq = lora.getIrqStatus(); - bool detected = (irq & (RADIOLIB_SX128X_IRQ_HEADER_VALID | RADIOLIB_SX128X_IRQ_RADIOLIB_PREAMBLE_DETECTED)); + bool detected = (irq & (RADIOLIB_SX128X_IRQ_HEADER_VALID | RADIOLIB_SX128X_IRQ_PREAMBLE_DETECTED)); // Handle false detections if (detected) { diff --git a/src/mesh/api/WiFiServerAPI.cpp b/src/mesh/api/WiFiServerAPI.cpp index 5f86dbe853..ba31f76e5f 100644 --- a/src/mesh/api/WiFiServerAPI.cpp +++ b/src/mesh/api/WiFiServerAPI.cpp @@ -15,6 +15,10 @@ void initApiServer(int port) apiPort->init(); } } +void deInitApiServer() +{ + delete apiPort; +} WiFiServerAPI::WiFiServerAPI(WiFiClient &_client) : ServerAPI(_client) { @@ -22,4 +26,4 @@ WiFiServerAPI::WiFiServerAPI(WiFiClient &_client) : ServerAPI(_client) } WiFiServerPort::WiFiServerPort(int port) : APIServerPort(port) {} -#endif +#endif \ No newline at end of file diff --git a/src/mesh/api/WiFiServerAPI.h b/src/mesh/api/WiFiServerAPI.h index e436a177dd..7a3d2967f5 100644 --- a/src/mesh/api/WiFiServerAPI.h +++ b/src/mesh/api/WiFiServerAPI.h @@ -22,4 +22,5 @@ class WiFiServerPort : public APIServerPort explicit WiFiServerPort(int port); }; -void initApiServer(int port = 4403); \ No newline at end of file +void initApiServer(int port = 4403); +void deInitApiServer(); \ No newline at end of file diff --git a/src/mesh/eth/ethClient.cpp b/src/mesh/eth/ethClient.cpp index f10c96866d..97f5027bd1 100644 --- a/src/mesh/eth/ethClient.cpp +++ b/src/mesh/eth/ethClient.cpp @@ -97,11 +97,6 @@ static int32_t reconnectETH() return 5000; // every 5 seconds } -static uint32_t bigToLittleEndian(uint32_t value) -{ - return ((value >> 24) & 0xFF) | ((value >> 8) & 0xFF00) | ((value << 8) & 0xFF0000) | ((value << 24) & 0xFF000000); -} - // Startup Ethernet bool initEthernet() { @@ -130,14 +125,7 @@ bool initEthernet() status = Ethernet.begin(mac); } else if (config.network.address_mode == meshtastic_Config_NetworkConfig_AddressMode_STATIC) { LOG_INFO("starting Ethernet Static\n"); - - IPAddress ip = IPAddress(bigToLittleEndian(config.network.ipv4_config.ip)); - IPAddress dns = IPAddress(bigToLittleEndian(config.network.ipv4_config.dns)); - IPAddress gateway = IPAddress(bigToLittleEndian(config.network.ipv4_config.gateway)); - IPAddress subnet = IPAddress(bigToLittleEndian(config.network.ipv4_config.subnet)); - - Ethernet.begin(mac, ip, dns, gateway, subnet); - + Ethernet.begin(mac, config.network.ipv4_config.ip, config.network.ipv4_config.dns, config.network.ipv4_config.subnet); status = 1; } else { LOG_INFO("Ethernet Disabled\n"); diff --git a/src/mesh/generated/meshtastic/admin.pb.h b/src/mesh/generated/meshtastic/admin.pb.h index 9978c55917..28bda429d5 100644 --- a/src/mesh/generated/meshtastic/admin.pb.h +++ b/src/mesh/generated/meshtastic/admin.pb.h @@ -59,7 +59,9 @@ typedef enum _meshtastic_AdminMessage_ModuleConfigType { /* TODO: REPLACE */ meshtastic_AdminMessage_ModuleConfigType_AMBIENTLIGHTING_CONFIG = 10, /* TODO: REPLACE */ - meshtastic_AdminMessage_ModuleConfigType_DETECTIONSENSOR_CONFIG = 11 + meshtastic_AdminMessage_ModuleConfigType_DETECTIONSENSOR_CONFIG = 11, + /* TODO: REPLACE */ + meshtastic_AdminMessage_ModuleConfigType_PAXCOUNTER_CONFIG = 12 } meshtastic_AdminMessage_ModuleConfigType; /* Struct definitions */ @@ -129,6 +131,11 @@ typedef struct _meshtastic_AdminMessage { bool get_node_remote_hardware_pins_request; /* Respond with the mesh's nodes with their available gpio pins for RemoteHardware module use */ meshtastic_NodeRemoteHardwarePinsResponse get_node_remote_hardware_pins_response; + /* Enter (UF2) DFU mode + Only implemented on NRF52 currently */ + bool enter_dfu_mode_request; + /* Delete the file by the specified path from the device */ + char delete_file_request[201]; /* Set the owner for this node */ meshtastic_User set_owner; /* Set channels (using the new API). @@ -180,8 +187,8 @@ extern "C" { #define _meshtastic_AdminMessage_ConfigType_ARRAYSIZE ((meshtastic_AdminMessage_ConfigType)(meshtastic_AdminMessage_ConfigType_BLUETOOTH_CONFIG+1)) #define _meshtastic_AdminMessage_ModuleConfigType_MIN meshtastic_AdminMessage_ModuleConfigType_MQTT_CONFIG -#define _meshtastic_AdminMessage_ModuleConfigType_MAX meshtastic_AdminMessage_ModuleConfigType_DETECTIONSENSOR_CONFIG -#define _meshtastic_AdminMessage_ModuleConfigType_ARRAYSIZE ((meshtastic_AdminMessage_ModuleConfigType)(meshtastic_AdminMessage_ModuleConfigType_DETECTIONSENSOR_CONFIG+1)) +#define _meshtastic_AdminMessage_ModuleConfigType_MAX meshtastic_AdminMessage_ModuleConfigType_PAXCOUNTER_CONFIG +#define _meshtastic_AdminMessage_ModuleConfigType_ARRAYSIZE ((meshtastic_AdminMessage_ModuleConfigType)(meshtastic_AdminMessage_ModuleConfigType_PAXCOUNTER_CONFIG+1)) #define meshtastic_AdminMessage_payload_variant_get_config_request_ENUMTYPE meshtastic_AdminMessage_ConfigType #define meshtastic_AdminMessage_payload_variant_get_module_config_request_ENUMTYPE meshtastic_AdminMessage_ModuleConfigType @@ -222,6 +229,8 @@ extern "C" { #define meshtastic_AdminMessage_set_ham_mode_tag 18 #define meshtastic_AdminMessage_get_node_remote_hardware_pins_request_tag 19 #define meshtastic_AdminMessage_get_node_remote_hardware_pins_response_tag 20 +#define meshtastic_AdminMessage_enter_dfu_mode_request_tag 21 +#define meshtastic_AdminMessage_delete_file_request_tag 22 #define meshtastic_AdminMessage_set_owner_tag 32 #define meshtastic_AdminMessage_set_channel_tag 33 #define meshtastic_AdminMessage_set_config_tag 34 @@ -259,6 +268,8 @@ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,get_device_connection_status X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_ham_mode,set_ham_mode), 18) \ X(a, STATIC, ONEOF, BOOL, (payload_variant,get_node_remote_hardware_pins_request,get_node_remote_hardware_pins_request), 19) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,get_node_remote_hardware_pins_response,get_node_remote_hardware_pins_response), 20) \ +X(a, STATIC, ONEOF, BOOL, (payload_variant,enter_dfu_mode_request,enter_dfu_mode_request), 21) \ +X(a, STATIC, ONEOF, STRING, (payload_variant,delete_file_request,delete_file_request), 22) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_owner,set_owner), 32) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_channel,set_channel), 33) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,set_config,set_config), 34) \ diff --git a/src/mesh/generated/meshtastic/apponly.pb.h b/src/mesh/generated/meshtastic/apponly.pb.h index b66af0ebdf..253fdd8ef9 100644 --- a/src/mesh/generated/meshtastic/apponly.pb.h +++ b/src/mesh/generated/meshtastic/apponly.pb.h @@ -54,7 +54,7 @@ extern const pb_msgdesc_t meshtastic_ChannelSet_msg; #define meshtastic_ChannelSet_fields &meshtastic_ChannelSet_msg /* Maximum encoded size of messages (where known) */ -#define meshtastic_ChannelSet_size 591 +#define meshtastic_ChannelSet_size 658 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/meshtastic/atak.pb.c b/src/mesh/generated/meshtastic/atak.pb.c new file mode 100644 index 0000000000..1413b748ea --- /dev/null +++ b/src/mesh/generated/meshtastic/atak.pb.c @@ -0,0 +1,29 @@ +/* Automatically generated nanopb constant definitions */ +/* Generated by nanopb-0.4.7 */ + +#include "meshtastic/atak.pb.h" +#if PB_PROTO_HEADER_VERSION != 40 +#error Regenerate this file with the current version of nanopb generator. +#endif + +PB_BIND(meshtastic_TAKPacket, meshtastic_TAKPacket, 2) + + +PB_BIND(meshtastic_GeoChat, meshtastic_GeoChat, 2) + + +PB_BIND(meshtastic_Group, meshtastic_Group, AUTO) + + +PB_BIND(meshtastic_Status, meshtastic_Status, AUTO) + + +PB_BIND(meshtastic_Contact, meshtastic_Contact, AUTO) + + +PB_BIND(meshtastic_PLI, meshtastic_PLI, AUTO) + + + + + diff --git a/src/mesh/generated/meshtastic/atak.pb.h b/src/mesh/generated/meshtastic/atak.pb.h new file mode 100644 index 0000000000..17d3cd3b9a --- /dev/null +++ b/src/mesh/generated/meshtastic/atak.pb.h @@ -0,0 +1,274 @@ +/* Automatically generated nanopb header */ +/* Generated by nanopb-0.4.7 */ + +#ifndef PB_MESHTASTIC_MESHTASTIC_ATAK_PB_H_INCLUDED +#define PB_MESHTASTIC_MESHTASTIC_ATAK_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_Team { + /* Unspecifed */ + meshtastic_Team_Unspecifed_Color = 0, + /* White */ + meshtastic_Team_White = 1, + /* Yellow */ + meshtastic_Team_Yellow = 2, + /* Orange */ + meshtastic_Team_Orange = 3, + /* Magenta */ + meshtastic_Team_Magenta = 4, + /* Red */ + meshtastic_Team_Red = 5, + /* Maroon */ + meshtastic_Team_Maroon = 6, + /* Purple */ + meshtastic_Team_Purple = 7, + /* Dark Blue */ + meshtastic_Team_Dark_Blue = 8, + /* Blue */ + meshtastic_Team_Blue = 9, + /* Cyan */ + meshtastic_Team_Cyan = 10, + /* Teal */ + meshtastic_Team_Teal = 11, + /* Green */ + meshtastic_Team_Green = 12, + /* Dark Green */ + meshtastic_Team_Dark_Green = 13, + /* Brown */ + meshtastic_Team_Brown = 14 +} meshtastic_Team; + +/* Role of the group member */ +typedef enum _meshtastic_MemberRole { + /* Unspecifed */ + meshtastic_MemberRole_Unspecifed = 0, + /* Team Member */ + meshtastic_MemberRole_TeamMember = 1, + /* Team Lead */ + meshtastic_MemberRole_TeamLead = 2, + /* Headquarters */ + meshtastic_MemberRole_HQ = 3, + /* Airsoft enthusiast */ + meshtastic_MemberRole_Sniper = 4, + /* Medic */ + meshtastic_MemberRole_Medic = 5, + /* ForwardObserver */ + meshtastic_MemberRole_ForwardObserver = 6, + /* Radio Telephone Operator */ + meshtastic_MemberRole_RTO = 7, + /* Doggo */ + meshtastic_MemberRole_K9 = 8 +} meshtastic_MemberRole; + +/* Struct definitions */ +/* ATAK GeoChat message */ +typedef struct _meshtastic_GeoChat { + /* The text message */ + char message[200]; + /* Uid recipient of the message */ + bool has_to; + char to[120]; +} meshtastic_GeoChat; + +/* ATAK Group + <__group role='Team Member' name='Cyan'/> */ +typedef struct _meshtastic_Group { + /* Role of the group member */ + meshtastic_MemberRole role; + /* Team (color) + Default Cyan */ + meshtastic_Team team; +} meshtastic_Group; + +/* ATAK EUD Status + */ +typedef struct _meshtastic_Status { + /* Battery level */ + uint8_t battery; +} meshtastic_Status; + +/* ATAK Contact + */ +typedef struct _meshtastic_Contact { + /* Callsign */ + char callsign[120]; + /* Device callsign */ + char device_callsign[120]; /* IP address of endpoint in integer form (0.0.0.0 default) */ +} meshtastic_Contact; + +/* Position Location Information from ATAK */ +typedef struct _meshtastic_PLI { + /* The new preferred location encoding, multiply by 1e-7 to get degrees + in floating point */ + int32_t latitude_i; + /* The new preferred location encoding, multiply by 1e-7 to get degrees + in floating point */ + int32_t longitude_i; + /* Altitude (ATAK prefers HAE) */ + int32_t altitude; + /* Speed */ + uint32_t speed; + /* Course in degrees */ + uint16_t course; +} meshtastic_PLI; + +/* Packets for the official ATAK Plugin */ +typedef struct _meshtastic_TAKPacket { + /* Are the payloads strings compressed for LoRA transport? */ + bool is_compressed; + /* The contact / callsign for ATAK user */ + bool has_contact; + meshtastic_Contact contact; + /* The group for ATAK user */ + bool has_group; + meshtastic_Group group; + /* The status of the ATAK EUD */ + bool has_status; + meshtastic_Status status; + pb_size_t which_payload_variant; + union { + /* TAK position report */ + meshtastic_PLI pli; + /* ATAK GeoChat message */ + meshtastic_GeoChat chat; + } payload_variant; +} meshtastic_TAKPacket; + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Helper constants for enums */ +#define _meshtastic_Team_MIN meshtastic_Team_Unspecifed_Color +#define _meshtastic_Team_MAX meshtastic_Team_Brown +#define _meshtastic_Team_ARRAYSIZE ((meshtastic_Team)(meshtastic_Team_Brown+1)) + +#define _meshtastic_MemberRole_MIN meshtastic_MemberRole_Unspecifed +#define _meshtastic_MemberRole_MAX meshtastic_MemberRole_K9 +#define _meshtastic_MemberRole_ARRAYSIZE ((meshtastic_MemberRole)(meshtastic_MemberRole_K9+1)) + + + +#define meshtastic_Group_role_ENUMTYPE meshtastic_MemberRole +#define meshtastic_Group_team_ENUMTYPE meshtastic_Team + + + + + +/* Initializer values for message structs */ +#define meshtastic_TAKPacket_init_default {0, false, meshtastic_Contact_init_default, false, meshtastic_Group_init_default, false, meshtastic_Status_init_default, 0, {meshtastic_PLI_init_default}} +#define meshtastic_GeoChat_init_default {"", false, ""} +#define meshtastic_Group_init_default {_meshtastic_MemberRole_MIN, _meshtastic_Team_MIN} +#define meshtastic_Status_init_default {0} +#define meshtastic_Contact_init_default {"", ""} +#define meshtastic_PLI_init_default {0, 0, 0, 0, 0} +#define meshtastic_TAKPacket_init_zero {0, false, meshtastic_Contact_init_zero, false, meshtastic_Group_init_zero, false, meshtastic_Status_init_zero, 0, {meshtastic_PLI_init_zero}} +#define meshtastic_GeoChat_init_zero {"", false, ""} +#define meshtastic_Group_init_zero {_meshtastic_MemberRole_MIN, _meshtastic_Team_MIN} +#define meshtastic_Status_init_zero {0} +#define meshtastic_Contact_init_zero {"", ""} +#define meshtastic_PLI_init_zero {0, 0, 0, 0, 0} + +/* Field tags (for use in manual encoding/decoding) */ +#define meshtastic_GeoChat_message_tag 1 +#define meshtastic_GeoChat_to_tag 2 +#define meshtastic_Group_role_tag 1 +#define meshtastic_Group_team_tag 2 +#define meshtastic_Status_battery_tag 1 +#define meshtastic_Contact_callsign_tag 1 +#define meshtastic_Contact_device_callsign_tag 2 +#define meshtastic_PLI_latitude_i_tag 1 +#define meshtastic_PLI_longitude_i_tag 2 +#define meshtastic_PLI_altitude_tag 3 +#define meshtastic_PLI_speed_tag 4 +#define meshtastic_PLI_course_tag 5 +#define meshtastic_TAKPacket_is_compressed_tag 1 +#define meshtastic_TAKPacket_contact_tag 2 +#define meshtastic_TAKPacket_group_tag 3 +#define meshtastic_TAKPacket_status_tag 4 +#define meshtastic_TAKPacket_pli_tag 5 +#define meshtastic_TAKPacket_chat_tag 6 + +/* Struct field encoding specification for nanopb */ +#define meshtastic_TAKPacket_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, BOOL, is_compressed, 1) \ +X(a, STATIC, OPTIONAL, MESSAGE, contact, 2) \ +X(a, STATIC, OPTIONAL, MESSAGE, group, 3) \ +X(a, STATIC, OPTIONAL, MESSAGE, status, 4) \ +X(a, STATIC, ONEOF, MESSAGE, (payload_variant,pli,payload_variant.pli), 5) \ +X(a, STATIC, ONEOF, MESSAGE, (payload_variant,chat,payload_variant.chat), 6) +#define meshtastic_TAKPacket_CALLBACK NULL +#define meshtastic_TAKPacket_DEFAULT NULL +#define meshtastic_TAKPacket_contact_MSGTYPE meshtastic_Contact +#define meshtastic_TAKPacket_group_MSGTYPE meshtastic_Group +#define meshtastic_TAKPacket_status_MSGTYPE meshtastic_Status +#define meshtastic_TAKPacket_payload_variant_pli_MSGTYPE meshtastic_PLI +#define meshtastic_TAKPacket_payload_variant_chat_MSGTYPE meshtastic_GeoChat + +#define meshtastic_GeoChat_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, STRING, message, 1) \ +X(a, STATIC, OPTIONAL, STRING, to, 2) +#define meshtastic_GeoChat_CALLBACK NULL +#define meshtastic_GeoChat_DEFAULT NULL + +#define meshtastic_Group_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, UENUM, role, 1) \ +X(a, STATIC, SINGULAR, UENUM, team, 2) +#define meshtastic_Group_CALLBACK NULL +#define meshtastic_Group_DEFAULT NULL + +#define meshtastic_Status_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, UINT32, battery, 1) +#define meshtastic_Status_CALLBACK NULL +#define meshtastic_Status_DEFAULT NULL + +#define meshtastic_Contact_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, STRING, callsign, 1) \ +X(a, STATIC, SINGULAR, STRING, device_callsign, 2) +#define meshtastic_Contact_CALLBACK NULL +#define meshtastic_Contact_DEFAULT NULL + +#define meshtastic_PLI_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, SFIXED32, latitude_i, 1) \ +X(a, STATIC, SINGULAR, SFIXED32, longitude_i, 2) \ +X(a, STATIC, SINGULAR, INT32, altitude, 3) \ +X(a, STATIC, SINGULAR, UINT32, speed, 4) \ +X(a, STATIC, SINGULAR, UINT32, course, 5) +#define meshtastic_PLI_CALLBACK NULL +#define meshtastic_PLI_DEFAULT NULL + +extern const pb_msgdesc_t meshtastic_TAKPacket_msg; +extern const pb_msgdesc_t meshtastic_GeoChat_msg; +extern const pb_msgdesc_t meshtastic_Group_msg; +extern const pb_msgdesc_t meshtastic_Status_msg; +extern const pb_msgdesc_t meshtastic_Contact_msg; +extern const pb_msgdesc_t meshtastic_PLI_msg; + +/* Defines for backwards compatibility with code written before nanopb-0.4.0 */ +#define meshtastic_TAKPacket_fields &meshtastic_TAKPacket_msg +#define meshtastic_GeoChat_fields &meshtastic_GeoChat_msg +#define meshtastic_Group_fields &meshtastic_Group_msg +#define meshtastic_Status_fields &meshtastic_Status_msg +#define meshtastic_Contact_fields &meshtastic_Contact_msg +#define meshtastic_PLI_fields &meshtastic_PLI_msg + +/* Maximum encoded size of messages (where known) */ +#define meshtastic_Contact_size 242 +#define meshtastic_GeoChat_size 323 +#define meshtastic_Group_size 4 +#define meshtastic_PLI_size 31 +#define meshtastic_Status_size 3 +#define meshtastic_TAKPacket_size 584 + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/src/mesh/generated/meshtastic/channel.pb.c b/src/mesh/generated/meshtastic/channel.pb.c index 62585fd179..f604f64e91 100644 --- a/src/mesh/generated/meshtastic/channel.pb.c +++ b/src/mesh/generated/meshtastic/channel.pb.c @@ -9,6 +9,9 @@ PB_BIND(meshtastic_ChannelSettings, meshtastic_ChannelSettings, AUTO) +PB_BIND(meshtastic_ModuleSettings, meshtastic_ModuleSettings, AUTO) + + PB_BIND(meshtastic_Channel, meshtastic_Channel, AUTO) diff --git a/src/mesh/generated/meshtastic/channel.pb.h b/src/mesh/generated/meshtastic/channel.pb.h index 535962ae6f..1587483c0e 100644 --- a/src/mesh/generated/meshtastic/channel.pb.h +++ b/src/mesh/generated/meshtastic/channel.pb.h @@ -30,6 +30,12 @@ typedef enum _meshtastic_Channel_Role { } meshtastic_Channel_Role; /* Struct definitions */ +/* This message is specifically for modules to store per-channel configuration data. */ +typedef struct _meshtastic_ModuleSettings { + /* Bits of precision for the location sent in position packets. */ + uint32_t position_precision; +} meshtastic_ModuleSettings; + typedef PB_BYTES_ARRAY_T(32) meshtastic_ChannelSettings_psk_t; /* This information can be encoded as a QRcode/url so that other users can configure their radio to join the same channel. @@ -85,6 +91,9 @@ typedef struct _meshtastic_ChannelSettings { bool uplink_enabled; /* If true, messages seen on the internet will be forwarded to the local mesh. */ bool downlink_enabled; + /* Per-channel module settings. */ + bool has_module_settings; + meshtastic_ModuleSettings module_settings; } meshtastic_ChannelSettings; /* A pair of a channel number, mode and the (sharable) settings for that channel */ @@ -111,22 +120,27 @@ extern "C" { #define _meshtastic_Channel_Role_ARRAYSIZE ((meshtastic_Channel_Role)(meshtastic_Channel_Role_SECONDARY+1)) + #define meshtastic_Channel_role_ENUMTYPE meshtastic_Channel_Role /* Initializer values for message structs */ -#define meshtastic_ChannelSettings_init_default {0, {0, {0}}, "", 0, 0, 0} +#define meshtastic_ChannelSettings_init_default {0, {0, {0}}, "", 0, 0, 0, false, meshtastic_ModuleSettings_init_default} +#define meshtastic_ModuleSettings_init_default {0} #define meshtastic_Channel_init_default {0, false, meshtastic_ChannelSettings_init_default, _meshtastic_Channel_Role_MIN} -#define meshtastic_ChannelSettings_init_zero {0, {0, {0}}, "", 0, 0, 0} +#define meshtastic_ChannelSettings_init_zero {0, {0, {0}}, "", 0, 0, 0, false, meshtastic_ModuleSettings_init_zero} +#define meshtastic_ModuleSettings_init_zero {0} #define meshtastic_Channel_init_zero {0, false, meshtastic_ChannelSettings_init_zero, _meshtastic_Channel_Role_MIN} /* Field tags (for use in manual encoding/decoding) */ +#define meshtastic_ModuleSettings_position_precision_tag 1 #define meshtastic_ChannelSettings_channel_num_tag 1 #define meshtastic_ChannelSettings_psk_tag 2 #define meshtastic_ChannelSettings_name_tag 3 #define meshtastic_ChannelSettings_id_tag 4 #define meshtastic_ChannelSettings_uplink_enabled_tag 5 #define meshtastic_ChannelSettings_downlink_enabled_tag 6 +#define meshtastic_ChannelSettings_module_settings_tag 7 #define meshtastic_Channel_index_tag 1 #define meshtastic_Channel_settings_tag 2 #define meshtastic_Channel_role_tag 3 @@ -138,9 +152,16 @@ X(a, STATIC, SINGULAR, BYTES, psk, 2) \ X(a, STATIC, SINGULAR, STRING, name, 3) \ X(a, STATIC, SINGULAR, FIXED32, id, 4) \ X(a, STATIC, SINGULAR, BOOL, uplink_enabled, 5) \ -X(a, STATIC, SINGULAR, BOOL, downlink_enabled, 6) +X(a, STATIC, SINGULAR, BOOL, downlink_enabled, 6) \ +X(a, STATIC, OPTIONAL, MESSAGE, module_settings, 7) #define meshtastic_ChannelSettings_CALLBACK NULL #define meshtastic_ChannelSettings_DEFAULT NULL +#define meshtastic_ChannelSettings_module_settings_MSGTYPE meshtastic_ModuleSettings + +#define meshtastic_ModuleSettings_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, UINT32, position_precision, 1) +#define meshtastic_ModuleSettings_CALLBACK NULL +#define meshtastic_ModuleSettings_DEFAULT NULL #define meshtastic_Channel_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, INT32, index, 1) \ @@ -151,15 +172,18 @@ X(a, STATIC, SINGULAR, UENUM, role, 3) #define meshtastic_Channel_settings_MSGTYPE meshtastic_ChannelSettings extern const pb_msgdesc_t meshtastic_ChannelSettings_msg; +extern const pb_msgdesc_t meshtastic_ModuleSettings_msg; extern const pb_msgdesc_t meshtastic_Channel_msg; /* Defines for backwards compatibility with code written before nanopb-0.4.0 */ #define meshtastic_ChannelSettings_fields &meshtastic_ChannelSettings_msg +#define meshtastic_ModuleSettings_fields &meshtastic_ModuleSettings_msg #define meshtastic_Channel_fields &meshtastic_Channel_msg /* Maximum encoded size of messages (where known) */ -#define meshtastic_ChannelSettings_size 62 -#define meshtastic_Channel_size 77 +#define meshtastic_ChannelSettings_size 70 +#define meshtastic_Channel_size 85 +#define meshtastic_ModuleSettings_size 6 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/meshtastic/config.pb.c b/src/mesh/generated/meshtastic/config.pb.c index 361e28d7cf..0fa8ba5888 100644 --- a/src/mesh/generated/meshtastic/config.pb.c +++ b/src/mesh/generated/meshtastic/config.pb.c @@ -45,3 +45,4 @@ PB_BIND(meshtastic_Config_BluetoothConfig, meshtastic_Config_BluetoothConfig, AU + diff --git a/src/mesh/generated/meshtastic/config.pb.h b/src/mesh/generated/meshtastic/config.pb.h index 8406dc8879..c56cf65a02 100644 --- a/src/mesh/generated/meshtastic/config.pb.h +++ b/src/mesh/generated/meshtastic/config.pb.h @@ -12,49 +12,53 @@ /* Enum definitions */ /* Defines the device's role on the Mesh network */ typedef enum _meshtastic_Config_DeviceConfig_Role { - /* Client device role */ + /* Description: App connected or stand alone messaging device. + Technical Details: Default Role */ meshtastic_Config_DeviceConfig_Role_CLIENT = 0, - /* Client Mute device role - Same as a client except packets will not hop over this node, does not contribute to routing packets for mesh. */ + /* Description: Device that does not forward packets from other devices. */ meshtastic_Config_DeviceConfig_Role_CLIENT_MUTE = 1, - /* Router device role. - Mesh packets will prefer to be routed over this node. This node will not be used by client apps. - The wifi/ble radios and the oled screen will be put to sleep. + /* Description: Infrastructure node for extending network coverage by relaying messages. Visible in Nodes list. + Technical Details: Mesh packets will prefer to be routed over this node. This node will not be used by client apps. + The wifi radio and the oled screen will be put to sleep. This mode may still potentially have higher power usage due to it's preference in message rebroadcasting on the mesh. */ meshtastic_Config_DeviceConfig_Role_ROUTER = 2, - /* Router Client device role - Mesh packets will prefer to be routed over this node. The Router Client can be used as both a Router and an app connected Client. */ + /* Description: Combination of both ROUTER and CLIENT. Not for mobile devices. */ meshtastic_Config_DeviceConfig_Role_ROUTER_CLIENT = 3, - /* Repeater device role - Mesh packets will simply be rebroadcasted over this node. Nodes configured with this role will not originate NodeInfo, Position, Telemetry + /* Description: Infrastructure node for extending network coverage by relaying messages with minimal overhead. Not visible in Nodes list. + Technical Details: Mesh packets will simply be rebroadcasted over this node. Nodes configured with this role will not originate NodeInfo, Position, Telemetry or any other packet type. They will simply rebroadcast any mesh packets on the same frequency, channel num, spread factor, and coding rate. */ meshtastic_Config_DeviceConfig_Role_REPEATER = 4, - /* Tracker device role - Position Mesh packets will be prioritized higher and sent more frequently by default. + /* Description: Broadcasts GPS position packets as priority. + Technical Details: Position Mesh packets will be prioritized higher and sent more frequently by default. When used in conjunction with power.is_power_saving = true, nodes will wake up, send position, and then sleep for position.position_broadcast_secs seconds. */ meshtastic_Config_DeviceConfig_Role_TRACKER = 5, - /* Sensor device role - Telemetry Mesh packets will be prioritized higher and sent more frequently by default. + /* Description: Broadcasts telemetry packets as priority. + Technical Details: Telemetry Mesh packets will be prioritized higher and sent more frequently by default. When used in conjunction with power.is_power_saving = true, nodes will wake up, send environment telemetry, and then sleep for telemetry.environment_update_interval seconds. */ meshtastic_Config_DeviceConfig_Role_SENSOR = 6, - /* TAK device role - Used for nodes dedicated for connection to an ATAK EUD. + /* Description: Optimized for ATAK system communication and reduces routine broadcasts. + Technical Details: Used for nodes dedicated for connection to an ATAK EUD. Turns off many of the routine broadcasts to favor CoT packet stream from the Meshtastic ATAK plugin -> IMeshService -> Node */ meshtastic_Config_DeviceConfig_Role_TAK = 7, - /* Client Hidden device role - Used for nodes that "only speak when spoken to" + /* Description: Device that only broadcasts as needed for stealth or power savings. + Technical Details: Used for nodes that "only speak when spoken to" Turns all of the routine broadcasts but allows for ad-hoc communication Still rebroadcasts, but with local only rebroadcast mode (known meshes only) Can be used for clandestine operation or to dramatically reduce airtime / power consumption */ meshtastic_Config_DeviceConfig_Role_CLIENT_HIDDEN = 8, - /* Lost and Found device role - Used to automatically send a text message to the mesh + /* Description: Broadcasts location as message to default channel regularly for to assist with device recovery. + Technical Details: Used to automatically send a text message to the mesh with the current position of the device on a frequent interval: "I'm lost! Position: lat / long" */ - meshtastic_Config_DeviceConfig_Role_LOST_AND_FOUND = 9 + meshtastic_Config_DeviceConfig_Role_LOST_AND_FOUND = 9, + /* Description: Enables automatic TAK PLI broadcasts and reduces routine broadcasts. + Technical Details: Turns off many of the routine broadcasts to favor ATAK CoT packet stream + and automatic TAK PLI (position location information) broadcasts. + Uses position module configuration to determine TAK PLI broadcast interval. */ + meshtastic_Config_DeviceConfig_Role_TAK_TRACKER = 10 } meshtastic_Config_DeviceConfig_Role; /* Defines the device's behavior for how messages are rebroadcast */ @@ -108,6 +112,15 @@ typedef enum _meshtastic_Config_PositionConfig_PositionFlags { meshtastic_Config_PositionConfig_PositionFlags_SPEED = 512 } meshtastic_Config_PositionConfig_PositionFlags; +typedef enum _meshtastic_Config_PositionConfig_GpsMode { + /* GPS is present but disabled */ + meshtastic_Config_PositionConfig_GpsMode_DISABLED = 0, + /* GPS is present and enabled */ + meshtastic_Config_PositionConfig_GpsMode_ENABLED = 1, + /* GPS is not present on the device */ + meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT = 2 +} meshtastic_Config_PositionConfig_GpsMode; + typedef enum _meshtastic_Config_NetworkConfig_AddressMode { /* obtain ip address via DHCP */ meshtastic_Config_NetworkConfig_AddressMode_DHCP = 0, @@ -201,7 +214,13 @@ typedef enum _meshtastic_Config_LoRaConfig_RegionCode { /* Ukraine 433mhz */ meshtastic_Config_LoRaConfig_RegionCode_UA_433 = 14, /* Ukraine 868mhz */ - meshtastic_Config_LoRaConfig_RegionCode_UA_868 = 15 + meshtastic_Config_LoRaConfig_RegionCode_UA_868 = 15, + /* Malaysia 433mhz */ + meshtastic_Config_LoRaConfig_RegionCode_MY_433 = 16, + /* Malaysia 919mhz */ + meshtastic_Config_LoRaConfig_RegionCode_MY_919 = 17, + /* Singapore 923mhz */ + meshtastic_Config_LoRaConfig_RegionCode_SG_923 = 18 } meshtastic_Config_LoRaConfig_RegionCode; /* Standard predefined channel settings @@ -281,10 +300,7 @@ typedef struct _meshtastic_Config_PositionConfig { or zero for the default of once every 30 seconds or a very large value (maxint) to update only once at boot. */ uint32_t gps_update_interval; - /* How long should we try to get our position during each gps_update_interval attempt? (in seconds) - Or if zero, use the default of 30 seconds. - If we don't get a new gps fix in that time, the gps will be put into sleep until the next gps_update_rate - window. */ + /* Deprecated in favor of using smart / regular broadcast intervals as implicit attempt time */ uint32_t gps_attempt_time; /* Bit field of boolean configuration options for POSITION messages (bitwise OR of PositionFlags) */ @@ -299,6 +315,8 @@ typedef struct _meshtastic_Config_PositionConfig { uint32_t broadcast_smart_minimum_interval_secs; /* (Re)define PIN_GPS_EN for your board. */ uint32_t gps_en_gpio; + /* Set where GPS is enabled, disabled, or not present */ + meshtastic_Config_PositionConfig_GpsMode gps_mode; } meshtastic_Config_PositionConfig; /* Power Config\ @@ -462,6 +480,8 @@ typedef struct _meshtastic_Config_LoRaConfig { in ignore_incoming will have packets they send dropped on receive (by router.cpp) */ pb_size_t ignore_incoming_count; uint32_t ignore_incoming[3]; + /* If true, the device will not process any packets received via LoRa that passed via MQTT anywhere on the path towards it. */ + bool ignore_mqtt; } meshtastic_Config_LoRaConfig; typedef struct _meshtastic_Config_BluetoothConfig { @@ -493,8 +513,8 @@ extern "C" { /* Helper constants for enums */ #define _meshtastic_Config_DeviceConfig_Role_MIN meshtastic_Config_DeviceConfig_Role_CLIENT -#define _meshtastic_Config_DeviceConfig_Role_MAX meshtastic_Config_DeviceConfig_Role_LOST_AND_FOUND -#define _meshtastic_Config_DeviceConfig_Role_ARRAYSIZE ((meshtastic_Config_DeviceConfig_Role)(meshtastic_Config_DeviceConfig_Role_LOST_AND_FOUND+1)) +#define _meshtastic_Config_DeviceConfig_Role_MAX meshtastic_Config_DeviceConfig_Role_TAK_TRACKER +#define _meshtastic_Config_DeviceConfig_Role_ARRAYSIZE ((meshtastic_Config_DeviceConfig_Role)(meshtastic_Config_DeviceConfig_Role_TAK_TRACKER+1)) #define _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN meshtastic_Config_DeviceConfig_RebroadcastMode_ALL #define _meshtastic_Config_DeviceConfig_RebroadcastMode_MAX meshtastic_Config_DeviceConfig_RebroadcastMode_KNOWN_ONLY @@ -504,6 +524,10 @@ extern "C" { #define _meshtastic_Config_PositionConfig_PositionFlags_MAX meshtastic_Config_PositionConfig_PositionFlags_SPEED #define _meshtastic_Config_PositionConfig_PositionFlags_ARRAYSIZE ((meshtastic_Config_PositionConfig_PositionFlags)(meshtastic_Config_PositionConfig_PositionFlags_SPEED+1)) +#define _meshtastic_Config_PositionConfig_GpsMode_MIN meshtastic_Config_PositionConfig_GpsMode_DISABLED +#define _meshtastic_Config_PositionConfig_GpsMode_MAX meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT +#define _meshtastic_Config_PositionConfig_GpsMode_ARRAYSIZE ((meshtastic_Config_PositionConfig_GpsMode)(meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT+1)) + #define _meshtastic_Config_NetworkConfig_AddressMode_MIN meshtastic_Config_NetworkConfig_AddressMode_DHCP #define _meshtastic_Config_NetworkConfig_AddressMode_MAX meshtastic_Config_NetworkConfig_AddressMode_STATIC #define _meshtastic_Config_NetworkConfig_AddressMode_ARRAYSIZE ((meshtastic_Config_NetworkConfig_AddressMode)(meshtastic_Config_NetworkConfig_AddressMode_STATIC+1)) @@ -525,8 +549,8 @@ extern "C" { #define _meshtastic_Config_DisplayConfig_DisplayMode_ARRAYSIZE ((meshtastic_Config_DisplayConfig_DisplayMode)(meshtastic_Config_DisplayConfig_DisplayMode_COLOR+1)) #define _meshtastic_Config_LoRaConfig_RegionCode_MIN meshtastic_Config_LoRaConfig_RegionCode_UNSET -#define _meshtastic_Config_LoRaConfig_RegionCode_MAX meshtastic_Config_LoRaConfig_RegionCode_UA_868 -#define _meshtastic_Config_LoRaConfig_RegionCode_ARRAYSIZE ((meshtastic_Config_LoRaConfig_RegionCode)(meshtastic_Config_LoRaConfig_RegionCode_UA_868+1)) +#define _meshtastic_Config_LoRaConfig_RegionCode_MAX meshtastic_Config_LoRaConfig_RegionCode_SG_923 +#define _meshtastic_Config_LoRaConfig_RegionCode_ARRAYSIZE ((meshtastic_Config_LoRaConfig_RegionCode)(meshtastic_Config_LoRaConfig_RegionCode_SG_923+1)) #define _meshtastic_Config_LoRaConfig_ModemPreset_MIN meshtastic_Config_LoRaConfig_ModemPreset_LONG_FAST #define _meshtastic_Config_LoRaConfig_ModemPreset_MAX meshtastic_Config_LoRaConfig_ModemPreset_LONG_MODERATE @@ -540,6 +564,7 @@ extern "C" { #define meshtastic_Config_DeviceConfig_role_ENUMTYPE meshtastic_Config_DeviceConfig_Role #define meshtastic_Config_DeviceConfig_rebroadcast_mode_ENUMTYPE meshtastic_Config_DeviceConfig_RebroadcastMode +#define meshtastic_Config_PositionConfig_gps_mode_ENUMTYPE meshtastic_Config_PositionConfig_GpsMode #define meshtastic_Config_NetworkConfig_address_mode_ENUMTYPE meshtastic_Config_NetworkConfig_AddressMode @@ -559,21 +584,21 @@ extern "C" { /* Initializer values for message structs */ #define meshtastic_Config_init_default {0, {meshtastic_Config_DeviceConfig_init_default}} #define meshtastic_Config_DeviceConfig_init_default {_meshtastic_Config_DeviceConfig_Role_MIN, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN, 0, 0, 0, 0} -#define meshtastic_Config_PositionConfig_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define meshtastic_Config_PositionConfig_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _meshtastic_Config_PositionConfig_GpsMode_MIN} #define meshtastic_Config_PowerConfig_init_default {0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_Config_NetworkConfig_init_default {0, "", "", "", 0, _meshtastic_Config_NetworkConfig_AddressMode_MIN, false, meshtastic_Config_NetworkConfig_IpV4Config_init_default, ""} #define meshtastic_Config_NetworkConfig_IpV4Config_init_default {0, 0, 0, 0} #define meshtastic_Config_DisplayConfig_init_default {0, _meshtastic_Config_DisplayConfig_GpsCoordinateFormat_MIN, 0, 0, 0, _meshtastic_Config_DisplayConfig_DisplayUnits_MIN, _meshtastic_Config_DisplayConfig_OledType_MIN, _meshtastic_Config_DisplayConfig_DisplayMode_MIN, 0, 0} -#define meshtastic_Config_LoRaConfig_init_default {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}} +#define meshtastic_Config_LoRaConfig_init_default {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0} #define meshtastic_Config_BluetoothConfig_init_default {0, _meshtastic_Config_BluetoothConfig_PairingMode_MIN, 0} #define meshtastic_Config_init_zero {0, {meshtastic_Config_DeviceConfig_init_zero}} #define meshtastic_Config_DeviceConfig_init_zero {_meshtastic_Config_DeviceConfig_Role_MIN, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN, 0, 0, 0, 0} -#define meshtastic_Config_PositionConfig_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define meshtastic_Config_PositionConfig_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _meshtastic_Config_PositionConfig_GpsMode_MIN} #define meshtastic_Config_PowerConfig_init_zero {0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_Config_NetworkConfig_init_zero {0, "", "", "", 0, _meshtastic_Config_NetworkConfig_AddressMode_MIN, false, meshtastic_Config_NetworkConfig_IpV4Config_init_zero, ""} #define meshtastic_Config_NetworkConfig_IpV4Config_init_zero {0, 0, 0, 0} #define meshtastic_Config_DisplayConfig_init_zero {0, _meshtastic_Config_DisplayConfig_GpsCoordinateFormat_MIN, 0, 0, 0, _meshtastic_Config_DisplayConfig_DisplayUnits_MIN, _meshtastic_Config_DisplayConfig_OledType_MIN, _meshtastic_Config_DisplayConfig_DisplayMode_MIN, 0, 0} -#define meshtastic_Config_LoRaConfig_init_zero {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}} +#define meshtastic_Config_LoRaConfig_init_zero {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0} #define meshtastic_Config_BluetoothConfig_init_zero {0, _meshtastic_Config_BluetoothConfig_PairingMode_MIN, 0} /* Field tags (for use in manual encoding/decoding) */ @@ -599,6 +624,7 @@ extern "C" { #define meshtastic_Config_PositionConfig_broadcast_smart_minimum_distance_tag 10 #define meshtastic_Config_PositionConfig_broadcast_smart_minimum_interval_secs_tag 11 #define meshtastic_Config_PositionConfig_gps_en_gpio_tag 12 +#define meshtastic_Config_PositionConfig_gps_mode_tag 13 #define meshtastic_Config_PowerConfig_is_power_saving_tag 1 #define meshtastic_Config_PowerConfig_on_battery_shutdown_after_secs_tag 2 #define meshtastic_Config_PowerConfig_adc_multiplier_override_tag 3 @@ -644,6 +670,7 @@ extern "C" { #define meshtastic_Config_LoRaConfig_sx126x_rx_boosted_gain_tag 13 #define meshtastic_Config_LoRaConfig_override_frequency_tag 14 #define meshtastic_Config_LoRaConfig_ignore_incoming_tag 103 +#define meshtastic_Config_LoRaConfig_ignore_mqtt_tag 104 #define meshtastic_Config_BluetoothConfig_enabled_tag 1 #define meshtastic_Config_BluetoothConfig_mode_tag 2 #define meshtastic_Config_BluetoothConfig_fixed_pin_tag 3 @@ -700,7 +727,8 @@ X(a, STATIC, SINGULAR, UINT32, rx_gpio, 8) \ X(a, STATIC, SINGULAR, UINT32, tx_gpio, 9) \ X(a, STATIC, SINGULAR, UINT32, broadcast_smart_minimum_distance, 10) \ X(a, STATIC, SINGULAR, UINT32, broadcast_smart_minimum_interval_secs, 11) \ -X(a, STATIC, SINGULAR, UINT32, gps_en_gpio, 12) +X(a, STATIC, SINGULAR, UINT32, gps_en_gpio, 12) \ +X(a, STATIC, SINGULAR, UENUM, gps_mode, 13) #define meshtastic_Config_PositionConfig_CALLBACK NULL #define meshtastic_Config_PositionConfig_DEFAULT NULL @@ -766,7 +794,8 @@ X(a, STATIC, SINGULAR, UINT32, channel_num, 11) \ X(a, STATIC, SINGULAR, BOOL, override_duty_cycle, 12) \ X(a, STATIC, SINGULAR, BOOL, sx126x_rx_boosted_gain, 13) \ X(a, STATIC, SINGULAR, FLOAT, override_frequency, 14) \ -X(a, STATIC, REPEATED, UINT32, ignore_incoming, 103) +X(a, STATIC, REPEATED, UINT32, ignore_incoming, 103) \ +X(a, STATIC, SINGULAR, BOOL, ignore_mqtt, 104) #define meshtastic_Config_LoRaConfig_CALLBACK NULL #define meshtastic_Config_LoRaConfig_DEFAULT NULL @@ -802,10 +831,10 @@ extern const pb_msgdesc_t meshtastic_Config_BluetoothConfig_msg; #define meshtastic_Config_BluetoothConfig_size 10 #define meshtastic_Config_DeviceConfig_size 32 #define meshtastic_Config_DisplayConfig_size 28 -#define meshtastic_Config_LoRaConfig_size 77 +#define meshtastic_Config_LoRaConfig_size 80 #define meshtastic_Config_NetworkConfig_IpV4Config_size 20 #define meshtastic_Config_NetworkConfig_size 196 -#define meshtastic_Config_PositionConfig_size 60 +#define meshtastic_Config_PositionConfig_size 62 #define meshtastic_Config_PowerConfig_size 40 #define meshtastic_Config_size 199 diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.h b/src/mesh/generated/meshtastic/deviceonly.pb.h index b099a3eab6..735644c475 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.h +++ b/src/mesh/generated/meshtastic/deviceonly.pb.h @@ -312,11 +312,11 @@ extern const pb_msgdesc_t meshtastic_NodeRemoteHardwarePin_msg; #define meshtastic_NodeRemoteHardwarePin_fields &meshtastic_NodeRemoteHardwarePin_msg /* Maximum encoded size of messages (where known) */ -#define meshtastic_ChannelFile_size 638 -#define meshtastic_DeviceState_size 17056 +#define meshtastic_ChannelFile_size 702 +#define meshtastic_DeviceState_size 17062 #define meshtastic_NodeInfoLite_size 153 #define meshtastic_NodeRemoteHardwarePin_size 29 -#define meshtastic_OEMStore_size 3231 +#define meshtastic_OEMStore_size 3246 #define meshtastic_PositionLite_size 28 #ifdef __cplusplus diff --git a/src/mesh/generated/meshtastic/localonly.pb.h b/src/mesh/generated/meshtastic/localonly.pb.h index 7dc96e79a3..7d39da01f4 100644 --- a/src/mesh/generated/meshtastic/localonly.pb.h +++ b/src/mesh/generated/meshtastic/localonly.pb.h @@ -81,6 +81,9 @@ typedef struct _meshtastic_LocalModuleConfig { /* The part of the config that is specific to the Detection Sensor module */ bool has_detection_sensor; meshtastic_ModuleConfig_DetectionSensorConfig detection_sensor; + /* Paxcounter Config */ + bool has_paxcounter; + meshtastic_ModuleConfig_PaxcounterConfig paxcounter; } meshtastic_LocalModuleConfig; @@ -90,9 +93,9 @@ extern "C" { /* Initializer values for message structs */ #define meshtastic_LocalConfig_init_default {false, meshtastic_Config_DeviceConfig_init_default, false, meshtastic_Config_PositionConfig_init_default, false, meshtastic_Config_PowerConfig_init_default, false, meshtastic_Config_NetworkConfig_init_default, false, meshtastic_Config_DisplayConfig_init_default, false, meshtastic_Config_LoRaConfig_init_default, false, meshtastic_Config_BluetoothConfig_init_default, 0} -#define meshtastic_LocalModuleConfig_init_default {false, meshtastic_ModuleConfig_MQTTConfig_init_default, false, meshtastic_ModuleConfig_SerialConfig_init_default, false, meshtastic_ModuleConfig_ExternalNotificationConfig_init_default, false, meshtastic_ModuleConfig_StoreForwardConfig_init_default, false, meshtastic_ModuleConfig_RangeTestConfig_init_default, false, meshtastic_ModuleConfig_TelemetryConfig_init_default, false, meshtastic_ModuleConfig_CannedMessageConfig_init_default, 0, false, meshtastic_ModuleConfig_AudioConfig_init_default, false, meshtastic_ModuleConfig_RemoteHardwareConfig_init_default, false, meshtastic_ModuleConfig_NeighborInfoConfig_init_default, false, meshtastic_ModuleConfig_AmbientLightingConfig_init_default, false, meshtastic_ModuleConfig_DetectionSensorConfig_init_default} +#define meshtastic_LocalModuleConfig_init_default {false, meshtastic_ModuleConfig_MQTTConfig_init_default, false, meshtastic_ModuleConfig_SerialConfig_init_default, false, meshtastic_ModuleConfig_ExternalNotificationConfig_init_default, false, meshtastic_ModuleConfig_StoreForwardConfig_init_default, false, meshtastic_ModuleConfig_RangeTestConfig_init_default, false, meshtastic_ModuleConfig_TelemetryConfig_init_default, false, meshtastic_ModuleConfig_CannedMessageConfig_init_default, 0, false, meshtastic_ModuleConfig_AudioConfig_init_default, false, meshtastic_ModuleConfig_RemoteHardwareConfig_init_default, false, meshtastic_ModuleConfig_NeighborInfoConfig_init_default, false, meshtastic_ModuleConfig_AmbientLightingConfig_init_default, false, meshtastic_ModuleConfig_DetectionSensorConfig_init_default, false, meshtastic_ModuleConfig_PaxcounterConfig_init_default} #define meshtastic_LocalConfig_init_zero {false, meshtastic_Config_DeviceConfig_init_zero, false, meshtastic_Config_PositionConfig_init_zero, false, meshtastic_Config_PowerConfig_init_zero, false, meshtastic_Config_NetworkConfig_init_zero, false, meshtastic_Config_DisplayConfig_init_zero, false, meshtastic_Config_LoRaConfig_init_zero, false, meshtastic_Config_BluetoothConfig_init_zero, 0} -#define meshtastic_LocalModuleConfig_init_zero {false, meshtastic_ModuleConfig_MQTTConfig_init_zero, false, meshtastic_ModuleConfig_SerialConfig_init_zero, false, meshtastic_ModuleConfig_ExternalNotificationConfig_init_zero, false, meshtastic_ModuleConfig_StoreForwardConfig_init_zero, false, meshtastic_ModuleConfig_RangeTestConfig_init_zero, false, meshtastic_ModuleConfig_TelemetryConfig_init_zero, false, meshtastic_ModuleConfig_CannedMessageConfig_init_zero, 0, false, meshtastic_ModuleConfig_AudioConfig_init_zero, false, meshtastic_ModuleConfig_RemoteHardwareConfig_init_zero, false, meshtastic_ModuleConfig_NeighborInfoConfig_init_zero, false, meshtastic_ModuleConfig_AmbientLightingConfig_init_zero, false, meshtastic_ModuleConfig_DetectionSensorConfig_init_zero} +#define meshtastic_LocalModuleConfig_init_zero {false, meshtastic_ModuleConfig_MQTTConfig_init_zero, false, meshtastic_ModuleConfig_SerialConfig_init_zero, false, meshtastic_ModuleConfig_ExternalNotificationConfig_init_zero, false, meshtastic_ModuleConfig_StoreForwardConfig_init_zero, false, meshtastic_ModuleConfig_RangeTestConfig_init_zero, false, meshtastic_ModuleConfig_TelemetryConfig_init_zero, false, meshtastic_ModuleConfig_CannedMessageConfig_init_zero, 0, false, meshtastic_ModuleConfig_AudioConfig_init_zero, false, meshtastic_ModuleConfig_RemoteHardwareConfig_init_zero, false, meshtastic_ModuleConfig_NeighborInfoConfig_init_zero, false, meshtastic_ModuleConfig_AmbientLightingConfig_init_zero, false, meshtastic_ModuleConfig_DetectionSensorConfig_init_zero, false, meshtastic_ModuleConfig_PaxcounterConfig_init_zero} /* Field tags (for use in manual encoding/decoding) */ #define meshtastic_LocalConfig_device_tag 1 @@ -116,6 +119,7 @@ extern "C" { #define meshtastic_LocalModuleConfig_neighbor_info_tag 11 #define meshtastic_LocalModuleConfig_ambient_lighting_tag 12 #define meshtastic_LocalModuleConfig_detection_sensor_tag 13 +#define meshtastic_LocalModuleConfig_paxcounter_tag 14 /* Struct field encoding specification for nanopb */ #define meshtastic_LocalConfig_FIELDLIST(X, a) \ @@ -150,7 +154,8 @@ X(a, STATIC, OPTIONAL, MESSAGE, audio, 9) \ X(a, STATIC, OPTIONAL, MESSAGE, remote_hardware, 10) \ X(a, STATIC, OPTIONAL, MESSAGE, neighbor_info, 11) \ X(a, STATIC, OPTIONAL, MESSAGE, ambient_lighting, 12) \ -X(a, STATIC, OPTIONAL, MESSAGE, detection_sensor, 13) +X(a, STATIC, OPTIONAL, MESSAGE, detection_sensor, 13) \ +X(a, STATIC, OPTIONAL, MESSAGE, paxcounter, 14) #define meshtastic_LocalModuleConfig_CALLBACK NULL #define meshtastic_LocalModuleConfig_DEFAULT NULL #define meshtastic_LocalModuleConfig_mqtt_MSGTYPE meshtastic_ModuleConfig_MQTTConfig @@ -165,6 +170,7 @@ X(a, STATIC, OPTIONAL, MESSAGE, detection_sensor, 13) #define meshtastic_LocalModuleConfig_neighbor_info_MSGTYPE meshtastic_ModuleConfig_NeighborInfoConfig #define meshtastic_LocalModuleConfig_ambient_lighting_MSGTYPE meshtastic_ModuleConfig_AmbientLightingConfig #define meshtastic_LocalModuleConfig_detection_sensor_MSGTYPE meshtastic_ModuleConfig_DetectionSensorConfig +#define meshtastic_LocalModuleConfig_paxcounter_MSGTYPE meshtastic_ModuleConfig_PaxcounterConfig extern const pb_msgdesc_t meshtastic_LocalConfig_msg; extern const pb_msgdesc_t meshtastic_LocalModuleConfig_msg; @@ -174,8 +180,8 @@ extern const pb_msgdesc_t meshtastic_LocalModuleConfig_msg; #define meshtastic_LocalModuleConfig_fields &meshtastic_LocalModuleConfig_msg /* Maximum encoded size of messages (where known) */ -#define meshtastic_LocalConfig_size 464 -#define meshtastic_LocalModuleConfig_size 621 +#define meshtastic_LocalConfig_size 469 +#define meshtastic_LocalModuleConfig_size 631 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/meshtastic/mesh.pb.h b/src/mesh/generated/meshtastic/mesh.pb.h index ae80b3fe5b..e8a27d43f0 100644 --- a/src/mesh/generated/meshtastic/mesh.pb.h +++ b/src/mesh/generated/meshtastic/mesh.pb.h @@ -71,6 +71,10 @@ typedef enum _meshtastic_HardwareModel { meshtastic_HardwareModel_SENSELORA_RP2040 = 27, /* Makerfabs SenseLoRA Industrial Monitor (ESP32-S3 + RFM96) */ meshtastic_HardwareModel_SENSELORA_S3 = 28, + /* Canary Radio Company - CanaryOne: https://canaryradio.io/products/canaryone */ + meshtastic_HardwareModel_CANARYONE = 29, + /* Waveshare RP2040 LoRa - https://www.waveshare.com/rp2040-lora.htm */ + meshtastic_HardwareModel_RP2040_LORA = 30, /* --------------------------------------------------------------------------- Less common/prototype boards listed here (needs one more byte over the air) --------------------------------------------------------------------------- */ @@ -105,7 +109,8 @@ typedef enum _meshtastic_HardwareModel { meshtastic_HardwareModel_BETAFPV_900_NANO_TX = 46, /* Raspberry Pi Pico (W) with Waveshare SX1262 LoRa Node Module */ meshtastic_HardwareModel_RPI_PICO = 47, - /* Heltec Wireless Tracker with ESP32-S3 CPU, built-in GPS, and TFT */ + /* Heltec Wireless Tracker with ESP32-S3 CPU, built-in GPS, and TFT + Newer V1.1, version is written on the PCB near the display. */ meshtastic_HardwareModel_HELTEC_WIRELESS_TRACKER = 48, /* Heltec Wireless Paper with ESP32-S3 CPU and E-Ink display */ meshtastic_HardwareModel_HELTEC_WIRELESS_PAPER = 49, @@ -119,6 +124,21 @@ typedef enum _meshtastic_HardwareModel { meshtastic_HardwareModel_HELTEC_HT62 = 53, /* EBYTE SPI LoRa module and ESP32-S3 */ meshtastic_HardwareModel_EBYTE_ESP32_S3 = 54, + /* Waveshare ESP32-S3-PICO with PICO LoRa HAT and 2.9inch e-Ink */ + meshtastic_HardwareModel_ESP32_S3_PICO = 55, + /* CircuitMess Chatter 2 LLCC68 Lora Module and ESP32 Wroom + Lora module can be swapped out for a Heltec RA-62 which is "almost" pin compatible + with one cut and one jumper Meshtastic works */ + meshtastic_HardwareModel_CHATTER_2 = 56, + /* Heltec Wireless Paper, With ESP32-S3 CPU and E-Ink display + Older "V1.0" Variant, has no "version sticker" + E-Ink model is DEPG0213BNS800 + Tab on the screen protector is RED + Flex connector marking is FPC-7528B */ + meshtastic_HardwareModel_HELTEC_WIRELESS_PAPER_V1_0 = 57, + /* Heltec Wireless Tracker with ESP32-S3 CPU, built-in GPS, and TFT + Older "V1.0" Variant */ + meshtastic_HardwareModel_HELTEC_WIRELESS_TRACKER_V1_0 = 58, /* ------------------------------------------------------------------------------------------------------------------------------------------ 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. ------------------------------------------------------------------------------------------------------------------------------------------ */ @@ -360,6 +380,8 @@ typedef struct _meshtastic_Position { /* A sequence number, incremented with each Position message to help detect lost updates if needed */ uint32_t seq_number; + /* Indicates the bits of precision set by the sending node */ + uint32_t precision_bits; } meshtastic_Position; /* Broadcast when a newly powered mesh node wants to find a node num it can use @@ -571,6 +593,8 @@ typedef struct _meshtastic_MeshPacket { int32_t rx_rssi; /* Describe if this message is delayed */ meshtastic_MeshPacket_Delayed delayed; + /* Describes whether this packet passed via MQTT somewhere along the path it currently took. */ + bool via_mqtt; } meshtastic_MeshPacket; /* The bluetooth to device link: @@ -860,14 +884,14 @@ extern "C" { /* Initializer values for message structs */ -#define meshtastic_Position_init_default {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN, _meshtastic_Position_AltSource_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define meshtastic_Position_init_default {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN, _meshtastic_Position_AltSource_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_User_init_default {"", "", "", {0}, _meshtastic_HardwareModel_MIN, 0, _meshtastic_Config_DeviceConfig_Role_MIN} #define meshtastic_RouteDiscovery_init_default {0, {0, 0, 0, 0, 0, 0, 0, 0}} #define meshtastic_Routing_init_default {0, {meshtastic_RouteDiscovery_init_default}} #define meshtastic_Data_init_default {_meshtastic_PortNum_MIN, {0, {0}}, 0, 0, 0, 0, 0, 0} #define meshtastic_Waypoint_init_default {0, 0, 0, 0, 0, "", "", 0} #define meshtastic_MqttClientProxyMessage_init_default {"", 0, {{0, {0}}}, 0} -#define meshtastic_MeshPacket_init_default {0, 0, 0, 0, {meshtastic_Data_init_default}, 0, 0, 0, 0, 0, _meshtastic_MeshPacket_Priority_MIN, 0, _meshtastic_MeshPacket_Delayed_MIN} +#define meshtastic_MeshPacket_init_default {0, 0, 0, 0, {meshtastic_Data_init_default}, 0, 0, 0, 0, 0, _meshtastic_MeshPacket_Priority_MIN, 0, _meshtastic_MeshPacket_Delayed_MIN, 0} #define meshtastic_NodeInfo_init_default {0, false, meshtastic_User_init_default, false, meshtastic_Position_init_default, 0, 0, false, meshtastic_DeviceMetrics_init_default, 0} #define meshtastic_MyNodeInfo_init_default {0, 0, 0} #define meshtastic_LogRecord_init_default {"", 0, "", _meshtastic_LogRecord_Level_MIN} @@ -878,14 +902,14 @@ extern "C" { #define meshtastic_NeighborInfo_init_default {0, 0, 0, 0, {meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default, meshtastic_Neighbor_init_default}} #define meshtastic_Neighbor_init_default {0, 0, 0, 0} #define meshtastic_DeviceMetadata_init_default {"", 0, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_Role_MIN, 0, _meshtastic_HardwareModel_MIN, 0} -#define meshtastic_Position_init_zero {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN, _meshtastic_Position_AltSource_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define meshtastic_Position_init_zero {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN, _meshtastic_Position_AltSource_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_User_init_zero {"", "", "", {0}, _meshtastic_HardwareModel_MIN, 0, _meshtastic_Config_DeviceConfig_Role_MIN} #define meshtastic_RouteDiscovery_init_zero {0, {0, 0, 0, 0, 0, 0, 0, 0}} #define meshtastic_Routing_init_zero {0, {meshtastic_RouteDiscovery_init_zero}} #define meshtastic_Data_init_zero {_meshtastic_PortNum_MIN, {0, {0}}, 0, 0, 0, 0, 0, 0} #define meshtastic_Waypoint_init_zero {0, 0, 0, 0, 0, "", "", 0} #define meshtastic_MqttClientProxyMessage_init_zero {"", 0, {{0, {0}}}, 0} -#define meshtastic_MeshPacket_init_zero {0, 0, 0, 0, {meshtastic_Data_init_zero}, 0, 0, 0, 0, 0, _meshtastic_MeshPacket_Priority_MIN, 0, _meshtastic_MeshPacket_Delayed_MIN} +#define meshtastic_MeshPacket_init_zero {0, 0, 0, 0, {meshtastic_Data_init_zero}, 0, 0, 0, 0, 0, _meshtastic_MeshPacket_Priority_MIN, 0, _meshtastic_MeshPacket_Delayed_MIN, 0} #define meshtastic_NodeInfo_init_zero {0, false, meshtastic_User_init_zero, false, meshtastic_Position_init_zero, 0, 0, false, meshtastic_DeviceMetrics_init_zero, 0} #define meshtastic_MyNodeInfo_init_zero {0, 0, 0} #define meshtastic_LogRecord_init_zero {"", 0, "", _meshtastic_LogRecord_Level_MIN} @@ -920,6 +944,7 @@ extern "C" { #define meshtastic_Position_sensor_id_tag 20 #define meshtastic_Position_next_update_tag 21 #define meshtastic_Position_seq_number_tag 22 +#define meshtastic_Position_precision_bits_tag 23 #define meshtastic_User_id_tag 1 #define meshtastic_User_long_name_tag 2 #define meshtastic_User_short_name_tag 3 @@ -964,6 +989,7 @@ extern "C" { #define meshtastic_MeshPacket_priority_tag 11 #define meshtastic_MeshPacket_rx_rssi_tag 12 #define meshtastic_MeshPacket_delayed_tag 13 +#define meshtastic_MeshPacket_via_mqtt_tag 14 #define meshtastic_NodeInfo_num_tag 1 #define meshtastic_NodeInfo_user_tag 2 #define meshtastic_NodeInfo_position_tag 3 @@ -1045,7 +1071,8 @@ X(a, STATIC, SINGULAR, UINT32, fix_type, 18) \ X(a, STATIC, SINGULAR, UINT32, sats_in_view, 19) \ X(a, STATIC, SINGULAR, UINT32, sensor_id, 20) \ X(a, STATIC, SINGULAR, UINT32, next_update, 21) \ -X(a, STATIC, SINGULAR, UINT32, seq_number, 22) +X(a, STATIC, SINGULAR, UINT32, seq_number, 22) \ +X(a, STATIC, SINGULAR, UINT32, precision_bits, 23) #define meshtastic_Position_CALLBACK NULL #define meshtastic_Position_DEFAULT NULL @@ -1119,7 +1146,8 @@ X(a, STATIC, SINGULAR, UINT32, hop_limit, 9) \ X(a, STATIC, SINGULAR, BOOL, want_ack, 10) \ X(a, STATIC, SINGULAR, UENUM, priority, 11) \ X(a, STATIC, SINGULAR, INT32, rx_rssi, 12) \ -X(a, STATIC, SINGULAR, UENUM, delayed, 13) +X(a, STATIC, SINGULAR, UENUM, delayed, 13) \ +X(a, STATIC, SINGULAR, BOOL, via_mqtt, 14) #define meshtastic_MeshPacket_CALLBACK NULL #define meshtastic_MeshPacket_DEFAULT NULL #define meshtastic_MeshPacket_payload_variant_decoded_MSGTYPE meshtastic_Data @@ -1284,13 +1312,13 @@ extern const pb_msgdesc_t meshtastic_DeviceMetadata_msg; #define meshtastic_DeviceMetadata_size 46 #define meshtastic_FromRadio_size 510 #define meshtastic_LogRecord_size 81 -#define meshtastic_MeshPacket_size 321 +#define meshtastic_MeshPacket_size 323 #define meshtastic_MqttClientProxyMessage_size 501 #define meshtastic_MyNodeInfo_size 18 #define meshtastic_NeighborInfo_size 258 #define meshtastic_Neighbor_size 22 -#define meshtastic_NodeInfo_size 263 -#define meshtastic_Position_size 137 +#define meshtastic_NodeInfo_size 270 +#define meshtastic_Position_size 144 #define meshtastic_QueueStatus_size 23 #define meshtastic_RouteDiscovery_size 40 #define meshtastic_Routing_size 42 diff --git a/src/mesh/generated/meshtastic/module_config.pb.c b/src/mesh/generated/meshtastic/module_config.pb.c index 7318d34f70..38965f3e25 100644 --- a/src/mesh/generated/meshtastic/module_config.pb.c +++ b/src/mesh/generated/meshtastic/module_config.pb.c @@ -24,6 +24,9 @@ PB_BIND(meshtastic_ModuleConfig_DetectionSensorConfig, meshtastic_ModuleConfig_D PB_BIND(meshtastic_ModuleConfig_AudioConfig, meshtastic_ModuleConfig_AudioConfig, AUTO) +PB_BIND(meshtastic_ModuleConfig_PaxcounterConfig, meshtastic_ModuleConfig_PaxcounterConfig, AUTO) + + PB_BIND(meshtastic_ModuleConfig_SerialConfig, meshtastic_ModuleConfig_SerialConfig, AUTO) diff --git a/src/mesh/generated/meshtastic/module_config.pb.h b/src/mesh/generated/meshtastic/module_config.pb.h index b9f43e352c..edfd56e4ca 100644 --- a/src/mesh/generated/meshtastic/module_config.pb.h +++ b/src/mesh/generated/meshtastic/module_config.pb.h @@ -170,6 +170,13 @@ typedef struct _meshtastic_ModuleConfig_AudioConfig { uint8_t i2s_sck; } meshtastic_ModuleConfig_AudioConfig; +/* Config for the Paxcounter Module */ +typedef struct _meshtastic_ModuleConfig_PaxcounterConfig { + /* Enable the Paxcounter Module */ + bool enabled; + uint32_t paxcounter_update_interval; +} meshtastic_ModuleConfig_PaxcounterConfig; + /* Serial Config */ typedef struct _meshtastic_ModuleConfig_SerialConfig { /* Preferences for the SerialModule */ @@ -384,6 +391,8 @@ typedef struct _meshtastic_ModuleConfig { meshtastic_ModuleConfig_AmbientLightingConfig ambient_lighting; /* TODO: REPLACE */ meshtastic_ModuleConfig_DetectionSensorConfig detection_sensor; + /* TODO: REPLACE */ + meshtastic_ModuleConfig_PaxcounterConfig paxcounter; } payload_variant; } meshtastic_ModuleConfig; @@ -420,6 +429,7 @@ extern "C" { #define meshtastic_ModuleConfig_AudioConfig_bitrate_ENUMTYPE meshtastic_ModuleConfig_AudioConfig_Audio_Baud + #define meshtastic_ModuleConfig_SerialConfig_baud_ENUMTYPE meshtastic_ModuleConfig_SerialConfig_Serial_Baud #define meshtastic_ModuleConfig_SerialConfig_mode_ENUMTYPE meshtastic_ModuleConfig_SerialConfig_Serial_Mode @@ -442,6 +452,7 @@ extern "C" { #define meshtastic_ModuleConfig_NeighborInfoConfig_init_default {0, 0} #define meshtastic_ModuleConfig_DetectionSensorConfig_init_default {0, 0, 0, 0, "", 0, 0, 0} #define meshtastic_ModuleConfig_AudioConfig_init_default {0, 0, _meshtastic_ModuleConfig_AudioConfig_Audio_Baud_MIN, 0, 0, 0, 0} +#define meshtastic_ModuleConfig_PaxcounterConfig_init_default {0, 0} #define meshtastic_ModuleConfig_SerialConfig_init_default {0, 0, 0, 0, _meshtastic_ModuleConfig_SerialConfig_Serial_Baud_MIN, 0, _meshtastic_ModuleConfig_SerialConfig_Serial_Mode_MIN, 0} #define meshtastic_ModuleConfig_ExternalNotificationConfig_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_ModuleConfig_StoreForwardConfig_init_default {0, 0, 0, 0, 0} @@ -456,6 +467,7 @@ extern "C" { #define meshtastic_ModuleConfig_NeighborInfoConfig_init_zero {0, 0} #define meshtastic_ModuleConfig_DetectionSensorConfig_init_zero {0, 0, 0, 0, "", 0, 0, 0} #define meshtastic_ModuleConfig_AudioConfig_init_zero {0, 0, _meshtastic_ModuleConfig_AudioConfig_Audio_Baud_MIN, 0, 0, 0, 0} +#define meshtastic_ModuleConfig_PaxcounterConfig_init_zero {0, 0} #define meshtastic_ModuleConfig_SerialConfig_init_zero {0, 0, 0, 0, _meshtastic_ModuleConfig_SerialConfig_Serial_Baud_MIN, 0, _meshtastic_ModuleConfig_SerialConfig_Serial_Mode_MIN, 0} #define meshtastic_ModuleConfig_ExternalNotificationConfig_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_ModuleConfig_StoreForwardConfig_init_zero {0, 0, 0, 0, 0} @@ -492,6 +504,8 @@ extern "C" { #define meshtastic_ModuleConfig_AudioConfig_i2s_sd_tag 5 #define meshtastic_ModuleConfig_AudioConfig_i2s_din_tag 6 #define meshtastic_ModuleConfig_AudioConfig_i2s_sck_tag 7 +#define meshtastic_ModuleConfig_PaxcounterConfig_enabled_tag 1 +#define meshtastic_ModuleConfig_PaxcounterConfig_paxcounter_update_interval_tag 2 #define meshtastic_ModuleConfig_SerialConfig_enabled_tag 1 #define meshtastic_ModuleConfig_SerialConfig_echo_tag 2 #define meshtastic_ModuleConfig_SerialConfig_rxd_tag 3 @@ -567,6 +581,7 @@ extern "C" { #define meshtastic_ModuleConfig_neighbor_info_tag 10 #define meshtastic_ModuleConfig_ambient_lighting_tag 11 #define meshtastic_ModuleConfig_detection_sensor_tag 12 +#define meshtastic_ModuleConfig_paxcounter_tag 13 /* Struct field encoding specification for nanopb */ #define meshtastic_ModuleConfig_FIELDLIST(X, a) \ @@ -581,7 +596,8 @@ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,audio,payload_variant.audio) X(a, STATIC, ONEOF, MESSAGE, (payload_variant,remote_hardware,payload_variant.remote_hardware), 9) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,neighbor_info,payload_variant.neighbor_info), 10) \ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,ambient_lighting,payload_variant.ambient_lighting), 11) \ -X(a, STATIC, ONEOF, MESSAGE, (payload_variant,detection_sensor,payload_variant.detection_sensor), 12) +X(a, STATIC, ONEOF, MESSAGE, (payload_variant,detection_sensor,payload_variant.detection_sensor), 12) \ +X(a, STATIC, ONEOF, MESSAGE, (payload_variant,paxcounter,payload_variant.paxcounter), 13) #define meshtastic_ModuleConfig_CALLBACK NULL #define meshtastic_ModuleConfig_DEFAULT NULL #define meshtastic_ModuleConfig_payload_variant_mqtt_MSGTYPE meshtastic_ModuleConfig_MQTTConfig @@ -596,6 +612,7 @@ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,detection_sensor,payload_var #define meshtastic_ModuleConfig_payload_variant_neighbor_info_MSGTYPE meshtastic_ModuleConfig_NeighborInfoConfig #define meshtastic_ModuleConfig_payload_variant_ambient_lighting_MSGTYPE meshtastic_ModuleConfig_AmbientLightingConfig #define meshtastic_ModuleConfig_payload_variant_detection_sensor_MSGTYPE meshtastic_ModuleConfig_DetectionSensorConfig +#define meshtastic_ModuleConfig_payload_variant_paxcounter_MSGTYPE meshtastic_ModuleConfig_PaxcounterConfig #define meshtastic_ModuleConfig_MQTTConfig_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, BOOL, enabled, 1) \ @@ -647,6 +664,12 @@ X(a, STATIC, SINGULAR, UINT32, i2s_sck, 7) #define meshtastic_ModuleConfig_AudioConfig_CALLBACK NULL #define meshtastic_ModuleConfig_AudioConfig_DEFAULT NULL +#define meshtastic_ModuleConfig_PaxcounterConfig_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, BOOL, enabled, 1) \ +X(a, STATIC, SINGULAR, UINT32, paxcounter_update_interval, 2) +#define meshtastic_ModuleConfig_PaxcounterConfig_CALLBACK NULL +#define meshtastic_ModuleConfig_PaxcounterConfig_DEFAULT NULL + #define meshtastic_ModuleConfig_SerialConfig_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, BOOL, enabled, 1) \ X(a, STATIC, SINGULAR, BOOL, echo, 2) \ @@ -745,6 +768,7 @@ extern const pb_msgdesc_t meshtastic_ModuleConfig_RemoteHardwareConfig_msg; extern const pb_msgdesc_t meshtastic_ModuleConfig_NeighborInfoConfig_msg; extern const pb_msgdesc_t meshtastic_ModuleConfig_DetectionSensorConfig_msg; extern const pb_msgdesc_t meshtastic_ModuleConfig_AudioConfig_msg; +extern const pb_msgdesc_t meshtastic_ModuleConfig_PaxcounterConfig_msg; extern const pb_msgdesc_t meshtastic_ModuleConfig_SerialConfig_msg; extern const pb_msgdesc_t meshtastic_ModuleConfig_ExternalNotificationConfig_msg; extern const pb_msgdesc_t meshtastic_ModuleConfig_StoreForwardConfig_msg; @@ -761,6 +785,7 @@ extern const pb_msgdesc_t meshtastic_RemoteHardwarePin_msg; #define meshtastic_ModuleConfig_NeighborInfoConfig_fields &meshtastic_ModuleConfig_NeighborInfoConfig_msg #define meshtastic_ModuleConfig_DetectionSensorConfig_fields &meshtastic_ModuleConfig_DetectionSensorConfig_msg #define meshtastic_ModuleConfig_AudioConfig_fields &meshtastic_ModuleConfig_AudioConfig_msg +#define meshtastic_ModuleConfig_PaxcounterConfig_fields &meshtastic_ModuleConfig_PaxcounterConfig_msg #define meshtastic_ModuleConfig_SerialConfig_fields &meshtastic_ModuleConfig_SerialConfig_msg #define meshtastic_ModuleConfig_ExternalNotificationConfig_fields &meshtastic_ModuleConfig_ExternalNotificationConfig_msg #define meshtastic_ModuleConfig_StoreForwardConfig_fields &meshtastic_ModuleConfig_StoreForwardConfig_msg @@ -778,6 +803,7 @@ extern const pb_msgdesc_t meshtastic_RemoteHardwarePin_msg; #define meshtastic_ModuleConfig_ExternalNotificationConfig_size 42 #define meshtastic_ModuleConfig_MQTTConfig_size 222 #define meshtastic_ModuleConfig_NeighborInfoConfig_size 8 +#define meshtastic_ModuleConfig_PaxcounterConfig_size 8 #define meshtastic_ModuleConfig_RangeTestConfig_size 10 #define meshtastic_ModuleConfig_RemoteHardwareConfig_size 96 #define meshtastic_ModuleConfig_SerialConfig_size 28 diff --git a/src/mesh/generated/meshtastic/paxcount.pb.c b/src/mesh/generated/meshtastic/paxcount.pb.c new file mode 100644 index 0000000000..57d5f5be9f --- /dev/null +++ b/src/mesh/generated/meshtastic/paxcount.pb.c @@ -0,0 +1,12 @@ +/* Automatically generated nanopb constant definitions */ +/* Generated by nanopb-0.4.7 */ + +#include "meshtastic/paxcount.pb.h" +#if PB_PROTO_HEADER_VERSION != 40 +#error Regenerate this file with the current version of nanopb generator. +#endif + +PB_BIND(meshtastic_Paxcount, meshtastic_Paxcount, AUTO) + + + diff --git a/src/mesh/generated/meshtastic/paxcount.pb.h b/src/mesh/generated/meshtastic/paxcount.pb.h new file mode 100644 index 0000000000..4b643293cd --- /dev/null +++ b/src/mesh/generated/meshtastic/paxcount.pb.h @@ -0,0 +1,57 @@ +/* Automatically generated nanopb header */ +/* Generated by nanopb-0.4.7 */ + +#ifndef PB_MESHTASTIC_MESHTASTIC_PAXCOUNT_PB_H_INCLUDED +#define PB_MESHTASTIC_MESHTASTIC_PAXCOUNT_PB_H_INCLUDED +#include + +#if PB_PROTO_HEADER_VERSION != 40 +#error Regenerate this file with the current version of nanopb generator. +#endif + +/* Struct definitions */ +/* TODO: REPLACE */ +typedef struct _meshtastic_Paxcount { + /* seen Wifi devices */ + uint32_t wifi; + /* Seen BLE devices */ + uint32_t ble; + /* Uptime in seconds */ + uint32_t uptime; +} meshtastic_Paxcount; + + +#ifdef __cplusplus +extern "C" { +#endif + +/* Initializer values for message structs */ +#define meshtastic_Paxcount_init_default {0, 0, 0} +#define meshtastic_Paxcount_init_zero {0, 0, 0} + +/* Field tags (for use in manual encoding/decoding) */ +#define meshtastic_Paxcount_wifi_tag 1 +#define meshtastic_Paxcount_ble_tag 2 +#define meshtastic_Paxcount_uptime_tag 3 + +/* Struct field encoding specification for nanopb */ +#define meshtastic_Paxcount_FIELDLIST(X, a) \ +X(a, STATIC, SINGULAR, UINT32, wifi, 1) \ +X(a, STATIC, SINGULAR, UINT32, ble, 2) \ +X(a, STATIC, SINGULAR, UINT32, uptime, 3) +#define meshtastic_Paxcount_CALLBACK NULL +#define meshtastic_Paxcount_DEFAULT NULL + +extern const pb_msgdesc_t meshtastic_Paxcount_msg; + +/* Defines for backwards compatibility with code written before nanopb-0.4.0 */ +#define meshtastic_Paxcount_fields &meshtastic_Paxcount_msg + +/* Maximum encoded size of messages (where known) */ +#define meshtastic_Paxcount_size 18 + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/src/mesh/generated/meshtastic/portnums.pb.h b/src/mesh/generated/meshtastic/portnums.pb.h index c94349d47c..88342e5dcc 100644 --- a/src/mesh/generated/meshtastic/portnums.pb.h +++ b/src/mesh/generated/meshtastic/portnums.pb.h @@ -79,6 +79,9 @@ typedef enum _meshtastic_PortNum { /* Used for the python IP tunnel feature ENCODING: IP Packet. Handled by the python API, firmware ignores this one and pases on. */ meshtastic_PortNum_IP_TUNNEL_APP = 33, + /* Paxcounter lib included in the firmware + ENCODING: protobuf */ + meshtastic_PortNum_PAXCOUNTER_APP = 34, /* Provides a hardware serial interface to send and receive from the Meshtastic network. Connect to the RX/TX pins of a device with 38400 8N1. Packets received from the Meshtastic network is forwarded to the RX pin while sending a packet to TX will go out to the Mesh network. @@ -116,6 +119,9 @@ typedef enum _meshtastic_PortNum { /* Aggregates edge info for the network by sending out a list of each node's neighbors ENCODING: Protobuf */ meshtastic_PortNum_NEIGHBORINFO_APP = 71, + /* ATAK Plugin + Portnum for payloads from the official Meshtastic ATAK plugin */ + meshtastic_PortNum_ATAK_PLUGIN = 72, /* 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/storeforward.pb.h b/src/mesh/generated/meshtastic/storeforward.pb.h index e6cb51f618..55ab0b5108 100644 --- a/src/mesh/generated/meshtastic/storeforward.pb.h +++ b/src/mesh/generated/meshtastic/storeforward.pb.h @@ -30,6 +30,10 @@ typedef enum _meshtastic_StoreAndForward_RequestResponse { meshtastic_StoreAndForward_RequestResponse_ROUTER_HISTORY = 6, /* Router is responding to a request for stats. */ meshtastic_StoreAndForward_RequestResponse_ROUTER_STATS = 7, + /* Router sends a text message from its history that was a direct message. */ + meshtastic_StoreAndForward_RequestResponse_ROUTER_TEXT_DIRECT = 8, + /* Router sends a text message from its history that was a broadcast. */ + meshtastic_StoreAndForward_RequestResponse_ROUTER_TEXT_BROADCAST = 9, /* Client is an in error state. */ meshtastic_StoreAndForward_RequestResponse_CLIENT_ERROR = 64, /* Client has requested a replay from the router. */ @@ -62,9 +66,9 @@ typedef struct _meshtastic_StoreAndForward_Statistics { uint32_t requests_history; /* Is the heartbeat enabled on the server? */ bool heartbeat; - /* Is the heartbeat enabled on the server? */ + /* Maximum number of messages the server will return. */ uint32_t return_max; - /* Is the heartbeat enabled on the server? */ + /* Maximum history window in minutes the server will return messages from. */ uint32_t return_window; } meshtastic_StoreAndForward_Statistics; @@ -74,18 +78,20 @@ typedef struct _meshtastic_StoreAndForward_History { uint32_t history_messages; /* The window of messages that was used to filter the history client requested */ uint32_t window; - /* The window of messages that was used to filter the history client requested */ + /* Index in the packet history of the last message sent in a previous request to the server. + Will be sent to the client before sending the history and can be set in a subsequent request to avoid getting packets the server already sent to the client. */ uint32_t last_request; } meshtastic_StoreAndForward_History; /* TODO: REPLACE */ typedef struct _meshtastic_StoreAndForward_Heartbeat { - /* Number of that will be sent to the client */ + /* Period in seconds that the heartbeat is sent out that will be sent to the client */ uint32_t period; /* If set, this is not the primary Store & Forward router on the mesh */ uint32_t secondary; } meshtastic_StoreAndForward_Heartbeat; +typedef PB_BYTES_ARRAY_T(237) meshtastic_StoreAndForward_text_t; /* TODO: REPLACE */ typedef struct _meshtastic_StoreAndForward { /* TODO: REPLACE */ @@ -98,8 +104,8 @@ typedef struct _meshtastic_StoreAndForward { meshtastic_StoreAndForward_History history; /* TODO: REPLACE */ meshtastic_StoreAndForward_Heartbeat heartbeat; - /* Empty Payload */ - bool empty; + /* Text from history message. */ + meshtastic_StoreAndForward_text_t text; } variant; } meshtastic_StoreAndForward; @@ -148,7 +154,7 @@ extern "C" { #define meshtastic_StoreAndForward_stats_tag 2 #define meshtastic_StoreAndForward_history_tag 3 #define meshtastic_StoreAndForward_heartbeat_tag 4 -#define meshtastic_StoreAndForward_empty_tag 5 +#define meshtastic_StoreAndForward_text_tag 5 /* Struct field encoding specification for nanopb */ #define meshtastic_StoreAndForward_FIELDLIST(X, a) \ @@ -156,7 +162,7 @@ X(a, STATIC, SINGULAR, UENUM, rr, 1) \ X(a, STATIC, ONEOF, MESSAGE, (variant,stats,variant.stats), 2) \ X(a, STATIC, ONEOF, MESSAGE, (variant,history,variant.history), 3) \ X(a, STATIC, ONEOF, MESSAGE, (variant,heartbeat,variant.heartbeat), 4) \ -X(a, STATIC, ONEOF, BOOL, (variant,empty,variant.empty), 5) +X(a, STATIC, ONEOF, BYTES, (variant,text,variant.text), 5) #define meshtastic_StoreAndForward_CALLBACK NULL #define meshtastic_StoreAndForward_DEFAULT NULL #define meshtastic_StoreAndForward_variant_stats_MSGTYPE meshtastic_StoreAndForward_Statistics @@ -204,7 +210,7 @@ extern const pb_msgdesc_t meshtastic_StoreAndForward_Heartbeat_msg; #define meshtastic_StoreAndForward_Heartbeat_size 12 #define meshtastic_StoreAndForward_History_size 18 #define meshtastic_StoreAndForward_Statistics_size 50 -#define meshtastic_StoreAndForward_size 54 +#define meshtastic_StoreAndForward_size 242 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/http/ContentHandler.cpp b/src/mesh/http/ContentHandler.cpp index 4ca37a256c..7640e879c9 100644 --- a/src/mesh/http/ContentHandler.cpp +++ b/src/mesh/http/ContentHandler.cpp @@ -398,7 +398,7 @@ void handleStatic(HTTPRequest *req, HTTPResponse *res) if (!file.available()) { LOG_WARN("File not available - %s\n", filenameGzip.c_str()); res->println("Web server is running.

The content you are looking for can't be found. Please see: FAQ.

FAQ.

admin"); return; @@ -854,4 +854,4 @@ void handleScanNetworks(HTTPRequest *req, HTTPResponse *res) JSONValue *value = new JSONValue(jsonObjOuter); res->print(value->Stringify().c_str()); delete value; -} \ No newline at end of file +} diff --git a/src/mesh/wifi/WiFiAPClient.cpp b/src/mesh/wifi/WiFiAPClient.cpp index 1e521e0331..b0b033ba0b 100644 --- a/src/mesh/wifi/WiFiAPClient.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -38,7 +38,8 @@ bool APStartupComplete = 0; unsigned long lastrun_ntp = 0; -bool needReconnect = true; // If we create our reconnector, run it once at the beginning +bool needReconnect = true; // If we create our reconnector, run it once at the beginning +bool isReconnecting = false; // If we are currently reconnecting WiFiUDP syslogClient; Syslog syslog(syslogClient); @@ -115,6 +116,7 @@ static int32_t reconnectWiFi() wifiPsw = NULL; needReconnect = false; + isReconnecting = true; // Make sure we clear old connection credentials #ifdef ARCH_ESP32 @@ -129,6 +131,7 @@ static int32_t reconnectWiFi() if (!WiFi.isConnected()) { WiFi.begin(wifiName, wifiPsw); } + isReconnecting = false; } #ifndef DISABLE_NTP @@ -277,10 +280,12 @@ static void WiFiEvent(WiFiEvent_t event) break; case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: LOG_INFO("Disconnected from WiFi access point\n"); - WiFi.disconnect(false, true); - syslog.disable(); - needReconnect = true; - wifiReconnect->setIntervalFromNow(1000); + if (!isReconnecting) { + WiFi.disconnect(false, true); + syslog.disable(); + needReconnect = true; + wifiReconnect->setIntervalFromNow(1000); + } break; case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE: LOG_INFO("Authentication mode of access point has changed\n"); @@ -294,10 +299,12 @@ static void WiFiEvent(WiFiEvent_t event) break; case ARDUINO_EVENT_WIFI_STA_LOST_IP: LOG_INFO("Lost IP address and IP address is reset to 0\n"); - WiFi.disconnect(false, true); - syslog.disable(); - needReconnect = true; - wifiReconnect->setIntervalFromNow(1000); + if (!isReconnecting) { + WiFi.disconnect(false, true); + syslog.disable(); + needReconnect = true; + wifiReconnect->setIntervalFromNow(1000); + } break; case ARDUINO_EVENT_WPS_ER_SUCCESS: LOG_INFO("WiFi Protected Setup (WPS): succeeded in enrollee mode\n"); @@ -398,4 +405,4 @@ static void WiFiEvent(WiFiEvent_t event) uint8_t getWifiDisconnectReason() { return wifiDisconnectReason; -} +} \ No newline at end of file diff --git a/src/meshUtils.cpp b/src/meshUtils.cpp index cab05e54b0..59d4e67142 100644 --- a/src/meshUtils.cpp +++ b/src/meshUtils.cpp @@ -39,10 +39,11 @@ */ char *strnstr(const char *s, const char *find, size_t slen) { - char c, sc; - size_t len; - + char c; if ((c = *find++) != '\0') { + char sc; + size_t len; + len = strlen(find); do { do { diff --git a/src/meshUtils.h b/src/meshUtils.h index a6436a8d59..e32ef230a1 100644 --- a/src/meshUtils.h +++ b/src/meshUtils.h @@ -8,5 +8,6 @@ template constexpr const T &clamp(const T &v, const T &lo, const T &hi #if (defined(ARCH_PORTDUINO) && !defined(STRNSTR)) #define STRNSTR +#include char *strnstr(const char *s, const char *find, size_t slen); #endif \ No newline at end of file diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index dce33ad48d..94df601d86 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -3,6 +3,7 @@ #include "MeshService.h" #include "NodeDB.h" #include "PowerFSM.h" +#include #ifdef ARCH_ESP32 #include "BleOta.h" #endif @@ -185,7 +186,22 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta case meshtastic_AdminMessage_remove_by_nodenum_tag: { LOG_INFO("Client is receiving a remove_nodenum command.\n"); nodeDB.removeNodeByNum(r->remove_by_nodenum); - reboot(DEFAULT_REBOOT_SECONDS); + break; + } + case meshtastic_AdminMessage_enter_dfu_mode_request_tag: { + LOG_INFO("Client is requesting to enter DFU mode.\n"); +#if defined(ARCH_NRF52) || defined(ARCH_RP2040) + enterDfuMode(); +#endif + break; + } + case meshtastic_AdminMessage_delete_file_request_tag: { + LOG_DEBUG("Client is requesting to delete file: %s\n", r->delete_file_request); + if (FSCom.remove(r->delete_file_request)) { + LOG_DEBUG("Successfully deleted file\n"); + } else { + LOG_DEBUG("Failed to delete file\n"); + } break; } #ifdef ARCH_PORTDUINO @@ -274,6 +290,7 @@ void AdminModule::handleSetOwner(const meshtastic_User &o) void AdminModule::handleSetConfig(const meshtastic_Config &c) { + auto changes = SEGMENT_CONFIG; auto existingRole = config.device.role; bool isRegionUnset = (config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_UNSET); @@ -314,6 +331,11 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) config.lora = c.payload_variant.lora; if (isRegionUnset && config.lora.region > meshtastic_Config_LoRaConfig_RegionCode_UNSET) { config.lora.tx_enabled = true; + initRegion(); + if (strcmp(moduleConfig.mqtt.root, default_mqtt_root) == 0) { + sprintf(moduleConfig.mqtt.root, "%s/%s", default_mqtt_root, myRegion->name); + changes = SEGMENT_CONFIG | SEGMENT_MODULECONFIG; + } } break; case meshtastic_Config_bluetooth_tag: @@ -323,7 +345,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) break; } - saveChanges(SEGMENT_CONFIG); + saveChanges(changes); } void AdminModule::handleSetModuleConfig(const meshtastic_ModuleConfig &c) @@ -389,6 +411,11 @@ void AdminModule::handleSetModuleConfig(const meshtastic_ModuleConfig &c) moduleConfig.has_ambient_lighting = true; moduleConfig.ambient_lighting = c.payload_variant.ambient_lighting; break; + case meshtastic_ModuleConfig_paxcounter_tag: + LOG_INFO("Setting module config: Paxcounter\n"); + moduleConfig.has_paxcounter = true; + moduleConfig.paxcounter = c.payload_variant.paxcounter; + break; } saveChanges(SEGMENT_MODULECONFIG); @@ -539,6 +566,11 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_ambient_lighting_tag; res.get_module_config_response.payload_variant.ambient_lighting = moduleConfig.ambient_lighting; break; + case meshtastic_AdminMessage_ModuleConfigType_PAXCOUNTER_CONFIG: + LOG_INFO("Getting module config: Paxcounter\n"); + res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_paxcounter_tag; + res.get_module_config_response.payload_variant.paxcounter = moduleConfig.paxcounter; + break; } // NOTE: The phone app needs to know the ls_secsvalue so it can properly expect sleep behavior. @@ -622,12 +654,12 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r #if HAS_BLUETOOTH conn.has_bluetooth = true; conn.bluetooth.pin = config.bluetooth.fixed_pin; -#endif #ifdef ARCH_ESP32 conn.bluetooth.is_connected = nimbleBluetooth->isConnected(); conn.bluetooth.rssi = nimbleBluetooth->getRssi(); #elif defined(ARCH_NRF52) conn.bluetooth.is_connected = nrf52Bluetooth->isConnected(); +#endif #endif conn.has_serial = true; // No serial-less devices conn.serial.is_connected = powerFSM.getState() == &stateSERIAL; diff --git a/src/modules/AtakPluginModule.cpp b/src/modules/AtakPluginModule.cpp new file mode 100644 index 0000000000..ffc4fe68ab --- /dev/null +++ b/src/modules/AtakPluginModule.cpp @@ -0,0 +1,145 @@ +#include "AtakPluginModule.h" +#include "MeshService.h" +#include "NodeDB.h" +#include "PowerFSM.h" +#include "configuration.h" +#include "main.h" +#include "meshtastic/atak.pb.h" + +extern "C" { +#include "mesh/compression/unishox2.h" +} + +AtakPluginModule *atakPluginModule; + +AtakPluginModule::AtakPluginModule() + : ProtobufModule("atak", meshtastic_PortNum_ATAK_PLUGIN, &meshtastic_TAKPacket_msg), concurrency::OSThread("AtakPluginModule") +{ + ourPortNum = meshtastic_PortNum_ATAK_PLUGIN; +} + +/* +Encompasses the full construction and sending packet to mesh +Will be used for broadcast. +*/ +int32_t AtakPluginModule::runOnce() +{ + return default_broadcast_interval_secs; +} + +bool AtakPluginModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_TAKPacket *r) +{ + return false; +} + +meshtastic_TAKPacket AtakPluginModule::cloneTAKPacketData(meshtastic_TAKPacket *t) +{ + meshtastic_TAKPacket clone = meshtastic_TAKPacket_init_zero; + if (t->has_group) { + clone.has_group = true; + clone.group = t->group; + } + if (t->has_status) { + clone.has_status = true; + clone.status = t->status; + } + if (t->has_contact) { + clone.has_contact = true; + clone.contact = {0}; + } + + if (t->which_payload_variant == meshtastic_TAKPacket_pli_tag) { + clone.which_payload_variant = meshtastic_TAKPacket_pli_tag; + clone.payload_variant.pli = t->payload_variant.pli; + } else if (t->which_payload_variant == meshtastic_TAKPacket_chat_tag) { + clone.which_payload_variant = meshtastic_TAKPacket_chat_tag; + clone.payload_variant.chat = {0}; + } + + return clone; +} + +void AtakPluginModule::alterReceivedProtobuf(meshtastic_MeshPacket &mp, meshtastic_TAKPacket *t) +{ + // From Phone (EUD) + if (mp.from == 0) { + LOG_DEBUG("Received uncompressed TAK payload from phone with %d bytes\n", mp.decoded.payload.size); + // Compress for LoRA transport + auto compressed = cloneTAKPacketData(t); + compressed.is_compressed = true; + if (t->has_contact) { + auto length = unishox2_compress_simple(t->contact.callsign, strlen(t->contact.callsign), compressed.contact.callsign); + LOG_DEBUG("Uncompressed callsign '%s' - %d bytes\n", t->contact.callsign, strlen(t->contact.callsign)); + LOG_DEBUG("Compressed callsign '%s' - %d bytes\n", t->contact.callsign, length); + + length = unishox2_compress_simple(t->contact.device_callsign, strlen(t->contact.device_callsign), + compressed.contact.device_callsign); + LOG_DEBUG("Uncompressed device_callsign '%s' - %d bytes\n", t->contact.device_callsign, + strlen(t->contact.device_callsign)); + LOG_DEBUG("Compressed device_callsign '%s' - %d bytes\n", compressed.contact.device_callsign, length); + } + if (t->which_payload_variant == meshtastic_TAKPacket_chat_tag) { + auto length = unishox2_compress_simple(t->payload_variant.chat.message, strlen(t->payload_variant.chat.message), + compressed.payload_variant.chat.message); + LOG_DEBUG("Uncompressed chat message '%s' - %d bytes\n", t->payload_variant.chat.message, + strlen(t->payload_variant.chat.message)); + LOG_DEBUG("Compressed chat message '%s' - %d bytes\n", compressed.payload_variant.chat.message, length); + + if (t->payload_variant.chat.has_to) { + compressed.payload_variant.chat.has_to = true; + length = unishox2_compress_simple(t->payload_variant.chat.to, strlen(t->payload_variant.chat.to), + compressed.payload_variant.chat.to); + LOG_DEBUG("Uncompressed chat to '%s' - %d bytes\n", t->payload_variant.chat.to, + strlen(t->payload_variant.chat.to)); + LOG_DEBUG("Compressed chat to '%s' - %d bytes\n", compressed.payload_variant.chat.to, length); + } + } + mp.decoded.payload.size = pb_encode_to_bytes(mp.decoded.payload.bytes, sizeof(mp.decoded.payload.bytes), + meshtastic_TAKPacket_fields, &compressed); + LOG_DEBUG("Final payload size of %d bytes\n", mp.decoded.payload.size); + } else { + if (!t->is_compressed) { + // Not compressed. Something is wrong + LOG_ERROR("Received uncompressed TAKPacket over radio!\n"); + return; + } + + // Decompress for Phone (EUD) + auto decompressedCopy = packetPool.allocCopy(mp); + auto uncompressed = cloneTAKPacketData(t); + uncompressed.is_compressed = false; + if (t->has_contact) { + auto length = + unishox2_decompress_simple(t->contact.callsign, strlen(t->contact.callsign), uncompressed.contact.callsign); + + LOG_DEBUG("Compressed callsign: %d bytes\n", strlen(t->contact.callsign)); + LOG_DEBUG("Decompressed callsign: '%s' @ %d bytes\n", uncompressed.contact.callsign, length); + + length = unishox2_decompress_simple(t->contact.device_callsign, strlen(t->contact.device_callsign), + uncompressed.contact.device_callsign); + + LOG_DEBUG("Compressed device_callsign: %d bytes\n", strlen(t->contact.device_callsign)); + LOG_DEBUG("Decompressed device_callsign: '%s' @ %d bytes\n", uncompressed.contact.device_callsign, length); + } + if (uncompressed.which_payload_variant == meshtastic_TAKPacket_chat_tag) { + auto length = unishox2_decompress_simple(t->payload_variant.chat.message, strlen(t->payload_variant.chat.message), + uncompressed.payload_variant.chat.message); + LOG_DEBUG("Compressed chat message: %d bytes\n", strlen(t->payload_variant.chat.message)); + LOG_DEBUG("Decompressed chat message: '%s' @ %d bytes\n", uncompressed.payload_variant.chat.message, length); + + if (t->payload_variant.chat.has_to) { + uncompressed.payload_variant.chat.has_to = true; + length = unishox2_decompress_simple(t->payload_variant.chat.to, strlen(t->payload_variant.chat.to), + uncompressed.payload_variant.chat.to); + LOG_DEBUG("Compressed chat to: %d bytes\n", strlen(t->payload_variant.chat.to)); + LOG_DEBUG("Decompressed chat to: '%s' @ %d bytes\n", uncompressed.payload_variant.chat.to, length); + } + } + decompressedCopy->decoded.payload.size = + pb_encode_to_bytes(decompressedCopy->decoded.payload.bytes, sizeof(decompressedCopy->decoded.payload), + meshtastic_TAKPacket_fields, &uncompressed); + + service.sendToPhone(decompressedCopy); + } + return; +} \ No newline at end of file diff --git a/src/modules/AtakPluginModule.h b/src/modules/AtakPluginModule.h new file mode 100644 index 0000000000..0470a3b32c --- /dev/null +++ b/src/modules/AtakPluginModule.h @@ -0,0 +1,26 @@ +#pragma once +#include "ProtobufModule.h" +#include "meshtastic/atak.pb.h" + +/** + * Waypoint message handling for meshtastic + */ +class AtakPluginModule : public ProtobufModule, private concurrency::OSThread +{ + public: + /** Constructor + * name is for debugging output + */ + AtakPluginModule(); + + protected: + virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_TAKPacket *t) override; + virtual void alterReceivedProtobuf(meshtastic_MeshPacket &mp, meshtastic_TAKPacket *t) override; + /* Does our periodic broadcast */ + int32_t runOnce() override; + + private: + meshtastic_TAKPacket cloneTAKPacketData(meshtastic_TAKPacket *t); +}; + +extern AtakPluginModule *atakPluginModule; \ No newline at end of file diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index dedfdb8500..3127b09861 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -1,6 +1,10 @@ #include "configuration.h" +#if ARCH_PORTDUINO +#include "PortduinoGlue.h" +#endif #if HAS_SCREEN #include "CannedMessageModule.h" +#include "Channels.h" #include "FSCommon.h" #include "MeshService.h" #include "NodeDB.h" @@ -138,17 +142,23 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event) // source at all) return 0; } - + if (this->runState == CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE) { + return 0; // Ignore input while sending + } bool validEvent = false; if (event->inputEvent == static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP)) { - // LOG_DEBUG("Canned message event UP\n"); - this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_UP; - validEvent = true; + if (this->messagesCount > 0) { + // LOG_DEBUG("Canned message event UP\n"); + this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_UP; + validEvent = true; + } } if (event->inputEvent == static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_DOWN)) { - // LOG_DEBUG("Canned message event DOWN\n"); - this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_DOWN; - validEvent = true; + if (this->messagesCount > 0) { + // LOG_DEBUG("Canned message event DOWN\n"); + this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_DOWN; + validEvent = true; + } } if (event->inputEvent == static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT)) { LOG_DEBUG("Canned message event Select\n"); @@ -163,9 +173,14 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event) } if (event->inputEvent == static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL)) { LOG_DEBUG("Canned message event Cancel\n"); - // emulate a timeout. Same result - this->lastTouchMillis = 0; - validEvent = true; + UIFrameEvent e = {false, true}; + e.frameChanged = true; + this->currentMessageIndex = -1; + this->freetext = ""; // clear freetext + this->cursor = 0; + this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE; + this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE; + this->notifyObservers(&e); } if ((event->inputEvent == static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_BACK)) || (event->inputEvent == static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT)) || @@ -175,10 +190,10 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event) if (!event->kbchar) { if (event->inputEvent == static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT)) { this->payload = 0xb4; - this->destSelect = true; + this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NODE; } else if (event->inputEvent == static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT)) { this->payload = 0xb7; - this->destSelect = true; + this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NODE; } } else { // pass the pressed key @@ -212,16 +227,21 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event) if (validEvent) { // Let runOnce to be called immediately. - setIntervalFromNow(0); + if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_SELECT) { + setIntervalFromNow(0); // on fast keypresses, this isn't fast enough. + } else { + runOnce(); + } } return 0; } -void CannedMessageModule::sendText(NodeNum dest, const char *message, bool wantReplies) +void CannedMessageModule::sendText(NodeNum dest, ChannelIndex channel, const char *message, bool wantReplies) { meshtastic_MeshPacket *p = allocDataPacket(); p->to = dest; + p->channel = channel; p->want_ack = true; p->decoded.payload.size = strlen(message); memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size); @@ -254,7 +274,7 @@ int32_t CannedMessageModule::runOnce() this->currentMessageIndex = -1; this->freetext = ""; // clear freetext this->cursor = 0; - this->destSelect = false; + this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE; this->notifyObservers(&e); } else if (((this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT)) && ((millis() - this->lastTouchMillis) > INACTIVATE_AFTER_MS)) { @@ -264,13 +284,13 @@ int32_t CannedMessageModule::runOnce() this->currentMessageIndex = -1; this->freetext = ""; // clear freetext this->cursor = 0; - this->destSelect = false; + this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE; this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE; this->notifyObservers(&e); } else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_SELECT) { if (this->payload == CANNED_MESSAGE_RUN_STATE_FREETEXT) { if (this->freetext.length() > 0) { - sendText(this->dest, this->freetext.c_str(), true); + sendText(this->dest, indexChannels[this->channel], this->freetext.c_str(), true); this->runState = CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE; } else { LOG_DEBUG("Reset message is empty.\n"); @@ -282,7 +302,7 @@ int32_t CannedMessageModule::runOnce() powerFSM.trigger(EVENT_PRESS); return INT32_MAX; } else { - sendText(NODENUM_BROADCAST, this->messages[this->currentMessageIndex], true); + sendText(NODENUM_BROADCAST, channels.getPrimaryIndex(), this->messages[this->currentMessageIndex], true); } this->runState = CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE; } else { @@ -294,7 +314,7 @@ int32_t CannedMessageModule::runOnce() this->currentMessageIndex = -1; this->freetext = ""; // clear freetext this->cursor = 0; - this->destSelect = false; + this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE; this->notifyObservers(&e); return 2000; } else if ((this->runState != CANNED_MESSAGE_RUN_STATE_FREETEXT) && (this->currentMessageIndex == -1)) { @@ -307,7 +327,7 @@ int32_t CannedMessageModule::runOnce() this->currentMessageIndex = getPrevIndex(); this->freetext = ""; // clear freetext this->cursor = 0; - this->destSelect = false; + this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE; this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE; LOG_DEBUG("MOVE UP (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage()); } @@ -316,14 +336,14 @@ int32_t CannedMessageModule::runOnce() this->currentMessageIndex = this->getNextIndex(); this->freetext = ""; // clear freetext this->cursor = 0; - this->destSelect = false; + this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE; this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE; LOG_DEBUG("MOVE DOWN (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage()); } } else if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT || this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) { switch (this->payload) { case 0xb4: // left - if (this->destSelect) { + if (this->destSelect == CANNED_MESSAGE_DESTINATION_TYPE_NODE) { size_t numMeshNodes = nodeDB.getNumMeshNodes(); if (this->dest == NODENUM_BROADCAST) { this->dest = nodeDB.getNodeNum(); @@ -338,6 +358,19 @@ int32_t CannedMessageModule::runOnce() if (this->dest == nodeDB.getNodeNum()) { this->dest = NODENUM_BROADCAST; } + } else if (this->destSelect == CANNED_MESSAGE_DESTINATION_TYPE_CHANNEL) { + for (unsigned int i = 0; i < channels.getNumChannels(); i++) { + if ((channels.getByIndex(i).role == meshtastic_Channel_Role_SECONDARY) || + (channels.getByIndex(i).role == meshtastic_Channel_Role_PRIMARY)) { + indexChannels[numChannels] = i; + numChannels++; + } + } + if (this->channel == 0) { + this->channel = numChannels - 1; + } else { + this->channel--; + } } else { if (this->cursor > 0) { this->cursor--; @@ -345,7 +378,7 @@ int32_t CannedMessageModule::runOnce() } break; case 0xb7: // right - if (this->destSelect) { + if (this->destSelect == CANNED_MESSAGE_DESTINATION_TYPE_NODE) { size_t numMeshNodes = nodeDB.getNumMeshNodes(); if (this->dest == NODENUM_BROADCAST) { this->dest = nodeDB.getNodeNum(); @@ -360,6 +393,19 @@ int32_t CannedMessageModule::runOnce() if (this->dest == nodeDB.getNodeNum()) { this->dest = NODENUM_BROADCAST; } + } else if (this->destSelect == CANNED_MESSAGE_DESTINATION_TYPE_CHANNEL) { + for (unsigned int i = 0; i < channels.getNumChannels(); i++) { + if ((channels.getByIndex(i).role == meshtastic_Channel_Role_SECONDARY) || + (channels.getByIndex(i).role == meshtastic_Channel_Role_PRIMARY)) { + indexChannels[numChannels] = i; + numChannels++; + } + } + if (this->channel == numChannels - 1) { + this->channel = 0; + } else { + this->channel++; + } } else { if (this->cursor < this->freetext.length()) { this->cursor++; @@ -384,10 +430,12 @@ int32_t CannedMessageModule::runOnce() } break; case 0x09: // tab - if (this->destSelect) { - this->destSelect = false; + if (this->destSelect == CANNED_MESSAGE_DESTINATION_TYPE_CHANNEL) { + this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE; + } else if (this->destSelect == CANNED_MESSAGE_DESTINATION_TYPE_NODE) { + this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_CHANNEL; } else { - this->destSelect = true; + this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NODE; } break; case 0xb4: // left @@ -508,19 +556,39 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st } else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) { display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(FONT_SMALL); - if (this->destSelect) { + if (this->destSelect != CANNED_MESSAGE_DESTINATION_TYPE_NONE) { display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL); display->setColor(BLACK); - display->drawStringf(1 + x, 0 + y, buffer, "To: %s", cannedMessageModule->getNodeName(this->dest)); } - display->drawStringf(0 + x, 0 + y, buffer, "To: %s", cannedMessageModule->getNodeName(this->dest)); - // used chars right aligned - uint16_t charsLeft = - meshtastic_Constants_DATA_PAYLOAD_LEN - this->freetext.length() - (moduleConfig.canned_message.send_bell ? 1 : 0); - snprintf(buffer, sizeof(buffer), "%d left", charsLeft); - display->drawString(x + display->getWidth() - display->getStringWidth(buffer), y + 0, buffer); - if (this->destSelect) { - display->drawString(x + display->getWidth() - display->getStringWidth(buffer) - 1, y + 0, buffer); + switch (this->destSelect) { + case CANNED_MESSAGE_DESTINATION_TYPE_NODE: + display->drawStringf(1 + x, 0 + y, buffer, "To: >%s<@%s", cannedMessageModule->getNodeName(this->dest), + channels.getName(indexChannels[this->channel])); + display->drawStringf(0 + x, 0 + y, buffer, "To: >%s<@%s", cannedMessageModule->getNodeName(this->dest), + channels.getName(indexChannels[this->channel])); + break; + case CANNED_MESSAGE_DESTINATION_TYPE_CHANNEL: + display->drawStringf(1 + x, 0 + y, buffer, "To: %s@>%s<", cannedMessageModule->getNodeName(this->dest), + channels.getName(indexChannels[this->channel])); + display->drawStringf(0 + x, 0 + y, buffer, "To: %s@>%s<", cannedMessageModule->getNodeName(this->dest), + channels.getName(indexChannels[this->channel])); + break; + default: + if (display->getWidth() > 128) { + display->drawStringf(0 + x, 0 + y, buffer, "To: %s@%s", cannedMessageModule->getNodeName(this->dest), + channels.getName(indexChannels[this->channel])); + } else { + display->drawStringf(0 + x, 0 + y, buffer, "To: %.5s@%.5s", cannedMessageModule->getNodeName(this->dest), + channels.getName(indexChannels[this->channel])); + } + break; + } + // used chars right aligned, only when not editing the destination + if (this->destSelect == CANNED_MESSAGE_DESTINATION_TYPE_NONE) { + uint16_t charsLeft = + meshtastic_Constants_DATA_PAYLOAD_LEN - this->freetext.length() - (moduleConfig.canned_message.send_bell ? 1 : 0); + snprintf(buffer, sizeof(buffer), "%d left", charsLeft); + display->drawString(x + display->getWidth() - display->getStringWidth(buffer), y + 0, buffer); } display->setColor(WHITE); display->drawStringMaxWidth( diff --git a/src/modules/CannedMessageModule.h b/src/modules/CannedMessageModule.h index b41fba045f..4802be0781 100644 --- a/src/modules/CannedMessageModule.h +++ b/src/modules/CannedMessageModule.h @@ -15,6 +15,12 @@ enum cannedMessageModuleRunState { CANNED_MESSAGE_RUN_STATE_ACTION_DOWN, }; +enum cannedMessageDestinationType { + CANNED_MESSAGE_DESTINATION_TYPE_NONE, + CANNED_MESSAGE_DESTINATION_TYPE_NODE, + CANNED_MESSAGE_DESTINATION_TYPE_CHANNEL +}; + #define CANNED_MESSAGE_MODULE_MESSAGE_MAX_COUNT 50 /** * Sum of CannedMessageModuleConfig part sizes. @@ -64,7 +70,7 @@ class CannedMessageModule : public SinglePortModule, public Observableinit()) { delete rotaryEncoderInterruptImpl1; @@ -79,6 +86,10 @@ void setupModules() kbMatrixImpl->init(); #endif // INPUTBROKER_MATRIX_TYPE #endif // HAS_BUTTON +#if ARCH_PORTDUINO + aLinuxInputImpl = new LinuxInputImpl(); + aLinuxInputImpl->init(); +#endif #if HAS_TRACKBALL trackballInterruptImpl1 = new TrackballInterruptImpl1(); trackballInterruptImpl1->init(); @@ -104,9 +115,11 @@ void setupModules() #endif #ifdef ARCH_ESP32 // Only run on an esp32 based device. +#ifdef USE_SX1280 audioModule = new AudioModule(); - +#endif storeForwardModule = new StoreForwardModule(); + paxcounterModule = new PaxcounterModule(); #endif #if defined(ARCH_ESP32) || defined(ARCH_NRF52) || defined(ARCH_RP2040) externalNotificationModule = new ExternalNotificationModule(); diff --git a/src/modules/NeighborInfoModule.cpp b/src/modules/NeighborInfoModule.cpp index 0e4ad338fc..d20dbeaca1 100644 --- a/src/modules/NeighborInfoModule.cpp +++ b/src/modules/NeighborInfoModule.cpp @@ -118,7 +118,7 @@ uint32_t NeighborInfoModule::collectNeighborInfo(meshtastic_NeighborInfo *neighb int num_neighbors = cleanUpNeighbors(); for (int i = 0; i < num_neighbors; i++) { - meshtastic_Neighbor *dbEntry = getNeighborByIndex(i); + const meshtastic_Neighbor *dbEntry = getNeighborByIndex(i); if ((neighborInfo->neighbors_count < MAX_NUM_NEIGHBORS) && (dbEntry->node_id != my_node_id)) { neighborInfo->neighbors[neighborInfo->neighbors_count].node_id = dbEntry->node_id; neighborInfo->neighbors[neighborInfo->neighbors_count].snr = dbEntry->snr; @@ -146,7 +146,7 @@ size_t NeighborInfoModule::cleanUpNeighbors() // Find neighbors to remove std::vector indices_to_remove; for (int i = 0; i < num_neighbors; i++) { - meshtastic_Neighbor *dbEntry = getNeighborByIndex(i); + const meshtastic_Neighbor *dbEntry = getNeighborByIndex(i); // We will remove a neighbor if we haven't heard from them in twice the broadcast interval if ((now - dbEntry->last_rx_time > dbEntry->node_broadcast_interval_secs * 2) && (dbEntry->node_id != my_node_id)) { indices_to_remove.push_back(i); diff --git a/src/modules/NodeInfoModule.cpp b/src/modules/NodeInfoModule.cpp index 799f6ec7ce..b0b4bbdcd0 100644 --- a/src/modules/NodeInfoModule.cpp +++ b/src/modules/NodeInfoModule.cpp @@ -12,7 +12,7 @@ bool NodeInfoModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes { auto p = *pptr; - bool hasChanged = nodeDB.updateUser(getFrom(&mp), p); + bool hasChanged = nodeDB.updateUser(getFrom(&mp), p, mp.channel); bool wasBroadcast = mp.to == NODENUM_BROADCAST; @@ -83,8 +83,6 @@ NodeInfoModule::NodeInfoModule() int32_t NodeInfoModule::runOnce() { - static uint32_t currentGeneration; - // If we changed channels, ask everyone else for their latest info bool requestReplies = currentGeneration != radioGeneration; currentGeneration = radioGeneration; diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index da10504d8c..e75822a863 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -8,21 +8,31 @@ #include "airtime.h" #include "configuration.h" #include "gps/GeoCoord.h" +#include "main.h" +#include "meshtastic/atak.pb.h" #include "sleep.h" #include "target_specific.h" +extern "C" { +#include "mesh/compression/unishox2.h" +} + PositionModule *positionModule; PositionModule::PositionModule() : ProtobufModule("position", meshtastic_PortNum_POSITION_APP, &meshtastic_Position_msg), concurrency::OSThread("PositionModule") { + precision = 0; // safe starting value isPromiscuous = true; // We always want to update our nodedb, even if we are sniffing on others - if (config.device.role != meshtastic_Config_DeviceConfig_Role_TRACKER) + if (config.device.role != meshtastic_Config_DeviceConfig_Role_TRACKER && + config.device.role != meshtastic_Config_DeviceConfig_Role_TAK_TRACKER) setIntervalFromNow(60 * 1000); // Power saving trackers should clear their position on startup to avoid waking up and sending a stale position - if (config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER && config.power.is_power_saving) { + if ((config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER || + config.device.role == meshtastic_Config_DeviceConfig_Role_TAK_TRACKER) && + config.power.is_power_saving) { clearPosition(); } } @@ -61,7 +71,7 @@ bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes p.altitude_geoidal_separation, p.PDOP, p.HDOP, p.VDOP, p.sats_in_view, p.fix_quality, p.fix_type, p.timestamp, p.time); - if (p.time) { + if (p.time && channels.getByIndex(mp.channel).role == meshtastic_Channel_Role_PRIMARY) { struct timeval tv; uint32_t secs = p.time; @@ -74,19 +84,13 @@ bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes nodeDB.updatePosition(getFrom(&mp), p); - // Only respond to location requests on the channel where we broadcast location. - if (channels.getByIndex(mp.channel).role == meshtastic_Channel_Role_PRIMARY) { - ignoreRequest = false; - } else { - ignoreRequest = true; - } - return false; // Let others look at this message also if they want } meshtastic_MeshPacket *PositionModule::allocReply() { - if (ignoreRequest) { + if (precision == 0) { + LOG_DEBUG("Skipping location send because precision is set to 0!\n"); return nullptr; } @@ -106,8 +110,10 @@ meshtastic_MeshPacket *PositionModule::allocReply() localPosition.seq_number++; // lat/lon are unconditionally included - IF AVAILABLE! - p.latitude_i = localPosition.latitude_i; - p.longitude_i = localPosition.longitude_i; + LOG_DEBUG("Sending location with precision %i\n", precision); + p.latitude_i = localPosition.latitude_i & (INT32_MAX << (32 - precision)); + p.longitude_i = localPosition.longitude_i & (INT32_MAX << (32 - precision)); + p.precision_bits = precision; p.time = localPosition.time; if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE) { @@ -150,29 +156,72 @@ meshtastic_MeshPacket *PositionModule::allocReply() LOG_INFO("Stripping time %u from position send\n", p.time); p.time = 0; } else { + p.time = getValidTime(RTCQualityDevice); LOG_INFO("Providing time to mesh %u\n", p.time); } - LOG_INFO("Position reply: time=%i, latI=%i, lonI=-%i\n", p.time, p.latitude_i, p.longitude_i); + LOG_INFO("Position reply: time=%i, latI=%i, lonI=%i\n", p.time, p.latitude_i, p.longitude_i); + + // TAK Tracker devices should send their position in a TAK packet over the ATAK port + if (config.device.role == meshtastic_Config_DeviceConfig_Role_TAK_TRACKER) + return allocAtakPli(); return allocDataProtobuf(p); } +meshtastic_MeshPacket *PositionModule::allocAtakPli() +{ + LOG_INFO("Sending TAK PLI packet\n"); + meshtastic_MeshPacket *mp = allocDataPacket(); + mp->decoded.portnum = meshtastic_PortNum_ATAK_PLUGIN; + + meshtastic_TAKPacket takPacket = {.is_compressed = true, + .has_contact = true, + .contact = {0}, + .has_group = true, + .group = {meshtastic_MemberRole_TeamMember, meshtastic_Team_Cyan}, + .has_status = true, + .status = + { + .battery = powerStatus->getBatteryChargePercent(), + }, + .which_payload_variant = meshtastic_TAKPacket_pli_tag, + {.pli = { + .latitude_i = localPosition.latitude_i, + .longitude_i = localPosition.longitude_i, + .altitude = localPosition.altitude_hae, + .speed = localPosition.ground_speed, + .course = static_cast(localPosition.ground_track), + }}}; + + auto length = unishox2_compress_simple(owner.long_name, strlen(owner.long_name), takPacket.contact.device_callsign); + LOG_DEBUG("Uncompressed device_callsign '%s' - %d bytes\n", owner.long_name, strlen(owner.long_name)); + LOG_DEBUG("Compressed device_callsign '%s' - %d bytes\n", takPacket.contact.device_callsign, length); + length = unishox2_compress_simple(owner.long_name, strlen(owner.long_name), takPacket.contact.callsign); + mp->decoded.payload.size = + pb_encode_to_bytes(mp->decoded.payload.bytes, sizeof(mp->decoded.payload.bytes), &meshtastic_TAKPacket_msg, &takPacket); + return mp; +} + void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t channel) { // cancel any not yet sent (now stale) position packets if (prevPacketId) // if we wrap around to zero, we'll simply fail to cancel in that rare case (no big deal) service.cancelSending(prevPacketId); + // Set's the class precision value for this particular packet + precision = channels.getByIndex(channel).settings.module_settings.position_precision; + meshtastic_MeshPacket *p = allocReply(); if (p == nullptr) { - LOG_WARN("allocReply returned a nullptr"); + LOG_DEBUG("allocReply returned a nullptr\n"); return; } p->to = dest; p->decoded.want_response = config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER ? false : wantReplies; - if (config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER) + if (config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER || + config.device.role == meshtastic_Config_DeviceConfig_Role_TAK_TRACKER) p->priority = meshtastic_MeshPacket_Priority_RELIABLE; else p->priority = meshtastic_MeshPacket_Priority_BACKGROUND; @@ -183,7 +232,9 @@ void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t cha service.sendToMesh(p, RX_SRC_LOCAL, true); - if (config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER && config.power.is_power_saving) { + if ((config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER || + config.device.role == meshtastic_Config_DeviceConfig_Role_TAK_TRACKER) && + config.power.is_power_saving) { LOG_DEBUG("Starting next execution in 5 seconds and then going to sleep.\n"); sleepOnNextExecution = true; setIntervalFromNow(5000); @@ -202,13 +253,16 @@ int32_t PositionModule::runOnce() } meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); + if (node == nullptr) + return RUNONCE_INTERVAL; // We limit our GPS broadcasts to a max rate uint32_t now = millis(); uint32_t intervalMs = getConfiguredOrDefaultMs(config.position.position_broadcast_secs, default_broadcast_interval_secs); uint32_t msSinceLastSend = now - lastGpsSend; // Only send packets if the channel util. is less than 25% utilized or we're a tracker with less than 40% utilized. - if (!airTime->isTxAllowedChannelUtil(config.device.role != meshtastic_Config_DeviceConfig_Role_TRACKER)) { + if (!airTime->isTxAllowedChannelUtil(config.device.role != meshtastic_Config_DeviceConfig_Role_TRACKER && + config.device.role != meshtastic_Config_DeviceConfig_Role_TAK_TRACKER)) { return RUNONCE_INTERVAL; } @@ -225,6 +279,9 @@ int32_t PositionModule::runOnce() LOG_INFO("Sending pos@%x:6 to mesh (wantReplies=%d)\n", localPosition.timestamp, requestReplies); sendOurPosition(NODENUM_BROADCAST, requestReplies); + if (config.device.role == meshtastic_Config_DeviceConfig_Role_LOST_AND_FOUND) { + sendLostAndFoundText(); + } } } else if (config.position.position_broadcast_smart_enabled) { const meshtastic_NodeInfoLite *node2 = service.refreshLocalMeshNode(); // should guarantee there is now a position @@ -261,6 +318,21 @@ int32_t PositionModule::runOnce() return RUNONCE_INTERVAL; // to save power only wake for our callback occasionally } +void PositionModule::sendLostAndFoundText() +{ + meshtastic_MeshPacket *p = allocDataPacket(); + p->to = NODENUM_BROADCAST; + char *message = new char[60]; + sprintf(message, "🚨I'm lost! Lat / Lon: %f, %f\a", (lastGpsLatitude * 1e-7), (lastGpsLongitude * 1e-7)); + p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP; + p->want_ack = false; + p->decoded.payload.size = strlen(message); + memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size); + + service.sendToMesh(p, RX_SRC_LOCAL, true); + delete[] message; +} + struct SmartPosition PositionModule::getDistanceTraveledSinceLastSend(meshtastic_PositionLite currentPosition) { // The minimum distance to travel before we are able to send a new position packet. diff --git a/src/modules/PositionModule.h b/src/modules/PositionModule.h index 1b7eca8004..fddafef6f7 100644 --- a/src/modules/PositionModule.h +++ b/src/modules/PositionModule.h @@ -49,9 +49,12 @@ class PositionModule : public ProtobufModule, private concu private: struct SmartPosition getDistanceTraveledSinceLastSend(meshtastic_PositionLite currentPosition); + meshtastic_MeshPacket *allocAtakPli(); + uint32_t precision; /** Only used in power saving trackers for now */ void clearPosition(); + void sendLostAndFoundText(); }; struct SmartPosition { diff --git a/src/modules/RemoteHardwareModule.cpp b/src/modules/RemoteHardwareModule.cpp index 3d4d735b43..8e64b9a9ca 100644 --- a/src/modules/RemoteHardwareModule.cpp +++ b/src/modules/RemoteHardwareModule.cpp @@ -56,7 +56,7 @@ bool RemoteHardwareModule::handleReceivedProtobuf(const meshtastic_MeshPacket &r LOG_INFO("Received RemoteHardware type=%d\n", p.type); switch (p.type) { - case meshtastic_HardwareMessage_Type_WRITE_GPIOS: + case meshtastic_HardwareMessage_Type_WRITE_GPIOS: { // Print notification to LCD screen screen->print("Write GPIOs\n"); @@ -69,6 +69,7 @@ bool RemoteHardwareModule::handleReceivedProtobuf(const meshtastic_MeshPacket &r pinModes(p.gpio_mask, OUTPUT); break; + } case meshtastic_HardwareMessage_Type_READ_GPIOS: { // Print notification to LCD screen @@ -92,8 +93,9 @@ bool RemoteHardwareModule::handleReceivedProtobuf(const meshtastic_MeshPacket &r watchGpios = p.gpio_mask; lastWatchMsec = 0; // Force a new publish soon previousWatch = - ~watchGpios; // generate a 'previous' value which is guaranteed to not match (to force an initial publish) - enabled = true; // Let our thread run at least once + ~watchGpios; // generate a 'previous' value which is guaranteed to not match (to force an initial publish) + enabled = true; // Let our thread run at least once + setInterval(2000); // Set a new interval so we'll run soon LOG_INFO("Now watching GPIOs 0x%llx\n", watchGpios); break; } @@ -118,6 +120,7 @@ int32_t RemoteHardwareModule::runOnce() if (now - lastWatchMsec >= WATCH_INTERVAL_MSEC) { uint64_t curVal = digitalReads(watchGpios); + lastWatchMsec = now; if (curVal != previousWatch) { previousWatch = curVal; @@ -136,5 +139,5 @@ int32_t RemoteHardwareModule::runOnce() return disable(); } - return 200; // Poll our GPIOs every 200ms (FIXME, make adjustable via protobuf arg) -} + return 2000; // Poll our GPIOs every 2000ms +} \ No newline at end of file diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index 42b1090506..820e1fb62b 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -58,7 +58,7 @@ SerialModule *serialModule; SerialModuleRadio *serialModuleRadio; -#ifdef TTGO_T_ECHO +#if defined(TTGO_T_ECHO) || defined(CANARYONE) SerialModule::SerialModule() : StreamAPI(&Serial), concurrency::OSThread("SerialModule") {} static Print *serialPrint = &Serial; #else @@ -140,7 +140,7 @@ int32_t SerialModule::runOnce() Serial.begin(baud); Serial.setTimeout(moduleConfig.serial.timeout > 0 ? moduleConfig.serial.timeout : TIMEOUT); } -#elif !defined(TTGO_T_ECHO) +#elif !defined(TTGO_T_ECHO) && !defined(CANARYONE) if (moduleConfig.serial.rxd && moduleConfig.serial.txd) { #ifdef ARCH_RP2040 Serial2.setFIFOSize(RX_BUFFER); @@ -188,7 +188,7 @@ int32_t SerialModule::runOnce() } } } -#if !defined(TTGO_T_ECHO) +#if !defined(TTGO_T_ECHO) && !defined(CANARYONE) else { while (Serial2.available()) { serialPayloadSize = Serial2.readBytes(serialBytes, meshtastic_Constants_DATA_PAYLOAD_LEN); diff --git a/src/modules/TraceRouteModule.cpp b/src/modules/TraceRouteModule.cpp index bf7eaa0cd8..311e211f3c 100644 --- a/src/modules/TraceRouteModule.cpp +++ b/src/modules/TraceRouteModule.cpp @@ -85,4 +85,4 @@ TraceRouteModule::TraceRouteModule() : ProtobufModule("traceroute", meshtastic_PortNum_TRACEROUTE_APP, &meshtastic_RouteDiscovery_msg) { ourPortNum = meshtastic_PortNum_TRACEROUTE_APP; -} +} \ No newline at end of file diff --git a/src/modules/esp32/AudioModule.cpp b/src/modules/esp32/AudioModule.cpp index a2e43347ad..bc104df117 100644 --- a/src/modules/esp32/AudioModule.cpp +++ b/src/modules/esp32/AudioModule.cpp @@ -1,6 +1,6 @@ #include "configuration.h" -#if defined(ARCH_ESP32) +#if defined(ARCH_ESP32) && defined(USE_SX1280) #include "AudioModule.h" #include "FSCommon.h" #include "MeshService.h" @@ -145,7 +145,7 @@ AudioModule::AudioModule() : SinglePortModule("AudioModule", meshtastic_PortNum_ encode_frame_num = (meshtastic_Constants_DATA_PAYLOAD_LEN - sizeof(tx_header)) / encode_codec_size; encode_frame_size = encode_frame_num * encode_codec_size; // max 233 bytes + 4 header bytes adc_buffer_size = codec2_samples_per_frame(codec2); - LOG_INFO(" using %d frames of %d bytes for a total payload length of %d bytes\n", encode_frame_num, encode_codec_size, + LOG_INFO("using %d frames of %d bytes for a total payload length of %d bytes\n", encode_frame_num, encode_codec_size, encode_frame_size); xTaskCreate(&run_codec2, "codec2_task", 30000, NULL, 5, &codec2HandlerTask); } else { diff --git a/src/modules/esp32/AudioModule.h b/src/modules/esp32/AudioModule.h index 8bf8c3f559..b6762706a6 100644 --- a/src/modules/esp32/AudioModule.h +++ b/src/modules/esp32/AudioModule.h @@ -3,7 +3,7 @@ #include "SinglePortModule.h" #include "concurrency/NotifiedWorkerThread.h" #include "configuration.h" -#if defined(ARCH_ESP32) +#if defined(ARCH_ESP32) && defined(USE_SX1280) #include "NodeDB.h" #include #include diff --git a/src/modules/esp32/PaxcounterModule.cpp b/src/modules/esp32/PaxcounterModule.cpp new file mode 100644 index 0000000000..f3df7ffdf5 --- /dev/null +++ b/src/modules/esp32/PaxcounterModule.cpp @@ -0,0 +1,90 @@ +#include "configuration.h" +#if defined(ARCH_ESP32) +#include "MeshService.h" +#include "PaxcounterModule.h" + +#include + +PaxcounterModule *paxcounterModule; + +void NullFunc(){}; + +// paxcounterModule->sendInfo(NODENUM_BROADCAST); + +PaxcounterModule::PaxcounterModule() + : concurrency::OSThread("PaxcounterModule"), + ProtobufModule("paxcounter", meshtastic_PortNum_PAXCOUNTER_APP, &meshtastic_Paxcount_msg) +{ +} + +bool PaxcounterModule::sendInfo(NodeNum dest) +{ + libpax_counter_count(&count_from_libpax); + LOG_INFO("(Sending): pax: wifi=%d; ble=%d; uptime=%d\n", count_from_libpax.wifi_count, count_from_libpax.ble_count, + millis() / 1000); + + meshtastic_Paxcount pl = meshtastic_Paxcount_init_default; + pl.wifi = count_from_libpax.wifi_count; + pl.ble = count_from_libpax.ble_count; + pl.uptime = millis() / 1000; + + meshtastic_MeshPacket *p = allocDataProtobuf(pl); + p->to = dest; + p->decoded.want_response = false; + p->priority = meshtastic_MeshPacket_Priority_MIN; + + service.sendToMesh(p, RX_SRC_LOCAL, true); + return true; +} + +bool PaxcounterModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Paxcount *p) +{ + return false; // Let others look at this message also if they want. We don't do anything with received packets. +} + +meshtastic_MeshPacket *PaxcounterModule::allocReply() +{ + if (ignoreRequest) { + return NULL; + } + + meshtastic_Paxcount pl = meshtastic_Paxcount_init_default; + pl.wifi = count_from_libpax.wifi_count; + pl.ble = count_from_libpax.ble_count; + pl.uptime = millis() / 1000; + return allocDataProtobuf(pl); +} + +int32_t PaxcounterModule::runOnce() +{ + if (moduleConfig.paxcounter.enabled && !config.bluetooth.enabled && !config.network.wifi_enabled) { + if (firstTime) { + firstTime = false; + LOG_DEBUG( + "Paxcounter starting up with interval of %d seconds\n", + getConfiguredOrDefault(moduleConfig.paxcounter.paxcounter_update_interval, default_broadcast_interval_secs)); + struct libpax_config_t configuration; + libpax_default_config(&configuration); + + configuration.blecounter = 1; + configuration.blescantime = 0; // infinit + configuration.wificounter = 1; + configuration.wifi_channel_map = WIFI_CHANNEL_ALL; + configuration.wifi_channel_switch_interval = 50; + configuration.wifi_rssi_threshold = -80; + configuration.ble_rssi_threshold = -80; + libpax_update_config(&configuration); + + // internal processing initialization + libpax_counter_init(NullFunc, &count_from_libpax, UINT16_MAX, 1); + libpax_counter_start(); + } else { + sendInfo(NODENUM_BROADCAST); + } + return getConfiguredOrDefaultMs(moduleConfig.paxcounter.paxcounter_update_interval, default_broadcast_interval_secs); + } else { + return disable(); + } +} + +#endif \ No newline at end of file diff --git a/src/modules/esp32/PaxcounterModule.h b/src/modules/esp32/PaxcounterModule.h new file mode 100644 index 0000000000..0aa9be68d1 --- /dev/null +++ b/src/modules/esp32/PaxcounterModule.h @@ -0,0 +1,29 @@ +#pragma once + +#include "ProtobufModule.h" +#include "configuration.h" +#if defined(ARCH_ESP32) +#include "../mesh/generated/meshtastic/paxcount.pb.h" +#include "NodeDB.h" +#include + +/** + * A simple example module that just replies with "Message received" to any message it receives. + */ +class PaxcounterModule : private concurrency::OSThread, public ProtobufModule +{ + bool firstTime = true; + + public: + PaxcounterModule(); + + protected: + struct count_payload_t count_from_libpax = {0, 0, 0}; + virtual int32_t runOnce() override; + bool sendInfo(NodeNum dest = NODENUM_BROADCAST); + virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Paxcount *p) override; + virtual meshtastic_MeshPacket *allocReply() override; +}; + +extern PaxcounterModule *paxcounterModule; +#endif \ No newline at end of file diff --git a/src/modules/esp32/StoreForwardModule.cpp b/src/modules/esp32/StoreForwardModule.cpp index 6b2c079cc1..cb15525212 100644 --- a/src/modules/esp32/StoreForwardModule.cpp +++ b/src/modules/esp32/StoreForwardModule.cpp @@ -38,16 +38,11 @@ int32_t StoreForwardModule::runOnce() // Only send packets if the channel is less than 25% utilized. if (airTime->isTxAllowedChannelUtil(true)) { storeForwardModule->sendPayload(this->busyTo, this->packetHistoryTXQueue_index); - if (this->packetHistoryTXQueue_index == packetHistoryTXQueue_size) { - // Tell the client we're done sending - meshtastic_StoreAndForward sf = meshtastic_StoreAndForward_init_zero; - sf.rr = meshtastic_StoreAndForward_RequestResponse_ROUTER_PING; - storeForwardModule->sendMessage(this->busyTo, sf); - LOG_INFO("*** S&F - Done. (ROUTER_PING)\n"); + if (this->packetHistoryTXQueue_index < packetHistoryTXQueue_size - 1) { + this->packetHistoryTXQueue_index++; + } else { this->packetHistoryTXQueue_index = 0; this->busy = false; - } else { - this->packetHistoryTXQueue_index++; } } } else if ((millis() - lastHeartbeat > (heartbeatInterval * 1000)) && airTime->isTxAllowedChannelUtil(true)) { @@ -56,7 +51,7 @@ int32_t StoreForwardModule::runOnce() meshtastic_StoreAndForward sf = meshtastic_StoreAndForward_init_zero; sf.rr = meshtastic_StoreAndForward_RequestResponse_ROUTER_HEARTBEAT; sf.which_variant = meshtastic_StoreAndForward_heartbeat_tag; - sf.variant.heartbeat.period = 300; + sf.variant.heartbeat.period = heartbeatInterval; sf.variant.heartbeat.secondary = 0; // TODO we always have one primary router for now storeForwardModule->sendMessage(NODENUM_BROADCAST, sf); } @@ -104,7 +99,8 @@ void StoreForwardModule::populatePSRAM() */ void StoreForwardModule::historySend(uint32_t msAgo, uint32_t to) { - uint32_t queueSize = storeForwardModule->historyQueueCreate(msAgo, to); + uint32_t lastIndex = lastRequest.find(to) != lastRequest.end() ? lastRequest[to] : 0; + uint32_t queueSize = storeForwardModule->historyQueueCreate(msAgo, to, &lastIndex); if (queueSize) { LOG_INFO("*** S&F - Sending %u message(s)\n", queueSize); @@ -118,6 +114,8 @@ void StoreForwardModule::historySend(uint32_t msAgo, uint32_t to) sf.which_variant = meshtastic_StoreAndForward_history_tag; sf.variant.history.history_messages = queueSize; sf.variant.history.window = msAgo; + sf.variant.history.last_request = lastIndex; + lastRequest[to] = lastIndex; storeForwardModule->sendMessage(to, sf); } @@ -125,15 +123,18 @@ void StoreForwardModule::historySend(uint32_t msAgo, uint32_t to) * Creates a new history queue with messages that were received within the specified time frame. * * @param msAgo The number of milliseconds ago to start the history queue. - * @param to The maximum number of messages to include in the history queue. + * @param to The NodeNum of the recipient. + * @param last_request_index The index in the packet history of the last request from this node. * @return The ID of the newly created history queue. */ -uint32_t StoreForwardModule::historyQueueCreate(uint32_t msAgo, uint32_t to) +uint32_t StoreForwardModule::historyQueueCreate(uint32_t msAgo, uint32_t to, uint32_t *last_request_index) { this->packetHistoryTXQueue_size = 0; + // If our history was cleared, ignore the last request index + uint32_t last_index = *last_request_index > this->packetHistoryCurrent ? 0 : *last_request_index; - for (int i = 0; i < this->packetHistoryCurrent; i++) { + for (uint32_t i = last_index; i < this->packetHistoryCurrent; i++) { /* LOG_DEBUG("SF historyQueueCreate\n"); LOG_DEBUG("SF historyQueueCreate - time %d\n", this->packetHistory[i].time); @@ -141,16 +142,11 @@ uint32_t StoreForwardModule::historyQueueCreate(uint32_t msAgo, uint32_t to) LOG_DEBUG("SF historyQueueCreate - math %d\n", (millis() - msAgo)); */ if (this->packetHistory[i].time && (this->packetHistory[i].time < (millis() - msAgo))) { - LOG_DEBUG("*** SF historyQueueCreate - Time matches - ok\n"); - /* - Copy the messages that were received by the router in the last msAgo + /* Copy the messages that were received by the router in the last msAgo to the packetHistoryTXQueue structure. - - TODO: The condition (this->packetHistory[i].to & NODENUM_BROADCAST) == to) is not tested since - I don't have an easy way to target a specific user. Will need to do this soon. - */ - if ((this->packetHistory[i].to & NODENUM_BROADCAST) == NODENUM_BROADCAST || - ((this->packetHistory[i].to & NODENUM_BROADCAST) == to)) { + Client not interested in packets from itself and only in broadcast packets or packets towards it. */ + if (this->packetHistory[i].from != to && + (this->packetHistory[i].to == NODENUM_BROADCAST || this->packetHistory[i].to == to)) { this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].time = this->packetHistory[i].time; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].to = this->packetHistory[i].to; this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].from = this->packetHistory[i].from; @@ -159,9 +155,10 @@ uint32_t StoreForwardModule::historyQueueCreate(uint32_t msAgo, uint32_t to) memcpy(this->packetHistoryTXQueue[this->packetHistoryTXQueue_size].payload, this->packetHistory[i].payload, meshtastic_Constants_DATA_PAYLOAD_LEN); this->packetHistoryTXQueue_size++; + *last_request_index = i + 1; // Set to one higher such that we don't send the same message again - LOG_DEBUG("*** PacketHistoryStruct time=%d\n", this->packetHistory[i].time); - LOG_DEBUG("*** PacketHistoryStruct msg=%s\n", this->packetHistory[i].payload); + LOG_DEBUG("*** PacketHistoryStruct time=%d, msg=%s\n", this->packetHistory[i].time, + this->packetHistory[i].payload); } } } @@ -177,15 +174,20 @@ void StoreForwardModule::historyAdd(const meshtastic_MeshPacket &mp) { const auto &p = mp.decoded; - this->packetHistory[this->packetHistoryCurrent].time = millis(); - this->packetHistory[this->packetHistoryCurrent].to = mp.to; - this->packetHistory[this->packetHistoryCurrent].channel = mp.channel; - this->packetHistory[this->packetHistoryCurrent].from = mp.from; - this->packetHistory[this->packetHistoryCurrent].payload_size = p.payload.size; - memcpy(this->packetHistory[this->packetHistoryCurrent].payload, p.payload.bytes, meshtastic_Constants_DATA_PAYLOAD_LEN); + if (this->packetHistoryCurrent < this->records) { + this->packetHistory[this->packetHistoryCurrent].time = millis(); + this->packetHistory[this->packetHistoryCurrent].to = mp.to; + this->packetHistory[this->packetHistoryCurrent].channel = mp.channel; + this->packetHistory[this->packetHistoryCurrent].from = mp.from; + this->packetHistory[this->packetHistoryCurrent].payload_size = p.payload.size; + memcpy(this->packetHistory[this->packetHistoryCurrent].payload, p.payload.bytes, meshtastic_Constants_DATA_PAYLOAD_LEN); - this->packetHistoryCurrent++; - this->packetHistoryMax++; + this->packetHistoryCurrent++; + this->packetHistoryMax++; + } else { + // TODO: Overwrite the oldest message in the history buffer when it is full. + LOG_WARN("*** S&F - PSRAM Full. Packet is not added to the history.\n"); + } } meshtastic_MeshPacket *StoreForwardModule::allocReply() @@ -213,10 +215,19 @@ void StoreForwardModule::sendPayload(NodeNum dest, uint32_t packetHistory_index) // TODO: Make this configurable. p->want_ack = false; - p->decoded.payload.size = - this->packetHistoryTXQueue[packetHistory_index].payload_size; // You must specify how many bytes are in the reply - memcpy(p->decoded.payload.bytes, this->packetHistoryTXQueue[packetHistory_index].payload, + meshtastic_StoreAndForward sf = meshtastic_StoreAndForward_init_zero; + sf.which_variant = meshtastic_StoreAndForward_text_tag; + sf.variant.text.size = this->packetHistoryTXQueue[packetHistory_index].payload_size; + memcpy(sf.variant.text.bytes, this->packetHistoryTXQueue[packetHistory_index].payload, this->packetHistoryTXQueue[packetHistory_index].payload_size); + if (this->packetHistoryTXQueue[packetHistory_index].to == NODENUM_BROADCAST) { + sf.rr = meshtastic_StoreAndForward_RequestResponse_ROUTER_TEXT_BROADCAST; + } else { + sf.rr = meshtastic_StoreAndForward_RequestResponse_ROUTER_TEXT_DIRECT; + } + + p->decoded.payload.size = + pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &meshtastic_StoreAndForward_msg, &sf); service.sendToMesh(p); } @@ -387,7 +398,8 @@ bool StoreForwardModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, LOG_INFO("*** S&F - Busy. Try again shortly.\n"); } else { if ((p->which_variant == meshtastic_StoreAndForward_history_tag) && (p->variant.history.window > 0)) { - storeForwardModule->historySend(p->variant.history.window * 60000, getFrom(&mp)); // window is in minutes + // window is in minutes + storeForwardModule->historySend(p->variant.history.window * 60000, getFrom(&mp)); } else { storeForwardModule->historySend(historyReturnWindow * 60000, getFrom(&mp)); // defaults to 4 hours } @@ -406,8 +418,7 @@ bool StoreForwardModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, case meshtastic_StoreAndForward_RequestResponse_CLIENT_PONG: if (is_server) { LOG_INFO("*** StoreAndForward_RequestResponse_CLIENT_PONG\n"); - // The Client is alive, update NodeDB - nodeDB.updateFrom(mp); + // NodeDB is already updated } break; @@ -546,9 +557,7 @@ StoreForwardModule::StoreForwardModule() } // Client - } - if ((config.device.role == meshtastic_Config_DeviceConfig_Role_CLIENT) || - (config.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER_CLIENT)) { + } else { is_client = true; LOG_INFO("*** Initializing Store & Forward Module in Client mode\n"); } diff --git a/src/modules/esp32/StoreForwardModule.h b/src/modules/esp32/StoreForwardModule.h index 806f0a8361..cfa9945d56 100644 --- a/src/modules/esp32/StoreForwardModule.h +++ b/src/modules/esp32/StoreForwardModule.h @@ -7,13 +7,13 @@ #include "configuration.h" #include #include +#include struct PacketHistoryStruct { uint32_t time; uint32_t to; uint32_t from; uint8_t channel; - bool ack; uint8_t payload[meshtastic_Constants_DATA_PAYLOAD_LEN]; pb_size_t payload_size; }; @@ -32,16 +32,19 @@ class StoreForwardModule : private concurrency::OSThread, public ProtobufModule< uint32_t packetHistoryTXQueue_size = 0; uint32_t packetHistoryTXQueue_index = 0; - uint32_t packetTimeMax = 5000; + uint32_t packetTimeMax = 5000; // Interval between sending history packets as a server. bool is_client = false; bool is_server = false; + // Unordered_map stores the last request for each nodeNum (`to` field) + std::unordered_map lastRequest; + public: StoreForwardModule(); unsigned long lastHeartbeat = 0; - uint32_t heartbeatInterval = 300; + uint32_t heartbeatInterval = default_broadcast_interval_secs; /** Update our local reference of when we last saw that node. @@ -51,7 +54,7 @@ class StoreForwardModule : private concurrency::OSThread, public ProtobufModule< void statsSend(uint32_t to); void historySend(uint32_t msAgo, uint32_t to); - uint32_t historyQueueCreate(uint32_t msAgo, uint32_t to); + uint32_t historyQueueCreate(uint32_t msAgo, uint32_t to, uint32_t *last_request_index); /** * Send our payload into the mesh @@ -79,16 +82,16 @@ class StoreForwardModule : private concurrency::OSThread, public ProtobufModule< void populatePSRAM(); // S&F Defaults - uint32_t historyReturnMax = 250; // 250 records - uint32_t historyReturnWindow = 240; // 4 hours + uint32_t historyReturnMax = 25; // Return maximum of 25 records by default. + uint32_t historyReturnWindow = 240; // Return history of last 4 hours by default. uint32_t records = 0; // Calculated bool heartbeat = false; // No heartbeat. // stats - uint32_t requests = 0; - uint32_t requests_history = 0; + uint32_t requests = 0; // Number of times any client sent a request to the S&F. + uint32_t requests_history = 0; // Number of times the history was requested. - uint32_t retry_delay = 0; + uint32_t retry_delay = 0; // If server is busy, retry after this delay (in ms). protected: virtual int32_t runOnce() override; @@ -102,4 +105,4 @@ class StoreForwardModule : private concurrency::OSThread, public ProtobufModule< virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_StoreAndForward *p); }; -extern StoreForwardModule *storeForwardModule; +extern StoreForwardModule *storeForwardModule; \ No newline at end of file diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index a97aa52552..8c241a3028 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -7,12 +7,16 @@ #include "mesh/Router.h" #include "mesh/generated/meshtastic/mqtt.pb.h" #include "mesh/generated/meshtastic/telemetry.pb.h" +#include "modules/RoutingModule.h" +#if defined(ARCH_ESP32) +#include "../mesh/generated/meshtastic/paxcount.pb.h" +#endif +#include "mesh/generated/meshtastic/remote_hardware.pb.h" #include "sleep.h" #if HAS_WIFI #include "mesh/wifi/WiFiAPClient.h" #include #endif -#include "mqtt/JSON.h" #include const int reconnectMax = 5; @@ -44,34 +48,32 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length) payloadStr[length] = 0; // null terminated string JSONValue *json_value = JSON::Parse(payloadStr); if (json_value != NULL) { - LOG_INFO("JSON Received on MQTT, parsing..\n"); - // check if it is a valid envelope JSONObject json; json = json_value->AsObject(); - // parse the channel name from the topic string - char *ptr = strtok(topic, "/"); - for (int i = 0; i < 3; i++) { - ptr = strtok(NULL, "/"); - } + // parse the channel name from the topic string by looking for "json/" + const char *jsonSlash = "json/"; + char *ptr = strstr(topic, jsonSlash) + sizeof(jsonSlash) + 1; // set pointer to after "json/" + ptr = strtok(ptr, "/") ? strtok(ptr, "/") : ptr; // if another "/" was added, parse string up to that character meshtastic_Channel sendChannel = channels.getByName(ptr); - LOG_DEBUG("Found Channel name: %s (Index %d)\n", channels.getGlobalId(sendChannel.index), sendChannel.index); - - if ((json.find("sender") != json.end()) && (json.find("payload") != json.end()) && - (json.find("type") != json.end()) && json["type"]->IsString() && - (json["type"]->AsString().compare("sendtext") == 0)) { - // this is a valid envelope - if (json["payload"]->IsString() && json["type"]->IsString() && - (json["sender"]->AsString().compare(owner.id) != 0)) { - std::string jsonPayloadStr = json["payload"]->AsString(); - LOG_INFO("JSON payload %s, length %u\n", jsonPayloadStr.c_str(), jsonPayloadStr.length()); - - // construct protobuf data packet using TEXT_MESSAGE, send it to the mesh - meshtastic_MeshPacket *p = router->allocForSending(); - p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP; - p->channel = sendChannel.index; - if (sendChannel.settings.downlink_enabled) { + // We allow downlink JSON packets only on a channel named "mqtt" + if (strncasecmp(channels.getGlobalId(sendChannel.index), Channels::mqttChannel, strlen(Channels::mqttChannel)) == 0 && + sendChannel.settings.downlink_enabled) { + if (isValidJsonEnvelope(json)) { + // this is a valid envelope + if (json["type"]->AsString().compare("sendtext") == 0 && json["payload"]->IsString()) { + std::string jsonPayloadStr = json["payload"]->AsString(); + LOG_INFO("JSON payload %s, length %u\n", jsonPayloadStr.c_str(), jsonPayloadStr.length()); + + // construct protobuf data packet using TEXT_MESSAGE, send it to the mesh + meshtastic_MeshPacket *p = router->allocForSending(); + p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP; + if (json.find("channel") != json.end() && json["channel"]->IsNumber() && + (json["channel"]->AsNumber() < channels.getNumChannels())) + p->channel = json["channel"]->AsNumber(); + if (json.find("to") != json.end() && json["to"]->IsNumber()) + p->to = json["to"]->AsNumber(); if (jsonPayloadStr.length() <= sizeof(p->decoded.payload.bytes)) { memcpy(p->decoded.payload.bytes, jsonPayloadStr.c_str(), jsonPayloadStr.length()); p->decoded.payload.size = jsonPayloadStr.length(); @@ -80,71 +82,76 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length) } else { LOG_WARN("Received MQTT json payload too long, dropping\n"); } - } else { - LOG_WARN("Received MQTT json payload on channel %s, but downlink is disabled, dropping\n", - sendChannel.settings.name); - } - } else { - LOG_DEBUG("JSON Ignoring downlink message we originally sent.\n"); - } - } else if ((json.find("sender") != json.end()) && (json.find("payload") != json.end()) && - (json.find("type") != json.end()) && json["type"]->IsString() && - (json["type"]->AsString().compare("sendposition") == 0)) { - // invent the "sendposition" type for a valid envelope - if (json["payload"]->IsObject() && json["type"]->IsString() && - (json["sender"]->AsString().compare(owner.id) != 0)) { - JSONObject posit; - posit = json["payload"]->AsObject(); // get nested JSON Position - meshtastic_Position pos = meshtastic_Position_init_default; - pos.latitude_i = posit["latitude_i"]->AsNumber(); - pos.longitude_i = posit["longitude_i"]->AsNumber(); - pos.altitude = posit["altitude"]->AsNumber(); - pos.time = posit["time"]->AsNumber(); - - // construct protobuf data packet using POSITION, send it to the mesh - meshtastic_MeshPacket *p = router->allocForSending(); - p->decoded.portnum = meshtastic_PortNum_POSITION_APP; - p->channel = sendChannel.index; - if (sendChannel.settings.downlink_enabled) { + } else if (json["type"]->AsString().compare("sendposition") == 0 && json["payload"]->IsObject()) { + // invent the "sendposition" type for a valid envelope + JSONObject posit; + posit = json["payload"]->AsObject(); // get nested JSON Position + meshtastic_Position pos = meshtastic_Position_init_default; + if (posit.find("latitude_i") != posit.end() && posit["latitude_i"]->IsNumber()) + pos.latitude_i = posit["latitude_i"]->AsNumber(); + if (posit.find("longitude_i") != posit.end() && posit["longitude_i"]->IsNumber()) + pos.longitude_i = posit["longitude_i"]->AsNumber(); + if (posit.find("altitude") != posit.end() && posit["altitude"]->IsNumber()) + pos.altitude = posit["altitude"]->AsNumber(); + if (posit.find("time") != posit.end() && posit["time"]->IsNumber()) + pos.time = posit["time"]->AsNumber(); + + // construct protobuf data packet using POSITION, send it to the mesh + meshtastic_MeshPacket *p = router->allocForSending(); + p->decoded.portnum = meshtastic_PortNum_POSITION_APP; + if (json.find("channel") != json.end() && json["channel"]->IsNumber() && + (json["channel"]->AsNumber() < channels.getNumChannels())) + p->channel = json["channel"]->AsNumber(); + if (json.find("to") != json.end() && json["to"]->IsNumber()) + p->to = json["to"]->AsNumber(); p->decoded.payload.size = pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &meshtastic_Position_msg, &pos); // make the Data protobuf from position service.sendToMesh(p, RX_SRC_LOCAL); } else { - LOG_WARN("Received MQTT json payload on channel %s, but downlink is disabled, dropping\n", - sendChannel.settings.name); + LOG_DEBUG("JSON Ignoring downlink message with unsupported type.\n"); } } else { - LOG_DEBUG("JSON Ignoring downlink message we originally sent.\n"); + LOG_ERROR("JSON Received payload on MQTT but not a valid envelope.\n"); } } else { - LOG_ERROR("JSON Received payload on MQTT but not a valid envelope\n"); + LOG_WARN("JSON downlink received on channel not called 'mqtt' or without downlink enabled.\n"); } } else { // no json, this is an invalid payload - LOG_ERROR("Invalid MQTT service envelope, topic %s, len %u!\n", topic, length); + LOG_ERROR("JSON Received payload on MQTT but not a valid JSON\n"); } delete json_value; } else { - if (!pb_decode_from_bytes(payload, length, &meshtastic_ServiceEnvelope_msg, &e)) { + if (length == 0) { + LOG_WARN("Empty MQTT payload received, topic %s!\n", topic); + return; + } else if (!pb_decode_from_bytes(payload, length, &meshtastic_ServiceEnvelope_msg, &e)) { LOG_ERROR("Invalid MQTT service envelope, topic %s, len %u!\n", topic, length); return; } else { - if (strcmp(e.gateway_id, owner.id) == 0) - LOG_INFO("Ignoring downlink message we originally sent.\n"); - else { + meshtastic_Channel ch = channels.getByName(e.channel_id); + if (strcmp(e.gateway_id, owner.id) == 0) { + // Generate an implicit ACK towards ourselves (handled and processed only locally!) for this message. + // We do this because packets are not rebroadcasted back into MQTT anymore and we assume that at least one node + // receives it when we get our own packet back. Then we'll stop our retransmissions. + if (e.packet && getFrom(e.packet) == nodeDB.getNodeNum()) + routingModule->sendAckNak(meshtastic_Routing_Error_NONE, getFrom(e.packet), e.packet->id, ch.index); + else + LOG_INFO("Ignoring downlink message we originally sent.\n"); + } else { // Find channel by channel_id and check downlink_enabled - meshtastic_Channel ch = channels.getByName(e.channel_id); if (strcmp(e.channel_id, channels.getGlobalId(ch.index)) == 0 && e.packet && ch.settings.downlink_enabled) { LOG_INFO("Received MQTT topic %s, len=%u\n", topic, length); meshtastic_MeshPacket *p = packetPool.allocCopy(*e.packet); + p->via_mqtt = true; // Mark that the packet was received via MQTT if (p->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { p->channel = ch.index; } - // ignore messages sent by us or if we don't have the channel key - if (router && p->from != nodeDB.getNodeNum() && perhapsDecode(p)) + // ignore messages if we don't have the channel key + if (router && perhapsDecode(p)) router->enqueueReceivedMessage(p); else packetPool.release(p); @@ -457,8 +464,11 @@ void MQTT::publishQueuedMessages() } } -void MQTT::onSend(const meshtastic_MeshPacket &mp, ChannelIndex chIndex) +void MQTT::onSend(const meshtastic_MeshPacket &mp, const meshtastic_MeshPacket &mp_decoded, ChannelIndex chIndex) { + if (mp.via_mqtt) + return; // Don't send messages that came from MQTT back into MQTT + auto &ch = channels.getByIndex(chIndex); if (&mp.decoded && strcmp(moduleConfig.mqtt.address, default_mqtt_address) == 0 && @@ -474,8 +484,15 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp, ChannelIndex chIndex) meshtastic_ServiceEnvelope *env = mqttPool.allocZeroed(); env->channel_id = (char *)channelId; env->gateway_id = owner.id; - env->packet = (meshtastic_MeshPacket *)∓ - LOG_DEBUG("MQTT onSend - Publishing portnum %i message\n", env->packet->decoded.portnum); + + LOG_DEBUG("MQTT onSend - Publishing "); + if (moduleConfig.mqtt.encryption_enabled) { + env->packet = (meshtastic_MeshPacket *)∓ + LOG_DEBUG("encrypted message\n"); + } else { + env->packet = (meshtastic_MeshPacket *)&mp_decoded; + LOG_DEBUG("portnum %i message\n", env->packet->decoded.portnum); + } if (moduleConfig.mqtt.proxy_to_client_enabled || this->isConnectedDirectly()) { // FIXME - this size calculation is super sloppy, but it will go away once we dynamically alloc meshpackets @@ -489,7 +506,7 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp, ChannelIndex chIndex) if (moduleConfig.mqtt.json_enabled) { // handle json topic - auto jsonString = this->meshPacketToJson((meshtastic_MeshPacket *)&mp); + auto jsonString = this->meshPacketToJson((meshtastic_MeshPacket *)&mp_decoded); if (jsonString.length() != 0) { std::string topicJson = jsonTopic + channelId + "/" + owner.id; LOG_INFO("JSON publish message to %s, %u bytes: %s\n", topicJson.c_str(), jsonString.length(), @@ -497,6 +514,7 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp, ChannelIndex chIndex) publish(topicJson.c_str(), jsonString.c_str(), false); } } + } else { LOG_INFO("MQTT not connected, queueing packet\n"); if (mqttQueue.numFree() == 0) { @@ -519,10 +537,10 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp) // the created jsonObj is immutable after creation, so // we need to do the heavy lifting before assembling it. std::string msgType; - JSONObject msgPayload; JSONObject jsonObj; if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag) { + JSONObject msgPayload; switch (mp->decoded.portnum) { case meshtastic_PortNum_TEXT_MESSAGE_APP: { msgType = "text"; @@ -684,6 +702,88 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp) } break; } + case meshtastic_PortNum_TRACEROUTE_APP: { + if (mp->decoded.request_id) { // Only report the traceroute response + msgType = "traceroute"; + meshtastic_RouteDiscovery scratch; + meshtastic_RouteDiscovery *decoded = NULL; + memset(&scratch, 0, sizeof(scratch)); + if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_RouteDiscovery_msg, + &scratch)) { + decoded = &scratch; + JSONArray route; // Route this message took + // Lambda function for adding a long name to the route + auto addToRoute = [](JSONArray *route, NodeNum num) { + char long_name[40] = "Unknown"; + meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(num); + bool name_known = node ? node->has_user : false; + if (name_known) + memcpy(long_name, node->user.long_name, sizeof(long_name)); + route->push_back(new JSONValue(long_name)); + }; + addToRoute(&route, mp->to); // Started at the original transmitter (destination of response) + for (uint8_t i = 0; i < decoded->route_count; i++) { + addToRoute(&route, decoded->route[i]); + } + addToRoute(&route, mp->from); // Ended at the original destination (source of response) + + msgPayload["route"] = new JSONValue(route); + jsonObj["payload"] = new JSONValue(msgPayload); + } else { + LOG_ERROR("Error decoding protobuf for traceroute message!\n"); + } + } + break; + } + case meshtastic_PortNum_DETECTION_SENSOR_APP: { + msgType = "detection"; + char payloadStr[(mp->decoded.payload.size) + 1]; + memcpy(payloadStr, mp->decoded.payload.bytes, mp->decoded.payload.size); + payloadStr[mp->decoded.payload.size] = 0; // null terminated string + msgPayload["text"] = new JSONValue(payloadStr); + jsonObj["payload"] = new JSONValue(msgPayload); + break; + } +#ifdef ARCH_ESP32 + case meshtastic_PortNum_PAXCOUNTER_APP: { + msgType = "paxcounter"; + meshtastic_Paxcount scratch; + meshtastic_Paxcount *decoded = NULL; + memset(&scratch, 0, sizeof(scratch)); + if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_Paxcount_msg, &scratch)) { + decoded = &scratch; + msgPayload["wifi_count"] = new JSONValue((uint)decoded->wifi); + msgPayload["ble_count"] = new JSONValue((uint)decoded->ble); + msgPayload["uptime"] = new JSONValue((uint)decoded->uptime); + jsonObj["payload"] = new JSONValue(msgPayload); + } else { + LOG_ERROR("Error decoding protobuf for Paxcount message!\n"); + } + break; + } +#endif + case meshtastic_PortNum_REMOTE_HARDWARE_APP: { + meshtastic_HardwareMessage scratch; + meshtastic_HardwareMessage *decoded = NULL; + memset(&scratch, 0, sizeof(scratch)); + if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &meshtastic_HardwareMessage_msg, + &scratch)) { + decoded = &scratch; + if (decoded->type == meshtastic_HardwareMessage_Type_GPIOS_CHANGED) { + msgType = "gpios_changed"; + msgPayload["gpio_value"] = new JSONValue((uint)decoded->gpio_value); + jsonObj["payload"] = new JSONValue(msgPayload); + } else if (decoded->type == meshtastic_HardwareMessage_Type_READ_GPIOS_REPLY) { + msgType = "gpios_read_reply"; + msgPayload["gpio_value"] = new JSONValue((uint)decoded->gpio_value); + msgPayload["gpio_mask"] = new JSONValue((uint)decoded->gpio_mask); + jsonObj["payload"] = new JSONValue(msgPayload); + } + } else { + LOG_ERROR("Error decoding protobuf for RemoteHardware message!\n"); + } + break; + } // add more packet types here if needed default: break; @@ -712,4 +812,14 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp) delete value; return jsonStr; +} + +bool MQTT::isValidJsonEnvelope(JSONObject &json) +{ + // if "sender" is provided, avoid processing packets we uplinked + return (json.find("sender") != json.end() ? (json["sender"]->AsString().compare(owner.id) != 0) : true) && + (json.find("from") != json.end()) && json["from"]->IsNumber() && + (json["from"]->AsNumber() == nodeDB.getNodeNum()) && // only accept message if the "from" is us + (json.find("type") != json.end()) && json["type"]->IsString() && // should specify a type + (json.find("payload") != json.end()); // should have a payload } \ No newline at end of file diff --git a/src/mqtt/MQTT.h b/src/mqtt/MQTT.h index 565f46ecfc..2b803e3fcd 100644 --- a/src/mqtt/MQTT.h +++ b/src/mqtt/MQTT.h @@ -5,6 +5,7 @@ #include "concurrency/OSThread.h" #include "mesh/Channels.h" #include "mesh/generated/meshtastic/mqtt.pb.h" +#include "mqtt/JSON.h" #if HAS_WIFI #include #define HAS_NETWORKING 1 @@ -48,14 +49,15 @@ class MQTT : private concurrency::OSThread MQTT(); /** - * Publish a packet on the glboal MQTT server. - * This hook must be called **after** the packet is encrypted (including the channel being changed to a hash). + * Publish a packet on the global MQTT server. + * @param mp the encrypted packet to publish + * @param mp_decoded the decrypted packet to publish * @param chIndex the index of the channel for this message * * Note: for messages we are forwarding on the mesh that we can't find the channel for (because we don't have the keys), we * can not forward those messages to the cloud - because no way to find a global channel ID. */ - void onSend(const meshtastic_MeshPacket &mp, ChannelIndex chIndex); + void onSend(const meshtastic_MeshPacket &mp, const meshtastic_MeshPacket &mp_decoded, ChannelIndex chIndex); /** Attempt to connect to server if necessary */ @@ -100,6 +102,9 @@ class MQTT : private concurrency::OSThread void publishStatus(); void publishQueuedMessages(); + // returns true if this is a valid JSON envelope which we accept on downlink + bool isValidJsonEnvelope(JSONObject &json); + /// Return 0 if sleep is okay, veto sleep if we are connected to pubsub server // int preflightSleepCb(void *unused = NULL) { return pubSub.connected() ? 1 : 0; } }; diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index 451d7ffbe5..7fab475f35 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -106,7 +106,13 @@ #elif defined(HELTEC_WSL_V3) #define HW_VENDOR meshtastic_HardwareModel_HELTEC_WSL_V3 #elif defined(HELTEC_WIRELESS_TRACKER) +#ifdef HELTEC_TRACKER_V1_0 +#define HW_VENDOR meshtastic_HardwareModel_HELTEC_WIRELESS_TRACKER_V1_0 +#else #define HW_VENDOR meshtastic_HardwareModel_HELTEC_WIRELESS_TRACKER +#endif +#elif defined(HELTEC_WIRELESS_PAPER_V1_0) +#define HW_VENDOR meshtastic_HardwareModel_HELTEC_WIRELESS_PAPER_V1_0 #elif defined(HELTEC_WIRELESS_PAPER) #define HW_VENDOR meshtastic_HardwareModel_HELTEC_WIRELESS_PAPER #elif defined(TLORA_T3S3_V1) @@ -119,12 +125,14 @@ #define HW_VENDOR meshtastic_HardwareModel_BETAFPV_900_NANO_TX #elif defined(PICOMPUTER_S3) #define HW_VENDOR meshtastic_HardwareModel_PICOMPUTER_S3 -#elif defined(HELTEC_HT62) -#define HW_VENDOR meshtastic_HardwareModel_HELTEC_HT62 +#elif defined(ESP32_S3_PICO) +#define HW_VENDOR meshtastic_HardwareModel_ESP32_S3_PICO #elif defined(SENSELORA_S3) #define HW_VENDOR meshtastic_HardwareModel_SENSELORA_S3 #elif defined(HELTEC_HT62) #define HW_VENDOR meshtastic_HardwareModel_HELTEC_HT62 +#elif defined(CHATTER_2) +#define HW_VENDOR meshtastic_HardwareModel_CHATTER_2 #endif // ----------------------------------------------------------------------------- @@ -147,4 +155,4 @@ #define LORA_CS 18 #endif -#define SERIAL0_RX_GPIO 3 // Always GPIO3 on ESP32 // FIXME: may be different on ESP32-S3, etc. \ No newline at end of file +#define SERIAL0_RX_GPIO 3 // Always GPIO3 on ESP32 // FIXME: may be different on ESP32-S3, etc. diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index 7da41512e6..c994eea48a 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -175,7 +175,8 @@ void cpuDeepSleep(uint32_t msecToWake) some current will flow through these external and internal resistors, increasing deep sleep current above the minimal possible value. - Note: we don't isolate pins that are used for the LORA, LED, i2c, spi or the wake button + Note: we don't isolate pins that are used for the LORA, LED, i2c, or ST7735 Display for the Chatter2, spi or the wake + button(s), maybe we should not include any other GPIOs... */ #if SOC_RTCIO_HOLD_SUPPORTED static const uint8_t rtcGpios[] = {/* 0, */ 2, @@ -184,9 +185,9 @@ void cpuDeepSleep(uint32_t msecToWake) 13, /* 14, */ /* 15, */ #endif - /* 25, */ 26, /* 27, */ - 32, 33, 34, 35, - 36, 37 + /* 25, */ /* 26, */ /* 27, */ + /* 32, */ /* 33, */ 34, 35, + /* 36, */ 37 /* 38, 39 */}; for (int i = 0; i < sizeof(rtcGpios); i++) diff --git a/src/platform/nrf52/architecture.h b/src/platform/nrf52/architecture.h index e6eebc45b9..35cd4fd84b 100644 --- a/src/platform/nrf52/architecture.h +++ b/src/platform/nrf52/architecture.h @@ -48,6 +48,8 @@ #define HW_VENDOR meshtastic_HardwareModel_T_ECHO #elif defined(NANO_G2_ULTRA) #define HW_VENDOR meshtastic_HardwareModel_NANO_G2_ULTRA +#elif defined(CANARYONE) +#define HW_VENDOR meshtastic_HardwareModel_CANARYONE #elif defined(NORDIC_PCA10059) #define HW_VENDOR meshtastic_HardwareModel_NRF52840_PCA10059 #elif defined(PRIVATE_HW) || defined(FEATHER_DIY) diff --git a/src/platform/nrf52/main-nrf52.cpp b/src/platform/nrf52/main-nrf52.cpp index 65b45f1e93..63b014c461 100644 --- a/src/platform/nrf52/main-nrf52.cpp +++ b/src/platform/nrf52/main-nrf52.cpp @@ -1,4 +1,5 @@ #include "configuration.h" +#include #include #include #include @@ -51,7 +52,7 @@ void getMacAddr(uint8_t *dmac) static void initBrownout() { - auto vccthresh = POWER_POFCON_THRESHOLD_V17; + auto vccthresh = POWER_POFCON_THRESHOLD_V24; auto err_code = sd_power_pof_enable(POWER_POFCON_POF_Enabled); assert(err_code == NRF_SUCCESS); @@ -184,6 +185,7 @@ void cpuDeepSleep(uint32_t msecToWake) // Don't enter this if we're sleeping portMAX_DELAY, since that's a shutdown event if (msecToWake != portMAX_DELAY && (config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER || + config.device.role == meshtastic_Config_DeviceConfig_Role_TAK_TRACKER || config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR) && config.power.is_power_saving == true) { sd_power_mode_set(NRF_POWER_MODE_LOWPWR); @@ -214,4 +216,9 @@ void clearBonds() nrf52Bluetooth->setup(); } nrf52Bluetooth->clearBonds(); +} + +void enterDfuMode() +{ + enterUf2Dfu(); } \ No newline at end of file diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index 06e18eb911..c8fcc3d13d 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -8,20 +8,16 @@ #include #include -#ifdef ARCH_RASPBERRY_PI #include "PortduinoGlue.h" #include "linux/gpio/LinuxGPIOPin.h" -#include "pigpio.h" #include "yaml-cpp/yaml.h" #include #include #include -std::map settingsMap; - -#else -#include -#endif +std::map settingsMap; +std::map settingsStrings; +char *configPath = nullptr; // FIXME - move setBluetoothEnable into a HALPlatform class void setBluetoothEnable(bool on) @@ -35,34 +31,7 @@ void cpuDeepSleep(uint32_t msecs) } void updateBatteryLevel(uint8_t level) NOT_IMPLEMENTED("updateBatteryLevel"); -#ifndef ARCH_RASPBERRY_PI -/** a simulated pin for busted IRQ hardware - * Porduino helper class to do this i2c based polling: - */ -class PolledIrqPin : public GPIOPin -{ - public: - PolledIrqPin() : GPIOPin(LORA_DIO1, "loraIRQ") {} - - /// Read the low level hardware for this pin - virtual PinStatus readPinHardware() - { - if (isrPinStatus < 0) - return LOW; // No interrupt handler attached, don't bother polling i2c right now - else { - extern RadioInterface *rIf; // FIXME, temporary hack until we know if we need to keep this - - assert(rIf); - RadioLibInterface *rIf95 = static_cast(rIf); - bool p = rIf95->isIRQPending(); - log(SysGPIO, LogDebug, "PolledIrqPin::readPinHardware(%s, %d, %d)", getName(), getPinNum(), p); - return p ? HIGH : LOW; - } - } -}; -static GPIOPin *loraIrq; -#endif int TCPPort = 4403; static error_t parse_opt(int key, char *arg, struct argp_state *state) @@ -72,7 +41,10 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) if (sscanf(arg, "%d", &TCPPort) < 1) return ARGP_ERR_UNKNOWN; else - printf("Using TCP port %d\n", TCPPort); + printf("Using config file %d\n", TCPPort); + break; + case 'c': + configPath = arg; break; case ARGP_KEY_ARG: return 0; @@ -84,7 +56,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) void portduinoCustomInit() { - static struct argp_option options[] = {{"port", 'p', "PORT", 0, "The TCP port to use."}, {0}}; + 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."}, + {0}}; static void *childArguments; static char doc[] = "Meshtastic native build."; static char args_doc[] = "..."; @@ -100,14 +74,22 @@ void portduinoCustomInit() void portduinoSetup() { printf("Setting up Meshtastic on Portduino...\n"); - -#ifdef ARCH_RASPBERRY_PI gpioInit(); std::string gpioChipName = "gpiochip"; + YAML::Node yamlConfig; - if (access("config.yaml", R_OK) == 0) { + if (configPath != nullptr) { + std::cout << "Using " << configPath << " as config file" << std::endl; + try { + yamlConfig = YAML::LoadFile(configPath); + } catch (YAML::Exception e) { + std::cout << "Could not open " << configPath << " because of error: " << e.what() << std::endl; + exit(EXIT_FAILURE); + } + } else if (access("config.yaml", R_OK) == 0) { + std::cout << "Using local config.yaml as config file" << std::endl; try { yamlConfig = YAML::LoadFile("config.yaml"); } catch (YAML::Exception e) { @@ -115,6 +97,7 @@ void portduinoSetup() exit(EXIT_FAILURE); } } else if (access("/etc/meshtasticd/config.yaml", R_OK) == 0) { + std::cout << "Using /etc/meshtasticd/config.yaml as config file" << std::endl; try { yamlConfig = YAML::LoadFile("/etc/meshtasticd/config.yaml"); } catch (YAML::Exception e) { @@ -122,27 +105,48 @@ void portduinoSetup() exit(EXIT_FAILURE); } } else { - std::cout << "No 'config.yaml' found, exiting." << std::endl; - exit(EXIT_FAILURE); + std::cout << "No 'config.yaml' found, running simulated." << std::endl; + // Set the random seed equal to TCPPort to have a different seed per instance + randomSeed(TCPPort); + return; } try { + if (yamlConfig["Logging"]) { + if (yamlConfig["Logging"]["LogLevel"].as("info") == "debug") { + settingsMap[logoutputlevel] = level_debug; + } else if (yamlConfig["Logging"]["LogLevel"].as("info") == "info") { + settingsMap[logoutputlevel] = level_info; + } else if (yamlConfig["Logging"]["LogLevel"].as("info") == "warn") { + settingsMap[logoutputlevel] = level_warn; + } else if (yamlConfig["Logging"]["LogLevel"].as("info") == "error") { + settingsMap[logoutputlevel] = level_error; + } + } if (yamlConfig["Lora"]) { settingsMap[use_sx1262] = false; settingsMap[use_rf95] = false; + settingsMap[use_sx1280] = false; if (yamlConfig["Lora"]["Module"] && yamlConfig["Lora"]["Module"].as("") == "sx1262") { settingsMap[use_sx1262] = true; } else if (yamlConfig["Lora"]["Module"] && yamlConfig["Lora"]["Module"].as("") == "RF95") { settingsMap[use_rf95] = true; + } else if (yamlConfig["Lora"]["Module"] && yamlConfig["Lora"]["Module"].as("") == "sx1280") { + settingsMap[use_sx1280] = true; } settingsMap[dio2_as_rf_switch] = yamlConfig["Lora"]["DIO2_AS_RF_SWITCH"].as(false); + settingsMap[dio3_tcxo_voltage] = yamlConfig["Lora"]["DIO3_TCXO_VOLTAGE"].as(false); settingsMap[cs] = yamlConfig["Lora"]["CS"].as(RADIOLIB_NC); settingsMap[irq] = yamlConfig["Lora"]["IRQ"].as(RADIOLIB_NC); settingsMap[busy] = yamlConfig["Lora"]["Busy"].as(RADIOLIB_NC); settingsMap[reset] = yamlConfig["Lora"]["Reset"].as(RADIOLIB_NC); + settingsMap[txen] = yamlConfig["Lora"]["TXen"].as(RADIOLIB_NC); + settingsMap[rxen] = yamlConfig["Lora"]["RXen"].as(RADIOLIB_NC); settingsMap[gpiochip] = yamlConfig["Lora"]["gpiochip"].as(0); gpioChipName += std::to_string(settingsMap[gpiochip]); + + settingsStrings[spidev] = "/dev/" + yamlConfig["Lora"]["spidev"].as("spidev0.0"); } if (yamlConfig["GPIO"]) { settingsMap[user] = yamlConfig["GPIO"]["User"].as(RADIOLIB_NC); @@ -154,15 +158,47 @@ void portduinoSetup() settingsMap[has_gps] = 1; } } + if (yamlConfig["I2C"]) { + settingsStrings[i2cdev] = yamlConfig["I2C"]["I2CDevice"].as(""); + } + settingsMap[displayPanel] = no_screen; + if (yamlConfig["Display"]) { + if (yamlConfig["Display"]["Panel"].as("") == "ST7789") + settingsMap[displayPanel] = st7789; + else if (yamlConfig["Display"]["Panel"].as("") == "ST7735") + settingsMap[displayPanel] = st7735; + else if (yamlConfig["Display"]["Panel"].as("") == "ST7735S") + settingsMap[displayPanel] = st7735s; + else if (yamlConfig["Display"]["Panel"].as("") == "ILI9341") + settingsMap[displayPanel] = ili9341; + settingsMap[displayHeight] = yamlConfig["Display"]["Height"].as(0); + settingsMap[displayWidth] = yamlConfig["Display"]["Width"].as(0); + settingsMap[displayDC] = yamlConfig["Display"]["DC"].as(-1); + settingsMap[displayCS] = yamlConfig["Display"]["CS"].as(-1); + settingsMap[displayBacklight] = yamlConfig["Display"]["Backlight"].as(-1); + settingsMap[displayReset] = yamlConfig["Display"]["Reset"].as(-1); + settingsMap[displayOffsetX] = yamlConfig["Display"]["OffsetX"].as(0); + settingsMap[displayOffsetY] = yamlConfig["Display"]["OffsetY"].as(0); + settingsMap[displayRotate] = yamlConfig["Display"]["Rotate"].as(false); + settingsMap[displayInvert] = yamlConfig["Display"]["Invert"].as(false); + } + settingsMap[touchscreenModule] = no_touchscreen; + if (yamlConfig["Touchscreen"]) { + if (yamlConfig["Touchscreen"]["Module"].as("") == "XPT2046") + settingsMap[touchscreenModule] = xpt2046; + else if (yamlConfig["Touchscreen"]["Module"].as("") == "STMPE610") + settingsMap[touchscreenModule] = stmpe610; + settingsMap[touchscreenCS] = yamlConfig["Touchscreen"]["CS"].as(-1); + settingsMap[touchscreenIRQ] = yamlConfig["Touchscreen"]["IRQ"].as(-1); + } + if (yamlConfig["Input"]) { + settingsStrings[keyboardDevice] = (yamlConfig["Input"]["KeyboardDevice"]).as(""); + } } catch (YAML::Exception e) { std::cout << "*** Exception " << e.what() << std::endl; exit(EXIT_FAILURE); } - if (access("/sys/kernel/debug/bluetooth/hci0/identity", R_OK) != 0) { - std::cout << "Cannot read Bluetooth MAC Address. Please run as root" << std::endl; - exit(EXIT_FAILURE); - } // Need to bind all the configured GPIO pins so they're not simulated if (settingsMap.count(cs) > 0 && settingsMap[cs] != RADIOLIB_NC) { @@ -190,57 +226,37 @@ void portduinoSetup() settingsMap[user] = RADIOLIB_NC; } } + if (settingsMap.count(rxen) > 0 && settingsMap[rxen] != RADIOLIB_NC) { + if (initGPIOPin(settingsMap[rxen], gpioChipName) != ERRNO_OK) { + settingsMap[rxen] = RADIOLIB_NC; + } + } + if (settingsMap.count(txen) > 0 && settingsMap[txen] != RADIOLIB_NC) { + if (initGPIOPin(settingsMap[txen], gpioChipName) != ERRNO_OK) { + settingsMap[txen] = RADIOLIB_NC; + } + } - return; -#endif - -#ifdef defined(PORTDUINO_LINUX_HARDWARE) - SPI.begin(); // We need to create SPI - bool usePineLora = !spiChip->isSimulated(); - if (usePineLora) { - printf("Connecting to PineLora board...\n"); - - // FIXME: remove this hack once interrupts are confirmed to work on new pine64 board - // loraIrq = new PolledIrqPin(); - loraIrq = new LinuxGPIOPin(LORA_DIO1, "ch341", "int", "loraIrq"); // or "err"? - loraIrq->setSilent(); - gpioBind(loraIrq); - - // BUSY hw was busted on current board - just use the simulated pin (which will read low) - auto busy = new LinuxGPIOPin(SX126X_BUSY, "ch341", "slct", "loraBusy"); - busy->setSilent(); - gpioBind(busy); - - gpioBind(new LinuxGPIOPin(SX126X_RESET, "ch341", "ini", "loraReset")); - - auto loraCs = new LinuxGPIOPin(SX126X_CS, "ch341", "cs0", "loraCs"); - loraCs->setSilent(); - gpioBind(loraCs); - } else -#endif -#ifndef ARCH_RASPBERRY_PI - { - // Set the random seed equal to TCPPort to have a different seed per instance - randomSeed(TCPPort); - - auto fakeBusy = new SimGPIOPin(SX126X_BUSY, "fakeBusy"); - fakeBusy->writePin(LOW); - fakeBusy->setSilent(true); - gpioBind(fakeBusy); - - auto cs = new SimGPIOPin(SX126X_CS, "fakeLoraCS"); - cs->setSilent(true); - gpioBind(cs); - - gpioBind(new SimGPIOPin(SX126X_RESET, "fakeLoraReset")); - gpioBind(new SimGPIOPin(LORA_DIO1, "fakeLoraIrq")); + if (settingsMap[displayPanel] != no_screen) { + if (settingsMap[displayCS] > 0) + initGPIOPin(settingsMap[displayCS], gpioChipName); + if (settingsMap[displayDC] > 0) + initGPIOPin(settingsMap[displayDC], gpioChipName); + if (settingsMap[displayBacklight] > 0) + initGPIOPin(settingsMap[displayBacklight], gpioChipName); + if (settingsMap[displayReset] > 0) + initGPIOPin(settingsMap[displayReset], gpioChipName); + } + if (settingsMap[touchscreenModule] != no_touchscreen) { + if (settingsMap[touchscreenCS] > 0) + initGPIOPin(settingsMap[touchscreenCS], gpioChipName); + if (settingsMap[touchscreenIRQ] > 0) + initGPIOPin(settingsMap[touchscreenIRQ], gpioChipName); } - // gpioBind((new SimGPIOPin(LORA_RESET, "LORA_RESET"))); - // gpioBind((new SimGPIOPin(LORA_CS, "LORA_CS"))->setSilent()); -#endif + + return; } -#ifdef ARCH_RASPBERRY_PI int initGPIOPin(int pinNum, std::string gpioChipName) { std::string gpio_name = "GPIO" + std::to_string(pinNum); @@ -250,9 +266,9 @@ int initGPIOPin(int pinNum, std::string gpioChipName) csPin->setSilent(); gpioBind(csPin); return ERRNO_OK; - } catch (std::invalid_argument &e) { - std::cout << "Warning, cannot claim pin" << gpio_name << std::endl; + } catch (...) { + std::exception_ptr p = std::current_exception(); + std::cout << "Warning, cannot claim pin " << gpio_name << (p ? p.__cxa_exception_type()->name() : "null") << std::endl; return ERRNO_DISABLED; } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h index b942ab46af..f8da20e37c 100644 --- a/src/platform/portduino/PortduinoGlue.h +++ b/src/platform/portduino/PortduinoGlue.h @@ -1,10 +1,44 @@ #pragma once -#ifdef ARCH_RASPBERRY_PI #include -extern std::map settingsMap; +enum configNames { + use_sx1262, + cs, + irq, + busy, + reset, + txen, + rxen, + dio2_as_rf_switch, + dio3_tcxo_voltage, + use_rf95, + use_sx1280, + user, + gpiochip, + spidev, + i2cdev, + has_gps, + touchscreenModule, + touchscreenCS, + touchscreenIRQ, + displayPanel, + displayWidth, + displayHeight, + displayCS, + displayDC, + displayBacklight, + displayReset, + displayRotate, + displayOffsetX, + displayOffsetY, + displayInvert, + keyboardDevice, + logoutputlevel +}; +enum { no_screen, st7789, st7735, st7735s, ili9341 }; +enum { no_touchscreen, xpt2046, stmpe610 }; +enum { level_error, level_warn, level_info, level_debug }; -enum { use_sx1262, cs, irq, busy, reset, dio2_as_rf_switch, use_rf95, user, gpiochip, has_gps }; -int initGPIOPin(int pinNum, std::string gpioChipname); - -#endif \ No newline at end of file +extern std::map settingsMap; +extern std::map settingsStrings; +int initGPIOPin(int pinNum, std::string gpioChipname); \ No newline at end of file diff --git a/src/platform/portduino/SimRadio.cpp b/src/platform/portduino/SimRadio.cpp index e3d56554a4..d0072cf35e 100644 --- a/src/platform/portduino/SimRadio.cpp +++ b/src/platform/portduino/SimRadio.cpp @@ -198,6 +198,8 @@ void SimRadio::startSend(meshtastic_MeshPacket *txp) p->decoded.payload.size = pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &meshtastic_Compressed_msg, &c); p->decoded.portnum = meshtastic_PortNum_SIMULATOR_APP; + + service.sendQueueStatusToPhone(router->getQueueStatus(), 0, p->id); service.sendToPhone(p); // Sending back to simulator } @@ -263,4 +265,4 @@ int16_t SimRadio::readData(uint8_t *data, size_t len) } return state; -} +} \ No newline at end of file diff --git a/src/platform/portduino/architecture.h b/src/platform/portduino/architecture.h index a987692222..321949226e 100644 --- a/src/platform/portduino/architecture.h +++ b/src/platform/portduino/architecture.h @@ -1,6 +1,6 @@ #pragma once -#define ARCH_PORTDUINO +#define ARCH_PORTDUINO 1 // // set HW_VENDOR diff --git a/src/platform/rp2040/architecture.h b/src/platform/rp2040/architecture.h index 61eb1bbe89..d7d7214c0d 100644 --- a/src/platform/rp2040/architecture.h +++ b/src/platform/rp2040/architecture.h @@ -27,4 +27,6 @@ #define HW_VENDOR meshtastic_HardwareModel_RAK11310 #elif defined(SENSELORA_RP2040) #define HW_VENDOR meshtastic_HardwareModel_SENSELORA_RP2040 +#elif defined(RP2040_LORA) +#define HW_VENDOR meshtastic_HardwareModel_RP2040_LORA #endif \ No newline at end of file diff --git a/src/platform/rp2040/main-rp2040.cpp b/src/platform/rp2040/main-rp2040.cpp index 1d7f8fe70c..3359263e90 100644 --- a/src/platform/rp2040/main-rp2040.cpp +++ b/src/platform/rp2040/main-rp2040.cpp @@ -35,4 +35,9 @@ void rp2040Setup() Taken from CPU cycle counter and ROSC oscillator, so should be pretty random. */ randomSeed(rp2040.hwrand32()); +} + +void enterDfuMode() +{ + reset_usb_boot(0, 0); } \ No newline at end of file diff --git a/src/power.h b/src/power.h index 54d98e7150..4dd35e7103 100644 --- a/src/power.h +++ b/src/power.h @@ -5,18 +5,39 @@ #include #include #endif -/** - * Per @spattinson - * MIN_BAT_MILLIVOLTS seems high. Typical 18650 are different chemistry to LiPo, even for LiPos that chart seems a bit off, other - * charts put 3690mV at about 30% for a lipo, for 18650 i think 10% remaining iis in the region of 3.2-3.3V. Reference 1st graph - * in [this test report](https://lygte-info.dk/review/batteries2012/Samsung%20INR18650-30Q%203000mAh%20%28Pink%29%20UK.html) - * looking at the red line - discharge at 0.2A - he gets a capacity of 2900mah, 90% of 2900 = 2610, that point in the graph looks - * to be a shade above 3.2V - */ -#define MIN_BAT_MILLIVOLTS 3250 // millivolts. 10% per https://blog.ampow.com/lipo-voltage-chart/ - -#define BAT_MILLIVOLTS_FULL 4100 -#define BAT_MILLIVOLTS_EMPTY 3500 + +#ifndef NUM_OCV_POINTS +#define NUM_OCV_POINTS 11 +#endif + +// 3400,3350,3320,3290,3270,3260,3250,3230,3200,3120,3000 //3.4 to 3.0 LiFePO4 +// 2120,2090,2070,2050,2030,2010,1990,1980,1970,1960,1950 //2.12 to 1.95 Lead Acid +// 4200,4050,3990,3890,3790,3700,3650,3550,3450,3300,3200 //4.2 to 3.2 LiIon/LiPo +// 4200,4050,3990,3890,3790,3700,3650,3550,3400,3300,3000 //4.2 to 3.0 LiIon/LiPo +// 4150,4050,3990,3890,3790,3690,3620,3520,3420,3300,3100 //4.15 to 3.1 LiIon/LiPo +// 2770,2650,2540,2420,2300,2180,2060,1940,1800,1680,1550 //2.8 to 1.5 Lithium Titanate + +#ifndef OCV_ARRAY +#ifdef CELL_TYPE_LIFEPO4 +#define OCV_ARRAY 3400, 3350, 3320, 3290, 3270, 3260, 3250, 3230, 3200, 3120, 3000 +#elif defined(CELL_TYPE_LEADACID) +#define OCV_ARRAY 2120, 2090, 2070, 2050, 2030, 2010, 1990, 1980, 1970, 1960, 1950 +#elif defined(CELL_TYPE_ALKALINE) +#define OCV_ARRAY 1580, 1400, 1350, 1300, 1280, 1250, 1230, 1190, 1150, 1100, 1000 +#elif defined(CELL_TYPE_NIMH) +#define OCV_ARRAY 1400, 1300, 1280, 1270, 1260, 1250, 1240, 1230, 1210, 1150, 1000 +#elif defined(CELL_TYPE_LTO) +#define OCV_ARRAY 2770, 2650, 2540, 2420, 2300, 2180, 2060, 1940, 1800, 1680, 1550 +#else // LiIon +#define OCV_ARRAY 4190, 4050, 3990, 3890, 3800, 3720, 3630, 3530, 3420, 3300, 3100 +#endif +#endif + +/*Note: 12V lead acid is 6 cells, most board accept only 1 cell LiIon/LiPo*/ +#ifndef NUM_CELLS +#define NUM_CELLS 1 +#endif + #ifdef BAT_MEASURE_ADC_UNIT extern RTC_NOINIT_ATTR uint64_t RTC_reg_b; #include "soc/sens_reg.h" // needed for adc pin reset @@ -44,6 +65,7 @@ class Power : private concurrency::OSThread virtual bool setup(); virtual int32_t runOnce() override; void setStatusHandler(meshtastic::PowerStatus *handler) { statusHandler = handler; } + const uint16_t OCV[11] = {OCV_ARRAY}; protected: meshtastic::PowerStatus *statusHandler; @@ -54,6 +76,7 @@ class Power : private concurrency::OSThread bool analogInit(); private: + // open circuit voltage lookup table uint8_t low_voltage_counter; #ifdef DEBUG_HEAP uint32_t lastheap; diff --git a/src/shutdown.h b/src/shutdown.h index f36a7f8ddc..6449b129ee 100644 --- a/src/shutdown.h +++ b/src/shutdown.h @@ -3,6 +3,11 @@ #include "graphics/Screen.h" #include "main.h" #include "power.h" +#if defined(ARCH_PORTDUINO) +#include "api/WiFiServerAPI.h" +#include "input/LinuxInputImpl.h" + +#endif void powerCommandsCheck() { @@ -14,8 +19,14 @@ void powerCommandsCheck() NVIC_SystemReset(); #elif defined(ARCH_RP2040) rp2040.reboot(); -#elif defined(ARCH_RASPBERRY_PI) - exit(EXIT_SUCCESS); +#elif defined(ARCH_PORTDUINO) + deInitApiServer(); + if (aLinuxInputImpl) + aLinuxInputImpl->deInit(); + SPI.end(); + Wire.end(); + Serial1.end(); + reboot(); #else rebootAtMsec = -1; LOG_WARN("FIXME implement reboot for this platform. Note that some settings require a restart to be applied.\n"); @@ -33,6 +44,8 @@ void powerCommandsCheck() #if defined(ARCH_NRF52) || defined(ARCH_ESP32) playShutdownMelody(); power->shutdown(); +#elif defined(ARCH_PORTDUINO) + exit(EXIT_SUCCESS); #else LOG_WARN("FIXME implement shutdown for this platform"); #endif diff --git a/src/sleep.cpp b/src/sleep.cpp index 464486d00c..0f71ab25b3 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -203,11 +203,10 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false) #endif #if defined(VEXT_ENABLE_V03) - if (heltec_version == 3) { - digitalWrite(VEXT_ENABLE_V03, 1); // turn off the display power - } else { - digitalWrite(VEXT_ENABLE_V05, 0); // turn off the display power - } + digitalWrite(VEXT_ENABLE_V03, 1); // turn off the display power +#elif defined(VEXT_ENABLE_V05) + digitalWrite(VEXT_ENABLE_V05, 0); // turn off the lora amplifier power + digitalWrite(ST7735_BL_V05, 0); // turn off the display power #elif defined(VEXT_ENABLE) digitalWrite(VEXT_ENABLE, 1); // turn off the display power #endif diff --git a/suppressions.txt b/suppressions.txt index 6cbd38d47a..04937523dc 100644 --- a/suppressions.txt +++ b/suppressions.txt @@ -50,4 +50,7 @@ virtualCallInConstructor passedByValue:*/RedirectablePrint.h internalAstError:*/CrossPlatformCryptoEngine.cpp -uninitMemberVar:*/AudioThread.h \ No newline at end of file +uninitMemberVar:*/AudioThread.h +// False positive +constVariableReference:*/Channels.cpp +constParameterPointer:*/unishox2.c \ No newline at end of file diff --git a/variants/canaryone/platformio.ini b/variants/canaryone/platformio.ini new file mode 100644 index 0000000000..d52bbb24a7 --- /dev/null +++ b/variants/canaryone/platformio.ini @@ -0,0 +1,15 @@ +; Public Beta oled/nrf52840/sx1262 device +[env:canaryone] +extends = nrf52840_base +board = canaryone +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/canaryone + -L "${platformio.libdeps_dir}/${this.__env__}/BSEC2 Software Library/src/cortex-m4/fpv4-sp-d16-hard" +build_src_filter = ${nrf52_base.build_src_filter} +<../variants/canaryone> +lib_deps = + ${nrf52840_base.lib_deps} + adafruit/Adafruit BusIO@^1.13.2 + lewisxhe/PCF8563_Library@^1.0.1 +;upload_protocol = fs diff --git a/variants/canaryone/variant.cpp b/variants/canaryone/variant.cpp new file mode 100644 index 0000000000..5967a2a96a --- /dev/null +++ b/variants/canaryone/variant.cpp @@ -0,0 +1,56 @@ +/* + 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() +{ + // LEDs + pinMode(PIN_LED1, OUTPUT); + ledOff(PIN_LED1); + + pinMode(PIN_LED2, OUTPUT); + ledOff(PIN_LED2); + + pinMode(PIN_LED3, OUTPUT); + ledOff(PIN_LED3); + + // Turn on power to the GPS and LoRa + pinMode(PIN_PWR_EN, OUTPUT); + digitalWrite(PIN_PWR_EN, HIGH); + + // Pull the GPS out of reset + pinMode(GPS_RESET_PIN, OUTPUT); + digitalWrite(GPS_RESET_PIN, HIGH); + + // Pull the LoRa out of reset + pinMode(LORA_RF_PWR, OUTPUT); + digitalWrite(LORA_RF_PWR, HIGH); +} diff --git a/variants/canaryone/variant.h b/variants/canaryone/variant.h new file mode 100644 index 0000000000..e31ba3c58f --- /dev/null +++ b/variants/canaryone/variant.h @@ -0,0 +1,188 @@ +/* + 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_CANARYONE +#define _VARIANT_CANARYONE + +/** 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 + +#define CANARYONE + +#define GPIO_PORT0 0 +#define GPIO_PORT1 32 + +// Number of pins defined in PinDescription array +#define PINS_COUNT (48) +#define NUM_DIGITAL_PINS (48) +#define NUM_ANALOG_INPUTS (1) +#define NUM_ANALOG_OUTPUTS (0) + +// LEDs +#define PIN_LED1 (GPIO_PORT1 + 1) // blue P1.01 +#define PIN_LED2 (GPIO_PORT0 + 14) // yellow P0.14 +#define PIN_LED3 (GPIO_PORT1 + 3) // green P1.03 + +#define LED_BLUE PIN_LED1 + +#define LED_BUILTIN PIN_LED1 +#define LED_CONN PIN_LED3 + +#define LED_STATE_ON 0 // State when LED is lit +#define LED_INVERTED 1 + +/* + * Buttons + */ +#define PIN_BUTTON1 (GPIO_PORT0 + 15) // BTN0 on schematic +#define PIN_BUTTON2 (GPIO_PORT0 + 16) // BTN1 on schematic + +/* + * Analog pins + */ +#define PIN_A0 (4) // Battery ADC P0.04 + +#define BATTERY_PIN PIN_A0 + +static const uint8_t A0 = PIN_A0; + +#define ADC_RESOLUTION 14 + +/** + * Wire Interfaces + */ +#define WIRE_INTERFACES_COUNT 1 + +#define PIN_WIRE_SDA (GPIO_PORT0 + 26) +// #define I2C_SDA (GPIO_PORT0 + 26) +#define PIN_WIRE_SCL (GPIO_PORT0 + 27) +// #define I2C_SCL (GPIO_PORT0 + 27) + +#define PIN_LCD_RESET (GPIO_PORT0 + 2) + +/* + * External serial flash WP25R1635FZUIL0 + */ + +// QSPI Pins +#define PIN_QSPI_SCK (GPIO_PORT1 + 14) +#define PIN_QSPI_CS (GPIO_PORT1 + 15) +#define PIN_QSPI_IO0 (GPIO_PORT1 + 12) // MOSI if using two bit interface +#define PIN_QSPI_IO1 (GPIO_PORT1 + 13) // MISO if using two bit interface +#define PIN_QSPI_IO2 (GPIO_PORT0 + 7) // WP if using two bit interface (i.e. not used) +#define PIN_QSPI_IO3 (GPIO_PORT0 + 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 RADIOLIB_DEBUG 1 +#define USE_SX1262 +#define SX126X_CS (GPIO_PORT0 + 24) +#define SX126X_DIO1 (GPIO_PORT1 + 11) +// #define SX126X_DIO3 (GPIO_PORT0 + 21) +// #define SX126X_DIO2 () // LORA_BUSY // LoRa RX/TX +#define SX126X_BUSY (GPIO_PORT0 + 17) +#define SX126X_RESET (GPIO_PORT0 + 25) +#define LORA_RF_PWR (GPIO_PORT0 + 28) // LORA_RF_SWITCH + +/* + * GPS pins + */ +#define HAS_GPS 1 +#define GPS_UBLOX +#define GPS_BAUDRATE 38400 + +// #define PIN_GPS_WAKE (GPIO_PORT1 + 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 (GPIO_PORT1 + 4) // Pulse per second input from the GPS +#define GPS_TX_PIN (GPIO_PORT1 + 9) // This is for bits going TOWARDS the CPU +#define GPS_RX_PIN (GPIO_PORT1 + 8) // This is for bits going TOWARDS the GPS + +#define GPS_THREAD_INTERVAL 50 + +#define PIN_SERIAL1_RX GPS_TX_PIN +#define PIN_SERIAL1_TX GPS_RX_PIN + +#define GPS_RESET_PIN (GPIO_PORT1 + 5) // GPS reset pin + +/* + * SPI Interfaces + */ +#define SPI_INTERFACES_COUNT 1 + +// For LORA, spi 0 +#define PIN_SPI_MISO (GPIO_PORT0 + 23) +#define PIN_SPI_MOSI (GPIO_PORT0 + 22) +#define PIN_SPI_SCK (GPIO_PORT0 + 19) + +// #define PIN_SPI1_MISO (GPIO_PORT1 + 6) // FIXME not really needed, but for now the SPI code requires something to be defined, +// pick an used GPIO #define PIN_SPI1_MOSI (GPIO_PORT1 + 8) #define PIN_SPI1_SCK (GPIO_PORT1 + 9) + +#define PIN_PWR_EN (GPIO_PORT0 + 12) + +// To debug via the segger JLINK console rather than the CDC-ACM serial device +#define USE_SEGGER 1 + +// #define LORA_DISABLE_SENDING 1 +#define SX126X_DIO2_AS_RF_SWITCH 1 + +// 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 +// Definition of milliVolt per LSB => 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096 +#define VBAT_MV_PER_LSB (0.73242188F) +// Voltage divider value => 100K + 100K voltage divider on VBAT = (100K / (100K + 100K)) +#define VBAT_DIVIDER (0.5F) +// Compensation factor for the VBAT divider +#define VBAT_DIVIDER_COMP (2.0) +// Fixed calculation of milliVolt from compensation value +#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) +#undef AREF_VOLTAGE +#define AREF_VOLTAGE 3.0 +#define VBAT_AR_INTERNAL AR_INTERNAL_3_0 +#define ADC_MULTIPLIER VBAT_DIVIDER_COMP +#define VBAT_RAW_TO_SCALED(x) (REAL_VBAT_MV_PER_LSB * x) + +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#endif \ No newline at end of file diff --git a/variants/chatter2/platformio.ini b/variants/chatter2/platformio.ini new file mode 100644 index 0000000000..0856debfc4 --- /dev/null +++ b/variants/chatter2/platformio.ini @@ -0,0 +1,13 @@ +; CircuitMess Chatter 2 based on ESP32-WROOM-32 (38 pins) devkit & DeeamLNK DL-LLCC68 or Heltec HT RA62 SX1262/SX1268 module +[env:chatter2] +extends = esp32_base +board = esp32doit-devkit-v1 +board_level = extra +build_flags = + ${esp32_base.build_flags} + -D CHATTER_2 + -I variants/chatter2 + +lib_deps = + ${esp32_base.lib_deps} + lovyan03/LovyanGFX@^1.1.8 \ No newline at end of file diff --git a/variants/chatter2/variant.h b/variants/chatter2/variant.h new file mode 100644 index 0000000000..90faa1d7ba --- /dev/null +++ b/variants/chatter2/variant.h @@ -0,0 +1,117 @@ +////////////////////////////////////////////////////////////////////////////////// +// // +// Have custom connections or functionality? Configure them in this section // +// // +////////////////////////////////////////////////////////////////////////////////// + +// Debugging +// #define GPS_DEBUG +// #define GPS_EXTRAVERBOSE + +// Lora +#define USE_LLCC68 // Original Chatter2 with LLCC68 module +#define USE_SX1262 // Added for when Lora module is swapped for HT-RA62 + +#define SX126X_CS 14 // module's NSS pin +#define LORA_SCK 16 // module's SCK pin +#define LORA_MOSI 5 // module's MOSI pin +#define LORA_MISO 17 // module's MISO pin +#define SX126X_RESET RADIOLIB_NC // module's NRST pin +#define SX126X_BUSY 4 // module's BUSY pin works for both LLCC68 and RA-62 with cut & jumper +#define SX126X_DIO1 18 // module's DIO1 pin +#define SX126X_DIO2_AS_RF_SWITCH // module's DIO2 pin +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 // module's DIO pin +#define SX126X_TXEN RADIOLIB_NC +#define SX126X_RXEN RADIOLIB_NC + +// Status +// #define LED_PIN 1 +// External notification +// FIXME: Check if EXT_NOTIFY_OUT actualy has any effect and removes the need for setting the external notication pin in the +// app/preferences +// #define EXT_NOTIFY_OUT 2 // The GPIO pin that acts as the external notification output (here we connect an LED to it) + +// Buzzer +#define PIN_BUZZER 19 +// Buttons +#define BUTTON_PIN 36 // Use the WAKE button as the user button +// I2C +// #define I2C_SCL 27 +// #define I2C_SDA 26 + +#define SX126X_MAX_POWER 22 // SX126xInterface.cpp defaults to 22 if not defined, but here we define it for good practice + +// Display + +#define HAS_SCREEN 1 // Assume no screen present by default to prevent crash... + +// ST7735S TFT LCD +#define ST7735S 1 // there are different (sub-)versions of ST7735 +#define ST7735_CS -1 +#define ST7735_RS 33 // DC +#define ST7735_SDA 26 // MOSI +#define ST7735_SCK 27 +#define ST7735_RESET 15 +#define ST7735_MISO -1 +#define ST7735_BUSY -1 +#define ST7735_BL 32 +#define ST7735_SPI_HOST HSPI_HOST // SPI2_HOST for S3, auto may work too +#define SPI_FREQUENCY 40000000 +#define SPI_READ_FREQUENCY 16000000 +#define TFT_HEIGHT 160 +#define TFT_WIDTH 128 +#define TFT_OFFSET_X 0 +#define TFT_OFFSET_Y 0 +#define TFT_INVERT false +#define SCREEN_ROTATE +#define SCREEN_TRANSITION_FRAMERATE 5 // fps +#define DISPLAY_FORCE_SMALL_FONTS + +// Battery + +#define BATTERY_PIN 34 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define ADC_CHANNEL ADC1_GPIO34_CHANNEL +#define ADC_ATTENUATION \ + ADC_ATTEN_DB_2_5 // 2_5-> 100mv-1250mv, 11-> 150mv-3100mv for ESP32 + // ESP32-S2/C3/S3 are different + // lower dB for lower voltage rnage +#define ADC_MULTIPLIER 5.0 // VBATT---10k--pin34---2.5K---GND +// Chatter2 uses 3 AAA cells +#define CELL_TYPE_ALKALINE +#define NUM_CELLS 3 +#undef EXT_PWR_DETECT + +// GPS +// FIXME: unsure what to define HAS_GPS as if GPS isn't always present +#define HAS_GPS 1 // Don't need to set this to 0 to prevent a crash as it doesn't crash if GPS not found, will probe by default +// #define PIN_GPS_EN 15 +// #define GPS_EN_ACTIVE 1 +#undef GPS_TX_PIN +#undef GPS_RX_PIN +#define GPS_TX_PIN 13 +#define GPS_RX_PIN 2 + +///////////////////////////////////////////////////////////////////////////////// +// // +// You should have no need to modify the code below, nor in pins_arduino.h // +// // +///////////////////////////////////////////////////////////////////////////////// + +#define LORA_CS SX126X_CS // FIXME: for some reason both are used in /src + +// Many of the below values would only be used if USE_RF95 was defined, but it's not as we aren't actually using an RF95, just +// that the 4 pins above are named like it If they aren't used they don't need to be defined and doing so cause confusion to those +// adapting this file LORA_RESET value is never used in src (as we are not using RF95), so no need to define LORA_DIO0 is not used +// in src (as we are not using RF95) as SX1262 does not have it per SX1262 datasheet, so no need to define +// FIXME: confirm that the linked lines below are actually only called when using the SX126x or SX128x and no other modules +// then use SX126X_DIO1 and SX128X_DIO1 respectively for that purpose, removing the need for RF95-style LORA_* definitions when +// the RF95 isn't used +#define LORA_DIO1 \ + SX126X_DIO1 // The old name is used in + // https://github.com/meshtastic/firmware/blob/7eff5e7bcb2084499b723c5e3846c15ee089e36d/src/sleep.cpp#L298, so + // must also define the old name +// LORA_DIO2 value is never used in src (as we are not using RF95), so no need to define, and if DIO2_AS_RF_SWITCH is set then it +// cannot serve any extra function even if requested to LORA_DIO3 value is never used in src (as we are not using RF95), so no +// need to define, and DIO3_AS_TCXO_AT_1V8 is set so it cannot serve any extra function even if requested to (from 13.3.2.1 +// DioxMask in SX1262 datasheet: Note that if DIO2 or DIO3 are used to control the RF Switch or the TCXO, the IRQ will not be +// generated even if it is mapped to the pins.) \ No newline at end of file diff --git a/variants/esp32-s3-pico/pins_arduino.h b/variants/esp32-s3-pico/pins_arduino.h new file mode 100644 index 0000000000..d24d98a2e6 --- /dev/null +++ b/variants/esp32-s3-pico/pins_arduino.h @@ -0,0 +1,36 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +#define EXTERNAL_NUM_INTERRUPTS 46 +#define NUM_DIGITAL_PINS 48 +#define NUM_ANALOG_INPUTS 20 + +#define analogInputToDigitalPin(p) (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) +#define digitalPinToInterrupt(p) (((p) < 48) ? (p) : -1) +#define digitalPinHasPWM(p) (p < 46) + +// The default Wire will be mapped to PMU and RTC +static const uint8_t SDA = 15; +static const uint8_t SCL = 16; + +// Default SPI will be mapped to Radio +static const uint8_t MISO = 37; +static const uint8_t SCK = 35; +static const uint8_t MOSI = 36; +static const uint8_t SS = 14; + +static const uint8_t BAT_ADC_PIN = 26; + +// #define SPI_MOSI (11) +// #define SPI_SCK (14) +// #define SPI_MISO (2) +// #define SPI_CS (13) + +// #define SDCARD_CS SPI_CS + +#endif /* Pins_Arduino_h */ \ No newline at end of file diff --git a/variants/esp32-s3-pico/platformio.ini b/variants/esp32-s3-pico/platformio.ini new file mode 100644 index 0000000000..f39004c361 --- /dev/null +++ b/variants/esp32-s3-pico/platformio.ini @@ -0,0 +1,25 @@ +[env:ESP32-S3-Pico] + +board_level = extra +extends = esp32s3_base +upload_protocol = esptool +board = esp32-s3-pico + +board_upload.use_1200bps_touch = yes +board_upload.wait_for_upload_port = yes +board_upload.require_upload_port = yes + +;upload_port = /dev/ttyACM0 + +build_flags = ${esp32_base.build_flags} + -DESP32_S3_PICO + ;-DPRIVATE_HW + -Ivariants/esp32-s3-pico + -DBOARD_HAS_PSRAM + -DTECHO_DISPLAY_MODEL=GxEPD2_290_T94_V2 + -DEPD_HEIGHT=128 + -DEPD_WIDTH=296 + +lib_deps = ${esp32s3_base.lib_deps} + zinggjm/GxEPD2@^1.5.3 + ;adafruit/Adafruit NeoPixel@^1.10.7 diff --git a/variants/esp32-s3-pico/variant.h b/variants/esp32-s3-pico/variant.h new file mode 100644 index 0000000000..9e10183fb5 --- /dev/null +++ b/variants/esp32-s3-pico/variant.h @@ -0,0 +1,77 @@ +/* + +*/ +#define HAS_GPS 0 +#undef GPS_RX_PIN +#undef GPS_TX_PIN + +#define EXT_NOTIFY_OUT 22 +#define BUTTON_PIN 0 // 17 + +// #define LED_PIN PIN_LED +// Board has RGB LED 21 + +// The usbPower state is revered ? +// DEBUG | ??:??:?? 365 [Power] Battery: usbPower=0, isCharging=0, batMv=4116, batPct=90 +// DEBUG | ??:??:?? 385 [Power] Battery: usbPower=1, isCharging=1, batMv=4243, batPct=0 + +// https://www.waveshare.com/img/devkit/ESP32-S3-Pico/ESP32-S3-Pico-details-inter-1.jpg +// digram is incorrect labeled as battery pin is getting readings on GPIO7_CH1? +#define BATTERY_PIN 7 +#define ADC_CHANNEL ADC1_GPIO7_CHANNEL +// #define ADC_CHANNEL ADC1_GPIO6_CHANNEL +// ratio of voltage divider = 3.0 (R17=200k, R18=100k) +#define ADC_MULTIPLIER 3.1 // 3.0 + a bit for being optimistic + +#define I2C_SDA 15 +#define I2C_SCL 16 + +// Enable secondary bus for external periherals +// https://www.waveshare.com/wiki/Pico-OLED-1.3 +// #define USE_SH1107_128_64 +// Not working +#define I2C_SDA1 17 +#define I2C_SCL1 18 + +#define BUTTON_PIN 0 // This is the BOOT button +#define BUTTON_NEED_PULLUP + +// #define USE_RF95 // RFM95/SX127x +#define USE_SX1262 +// #define USE_SX1280 + +#define LORA_MISO 37 +#define LORA_SCK 35 +#define LORA_MOSI 36 +#define LORA_CS 14 + +#define LORA_RESET 40 +#define LORA_DIO1 4 +#define LORA_DIO2 13 + +#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 + +#ifdef USE_SX1280 +#define SX128X_CS LORA_CS +#define SX128X_DIO1 LORA_DIO1 +#define SX128X_BUSY 9 +#define SX128X_RESET LORA_RESET +#endif + +#define USE_EINK +/* + * eink display pins + */ +#define PIN_EINK_CS 34 +#define PIN_EINK_BUSY 38 +#define PIN_EINK_DC 33 +#define PIN_EINK_RES 42 // 37 //(-1) // cant be MISO Waveshare ??) +#define PIN_EINK_SCLK 35 +#define PIN_EINK_MOSI 36 diff --git a/variants/heltec_v2.1/variant.h b/variants/heltec_v2.1/variant.h index ed123efec8..8ebccc54fb 100644 --- a/variants/heltec_v2.1/variant.h +++ b/variants/heltec_v2.1/variant.h @@ -29,7 +29,8 @@ #define LORA_DIO1 35 // https://www.thethingsnetwork.org/forum/t/big-esp32-sx127x-topic-part-3/18436 #define LORA_DIO2 34 // Not really used -#define ADC_MULTIPLIER 3.8 +#define ADC_MULTIPLIER 3.2 // 220k + 100k (320k/100k=3.2) +// #define ADC_WIDTH ADC_WIDTH_BIT_10 #define BATTERY_PIN 37 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage #define ADC_CHANNEL ADC1_GPIO37_CHANNEL diff --git a/variants/heltec_v3/variant.h b/variants/heltec_v3/variant.h index 2532ea682a..70b122f584 100644 --- a/variants/heltec_v3/variant.h +++ b/variants/heltec_v3/variant.h @@ -11,6 +11,8 @@ #define VEXT_ENABLE Vext // active low, powers the oled display and the lora antenna boost #define BUTTON_PIN 0 +#define ADC_CTRL 37 +#define ADC_CTRL_ENABLED LOW #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage #define ADC_CHANNEL ADC1_GPIO1_CHANNEL #define ADC_ATTENUATION ADC_ATTEN_DB_2_5 // lower dB for high resistance voltage divider diff --git a/variants/heltec_wireless_paper/pins_arduino.h b/variants/heltec_wireless_paper/pins_arduino.h new file mode 100644 index 0000000000..66d0916914 --- /dev/null +++ b/variants/heltec_wireless_paper/pins_arduino.h @@ -0,0 +1,78 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define WIFI_Kit_32 true +#define DISPLAY_HEIGHT 64 +#define DISPLAY_WIDTH 128 + +#define EXTERNAL_NUM_INTERRUPTS 16 +#define NUM_DIGITAL_PINS 40 +#define NUM_ANALOG_INPUTS 16 + +#define analogInputToDigitalPin(p) (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) +#define digitalPinToInterrupt(p) (((p) < 40) ? (p) : -1) +#define digitalPinHasPWM(p) (p < 34) + +static const uint8_t LED_BUILTIN = 35; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN + +static const uint8_t KEY_BUILTIN = 0; + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t SDA = 41; +static const uint8_t SCL = 42; + +static const uint8_t SS = 8; +static const uint8_t MOSI = 10; +static const uint8_t MISO = 11; +static const uint8_t SCK = 9; + +static const uint8_t A0 = 1; +static const uint8_t A1 = 2; +static const uint8_t A2 = 3; +static const uint8_t A3 = 4; +static const uint8_t A4 = 5; +static const uint8_t A5 = 6; +static const uint8_t A6 = 7; +static const uint8_t A7 = 8; +static const uint8_t A8 = 9; +static const uint8_t A9 = 10; +static const uint8_t A10 = 11; +static const uint8_t A11 = 12; +static const uint8_t A12 = 13; +static const uint8_t A13 = 14; +static const uint8_t A14 = 15; +static const uint8_t A15 = 16; +static const uint8_t A16 = 17; +static const uint8_t A17 = 18; +static const uint8_t A18 = 19; +static const uint8_t A19 = 20; + +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; +static const uint8_t T4 = 4; +static const uint8_t T5 = 5; +static const uint8_t T6 = 6; +static const uint8_t T7 = 7; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; +static const uint8_t T10 = 10; +static const uint8_t T11 = 11; +static const uint8_t T12 = 12; +static const uint8_t T13 = 13; +static const uint8_t T14 = 14; + +static const uint8_t Vext = 45; +static const uint8_t LED = 18; + +static const uint8_t RST_LoRa = 12; +static const uint8_t BUSY_LoRa = 13; +static const uint8_t DIO0 = 14; + +#endif /* Pins_Arduino_h */ diff --git a/variants/heltec_wireless_paper/platformio.ini b/variants/heltec_wireless_paper/platformio.ini index 0bc7f14d17..dd93b52cb4 100644 --- a/variants/heltec_wireless_paper/platformio.ini +++ b/variants/heltec_wireless_paper/platformio.ini @@ -5,4 +5,7 @@ build_flags = ${esp32s3_base.build_flags} -D HELTEC_WIRELESS_PAPER -I variants/heltec_wireless_paper lib_deps = ${esp32s3_base.lib_deps} - zinggjm/GxEPD2@^1.5.2 + https://github.com/ixt/GxEPD2#39f325b677713eb04dfcc83b8e402e77523fb8bf + adafruit/Adafruit BusIO@^1.13.2 + lewisxhe/PCF8563_Library@^1.0.1 +upload_speed = 115200 \ No newline at end of file diff --git a/variants/heltec_wireless_paper/variant.h b/variants/heltec_wireless_paper/variant.h index 88c5faaa1f..c2a030ed07 100644 --- a/variants/heltec_wireless_paper/variant.h +++ b/variants/heltec_wireless_paper/variant.h @@ -15,13 +15,24 @@ #define PIN_EINK_SCLK 3 #define PIN_EINK_MOSI 2 -#define VEXT_ENABLE Vext // active low, powers the oled display and the lora antenna boost +/* + * SPI interfaces + */ +#define SPI_INTERFACES_COUNT 2 + +#define PIN_SPI_MISO 10 // MISO P0.17 +#define PIN_SPI_MOSI 11 // MOSI P0.15 +#define PIN_SPI_SCK 9 // SCK P0.13 + +#define VEXT_ENABLE 45 // active low, powers the oled display and the lora antenna boost #define BUTTON_PIN 0 -#define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage -#define ADC_CHANNEL ADC1_GPIO1_CHANNEL -#define ADC_ATTENUATION ADC_ATTEN_DB_2_5 // lower dB for high resistance voltage divider -#define ADC_MULTIPLIER 4.9 +#define ADC_CTRL 19 +#define BATTERY_PIN 20 +#define ADC_CHANNEL ADC2_GPIO20_CHANNEL +#define ADC_MULTIPLIER 2 // Voltage divider is roughly 1:1 +#define BAT_MEASURE_ADC_UNIT 2 // Use ADC2 +#define ADC_ATTENUATION ADC_ATTEN_DB_11 // Voltage divider output is quite high #define USE_SX1262 diff --git a/variants/heltec_wireless_paper_v1/pins_arduino.h b/variants/heltec_wireless_paper_v1/pins_arduino.h new file mode 100644 index 0000000000..66d0916914 --- /dev/null +++ b/variants/heltec_wireless_paper_v1/pins_arduino.h @@ -0,0 +1,78 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define WIFI_Kit_32 true +#define DISPLAY_HEIGHT 64 +#define DISPLAY_WIDTH 128 + +#define EXTERNAL_NUM_INTERRUPTS 16 +#define NUM_DIGITAL_PINS 40 +#define NUM_ANALOG_INPUTS 16 + +#define analogInputToDigitalPin(p) (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) +#define digitalPinToInterrupt(p) (((p) < 40) ? (p) : -1) +#define digitalPinHasPWM(p) (p < 34) + +static const uint8_t LED_BUILTIN = 35; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN + +static const uint8_t KEY_BUILTIN = 0; + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t SDA = 41; +static const uint8_t SCL = 42; + +static const uint8_t SS = 8; +static const uint8_t MOSI = 10; +static const uint8_t MISO = 11; +static const uint8_t SCK = 9; + +static const uint8_t A0 = 1; +static const uint8_t A1 = 2; +static const uint8_t A2 = 3; +static const uint8_t A3 = 4; +static const uint8_t A4 = 5; +static const uint8_t A5 = 6; +static const uint8_t A6 = 7; +static const uint8_t A7 = 8; +static const uint8_t A8 = 9; +static const uint8_t A9 = 10; +static const uint8_t A10 = 11; +static const uint8_t A11 = 12; +static const uint8_t A12 = 13; +static const uint8_t A13 = 14; +static const uint8_t A14 = 15; +static const uint8_t A15 = 16; +static const uint8_t A16 = 17; +static const uint8_t A17 = 18; +static const uint8_t A18 = 19; +static const uint8_t A19 = 20; + +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; +static const uint8_t T4 = 4; +static const uint8_t T5 = 5; +static const uint8_t T6 = 6; +static const uint8_t T7 = 7; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; +static const uint8_t T10 = 10; +static const uint8_t T11 = 11; +static const uint8_t T12 = 12; +static const uint8_t T13 = 13; +static const uint8_t T14 = 14; + +static const uint8_t Vext = 45; +static const uint8_t LED = 18; + +static const uint8_t RST_LoRa = 12; +static const uint8_t BUSY_LoRa = 13; +static const uint8_t DIO0 = 14; + +#endif /* Pins_Arduino_h */ diff --git a/variants/heltec_wireless_paper_v1/platformio.ini b/variants/heltec_wireless_paper_v1/platformio.ini new file mode 100644 index 0000000000..7d7f4eb14f --- /dev/null +++ b/variants/heltec_wireless_paper_v1/platformio.ini @@ -0,0 +1,13 @@ +[env:heltec-wireless-paper-v1_0] +extends = esp32s3_base +board = heltec_wifi_lora_32_V3 +build_flags = + ${esp32s3_base.build_flags} + -I variants/heltec_wireless_paper_v1 + -D HELTEC_WIRELESS_PAPER_V1_0 +lib_deps = + ${esp32s3_base.lib_deps} + https://github.com/meshtastic/GxEPD2/ + adafruit/Adafruit BusIO@^1.13.2 + lewisxhe/PCF8563_Library@^1.0.1 +upload_speed = 115200 \ No newline at end of file diff --git a/variants/heltec_wireless_paper_v1/variant.h b/variants/heltec_wireless_paper_v1/variant.h new file mode 100644 index 0000000000..166b7f30e6 --- /dev/null +++ b/variants/heltec_wireless_paper_v1/variant.h @@ -0,0 +1,64 @@ +#define LED_PIN 18 + +// Enable bus for external periherals +#define I2C_SDA SDA +#define I2C_SCL SCL + +#define USE_EINK + +// Settings for Dynamic Partial mode +// Change between partial and full refresh config, or skip update, balancing urgency and display health. +#define USE_EINK_DYNAMIC_PARTIAL +#define EINK_LOWPRIORITY_LIMIT_SECONDS 30 +#define EINK_HIGHPRIORITY_LIMIT_SECONDS 1 +#define EINK_PARTIAL_REPEAT_LIMIT 5 + +/* + * eink display pins + */ +#define PIN_EINK_CS 4 +#define PIN_EINK_BUSY 7 +#define PIN_EINK_DC 5 +#define PIN_EINK_RES 6 +#define PIN_EINK_SCLK 3 +#define PIN_EINK_MOSI 2 + +/* + * SPI interfaces + */ +#define SPI_INTERFACES_COUNT 2 + +#define PIN_SPI_MISO 10 // MISO P0.17 +#define PIN_SPI_MOSI 11 // MOSI P0.15 +#define PIN_SPI_SCK 9 // SCK P0.13 + +#define VEXT_ENABLE 45 // active low, powers the oled display and the lora antenna boost +#define BUTTON_PIN 0 + +#define ADC_CTRL 19 +#define BATTERY_PIN 20 +#define ADC_CHANNEL ADC2_GPIO20_CHANNEL +#define ADC_MULTIPLIER 2 // Voltage divider is roughly 1:1 +#define BAT_MEASURE_ADC_UNIT 2 // Use ADC2 +#define ADC_ATTENUATION ADC_ATTEN_DB_11 // Voltage divider output is quite high + +#define USE_SX1262 + +#define LORA_DIO0 -1 // a No connect on the SX1262 module +#define LORA_RESET 12 +#define LORA_DIO1 14 // SX1262 IRQ +#define LORA_DIO2 13 // SX1262 BUSY +#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled + +#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 diff --git a/variants/heltec_wireless_tracker/pins_arduino.h b/variants/heltec_wireless_tracker/pins_arduino.h index e4d2631e78..5c0b529b04 100644 --- a/variants/heltec_wireless_tracker/pins_arduino.h +++ b/variants/heltec_wireless_tracker/pins_arduino.h @@ -5,8 +5,8 @@ #include #define WIFI_LoRa_32_V3 true -#define DISPLAY_HEIGHT 64 -#define DISPLAY_WIDTH 128 +#define DISPLAY_HEIGHT 80 +#define DISPLAY_WIDTH 160 #define USB_VID 0x303a #define USB_PID 0x1001 @@ -26,8 +26,8 @@ static const uint8_t LED_BUILTIN = 18; static const uint8_t TX = 43; static const uint8_t RX = 44; -static const uint8_t SDA = 41; -static const uint8_t SCL = 42; +static const uint8_t SDA = 45; +static const uint8_t SCL = 46; static const uint8_t SS = 8; static const uint8_t MOSI = 10; diff --git a/variants/heltec_wireless_tracker/platformio.ini b/variants/heltec_wireless_tracker/platformio.ini index fa79eeb6a0..3259d563c3 100644 --- a/variants/heltec_wireless_tracker/platformio.ini +++ b/variants/heltec_wireless_tracker/platformio.ini @@ -5,7 +5,9 @@ upload_protocol = esp-builtin build_flags = ${esp32s3_base.build_flags} -I variants/heltec_wireless_tracker - -DGPS_POWER_TOGGLE + -D HELTEC_TRACKER_V1_1 + -D GPS_POWER_TOGGLE ; comment this line to disable triple press function on the user button to turn off gps entirely. + ;-D DEBUG_DISABLED ; uncomment this line to disable DEBUG output lib_deps = ${esp32s3_base.lib_deps} diff --git a/variants/heltec_wireless_tracker/variant.h b/variants/heltec_wireless_tracker/variant.h index 88b4804a12..167345e1a9 100644 --- a/variants/heltec_wireless_tracker/variant.h +++ b/variants/heltec_wireless_tracker/variant.h @@ -1,5 +1,11 @@ #define LED_PIN 18 +#define HELTEC_TRACKER_V1_X + +// I2C +#define I2C_SDA SDA +#define I2C_SCL SCL + // ST7735S TFT LCD #define ST7735S 1 // there are different (sub-)versions of ST7735 #define ST7735_CS 38 @@ -9,25 +15,19 @@ #define ST7735_RESET 39 #define ST7735_MISO -1 #define ST7735_BUSY -1 -#define ST7735_BL_V03 45 #define ST7735_BL_V05 21 /* V1.1 PCB marking */ #define ST7735_SPI_HOST SPI3_HOST -#define ST7735_BACKLIGHT_EN_V03 45 -#define ST7735_BACKLIGHT_EN_V05 21 #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 #define SCREEN_ROTATE -#define TFT_HEIGHT 160 -#define TFT_WIDTH 80 +#define TFT_HEIGHT DISPLAY_WIDTH +#define TFT_WIDTH DISPLAY_HEIGHT #define TFT_OFFSET_X 26 -#define TFT_OFFSET_Y 0 -#define VTFT_CTRL_V03 46 // Heltec Tracker needs this pulled low for TFT -#define VTFT_CTRL_V05 -1 -#define SCREEN_TRANSITION_FRAMERATE 1 // fps +#define TFT_OFFSET_Y -1 +#define SCREEN_TRANSITION_FRAMERATE 3 // fps #define DISPLAY_FORCE_SMALL_FONTS -#define VEXT_ENABLE_V03 Vext // active low, powers the oled display and the lora antenna boost -#define VEXT_ENABLE_V05 3 // active HIGH, powers the oled display +#define VEXT_ENABLE_V05 3 // active HIGH, powers the lora antenna boost #define BUTTON_PIN 0 #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage @@ -35,6 +35,7 @@ #define ADC_ATTENUATION ADC_ATTEN_DB_2_5 // lower dB for high resistance voltage divider #define ADC_MULTIPLIER 4.9 #define ADC_CTRL 2 // active HIGH, powers the voltage divider. Only on 1.1 +#define ADC_CTRL_ENABLED HIGH #undef GPS_RX_PIN #undef GPS_TX_PIN @@ -43,11 +44,6 @@ #define PIN_GPS_RESET 35 #define PIN_GPS_PPS 36 -#define VGNSS_CTRL_V03 37 // Heltec Tracker needs this pulled low for GPS -#define VGNSS_CTRL_V05 -1 // Heltec Tracker needs this pulled low for GPS -#define PIN_GPS_EN VGNSS_CTRL_V03 -#define GPS_EN_ACTIVE LOW - #define GPS_RESET_MODE LOW #define GPS_UC6580 diff --git a/variants/heltec_wireless_tracker_V1_0/pins_arduino.h b/variants/heltec_wireless_tracker_V1_0/pins_arduino.h new file mode 100644 index 0000000000..5c0b529b04 --- /dev/null +++ b/variants/heltec_wireless_tracker_V1_0/pins_arduino.h @@ -0,0 +1,80 @@ +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include "soc/soc_caps.h" +#include + +#define WIFI_LoRa_32_V3 true +#define DISPLAY_HEIGHT 80 +#define DISPLAY_WIDTH 160 + +#define USB_VID 0x303a +#define USB_PID 0x1001 + +#define EXTERNAL_NUM_INTERRUPTS 46 +#define NUM_DIGITAL_PINS 48 +#define NUM_ANALOG_INPUTS 20 + +static const uint8_t LED_BUILTIN = 18; +#define BUILTIN_LED LED_BUILTIN // backward compatibility +#define LED_BUILTIN LED_BUILTIN + +#define analogInputToDigitalPin(p) (((p) < 20) ? (analogChannelToDigitalPin(p)) : -1) +#define digitalPinToInterrupt(p) (((p) < 48) ? (p) : -1) +#define digitalPinHasPWM(p) (p < 46) + +static const uint8_t TX = 43; +static const uint8_t RX = 44; + +static const uint8_t SDA = 45; +static const uint8_t SCL = 46; + +static const uint8_t SS = 8; +static const uint8_t MOSI = 10; +static const uint8_t MISO = 11; +static const uint8_t SCK = 9; + +static const uint8_t A0 = 1; +static const uint8_t A1 = 2; +static const uint8_t A2 = 3; +static const uint8_t A3 = 4; +static const uint8_t A4 = 5; +static const uint8_t A5 = 6; +static const uint8_t A6 = 7; +static const uint8_t A7 = 8; +static const uint8_t A8 = 9; +static const uint8_t A9 = 10; +static const uint8_t A10 = 11; +static const uint8_t A11 = 12; +static const uint8_t A12 = 13; +static const uint8_t A13 = 14; +static const uint8_t A14 = 15; +static const uint8_t A15 = 16; +static const uint8_t A16 = 17; +static const uint8_t A17 = 18; +static const uint8_t A18 = 19; +static const uint8_t A19 = 20; + +static const uint8_t T1 = 1; +static const uint8_t T2 = 2; +static const uint8_t T3 = 3; +static const uint8_t T4 = 4; +static const uint8_t T5 = 5; +static const uint8_t T6 = 6; +static const uint8_t T7 = 7; +static const uint8_t T8 = 8; +static const uint8_t T9 = 9; +static const uint8_t T10 = 10; +static const uint8_t T11 = 11; +static const uint8_t T12 = 12; +static const uint8_t T13 = 13; +static const uint8_t T14 = 14; + +static const uint8_t Vext = 36; +static const uint8_t LED = 18; + +static const uint8_t RST_LoRa = 12; +static const uint8_t BUSY_LoRa = 13; +static const uint8_t DIO0 = 14; + +#endif /* Pins_Arduino_h */ diff --git a/variants/heltec_wireless_tracker_V1_0/platformio.ini b/variants/heltec_wireless_tracker_V1_0/platformio.ini new file mode 100644 index 0000000000..034360c3da --- /dev/null +++ b/variants/heltec_wireless_tracker_V1_0/platformio.ini @@ -0,0 +1,14 @@ +[env:heltec-wireless-tracker-V1-0] +extends = esp32s3_base +board = heltec_wireless_tracker +upload_protocol = esp-builtin + +build_flags = + ${esp32s3_base.build_flags} -I variants/heltec_wireless_tracker_V1_0 + -D HELTEC_TRACKER_V1_0 + -D GPS_POWER_TOGGLE ; comment this line to disable triple press function on the user button to turn off gps entirely. + ;-D DEBUG_DISABLED ; uncomment this line to disable DEBUG output + +lib_deps = + ${esp32s3_base.lib_deps} + lovyan03/LovyanGFX@^1.1.8 \ No newline at end of file diff --git a/variants/heltec_wireless_tracker_V1_0/variant.h b/variants/heltec_wireless_tracker_V1_0/variant.h new file mode 100644 index 0000000000..84e77a6b95 --- /dev/null +++ b/variants/heltec_wireless_tracker_V1_0/variant.h @@ -0,0 +1,71 @@ +#define LED_PIN 18 + +#define HELTEC_TRACKER_V1_X + +// I2C +#define I2C_SDA SDA +#define I2C_SCL SCL + +// ST7735S TFT LCD +#define ST7735S 1 // there are different (sub-)versions of ST7735 +#define ST7735_CS 38 +#define ST7735_RS 40 // DC +#define ST7735_SDA 42 // MOSI +#define ST7735_SCK 41 +#define ST7735_RESET 39 +#define ST7735_MISO -1 +#define ST7735_BUSY -1 +#define ST7735_BL_V03 45 +#define ST7735_SPI_HOST SPI3_HOST +#define SPI_FREQUENCY 40000000 +#define SPI_READ_FREQUENCY 16000000 +#define SCREEN_ROTATE +#define TFT_HEIGHT DISPLAY_WIDTH +#define TFT_WIDTH DISPLAY_HEIGHT +#define TFT_OFFSET_X 26 +#define TFT_OFFSET_Y -1 +#define VTFT_CTRL_V03 46 // Heltec Tracker needs this pulled low for TFT +#define SCREEN_TRANSITION_FRAMERATE 3 // fps +#define DISPLAY_FORCE_SMALL_FONTS + +#define VEXT_ENABLE_V03 Vext // active low, powers the oled display and the lora antenna boost +#define BUTTON_PIN 0 + +#define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +#define ADC_CHANNEL ADC1_GPIO1_CHANNEL +#define ADC_ATTENUATION ADC_ATTEN_DB_2_5 // lower dB for high resistance voltage divider +#define ADC_MULTIPLIER 4.9 + +#undef GPS_RX_PIN +#undef GPS_TX_PIN +#define GPS_RX_PIN 33 +#define GPS_TX_PIN 34 +#define PIN_GPS_RESET 35 +#define PIN_GPS_PPS 36 + +#define VGNSS_CTRL_V03 37 // Heltec Tracker needs this pulled low for GPS +#define PIN_GPS_EN VGNSS_CTRL_V03 +#define GPS_EN_ACTIVE LOW + +#define GPS_RESET_MODE LOW +#define GPS_UC6580 + +#define USE_SX1262 +#define LORA_DIO0 -1 // a No connect on the SX1262 module +#define LORA_RESET 12 +#define LORA_DIO1 14 // SX1262 IRQ +#define LORA_DIO2 13 // SX1262 BUSY +#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled + +#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 diff --git a/variants/heltec_wsl_v3/variant.h b/variants/heltec_wsl_v3/variant.h index 0ad1b8487b..d3a009adeb 100644 --- a/variants/heltec_wsl_v3/variant.h +++ b/variants/heltec_wsl_v3/variant.h @@ -8,6 +8,8 @@ #define VEXT_ENABLE Vext // active low, powers the oled display and the lora antenna boost #define BUTTON_PIN 0 +#define ADC_CTRL 37 +#define ADC_CTRL_ENABLED LOW #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage #define ADC_CHANNEL ADC1_GPIO1_CHANNEL #define ADC_ATTENUATION ADC_ATTEN_DB_2_5 // lower dB for high resistance voltage divider diff --git a/variants/lora_relay_v1/variant.h b/variants/lora_relay_v1/variant.h index b310223d73..9cfb693374 100644 --- a/variants/lora_relay_v1/variant.h +++ b/variants/lora_relay_v1/variant.h @@ -80,6 +80,7 @@ static const uint8_t A5 = PIN_A5; // Other pins #define PIN_AREF PIN_A5 #define PIN_VBAT PIN_A4 +#define BATTERY_PIN PIN_VBAT #define PIN_NFC1 (33) #define PIN_NFC2 (2) #define PIN_PIEZO (37) diff --git a/variants/lora_relay_v2/variant.h b/variants/lora_relay_v2/variant.h index 172da17f7a..3afe8620ee 100644 --- a/variants/lora_relay_v2/variant.h +++ b/variants/lora_relay_v2/variant.h @@ -100,6 +100,7 @@ static const uint8_t A5 = PIN_A5; // Other pins #define PIN_AREF PIN_A5 #define PIN_VBAT PIN_A4 +#define BATTERY_PIN PIN_VBAT #define PIN_NFC1 (33) #define PIN_NFC2 (2) #define PIN_PIEZO (37) diff --git a/variants/m5stack_coreink/platformio.ini b/variants/m5stack_coreink/platformio.ini index e6aef380c2..ee6d340dc2 100644 --- a/variants/m5stack_coreink/platformio.ini +++ b/variants/m5stack_coreink/platformio.ini @@ -16,11 +16,11 @@ build_flags = -DM5STACK lib_deps = ${esp32_base.lib_deps} - zinggjm/GxEPD2@^1.4.9 + zinggjm/GxEPD2@^1.5.3 lewisxhe/PCF8563_Library@^1.0.1 lib_ignore = m5stack-coreink monitor_filters = esp32_exception_decoder board_build.f_cpu = 240000000L upload_protocol = esptool -;upload_port = /dev/ttyACM0 +upload_port = /dev/ttyACM0 diff --git a/variants/m5stack_coreink/variant.h b/variants/m5stack_coreink/variant.h index 0fc56477c1..f19da26967 100644 --- a/variants/m5stack_coreink/variant.h +++ b/variants/m5stack_coreink/variant.h @@ -2,16 +2,12 @@ #define I2C_SDA 21 #define I2C_SCL 22 -// 7-07-2023 Or enable Secondary I2C Bus -// #define I2C_SDA1 32 -// #define I2C_SCL1 33 - #define HAS_GPS 1 #undef GPS_RX_PIN #undef GPS_TX_PIN // Use Secondary I2C Bus as GPS Serial #define GPS_RX_PIN 33 -#define GPS_TX_PIN 32 +// #define GPS_TX_PIN 32 (now used by SX1262 BUSY as GPS works with just RX) // Green LED #define LED_INVERTED 0 @@ -38,7 +34,9 @@ #undef LORA_MISO #undef LORA_MOSI #undef LORA_CS + #define USE_RF95 +// #define USE_SX1262 // #define USE_SX1280 #ifdef USE_RF95 @@ -52,6 +50,23 @@ #define LORA_DIO2 RADIOLIB_NC #endif +// https://www.waveshare.com/core1262-868m.htm +#ifdef USE_SX1262 +#define LORA_SCK 18 +#define LORA_MISO 34 +#define LORA_MOSI 23 +#define LORA_CS 14 +#define LORA_RESET 26 +#define LORA_DIO1 25 +#define LORA_DIO2 32 // 33 // (13 not working) //BUSY pin on 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 + #ifdef USE_SX1280 #define LORA_SCK 18 #define LORA_MISO 34 @@ -90,5 +105,5 @@ // | // GND // https://github.com/m5stack/M5Core-Ink/blob/master/examples/Basics/FactoryTest/FactoryTest.ino#L58 -#define ADC_MULTIPLIER 5 // Just a guess for now... more detailed getBatVoltage above +#define ADC_MULTIPLIER 5 // https://embeddedexplorer.com/esp32-adc-esp-idf-tutorial/ diff --git a/variants/nano-g2-ultra/variant.h b/variants/nano-g2-ultra/variant.h index d69235fd4a..c328d22711 100644 --- a/variants/nano-g2-ultra/variant.h +++ b/variants/nano-g2-ultra/variant.h @@ -170,7 +170,7 @@ External serial flash W25Q16JV_IQ // Voltage divider value => 100K + 100K voltage divider on VBAT = (100K / (100K + 100K)) #define VBAT_DIVIDER (0.5F) // Compensation factor for the VBAT divider -#define VBAT_DIVIDER_COMP (2.0) +#define VBAT_DIVIDER_COMP (2.0F) // Fixed calculation of milliVolt from compensation value #define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) #undef AREF_VOLTAGE diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index 5e9428d4e2..d37c6be21f 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -3,20 +3,4 @@ extends = portduino_base build_flags = ${portduino_base.build_flags} -O0 -I variants/portduino board = cross_platform lib_deps = ${portduino_base.lib_deps} -build_src_filter = ${portduino_base.build_src_filter} - -; The Portduino based sim environment on top of a linux OS and touching linux hardware devices -[env:linux] -extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino -board = linux_hardware -lib_deps = ${portduino_base.lib_deps} -build_src_filter = ${portduino_base.build_src_filter} - -; The Raspberry Pi actually has accessible SPI and GPIO, so we can support real hardware there. -[env:raspbian] -extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino -DARCH_RASPBERRY_PI -lpigpio -lyaml-cpp -board = linux_arm -lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} \ No newline at end of file diff --git a/variants/portduino/variant.h b/variants/portduino/variant.h index 23066276b8..f47b58afc2 100644 --- a/variants/portduino/variant.h +++ b/variants/portduino/variant.h @@ -1,32 +1,3 @@ -#if defined(ARCH_RASPBERRY_PI) -#define HAS_WIRE 1 #define HAS_SCREEN 1 - -#else // Pine64 mode. - -// Pine64 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. Currently the RF95 code is disabled because I think the RF95 module won't need to ship. -// #define USE_RF95 -#define USE_SX1262 - -// Fake SPI device selections -#define LORA_SCK 5 -#define LORA_MISO 19 -#define LORA_MOSI 27 -#define LORA_CS RADIOLIB_NC // the ch341f spi controller does CS for us - -#define LORA_DIO0 26 // a No connect on the SX1262 module -#define LORA_RESET 14 -#define LORA_DIO1 33 // SX1262 IRQ, called DIO0 on pinelora schematic, pin 7 on ch341f "ack" - FIXME, enable hwints in linux -#define LORA_DIO2 32 // SX1262 BUSY, actually connected to "DIO5" on pinelora schematic, pin 8 on ch341f "slct" -#define LORA_DIO3 RADIOLIB_NC // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled - -#ifdef USE_SX1262 -#define SX126X_CS 20 // CS0 on pinelora schematic, hooked to gpio D0 on ch341f -#define SX126X_DIO1 LORA_DIO1 -#define SX126X_BUSY LORA_DIO2 -#define SX126X_RESET LORA_RESET -#define SX126X_DIO2_AS_RF_SWITCH -#endif - -#endif \ No newline at end of file +#define CANNED_MESSAGE_MODULE_ENABLE 1 +#define HAS_GPS 1 diff --git a/variants/rak11200/variant.h b/variants/rak11200/variant.h index 007ed8f152..3399594e53 100644 --- a/variants/rak11200/variant.h +++ b/variants/rak11200/variant.h @@ -56,6 +56,8 @@ static const uint8_t SCK = 33; #define LED_PIN LED_BLUE #define PIN_VBAT WB_A0 +#define BATTERY_PIN PIN_VBAT +#define ADC_CHANNEL ADC1_GPIO36_CHANNEL // https://docs.rakwireless.com/Product-Categories/WisBlock/RAK13300/ diff --git a/variants/rak11310/platformio.ini b/variants/rak11310/platformio.ini index a69b18c1a3..6495278bff 100644 --- a/variants/rak11310/platformio.ini +++ b/variants/rak11310/platformio.ini @@ -10,4 +10,6 @@ build_flags = ${rp2040_base.build_flags} -DDEBUG_RP2040_PORT=Serial -L "${platformio.libdeps_dir}/${this.__env__}/BSEC2 Software Library/src/cortex-m0plus" lib_deps = - ${rp2040_base.lib_deps} \ No newline at end of file + ${rp2040_base.lib_deps} +debug_build_flags = ${rp2040_base.build_flags} +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 6334157f53..ba3d4fed72 100644 --- a/variants/rak11310/variant.h +++ b/variants/rak11310/variant.h @@ -12,6 +12,7 @@ // #define EXT_NOTIFY_OUT 4 #define BATTERY_PIN 26 +#define BATTERY_SENSE_RESOLUTION_BITS ADC_RESOLUTION // ratio of voltage divider = 3.0 (R17=200k, R18=100k) #define ADC_MULTIPLIER 3.1 // 3.0 + a bit for being optimistic diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index 956bcd7721..cc18a901f6 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -254,7 +254,7 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG // Voltage divider value => 1.5M + 1M voltage divider on VBAT = (1.5M / (1M + 1.5M)) #define VBAT_DIVIDER (0.4F) // Compensation factor for the VBAT divider -#define VBAT_DIVIDER_COMP (1.73) +#define VBAT_DIVIDER_COMP (1.73F) // Fixed calculation of milliVolt from compensation value #define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) #undef AREF_VOLTAGE diff --git a/variants/rak4631_epaper/variant.h b/variants/rak4631_epaper/variant.h index bc2eddfee7..d8a5e55977 100644 --- a/variants/rak4631_epaper/variant.h +++ b/variants/rak4631_epaper/variant.h @@ -223,7 +223,7 @@ static const uint8_t SCK = PIN_SPI_SCK; // Voltage divider value => 1.5M + 1M voltage divider on VBAT = (1.5M / (1M + 1.5M)) #define VBAT_DIVIDER (0.4F) // Compensation factor for the VBAT divider -#define VBAT_DIVIDER_COMP (1.73) +#define VBAT_DIVIDER_COMP (1.73F) // Fixed calculation of milliVolt from compensation value #define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) #undef AREF_VOLTAGE diff --git a/variants/rp2040-lora/platformio.ini b/variants/rp2040-lora/platformio.ini new file mode 100644 index 0000000000..a1d6bea9d4 --- /dev/null +++ b/variants/rp2040-lora/platformio.ini @@ -0,0 +1,16 @@ +[env:rp2040-lora] +extends = rp2040_base +board = rpipico +upload_protocol = picotool + +# add our variants files to the include and src paths +build_flags = ${rp2040_base.build_flags} + -DRP2040_LORA + -Ivariants/rp2040-lora + -DDEBUG_RP2040_PORT=Serial + -DHW_SPI1_DEVICE + -L "${platformio.libdeps_dir}/${this.__env__}/BSEC2 Software Library/src/cortex-m0plus" +lib_deps = + ${rp2040_base.lib_deps} +debug_build_flags = ${rp2040_base.build_flags} +debug_tool = cmsis-dap ; for e.g. Picotool \ No newline at end of file diff --git a/variants/rp2040-lora/variant.h b/variants/rp2040-lora/variant.h new file mode 100644 index 0000000000..1f42c4db74 --- /dev/null +++ b/variants/rp2040-lora/variant.h @@ -0,0 +1,54 @@ +// #define RADIOLIB_CUSTOM_ARDUINO 1 +// #define RADIOLIB_TONE_UNSUPPORTED 1 +// #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED 1 + +#define ARDUINO_ARCH_AVR + +// #define USE_SH1106 1 + +// default I2C pins: +// SDA = 4 +// SCL = 5 + +// Recommended pins for SerialModule: +// txd = 8 +// rxd = 9 + +#define EXT_NOTIFY_OUT 22 +#define BUTTON_PIN 17 + +#define LED_PIN PIN_LED + +// #define BATTERY_PIN 26 +// ratio of voltage divider = 3.0 (R17=200k, R18=100k) +// #define ADC_MULTIPLIER 3.1 // 3.0 + a bit for being optimistic + +#define USE_SX1262 + +#undef LORA_SCK +#undef LORA_MISO +#undef LORA_MOSI +#undef LORA_CS + +// https://www.waveshare.com/rp2040-lora.htm +// https://www.waveshare.com/img/devkit/RP2040-LoRa-HF/RP2040-LoRa-HF-details-11.jpg +#define LORA_SCK 14 // 10 +#define LORA_MISO 24 // 12 +#define LORA_MOSI 15 // 11 +#define LORA_CS 13 // 3 + +#define LORA_DIO0 RADIOLIB_NC +#define LORA_RESET 23 // 15 +#define LORA_DIO1 16 // 20 +#define LORA_DIO2 18 // 2 +#define LORA_DIO3 RADIOLIB_NC +#define LORA_DIO4 17 + +#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 \ No newline at end of file diff --git a/variants/rpipico/platformio.ini b/variants/rpipico/platformio.ini index 727a1cab66..9537694ec9 100644 --- a/variants/rpipico/platformio.ini +++ b/variants/rpipico/platformio.ini @@ -11,4 +11,6 @@ build_flags = ${rp2040_base.build_flags} -DHW_SPI1_DEVICE -L "${platformio.libdeps_dir}/${this.__env__}/BSEC2 Software Library/src/cortex-m0plus" lib_deps = - ${rp2040_base.lib_deps} \ No newline at end of file + ${rp2040_base.lib_deps} +debug_build_flags = ${rp2040_base.build_flags} +debug_tool = cmsis-dap ; for e.g. Picotool \ No newline at end of file diff --git a/variants/rpipico/variant.h b/variants/rpipico/variant.h index aeda3d8331..ad6d0b2116 100644 --- a/variants/rpipico/variant.h +++ b/variants/rpipico/variant.h @@ -22,6 +22,7 @@ #define BATTERY_PIN 26 // ratio of voltage divider = 3.0 (R17=200k, R18=100k) #define ADC_MULTIPLIER 3.1 // 3.0 + a bit for being optimistic +#define BATTERY_SENSE_RESOLUTION_BITS ADC_RESOLUTION #define USE_SX1262 diff --git a/variants/rpipicow/platformio.ini b/variants/rpipicow/platformio.ini index 4c8cf992df..29b5c8bcbb 100644 --- a/variants/rpipicow/platformio.ini +++ b/variants/rpipicow/platformio.ini @@ -14,4 +14,6 @@ build_flags = ${rp2040_base.build_flags} build_src_filter = ${rp2040_base.build_src_filter} + lib_deps = ${rp2040_base.lib_deps} - ${networking_base.lib_deps} \ No newline at end of file + ${networking_base.lib_deps} +debug_build_flags = ${rp2040_base.build_flags} +debug_tool = cmsis-dap ; for e.g. Picotool \ No newline at end of file diff --git a/variants/rpipicow/variant.h b/variants/rpipicow/variant.h index c48b901ac4..27117680f8 100644 --- a/variants/rpipicow/variant.h +++ b/variants/rpipicow/variant.h @@ -24,6 +24,7 @@ #define BATTERY_PIN 26 // ratio of voltage divider = 3.0 (R17=200k, R18=100k) #define ADC_MULTIPLIER 3.1 // 3.0 + a bit for being optimistic +#define BATTERY_SENSE_RESOLUTION_BITS ADC_RESOLUTION #define USE_SX1262 diff --git a/variants/senselora_rp2040/variant.h b/variants/senselora_rp2040/variant.h index 9eda655210..2f68cf0344 100644 --- a/variants/senselora_rp2040/variant.h +++ b/variants/senselora_rp2040/variant.h @@ -8,6 +8,7 @@ #define LED_PIN PIN_LED #undef BATTERY_PIN +#define BATTERY_SENSE_RESOLUTION_BITS ADC_RESOLUTION #undef LORA_SCK #undef LORA_MISO diff --git a/variants/station-g1/variant.h b/variants/station-g1/variant.h index e58853fb7d..9a3c37b735 100644 --- a/variants/station-g1/variant.h +++ b/variants/station-g1/variant.h @@ -37,10 +37,8 @@ #define ADC_CHANNEL ADC1_GPIO35_CHANNEL #define BATTERY_SENSE_SAMPLES 30 // Set the number of samples, It has an effect of increasing sensitivity. #define ADC_MULTIPLIER 6.45 -#define BAT_FULLVOLT 12600 -#define BAT_EMPTYVOLT 8200 -#define BAT_CHARGINGVOLT 12600 -#define BAT_NOBATVOLT 6690 +#define CELL_TYPE_LION // same curve for liion/lipo +#define NUM_CELLS 3 // different screen #define USE_SH1106 diff --git a/variants/t-echo/platformio.ini b/variants/t-echo/platformio.ini index 2555032dfc..843bd88ff0 100644 --- a/variants/t-echo/platformio.ini +++ b/variants/t-echo/platformio.ini @@ -6,6 +6,7 @@ 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/t-echo + -DGPS_POWER_TOGGLE -L "${platformio.libdeps_dir}/${this.__env__}/BSEC2 Software Library/src/cortex-m4/fpv4-sp-d16-hard" build_src_filter = ${nrf52_base.build_src_filter} +<../variants/t-echo> lib_deps = diff --git a/variants/t-echo/variant.h b/variants/t-echo/variant.h index 6bd5091dd0..345091c2fa 100644 --- a/variants/t-echo/variant.h +++ b/variants/t-echo/variant.h @@ -43,9 +43,9 @@ extern "C" { #define NUM_ANALOG_OUTPUTS (0) // LEDs -#define PIN_LED1 (0 + 14) // 13 red (confirmed on 1.0 board) -#define PIN_LED2 (0 + 15) // 14 blue -#define PIN_LED3 (0 + 13) // 15 green +#define PIN_LED1 (0 + 14) // blue (confirmed on boards marked v1.0, date 2021-6-28) +#define PIN_LED2 (32 + 1) // green +#define PIN_LED3 (32 + 3) // red #define LED_RED PIN_LED3 #define LED_BLUE PIN_LED1 @@ -213,7 +213,7 @@ External serial flash WP25R1635FZUIL0 // Voltage divider value => 100K + 100K voltage divider on VBAT = (100K / (100K + 100K)) #define VBAT_DIVIDER (0.5F) // Compensation factor for the VBAT divider -#define VBAT_DIVIDER_COMP (2.0) +#define VBAT_DIVIDER_COMP (2.0F) // Fixed calculation of milliVolt from compensation value #define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) #undef AREF_VOLTAGE @@ -232,4 +232,4 @@ External serial flash WP25R1635FZUIL0 * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif +#endif \ No newline at end of file diff --git a/variants/tlora_v2_1_16/variant.h b/variants/tlora_v2_1_16/variant.h index b8c43e5572..8bb5ce3b1c 100644 --- a/variants/tlora_v2_1_16/variant.h +++ b/variants/tlora_v2_1_16/variant.h @@ -16,5 +16,13 @@ #define USE_RF95 #define LORA_DIO0 26 // a No connect on the SX1262 module #define LORA_RESET 23 + +// In the T3 V1.6.1 TXCO version, GPIO 33 is connected to Radio’s +// internal temperature-compensated crystal oscillator enable +#ifdef LORA_TCXO_GPIO +#define LORA_DIO1 RADIOLIB_NC // no-connect on sx127x module +#else #define LORA_DIO1 33 // https://www.thethingsnetwork.org/forum/t/big-esp32-sx127x-topic-part-3/18436 +#endif + #define LORA_DIO2 32 // Not really used \ No newline at end of file diff --git a/variants/tlora_v2_1_16_tcxo/platformio.ini b/variants/tlora_v2_1_16_tcxo/platformio.ini new file mode 100644 index 0000000000..e54c1a9207 --- /dev/null +++ b/variants/tlora_v2_1_16_tcxo/platformio.ini @@ -0,0 +1,9 @@ +[env:tlora-v2-1-1_6-tcxo] +extends = esp32_base +board = ttgo-lora32-v21 +build_flags = + ${esp32_base.build_flags} + -D TLORA_V2_1_16 + -I variants/tlora_v2_1_16 + -D GPS_POWER_TOGGLE ; comment this line to disable triple press function on the user button to turn off gps entirely. + -D LORA_TCXO_GPIO=33 \ No newline at end of file diff --git a/version.properties b/version.properties index c95d5701ab..ed7e931545 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 2 -build = 16 +build = 24