Skip to content

Commit

Permalink
Revise codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Rarisma committed Dec 22, 2023
1 parent b90f904 commit 690e637
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 72 deletions.
Empty file removed src/Apps/ButtonTest.cpp
Empty file.
6 changes: 6 additions & 0 deletions src/Apps/Internal/LayoutObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "Arduino.h"

/// @brief Main content of the object
String Content;

int RequestedWidth = 0;
7 changes: 7 additions & 0 deletions src/Apps/Internal/RendererTool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "Arduino.h"

/// @brief Takes a File, renders it.
/// @param FilePath
void RenderFromFile(String FilePath){
return;
}
6 changes: 2 additions & 4 deletions src/Apps/TimeSquare/WatchFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "WatchFace.h"
#include "WiFi.h"
#include "Location/Geo.h"
#include "OSWBoot/Flags.h"
#include "System/Flags.h"
#include "OSWBoot/APIKeys.h"
#include <esp_sleep.h>
#include "System/Input.h"
Expand Down Expand Up @@ -99,9 +99,7 @@ void WaitForNextUpdate() {
secondsToSleep -= 60;
}



#ifdef UseDelayBasedSleep = true
#if UseDelayBasedSleep
msToSleep = secondsToSleep * 1000;
while (msToSleep != 0)
{
Expand Down
25 changes: 12 additions & 13 deletions src/Display/Display.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#include "Arduino.h"
#include "OSWBoot/Flags.h"
#include "System/Flags.h"
#include "Logging/SysLog.h"
#include <SPI.h>
#include <System/SystemInfo.h>
#include "Location/Geo.h"
#include <System/Flags.h>
#include <Adafruit_GFX.h> //Standard Adafruit Library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789

/* ==Display IDs (i.e Who made your display and what type is it)
/* Display IDs (i.e Who made your display and what type is it)
0 - No Display (Just goes to serial)
1 - Adafruit ST7789 Displays.
*///We use the display ID system to save on compiled code space.
We use the display ID system to save on compiled code space.*/

#define DisplayID 1 //Change to value of the display you have.

#ifdef DisplayID == 1
#if DisplayID == 1
// Adafruit Display
Adafruit_ST7789 Display = Adafruit_ST7789(DisplayCSPin, DisplayDCPin, DisplayRSTPin);
#endif
Expand All @@ -25,7 +24,7 @@
/// Display in flags.cpp as OSW WILL NOT detect the display
/// This probably won't be bad if you mess it but I wouldn't.
void InitaliseDisplay(){
#ifdef DisplayID == 1 //Adafruit ST7789
#if DisplayID == 1 //Adafruit ST7789
Log("Display initalising as ST7789", LogLevel::Info);
Display.init(240, 280);
Display.fillScreen(ST77XX_BLACK);
Expand All @@ -40,7 +39,7 @@ void InitaliseDisplay(){
/// @brief Prints a Welcome to OSW message showing
///the build name and number.
void PrintBootScreen(){
#ifdef DisplayID == 1 //Adafruit ST7789
#if DisplayID == 1 //Adafruit ST7789
Display.setTextColor(ST77XX_WHITE, ST77XX_BLACK);
Display.setCursor(80,10);
Display.println("OpenSW - " + String(Branch) + "!");
Expand All @@ -58,7 +57,7 @@ void PrintBootScreen(){
/// @param X Xcoord where to place it (You should also specify X.)
/// @param Y Ycoord where to place it (You should also specify Y.)
void PrintToDisplay (String Message, int FontSize = 2, bool Newline = true, int X=-1,int Y=-1, int Color=0xFFFFFF){
#ifdef DisplayID == 1 //Adafruit ST7789
#if DisplayID == 1 //Adafruit ST7789
Display.setTextSize(FontSize);
Display.setTextColor(Color); //Sets text to color (defaults to white.).
//Sets cursor if X/Y vars are set.
Expand All @@ -77,7 +76,7 @@ void PrintToDisplay (String Message, int FontSize = 2, bool Newline = true, int
/// @brief Clears the display and resets cursor to 0,0.
/// @param Color Color to fill display with (defaults to black.)
void ClearDisplay(int Color = 0x00000){
#ifdef DisplayID == 1 //Adafruit ST7789
#if DisplayID == 1 //Adafruit ST7789
Display.fillScreen(Color);
Display.setCursor(0,0);
#else
Expand All @@ -88,7 +87,7 @@ void ClearDisplay(int Color = 0x00000){
/// @brief This prints a syslog message to the display with coloring.
/// @param Message Message to be shown
void ShowLog (String Message, String Level, int Color){
#ifdef DisplayID == 1; //Adafruit ST7789
#if DisplayID == 1 //Adafruit ST7789
Display.print("[");
Display.setTextColor(Color);
Display.print(Level);
Expand All @@ -100,8 +99,8 @@ void ShowLog (String Message, String Level, int Color){
}

int GetTextWidth(String Text, int FontSize)
{
#ifdef DisplayID == 1 //Adafruit ST7789
{
#if DisplayID == 1 //Adafruit ST7789
int16_t x1, y1;
uint16_t w, h;

Expand Down
1 change: 0 additions & 1 deletion src/Display/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "Arduino.h"

void InitaliseDisplay();
void PrintHomeScreen();
void PrintBootScreen();
void PrintToDisplay(String Message, int FontSize = 2, bool NewLine=true, int X=-1,int Y=-1, int Color=0xFFFFFF);
void ShowLog(String Message, String Level, int Color);
Expand Down
7 changes: 3 additions & 4 deletions src/Location/Geo.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <Logging/SysLog.h>
#include <OSWBoot/Flags.h>
#include <System/Flags.h>
#include <System/SystemState.h>
#include <WiFi.h>
#include <OSWBoot/APIKeys.h>
Expand Down Expand Up @@ -27,13 +27,12 @@ struct WeatherData {
unsigned long sunsetTime;
};

//Conver GoogleMapsAPIKey to key for some reason we can't just String(GoogleMapsAPIKey)
String Key = String(GoogleMapsAPIKey);
String Key = GoogleMapsAPIKey;
WifiLocation location(Key);

void GetLocation(){
if (AllowGeolocation) {
Log("Geoloc disabled.", LogLevel::Warn);
Log("loc disabled.", LogLevel::Warn);
return;
}

Expand Down
7 changes: 4 additions & 3 deletions src/Logging/SysLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "LogLevel.h"
#include "Display/Display.h"
#include "System/TimeUtils.h"
#include "OSWBoot/Flags.h"
#include "System/Flags.h"

bool SerialInitalised = false; //Will initalise serial and then set to true.
bool LogToDisplay = false; //Shows log messages on display.
Expand All @@ -17,6 +17,9 @@ void Log(String Message, LogLevel level) {
int Color = 0xFFFFFF; //RGB in hex after the 0x part.
switch (level) {
case LogLevel::Debug:
#if !ShowDebugLogs // Supress debug logs if they aren't enabled.
return;
#endif
Prefix += "DBG";
Color = 0x001F; // Blue
break;
Expand All @@ -37,8 +40,6 @@ void Log(String Message, LogLevel level) {
break;
}

//Supress debug logs if enabled.
if (SupressDebugLogs && level == LogLevel::Debug){ return; }

if (LogToDisplay)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Networking/Networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "time.h"
#include "Logging/SysLog.h"
#include "Arduino.h"
#include "OSWBoot/Flags.h"
#include "System/Flags.h"
#include "Arduino.h"
#include "rtc.h"
#include <WiFiClientSecure.h> //Fixes compilation failure relating to WifiLocation, platformIO bug.
Expand Down
4 changes: 2 additions & 2 deletions src/OSWBoot/APIKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

#include <Arduino.h>

constexpr char* GoogleMapsAPIKey = "API KEY HERE";
constexpr char* OpenWeatherMapAPIKey = "API KEY HERE";
const String GoogleMapsAPIKey = "API KEY HERE";
const String OpenWeatherMapAPIKey = "API KEY HERE";
12 changes: 6 additions & 6 deletions src/OSWBoot/OSWBoot.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <Arduino.h>
#include "Logging/SysLog.h"
#include "System/SystemInfo.h"
#include "System/Flags.h"
#include "Display/Display.h"
#include "Networking/Networking.h"
#include "OSWBoot/Flags.h"
#include "System/Flags.h"
#include "System/TimeUtils.h"
#include "Apps/TimeSquare/WatchFace.h"
#include <esp_sleep.h>
Expand All @@ -16,20 +16,20 @@ void Initalise(){

InitaliseDisplay();

//Log("Hold upper left for config", LogLevel::Info);
Log("Hold any button for config", LogLevel::Info);
//ButtonManager.ReadButtons.Contains(UL) => ConfigManager
//delay(500); //Wait 0.5 seconds for any press.
delay(500); //Wait 0.5 seconds for any press.
PrintBootScreen(); //Prints the welcome to OSW message to the disp.
ShowPowerOnCause(); //Gets why we are here.
HandleRTC();

if (DelayBoot)
{
Log("BootDelay enabled, press anything to continue", LogLevel::Info);
Log("Press Button to continue", LogLevel::Info);
AwaitInput();
}

Log("Init complete, Downclocking to 80MHz",LogLevel::Info);
Log("Boot complete! Downclocking to 80MHz",LogLevel::Info);
setCpuFrequencyMhz(80);

//esp_sleep_enable_light_sleep_after(100); // this will sleep the cpu after 100ms.
Expand Down
4 changes: 2 additions & 2 deletions src/SDStorage/FileSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "Arduino.h"
#include "SD.h"
#include "OSWBoot/Flags.h"
#include "System/Flags.h"
#include "Logging/SysLog.h"

void InitaliseSDCard() {
if (!SD.begin(DisplaySDPin)) {
if (!SD.begin(SDCardPin)) {
Log("SD init Failed.", LogLevel::Error);
return;
}
Expand Down
35 changes: 24 additions & 11 deletions src/OSWBoot/Flags.h → src/System/Flags.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
// OSWConfig.h - Open Smart Watch Configuration Header
// Flags.h - Open Smart Watch Configuration File
#ifndef FLAGS_H
#define FLAGS_H

#include <Arduino.h>

// === OSW Version Information ===
// Don't edit this UNLESS you know what you are doing!
constexpr int Version[] = {1, 2, 0};
constexpr const char* ReleaseName = "Reckless Tongue";
constexpr const char* Branch = "MINIMA";

/* Release Name History.
All releases are based on song names, generally music I like.
== Progenitor ==
0.0.C - Kick Back - Kenshi Yonezu
0.0.F - Wannabe
== MINIMA ==
1.0.0 - Exhibition Prototype Ultra (K-Rino)
1.1.0 - Time Out (DJ Hoppa)
1.2.0 - Reckless Tongue (Airways) */

// === Feature availability ===
// Allow or disable OSW features like WiFi. This is NOT the same as turning it off.
// If a feature is disabled, trying to use it will just skip the function call.
Expand All @@ -27,11 +43,11 @@ inline String DefaultWiFiSSID = "DREAMLAND"; // SSID to connect to.
inline String DefaultWiFiPass = "NIGHTMARE"; // Password to SSID.

// Geolocation Settings
inline int GeolocationCooldown = 90; // How often to ping geo APIs in the background.
inline int GeolocationCooldown = 90; // How often to ping geo APIs in the background. (Seconds)

// OSWBoot Settings
inline bool DelayBoot = true; // Delays boot until button pressed.
inline bool SupressDebugLogs = true; // Debug logs will be ignored.
const inline bool ShowDebugLogs = false; // Debug logs will be ignored. (requires reflash)
// Experimental Settings
// Many of these aren't implemented and are more ideas/concepts currently
inline bool EnableOTAMenu = true; // Allows OTAs. // Not implemented.
Expand All @@ -42,15 +58,12 @@ inline bool Autoregion = false; //Unimplemented, Use Geoloc and Weather APIs to
inline bool AllowBluetooth = true; //Unimplemented, Enables Bluetooth

//=== HARDWARE INFO ===
// These are considered read-only.
// To change these you will need to reflash OSW.
const bool UseDelayBasedSleep = true; //Set true to use Delays instead of ESP32 Light Sleep
// These are considered read-only, changing these requires a reflash.
const bool UseDelayBasedSleep = true; //Set to false if your ESP model supports wake from GPIO (ESP32-S3 )
const int DisplayWidth = 240; // Display Width in pixels
const int DisplayHeight = 280; // Display Height in pixels
//To set your display type please go to Display.cpp

// SD Card Pins
const int DisplaySDPin = 5;
const int SDCardPin = 5;

// ST7789 Pins
const int DisplayCSPin = 21;
Expand All @@ -61,4 +74,4 @@ const int DisplayDCPin = 20;
const int ButtonAPin = 3;
const int ButtonBPin = 4;

#endif // OSWCONFIG_H
#endif
15 changes: 12 additions & 3 deletions src/System/Input.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <Arduino.h>
#include "OSWBoot/Flags.h"
#include "System/Flags.h"
#include "Logging/SysLog.h"

/// @brief This initalises buttons attached to OSW
Expand All @@ -13,19 +13,28 @@ void InitaliseInput(){
}

/// @brief Loops until ButtonA and/or ButtonB are pressed
/// @param Timeout The timeout duration in milliseconds (0 for no timeout).
/// @return An array of booleans, corresponding to if button a or b are pressed.
bool* AwaitInput(int Timeout = 0){
Log("Waiting for a button press..",LogLevel::Info);
bool ButtonAVal = false;
bool ButtonBVal = false;

unsigned long startTime = millis(); // Record the start time
while (ButtonAVal == false && ButtonBVal == false)
{
// Check for button states
ButtonAVal = (analogRead(ButtonAPin) == 4095);
ButtonBVal = (analogRead(ButtonBPin) == 4095);
Log("AVal:" + String(ButtonAVal) + " BVal: " + String(ButtonBVal),LogLevel::Debug);

Log("AVal:" + String(ButtonAVal) + " BVal: " + String(ButtonBVal), LogLevel::Debug);

// Check for timeout if Timeout is not 0
if (Timeout > 0 && (millis() - startTime) >= Timeout) {
Log("Timeout reached!", LogLevel::Info);
break; // Exit the loop if timeout has been reached
}
}

Log("Button pressed!",LogLevel::Info);
return new bool[2] {ButtonAVal, ButtonBVal};
}
21 changes: 0 additions & 21 deletions src/System/SystemInfo.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <OSWBoot/OSWBoot.h>
#include <WiFi.h>
#include <Arduino.h>
#include <System/SystemInfo.h>
#include <System/Flags.h>
#include <Logging/SysLog.h>

/// @brief Calls OSWBoot.Initalise()
Expand Down

0 comments on commit 690e637

Please sign in to comment.