Skip to content

Commit

Permalink
esp-now mode mostly good
Browse files Browse the repository at this point in the history
  • Loading branch information
nonik0 committed Mar 1, 2024
1 parent 72a429a commit 16942c8
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 71 deletions.
26 changes: 25 additions & 1 deletion common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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;
};
Expand All @@ -22,6 +23,7 @@ struct Message
struct Presence
{
String username;
bool isEspNow;
int rssi;
unsigned long lastSeenMillis;
};
Expand Down Expand Up @@ -49,4 +51,26 @@ enum Settings

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";
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;
16 changes: 8 additions & 8 deletions draw_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ inline void draw_rx_indicator(M5Canvas *canvas, int x, int y) {
canvas->drawLine(rxx + rxw, y, rxx + rxw - rxa, y + rxa - 1, TFT_SILVER);
}

inline void draw_rssi_indicator(M5Canvas *canvas, int x, int y, int rssi)
inline void draw_rssi_indicator(M5Canvas *canvas, int x, int y, int rssi, bool altColor = false)
{
const uint8_t bar1 = 2, bar2 = 5, bar3 = 8, bar4 = 11;
const uint8_t barW = 3;
Expand All @@ -53,23 +53,23 @@ inline void draw_rssi_indicator(M5Canvas *canvas, int x, int y, int rssi)
canvas->drawTriangle(x - 3, barY, x + 3, barY, x, barY + 3, TFT_SILVER);

uint8_t barX = x + 4;
(rssi > -130)
? canvas->fillRect(barX, barY + (bar4 - bar1), barW, bar1, UX_COLOR_ACCENT)
(rssi > -200) // ~ -130 is around min
? canvas->fillRect(barX, barY + (bar4 - bar1), barW, bar1, altColor ? UX_COLOR_ACCENT : UX_COLOR_ACCENT2)
: canvas->drawRect(barX, barY + (bar4 - bar1), barW, bar1, TFT_SILVER);

barX += barW + barSpace;
(rssi > -100)
? canvas->fillRect(barX, barY + (bar4 - bar2), barW, bar2, UX_COLOR_ACCENT)
(rssi > -105)
? canvas->fillRect(barX, barY + (bar4 - bar2), barW, bar2, altColor ? UX_COLOR_ACCENT : UX_COLOR_ACCENT2)
: canvas->drawRect(barX, barY + (bar4 - bar2), barW, bar2, TFT_SILVER);

barX += barW + barSpace;
(rssi > -70)
? canvas->fillRect(barX, barY + (bar4 - bar3), barW, bar3, UX_COLOR_ACCENT)
? canvas->fillRect(barX, barY + (bar4 - bar3), barW, bar3, altColor ? UX_COLOR_ACCENT : UX_COLOR_ACCENT2)
: canvas->drawRect(barX, barY + (bar4 - bar3), barW, bar3, TFT_SILVER);

barX += barW + barSpace;
(rssi > -40)
? canvas->fillRect(barX, barY + (bar4 - bar4), barW, bar4, UX_COLOR_ACCENT)
(rssi > -45)
? canvas->fillRect(barX, barY + (bar4 - bar4), barW, bar4, altColor ? UX_COLOR_ACCENT : UX_COLOR_ACCENT2)
: canvas->drawRect(barX, barY + (bar4 - bar4), barW, bar4, TFT_SILVER);
}

Expand Down
Loading

0 comments on commit 16942c8

Please sign in to comment.