Initial commit

This commit is contained in:
Djuri 2023-06-10 21:23:31 +02:00
commit 56569b8ed2
85 changed files with 39036 additions and 0 deletions

7
src/screens/base.cpp Normal file
View file

@ -0,0 +1,7 @@
#include "base.hpp"
//std::array<String, 7> BcScreen::epdContent = { "", "", "", "", "", "", "" };
std::array<String, 7> BcScreen::getEpdContent() {
return BcScreen::epdContent;
}

13
src/screens/base.hpp Normal file
View file

@ -0,0 +1,13 @@
#pragma once
#include "config.h"
#include "shared.hpp"
class BcScreen
{
protected:
std::array<String, 7> epdContent;
public:
void init();
void showScreen();
std::array<String, 7> getEpdContent();
};

View file

@ -0,0 +1,33 @@
#include "blockheight.hpp"
uint BlockHeightScreen::blockNr = 0;
std::array<String, 7> BlockHeightScreen::epdContent = { "", "", "", "", "", "", "" };
void BlockHeightScreen::init()
{
BlockHeightScreen::blockNr = preferences.getUInt("blockHeight", 789000);
setupBlockNotify();
BlockHeightScreen::showScreen();
}
void BlockHeightScreen::showScreen()
{
std::string blockNrString = String(BlockHeightScreen::blockNr).c_str();
blockNrString.insert(blockNrString.begin(), 7 - blockNrString.length(), ' ');
epdContent[0] = "BLOCK/HEIGHT";
for (uint i = 1; i < 7; i++)
{
BlockHeightScreen::epdContent[i] = blockNrString[i];
}
}
void BlockHeightScreen::onNewBlock(uint blockNr)
{
BlockHeightScreen::blockNr = blockNr;
BlockHeightScreen::showScreen();
}
std::array<String, 7> BlockHeightScreen::getEpdContent() {
return BlockHeightScreen::epdContent;
}

View file

@ -0,0 +1,18 @@
#pragma once
#include "base.hpp"
#include "config.h"
#include "shared.hpp"
#include "tasks/epd.hpp"
#include "tasks/blocknotify.hpp"
class BlockHeightScreen {
protected:
static uint blockNr;
static std::array<String, 7> epdContent;
public:
static void init();
static void showScreen();
static void onNewBlock(uint blockNr);
static std::array<String, 7> getEpdContent();
};

43
src/screens/countdown.cpp Normal file
View file

@ -0,0 +1,43 @@
#include "countdown.hpp"
uint CountdownScreen::countdownMinutes = 1;
uint CountdownScreen::countdownSeconds = 0;
std::array<String, 7> CountdownScreen::epdContent = {"COUNT/DOWN", "", "", "", "", "", ""};
void CountdownScreen::init()
{
CountdownScreen::showScreen();
}
void CountdownScreen::showScreen()
{
}
std::array<String, 7> CountdownScreen::getEpdContent()
{
return CountdownScreen::epdContent;
}
void CountdownScreen::setCountdownSeconds(uint sec) {
countdownSeconds = sec;
}
void CountdownScreen::countdownTask(void *pvParameters)
{
for (int i = CountdownScreen::countdownSeconds; i >= 0; i--)
{
char countdownString[7];
sprintf(countdownString, "%02d:%02d", i / 60, i % 60);
std::string timeString = countdownString;
timeString.insert(timeString.begin(), 7 - timeString.length(), ' ');
CountdownScreen::epdContent[0] = "COUNT/DOWN";
for (uint i = 1; i < 7; i++)
{
CountdownScreen::epdContent[i] = timeString[i];
}
vTaskDelay(pdMS_TO_TICKS(1000));
}
Serial.println("Countdown finished!");
vTaskDelete(NULL);
}

21
src/screens/countdown.hpp Normal file
View file

@ -0,0 +1,21 @@
#pragma once
#include "base.hpp"
#include "config.h"
#include "shared.hpp"
#include <string>
#include <iostream>
#include "tasks/epd.hpp"
class CountdownScreen {
protected:
static uint countdownMinutes;
static uint countdownSeconds;
static std::array<String, 7> epdContent;
public:
static void init();
static void showScreen();
static std::array<String, 7> getEpdContent();
static void setCountdownSeconds(uint sec);
static void countdownTask(void *pvParameters);
};

View file

