-
Notifications
You must be signed in to change notification settings - Fork 3
/
common.h
76 lines (68 loc) · 1.7 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <Arduino.h>
enum RedrawFlags
{
MainWindow = 0b001,
SystemBar = 0b010,
TabBar = 0b100,
None = 0b000
};
// TODO: refine message format
struct Message
{
uint8_t nonce : 6;
uint8_t channel : 2; // 4 channels, 0b01,0b10,0b11 channels, 0b11 reserved for pings
String username; // use MAC or something tied to device?
bool isEspNow;
int rssi;
String text;
};
// track presence of other users
struct Presence
{
String username;
bool isEspNow;
int rssi;
unsigned long lastSeenMillis;
};
std::vector<Presence> presence;
struct ChatTab
{
unsigned char channel;
// TODO: access in thread-safe way
std::vector<Message> messages;
String messageBuffer;
int viewIndex;
};
enum Settings
{
Username = 0,
Brightness = 1,
PingMode = 2,
RepeatMode = 3,
EspNowMode = 4,
WriteConfig = 5,
LoRaSettings = 6
};
const int SettingsCount = 7;
const String SettingsNames[SettingsCount] = {"Username", "Brightness", "Ping Mode", "Repeat Mode", "ESP-NOW Mode", "App Config", "LoRa Config"};
const String SettingsFilename = "/LoRaChat.conf";
// hack
typedef struct {
uint16_t frame_head;
uint16_t duration;
uint8_t destination_address[6];
uint8_t source_address[6];
uint8_t broadcast_address[6];
uint16_t sequence_control;
uint8_t category_code;
uint8_t organization_identifier[3]; // 0x18fe34
uint8_t random_values[4];
struct {
uint8_t element_id; // 0xdd
uint8_t lenght; //
uint8_t organization_identifier[3]; // 0x18fe34
uint8_t type; // 4
uint8_t version;
uint8_t body[0];
} vendor_specific_content;
} __attribute__ ((packed)) espnow_frame_format_t;