Skip to content

Commit bb63f81

Browse files
authored
Merge pull request #2 from Quency-D/dev
Merging changes
2 parents bd6bd06 + 3f5c772 commit bb63f81

File tree

112 files changed

+1871
-269
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+1871
-269
lines changed

build.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# usage
44
# sh build.sh build-firmware RAK_4631_Repeater
55
# sh build.sh build-firmwares
6+
# sh build.sh build-matching-firmwares RAK_4631
67
# sh build.sh build-companion-firmwares
78
# sh build.sh build-repeater-firmwares
89
# sh build.sh build-room-server-firmwares
@@ -144,6 +145,16 @@ mkdir -p out
144145
if [[ $1 == "build-firmware" ]]; then
145146
if [ "$2" ]; then
146147
build_firmware $2
148+
else
149+
echo "usage: $0 build-firmware <target>"
150+
exit 1
151+
fi
152+
elif [[ $1 == "build-matching-firmwares" ]]; then
153+
if [ "$2" ]; then
154+
build_all_firmwares_matching $2
155+
else
156+
echo "usage: $0 build-matching-firmwares <build-match-spec>"
157+
exit 1
147158
fi
148159
elif [[ $1 == "build-firmwares" ]]; then
149160
build_firmwares

build_as_lib.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from os.path import realpath
2+
3+
Import("env") # type: ignore
4+
menv=env # type: ignore
5+
6+
src_filter = [
7+
'+<*.cpp>',
8+
'+<helpers/*.cpp>',
9+
'+<helpers/sensors>',
10+
'+<helpers/radiolib/*.cpp>',
11+
'+<helpers/ui/MomentaryButton.cpp>',
12+
'+<helpers/ui/buzzer.cpp>',
13+
]
14+
15+
# add build and include dirs according to CPPDEFINES
16+
for item in menv.get("CPPDEFINES", []):
17+
18+
# PLATFORM HANDLING
19+
if item == "STM32_PLATFORM":
20+
src_filter.append("+<helpers/stm32/*>")
21+
elif item == "ESP32":
22+
src_filter.append("+<helpers/esp32/*>")
23+
elif item == "NRF52_PLATFORM":
24+
src_filter.append("+<helpers/nrf52/*>")
25+
elif item == "RP2040_PLATFORM":
26+
src_filter.append("+<helpers/rp2040/*>")
27+
28+
# DISPLAY HANDLING
29+
elif isinstance(item, tuple) and item[0] == "DISPLAY_CLASS":
30+
display_class = item[1]
31+
src_filter.append(f"+<helpers/ui/{display_class}.cpp>")
32+
if (display_class == "ST7789Display") :
33+
src_filter.append(f"+<helpers/ui/OLEDDisplay.cpp>")
34+
src_filter.append(f"+<helpers/ui/OLEDDisplayFonts.cpp>")
35+
36+
# VARIANTS HANDLING
37+
elif isinstance(item, tuple) and item[0] == "MC_VARIANT":
38+
variant_name = item[1]
39+
src_filter.append(f"+<../variants/{variant_name}>")
40+
41+
# INCLUDE EXAMPLE CODE IN BUILD (to provide your own support files without touching the tree)
42+
elif isinstance(item, tuple) and item[0] == "BUILD_EXAMPLE":
43+
example_name = item[1]
44+
src_filter.append(f"+<../examples/{example_name}/*.cpp>")
45+
46+
# EXCLUDE A SOURCE FILE FROM AN EXAMPLE (must be placed after example name or boom)
47+
elif isinstance(item, tuple) and item[0] == "EXCLUDE_FROM_EXAMPLE":
48+
exclude_name = item[1]
49+
if example_name is None:
50+
print("***** PLEASE DEFINE EXAMPLE FIRST *****")
51+
break
52+
src_filter.append(f"-<../examples/{example_name}/{exclude_name}>")
53+
54+
# DEAL WITH UI VARIANT FOR AN EXAMPLE
55+
elif isinstance(item, tuple) and item[0] == "MC_UI_FLAVOR":
56+
ui_flavor = item[1]
57+
if example_name is None:
58+
print("***** PLEASE DEFINE EXAMPLE FIRST *****")
59+
break
60+
src_filter.append(f"+<../examples/{example_name}/{ui_flavor}/*.cpp>")
61+
62+
menv.Replace(SRC_FILTER=src_filter)
63+
64+
#print (menv.Dump())
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() = 0;
46+
};