@ -0,0 +1,36 @@
#include "custom_text.hpp"
std::string CustomTextScreen::customText = "";
std::array<String, 7> CustomTextScreen::epdContent = {"", "", "", "", "", "", ""};
void CustomTextScreen::init()
{
CustomTextScreen::showScreen();
}
void CustomTextScreen::showScreen()
{
}
void CustomTextScreen::setSimpleText(String text)
{
customText = text.c_str();
customText.insert(customText.begin(), 7 - customText.length(), ' ');
for (uint i = 0; i < 7; i++)
{
CustomTextScreen::epdContent[i] = customText[i];
}
}
void CustomTextScreen::setText(std::array<String, 7> customContent)
{
epdContent = customContent;
}
std::array<String, 7> CustomTextScreen::getEpdContent()
{
return CustomTextScreen::epdContent;
}

View file

@ -0,0 +1,20 @@
#pragma once
#include "base.hpp"
#include "config.h"
#include "shared.hpp"
#include <string>
#include <iostream>
#include "tasks/epd.hpp"
class CustomTextScreen {
protected:
static std::string customText;
static std::array<String, 7> epdContent;
public:
static void init();
static void showScreen();
static std::array<String, 7> getEpdContent();
static void setSimpleText(String text);
static void setText(std::array<String, 7> customContent);
};

View file

@ -0,0 +1,50 @@
#include "halvingcountdown.hpp"
uint HalvingCountdownScreen::currentBlockNr = 0;
uint HalvingCountdownScreen::halvingBlockNr = 0;
std::array<String, 7> HalvingCountdownScreen::epdContent = {"", "", "", "", "", "", ""};
void HalvingCountdownScreen::init()
{
HalvingCountdownScreen::currentBlockNr = preferences.getUInt("blockHeight", 789000);
setupBlockNotify();
HalvingCountdownScreen::showScreen();
}
void HalvingCountdownScreen::showScreen()
{
uint minutesToHalving = HalvingCountdownScreen::getNextHalvingBlockNr() * 10;
int years = floor(minutesToHalving / 525600);
int days = floor((minutesToHalving - (years * 525600)) / (24*60));
int hours = floor((minutesToHalving - (years * 525600) - (days * (24*60))) / 60);
int mins = floor(minutesToHalving - (years * 525600) - (days * (24*60)) - (hours * 60));
// int secs = floor((minutesToHalving - (years * 525600) - (days * (24*60)) - (hours * 60) - mins) * 60);
epdContent[0] = "BIT/HALV";
epdContent[1] = "COIN/ING";
epdContent[2] = String(years) + "/YRS";
epdContent[3] = String(days) + "/DAYS";
epdContent[4] = String(hours) + "/HRS";
epdContent[5] = String(mins) + "/MINS";
epdContent[6] = "TO/GO";
}
uint HalvingCountdownScreen::getNextHalvingBlockNr()
{
return 210000 - (HalvingCountdownScreen::currentBlockNr % 210000);
}
void HalvingCountdownScreen::onNewBlock(uint blockNr)
{
HalvingCountdownScreen::currentBlockNr = blockNr;
HalvingCountdownScreen::showScreen();
}
std::array<String, 7> HalvingCountdownScreen::getEpdContent()
{
return HalvingCountdownScreen::epdContent;
}

View file

@ -0,0 +1,20 @@
#pragma once
#include "base.hpp"
#include "config.h"
#include "shared.hpp"
#include "tasks/epd.hpp"
#include "tasks/blocknotify.hpp"
class HalvingCountdownScreen {
protected:
static uint currentBlockNr;
static uint halvingBlockNr;
static std::array<String, 7> epdContent;
public:
static void init();
static void showScreen();
static void onNewBlock(uint blockNr);
static uint getNextHalvingBlockNr();
static std::array<String, 7> getEpdContent();
};

View file

