1+ //
2+ // This file contains a simple dashboard that is set up using the dashboard classes
3+ // within the menu library extras. See ref docs:
4+ //
5+ // Reference docs https://www.thecoderscorner.com/ref-docs/tcmenu/html/_drawable_dashboard_8h.html
6+ //
17
28#include " picoAdafruitDashboard_menu.h"
39#include < Adafruit_ILI9341.h>
410#include " dashboardConfig.h"
511
12+ // START a title widget that was built using TcMenu Designers widget generator, see the "Code" menu for the widget
13+ // generator. This is added to both the main renderer and the dashboard.
14+
615// YesNo icon=0, width=17, height=12, size=36
716const uint8_t YesNoWidIcon0[] PROGMEM = {
817 0x00 ,0x40 ,0x00 ,0x00 ,0xe0 ,0x00 ,0x00 ,0xf0 ,0x01 ,0x00 ,0xf8 ,0x00 ,0x00 ,0x7c ,0x00 ,0x04 ,0x3e ,0x00 ,0x0e ,0x1f ,
@@ -18,59 +27,105 @@ const uint8_t* const YesNoWidIcons[] PROGMEM = { YesNoWidIcon0, YesNoWidIcon1 };
1827// Widget Generator yesNo
1928TitleWidget YesNoWidget (YesNoWidIcons, 2 , 17 , 12 , nullptr );
2029
30+ // END title widget
2131
2232// TickIcon icon=0, width=17, height=12, size=36
2333const uint8_t TickIconBitmap0[] PROGMEM = {
2434 0x00 ,0x40 ,0x00 ,0x00 ,0xe0 ,0x00 ,0x00 ,0xf0 ,0x01 ,0x00 ,0xf8 ,0x00 ,0x00 ,0x7c ,0x00 ,0x04 ,0x3e ,0x00 ,0x0e ,0x1f ,
2535 0x00 ,0x9f ,0x0f ,0x00 ,0xfe ,0x07 ,0x00 ,0xfc ,0x03 ,0x00 ,0xf8 ,0x01 ,0x00 ,0xf0 ,0x00 ,0x00
2636};
2737
38+ // we define a global pointer to the dashboard, it will be created during the dash setup.
2839DrawableDashboard* mainDashboard;
2940
41+ // Any value item or scroll choice (integer based items) can have ranges of colors, these allow the color to be
42+ // selected based on the value, IE for a rev-counter above 8000 RPM may be shown in red, otherwise green. These
43+ // represented as below. In this case we are creating for an enum value.
44+ // Note that this is a parameter, not the actual dashboard item, they are defined below
3045DashDrawParametersIntUpdateRange::IntColorRange drawEnumColorRanges[] {
3146 {ILI9341_YELLOW, ILI9341_RED, 0 , 1 },
3247 {ILI9341_CYAN, ILI9341_BLUE, 2 , 3 }
3348};
3449DashDrawParametersIntUpdateRange drawEnumWithIntRange (ILI9341_WHITE, ILI9341_BLACK, ILI9341_BLACK, ILI9341_YELLOW,
3550 &RobotoMedium24, drawEnumColorRanges, 2 );
3651
52+ // As above we create another one for the analog item, it has two ranges.
53+ // Note that this is a parameter, not the actual dashboard item, they are defined below
3754DashDrawParametersIntUpdateRange::IntColorRange drawAnalogColorRanges[] {
3855 {ILI9341_LIGHTGREY, ILI9341_BLUE, 0 , 50 },
3956 {ILI9341_YELLOW, ILI9341_RED, 51 , 100 }
4057};
4158DashDrawParametersIntUpdateRange drawAnalogValueWithIntRange (ILI9341_WHITE, ILI9341_BLACK, ILI9341_BLACK, ILI9341_WHITE,
4259 &RobotoMedium24, drawAnalogColorRanges, 2 );
60+
61+ // and lastly we create a simple one for the title.
62+ // Note that this is a parameter, not the actual dashboard item, they are defined below
4363DashDrawParameters titleDrawParameters (ILI9341_WHITE, ILI9341_BLACK, &RobotoMedium24);
4464
65+ //
66+ // Although the dashboard support provides a wide range of menu drawing capabilities, it does not cover every case
67+ // so you can create a delegate that can do the extra drawing and other functions that are needed. Here is a simple
68+ // example that draws a few extra items onto the display
69+ // For drawing onto device drawble see:
70+ // https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/rendering-with-tcmenu-lcd-tft-oled/#drawing-direct-to-the-display-with-devicedrawabl
71+ // For more on the delegate class and all the points where you can extend
72+ // https://www.thecoderscorner.com/ref-docs/tcmenu/html/class_drawable_dashboard_delegate.html
73+ //
4574class MyDrawableDashboardDelegate : public DrawableDashboardDelegate {
4675public:
76+ // this is called after the dashboard has opened
4777 void dashboardDidOpen (BaseMenuRenderer *renderer) override {
4878 switches.getEncoder ()->changePrecision (320 , 100 );
4979 }
5080
81+ // this is called before the dashboard draws any items
5182 void dashboardWillDraw (unsigned int encVal, RenderPressMode mode) override {
5283 renderer.getDeviceDrawable ()->drawXBitmap (Coord (300 , 30 ), Coord (17 , 12 ), TickIconBitmap0);
5384 }
5485
86+ // this is called after the dashboard has drawn all items, you get the current value of the encoder and the
87+ // current state of the select button.
5588 void dashboardDidDraw (unsigned int encVal, RenderPressMode mode) override {
89+ // get the drawing device from the renderer and its dimensions
5690 DeviceDrawable *pDrawable = renderer.getDeviceDrawable ();
5791 const Coord &totalSize = Coord (pDrawable->getDisplayDimensions ().x , 20 );
92+
93+ // create a dashboard wrapper that can work out if we are on a sub device or the main device.
5894 DrawableWrapper wrapper (pDrawable, &titleDrawParameters, &menuSettings, Coord (0 , 200 ), totalSize);
95+
96+ // now we draw onto the drawable, we don't need to care if it is buffered or not
5997 wrapper.getDrawable ()->setDrawColor (wrapper.bgCol ());
6098 wrapper.getDrawable ()->drawBox (wrapper.offsetLocation (Coord (0 , 200 )), totalSize, true );
6199 wrapper.getDrawable ()->setDrawColor (wrapper.fgCol ());
62100 wrapper.getDrawable ()->drawBox (wrapper.offsetLocation (Coord (0 , 200 )), Coord (encVal, 20 ), true );
101+
102+ // lastly we tell the wrapper that we are done, if needed it will push the buffer to the screen
63103 wrapper.endDraw ();
64104 }
65105} myDrawableDashboardDelegate;
66106
67107void setupDashboard () {
108+ // Reference docs https://www.thecoderscorner.com/ref-docs/tcmenu/html/_drawable_dashboard_8h.html
109+
110+ // create a dashboard instance, giving it the renderer and drawable, any widgets to display in the top corner,
111+ // and the mode in which it is to operate
68112 mainDashboard = new DrawableDashboard (renderer.getDeviceDrawable (), &renderer, &YesNoWidget,
69113 DrawableDashboard::DASH_ON_RESET_CLICK_EXIT);
114+
115+ // here we tell the dashboard about the delegate we created above.
70116 mainDashboard->setDelegate (&myDrawableDashboardDelegate);
117+
118+ // now prepare the base colors
71119 mainDashboard->setBaseColors (RGB (0 , 0 , 0 ), RGB (220 , 220 , 220 ));
120+
121+ // here we set up the entries on the dashboard, this is where we provide the menu item and position on the display
122+ // for each entry. A parameter object that we defined above is then associated with an item. Note that more than
123+ // one entry can share a parameter.
72124 mainDashboard->addDrawingItem (&menuAnalog, Coord (0 , 0 ), &drawAnalogValueWithIntRange, 10 , nullptr , 10 );
73125 mainDashboard->addDrawingItem (&menuEnum, Coord (0 , 50 ), &drawEnumWithIntRange, 10 , nullptr , 10 );
74126 mainDashboard->addDrawingItem (&menuSettings, Coord (0 , 100 ), &titleDrawParameters, 0 , " Dashboard" );
127+
128+ // lastly, add the dashboard to the renderer, this is important, the dashboard implements CustomDrawing so it
129+ // handles taking over the display and reset notification.
75130 renderer.setCustomDrawingHandler (mainDashboard);
76- }
131+ }
0 commit comments