Merge pull request #598 from 446564/nano-g2-new-ui

add new UI to nano g2
This commit is contained in:
ripplebiz 2025-08-10 14:44:04 +10:00 committed by GitHub
commit c8bbec6549
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 34 deletions

View file

@ -47,6 +47,7 @@ build_src_filter = ${Nano_G2_Ultra.build_src_filter}
+<helpers/nrf52/SerialBLEInterface.cpp> +<helpers/nrf52/SerialBLEInterface.cpp>
+<helpers/ui/SH1106Display.cpp> +<helpers/ui/SH1106Display.cpp>
+<helpers/ui/buzzer.cpp> +<helpers/ui/buzzer.cpp>
+<helpers/ui/MomentaryButton.cpp>
+<../examples/companion_radio> +<../examples/companion_radio>
lib_deps = lib_deps =
${Nano_G2_Ultra.lib_deps} ${Nano_G2_Ultra.lib_deps}

View file

@ -1,5 +1,6 @@
#include <Arduino.h>
#include "target.h" #include "target.h"
#include <Arduino.h>
#include <helpers/ArduinoHelpers.h> #include <helpers/ArduinoHelpers.h>
#include <helpers/sensors/MicroNMEALocationProvider.h> #include <helpers/sensors/MicroNMEALocationProvider.h>
@ -16,29 +17,26 @@ NanoG2UltraSensorManager sensors = NanoG2UltraSensorManager(nmea);
#ifdef DISPLAY_CLASS #ifdef DISPLAY_CLASS
DISPLAY_CLASS display; DISPLAY_CLASS display;
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
#endif #endif
bool radio_init() bool radio_init() {
{
rtc_clock.begin(Wire); rtc_clock.begin(Wire);
return radio.std_init(&SPI); return radio.std_init(&SPI);
} }
uint32_t radio_get_rng_seed() uint32_t radio_get_rng_seed() {
{
return radio.random(0x7FFFFFFF); return radio.random(0x7FFFFFFF);
} }
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
{
radio.setFrequency(freq); radio.setFrequency(freq);
radio.setSpreadingFactor(sf); radio.setSpreadingFactor(sf);
radio.setBandwidth(bw); radio.setBandwidth(bw);
radio.setCodingRate(cr); radio.setCodingRate(cr);
} }
void radio_set_tx_power(uint8_t dbm) void radio_set_tx_power(uint8_t dbm) {
{
radio.setOutputPower(dbm); radio.setOutputPower(dbm);
} }
@ -64,8 +62,7 @@ void NanoG2UltraSensorManager::stop_gps() {
_location->stop(); _location->stop();
} }
bool NanoG2UltraSensorManager::begin() bool NanoG2UltraSensorManager::begin() {
{
digitalWrite(PIN_GPS_STANDBY, HIGH); // Wake GPS from standby digitalWrite(PIN_GPS_STANDBY, HIGH); // Wake GPS from standby
Serial1.setPins(PIN_GPS_TX, PIN_GPS_RX); Serial1.setPins(PIN_GPS_TX, PIN_GPS_RX);
Serial1.begin(9600); Serial1.begin(9600);
@ -83,29 +80,26 @@ bool NanoG2UltraSensorManager::begin()
return true; return true;
} }
bool NanoG2UltraSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP &telemetry) bool NanoG2UltraSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP &telemetry) {
{ if (requester_permissions & TELEM_PERM_LOCATION) { // does requester have permission?
if (requester_permissions & TELEM_PERM_LOCATION)
{ // does requester have permission?
telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude); telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude);
} }
return true; return true;
} }
void NanoG2UltraSensorManager::loop() void NanoG2UltraSensorManager::loop() {
{
static long next_gps_update = 0; static long next_gps_update = 0;
if (!gps_active) { if (!gps_active) {
return; // GPS is not active, skip further processing return; // GPS is not active, skip further processing
} }
_location->loop(); _location->loop();
if (millis() > next_gps_update) { if (millis() > next_gps_update) {
if (_location->isValid()) { if (_location->isValid()) {
node_lat = ((double)_location->getLatitude())/1000000.; node_lat = ((double)_location->getLatitude()) / 1000000.;
node_lon = ((double)_location->getLongitude())/1000000.; node_lon = ((double)_location->getLongitude()) / 1000000.;
node_altitude = ((double)_location->getAltitude()) / 1000.0; node_altitude = ((double)_location->getAltitude()) / 1000.0;
MESH_DEBUG_PRINTLN("VALID location: lat %f lon %f", node_lat, node_lon); MESH_DEBUG_PRINTLN("VALID location: lat %f lon %f", node_lat, node_lon);
} else { } else {
@ -116,24 +110,22 @@ void NanoG2UltraSensorManager::loop()
} }
} }
int NanoG2UltraSensorManager::getNumSettings() const { return 1; } // just one supported: "gps" (power switch) int NanoG2UltraSensorManager::getNumSettings() const {
return 1;
} // just one supported: "gps" (power switch)
const char *NanoG2UltraSensorManager::getSettingName(int i) const const char *NanoG2UltraSensorManager::getSettingName(int i) const {
{
return i == 0 ? "gps" : NULL; return i == 0 ? "gps" : NULL;
} }
const char *NanoG2UltraSensorManager::getSettingValue(int i) const const char *NanoG2UltraSensorManager::getSettingValue(int i) const {
{ if (i == 0) {
if (i == 0)
{
return gps_active ? "1" : "0"; return gps_active ? "1" : "0";
} }
return NULL; return NULL;
} }
bool NanoG2UltraSensorManager::setSettingValue(const char *name, const char *value) bool NanoG2UltraSensorManager::setSettingValue(const char *name, const char *value) {
{
if (strcmp(name, "gps") == 0) { if (strcmp(name, "gps") == 0) {
if (strcmp(value, "0") == 0) { if (strcmp(value, "0") == 0) {
stop_gps(); stop_gps();
@ -145,8 +137,7 @@ bool NanoG2UltraSensorManager::setSettingValue(const char *name, const char *val
return false; // not supported return false; // not supported
} }
mesh::LocalIdentity radio_new_identity() mesh::LocalIdentity radio_new_identity() {
{
RadioNoiseListener rng(radio); RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng); // create new random identity return mesh::LocalIdentity(&rng); // create new random identity
} }

View file

@ -1,13 +1,15 @@
#pragma once #pragma once
#define RADIOLIB_STATIC_ONLY 1 #define RADIOLIB_STATIC_ONLY 1
#include <RadioLib.h>
#include "nano-g2.h" #include "nano-g2.h"
#include <helpers/radiolib/RadioLibWrappers.h>
#include <helpers/radiolib/CustomSX1262Wrapper.h> #include <RadioLib.h>
#include <helpers/AutoDiscoverRTCClock.h> #include <helpers/AutoDiscoverRTCClock.h>
#include <helpers/SensorManager.h> #include <helpers/SensorManager.h>
#include <helpers/radiolib/CustomSX1262Wrapper.h>
#include <helpers/radiolib/RadioLibWrappers.h>
#ifdef DISPLAY_CLASS #ifdef DISPLAY_CLASS
#include <helpers/ui/MomentaryButton.h>
#include <helpers/ui/SH1106Display.h> #include <helpers/ui/SH1106Display.h>
#endif #endif
#include <helpers/sensors/LocationProvider.h> #include <helpers/sensors/LocationProvider.h>
@ -37,6 +39,7 @@ extern NanoG2UltraSensorManager sensors;
#ifdef DISPLAY_CLASS #ifdef DISPLAY_CLASS
extern DISPLAY_CLASS display; extern DISPLAY_CLASS display;
extern MomentaryButton user_btn;
#endif #endif
bool radio_init(); bool radio_init();