+12



![github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)





Tom Fifield
GitHub
Mike
Ben Meadors
Mike G
github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
thebentern
GUVWAF
Warren Guy
todd-herbert
geeksville
Jonathan Bennett
Alexander
Thomas Göttgens
quimnut
Manuel
Agent Blu, 006 <blu006@ucr.edu>
Mark Trevor Birss
Aaron.Lee
Daniel.Cao
BIST
slash-bit
5cc8ca59a3
* Fix protobuf structs handling (#4140) * Fix protobuf structs handling * Log instead of assert --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * BLE based logging (#4146) * WIP log characteristic * Bluetooth logging plumbing * Characteristic * Callback * Check for nullptr * Esp32 bluetooth impl * Formatting * Add thread name and log level * Add settings guard * Remove comments * Field name * Fixes esp32 * Open it up * Whoops * Move va_end past our logic * Use `upload_protocol = esptool` as with the other heltec devices instead of `esp-builtin` (#4151) * Standardize lat/lon position logs (#4156) * Standardize lat/lon position logs * Missed sone and condensed logs * [create-pull-request] automated change (#4157) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> * Pause BLE logging during want_config flow (#4162) * Update NimBLE to 1.4.2 (#4163) * Implement replies for all telemetry types based on variant tag (#4164) * Implement replies for all telemetry types based on variant tag * Remove check for `ignoreRequest`: modules can set this, don't need to check --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * Esptool is better * Explicitly set characteristic * fix INA3221 sensor (#4168) - pass wire to begin() - remove redundant setAddr() (already set in header) * Show compass on waypoint frame; clear when waypoint deleted (#4116) * Clear expired or deleted waypoint frame * Return 0 to CallbackObserver * Add a missing comment * Draw compass for waypoint frame * Display our own waypoints * [create-pull-request] automated change (#4171) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> * Add semihosting support for nrf52 devices (#4137) * Turn off vscode cmake prompt - we don't use cmake on meshtastic * Add rak4631_dap variant for debugging with NanoDAP debug probe device. * The rak device can also run freertos (which is underneath nrf52 arduino) * Add semihosting support for nrf52840 devices Initial platformio.ini file only supports rak4630 Default to non TCP for the semihosting log output for now... Fixes https://github.com/meshtastic/firmware/issues/4135 * fix my botched merge - keep board_level = extra flag for rak3631_dbg --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * [create-pull-request] automated change (#4174) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> * Display alerts (#4170) * Move static functions into Screen.h, show compass during calibration * Move to _fontHeight macro to avoid collision * Move some alert functions to new alert handler * Catch missed reboot code * ESP32 fixes * Bump esp8266-oled-ssd1306 * Fixes for when a device has no screen * Use new startAlert(char*) helper class * Add EINK bits back to alert handling * Add noop class for no-display devices --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * Send file system manifest up on want_config (#4176) * Send file system manifest up on want_config * Platform specific methods * Helps to actually make the change * Clear * tell vscode, if formatting, use whatever our trunk formatter wants (#4186) without this flag if the user has set some other formatter (clang) in their user level settings, it will be looking in the wrong directory for the clang options (we want the options in .trunk/clang) Note: formatOnSave is true in master, which means a bunch of our older files are non compliant and if you edit them it will generate lots of formatting related diffs. I guess I'll start letting that happen with my future commits ;-). * fix the build - would loop forever if there were no files to send (#4188) * Show owner.short_name on boot (and E-Ink sleep screen) (#4134) * Show owner.short_name on boot and sleep screen (on e-ink) * Update Screen.cpp - new line for short_name Boot screen short_name now below the region setting. Looks better on small screens. * Draw short_name on right --------- Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com> Co-authored-by: todd-herbert <herbert.todd@gmail.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * nrf52 soft device will watchdog if you use ICE while BT on... (#4189) so have debugger disable bluetooth. * correct xiao_ble build preventing sx1262 init (#4191) * Force a compile time failur if FromRadio or ToRadio get larger than (#4190) a BLE packet size. We are actually very close to this threshold so important to make sure we don't accidentally pass it. * Clear vector after complete config state (#4194) * Clear after complete config * Don't collect . entries * Log file name and size * [create-pull-request] automated change (#4200) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> * Make the logs Colorful! (#4199) * Squash needlessly static functions (#4183) * Trim extra vprintf and filter for unprintable characters * Deprecate Router Client role (and make it Client) (#4201) * [create-pull-request] automated change (#4205) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> * Move waypoint (#4202) * Move waypoint screen draw into the waypoint module * Get the observer set up for the waypoint screen draw * Static squashing: screen dimensions Macros moved back to Screen.cpp, as a band-aid until we eventually move all those static functions into the Screen class. * Move getCompassDiam into Screen class (supress compiler warnings) At this stage, the method is still static, because it's used by drawNodeInfo, which has no tidy reference to our screen instance. This is probably just another band-aid until these static functions all move. * Use new getCompassDiam function in AccelerometerThread * Properly gate display code in WaypointModule --------- Co-authored-by: Todd Herbert <herbert.todd@gmail.com> * Fix flakey phone api transition from file manifest to complete (#4209) * Try fix flakey phone api transition from file manifest to complete * Skip * enable colors in platformio serial monitor (#4217) * When talking via serial, encapsulate log messages in protobufs if necessary (#4187) * clean up RedirectablePrint::log so it doesn't have three very different implementations inline. * remove NoopPrint - it is no longer needed * when talking to API clients via serial, don't turn off log msgs instead encapsuate them * fix the build - would loop forever if there were no files to send * don't use Segger code if not talking to a Segger debugger * when encapsulating logs, make sure the strings always has nul terminators * nrf52 soft device will watchdog if you use ICE while BT on... so have debugger disable bluetooth. * Important to not print debug messages while writing to the toPhone scratch buffer * don't include newlines if encapsulating log records as protobufs --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * [create-pull-request] automated change (#4218) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> * Fix SHT41 support (#4222) * Add SHT41 Serial to I2c Detection Code On the Seeed Wio-WM1110 Dev Kit board, the SHT41 chip was being incorrectly detected as SHT31. This patch adds the necessary serial number for the SHT41 chip to be correctly detected. fixes meshtastic/firmware#4221 * Add missing sensor read for SHT41 * Typo fix in logs - mhz - MHz (#4225) As reported by karamo, a few different places in our logs had incorrect capitalization of MHz. fixes meshtastic/firmware#4126 * New new BLE logging characteristic with LogRecord protos (#4220) * New UUID * New log radio characteristic with LogRecord protobuf * LogRecord * Merge derp * How did you get there * Trunk * Fix length * Remove assert * minor cleanup proposal (#4169) * MESHTASTIC_EXCLUDE_WIFI and HAS_WIFI cleanup... Our code was checking HAS_WIFI and the new MESHTASTIC_EXCLUDE_WIFI flags in various places (even though EXCLUDE_WIFI forces HAS_WIFI to 0). Instead just check HAS_WIFI, only use EXCLUDE_WIFI inside configuration.h * cleanup: use HAS_NETWORKING instead of HAS_WIFI || HAS_ETHERNET We already had HAS_NETWORKING as flag in MQTT to mean 'we have tcpip'. Generallize that and move it into configuration.h so that we can use it elsewhere. * Use #pragma once, because supported by gcc and all modern compilers instead of #ifdef DOTHFILE_H etc... --------- Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz> * Add PowerMon support (#4155) * Turn off vscode cmake prompt - we don't use cmake on meshtastic * Add rak4631_dap variant for debugging with NanoDAP debug probe device. * The rak device can also run freertos (which is underneath nrf52 arduino) * Add semihosting support for nrf52840 devices Initial platformio.ini file only supports rak4630 Default to non TCP for the semihosting log output for now... Fixes https://github.com/meshtastic/firmware/issues/4135 * powermon WIP (for https://github.com/meshtastic/firmware/issues/4136 ) * oops - mean't to mark the _dbg variant as an 'extra' board. * powermon wip * Make serial port on wio-sdk-wm1110 board work By disabling the (inaccessible) adafruit USB * Instrument (radiolib only for now) lora for powermon per https://github.com/meshtastic/firmware/issues/4136 * powermon gps support https://github.com/meshtastic/firmware/issues/4136 * Add CPU deep and light sleep powermon states https://github.com/meshtastic/firmware/issues/4136 * Change the board/swversion bootstring so it is a new "structured" log msg. * powermon wip * add example script for getting esp S3 debugging working Not yet used but I didn't want these nasty tricks to get lost yet. * Add PowerMon reporting for screen and bluetooth pwr. * make power.powermon_enables config setting work. * update to latest protobufs * fix bogus shellcheck warning * make powermon optional (but default enabled because tiny and no runtime impact) * tell vscode, if formatting, use whatever our trunk formatter wants without this flag if the user has set some other formatter (clang) in their user level settings, it will be looking in the wrong directory for the clang options (we want the options in .trunk/clang) Note: formatOnSave is true in master, which means a bunch of our older files are non compliant and if you edit them it will generate lots of formatting related diffs. I guess I'll start letting that happen with my future commits ;-). * add PowerStress module * nrf52 arduino is built upon freertos, so let platformio debug it * don't accidentally try to Segger ICE if we are using another ICE * clean up RedirectablePrint::log so it doesn't have three very different implementations inline. * remove NoopPrint - it is no longer needed * when talking to API clients via serial, don't turn off log msgs instead encapsuate them * fix the build - would loop forever if there were no files to send * don't use Segger code if not talking to a Segger debugger * when encapsulating logs, make sure the strings always has nul terminators * nrf52 soft device will watchdog if you use ICE while BT on... so have debugger disable bluetooth. * Important to not print debug messages while writing to the toPhone scratch buffer * don't include newlines if encapsulating log records as protobufs * update to latest protobufs (needed for powermon goo) * PowerStress WIP * fix linter warning * Cleanup buffer * Merge hex for wm1110 target(s) * Only sdk * Sudo * Fix exclude macros (#4233) * fix MESHTASTIC_EXCLUDE_BLUETOOTH * fix HAS_SCREEN=0 * fix MESHTASTIC_EXCLUDE_GPS * fix typo in build-nrf52.sh (#4231) chmod is the command, '+x' is the argument. * Tidy Wireless Paper variant files (#4238) * Quick tidy of pins_arduino.h Matches requests made at https://github.com/meshtastic/firmware/pull/4226#discussion_r1664183480) * Tidy variant.h * Change deprecated ADC attenuation parameter From 11dB to 12dB. Resolves compiler warning. Allegly, no impact on function: `This is deprecated, it behaves the same as `ADC_ATTEN_DB_12` * Updated raspbian CI to update apt repository ahead of libbluetooth. (#4243) * Fix BLE logging on nrf52 (#4244) * allow ble logrecords to be fetched either by NOTIFY or INDICATE ble types This allows 'lossless' log reading. If client has requested INDICATE (rather than NOTIFY) each log record emitted via log() will have to fetched by the client device before the meshtastic node can continue. * Fix serious problem with nrf52 BLE logging. When doing notifies of LogRecords it is important to use the binary write routines - writing using the 'string' write won't work. Because protobufs can contain \0 nuls inside of them which if being parsed as a string will cause only a portion of the protobuf to be sent. I noticed this because some log messages were not getting through. --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * Fix build when HAS_NETWORKING is false on nrf52 (#4237) (tested on a rak4631 by setting HAS_ETHERNET false when shrinking image) * If `toPhoneQueue` is full, still increment `fromNum` to avoid client never getting packets (#4246) * Update to SoftDevice 7.3.0 for wio-sdk-wm1110 and wio-tracker-wm1110 (#4248) * Update variant.h * Update wio-tracker-wm1110.json * Update wio-sdk-wm1110.json * Update platformio.ini * Update platformio.ini * Add files via upload * Add files via upload * Update variant.h * Cleanup NRF s140 Softdevice variants (#4252) Note: This idea is originally from @caveman99 and should be credited as such. Submitting as a separate PR so the work in meshtastic/firmware#4148 can be a bit cleaner and Seeed boards can build while that work is ongoing. The nrf52 boards that depend on the v7 softdevice all use the same code and linker files. Rather than duplicate the code, keep it all together with the platform. * Remove tracker variant specific soft device headers (#4255) * [create-pull-request] automated change (#4247) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> * Add wio-sdk-wm1110 to build. (#4258) The wio-sdk-wm1110 is distinct from the wio-tracker-wm1110, with different platformio build options and pin config. This change adds the wio-sdk-wm1110 to the CI matrix so firmware is built as part of release. * fix python warning in uf2conf (#4235) the old regex worked but was technically incorrect. fixes: Generating NRF52 uf2 file /home/kevinh/development/meshtastic/firmware/bin/uf2conv.py:195: SyntaxWarning: invalid escape sequence '\s' words = re.split('\s+', line) Converting to uf2, output size: 1458688, start address: 0x26000 * Collect hex files and specifically wm1110 sdk * Skip dfu file for sdk (for now) * Helps if you remove the original clause * Add Heltec new boards. (#4226) * Add Heltec new boards * Update variant.h disable RTC by default * Add Heltec New boards * Add Heltec new boards * Update Heltec Mesh Node definition. * Update Heltec Vision Mater E290 * [create-pull-request] automated change (#4259) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> * Trunk fmt * Fix macros * Move e290 to board level extra while CI is broken * Tell trunk to ignore bin folder * Fix missing * Update trunk.yaml, fix whitespace * Update trunk.yaml * Update build_raspbian_armv7l.yml --fix-missing * [create-pull-request] automated change (#4263) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> * GPS Power State tidy-up (#4161) * Refactor GPSPowerState enum Identifies a case where the GPS hardware is awake, but an update is not yet desired * Change terminology * Clear old lock-time prediction on triple press * Use exponential smoothing to predict lock time * Rename averageLockTime to predictedLockTime * Attempt: Send PMREQ with duration 0 on MCU deep-sleep * Attempt 2: Send PMREQ with duration 0 on MCU deep-sleep * Revert "Attempt 2: Send PMREQ with duration 0 on MCU deep-sleep" This reverts commit 8b697cd2a445355dcfab5b33e0ce7a3128cab151. * Revert "Attempt: Send PMREQ with duration 0 on MCU deep-sleep" This reverts commit 9d29ec7603a88056b9115796b29b5023165a93bb. * Remove unused notifyGPSSleep Observable Handled with notifyDeepSleep, and enable() / disable() * WIP: simplify GPS power management An initial attempt only. * Honor #3e9e0fd * No-op when moving between GPS_IDLE and GPS_ACTIVE * Ensure U-blox GPS is awake to receive indefinite sleep command * Longer pause when waking U-blox to send sleep command * Actually implement soft and hard sleep.. * Dynamically estimate the threshold for GPS_HARDSLEEP * Fallback to GPS_HARDSLEEP, if GPS_SOFTSLEEP unsupported * Move "excessive search time" behavior to scheduler class * Minor logging adjustments * Promote log to warning * Gratuitous buffer clearing on boot * Fix inverted standby pin logic Specifically the standby pin for L76B, L76K and clones Discovered during T-Echo testing: totally broken function, probe method failing. * Remove redundant pin init Now handled by setPowerState * Replace max() with if statements Avoid those platform specific implementations.. * Trunk formatting New round of settings.json changes keep catching me out, have to remember to re-enable my "clang-format" for windows workaround. * Remove some asserts from setPowerState Original aim was to prevent sending a 0 second PMREQ to U-blox hardware as part of a timed sleep (GPS_HARDSLEEP, GPS_SOFTSLEEP). I'm not sure this is super important, and it feels tidier to just allow the 0 second sleeptime here, rather than fudge the sleeptime further up. * Fix an error determining whether GPS_SOFTSLEEP is supported * Clarify a log entry * Set PIN_STANDBY for MCU deep-sleep Required to reach TTGO's advertised 0.25mA sleep current for T-Echo. Without this change: ~6mA. * Optimize the shutdown current of RAK10701 to around 25uA (#4260) Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz> * INA3221 sensor: use for bus voltage & environment metrics (#4215) * use INA3221 for bus voltage; fixes for telemetry variants - add to sensors available for environment telemetry (to report voltage/current) - add vars to define channels to use for battery voltage (for getBusVoltage) and environment metrics (default to CH1 for both) - write to the correct fields on the measurement struct depending on the measurement variant, and DRY up the sensor measurement collection code a bit - this might be suitable for a common implementation for the INA* sensors in a future PR... * formatting * derp --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> * WM1110 SDK kit enter serial DFU and add deployment packages (#4266) * Switch default upload protocol to nrfutil so that pio generates zip deploy packages * Enter serial DFU on SDK board * Remove guard for DFU zip from SDK build * NRF_USE_SERIAL_DFU macro instead * Show specific frame when updating screen (#4264) * Updated setFrames in Screen.cpp Added code to attempt to revert back to the same frame that user was on prior to setFrame reload. * Space added Screen.cpp * Update Screen.cpp Make screen to revert to Frame 0 if the originally displayed frame is no longer there. * Update Screen.cpp Inserted boolean holdPosition into setFrames to indicate the requirement to stay on the same frame ( if =true) or else it will switch to new frame . Only Screen::handleStatusUpdate calls with setFrame(true). ( For Node Updates) All other types of updates call as before setFrame(), so it will change focus as needed. * Hold position, even if number of frames increases * Hold position, if handling an outgoing text message * Update Screen.cpp * Reverted chnages related to devicestate.has_rx_text_message * Reset to master * CannedMessages only handles routing packets when waiting for ACK Previously, this was calling Screen::setFrames at unexpected times * Gather position info about screen frames while regenerating * Make admin module observable Notify only when relevant. Currently: only to handle remove_nodenum. * Optionally specify which frame to focus when setFrames runs * UIFrameEvent uses enum instead of multiple booleans * Allow modules to request their own frame to be focussed This is done internally by calling MeshModule::requestFocus() Easier this way, insteady of passing the info in the UIFrameEvent: * Modules don't always know whether they should be focussed until after the UIFrameEvent has been raised, in dramFrame * Don't have to pass reference to module instance as parameter though several methods * E-Ink screensaver uses FOCUS_PRESERVE Previously, it had its own basic implementation of this. * Spelling: regional variant * trunk * Fix HAS_SCREEN guarding * More HAS_SCREEN guarding --------- Co-authored-by: BIST <77391720+slash-bit@users.noreply.github.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: slash-bit <v-b2@live.com> * Move up telemetry defaults to every 30 minutes (#4274) * Don't send node info interrogation when ch. util is >25% (#4273) * Moar LR1110 Targets * update SD_FLASH_SIZE to 0x27000 (#4232) The 7.3.0 softdevice needs the extra 1000 :) * Fix spacing. --------- Co-authored-by: Mike <mikhael.skvortsov@gmail.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: Mike G <mkgin@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> Co-authored-by: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Co-authored-by: Warren Guy <5602790+warrenguy@users.noreply.github.com> Co-authored-by: todd-herbert <herbert.todd@gmail.com> Co-authored-by: geeksville <kevinh@geeksville.com> Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz> Co-authored-by: Alexander <156134901+Dorn8010@users.noreply.github.com> Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com> Co-authored-by: quimnut <github@dopegoat.com> Co-authored-by: Manuel <71137295+mverch67@users.noreply.github.com> Co-authored-by: Agent Blu, 006 <blu006@ucr.edu> Co-authored-by: Mark Trevor Birss <markbirss@gmail.com> Co-authored-by: Aaron.Lee <32860565+Heltec-Aaron-Lee@users.noreply.github.com> Co-authored-by: Daniel.Cao <144674500+DanielCao0@users.noreply.github.com> Co-authored-by: BIST <77391720+slash-bit@users.noreply.github.com> Co-authored-by: slash-bit <v-b2@live.com>
549 lines
18 KiB
C++
549 lines
18 KiB
C++
#pragma once
|
||
|
||
#include "configuration.h"
|
||
|
||
#include "detect/ScanI2C.h"
|
||
#include "mesh/generated/meshtastic/config.pb.h"
|
||
#include <OLEDDisplay.h>
|
||
|
||
#if !HAS_SCREEN
|
||
#include "power.h"
|
||
namespace graphics
|
||
{
|
||
// Noop class for boards without screen.
|
||
class Screen
|
||
{
|
||
public:
|
||
explicit Screen(ScanI2C::DeviceAddress, meshtastic_Config_DisplayConfig_OledType, OLEDDISPLAY_GEOMETRY);
|
||
void onPress() {}
|
||
void setup() {}
|
||
void setOn(bool) {}
|
||
void print(const char *) {}
|
||
void doDeepSleep() {}
|
||
void forceDisplay(bool forceUiUpdate = false) {}
|
||
void startFirmwareUpdateScreen() {}
|
||
void increaseBrightness() {}
|
||
void decreaseBrightness() {}
|
||
void setFunctionSymbal(std::string) {}
|
||
void removeFunctionSymbal(std::string) {}
|
||
void startAlert(const char *) {}
|
||
void endAlert() {}
|
||
};
|
||
} // namespace graphics
|
||
#else
|
||
#include <cstring>
|
||
|
||
#include <OLEDDisplayUi.h>
|
||
|
||
#include "../configuration.h"
|
||
#include "gps/GeoCoord.h"
|
||
#include "graphics/ScreenFonts.h"
|
||
|
||
#ifdef USE_ST7567
|
||
#include <ST7567Wire.h>
|
||
#elif defined(USE_SH1106) || defined(USE_SH1107) || defined(USE_SH1107_128_64)
|
||
#include <SH1106Wire.h>
|
||
#elif defined(USE_SSD1306)
|
||
#include <SSD1306Wire.h>
|
||
#elif defined(USE_ST7789)
|
||
#include <ST7789Spi.h>
|
||
#else
|
||
// the SH1106/SSD1306 variant is auto-detected
|
||
#include <AutoOLEDWire.h>
|
||
#endif
|
||
|
||
#include "EInkDisplay2.h"
|
||
#include "EInkDynamicDisplay.h"
|
||
#include "PointStruct.h"
|
||
#include "TFTDisplay.h"
|
||
#include "TypedQueue.h"
|
||
#include "commands.h"
|
||
#include "concurrency/LockGuard.h"
|
||
#include "concurrency/OSThread.h"
|
||
#include "input/InputBroker.h"
|
||
#include "mesh/MeshModule.h"
|
||
#include "power.h"
|
||
#include <string>
|
||
|
||
// 0 to 255, though particular variants might define different defaults
|
||
#ifndef BRIGHTNESS_DEFAULT
|
||
#define BRIGHTNESS_DEFAULT 150
|
||
#endif
|
||
|
||
// Meters to feet conversion
|
||
#ifndef METERS_TO_FEET
|
||
#define METERS_TO_FEET 3.28
|
||
#endif
|
||
|
||
// Feet to miles conversion
|
||
#ifndef MILES_TO_FEET
|
||
#define MILES_TO_FEET 5280
|
||
#endif
|
||
|
||
// Intuitive colors. E-Ink display is inverted from OLED(?)
|
||
#define EINK_BLACK OLEDDISPLAY_COLOR::WHITE
|
||
#define EINK_WHITE OLEDDISPLAY_COLOR::BLACK
|
||
|
||
// Base segment dimensions for T-Watch segmented display
|
||
#define SEGMENT_WIDTH 16
|
||
#define SEGMENT_HEIGHT 4
|
||
|
||
/// Convert an integer GPS coords to a floating point
|
||
#define DegD(i) (i * 1e-7)
|
||
|
||
namespace
|
||
{
|
||
/// A basic 2D point class for drawing
|
||
class Point
|
||
{
|
||
public:
|
||
float x, y;
|
||
|
||
Point(float _x, float _y) : x(_x), y(_y) {}
|
||
|
||
/// Apply a rotation around zero (standard rotation matrix math)
|
||
void rotate(float radian)
|
||
{
|
||
float cos = cosf(radian), sin = sinf(radian);
|
||
float rx = x * cos + y * sin, ry = -x * sin + y * cos;
|
||
|
||
x = rx;
|
||
y = ry;
|
||
}
|
||
|
||
void translate(int16_t dx, int dy)
|
||
{
|
||
x += dx;
|
||
y += dy;
|
||
}
|
||
|
||
void scale(float f)
|
||
{
|
||
// We use -f here to counter the flip that happens
|
||
// on the y axis when drawing and rotating on screen
|
||
x *= f;
|
||
y *= -f;
|
||
}
|
||
};
|
||
|
||
} // namespace
|
||
|
||
namespace graphics
|
||
{
|
||
|
||
// Forward declarations
|
||
class Screen;
|
||
|
||
/// Handles gathering and displaying debug information.
|
||
class DebugInfo
|
||
{
|
||
public:
|
||
DebugInfo(const DebugInfo &) = delete;
|
||
DebugInfo &operator=(const DebugInfo &) = delete;
|
||
|
||
private:
|
||
friend Screen;
|
||
|
||
DebugInfo() {}
|
||
|
||
/// Renders the debug screen.
|
||
void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
||
void drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
||
void drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
||
|
||
/// Protects all of internal state.
|
||
concurrency::Lock lock;
|
||
};
|
||
|
||
/**
|
||
* @brief This class deals with showing things on the screen of the device.
|
||
*
|
||
* @details Other than setup(), this class is thread-safe as long as drawFrame is not called
|
||
* multiple times simultaneously. All state-changing calls are queued and executed
|
||
* when the main loop calls us.
|
||
*/
|
||
class Screen : public concurrency::OSThread
|
||
{
|
||
CallbackObserver<Screen, const meshtastic::Status *> powerStatusObserver =
|
||
CallbackObserver<Screen, const meshtastic::Status *>(this, &Screen::handleStatusUpdate);
|
||
CallbackObserver<Screen, const meshtastic::Status *> gpsStatusObserver =
|
||
CallbackObserver<Screen, const meshtastic::Status *>(this, &Screen::handleStatusUpdate);
|
||
CallbackObserver<Screen, const meshtastic::Status *> nodeStatusObserver =
|
||
CallbackObserver<Screen, const meshtastic::Status *>(this, &Screen::handleStatusUpdate);
|
||
CallbackObserver<Screen, const meshtastic_MeshPacket *> textMessageObserver =
|
||
CallbackObserver<Screen, const meshtastic_MeshPacket *>(this, &Screen::handleTextMessage);
|
||
CallbackObserver<Screen, const UIFrameEvent *> uiFrameEventObserver =
|
||
CallbackObserver<Screen, const UIFrameEvent *>(this, &Screen::handleUIFrameEvent); // Sent by Mesh Modules
|
||
CallbackObserver<Screen, const InputEvent *> inputObserver =
|
||
CallbackObserver<Screen, const InputEvent *>(this, &Screen::handleInputEvent);
|
||
CallbackObserver<Screen, const meshtastic_AdminMessage *> adminMessageObserver =
|
||
CallbackObserver<Screen, const meshtastic_AdminMessage *>(this, &Screen::handleAdminMessage);
|
||
|
||
public:
|
||
explicit Screen(ScanI2C::DeviceAddress, meshtastic_Config_DisplayConfig_OledType, OLEDDISPLAY_GEOMETRY);
|
||
|
||
~Screen();
|
||
|
||
Screen(const Screen &) = delete;
|
||
Screen &operator=(const Screen &) = delete;
|
||
|
||
ScanI2C::DeviceAddress address_found;
|
||
meshtastic_Config_DisplayConfig_OledType model;
|
||
OLEDDISPLAY_GEOMETRY geometry;
|
||
|
||
/// Initializes the UI, turns on the display, starts showing boot screen.
|
||
//
|
||
// Not thread safe - must be called before any other methods are called.
|
||
void setup();
|
||
|
||
/// Turns the screen on/off. Optionally, pass a custom screensaver frame for E-Ink
|
||
void setOn(bool on, FrameCallback einkScreensaver = NULL)
|
||
{
|
||
if (!on)
|
||
// We handle off commands immediately, because they might be called because the CPU is shutting down
|
||
handleSetOn(false, einkScreensaver);
|
||
else
|
||
enqueueCmd(ScreenCmd{.cmd = Cmd::SET_ON});
|
||
}
|
||
|
||
/**
|
||
* Prepare the display for the unit going to the lowest power mode possible. Most screens will just
|
||
* poweroff, but eink screens will show a "I'm sleeping" graphic, possibly with a QR code
|
||
*/
|
||
void doDeepSleep();
|
||
|
||
void blink();
|
||
|
||
void drawFrameText(OLEDDisplay *, OLEDDisplayUiState *, int16_t, int16_t, const char *);
|
||
|
||
void getTimeAgoStr(uint32_t agoSecs, char *timeStr, uint8_t maxLength);
|
||
|
||
// Draw north
|
||
void drawCompassNorth(OLEDDisplay *display, int16_t compassX, int16_t compassY, float myHeading);
|
||
|
||
static uint16_t getCompassDiam(uint32_t displayWidth, uint32_t displayHeight);
|
||
|
||
float estimatedHeading(double lat, double lon);
|
||
|
||
void drawNodeHeading(OLEDDisplay *display, int16_t compassX, int16_t compassY, uint16_t compassDiam, float headingRadian);
|
||
|
||
void drawColumns(OLEDDisplay *display, int16_t x, int16_t y, const char **fields);
|
||
|
||
/// Handle button press, trackball or swipe action)
|
||
void onPress() { enqueueCmd(ScreenCmd{.cmd = Cmd::ON_PRESS}); }
|
||
void showPrevFrame() { enqueueCmd(ScreenCmd{.cmd = Cmd::SHOW_PREV_FRAME}); }
|
||
void showNextFrame() { enqueueCmd(ScreenCmd{.cmd = Cmd::SHOW_NEXT_FRAME}); }
|
||
|
||
// generic alert start
|
||
void startAlert(FrameCallback _alertFrame)
|
||
{
|
||
alertFrame = _alertFrame;
|
||
ScreenCmd cmd;
|
||
cmd.cmd = Cmd::START_ALERT_FRAME;
|
||
enqueueCmd(cmd);
|
||
}
|
||
|
||
void startAlert(const char *_alertMessage)
|
||
{
|
||
startAlert([_alertMessage](OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) -> void {
|
||
uint16_t x_offset = display->width() / 2;
|
||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||
display->setFont(FONT_MEDIUM);
|
||
display->drawString(x_offset + x, 26 + y, _alertMessage);
|
||
});
|
||
}
|
||
|
||
void endAlert()
|
||
{
|
||
ScreenCmd cmd;
|
||
cmd.cmd = Cmd::STOP_ALERT_FRAME;
|
||
enqueueCmd(cmd);
|
||
}
|
||
|
||
void startFirmwareUpdateScreen()
|
||
{
|
||
ScreenCmd cmd;
|
||
cmd.cmd = Cmd::START_FIRMWARE_UPDATE_SCREEN;
|
||
enqueueCmd(cmd);
|
||
}
|
||
|
||
// Function to allow the AccelerometerThread to set the heading if a sensor provides it
|
||
// Mutex needed?
|
||
void setHeading(long _heading)
|
||
{
|
||
hasCompass = true;
|
||
compassHeading = _heading;
|
||
}
|
||
|
||
bool hasHeading() { return hasCompass; }
|
||
|
||
long getHeading() { return compassHeading; }
|
||
// functions for display brightness
|
||
void increaseBrightness();
|
||
void decreaseBrightness();
|
||
|
||
void setFunctionSymbal(std::string sym);
|
||
void removeFunctionSymbal(std::string sym);
|
||
|
||
/// Stops showing the boot screen.
|
||
void stopBootScreen() { enqueueCmd(ScreenCmd{.cmd = Cmd::STOP_BOOT_SCREEN}); }
|
||
|
||
/// Writes a string to the screen.
|
||
void print(const char *text)
|
||
{
|
||
ScreenCmd cmd;
|
||
cmd.cmd = Cmd::PRINT;
|
||
// TODO(girts): strdup() here is scary, but we can't use std::string as
|
||
// FreeRTOS queue is just dumbly copying memory contents. It would be
|
||
// nice if we had a queue that could copy objects by value.
|
||
cmd.print_text = strdup(text);
|
||
if (!enqueueCmd(cmd)) {
|
||
free(cmd.print_text);
|
||
}
|
||
}
|
||
|
||
/// generates a very brief time delta display
|
||
std::string drawTimeDelta(uint32_t days, uint32_t hours, uint32_t minutes, uint32_t seconds);
|
||
|
||
/// Overrides the default utf8 character conversion, to replace empty space with question marks
|
||
static char customFontTableLookup(const uint8_t ch)
|
||
{
|
||
// UTF-8 to font table index converter
|
||
// Code form http://playground.arduino.cc/Main/Utf8ascii
|
||
static uint8_t LASTCHAR;
|
||
static bool SKIPREST; // Only display a single unconvertable-character symbol per sequence of unconvertable characters
|
||
|
||
if (ch < 128) { // Standard ASCII-set 0..0x7F handling
|
||
LASTCHAR = 0;
|
||
SKIPREST = false;
|
||
return ch;
|
||
}
|
||
|
||
uint8_t last = LASTCHAR; // get last char
|
||
LASTCHAR = ch;
|
||
|
||
switch (last) { // conversion depending on first UTF8-character
|
||
case 0xC2: {
|
||
SKIPREST = false;
|
||
return (uint8_t)ch;
|
||
}
|
||
case 0xC3: {
|
||
SKIPREST = false;
|
||
return (uint8_t)(ch | 0xC0);
|
||
}
|
||
// map UTF-8 cyrillic chars to it Windows-1251 (CP-1251) ASCII codes
|
||
// note: in this case we must use compatible font - provided ArialMT_Plain_10/16/24 by 'ThingPulse/esp8266-oled-ssd1306'
|
||
// library have empty chars for non-latin ASCII symbols
|
||
case 0xD0: {
|
||
SKIPREST = false;
|
||
if (ch == 132)
|
||
return (uint8_t)(170); // Є
|
||
if (ch == 134)
|
||
return (uint8_t)(178); // І
|
||
if (ch == 135)
|
||
return (uint8_t)(175); // Ї
|
||
if (ch == 129)
|
||
return (uint8_t)(168); // Ё
|
||
if (ch > 143 && ch < 192)
|
||
return (uint8_t)(ch + 48);
|
||
break;
|
||
}
|
||
case 0xD1: {
|
||
SKIPREST = false;
|
||
if (ch == 148)
|
||
return (uint8_t)(186); // є
|
||
if (ch == 150)
|
||
return (uint8_t)(179); // і
|
||
if (ch == 151)
|
||
return (uint8_t)(191); // ї
|
||
if (ch == 145)
|
||
return (uint8_t)(184); // ё
|
||
if (ch > 127 && ch < 144)
|
||
return (uint8_t)(ch + 112);
|
||
break;
|
||
}
|
||
case 0xD2: {
|
||
SKIPREST = false;
|
||
if (ch == 144)
|
||
return (uint8_t)(165); // Ґ
|
||
if (ch == 145)
|
||
return (uint8_t)(180); // ґ
|
||
break;
|
||
}
|
||
}
|
||
|
||
// We want to strip out prefix chars for two-byte char formats
|
||
if (ch == 0xC2 || ch == 0xC3 || ch == 0x82 || ch == 0xD0 || ch == 0xD1)
|
||
return (uint8_t)0;
|
||
|
||
// If we already returned an unconvertable-character symbol for this unconvertable-character sequence, return NULs for the
|
||
// rest of it
|
||
if (SKIPREST)
|
||
return (uint8_t)0;
|
||
SKIPREST = true;
|
||
|
||
return (uint8_t)191; // otherwise: return ¿ if character can't be converted (note that the font map we're using doesn't
|
||
// stick to standard EASCII codes)
|
||
}
|
||
|
||
/// Returns a handle to the DebugInfo screen.
|
||
//
|
||
// Use this handle to set things like battery status, user count, GPS status, etc.
|
||
DebugInfo *debug_info() { return &debugInfo; }
|
||
|
||
// Handle observer events
|
||
int handleStatusUpdate(const meshtastic::Status *arg);
|
||
int handleTextMessage(const meshtastic_MeshPacket *arg);
|
||
int handleUIFrameEvent(const UIFrameEvent *arg);
|
||
int handleInputEvent(const InputEvent *arg);
|
||
int handleAdminMessage(const meshtastic_AdminMessage *arg);
|
||
|
||
/// Used to force (super slow) eink displays to draw critical frames
|
||
void forceDisplay(bool forceUiUpdate = false);
|
||
|
||
/// Draws our SSL cert screen during boot (called from WebServer)
|
||
void setSSLFrames();
|
||
|
||
void setWelcomeFrames();
|
||
|
||
#ifdef USE_EINK
|
||
/// Draw an image to remain on E-Ink display after screen off
|
||
void setScreensaverFrames(FrameCallback einkScreensaver = NULL);
|
||
#endif
|
||
|
||
protected:
|
||
/// Updates the UI.
|
||
//
|
||
// Called periodically from the main loop.
|
||
int32_t runOnce() final;
|
||
|
||
bool isAUTOOled = false;
|
||
|
||
// Screen dimensions (for convenience)
|
||
// Defined during Screen::setup
|
||
uint16_t displayWidth = 0;
|
||
uint16_t displayHeight = 0;
|
||
|
||
private:
|
||
FrameCallback alertFrames[1];
|
||
struct ScreenCmd {
|
||
Cmd cmd;
|
||
union {
|
||
uint32_t bluetooth_pin;
|
||
char *print_text;
|
||
};
|
||
};
|
||
|
||
/// Enques given command item to be processed by main loop().
|
||
bool enqueueCmd(const ScreenCmd &cmd)
|
||
{
|
||
if (!useDisplay)
|
||
return false; // not enqueued if our display is not in use
|
||
else {
|
||
bool success = cmdQueue.enqueue(cmd, 0);
|
||
enabled = true; // handle ASAP (we are the registered reader for cmdQueue, but might have been disabled)
|
||
return success;
|
||
}
|
||
}
|
||
|
||
// Implementations of various commands, called from doTask().
|
||
void handleSetOn(bool on, FrameCallback einkScreensaver = NULL);
|
||
void handleOnPress();
|
||
void handleShowNextFrame();
|
||
void handleShowPrevFrame();
|
||
void handlePrint(const char *text);
|
||
void handleStartFirmwareUpdateScreen();
|
||
|
||
// Info collected by setFrames method.
|
||
// Index location of specific frames. Used to apply the FrameFocus parameter of setFrames
|
||
struct FramesetInfo {
|
||
struct FramePositions {
|
||
uint8_t fault = 0;
|
||
uint8_t textMessage = 0;
|
||
uint8_t focusedModule = 0;
|
||
uint8_t log = 0;
|
||
uint8_t settings = 0;
|
||
uint8_t wifi = 0;
|
||
} positions;
|
||
|
||
uint8_t frameCount = 0;
|
||
} framesetInfo;
|
||
|
||
// Which frame we want to be displayed, after we regen the frameset by calling setFrames
|
||
enum FrameFocus : uint8_t {
|
||
FOCUS_DEFAULT, // No specific frame
|
||
FOCUS_PRESERVE, // Return to the previous frame
|
||
FOCUS_FAULT,
|
||
FOCUS_TEXTMESSAGE,
|
||
FOCUS_MODULE, // Note: target module should call requestFocus(), otherwise no info about which module to focus
|
||
};
|
||
|
||
// Regenerate the normal set of frames, focusing a specific frame if requested
|
||
// Call when a frame should be added / removed, or custom frames should be cleared
|
||
void setFrames(FrameFocus focus = FOCUS_DEFAULT);
|
||
|
||
/// Try to start drawing ASAP
|
||
void setFastFramerate();
|
||
|
||
// Sets frame up for immediate drawing
|
||
void setFrameImmediateDraw(FrameCallback *drawFrames);
|
||
|
||
/// Called when debug screen is to be drawn, calls through to debugInfo.drawFrame.
|
||
static void drawDebugInfoTrampoline(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
||
|
||
static void drawDebugInfoSettingsTrampoline(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
||
|
||
static void drawDebugInfoWiFiTrampoline(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
||
|
||
#ifdef T_WATCH_S3
|
||
static void drawAnalogClockFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
||
|
||
static void drawDigitalClockFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
||
|
||
static void drawSegmentedDisplayCharacter(OLEDDisplay *display, int x, int y, uint8_t number, float scale = 1);
|
||
|
||
static void drawHorizontalSegment(OLEDDisplay *display, int x, int y, int width, int height);
|
||
|
||
static void drawVerticalSegment(OLEDDisplay *display, int x, int y, int width, int height);
|
||
|
||
static void drawSegmentedDisplayColon(OLEDDisplay *display, int x, int y, float scale = 1);
|
||
|
||
static void drawWatchFaceToggleButton(OLEDDisplay *display, int16_t x, int16_t y, bool digitalMode = true, float scale = 1);
|
||
|
||
static void drawBluetoothConnectedIcon(OLEDDisplay *display, int16_t x, int16_t y);
|
||
|
||
// Whether we are showing the digital watch face or the analog one
|
||
bool digitalWatchFace = true;
|
||
#endif
|
||
|
||
/// callback for current alert frame
|
||
FrameCallback alertFrame;
|
||
|
||
/// Queue of commands to execute in doTask.
|
||
TypedQueue<ScreenCmd> cmdQueue;
|
||
/// Whether we are using a display
|
||
bool useDisplay = false;
|
||
/// Whether the display is currently powered
|
||
bool screenOn = false;
|
||
// Whether we are showing the regular screen (as opposed to booth screen or
|
||
// Bluetooth PIN screen)
|
||
bool showingNormalScreen = false;
|
||
|
||
// Implementation to Adjust Brightness
|
||
uint8_t brightness = BRIGHTNESS_DEFAULT; // H = 254, MH = 192, ML = 130 L = 103
|
||
|
||
bool hasCompass = false;
|
||
float compassHeading;
|
||
/// Holds state for debug information
|
||
DebugInfo debugInfo;
|
||
|
||
/// Display device
|
||
OLEDDisplay *dispdev;
|
||
|
||
/// UI helper for rendering to frames and switching between them
|
||
OLEDDisplayUi *ui;
|
||
};
|
||
|
||
} // namespace graphics
|
||
|
||
#endif |