2021-03-31 18:50:00 +00:00
|
|
|
#pragma once
|
|
|
|
#include <FastLED.h>
|
2021-04-10 18:10:25 +00:00
|
|
|
#include <Figments.h>
|
2021-03-31 18:50:00 +00:00
|
|
|
#include "BootOptions.h"
|
|
|
|
|
2021-04-10 18:10:25 +00:00
|
|
|
class Platform : public Task {
|
2021-03-31 18:50:00 +00:00
|
|
|
static int s_timezone;
|
|
|
|
static char s_deviceID[15];
|
|
|
|
public:
|
2023-02-18 15:33:09 +00:00
|
|
|
Platform() : Task("Platform") {state = Task::Running;}
|
2021-03-31 18:50:00 +00:00
|
|
|
static BootOptions bootopts;
|
|
|
|
static void setTimezone(int tz) { s_timezone = tz; }
|
|
|
|
static int getTimezone() { return s_timezone; }
|
2023-12-11 07:07:38 +00:00
|
|
|
static void addLEDs(CRGB* leds, uint16_t ledCount);
|
2021-03-31 18:50:00 +00:00
|
|
|
|
|
|
|
static const char* name();
|
|
|
|
static const char* version();
|
2023-02-19 17:44:26 +00:00
|
|
|
static const String model();
|
2021-04-10 18:10:25 +00:00
|
|
|
static const String deviceName() {
|
|
|
|
static String devName = model() + " " + Platform::deviceID();
|
|
|
|
return devName;
|
|
|
|
}
|
2021-03-31 18:50:00 +00:00
|
|
|
static void preSetup();
|
|
|
|
static void bootSplash();
|
|
|
|
static void setup();
|
2021-04-10 18:10:25 +00:00
|
|
|
void loop() override;
|
2021-03-31 18:50:00 +00:00
|
|
|
static bool getLocalTime(struct tm* timedata);
|
|
|
|
static const char* deviceID();
|
2023-02-18 14:43:15 +00:00
|
|
|
static int freeRam();
|
2021-04-10 18:10:25 +00:00
|
|
|
|
2022-06-11 09:02:27 +00:00
|
|
|
struct TaskRegistration {
|
|
|
|
Task* task = 0;
|
|
|
|
TaskRegistration* next = 0;
|
|
|
|
|
|
|
|
TaskRegistration(Task* task) : task(task) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
static TaskRegistration* firstTask;
|
|
|
|
static TaskRegistration* lastTask;
|
|
|
|
|
|
|
|
static void registerTask(TaskRegistration* reg) {
|
|
|
|
if (firstTask == NULL) {
|
|
|
|
firstTask = reg;
|
|
|
|
lastTask = firstTask;
|
|
|
|
} else {
|
|
|
|
lastTask->next = reg;
|
|
|
|
lastTask = reg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-18 15:18:57 +00:00
|
|
|
struct figment_iterator: public std::iterator<std::input_iterator_tag, Figment*> {
|
|
|
|
TaskRegistration* cur;
|
|
|
|
explicit figment_iterator() : cur(NULL) {}
|
|
|
|
explicit figment_iterator(TaskRegistration* head) : cur(head) {
|
|
|
|
while (cur && !cur->task->isFigment()) {
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
figment_iterator& operator++() {
|
|
|
|
if (cur) {
|
|
|
|
do {
|
|
|
|
cur = cur->next;
|
|
|
|
} while (cur && !cur->task->isFigment());
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
figment_iterator operator++(int) {figment_iterator ret = *this; ++(*this); return ret;}
|
|
|
|
bool operator==(figment_iterator other) const { return cur == other.cur; }
|
|
|
|
bool operator!=(figment_iterator other) const { return !(*this == other); }
|
|
|
|
Figment* operator*() const { return static_cast<Figment*>(cur->task); }
|
|
|
|
};
|
|
|
|
|
2022-06-11 09:02:27 +00:00
|
|
|
struct task_iterator: public std::iterator<std::input_iterator_tag, Task*> {
|
|
|
|
TaskRegistration* cur;
|
|
|
|
explicit task_iterator() : cur(NULL) {}
|
|
|
|
explicit task_iterator(TaskRegistration* head) : cur(head) {}
|
|
|
|
task_iterator& operator++() {
|
|
|
|
if (cur) {
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
task_iterator operator++(int) {task_iterator ret = *this; ++(*this); return ret;}
|
|
|
|
bool operator==(task_iterator other) const { return cur == other.cur; }
|
|
|
|
bool operator!=(task_iterator other) const { return !(*this == other); }
|
|
|
|
Task* operator*() const { return cur->task; }
|
|
|
|
};
|
|
|
|
|
2023-02-18 15:18:57 +00:00
|
|
|
static figment_iterator beginFigments() {
|
|
|
|
return figment_iterator(firstTask);
|
|
|
|
}
|
|
|
|
|
|
|
|
static figment_iterator endFigments() {
|
|
|
|
return figment_iterator(NULL);
|
|
|
|
}
|
|
|
|
|
2022-06-11 09:02:27 +00:00
|
|
|
static task_iterator beginTasks() {
|
|
|
|
return task_iterator(firstTask);
|
|
|
|
}
|
|
|
|
|
|
|
|
static task_iterator endTasks() {
|
|
|
|
return task_iterator(NULL);
|
|
|
|
}
|
|
|
|
|
2023-02-19 17:44:26 +00:00
|
|
|
static void restart();
|
2022-06-11 09:02:27 +00:00
|
|
|
};
|