Skip to content

make notifications frame indicators bounce on text message #715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ debug_tool = jlink
; monitor adapter_khz 10000

lib_deps =
https://github.com/meshtastic/esp8266-oled-ssd1306.git#35d796226b853b0c0ff818b2f1aa3d35e7296a96 ; ESP8266_SSD1306
https://github.com/meshtastic/esp8266-oled-ssd1306.git#22c7eef2025431ba5e1f5f8bd1720cfdcc49cadc ; ESP8266_SSD1306
https://github.com/geeksville/OneButton.git ; OneButton library for non-blocking button debounce
1202 ; CRC32, explicitly needed because dependency is missing in the ble ota update lib
https://github.com/meshtastic/arduino-fsm.git#2f106146071fc7bc620e1e8d4b88dc4e0266ce39
Expand Down
36 changes: 32 additions & 4 deletions src/graphics/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace graphics

// A text message frame + debug frame + all the node infos
static FrameCallback normalFrames[MAX_NUM_NODES + NUM_EXTRA_FRAMES];
static FrameNotificationCallback notificationCallback;
static uint32_t targetFramerate = IDLE_FRAMERATE;
static char btPIN[16] = "888888";

Expand Down Expand Up @@ -136,6 +137,12 @@ static void drawIconScreen(const char *upperMsg, OLEDDisplay *display, OLEDDispl
// FIXME - draw serial # somewhere?
}

static void handleFrameNotificationCallback(uint32_t FrameNumber, void* UI) {
//DEBUG_MSG("SCREEN: Received notification that frame %d is active", FrameNumber);
OLEDDisplayUi* ui = reinterpret_cast<OLEDDisplayUi *>(UI);
ui->removeFrameFromNotifications(FrameNumber);
}

static void drawBootScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
// Draw region in upper left
Expand Down Expand Up @@ -941,8 +948,10 @@ void Screen::setFrames()
normalFrames[numframes++] = drawCriticalFaultFrame;

// If we have a text message - show it next
if (devicestate.has_rx_text_message)
if (devicestate.has_rx_text_message) {
textMessageFrame = numframes;
normalFrames[numframes++] = drawTextMessageFrame;
}

// then all the nodes
for (size_t i = 0; i < numnodes; i++)
Expand All @@ -967,6 +976,9 @@ void Screen::setFrames()
DEBUG_MSG("Finished building frames. numframes: %d\n", numframes);

ui.setFrames(normalFrames, numframes);

notificationCallback = handleFrameNotificationCallback;
ui.setFrameNotificationCallback(&notificationCallback);
ui.enableAllIndicators();

prevFrame = -1; // Force drawNodeInfo to pick a new node (because our list
Expand Down Expand Up @@ -1343,11 +1355,27 @@ int Screen::handleStatusUpdate(const meshtastic::Status *arg)

int Screen::handleTextMessage(const MeshPacket *arg)
{
if (showingNormalScreen) {
setFrames(); // Regen the list of screens (will show new text message)
DEBUG_MSG("SCREEN: text received; telling ui to bounce the frame symbol");
setFastFramerate();
// The text message screen is currently at a variable position in the frame array
// it should usually come after all plugins and critical messages
// let's use an instance variable to track which UI frame is for text messages.
// TODO: Move the text messages display UI to a plugin
// so we can get it out of Screen.cpp
ui.addFrameToNotifications(textMessageFrame);

return 0;
}
bool Screen::goToNextNotification() {
uint32_t frame = ui.getFirstNotifyingFrame();
if (frame == -1) {
return false;
}
ui.switchToFrame(frame);
}

return 0;
void Screen::goToFirstUIFrame() {
ui.switchToFrame(0);
}

} // namespace graphics
4 changes: 4 additions & 0 deletions src/graphics/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ class Screen : public concurrency::OSThread

int handleStatusUpdate(const meshtastic::Status *arg);
int handleTextMessage(const MeshPacket *arg);
bool goToNextNotification();
void goToFirstUIFrame();

/// Used to force (super slow) eink displays to draw critical frames
void forceDisplay();
Expand Down Expand Up @@ -247,6 +249,8 @@ class Screen : public concurrency::OSThread

static void drawDebugInfoWiFiTrampoline(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);

uint32_t textMessageFrame;

/// Queue of commands to execute in doTask.
TypedQueue<ScreenCmd> cmdQueue;
/// Whether we are using a display
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ class ButtonThread : public OSThread
{
#ifndef NO_ESP32
disablePin();
if (!screen->goToNextNotification()) {
screen->goToFirstUIFrame();
}
#endif
}

Expand Down