examples/companion_radio/MyMesh.cpp

Lines changed: 25 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

@@ -267,6 +263,7 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
267263
}
268264

269265
memcpy(p->pubkey_prefix, contact.id.pub_key, sizeof(p->pubkey_prefix));
266+
strcpy(p->name, contact.name);
270267
p->recv_timestamp = getRTCClock()->getCurrentTime();
271268
p->path_len = path_len;
272269
memcpy(p->path, path, p->path_len);
@@ -275,6 +272,20 @@ void MyMesh::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path
275272
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);
276273
}
277274

275+
static int sort_by_recent(const void *a, const void *b) {
276+
return ((AdvertPath *) b)->recv_timestamp - ((AdvertPath *) a)->recv_timestamp;
277+
}
278+
279+
int MyMesh::getRecentlyHeard(AdvertPath dest[], int max_num) {
280+
if (max_num > ADVERT_PATH_TABLE_SIZE) max_num = ADVERT_PATH_TABLE_SIZE;
281+
qsort(advert_paths, ADVERT_PATH_TABLE_SIZE, sizeof(advert_paths[0]), sort_by_recent);
282+
283+
for (int i = 0; i < max_num; i++) {
284+
dest[i] = advert_paths[i];
285+
}
286+
return max_num;
287+
}
288+
278289
void MyMesh::onContactPathUpdated(const ContactInfo &contact) {
279290
out_frame[0] = PUSH_CODE_PATH_UPDATED;
280291
memcpy(&out_frame[1], contact.id.pub_key, PUB_KEY_SIZE);
@@ -339,10 +350,10 @@ void MyMesh::queueMessage(const ContactInfo &from, uint8_t txt_type, mesh::Packe
339350
#ifdef DISPLAY_CLASS
340351
// we only want to show text messages on display, not cli data
341352
bool should_display = txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_SIGNED_PLAIN;
342-
if (should_display) {
343-
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);
344355
if (!_serial->isConnected()) {
345-
ui_task.soundBuzzer(UIEventType::contactMessage);
356+
_ui->soundBuzzer(UIEventType::contactMessage);
346357
}
347358
}
348359
#endif
@@ -401,7 +412,7 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe
401412
_serial->writeFrame(frame, 1);
402413
} else {
403414
#ifdef DISPLAY_CLASS
404-
ui_task.soundBuzzer(UIEventType::channelMessage);
415+
if (_ui) _ui->soundBuzzer(UIEventType::channelMessage);
405416
#endif
406417
}
407418
#ifdef DISPLAY_CLASS
@@ -411,7 +422,7 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe
411422
if (getChannel(channel_idx, channel_details)) {
412423
channel_name = channel_details.name;
413424
}
414-
ui_task.newMsg(path_len, channel_name, text, offline_queue_len);
425+
if (_ui) _ui->newMsg(path_len, channel_name, text, offline_queue_len);
415426
#endif
416427
}
417428

