Added seperate UI HAL interface
* DisplayInterface now is for hardware display only * UIInterface is the general interface for UI
This commit is contained in:
parent
1bbafd4bb5
commit
03c4441bb0
4 changed files with 108 additions and 307 deletions
|
@ -1,18 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
class DisplayInterface
|
||||
{
|
||||
public:
|
||||
virtual void setup() = 0;
|
||||
virtual void setup_ui() = 0;
|
||||
virtual void flush() = 0;
|
||||
virtual void wifi_scan_complete(unsigned int size) = 0;
|
||||
virtual void clear_wifi_networks() = 0;
|
||||
virtual void update_wifi(bool connected) = 0;
|
||||
virtual void hide_keyboard() = 0;
|
||||
virtual void show_keyboard() = 0;
|
||||
virtual void updated() = 0;
|
||||
virtual void reset_settings_menu() = 0;
|
||||
virtual void update_battery(int percentage, bool isCharging, bool isConnected) = 0;
|
||||
virtual void setup(int backlight_pin, int enable_pin) = 0;
|
||||
virtual void pushPixel(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint16_t* pixel_values) = 0;
|
||||
virtual void turnOff() = 0;
|
||||
virtual void setBrightness(uint8_t brightness) = 0;
|
||||
};
|
17
Platformio/HAL/HardwareInterfaces/UIInterface.h
Normal file
17
Platformio/HAL/HardwareInterfaces/UIInterface.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
class UIInterface
|
||||
{
|
||||
public:
|
||||
virtual void setup() = 0;
|
||||
virtual void setup_ui() = 0;
|
||||
virtual void wifi_scan_complete(unsigned int size) = 0;
|
||||
virtual void clear_wifi_networks() = 0;
|
||||
virtual void update_wifi(bool connected) = 0;
|
||||
virtual void hide_keyboard() = 0;
|
||||
virtual void show_keyboard() = 0;
|
||||
virtual void update() = 0;
|
||||
virtual void reset_settings_menu() = 0;
|
||||
virtual void update_battery(int percentage, bool isCharging, bool isConnected) = 0;
|
||||
virtual void turnOff() = 0;
|
||||
};
|
|
@ -0,0 +1,67 @@
|
|||
|
||||
#include "display.hpp"
|
||||
|
||||
Display* Display::getInstance()
|
||||
{
|
||||
if (instance == nullptr)
|
||||
{
|
||||
instance = new Display();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void Display::setup(int backlight_pin, int enable_pin)
|
||||
{
|
||||
this->enable_pin = enable_pin;
|
||||
this->backlight_pin = backlight_pin;
|
||||
pinMode(this->enable_pin, OUTPUT);
|
||||
digitalWrite(this->enable_pin, HIGH);
|
||||
pinMode(this->backlight_pin, OUTPUT);
|
||||
digitalWrite(this->backlight_pin, HIGH);
|
||||
|
||||
this->tft = TFT_eSPI();
|
||||
|
||||
ledcSetup(LCD_BACKLIGHT_LEDC_CHANNEL, LCD_BACKLIGHT_LEDC_FREQUENCY, LCD_BACKLIGHT_LEDC_BIT_RESOLUTION);
|
||||
ledcAttachPin(this->backlight_pin, LCD_BACKLIGHT_LEDC_CHANNEL);
|
||||
ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, 0);
|
||||
|
||||
this->tft.init();
|
||||
this->tft.initDMA();
|
||||
this->tft.setRotation(0);
|
||||
this->tft.fillScreen(TFT_BLACK);
|
||||
this->tft.setSwapBytes(true);
|
||||
|
||||
// Slowly charge the VSW voltage to prevent a brownout
|
||||
// Workaround for hardware rev 1!
|
||||
for(int i = 0; i < 100; i++){
|
||||
digitalWrite(this->enable_pin, HIGH); // LCD Logic off
|
||||
delayMicroseconds(1);
|
||||
digitalWrite(this->enable_pin, LOW); // LCD Logic on
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Display::pushPixel(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint16_t* pixel_values)
|
||||
{
|
||||
this->tft.startWrite();
|
||||
this->tft.setAddrWindow( x, y, w, h );
|
||||
this->tft.pushPixelsDMA(pixel_values, w * h);
|
||||
this->tft.endWrite();
|
||||
}
|
||||
|
||||
void Display::setBrightness(uint8_t brigthness)
|
||||
{
|
||||
ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, brigthness);
|
||||
}
|
||||
|
||||
void Display::turnOff()
|
||||
{
|
||||
digitalWrite(this->backlight_pin, HIGH);
|
||||
digitalWrite(this->enable_pin, HIGH);
|
||||
pinMode(this->backlight_pin, INPUT);
|
||||
pinMode(this->enable_pin, INPUT);
|
||||
gpio_hold_en((gpio_num_t) this->backlight_pin);
|
||||
gpio_hold_en((gpio_num_t) this->enable_pin);
|
||||
}
|
||||
|
|
@ -1,305 +1,31 @@
|
|||
#pragma once
|
||||
#include "DisplayInterface.h"
|
||||
#include <lvgl.h>
|
||||
#include <TFT_eSPI.h>
|
||||
#include <Adafruit_FT6206.h>
|
||||
#include "driver/ledc.h"
|
||||
|
||||
/*LEDC Channel to use for the LCD backlight*/
|
||||
#define LCD_BACKLIGHT_LEDC_CHANNEL LEDC_CHANNEL_5
|
||||
|
||||
#define LCD_BACKLIGHT_LEDC_FREQUENCY 640
|
||||
|
||||
#define LCD_BACKLIGHT_LEDC_BIT_RESOLUTION 8
|
||||
|
||||
#define DEFAULT_BACKLIGHT_BRIGHTNESS 128
|
||||
|
||||
|
||||
class Display:public DisplayInterface
|
||||
{
|
||||
public:
|
||||
static Display* getInstance();
|
||||
/**
|
||||
* @brief Function to setup the display.
|
||||
*
|
||||
*/
|
||||
void setup();
|
||||
|
||||
/**
|
||||
* @brief Function to setup the user interface. This function has to be called after setup.
|
||||
*
|
||||
*/
|
||||
void setup_ui();
|
||||
|
||||
/**
|
||||
* @brief Function to flush the display (update what is shown on the LCD). This function is called within
|
||||
* the LVGL callback function
|
||||
*
|
||||
* @param disp
|
||||
* @param area
|
||||
* @param color_p
|
||||
*/
|
||||
void flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p );
|
||||
|
||||
|
||||
/**
|
||||
* @brief API function to inform display that wifi scan is completed
|
||||
*
|
||||
* @param size number of wifi networks found
|
||||
*/
|
||||
void wifi_scan_complete(unsigned int size);
|
||||
|
||||
/**
|
||||
* @brief Clear the wifi networks listed in the wifi selection page. This function is called before new wifi
|
||||
* networks are added to the list to avoid double listing
|
||||
*
|
||||
*/
|
||||
void clear_wifi_networks();
|
||||
|
||||
/**
|
||||
* @brief Update the wifi status. This function will update the wifi label in the status bar according to the
|
||||
* parameter.
|
||||
*
|
||||
* @param connected Boolean parameter to indicate if a wifi connection is established or not.
|
||||
*/
|
||||
void update_wifi(bool connected);
|
||||
|
||||
|
||||
/**
|
||||
* @brief API function which needs to be called regularly to update the display
|
||||
*
|
||||
*/
|
||||
void update();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function to update the battery indicator on the display
|
||||
*
|
||||
* @param percentage Battery percentage
|
||||
* @param isCharging True if the battery is charging. False otherwise
|
||||
* @param isConnected True if a battery is connected, false otherwise
|
||||
*/
|
||||
void update_battery(int percentage, bool isCharging, bool isConnected);
|
||||
|
||||
void turnOff();
|
||||
virtual void setup(int backlight_pin, int enable_pin) override;
|
||||
virtual void pushPixel(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint16_t* pixel_values) override;
|
||||
virtual void setBrightness(uint8_t brightness) override;
|
||||
virtual void turnOff() override;
|
||||
private:
|
||||
/**
|
||||
* @brief Function to change the settings menu to main page again.
|
||||
*
|
||||
*/
|
||||
void reset_settings_menu();
|
||||
/**
|
||||
* @brief Function to hide the keyboard. If the keyboard is attached to a text area, it will be hidden when the
|
||||
* text area is defocused. This function can be used if the keyboard need to be hidden due to some script event.
|
||||
*
|
||||
*/
|
||||
void hide_keyboard();
|
||||
|
||||
/**
|
||||
* @brief Function to show the keyboard. If a text area needs the keybaord, it should be attached to the text area
|
||||
* using the approbiate function. The keyboard will then show up when the text area is focused. This function is
|
||||
* needed if the keyboard should be shown due to some script or other trigger.
|
||||
*
|
||||
*/
|
||||
void show_keyboard();
|
||||
Display();
|
||||
/**
|
||||
* @brief Pin used for LCD backlight control
|
||||
*
|
||||
*/
|
||||
int backlight_pin;
|
||||
|
||||
/**
|
||||
* @brief Pin used to enable the LCD
|
||||
*
|
||||
*/
|
||||
static Display* instance;
|
||||
int enable_pin;
|
||||
|
||||
/**
|
||||
* @brief Width of the display in pixel
|
||||
*
|
||||
*/
|
||||
int width;
|
||||
|
||||
/**
|
||||
* @brief Height of the display in pixel
|
||||
*
|
||||
*/
|
||||
int height;
|
||||
|
||||
/**
|
||||
* @brief Pointer to the buffer used for drawing on the screen
|
||||
*
|
||||
*/
|
||||
lv_color_t *bufA;
|
||||
|
||||
/**
|
||||
* @brief Pointer to the buffer used for drawing on the screen
|
||||
*
|
||||
*/
|
||||
lv_color_t *bufB;
|
||||
|
||||
/**
|
||||
* @brief Object of the touch input driver
|
||||
*
|
||||
*/
|
||||
Adafruit_FT6206 touch;
|
||||
/**
|
||||
* @brief Keyboard object used whenever a keyboard is needed.
|
||||
*
|
||||
*/
|
||||
lv_obj_t* kb;
|
||||
|
||||
/**
|
||||
* @brief Variable to store the primary color
|
||||
*
|
||||
*/
|
||||
lv_color_t primary_color;
|
||||
|
||||
/**
|
||||
* @brief Object of the TFT driver
|
||||
*
|
||||
*/
|
||||
int backlight_pin;
|
||||
Display();
|
||||
TFT_eSPI tft;
|
||||
|
||||
/**
|
||||
* @brief Set the up settings object
|
||||
*
|
||||
* @param parent
|
||||
*/
|
||||
void setup_settings(lv_obj_t* parent);
|
||||
|
||||
/**
|
||||
* @brief Function to create the keyboard object which can then be attached to different text areas.
|
||||
*
|
||||
*/
|
||||
void create_keyboard();
|
||||
|
||||
/**
|
||||
* @brief Function to attach the keyboard to a text area. If the text area is selected, the keyboard
|
||||
* is shown and if the textarea is defocused, the keyboard will be hidden again.
|
||||
*
|
||||
* @param textarea Textarea where the keyboard should be attached to.
|
||||
*/
|
||||
void attach_keyboard(lv_obj_t* textarea);
|
||||
|
||||
/**
|
||||
* @brief LVGL Menu for settings pages as needed.
|
||||
*
|
||||
*/
|
||||
lv_obj_t* settingsMenu;
|
||||
|
||||
/**
|
||||
* @brief Main page of the settings menu
|
||||
*
|
||||
*/
|
||||
lv_obj_t* settingsMainPage;
|
||||
|
||||
/**
|
||||
* @brief Battery percentage label
|
||||
*
|
||||
*/
|
||||
lv_obj_t* objBattPercentage;
|
||||
|
||||
/**
|
||||
* @brief Battery icon object in the status bar
|
||||
*
|
||||
*/
|
||||
lv_obj_t* objBattIcon;
|
||||
|
||||
/************************************** WIFI Settings Menu *******************************************************/
|
||||
/**
|
||||
* @brief Container within the wifi selection page
|
||||
*/
|
||||
lv_obj_t* wifi_setting_cont;
|
||||
|
||||
/**
|
||||
* @brief Wifi settings entry point on the settings tab
|
||||
*
|
||||
*/
|
||||
lv_obj_t* wifiOverview;
|
||||
|
||||
/**
|
||||
* @brief Label in the wifi password page. This label is updated with the selected SSID when the credentials for
|
||||
* a wifi network is entered.
|
||||
*
|
||||
*/
|
||||
lv_obj_t* wifi_password_label;
|
||||
|
||||
/**
|
||||
* @brief Menu Subpage for the wifi password
|
||||
*/
|
||||
lv_obj_t* wifi_password_page;
|
||||
|
||||
/**
|
||||
* @brief Menu Subpage for wifi selection
|
||||
*/
|
||||
lv_obj_t* wifi_selection_page;
|
||||
|
||||
/**
|
||||
* @brief Wifi Label shown in the top status bar
|
||||
*/
|
||||
lv_obj_t* WifiLabel;
|
||||
|
||||
/**
|
||||
* @brief Number of wifi subpage needed to display the found wifi networks
|
||||
*
|
||||
*/
|
||||
unsigned int no_subpages;
|
||||
|
||||
/**
|
||||
* @brief number of wifi networks found
|
||||
*
|
||||
*/
|
||||
unsigned int no_wifi_networks;
|
||||
|
||||
|
||||
/**
|
||||
* @brief callback function to get next wifi subpage. This callback can be used to get the next or previous page
|
||||
*
|
||||
* @param e lvgl event object
|
||||
*/
|
||||
void next_wifi_selection_subpage(lv_event_t* e);
|
||||
|
||||
/**
|
||||
* @brief Create a wifi selection sub page object
|
||||
*
|
||||
* @param menu LVGL Menu where the sub page should be added to
|
||||
* @return lv_obj_t* Menu sub page object pointer
|
||||
*/
|
||||
lv_obj_t* create_wifi_selection_page(lv_obj_t* menu);
|
||||
|
||||
/**
|
||||
* @brief Method to create the wifi password sub page
|
||||
*
|
||||
* @param menu Menu where the sub page should be created
|
||||
* @return lv_obj_t* menu sub page object pointer
|
||||
*/
|
||||
lv_obj_t* create_wifi_password_page(lv_obj_t* menu);
|
||||
|
||||
/**
|
||||
* @brief Method to create the wifi settings on the main page
|
||||
*
|
||||
* @param parent lv object parent where the main settings page should be added to
|
||||
*/
|
||||
void create_wifi_main_page(lv_obj_t* parent);
|
||||
|
||||
/**
|
||||
* @brief Method to create wifi settings. This method will call the create_wifi_selection_page,
|
||||
* the create_wifi_password_page, and the create_wifi_main_page
|
||||
*
|
||||
* @param menu Settings menu where the sub pages should be added to
|
||||
* @param parent lv object parent where the main settings page should be added to
|
||||
*/
|
||||
void create_wifi_settings(lv_obj_t* menu, lv_obj_t* parent);
|
||||
|
||||
/**
|
||||
* @brief Function to update the wifi selection sub page
|
||||
*
|
||||
* @param page index of the page to display
|
||||
*/
|
||||
void update_wifi_selection_subpage(int page);
|
||||
|
||||
/************************************** Display settings menu ********************************************************/
|
||||
/**
|
||||
* Variable to store the current backlight brightness level
|
||||
*/
|
||||
unsigned int backlight_brightness;
|
||||
|
||||
/**
|
||||
* @brief Function to create the display settings page.
|
||||
*
|
||||
* @param parent LVGL object acting as a parent for the display settings page
|
||||
*/
|
||||
void display_settings(lv_obj_t* parent);
|
||||
};
|
Loading…
Add table
Reference in a new issue