Skip to content

Commit acde992

Browse files
author
Scott Powell
committed
* Refactor of UITask, moved to /ui-new
1 parent 29fd5da commit acde992

File tree

9 files changed

+86
-101
lines changed

9 files changed

+86
-101
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#pragma once
2+
3+
#include <MeshCore.h>
4+
#include <helpers/ui/DisplayDriver.h>
5+
#include <helpers/ui/UIScreen.h>
6+
#include <helpers/SensorManager.h>
7+
#include <helpers/BaseSerialInterface.h>
8+
#include <Arduino.h>
9+
10+
#ifdef PIN_BUZZER
11+
#include <helpers/ui/buzzer.h>
12+
#endif
13+
14+
#include "NodePrefs.h"
15+
16+
enum class UIEventType {
17+
none,
18+
contactMessage,
19+
channelMessage,
20+
roomMessage,
21+
newContactMessage,
22+
ack
23+
};
24+
25+
class AbstractUITask {
26+
protected:
27+
mesh::MainBoard* _board;
28+
BaseSerialInterface* _serial;
29+
bool _connected;
30+
31+
AbstractUITask(mesh::MainBoard* board, BaseSerialInterface* serial) : _board(board), _serial(serial) {
32+
_connected = false;
33+
}
34+
35+
public:
36+
void setHasConnection(bool connected) { _connected = connected; }
37+
bool hasConnection() const { return _connected; }
38+
uint16_t getBattMilliVolts() const { return _board->getBattMilliVolts(); }
39+
bool isSerialEnabled() const { return _serial->isEnabled(); }
40+
void enableSerial() { _serial->enable(); }
41+
void disableSerial() { _serial->disable(); }
42+
virtual void msgRead(int msgcount) = 0;
43+
virtual void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) = 0;
44+
virtual void soundBuzzer(UIEventType bet = UIEventType::none) = 0;
45+
virtual void loop();
46+
};

examples/companion_radio/MyMesh.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@
109109

110110
#define MAX_SIGN_DATA_LEN (8 * 1024) // 8K
111111

112-
#ifdef DISPLAY_CLASS
113-
#include "UITask.h"
114-
#endif
115-
116112
void MyMesh::writeOKFrame() {
117113
uint8_t buf[1];
118114
buf[0] = RESP_CODE_OK;
@@ -247,7 +243,7 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
247243
}
248244
} else {
249245
#ifdef DISPLAY_CLASS
250-
ui_task.soundBuzzer(UIEventType::newContactMessage);
246+
if (_ui) _ui->soundBuzzer(UIEventType::newContactMessage);
251247
#endif
252248
}
253249

@@ -354,10 +350,10 @@ void MyMesh::queueMessage(const ContactInfo &from, uint8_t txt_type, mesh::Packe
354350
#ifdef DISPLAY_CLASS
355351
// we only want to show text messages on display, not cli data
356352
bool should_display = txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_SIGNED_PLAIN;
357-
if (should_display) {
358-
ui_task.newMsg(path_len, from.name, text, offline_queue_len);
353+
if (should_display && _ui) {
354+
_ui->newMsg(path_len, from.name, text, offline_queue_len);
359355
if (!_serial->isConnected()) {
360-
ui_task.soundBuzzer(UIEventType::contactMessage);
356+
_ui->soundBuzzer(UIEventType::contactMessage);
361357
}
362358
}
363359
#endif
@@ -416,7 +412,7 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe
416412
_serial->writeFrame(frame, 1);
417413
} else {
418414
#ifdef DISPLAY_CLASS
419-
ui_task.soundBuzzer(UIEventType::channelMessage);
415+
if (_ui) _ui->soundBuzzer(UIEventType::channelMessage);
420416
#endif
421417
}
422418
#ifdef DISPLAY_CLASS
@@ -426,7 +422,7 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe
426422
if (getChannel(channel_idx, channel_details)) {
427423
channel_name = channel_details.name;
428424
}
429-
ui_task.newMsg(path_len, channel_name, text, offline_queue_len);
425+
if (_ui) _ui->newMsg(path_len, channel_name, text, offline_queue_len);
430426
#endif
431427
}
432428