@ -0,0 +1,30 @@
#include "sats_per_dollar.hpp"
uint SatsPerDollarScreen::satsPerDollar = 0;
std::array<String, 7> SatsPerDollarScreen::epdContent = { "", "", "", "", "", "", "" };
void SatsPerDollarScreen::init() {
SatsPerDollarScreen::satsPerDollar = int(round(1 / preferences.getFloat("btcPrice", 12345) * 10e7));
setupGetPriceTask();
SatsPerDollarScreen::showScreen();
}
void SatsPerDollarScreen::showScreen() {
std::string satsPerDollarString = String(SatsPerDollarScreen::satsPerDollar).c_str();
satsPerDollarString.insert(satsPerDollarString.begin(), 7 - satsPerDollarString.length(), ' ');
epdContent[0] = "MSCW/TIME";
for (uint i = 1; i < 7; i++)
{
SatsPerDollarScreen::epdContent[i] = satsPerDollarString[i];
}
}
void SatsPerDollarScreen::onPriceUpdate(uint price) {
SatsPerDollarScreen::satsPerDollar = int(round(1 / float(price) * 10e7));
SatsPerDollarScreen::showScreen();
}
std::array<String, 7> SatsPerDollarScreen::getEpdContent() {
return SatsPerDollarScreen::epdContent;
}

View file

@ -0,0 +1,17 @@
#pragma once
#include "base.hpp"
#include "config.h"
#include "shared.hpp"
#include "tasks/epd.hpp"
class SatsPerDollarScreen {
protected:
static uint satsPerDollar;
static std::array<String, 7> epdContent;
public:
static void init();
static void showScreen();
static void onPriceUpdate(uint price);
static std::array<String, 7> getEpdContent();
};

29
src/screens/ticker.cpp Normal file
View file

@ -0,0 +1,29 @@
#include "ticker.hpp"
uint TickerScreen::price = 12345;
std::array<String, 7> TickerScreen::epdContent = { "", "", "", "", "", "", "" };
void TickerScreen::init() {
TickerScreen::price = preferences.getFloat("btcPrice", 12345);;
setupGetPriceTask();
TickerScreen::showScreen();
}
void TickerScreen::showScreen() {
std::string priceString = ("$" + String(TickerScreen::price)).c_str();
priceString.insert(priceString.begin(), 7 - priceString.length(), ' ');
epdContent[0] = "BTC/USD";
for (uint i = 1; i < 7; i++)
{
TickerScreen::epdContent[i] = priceString[i];
}
}
void TickerScreen::onPriceUpdate(uint price) {
TickerScreen::price = price;
TickerScreen::showScreen();
}
std::array<String, 7> TickerScreen::getEpdContent() {
return TickerScreen::epdContent;
}

19
src/screens/ticker.hpp Normal file
View file

@ -0,0 +1,19 @@
#pragma once
#include "base.hpp"
#include "config.h"
#include "shared.hpp"
#include "tasks/epd.hpp"
class TickerScreen
{
protected:
static uint price;
static std::array<String, 7> epdContent;
public:
static void init();
static void showScreen();
static void onPriceUpdate(uint price);
static std::array<String, 7> getEpdContent();
};

39
src/screens/time.cpp Normal file
View file

@ -0,0 +1,39 @@
#include "time.hpp"
String TimeScreen::timeString = "";
String TimeScreen::dateString = "";
std::array<String, 7> TimeScreen::epdContent = { "", "", "", "", "", "", "" };
void TimeScreen::init() {
setupMinuteEvent();
TimeScreen::showScreen();
}
void TimeScreen::showScreen() {
TimeScreen::dateString = String(rtc.getDay()) + "/" + String(rtc.getMonth() + 1);
TimeScreen::timeString = rtc.getTime("%H:%M").c_str();
std::string timeString = TimeScreen::timeString.c_str();
timeString.insert(timeString.begin(), 7 - timeString.length(), ' ');
TimeScreen::epdContent[0] = TimeScreen::dateString;
for (uint i = 1; i < 7; i++)
{
TimeScreen::epdContent[i] = timeString[i];
}
}
void TimeScreen::onNewMinute() {
TimeScreen::showScreen();
}
std::array<String, 7> TimeScreen::getEpdContent() {
return TimeScreen::epdContent;
}
TimeScreen* TimeScreen::getInstance() {
if (instance_ == nullptr) {
instance_ = new TimeScreen;
}
return instance_;
}

20
src/screens/time.hpp Normal file
View file

@ -0,0 +1,20 @@
#pragma once
#include "base.hpp"
#include "config.h"
#include "shared.hpp"
#include "tasks/epd.hpp"
class TimeScreen {
protected:
static String timeString;
static String dateString;
static std::array<String, 7> epdContent;
static TimeScreen* instance_;
public:
static void init();
static void showScreen();
static void onNewMinute();
static std::array<String, 7> getEpdContent();
static TimeScreen* getInstance();
};