Skip to content

Commit 153051a

Browse files
committed
add new UI to nano g2
1 parent 67529d0 commit 153051a

File tree

3 files changed

+29
-34
lines changed

3 files changed

+29
-34
lines changed

variants/nano_g2_ultra/platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ build_src_filter = ${Nano_G2_Ultra.build_src_filter}
4747
+<helpers/nrf52/SerialBLEInterface.cpp>
4848
+<helpers/ui/SH1106Display.cpp>
4949
+<helpers/ui/buzzer.cpp>
50+
+<helpers/ui/MomentaryButton.cpp>
5051
+<../examples/companion_radio>
5152
lib_deps =
5253
${Nano_G2_Ultra.lib_deps}

variants/nano_g2_ultra/target.cpp

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#include <Arduino.h>
21
#include "target.h"
2+
3+
#include <Arduino.h>
34
#include <helpers/ArduinoHelpers.h>
45
#include <helpers/sensors/MicroNMEALocationProvider.h>
56

@@ -16,29 +17,26 @@ NanoG2UltraSensorManager sensors = NanoG2UltraSensorManager(nmea);
1617

1718
#ifdef DISPLAY_CLASS
1819
DISPLAY_CLASS display;
20+
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
1921
#endif
2022

21-
bool radio_init()
22-
{
23+
bool radio_init() {
2324
rtc_clock.begin(Wire);
2425
return radio.std_init(&SPI);
2526
}
2627

27-
uint32_t radio_get_rng_seed()
28-
{
28+
uint32_t radio_get_rng_seed() {
2929
return radio.random(0x7FFFFFFF);
3030
}
3131

32-
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr)
33-
{
32+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
3433
radio.setFrequency(freq);
3534
radio.setSpreadingFactor(sf);
3635
radio.setBandwidth(bw);
3736
radio.setCodingRate(cr);
3837
}
3938

40-
void radio_set_tx_power(uint8_t dbm)
41-
{
39+
void radio_set_tx_power(uint8_t dbm) {
4240
radio.setOutputPower(dbm);
4341
}
4442

@@ -64,8 +62,7 @@ void NanoG2UltraSensorManager::stop_gps() {
6462
_location->stop();
6563
}
6664

67-
bool NanoG2UltraSensorManager::begin()
68-
{
65+
bool NanoG2UltraSensorManager::begin() {
6966
digitalWrite(PIN_GPS_STANDBY, HIGH); // Wake GPS from standby
7067
Serial1.setPins(PIN_GPS_TX, PIN_GPS_RX);
7168
Serial1.begin(9600);
@@ -83,29 +80,26 @@ bool NanoG2UltraSensorManager::begin()
8380
return true;
8481
}
8582

86-
bool NanoG2UltraSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP &telemetry)
87-
{
88-
if (requester_permissions & TELEM_PERM_LOCATION)
89-
{ // does requester have permission?
83+
bool NanoG2UltraSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP &telemetry) {
84+
if (requester_permissions & TELEM_PERM_LOCATION) { // does requester have permission?
9085
telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude);
9186
}
9287
return true;
9388
}
9489

95-
void NanoG2UltraSensorManager::loop()
96-
{
90+
void NanoG2UltraSensorManager::loop() {
9791
static long next_gps_update = 0;
9892

9993
if (!gps_active) {
100-
return; // GPS is not active, skip further processing
94+
return; // GPS is not active, skip further processing
10195
}
10296

10397
_location->loop();
10498

10599
if (millis() > next_gps_update) {
106100
if (_location->isValid()) {
107-
node_lat = ((double)_location->getLatitude())/1000000.;
108-
node_lon = ((double)_location->getLongitude())/1000000.;
101+
node_lat = ((double)_location->getLatitude()) / 1000000.;
102+
node_lon = ((double)_location->getLongitude()) / 1000000.;
109103
node_altitude = ((double)_location->getAltitude()) / 1000.0;
110104
MESH_DEBUG_PRINTLN("VALID location: lat %f lon %f", node_lat, node_lon);
111105
} else {
@@ -116,24 +110,22 @@ void NanoG2UltraSensorManager::loop()
116110
}
117111
}
118112

119-
int NanoG2UltraSensorManager::getNumSettings() const { return 1; } // just one supported: "gps" (power switch)
113+
int NanoG2UltraSensorManager::getNumSettings() const {
114+
return 1;
115+
} // just one supported: "gps" (power switch)
120116

121-
const char *NanoG2UltraSensorManager::getSettingName(int i) const
122-
{
117+
const char *NanoG2UltraSensorManager::getSettingName(int i) const {
123118
return i == 0 ? "gps" : NULL;
124119
}
125120

126-
const char *NanoG2UltraSensorManager::getSettingValue(int i) const
127-
{
128-
if (i == 0)
129-
{
121+
const char *NanoG2UltraSensorManager::getSettingValue(int i) const {
122+
if (i == 0) {
130123
return gps_active ? "1" : "0";
131124
}
132125
return NULL;
133126
}
134127

135-
bool NanoG2UltraSensorManager::setSettingValue(const char *name, const char *value)
136-
{
128+
bool NanoG2UltraSensorManager::setSettingValue(const char *name, const char *value) {
137129
if (strcmp(name, "gps") == 0) {
138130
if (strcmp(value, "0") == 0) {
139131
stop_gps();
@@ -145,8 +137,7 @@ bool NanoG2UltraSensorManager::setSettingValue(const char *name, const char *val
145137
return false; // not supported
146138
}
147139

148-
mesh::LocalIdentity radio_new_identity()
149-
{
140+
mesh::LocalIdentity radio_new_identity() {
150141
RadioNoiseListener rng(radio);
151142
return mesh::LocalIdentity(&rng); // create new random identity
152143
}

variants/nano_g2_ultra/target.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#pragma once
22

33
#define RADIOLIB_STATIC_ONLY 1
4-
#include <RadioLib.h>
54
#include "nano-g2.h"
6-
#include <helpers/radiolib/RadioLibWrappers.h>
7-
#include <helpers/radiolib/CustomSX1262Wrapper.h>
5+
6+
#include <RadioLib.h>
87
#include <helpers/AutoDiscoverRTCClock.h>
98
#include <helpers/SensorManager.h>
9+
#include <helpers/radiolib/CustomSX1262Wrapper.h>
10+
#include <helpers/radiolib/RadioLibWrappers.h>
1011
#ifdef DISPLAY_CLASS
12+
#include <helpers/ui/MomentaryButton.h>
1113
#include <helpers/ui/SH1106Display.h>
1214
#endif
1315
#include <helpers/sensors/LocationProvider.h>
@@ -37,6 +39,7 @@ extern NanoG2UltraSensorManager sensors;
3739

3840
#ifdef DISPLAY_CLASS
3941
extern DISPLAY_CLASS display;
42+
extern MomentaryButton user_btn;
4043
#endif
4144

4245
bool radio_init();

0 commit comments

Comments
 (0)