@@ -635,9 +631,9 @@ uint32_t MyMesh::calcDirectTimeoutMillisFor(uint32_t pkt_airtime_millis, uint8_t
635631

636632
void MyMesh::onSendTimeout() {}
637633

638-
MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store)
634+
MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store, AbstractUITask* ui)
639635
: BaseChatMesh(radio, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables),
640-
_serial(NULL), telemetry(MAX_PACKET_PAYLOAD - 4), _store(&store) {
636+
_serial(NULL), telemetry(MAX_PACKET_PAYLOAD - 4), _store(&store), _ui(ui) {
641637
_iter_started = false;
642638
_cli_rescue = false;
643639
offline_queue_len = 0;
@@ -1041,7 +1037,7 @@ void MyMesh::handleCmdFrame(size_t len) {
10411037
if ((out_len = getFromOfflineQueue(out_frame)) > 0) {
10421038
_serial->writeFrame(out_frame, out_len);
10431039
#ifdef DISPLAY_CLASS
1044-
ui_task.msgRead(offline_queue_len);
1040+
if (_ui) _ui->msgRead(offline_queue_len);
10451041
#endif
10461042
} else {
10471043
out_frame[0] = RESP_CODE_NO_MORE_MESSAGES;
@@ -1643,7 +1639,7 @@ void MyMesh::loop() {
16431639
}
16441640

16451641
#ifdef DISPLAY_CLASS
1646-
ui_task.setHasConnection(_serial->isConnected());
1642+
if (_ui) _ui->setHasConnection(_serial->isConnected());
16471643
#endif
16481644
}
16491645

examples/companion_radio/MyMesh.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
#include <Arduino.h>
44
#include <Mesh.h>
5-
#ifdef DISPLAY_CLASS
6-
#include "UITask.h"
7-
#endif
5+
#include "AbstractUITask.h"
86

97
/*------------ Frame Protocol --------------*/
108
#define FIRMWARE_VER_CODE 7
@@ -87,7 +85,7 @@ struct AdvertPath {
8785

8886
class MyMesh : public BaseChatMesh, public DataStoreHost {
8987
public:
90-
MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store);
88+
MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMeshTables &tables, DataStore& store, AbstractUITask* ui=NULL);
9189

9290
void begin(bool has_display);
9391
void startInterface(BaseSerialInterface &serial);
@@ -179,6 +177,7 @@ class MyMesh : public BaseChatMesh, public DataStoreHost {
179177
uint32_t pending_telemetry, pending_discovery; // pending _TELEMETRY_REQ
180178
uint32_t pending_req; // pending _BINARY_REQ
181179
BaseSerialInterface *_serial;
180+
AbstractUITask* _ui;
182181

183182
ContactsIterator _iter;
184183
uint32_t _iter_filter_since;
@@ -216,6 +215,3 @@ class MyMesh : public BaseChatMesh, public DataStoreHost {
216215
};
217216

218217
extern MyMesh the_mesh;
219-
#ifdef DISPLAY_CLASS
220-
extern UITask ui_task;
221-
#endif

examples/companion_radio/main.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,19 @@ static uint32_t _atoi(const char* sp) {
7575
#endif
7676

7777
/* GLOBAL OBJECTS */
78-
StdRNG fast_rng;
79-
SimpleMeshTables tables;
80-
MyMesh the_mesh(radio_driver, fast_rng, rtc_clock, tables, store);
81-
8278
#ifdef DISPLAY_CLASS
8379
#include "UITask.h"
8480
UITask ui_task(&board, &serial_interface);
8581
#endif
82+
83+
StdRNG fast_rng;
84+
SimpleMeshTables tables;
85+
MyMesh the_mesh(radio_driver, fast_rng, rtc_clock, tables, store
86+
#ifdef DISPLAY_CLASS
87+
, &ui_task
88+
#endif
89+
);
90+
8691
/* END GLOBAL OBJECTS */
8792

8893
void halt() {

examples/companion_radio/UITask.cpp renamed to examples/companion_radio/ui-new/UITask.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "UITask.h"
22
#include <helpers/TxtDataHelpers.h>
3-
#include "NodePrefs.h"
4-
#include "MyMesh.h"
3+
#include "../MyMesh.h"
54
#include "target.h"
65

76
#define AUTO_OFF_MILLIS 15000 // 15 seconds

examples/companion_radio/UITask.h renamed to examples/companion_radio/ui-new/UITask.h

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,16 @@
1111
#include <helpers/ui/buzzer.h>
1212
#endif
1313

14-
#include "NodePrefs.h"
14+
#include "../AbstractUITask.h"
15+
#include "../NodePrefs.h"
1516

16-
enum class UIEventType {
17-
none,
18-
contactMessage,
19-
channelMessage,
20-
roomMessage,
21-
newContactMessage,
22-
ack
23-
};
24-
25-
#define MAX_TOP_LEVEL 8
26-
27-
class UITask {
17+
class UITask : public AbstractUITask {
2818
DisplayDriver* _display;
29-
mesh::MainBoard* _board;
30-
BaseSerialInterface* _serial;
3119
SensorManager* _sensors;
3220
#ifdef PIN_BUZZER
3321
genericBuzzer buzzer;
3422
#endif
3523
unsigned long _next_refresh, _auto_off;
36-
bool _connected;
3724
NodePrefs* _node_prefs;
3825
char _alert[80];
3926
unsigned long _alert_expiry;
@@ -55,28 +42,24 @@ class UITask {
5542

5643
public:
5744

58-
UITask(mesh::MainBoard* board, BaseSerialInterface* serial) : _board(board), _serial(serial), _display(NULL), _sensors(NULL) {
45+
UITask(mesh::MainBoard* board, BaseSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) {
5946
next_batt_chck = _next_refresh = 0;
6047
ui_started_at = 0;
61-
_connected = false;
6248
curr = NULL;
6349
}
6450
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
6551

6652
void gotoHomeScreen() { setCurrScreen(home); }
6753
void showAlert(const char* text, int duration_millis);
68-
void setHasConnection(bool connected) { _connected = connected; }
69-
bool hasConnection() const { return _connected; }
70-
uint16_t getBattMilliVolts() const { return _board->getBattMilliVolts(); }
71-
bool isSerialEnabled() const { return _serial->isEnabled(); }
72-
void enableSerial() { _serial->enable(); }
73-
void disableSerial() { _serial->disable(); }
7454
int getMsgCount() const { return _msgcount; }
7555
bool hasDisplay() const { return _display != NULL; }
7656
bool isButtonPressed() const;
77-
void msgRead(int msgcount);
78-
void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount);
79-
void soundBuzzer(UIEventType bet = UIEventType::none);
57+
58+
// from AbsractUITask
59+
void msgRead(int msgcount) override;
60+
void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) override;
61+
void soundBuzzer(UIEventType bet = UIEventType::none) override;
62+
void loop() override;
63+
8064
void shutdown(bool restart = false);
81-
void loop();
8265
};
File renamed without changes.

variants/heltec_v3/platformio.ini

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ lib_deps =
103103
extends = Heltec_lora32_v3
104104
build_flags =
105105
${Heltec_lora32_v3.build_flags}
106+
-I examples/companion_radio/ui-new
106107
-D MAX_CONTACTS=160
107108
-D MAX_GROUP_CHANNELS=8
108109
-D DISPLAY_CLASS=SSD1306Display
@@ -117,6 +118,7 @@ build_src_filter = ${Heltec_lora32_v3.build_src_filter}
117118
+<helpers/ui/MomentaryButton.cpp>
118119
+<helpers/esp32/*.cpp>
119120
+<../examples/companion_radio>
121+
+<../examples/companion_radio/ui-new>
120122
lib_deps =
121123
${Heltec_lora32_v3.lib_deps}
122124
densaugeo/base64 @ ~1.4.0
@@ -244,49 +246,3 @@ build_src_filter = ${Heltec_lora32_v3.build_src_filter}
244246
lib_deps =
245247
${Heltec_lora32_v3.lib_deps}
246248
${esp32_ota.lib_deps}
247-
248-
[env:Heltec_WSL3_espnow_bridge]
249-
extends = Heltec_lora32_v3
250-
build_flags =
251-
${Heltec_lora32_v3.build_flags}
252-
; -D LORA_FREQ=915.8
253-
-D MESH_PACKET_LOGGING=1
254-
-D ENV_INCLUDE_AHTX0=0
255-
-D ENV_INCLUDE_BME280=0
256-
-D ENV_INCLUDE_BMP280=0
257-
-D ENV_INCLUDE_INA3221=0
258-
-D ENV_INCLUDE_INA219=0
259-
-D ENV_INCLUDE_MLX90614=0
260-
-D ENV_INCLUDE_VL53L0X=0
261-
-D ENV_INCLUDE_GPS=0
262-
; -D MESH_DEBUG=1
263-
build_src_filter = ${Heltec_lora32_v3.build_src_filter}
264-
+<../examples/simple_bridge/main.cpp>
265-
+<helpers/esp32/ESPNOWRadio.cpp>
266-
lib_deps =
267-
${Heltec_lora32_v3.lib_deps}
268-
bakercp/CRC32 @ ^2.0.0
269-
270-
[env:Heltec_WSL3_serial_bridge]
271-
extends = Heltec_lora32_v3
272-
build_flags =
273-
${Heltec_lora32_v3.build_flags}
274-
; -D LORA_FREQ=915.8
275-
-D MESH_PACKET_LOGGING=1
276-
-D SERIAL_BRIDGE_RX=47
277-
-D SERIAL_BRIDGE_TX=48
278-
-D ENV_INCLUDE_AHTX0=0
279-
-D ENV_INCLUDE_BME280=0
280-
-D ENV_INCLUDE_BMP280=0
281-
-D ENV_INCLUDE_INA3221=0
282-
-D ENV_INCLUDE_INA219=0
283-
-D ENV_INCLUDE_MLX90614=0
284-
-D ENV_INCLUDE_VL53L0X=0
285-
-D ENV_INCLUDE_GPS=0
286-
; -D MESH_DEBUG=1
287-
build_src_filter = ${Heltec_lora32_v3.build_src_filter}
288-
+<../examples/simple_bridge/main.cpp>
289-
+<../examples/simple_bridge/SerialBridgeRadio.cpp>
290-
lib_deps =
291-
${Heltec_lora32_v3.lib_deps}
292-
bakercp/CRC32 @ ^2.0.0

variants/t114/platformio.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ build_flags =
7373
extends = Heltec_t114
7474
build_flags =
7575
${Heltec_t114.build_flags}
76+
-I examples/companion_radio/ui-new
7677
-D MAX_CONTACTS=100
7778
-D MAX_GROUP_CHANNELS=8
7879
-D BLE_PIN_CODE=123456
@@ -83,6 +84,7 @@ build_flags =
8384
build_src_filter = ${Heltec_t114.build_src_filter}
8485
+<helpers/nrf52/SerialBLEInterface.cpp>
8586
+<../examples/companion_radio>
87+
+<../examples/companion_radio/ui-new>
8688
lib_deps =
8789
${Heltec_t114.lib_deps}
8890
densaugeo/base64 @ ~1.4.0
@@ -91,6 +93,7 @@ lib_deps =
9193
extends = Heltec_t114
9294
build_flags =
9395
${Heltec_t114.build_flags}
96+
-I examples/companion_radio/ui-new
9497
-D MAX_CONTACTS=100
9598
-D MAX_GROUP_CHANNELS=8
9699
; -D BLE_PIN_CODE=123456
@@ -100,6 +103,7 @@ build_flags =
100103
build_src_filter = ${Heltec_t114.build_src_filter}
101104
+<helpers/nrf52/*.cpp>
102105
+<../examples/companion_radio>
106+
+<../examples/companion_radio/ui-new>
103107
lib_deps =
104108
${Heltec_t114.lib_deps}
105109
densaugeo/base64 @ ~1.4.0

0 commit comments

Comments
 (0)