Skip to content

Commit

Permalink
Support for different display sizes added. A plugin can have differen…
Browse files Browse the repository at this point in the history
…t views for the different display sizes. Which view to use will be decided on compile time by the CONFIG_LED_MATRIX_WIDTH and CONFIG_LED_MATRIX_HEIGHT.
  • Loading branch information
BlueAndi committed Jun 1, 2024
1 parent 1365493 commit 1a8f0a3
Show file tree
Hide file tree
Showing 135 changed files with 8,883 additions and 2,780 deletions.
13 changes: 7 additions & 6 deletions config/display.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ build_flags =
; ********************************************************************************
[display:hub75-esp32]
build_flags =
${display:common.build_flags}
-D CONFIG_LED_MATRIX_WIDTH=64U
-D CONFIG_LED_MATRIX_HEIGHT=64U
-D R1_PIN=25
Expand Down Expand Up @@ -82,6 +83,8 @@ lib_ignore_external =
[display:lilygo_ttgo_tdisplay]
build_flags =
${display:common.build_flags}
-D CONFIG_LED_MATRIX_WIDTH=32U
-D CONFIG_LED_MATRIX_HEIGHT=8U
-D USER_SETUP_LOADED=1
-D ST7789_DRIVER
-D TFT_WIDTH=135
Expand All @@ -98,8 +101,6 @@ build_flags =
-D SPI_FREQUENCY=40000000
-D SPI_READ_FREQUENCY=6000000
-D DISABLE_ALL_LIBRARY_WARNINGS
-D TFT_MATRIX_WIDTH=32U
-D TFT_MATRIX_HEIGHT=8U
-D TFT_PIXEL_WIDTH=6
-D TFT_PIXEL_HEIGHT=6
-D TFT_PIXEL_DISTANCE=1
Expand All @@ -120,6 +121,8 @@ lib_ignore_external =
[display:lilygo_tdisplay-s3]
build_flags =
${display:common.build_flags}
-D CONFIG_LED_MATRIX_WIDTH=32U
-D CONFIG_LED_MATRIX_HEIGHT=8U
-D USER_SETUP_LOADED=1
-D ST7789_DRIVER
-D TFT_PARALLEL_8_BIT
Expand Down Expand Up @@ -148,8 +151,6 @@ build_flags =
-D SPI_READ_FREQUENCY=2000000
-D SPI_TOUCH_FREQUENCY=2500000
-D DISABLE_ALL_LIBRARY_WARNINGS
-D TFT_MATRIX_WIDTH=32U
-D TFT_MATRIX_HEIGHT=8U
-D TFT_PIXEL_WIDTH=8
-D TFT_PIXEL_HEIGHT=8
-D TFT_PIXEL_DISTANCE=1
Expand All @@ -171,6 +172,8 @@ lib_ignore_external =
[display:m5stack_core]
build_flags =
${display:common.build_flags}
-D CONFIG_LED_MATRIX_WIDTH=32U
-D CONFIG_LED_MATRIX_HEIGHT=8U
-D USER_SETUP_LOADED=1
-D ILI9341_DRIVER
-D M5STACK
Expand All @@ -189,8 +192,6 @@ build_flags =
-D SPI_READ_FREQUENCY=5000000
-D TFT_INVERSION_ON
-D DISABLE_ALL_LIBRARY_WARNINGS
-D TFT_MATRIX_WIDTH=32U
-D TFT_MATRIX_HEIGHT=8U
-D TFT_PIXEL_WIDTH=6
-D TFT_PIXEL_HEIGHT=6
-D TFT_PIXEL_DISTANCE=1
Expand Down
17 changes: 8 additions & 9 deletions doc/architecture/uml/gfx.wsd
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class "BaseGfxOverlayBitmap<TColor>" as baseGfxOverlayBitmap {

note top of baseGfxOverlayBitmap
Maps the bitmap interface to a GFX inherited class.
This is helpful, e.g. in case a BaseGfxMap shall
This is helpful, e.g. in case a BaseGfxCanvas shall
be drawn.
end note

Expand Down Expand Up @@ -92,13 +92,13 @@ baseGfxOverlayBitmap --|> baseGfxBitmap

baseGfxOverlayBitmap --> baseGfx

class "BaseGfxMap<TColor>" as baseGfxMap {
class "BaseGfxCanvas<TColor>" as baseGfxCanvas {
- m_gfx : BaseGfx<TColor>*
- m_offsX : int16_t
- m_offsY : int16_t
- m_width : uint16_t
- m_height : uint16_t
+ BaseGfxMap(gfx : BaseGfx<TColor>, width : uint16_t, height : uint16_t, offsX : int16_t, offsY : int16_t)
+ BaseGfxCanvas(gfx : BaseGfx<TColor>, width : uint16_t, height : uint16_t, offsX : int16_t, offsY : int16_t)
+ setGfx(gfx : BaseGfx<TColor>&) : void
+ getOffsX() const : int16_t
+ getOffsY() const : int16_t
Expand All @@ -112,15 +112,14 @@ class "BaseGfxMap<TColor>" as baseGfxMap {
+ drawPixel(x : int16_t, y : int16_t, color : const TColor&) : void
}

note left of baseGfxMap
A map is like a window over graphic operations.
note left of baseGfxCanvas
The canvas ensures that all graphic operation
will be performed only inside the canvas.
It defines the window size and the offset.
It ensures that drawing is kept inside
its defined borders (width, height).
end note

baseGfxMap ---|> baseGfx
baseGfxMap ---> baseGfx
baseGfxCanvas ---|> baseGfx
baseGfxCanvas ---> baseGfx

note left of baseGfx
Basic graphics operations,
Expand Down
109 changes: 23 additions & 86 deletions doc/architecture/uml/widgets.wsd
Original file line number Diff line number Diff line change
@@ -1,112 +1,49 @@
@startuml

note as N1
This diagram shows only the important classes
and interfaces. In case of class attributes and
methods, it may not be complete compared to
sourcecode.
end note

class YAGfx
class YAGfxCanvas

class WidgetGroup {
- m_gfx : YAGfx&
- m_widgets : LinkedList<Widget*>
+ WidgetGroup(width : uint16_t, height : uint16_t, x : uint16_t, y : uint16_t)
+ getWidth() const : uint16_t
+ getHeight() const : uint16_t
+ getColor(x : int16_t, y : int16_t) = 0 : Color&
+ getColor(x : int16_t, y : int16_t) const : const Color&
+ addWidget(widget : Widget&) : bool
+ removeWidget(widget : Widget&) : bool
+ children() : const LinkedList<Widget*>&
+ update() : void
+ find(name : const char*) : Widget*
- paint(gfx : YAGfx&) : void
- drawPixel(x : int16_t, y : int16_t, color : uint16_t) : void
}

YAGfx <|-- WidgetGroup
Widget <|-- WidgetGroup
WidgetGroup o--> Widget

note right of WidgetGroup
A widget group contains several widgets and
will update them periodically. It ensures
that a widget can not draw over the canvas
borders.

The widget group itself is a widget too and therefore
can be inside another widget group.
note left of YAGfxCanvas
The widget uses the canvas to draw itself.
end note

class Widget {
- m_type : const char*
- m_posX : uint16_t
- m_posY : uint16_t
- m_name : const char*
- m_isEnabled : bool
+ move(x : uint16_t, y : uint16_t) : void
+ getPos(x : uint16_t&, y : uint16_t&) const : void
- m_canvas : YAGfxCanvas
- {abstract} paint(gfx : YAGfx&) : void
+ update(gfx : YAGfx&) : void
+ getType() : const char*
+ getName() : const char*
+ setName(name : const char*) : void
+ find(name : const char*) : Widget*
# {abstract} paint(gfx : YAGfx&) = 0 : void
}

note left of Widget
The base widget contains the
position inside a canvas and declares
the graphics interface.
The base widget provides the common widget functionality.
It contains the width, height and position in the parent canvas.
end note

class TextWidget {
- m_str : String
- m_textColor : uint16_t
+ setFormatStr(str : const String&) : void
+ getFormatStr() : String
+ getStr() : String
+ setTextColor(color : uint16_t) : void
+ getTextColor() const : uint16_t
+ setFont(font : const GFXfont*) : void
+ getFont() : const GFXfont*
+ {static} setScrollPause(pause : uint32_t) : bool
+ getScrollInfo(isScrollingEnabled : bool&, scrollingCnt : uint32_t&) : bool
YAGfx <|-- YAGfxCanvas
YAGfxCanvas <-- Widget

class BitmapWidget {
- paint(gfx : YAGfx&) : void
}
class CanvasWidget {
- paint(gfx : YAGfx&) : void
}

Widget <|-- TextWidget

class BitmapWidget {
- m_buffer : uint16_t*
- m_width : uint16_t
- m_height : uint16_t
+ set(bitmap : const Color*, width : uint16_t, height : uint16_t)
+ get(width : uint16_t&, height: uint16_t&) : const Color*
+ load(fs : FS&, filename : const String&) : bool
class LampWidget {
- paint(gfx : YAGfx&) : void
}

Widget <|-- BitmapWidget
class ProgressBar {
- paint(gfx : YAGfx&) : void
}

class LampWidget {
- m_isOn : bool
- m_colorOff : uint16_t
- m_colorOn : uint16_t
- m_width : uint16_t
+ setOnState(state : bool) : void
+ getOnState() const : bool
+ setColorOff(color : const Color&) : void
+ getColorOff() : const Color&
+ setColorOn(color : const Color&) : void
+ getColorOn() : const Color&
+ setWidth(width : uint16_t) : void
+ getWidth() const : uin16_t
class TextWidget {
- paint(gfx : YAGfx&) : void
}

Widget <|-- BitmapWidget
Widget <|-- CanvasWidget
Widget <|-- LampWidget
Widget <|-- ProgressBar
Widget <|-- TextWidget

@enduml
37 changes: 4 additions & 33 deletions lib/BTCQuotePlugin/src/BTCQuotePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
/******************************************************************************
* Includes
*****************************************************************************/
#include "AsyncHttpClient.h"
#include "BTCQuotePlugin.h"
#include "FileSystem.h"

#include <FileSystem.h>
#include <ArduinoJson.h>
#include <Logging.h>
#include <JsonFile.h>
Expand All @@ -61,9 +60,6 @@
* Local Variables
*****************************************************************************/

/* Initialize image path. */
const char* BTCQuotePlugin::BTC_USD_IMAGE_PATH = "/plugins/BTCQuotePlugin/BTC_USD.bmp";

/******************************************************************************
* Public Methods
*****************************************************************************/
Expand All @@ -72,30 +68,7 @@ void BTCQuotePlugin::start(uint16_t width, uint16_t height)
{
MutexGuard<MutexRecursive> guard(m_mutex);

m_iconCanvas.setPosAndSize(0, 0, ICON_WIDTH, ICON_HEIGHT);
(void)m_iconCanvas.addWidget(m_bitmapWidget);

(void)m_bitmapWidget.load(FILESYSTEM, BTC_USD_IMAGE_PATH);

/* The text canvas is left aligned to the icon canvas and it spans over
* the whole display height.
*/
m_textCanvas.setPosAndSize(ICON_WIDTH, 0, width - ICON_WIDTH, height);
(void)m_textCanvas.addWidget(m_textWidget);

/* Choose font. */
m_textWidget.setFont(Fonts::getFontByType(m_fontType));

/* The text widget inside the text canvas is left aligned on x-axis and
* aligned to the center of y-axis.
*/
if (height > m_textWidget.getFont().getHeight())
{
uint16_t diffY = height - m_textWidget.getFont().getHeight();
uint16_t offsY = diffY / 2U;

m_textWidget.move(0, offsY);
}
m_view.init(width, height);

initHttpClient();
}
Expand Down Expand Up @@ -182,9 +155,7 @@ void BTCQuotePlugin::update(YAGfx& gfx)
{
MutexGuard<MutexRecursive> guard(m_mutex);

gfx.fillScreen(ColorDef::BLACK);
m_iconCanvas.update(gfx);
m_textCanvas.update(gfx);
m_view.update(gfx);
}

/******************************************************************************
Expand Down Expand Up @@ -296,7 +267,7 @@ void BTCQuotePlugin::handleWebResponse(DynamicJsonDocument& jsonDoc)

LOG_INFO("BTC/USD to print %s", m_relevantResponsePart.c_str());

m_textWidget.setFormatStr(m_relevantResponsePart);
m_view.setFormatText(m_relevantResponsePart);
}
}

Expand Down
Loading

0 comments on commit 1a8f0a3

Please sign in to comment.