@@ -620,9 +631,9 @@ uint32_t MyMesh::calcDirectTimeoutMillisFor(uint32_t pkt_airtime_millis, uint8_t
620631

621632
void MyMesh::onSendTimeout() {}
622633

623-
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)
624635
: BaseChatMesh(radio, *new ArduinoMillis(), rng, rtc, *new StaticPoolPacketManager(16), tables),
625-
_serial(NULL), telemetry(MAX_PACKET_PAYLOAD - 4), _store(&store) {
636+
_serial(NULL), telemetry(MAX_PACKET_PAYLOAD - 4), _store(&store), _ui(ui) {
626637
_iter_started = false;
627638
_cli_rescue = false;
628639
offline_queue_len = 0;
@@ -1026,7 +1037,7 @@ void MyMesh::handleCmdFrame(size_t len) {
10261037
if ((out_len = getFromOfflineQueue(out_frame)) > 0) {
10271038
_serial->writeFrame(out_frame, out_len);
10281039
#ifdef DISPLAY_CLASS
1029-
ui_task.msgRead(offline_queue_len);
1040+
if (_ui) _ui->msgRead(offline_queue_len);
10301041
#endif
10311042
} else {
10321043
out_frame[0] = RESP_CODE_NO_MORE_MESSAGES;
@@ -1628,7 +1639,7 @@ void MyMesh::loop() {
16281639
}
16291640

16301641
#ifdef DISPLAY_CLASS
1631-
ui_task.setHasConnection(_serial->isConnected());
1642+
if (_ui) _ui->setHasConnection(_serial->isConnected());
16321643
#endif
16331644
}
16341645

examples/companion_radio/MyMesh.h

Lines changed: 13 additions & 13 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
@@ -77,9 +75,17 @@
7775
#define REQ_TYPE_KEEP_ALIVE 0x02
7876
#define REQ_TYPE_GET_TELEMETRY_DATA 0x03
7977

78+
struct AdvertPath {
79+
uint8_t pubkey_prefix[7];
80+
uint8_t path_len;
81+
char name[32];
82+
uint32_t recv_timestamp;
83+
uint8_t path[MAX_PATH_SIZE];
84+
};
85+
8086
class MyMesh : public BaseChatMesh, public DataStoreHost {
8187
public:
82-
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);
8389

8490
void begin(bool has_display);
8591
void startInterface(BaseSerialInterface &serial);
@@ -93,6 +99,8 @@ class MyMesh : public BaseChatMesh, public DataStoreHost {
9399
bool advert();
94100
void enterCLIRescue();
95101

102+
int getRecentlyHeard(AdvertPath dest[], int max_num);
103+
96104
protected:
97105
float getAirtimeBudgetFactor() const override;
98106
int getInterferenceThreshold() const override;
@@ -169,6 +177,7 @@ class MyMesh : public BaseChatMesh, public DataStoreHost {
169177
uint32_t pending_telemetry, pending_discovery; // pending _TELEMETRY_REQ
170178
uint32_t pending_req; // pending _BINARY_REQ
171179
BaseSerialInterface *_serial;
180+
AbstractUITask* _ui;
172181

173182
ContactsIterator _iter;
174183
uint32_t _iter_filter_since;
@@ -201,17 +210,8 @@ class MyMesh : public BaseChatMesh, public DataStoreHost {
201210
AckTableEntry expected_ack_table[EXPECTED_ACK_TABLE_SIZE]; // circular table
202211
int next_ack_idx;
203212

204-
struct AdvertPath {
205-
uint8_t pubkey_prefix[7];
206-
uint8_t path_len;
207-
uint32_t recv_timestamp;
208-
uint8_t path[MAX_PATH_SIZE];
209-
};
210213
#define ADVERT_PATH_TABLE_SIZE 16
211214
AdvertPath advert_paths[ADVERT_PATH_TABLE_SIZE]; // circular table
212215
};
213216

214217
extern MyMesh the_mesh;
215-
#ifdef DISPLAY_CLASS
216-
extern UITask ui_task;
217-
#endif

examples/companion_radio/main.cpp

Lines changed: 14 additions & 6 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"
84-
UITask ui_task(&board);
80+
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() {
@@ -99,7 +104,10 @@ void setup() {
99104
if (display.begin()) {
100105
disp = &display;
101106
disp->startFrame();
102-
disp->print("Please wait...");
107+
#ifdef ST7789
108+
disp->setTextSize(2);
109+
#endif
110+
disp->drawTextCentered(disp->width() / 2, 28, "Loading...");
103111
disp->endFrame();
104112
}
105113
#endif

0 commit comments

Comments
 (0)