Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stock Api & styling updates #77

Closed
wants to merge 11 commits into from
6 changes: 4 additions & 2 deletions Info-Orbs/include/core/wifiWidget.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
#ifndef WIFIWIDGET_H
#define WIFIWIDGET_H
#include "widget.h"

#include <widget.h>

class WifiWidget : public Widget{
public:
Expand All @@ -11,7 +12,8 @@ class WifiWidget : public Widget{
void update(bool force = false) override;
void draw(bool force = false) override;
void changeMode() override;

String getName() override;

bool isConnected() { return m_isConnected; }

private:
Expand Down
25 changes: 20 additions & 5 deletions Info-Orbs/include/model/stockDataModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,46 @@
class StockDataModel {
public:
StockDataModel();
StockDataModel &setCurrencySymbol(String currencySymbol);
String getCurrencySymbol();
StockDataModel &setSymbol(String symbol);
String getSymbol();
StockDataModel &setTicker(String ticker);
String getTicker();
StockDataModel &setCompany(String company);
String getCompany();
StockDataModel &setCurrentPrice(float currentPrice);
float getCurrentPrice();
String getCurrentPrice(int8_t digits);
StockDataModel &setVolume(float volume);
float getVolume();
String getVolume(int8_t digits);
StockDataModel &setHighPrice(float volume);
float getHighPrice();
String getHighPrice(int8_t digits);
StockDataModel &setLowPrice(float volume);
float getLowPrice();
String getLowPrice(int8_t digits);
StockDataModel &setPriceChange(float change);
float getPriceChange();
String getPriceChange(int8_t digits);
StockDataModel &setPercentChange(float percentChange);
float getPercentChange();
String getPercentChange(int8_t digits);

bool isChanged();
StockDataModel &setChangedStatus(bool changed);

private:
String m_symbol = "";
String m_ticker = "";
String m_company = "";
String m_currencySymbolGBP = "GBP";
String m_currencySymbolEUR = "EUR";
String m_currencySymbol = "";
float m_currentPrice = 0.0;
float m_volume = 0.0;
float m_highPrice = 0.0;
float m_lowPrice = 0.0;
float m_priceChange = 0.0;
float m_percentChange = 0.0;
bool m_changed = false;
};

#endif // STOCK_DATA_MODEL_H
#endif // STOCK_DATA_MODEL_H
25 changes: 13 additions & 12 deletions Info-Orbs/include/widgets/clockWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ class ClockWidget : public Widget {
void update(bool force = false) override;
void draw(bool force = false) override;
void changeMode() override;
String getName() override;

private:
void displayDidget(int displayIndex, const String& didget, int font, int fontSize, uint32_t color, bool shadowing);
void displayDidget(int displayIndex, const String& didget, int font, int fontSize, uint32_t color);
void displayDigit(int displayIndex, const String& digit, int font, int fontSize, uint32_t color, bool shadowing);
void displayDigit(int displayIndex, const String& digit, int font, int fontSize, uint32_t color);
void displaySeconds(int displayIndex, int seconds, int color);
void displayAmPm(uint32_t color);

time_t m_unixEpoch;
int m_timeZoneOffset;

// Delays for setting how often certain screens/functions are refreshed/checked. These include both the frequency which they need to be checked and a varibale to store the last checked value.
long m_secondTimer = 2000; // this time is used to refressh/check the clock every second.
long m_secondTimer = 2000; // This time is used to refressh/check the clock every second.
long m_secondTimerPrev = 0;

// WiFiUDP m_udp;
Expand All @@ -37,15 +38,15 @@ class ClockWidget : public Widget {
int m_lastHourSingle{-1};
int m_lastSecondSingle{-1};

// Didgets
String m_display1Didget;
String m_lastDisplay1Didget{"-1"};
String m_display2Didget;
String m_lastDisplay2Didget{"-1"};
// Digits
String m_display1Digit;
String m_lastDisplay1Digit{"-1"};
String m_display2Digit;
String m_lastDisplay2Digit{"-1"};
// Display 3 is :
String m_display4Didget;
String m_lastDisplay4Didget{"-1"};
String m_display5Didget;
String m_lastDisplay5Didget{"-1"};
String m_display4Digit;
String m_lastDisplay4Digit{"-1"};
String m_display5Digit;
String m_lastDisplay5Digit{"-1"};
};
#endif // CLOCKWIDGET_H
3 changes: 2 additions & 1 deletion Info-Orbs/include/widgets/stockWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class StockWidget : public Widget {
void update(bool force = false) override;
void draw(bool force = false) override;
void changeMode() override;

String getName() override;

private:
void getStockData(StockDataModel &stock);
void displayStock(int8_t displayIndex, StockDataModel &stock, uint32_t backgroundColor, uint32_t textColor);
Expand Down
7 changes: 4 additions & 3 deletions Info-Orbs/include/widgets/weatherWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class WeatherWidget : public Widget {
void update(bool force = false) override;
void draw(bool force = false) override;
void changeMode() override;

String getName() override;

private:
void displayClock(int displayIndex, uint32_t background, uint32_t textColor);

Expand All @@ -35,10 +36,10 @@ class WeatherWidget : public Widget {
GlobalTime* m_time;
int8_t m_mode;

const long m_updateDelay = 600000; // weather refresh rate
const long m_updateDelay = 600000; // Weather refresh rate
unsigned long m_lastUpdate = 0;

const int centre = 120; // centre location of the screen(240x240)
const int centre = 120; // Centre location of the screen(240x240)

int m_clockStamp = 0;

Expand Down
3 changes: 2 additions & 1 deletion Info-Orbs/include/widgets/webDataWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class WebDataWidget : public Widget {
void update(bool force = false) override;
void draw(bool force = false) override;
void changeMode() override;

String getName() override;

private:
int m_lastUpdate = 0;
int m_updateDelay = 1000;
Expand Down
21 changes: 10 additions & 11 deletions Info-Orbs/lib/config/config.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@


// ============= CONFIGURE THESE FIELDS BEFORE FLASHING ====================================================
#define WIFI_SSID "WIFINAME" // wifi name (please use 2.4gz network)
#define WIFI_PASS "WIFIPASS" // wifi password
#define WIFI_SSID "WIFINAME" // Wifi name (please use 2.4gz network)
#define WIFI_PASS "WIFIPASS" // Wifi password
#define TIMEZONE_API_LOCATION "America/Vancouver" // Use timezone from this list: https://timezonedb.com/time-zones
#define WEATHER_LOCAION "Victoria, BC" //city/state for the weather
#define STOCK_TICKER_LIST "SPY,VT,GOOG,TSLA,GME" // Choose your 5 stokcs to display on the stock tracker
#define STOCK_TICKER_LIST "BTC/USD,USD/CAD,XEQT,SPY,APC&country=Germany" //Choose 5 securities to track. You can track forex, crypto (symbol/USD) or stocks from any exchange (if one tickerr is part of multiple exchanges you can add on "&country=Canada" to narrow down to your ticker)
#define WEATHER_UNITS_METRIC //Comment this line out(or delete it) if you want imperial units for the weather
#define FORMAT_24_HOUR false // toggle 24 hour clock vs 12 hour clock, chnage between true/false
#define SHOW_AM_PM_INDICATOR false // am/pm on the clock if using 12 hour
#define SHOW_SECOND_TICKS true // ticking indeicator on the centre clock
#define FORMAT_24_HOUR false // Toggle 24 hour clock vs 12 hour clock, change between true/false
#define SHOW_AM_PM_INDICATOR false // AM/PM on the clock if using 12 hour
#define SHOW_SECOND_TICKS true // Ticking indicator on the centre clock
#define INVERTED_ORBS false // Set to true if using InfoOrbs upside down. Inverts screens and re-orders screens and buttons.
//#define WEB_DATA_WIDGET_URL "" // use this to make your own widgets using an API/Webdata source
//#define WEB_DATA_STOCK_WIDGET_URL "http://<insert host here>/stocks.php?stocks=SPY,VT,GOOG,TSLA,GME" // use this as an alternative to the stock ticker widget
//#define WEB_DATA_WIDGET_URL "" // Use this to make your own widgets using an API/Webdata source
//#define WEB_DATA_STOCK_WIDGET_URL "http://<insert host here>/stocks.php?stocks=SPY,VT,GOOG,TSLA,GME" // Use this as an alternative to the stock ticker widget
// ============= END CONFIG ==============================================================================


Expand Down Expand Up @@ -78,9 +78,8 @@
#define TIMEZONE_API_URL "http://api.timezonedb.com/v2.1/get-time-zone"
#define WEATHER_API_KEY "XW2RDGD6XK432AF25BNK2A3C7"


#define BG_COLOR 0x20a1 // clock shadow colour(Light brown)
#define FOREGROUND_COLOR 0xfc80 // orange for clock
#define BG_COLOR 0x20a1 // Clock shadow color (Light brown)
#define FOREGROUND_COLOR 0xfc80 // Orange for clock

#define MAX_RETRIES 3

Expand Down
2 changes: 1 addition & 1 deletion Info-Orbs/lib/globalTime/globalTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GlobalTime {
int m_year = 0;
String m_time;
String m_weekday;
int m_timeZoneOffset = -1; // a value that will be overwritten by the API
int m_timeZoneOffset = -1; // A value that will be overwritten by the API

WiFiUDP m_udp;
NTPClient *m_timeClient{nullptr};
Expand Down
6 changes: 3 additions & 3 deletions Info-Orbs/lib/screenManager/screenManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ void ScreenManager::fillAllScreens(uint32_t color) {
reset();
}

// clears all screens by resetting them to black
// Clears all screens by resetting them to black
void ScreenManager::clearAllScreens() {
fillAllScreens(TFT_BLACK);
}

// clears one screens by resetting it to black
// Clears one screens by resetting it to black
void ScreenManager::clearScreen(int screen) {
selectScreen(screen);
m_tft.fillScreen(TFT_BLACK);
}

// Selects all screens
// I don't think that state should be used, It's kinda wierd saying "ow select
// I don't think that state should be used, It's kinda weird saying "ow select
// all the screens to "off"
void ScreenManager::selectAllScreens() {
for (int i = 0; i < NUM_SCREENS; i++) {
Expand Down
1 change: 1 addition & 0 deletions Info-Orbs/lib/widget/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Widget {
virtual void update(bool force = false) = 0;
virtual void draw(bool force = false) = 0;
virtual void changeMode() = 0;
virtual String getName() = 0;
void setBusy(bool busy);

protected:
Expand Down
21 changes: 12 additions & 9 deletions Info-Orbs/lib/widget/widgetSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,28 @@ void WidgetSet::switchWidget() {
getCurrent()->draw(true);
}

void WidgetSet::showLoading() {
// display loading screen here
m_screenManager->fillAllScreens(TFT_BLACK);
m_screenManager->selectScreen(2);
void WidgetSet::showCenteredLine(int screen, int size, String text) {
m_screenManager->selectScreen(screen);

TFT_eSPI &display = m_screenManager->getDisplay();

display.fillScreen(TFT_BLACK);
display.setTextColor(TFT_WHITE);
display.setTextSize(3); // Set text size
display.setTextSize(size); // Set text size
display.drawCentreString(text, 120, 100, 1);
}

// Calculate center positions
int centre = display.width() / 2;
display.drawString("Loading Data", centre, centre, 1);

void WidgetSet::showLoading() {
m_screenManager->fillAllScreens(TFT_BLACK);

WidgetSet::showCenteredLine(2, 3, "Loading Data:");
}

void WidgetSet::updateAll() {
for (int8_t i; i<m_widgetCount; i++) {
Serial.println("updating widget #" + String(i));
Serial.printf("updating widget %s\n", m_widgets[i]->getName().c_str());
showCenteredLine(3, 3, m_widgets[i]->getName().c_str());
m_widgets[i]->update();
}
}
Expand Down
1 change: 1 addition & 0 deletions Info-Orbs/lib/widget/widgetSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class WidgetSet {
void setClearScreensOnDrawCurrent();

private:
void showCenteredLine(int screen, int size, String text);
ScreenManager *m_screenManager;
bool m_clearScreensOnDrawCurrent = true;
Widget *m_widgets[MAX_WIDGETS];
Expand Down
11 changes: 6 additions & 5 deletions Info-Orbs/src/core/wifiWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ void WifiWidget::setup() {
WiFi.begin(WIFI_SSID, WIFI_PASS);

Serial.println("Connecting to WiFi..");



}

void WifiWidget::update(bool force) {
//force is currently an unhandled due to not knowing what behavior it would change
// Force is currently an unhandled due to not knowing what behavior it would change

if(WiFi.status() == WL_CONNECTED) {
m_isConnected = true;
Expand All @@ -52,7 +49,7 @@ void WifiWidget::update(bool force) {
}

void WifiWidget::draw(bool force) {
//force is currently an unhandled due to not knowing what behavior it would change
// Force is currently an unhandled due to not knowing what behavior it would change

if(!m_isConnected && !m_connectionFailed) {
TFT_eSPI &display = m_manager.getDisplay();
Expand Down Expand Up @@ -108,3 +105,7 @@ void WifiWidget::connectionTimedOut() {
// display.drawCentreString("Connection", 120, 80, 1);
// display.drawCentreString(m_connectionString, 120, 100, 1);
}

String WifiWidget::getName(){
return "WiFi";
}
13 changes: 2 additions & 11 deletions Info-Orbs/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,9 @@ void setup() {
sm->reset();
widgetSet = new WidgetSet(sm);

TJpgDec.setSwapBytes(true); // jpeg rendering setup
TJpgDec.setSwapBytes(true); // JPEG rendering setup
TJpgDec.setCallback(tft_output);

#ifdef GC9A01_DRIVER
Serial.println("GC9A01 Driver");
#endif
#ifdef ILI9341_DRIVER
Serial.println("ILI9341 Driver");
#endif
#if HARDWARE == WOKWI
Serial.println("Wokwi Build");
#endif

pinMode(BUSY_PIN, OUTPUT);
Serial.println("Connecting to: " + String(WIFI_SSID));
Expand All @@ -93,7 +84,7 @@ void loop() {
if (wifiWidget->isConnected() == false) {
wifiWidget->update();
wifiWidget->draw();
widgetSet->setClearScreensOnDrawCurrent(); //clear screen after wifiWidget
widgetSet->setClearScreensOnDrawCurrent(); // Clear screen after wifiWidget
delay(100);
} else {
if (!widgetSet->initialUpdateDone()) {
Expand Down
Loading