Skip to content

Commit

Permalink
Add Text-Ticker Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehaenger committed Sep 12, 2023
1 parent d8e2654 commit 0004dc0
Show file tree
Hide file tree
Showing 4 changed files with 708 additions and 6 deletions.
9 changes: 7 additions & 2 deletions Firmware/CoverUI/YardForce/WYM240128K1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "LEDcontrol.h"
#include "WidgetLedSymbol.hpp"
#include "WidgetBar.hpp"
#include "WidgetTextTicker.hpp"

// C images
LV_IMG_DECLARE(OM_Logo_Inv_120x54x1);
Expand All @@ -41,6 +42,7 @@ namespace display
// Status Screen Widgets
WidgetLedSymbol *v_led_ros, *v_led_charge;
WidgetBar *bar_gps, *bar_bat;
WidgetTextTicker *text_ticker_status;

/**
* @brief Rounder callback will round the display area to a multiple of 3, on x axis (RGB control lines of a pixel are connected to 3 monochrome pixels)
Expand Down Expand Up @@ -89,6 +91,9 @@ namespace display
// GPS & Battery bars
bar_gps = new WidgetBar(FA_SYMBOL_GPS2 " %d %%", LV_ALIGN_TOP_MID, 0, 30, UC1698_DISPLAY_WIDTH, 21);
bar_bat = new WidgetBar(FA_SYMBOL_BATTERY " %d %%", LV_ALIGN_TOP_MID, 0, 60, UC1698_DISPLAY_WIDTH, 21);
// Mower status text (ticker)
text_ticker_status = new WidgetTextTicker(LV_ALIGN_TOP_MID, 0, 95, UC1698_DISPLAY_WIDTH);
text_ticker_status->set_text("Bla bla");
}

static void anim_x_cb(void *var, int32_t v)
Expand Down Expand Up @@ -161,8 +166,8 @@ namespace display
disp = lv_disp_drv_register(&lv_disp_drv); // Register the driver and save the created display objects
lv_obj_set_style_bg_color(lv_scr_act(), lv_color_hex(0x000000), LV_PART_MAIN); // No background color

openmower_anim();
//mainStatusScreen();
//openmower_anim();
mainStatusScreen();
// test1();
// testCanvas();

Expand Down
7 changes: 3 additions & 4 deletions Firmware/CoverUI/YardForce/WidgetBar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ namespace display
{
// Init bar style settings for custom (labeled) bar graph
lv_style_init(&bar_style_bg);
lv_style_set_border_color(&bar_style_bg, lv_color_hex(0xffffff));
lv_style_set_border_color(&bar_style_bg, lv_color_white());
lv_style_set_border_width(&bar_style_bg, 2);
lv_style_set_pad_all(&bar_style_bg, 3); // To make the indicator smaller
lv_style_set_radius(&bar_style_bg, 4);

lv_style_init(&bar_style_indic);
lv_style_set_bg_opa(&bar_style_indic, LV_OPA_COVER);
lv_style_set_bg_color(&bar_style_indic, lv_color_hex(0xffffff));
lv_style_set_bg_color(&bar_style_indic, lv_color_white());
lv_style_set_radius(&bar_style_indic, 1);

// Draw bar
bar = lv_bar_create(lv_scr_act());
lv_obj_set_user_data(bar, (void *)bar_label.c_str()); // Store bar label to object user data
lv_obj_remove_style_all(bar); // To have a clean start
lv_obj_remove_style_all(bar); // To have a clean start
lv_obj_add_style(bar, &bar_style_bg, 0);
lv_obj_add_style(bar, &bar_style_indic, LV_PART_INDICATOR);

Expand All @@ -52,7 +52,6 @@ namespace display
lv_bar_set_value(bar, value, LV_ANIM_OFF);
}


private:
lv_obj_t *bar;
lv_style_t bar_style_bg, bar_style_indic;
Expand Down
45 changes: 45 additions & 0 deletions Firmware/CoverUI/YardForce/WidgetTextTicker.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @file WidgetTextTicker.hpp
* @author Apehaenger ([email protected])
* @brief Tiny class/wrapper for a text-ticker, which get displayed for mower status messages (as LVGL label + anim) for OpenMower https://github.com/ClemensElflein/OpenMower
* @version 0.1
* @date 2023-09-12
*
* @copyright Copyright (c) 2023
*/
#ifndef __WIDGETTEXTTICKER_HPP
#define __WIDGETTEXTTICKER_HPP

#include <Arduino.h>
#include <lvgl.h>
#include "LEDcontrol.h"

LV_FONT_DECLARE(PerfectPixel_20);

namespace display
{
class WidgetTextTicker
{
public:
WidgetTextTicker(lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs, lv_coord_t w)
{
label = lv_label_create(lv_scr_act());
//lv_obj_set_style_text_color(lv_scr_act(), lv_color_hex(0xffffff), LV_PART_MAIN);
lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_set_style_text_font(label, &PerfectPixel_20, LV_PART_MAIN);
lv_obj_align(label, align, x_ofs, y_ofs);
lv_obj_set_width(label, w);
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
}

void set_text(const char *t_text)
{
lv_label_set_text(label, t_text);
}

private:
lv_obj_t *label;
};
} // namespace display

#endif // __WIDGETTEXTTICKER_HPP
Loading

0 comments on commit 0004dc0

Please sign in to comment.