diff --git a/img/square.png b/img/square.png deleted file mode 100644 index c8eb5fd..0000000 Binary files a/img/square.png and /dev/null differ diff --git a/img/wifi_background.jpg b/img/wifi_background.jpg new file mode 100755 index 0000000..ceebe4c Binary files /dev/null and b/img/wifi_background.jpg differ diff --git a/src/config.cpp b/src/config.cpp index d86fe9e..6b8e454 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -10,6 +10,7 @@ // A list of all panels to be displayed, in order dashboard::panel::panel* PANELS[] = { new dashboard::panel::weather(), + new dashboard::panel::wifi(), }; size_t PANELS_LENGTH = sizeof(PANELS)/sizeof(PANELS[0]); @@ -22,6 +23,7 @@ dashboard::panel::panel* OVERLAY = new dashboard::panel::def_overlay(); const char* IMAGE_LOCATIONS[] = { "bmp_24.png", "sky.png", + "wifi_background.jpg", }; size_t IMAGE_LOCATIONS_LENGTH = sizeof(IMAGE_LOCATIONS)/sizeof(IMAGE_LOCATIONS[0]); diff --git a/src/config.def.hpp b/src/config.def.hpp index c9ce9c3..07cb519 100644 --- a/src/config.def.hpp +++ b/src/config.def.hpp @@ -77,6 +77,7 @@ constexpr int IMG_FLAGS = 0 #include "panel/panel.hpp" #include "panel/weather.hpp" #include "panel/def_overlay.hpp" +#include "panel/wifi.hpp" extern dashboard::panel::panel* PANELS[]; extern size_t PANELS_LENGTH; diff --git a/src/panel/wifi.cpp b/src/panel/wifi.cpp new file mode 100644 index 0000000..bf17aea --- /dev/null +++ b/src/panel/wifi.cpp @@ -0,0 +1,93 @@ +/////////////////////////////////////////////////////////////////////////////// +// Tyler Perkins +// 21-12-21 +// wifi panel +// + +#include "wifi.hpp" +#include "wifi_config.hpp" + +using namespace dashboard::panel; + +/////////////////////////////////////////////////////////////////////////////// +// Constructors /////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +wifi::wifi(){ + std::cerr << "WIFI CONSTRUCTOR\n"; + _texture = nullptr; + _time_on_screen = WIFI_DEFAULT_TIME_ON_SCREEN; +} + +wifi::~wifi(){ + std::cerr << "WIFI DECONSTRUCTOR\n"; + if(_texture != nullptr) + SDL_DestroyTexture(_texture); +} + +/////////////////////////////////////////////////////////////////////////////// +// Draw function ////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +void wifi::draw(){ + //create the texture if this is the first time running draw + if(_texture == nullptr){ + initTexture(); + update(); + update_texture(); + } + + SDL_RenderCopy(board::getRenderer(), _texture, NULL, NULL); +} + +/////////////////////////////////////////////////////////////////////////////// +// Helper functions /////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////// +// Update the information of wifi +// This DOES NOT update the display +void wifi::update() { + //this shows static info on the wifi network, which does need to change + //therefore, no update +} + +/////////////////////////////////////// +// Update the texture that is being +// displayed. Due to the nature of what +// is being displayed, this will only +// ever be called once, as the wifi +// info doesnt change +void wifi::update_texture(){ + std::cerr << "WIFI::UPDATE_TEXTURE\n"; + SDL_Rect tgt; + + SDL_SetRenderTarget(board::getRenderer(), _texture); + SDL_RenderClear(board::getRenderer()); + + //place background image + SDL_RenderCopy(board::getRenderer(), + board::getImage("wifi_background.jpg"), NULL, NULL); + + + + + + SDL_SetRenderTarget(board::getRenderer(), NULL); +} + +/////////////////////////////////////// +// Lazy load the texture object +// This is to make sure that all of SDL +// is init before we attempt to draw anything +void wifi::initTexture(){ + std::cerr << "WIFI INIT TEXTURE\n"; + if(_texture == nullptr){ + _texture = SDL_CreateTexture(board::getRenderer(), + SDL_PIXELFORMAT_RGBA8888, + SDL_TEXTUREACCESS_TARGET, + SCREEN_WIDTH, SCREEN_HEIGHT); + + SDL_SetTextureBlendMode(_texture, SDL_BLENDMODE_BLEND); + } +} diff --git a/src/panel/wifi.hpp b/src/panel/wifi.hpp new file mode 100644 index 0000000..fbee419 --- /dev/null +++ b/src/panel/wifi.hpp @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// Tyler Perkins +// 21-12-21 +// Wifi panel +// + +#pragma once + +#include "panel.hpp" + +#include +#include +#include + +#include + +namespace dashboard::panel { + class wifi : public panel { + public: + wifi(); + ~wifi(); + + void draw(); + private: + void update(); + void update_texture(); + void initTexture(); + }; +} + +#include "../board.hpp" diff --git a/src/panel/wifi_config.hpp b/src/panel/wifi_config.hpp new file mode 100644 index 0000000..9be4d04 --- /dev/null +++ b/src/panel/wifi_config.hpp @@ -0,0 +1,17 @@ +/////////////////////////////////////////////////////////////////////////////// +// Tyler Perkins +// 21-12-21 +// def overlay configuration +// + +#pragma once + +namespace dashboard::panel { + //Default time the slid is shown on the screen, in ms + //Default 15s + constexpr size_t WIFI_DEFAULT_TIME_ON_SCREEN = 15000; + + //How long should we wait between updates? in ms + //Due to the nature of this panel, this value is ignored + constexpr size_t WIFI_UPDATE_INTERVAL = 60000; +}