Project restructuring (fixes macOS builds) (#198)

- Create `Include/` folder for all main projects
- Fix some issues here and there (found while moving things)
- All includes are now in `Tactility/` subfolder and must be included with that prefix. This fixes issues with clashing POSIX headers (e.g. `<semaphore.h>` versus Tactility's `Semaphore.h`)
This commit is contained in:
Ken Van Hoeylandt
2025-02-01 18:13:20 +01:00
committed by GitHub
parent 7856827ecf
commit c87200a80d
350 changed files with 967 additions and 870 deletions
-17
View File
@@ -1,17 +0,0 @@
#pragma once
#define TT_ASSET_FOLDER "A:/system/"
#define TT_ASSET(file) TT_ASSET_FOLDER file
// UI
#define TT_ASSETS_UI_SPINNER TT_ASSET("spinner.png")
// App icons
#define TT_ASSETS_APP_ICON_FALLBACK TT_ASSET("app_icon_fallback.png")
#define TT_ASSETS_APP_ICON_FILES TT_ASSET("app_icon_files.png")
#define TT_ASSETS_APP_ICON_DISPLAY_SETTINGS TT_ASSET("app_icon_display_settings.png")
#define TT_ASSETS_APP_ICON_POWER_SETTINGS TT_ASSET("app_icon_power_settings.png")
#define TT_ASSETS_APP_ICON_I2C_SETTINGS TT_ASSET("app_icon_i2c.png")
#define TT_ASSETS_APP_ICON_SETTINGS TT_ASSET("app_icon_settings.png")
#define TT_ASSETS_APP_ICON_SYSTEM_INFO TT_ASSET("app_icon_system_info.png")
#define TT_ASSETS_APP_ICON_TIME_DATE_SETTINGS TT_ASSET("app_icon_time_date_settings.png")
-21
View File
@@ -1,21 +0,0 @@
#pragma once
namespace tt {
#define SYSTEM_PARTITION_NAME "system"
#ifdef ESP_PLATFORM
#define MOUNT_POINT_SYSTEM "/system"
#else
#define MOUNT_POINT_SYSTEM "system"
#endif
#define DATA_PARTITION_NAME "data"
#ifdef ESP_PLATFORM
#define MOUNT_POINT_DATA "/data"
#else
#define MOUNT_POINT_DATA "data"
#endif
} // namespace
+3 -2
View File
@@ -1,7 +1,8 @@
#ifdef ESP_PLATFORM
#include "EspPartitions_i.h"
#include "Log.h"
#include "Tactility/PartitionsEsp.h"
#include <Tactility/Log.h>
#include <esp_vfs_fat.h>
#include <nvs_flash.h>
-34
View File
@@ -1,34 +0,0 @@
#pragma once
#include <cstdint>
#include <string>
namespace tt {
/**
* Settings that persist on NVS flash for ESP32.
* On simulator, the settings are only in-memory.
*/
class Preferences {
private:
const char* namespace_;
public:
explicit Preferences(const char* namespace_) {
this->namespace_ = namespace_;
}
bool hasBool(const std::string& key) const;
bool hasInt32(const std::string& key) const;
bool hasString(const std::string& key) const;
bool optBool(const std::string& key, bool& out) const;
bool optInt32(const std::string& key, int32_t& out) const;
bool optString(const std::string& key, std::string& out) const;
void putBool(const std::string& key, bool value);
void putInt32(const std::string& key, int32_t value);
void putString(const std::string& key, const std::string& value);
};
} // namespace
+3 -2
View File
@@ -1,8 +1,9 @@
#ifdef ESP_PLATFORM
#include "nvs_flash.h"
#include "Preferences.h"
#include "TactilityCore.h"
#include "Tactility/Preferences.h"
#include <Tactility/TactilityCore.h>
#define TAG "preferences"
+3 -2
View File
@@ -1,7 +1,8 @@
#ifndef ESP_PLATFOM
#include "Bundle.h"
#include "Preferences.h"
#include "Tactility/Preferences.h"
#include <Tactility/Bundle.h>
namespace tt {
+10 -10
View File
@@ -1,15 +1,15 @@
#include <Dispatcher.h>
#include "TactilityHeadless.h"
#include "hal/Configuration.h"
#include "hal/Hal_i.h"
#include "service/ServiceManifest.h"
#include "service/ServiceRegistry.h"
#include "kernel/SystemEvents.h"
#include "network/NtpPrivate.h"
#include "time/TimePrivate.h"
#include "Tactility/TactilityHeadless.h"
#include "Tactility/hal/Configuration.h"
#include "Tactility/hal/Hal_i.h"
#include "Tactility/network/NtpPrivate.h"
#include "Tactility/service/ServiceManifest.h"
#include "Tactility/service/ServiceRegistry.h"
#include <Tactility/Dispatcher.h>
#include <Tactility/time/TimePrivate.h>
#ifdef ESP_PLATFORM
#include "EspInit.h"
#include "Tactility/InitEsp.h"
#endif
namespace tt {
@@ -1,25 +0,0 @@
#pragma once
#include "TactilityCore.h"
#include "hal/Configuration.h"
#include "Dispatcher.h"
namespace tt {
/** Initialize the hardware and started the internal services. */
void initHeadless(const hal::Configuration& config);
/** Provides access to the dispatcher that runs on the main task.
* @warning This dispatcher is used for WiFi and might block for some time during WiFi connection.
* @return the dispatcher
*/
Dispatcher& getMainDispatcher();
} // namespace
namespace tt::hal {
/** While technically this configuration is nullable, it's never null after initHeadless() is called. */
const Configuration* _Nullable getConfiguration();
} // namespace
@@ -1,7 +1,7 @@
#ifdef ESP_PLATFORM
#include "TactilityCore.h"
#include "EspPartitions_i.h"
#include "Tactility/PartitionsEsp.h"
#include "Tactility/TactilityCore.h"
#include "esp_event.h"
#include "esp_netif.h"
@@ -1,63 +0,0 @@
#pragma once
#include "Power.h"
#include "hal/i2c/I2c.h"
#include "SdCard.h"
namespace tt::hal {
typedef bool (*InitBoot)();
typedef bool (*InitHardware)();
typedef bool (*InitLvgl)();
class Display;
class Keyboard;
typedef Display* (*CreateDisplay)();
typedef Keyboard* (*CreateKeyboard)();
typedef std::shared_ptr<Power> (*CreatePower)();
struct Configuration {
/**
* Called before I2C/SPI/etc is initialized.
* Used for powering on the peripherals manually.
*/
const InitBoot _Nullable initBoot = nullptr;
/**
* Called after I2C/SPI/etc is initialized.
* This can be used to communicate with built-in peripherals such as an I2C keyboard.
*/
const InitHardware _Nullable initHardware = nullptr;
/**
* Create and initialize all LVGL devices. (e.g. display, touch, keyboard)
*/
const InitLvgl _Nullable initLvgl = nullptr;
/**
* Display HAL functionality.
*/
const CreateDisplay _Nullable createDisplay = nullptr;
/**
* Display HAL functionality.
*/
const CreateKeyboard _Nullable createKeyboard = nullptr;
/**
* An optional SD card interface.
*/
const std::shared_ptr<SdCard> _Nullable sdcard = nullptr;
/**
* An optional power interface for battery or other power delivery.
*/
const CreatePower _Nullable power = nullptr;
/**
* A list of i2c interfaces
*/
const std::vector<i2c::Configuration> i2c = {};
};
} // namespace
-32
View File
@@ -1,32 +0,0 @@
#pragma once
#include "lvgl.h"
namespace tt::hal {
class Touch;
class Display {
public:
virtual bool start() = 0;
virtual bool stop() = 0;
virtual void setPowerOn(bool turnOn) {}
virtual bool isPoweredOn() const { return true; }
virtual bool supportsPowerControl() const { return false; }
virtual Touch* _Nullable createTouch() = 0;
/** Set a value in the range [0, 255] */
virtual void setBacklightDuty(uint8_t backlightDuty) { /* NO-OP */ }
virtual bool supportsBacklightDuty() const { return false; }
/** Set a value in the range [0, 255] */
virtual void setGammaCurve(uint8_t index) { /* NO-OP */ }
virtual uint8_t getGammaCurveCount() const { return 0; };
/** After start() returns true, this should return a valid pointer until stop() is called and returns true */
virtual lv_display_t* _Nullable getLvglDisplay() const = 0;
};
}
+4 -3
View File
@@ -1,6 +1,7 @@
#include "hal/Hal_i.h"
#include "hal/i2c/I2c.h"
#include "kernel/SystemEvents.h"
#include "Tactility/hal/Hal_i.h"
#include "Tactility/hal/i2c/I2c.h"
#include <Tactility/kernel/SystemEvents.h>
#define TAG "hal"
-18
View File
@@ -1,18 +0,0 @@
#pragma once
#include "lvgl.h"
namespace tt::hal {
class Display;
class Keyboard {
public:
virtual bool start(lv_display_t* display) = 0;
virtual bool stop() = 0;
virtual bool isAttached() const = 0;
virtual lv_indev_t* _Nullable getLvglIndev() = 0;
};
}
-41
View File
@@ -1,41 +0,0 @@
#pragma once
#include <cstdint>
namespace tt::hal {
class Power{
public:
Power() = default;
virtual ~Power() = default;
enum class MetricType {
IsCharging, // bool
Current, // int32_t, mAh - battery current: either during charging (positive value) or discharging (negative value)
BatteryVoltage, // uint32_t, mV
ChargeLevel, // uint8_t [0, 100]
};
union MetricData {
int32_t valueAsInt32 = 0;
uint32_t valueAsUint32;
uint8_t valueAsUint8;
float valueAsFloat;
bool valueAsBool;
};
virtual bool supportsMetric(MetricType type) const = 0;
/**
* @return false when metric is not supported or (temporarily) not available.
*/
virtual bool getMetric(Power::MetricType type, MetricData& data) = 0;
virtual bool supportsChargeControl() const { return false; }
virtual bool isAllowedToCharge() const { return false; }
virtual void setAllowedToCharge(bool canCharge) { /* NO-OP*/ }
};
} // namespace tt
-39
View File
@@ -1,39 +0,0 @@
#pragma once
#include "TactilityCore.h"
namespace tt::hal {
#define TT_SDCARD_MOUNT_NAME "sdcard"
#define TT_SDCARD_MOUNT_POINT "/sdcard"
class SdCard {
public:
enum class State {
Mounted,
Unmounted,
Error,
Unknown
};
enum class MountBehaviour {
AtBoot, /** Only mount at boot */
Anytime /** Mount/dismount any time */
};
private:
MountBehaviour mountBehaviour;
public:
explicit SdCard(MountBehaviour mountBehaviour) : mountBehaviour(mountBehaviour) {}
virtual ~SdCard() = default;
virtual bool mount(const char* mountPath) = 0;
virtual bool unmount() = 0;
virtual State getState() const = 0;
virtual MountBehaviour getMountBehaviour() const { return mountBehaviour; }
bool isMounted() const { return getState() == State::Mounted; }
};
} // namespace
+2 -3
View File
@@ -1,9 +1,8 @@
#ifdef ESP_PLATFORM
#include "SpiSdCard.h"
#include "Tactility/hal/SpiSdCard.h"
#include "Check.h"
#include "Log.h"
#include <Tactility/Log.h>
#include <driver/gpio.h>
#include <esp_vfs_fat.h>
-82
View File
@@ -1,82 +0,0 @@
#ifdef ESP_PLATFORM
#pragma once
#include "hal/SdCard.h"
#include <sd_protocol_types.h>
#include <utility>
#include <vector>
#include <hal/spi_types.h>
#include <soc/gpio_num.h>
namespace tt::hal {
/**
* SD card interface at the default SPI interface
*/
class SpiSdCard : public tt::hal::SdCard {
public:
struct Config {
Config(
gpio_num_t spiPinCs,
gpio_num_t spiPinCd,
gpio_num_t spiPinWp,
gpio_num_t spiPinInt,
MountBehaviour mountBehaviourAtBoot,
std::shared_ptr<Lockable> lockable = nullptr,
std::vector<gpio_num_t> csPinWorkAround = std::vector<gpio_num_t>(),
spi_host_device_t spiHost = SPI2_HOST,
int spiFrequencyKhz = SDMMC_FREQ_DEFAULT
) : spiFrequencyKhz(spiFrequencyKhz),
spiPinCs(spiPinCs),
spiPinCd(spiPinCd),
spiPinWp(spiPinWp),
spiPinInt(spiPinInt),
mountBehaviourAtBoot(mountBehaviourAtBoot),
lockable(std::move(lockable)),
csPinWorkAround(std::move(csPinWorkAround)),
spiHost(spiHost)
{}
int spiFrequencyKhz;
gpio_num_t spiPinCs; // Clock
gpio_num_t spiPinCd; // Card detect
gpio_num_t spiPinWp; // Write-protect
gpio_num_t spiPinInt; // Interrupt
SdCard::MountBehaviour mountBehaviourAtBoot;
std::shared_ptr<Lockable> _Nullable lockable;
std::vector<gpio_num_t> csPinWorkAround;
spi_host_device_t spiHost;
bool formatOnMountFailed = false;
uint16_t maxOpenFiles = 4;
uint16_t allocUnitSize = 16 * 1024;
bool statusCheckEnabled = false;
};
private:
std::string mountPoint;
sdmmc_card_t* card = nullptr;
std::shared_ptr<Config> config;
bool applyGpioWorkAround();
bool mountInternal(const char* mount_point);
public:
explicit SpiSdCard(std::unique_ptr<Config> config) :
SdCard(config->mountBehaviourAtBoot),
config(std::move(config))
{}
bool mount(const char* mountPath) override;
bool unmount() override;
State getState() const override;
sdmmc_card_t* _Nullable getCard() { return card; }
};
}
#endif
-18
View File
@@ -1,18 +0,0 @@
#pragma once
#include "lvgl.h"
namespace tt::hal {
class Display;
class Touch {
public:
virtual bool start(lv_display_t* display) = 0;
virtual bool stop() = 0;
virtual lv_indev_t* _Nullable getLvglIndev() = 0;
};
}
+4 -3
View File
@@ -1,8 +1,9 @@
#ifdef ESP_PLATFORM
#include "I2c.h"
#include "Log.h"
#include "Mutex.h"
#include "Tactility/hal/i2c/I2c.h"
#include <Tactility/Log.h>
#include <Tactility/Mutex.h>
#include <esp_check.h>
-54
View File
@@ -1,54 +0,0 @@
#pragma once
#include "I2cCompat.h"
#include "RtosCompat.h"
#include <climits>
#include <string>
#include <vector>
namespace tt::hal::i2c {
enum class InitMode {
ByTactility, // Tactility will initialize it in the correct bootup phase
ByExternal, // The device is already initialized and Tactility should assume it works
Disabled // Not initialized by default
};
struct Configuration {
std::string name;
/** The port to operate on */
i2c_port_t port;
/** Whether this bus should be initialized when device starts up */
InitMode initMode;
/** Whether this bus can stopped and re-started. */
bool canReinit;
/** Whether configuration can be changed. */
bool hasMutableConfiguration;
/** Configuration that must be valid when initAtBoot is set to true. */
i2c_config_t config;
};
enum class Status {
Started,
Stopped,
Unknown
};
bool init(const std::vector<i2c::Configuration>& configurations);
bool start(i2c_port_t port);
bool stop(i2c_port_t port);
bool isStarted(i2c_port_t port);
bool masterRead(i2c_port_t port, uint8_t address, uint8_t* data, size_t dataSize, TickType_t timeout);
bool masterReadRegister(i2c_port_t port, uint8_t address, uint8_t reg, uint8_t* data, size_t dataSize, TickType_t timeout);
bool masterWrite(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout);
bool masterWriteRegister(i2c_port_t port, uint8_t address, uint8_t reg, const uint8_t* data, uint16_t dataSize, TickType_t timeout);
bool masterWriteRegisterArray(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout);
bool masterWriteRead(i2c_port_t port, uint8_t address, const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout);
bool masterHasDeviceAtAddress(i2c_port_t port, uint8_t address, TickType_t timeout);
bool lock(i2c_port_t port, TickType_t timeout = 10 / portTICK_PERIOD_MS);
bool unlock(i2c_port_t port);
} // namespace
@@ -1,39 +0,0 @@
#pragma once
#ifdef ESP_PLATFORM
#include <hal/i2c_types.h>
#include <driver/i2c.h>
#else
#include <cstdint>
typedef int esp_err_t;
typedef enum {
I2C_NUM_0 = 0,
I2C_NUM_1,
LP_I2C_NUM_0,
I2C_NUM_MAX,
} i2c_port_t;
typedef enum{
I2C_MODE_MASTER,
I2C_MODE_MAX,
} i2c_mode_t;
typedef struct {
i2c_mode_t mode;
int sda_io_num;
int scl_io_num;
bool sda_pullup_en;
bool scl_pullup_en;
union {
struct {
uint32_t clk_speed;
} master;
};
uint32_t clk_flags;
} i2c_config_t;
#endif
@@ -1,4 +1,5 @@
#include "I2cDevice.h"
#include "Tactility/hal/i2c/I2cDevice.h"
#include <cstdint>
bool I2cDevice::readRegister12(uint8_t reg, float& out) const {
@@ -1,32 +0,0 @@
#pragma once
#include "./I2c.h"
/**
* Represents an I2C peripheral at a specific port and address.
* It helps to read and write registers.
*
* All read and write calls are thread-safe.
*/
class I2cDevice {
protected:
i2c_port_t port;
uint8_t address;
static constexpr TickType_t DEFAULT_TIMEOUT = 1000 / portTICK_PERIOD_MS;
bool readRegister8(uint8_t reg, uint8_t& result) const;
bool writeRegister8(uint8_t reg, uint8_t value) const;
bool readRegister12(uint8_t reg, float& out) const;
bool readRegister14(uint8_t reg, float& out) const;
bool readRegister16(uint8_t reg, uint16_t& out) const;
bool bitOn(uint8_t reg, uint8_t bitmask) const;
bool bitOff(uint8_t reg, uint8_t bitmask) const;
bool bitOnByIndex(uint8_t reg, uint8_t index) const { return bitOn(reg, 1 << index); }
bool bitOffByIndex(uint8_t reg, uint8_t index) const { return bitOff(reg, 1 << index); }
public:
explicit I2cDevice(i2c_port_t port, uint32_t address) : port(port), address(address) {}
};
+2 -2
View File
@@ -3,8 +3,8 @@
/**
* This code is based on i2c_manager from https://github.com/ropg/i2c_manager/blob/master/i2c_manager/i2c_manager.c (original has MIT license)
*/
#include "TactilityCore.h"
#include "I2c.h"
#include "Tactility/TactilityCore.h"
#include "Tactility/hal/i2c/I2c.h"
namespace tt::hal::i2c {
+6 -5
View File
@@ -1,10 +1,11 @@
#ifdef ESP_PLATFORM
#include <Log.h>
#include "Usb.h"
#include "UsbTusb.h"
#include "TactilityHeadless.h"
#include "hal/SpiSdCard.h"
#include "Tactility/hal/usb/Usb.h"
#include "Tactility/hal/usb/UsbTusb.h"
#include "Tactility/hal/SpiSdCard.h"
#include "Tactility/TactilityHeadless.h"
#include <Tactility/Log.h>
namespace tt::hal::usb {
-21
View File
@@ -1,21 +0,0 @@
#pragma once
namespace tt::hal::usb {
enum class Mode {
Default, // Default state of USB stack
None, // State after TinyUSB was used and (partially) deinitialized
MassStorageSdmmc
};
bool startMassStorageWithSdmmc();
void stop();
Mode getMode();
bool isSupported();
bool canRebootIntoMassStorageSdmmc();
void rebootIntoMassStorageSdmmc();
bool isUsbBootMode();
void resetUsbBootMode();
}
+1 -1
View File
@@ -1,6 +1,6 @@
#ifndef ESP_PLATFORM
#include "Usb.h"
#include "Tactility/hal/usb/Usb.h"
#define TAG "usb"
+6 -5
View File
@@ -1,13 +1,14 @@
#ifdef ESP_PLATFORM
#include "UsbTusb.h"
#include "sdkconfig.h"
#include "Tactility/hal/usb/UsbTusb.h"
#include <sdkconfig.h>
#if CONFIG_TINYUSB_MSC_ENABLED == 1
#include "Log.h"
#include "tinyusb.h"
#include "tusb_msc_storage.h"
#include <Tactility/Log.h>
#include <tinyusb.h>
#include <tusb_msc_storage.h>
#define TAG "usb"
#define EPNUM_MSC 1
@@ -1,5 +0,0 @@
#pragma once
bool tusbIsSupported();
bool tusbStartMassStorageWithSdmmc();
void tusbStop();
@@ -1,6 +1,8 @@
#include "SystemEvents.h"
#include "Mutex.h"
#include "CoreExtraDefines.h"
#include "Tactility/kernel/SystemEvents.h"
#include <Tactility/Mutex.h>
#include <Tactility/CoreExtraDefines.h>
#include <list>
#define TAG "system_event"
@@ -1,31 +0,0 @@
#pragma once
#include <cstdint>
namespace tt::kernel {
enum class SystemEvent {
BootInitHalBegin,
BootInitHalEnd,
BootInitI2cBegin,
BootInitI2cEnd,
BootInitLvglBegin,
BootInitLvglEnd,
BootSplash,
/** Gained IP address */
NetworkConnected,
NetworkDisconnected,
/** An important system time-related event, such as NTP update or time-zone change */
Time,
};
/** Value 0 mean "no subscription" */
typedef uint32_t SystemEventSubscription;
typedef void (*OnSystemEvent)(SystemEvent event);
void systemEventPublish(SystemEvent event);
SystemEventSubscription systemEventAddListener(SystemEvent event, OnSystemEvent handler);
void systemEventRemoveListener(SystemEventSubscription subscription);
}
+3 -3
View File
@@ -1,8 +1,8 @@
#include "network/NtpPrivate.h"
#include "Tactility/network/NtpPrivate.h"
#ifdef ESP_PLATFORM
#include "kernel/SystemEvents.h"
#include "TactilityCore.h"
#include <Tactility/kernel/SystemEvents.h>
#include <Tactility/TactilityCore.h>
#include <esp_netif_sntp.h>
#include <esp_sntp.h>
#endif
@@ -1,24 +0,0 @@
#pragma once
#include <memory>
namespace tt::service {
// Forward declaration
class ServiceContext;
class Service {
public:
Service() = default;
virtual ~Service() = default;
virtual void onStart(ServiceContext& serviceContext) {}
virtual void onStop(ServiceContext& serviceContext) {}
};
template<typename T>
std::shared_ptr<Service> create() { return std::shared_ptr<T>(new T); }
}
@@ -1,91 +0,0 @@
#pragma once
#include "Mutex.h"
#include "ServiceManifest.h"
#include <memory>
namespace tt::service {
class Paths;
/**
* The public representation of a service instance.
* @warning Do not store references or pointers to these! You can retrieve them via the Loader service.
*/
class ServiceContext {
protected:
virtual ~ServiceContext() = default;
public:
/** @return a reference ot the service's manifest */
virtual const service::ServiceManifest& getManifest() const = 0;
/** Retrieve the paths that are relevant to this service */
virtual std::unique_ptr<Paths> getPaths() const = 0;
};
class Paths {
public:
Paths() = default;
virtual ~Paths() = default;
/**
* Returns the directory path for the data location for a service.
* The data directory is intended to survive OS upgrades.
* The path will not end with a "/".
*/
virtual std::string getDataDirectory() const = 0;
/**
* @see getDataDirectory(), but with LVGL prefix.
*/
virtual std::string getDataDirectoryLvgl() const = 0;
/**
* Returns the full path for an entry inside the data location for a service.
* The data directory is intended to survive OS upgrades.
* Configuration data should be stored here.
* @param[in] childPath the path without a "/" prefix
*/
virtual std::string getDataPath(const std::string& childPath) const = 0;
/**
* @see getDataPath(), but with LVGL prefix.
*/
virtual std::string getDataPathLvgl(const std::string& childPath) const = 0;
/**
* Returns the directory path for the system location for a service.
* The system directory is not intended to survive OS upgrades.
* You should not store configuration data here.
* The path will not end with a "/".
* This is mainly used for core services.
*/
virtual std::string getSystemDirectory() const = 0;
/**
* @see getSystemDirectory(), but with LVGL prefix.
*/
virtual std::string getSystemDirectoryLvgl() const = 0;
/**
* Returns the full path for an entry inside the system location for an app.
* The data directory is not intended to survive OS upgrades.
* You should not store configuration data here.
* This is mainly used for core apps (system/boot/settings type).
* @param[in] childPath the path without a "/" prefix
*/
virtual std::string getSystemPath(const std::string& childPath) const = 0;
/**
* @see getSystemPath(), but with LVGL prefix.
*/
virtual std::string getSystemPathLvgl(const std::string& childPath) const = 0;
};
} // namespace
@@ -1,5 +1,5 @@
#include "service/ServiceInstance.h"
#include "service/ServiceInstancePaths.h"
#include "Tactility/service/ServiceInstance.h"
#include "Tactility/service/ServiceInstancePaths.h"
namespace tt::service {
@@ -1,5 +1,6 @@
#include "service/ServiceInstancePaths.h"
#include "Partitions.h"
#include "Tactility/service/ServiceInstancePaths.h"
#include "Tactility/Partitions.h"
#define LVGL_PATH_PREFIX std::string("A:/")
#ifdef ESP_PLATFORM
@@ -1,22 +0,0 @@
#pragma once
#include "service/Service.h"
#include <string>
namespace tt::service {
// Forward declarations
class ServiceContext;
typedef std::shared_ptr<Service>(*CreateService)();
/** A ledger that describes the main parts of a service. */
struct ServiceManifest {
/** The identifier by which the app is launched by the system and other apps. */
std::string id {};
/** Create the instance of the app */
CreateService createService = nullptr;
};
} // namespace
@@ -1,8 +1,10 @@
#include "ServiceRegistry.h"
#include "Tactility/service/ServiceRegistry.h"
#include "Tactility/service/ServiceInstance.h"
#include "Tactility/service/ServiceManifest.h"
#include <Tactility/Mutex.h>
#include "Mutex.h"
#include "service/ServiceInstance.h"
#include "service/ServiceManifest.h"
#include <string>
#include <unordered_map>
@@ -1,58 +0,0 @@
#pragma once
#include "service/ServiceManifest.h"
#include "service/Service.h"
#include <memory>
namespace tt::service {
/** Register a service.
* @param[in] the service manifest
*/
void addService(std::shared_ptr<const ServiceManifest> manifest, bool autoStart = true);
/** Register a service.
* @param[in] the service manifest
*/
void addService(const ServiceManifest& manifest, bool autoStart = true);
/** Start a service.
* @param[in] the service id as defined in its manifest
* @return true on success
*/
bool startService(const std::string& id);
/** Stop a service.
* @param[in] the service id as defined in its manifest
* @return true on success or false when service wasn't running.
*/
bool stopService(const std::string& id);
/** Find a service manifest by its id.
* @param[in] id the id as defined in the manifest
* @return the matching manifest or nullptr when it wasn't found
*/
std::shared_ptr<const ServiceManifest> _Nullable findManifestId(const std::string& id);
/** Find a ServiceContext by its manifest id.
* @param[in] id the id as defined in the manifest
* @return the service context or nullptr when it wasn't found
*/
std::shared_ptr<ServiceContext> _Nullable findServiceContextById(const std::string& id);
/** Find a Service by its manifest id.
* @param[in] id the id as defined in the manifest
* @return the service context or nullptr when it wasn't found
*/
std::shared_ptr<Service> _Nullable findServiceById(const std::string& id);
/** Find a Service by its manifest id.
* @param[in] id the id as defined in the manifest
* @return the service context or nullptr when it wasn't found
*/
template <typename T>
std::shared_ptr<T> _Nullable findServiceById(const std::string& id) {
return std::static_pointer_cast<T>(findServiceById(id));
}
} // namespace
@@ -1,9 +1,9 @@
#include "Mutex.h"
#include "Timer.h"
#include "Tactility/service/ServiceContext.h"
#include "Tactility/TactilityHeadless.h"
#include "Tactility/service/ServiceRegistry.h"
#include "service/ServiceContext.h"
#include "TactilityHeadless.h"
#include "service/ServiceRegistry.h"
#include <Tactility/Mutex.h>
#include <Tactility/Timer.h>
#define TAG "sdcard_service"
@@ -1,4 +1,4 @@
#include "./Wifi.h"
#include "Tactility/service/wifi/Wifi.h"
namespace tt::service::wifi {
@@ -1,131 +0,0 @@
#pragma once
#include "PubSub.h"
#include "WifiGlobals.h"
#include "WifiSettings.h"
#include <cstdio>
#include <string>
#include <vector>
#ifdef ESP_PLATFORM
#include "esp_wifi.h"
#include "WifiSettings.h"
#else
#include <cstdint>
// From esp_wifi_types.h in ESP-IDF 5.2
typedef enum {
WIFI_AUTH_OPEN = 0, /**< authenticate mode : open */
WIFI_AUTH_WEP, /**< authenticate mode : WEP */
WIFI_AUTH_WPA_PSK, /**< authenticate mode : WPA_PSK */
WIFI_AUTH_WPA2_PSK, /**< authenticate mode : WPA2_PSK */
WIFI_AUTH_WPA_WPA2_PSK, /**< authenticate mode : WPA_WPA2_PSK */
WIFI_AUTH_ENTERPRISE, /**< authenticate mode : WiFi EAP security */
WIFI_AUTH_WPA2_ENTERPRISE = WIFI_AUTH_ENTERPRISE, /**< authenticate mode : WiFi EAP security */
WIFI_AUTH_WPA3_PSK, /**< authenticate mode : WPA3_PSK */
WIFI_AUTH_WPA2_WPA3_PSK, /**< authenticate mode : WPA2_WPA3_PSK */
WIFI_AUTH_WAPI_PSK, /**< authenticate mode : WAPI_PSK */
WIFI_AUTH_OWE, /**< authenticate mode : OWE */
WIFI_AUTH_WPA3_ENT_192, /**< authenticate mode : WPA3_ENT_SUITE_B_192_BIT */
WIFI_AUTH_WPA3_EXT_PSK, /**< authenticate mode : WPA3_PSK_EXT_KEY */
WIFI_AUTH_WPA3_EXT_PSK_MIXED_MODE, /**< authenticate mode: WPA3_PSK + WPA3_PSK_EXT_KEY */
WIFI_AUTH_MAX
} wifi_auth_mode_t;
#endif
namespace tt::service::wifi {
enum class EventType {
/** Radio was turned on */
RadioStateOn,
/** Radio is turning on. */
RadioStateOnPending,
/** Radio is turned off */
RadioStateOff,
/** Radio is turning off */
RadioStateOffPending,
/** Started scanning for access points */
ScanStarted,
/** Finished scanning for access points */ // TODO: 1 second validity
ScanFinished,
Disconnected,
ConnectionPending,
ConnectionSuccess,
ConnectionFailed
};
enum class RadioState {
OnPending,
On,
ConnectionPending,
ConnectionActive,
OffPending,
Off,
};
struct Event {
EventType type;
};
struct ApRecord {
std::string ssid;
int8_t rssi;
int32_t channel;
wifi_auth_mode_t auth_mode;
};
/**
* @brief Get wifi pubsub
* @return PubSub
*/
std::shared_ptr<PubSub> getPubsub();
/** @return Get the current radio state */
RadioState getRadioState();
/** For logging purposes */
const char* radioStateToString(RadioState state);
/**
* @brief Request scanning update. Returns immediately. Results are through pubsub.
*/
void scan();
/** @return true if wifi is actively scanning */
bool isScanning();
/** @return true the ssid name or empty string */
std::string getConnectionTarget();
/** @return the access points from the last scan (if any). It only contains public APs. */
std::vector<ApRecord> getScanResults();
/**
* @brief Overrides the default scan result size of 16.
* @param[in] records the record limit for the scan result (84 bytes per record!)
*/
void setScanRecords(uint16_t records);
/**
* @brief Enable/disable the radio. Ignores input if desired state matches current state.
* @param[in] enabled
*/
void setEnabled(bool enabled);
/**
* @brief Connect to a network. Disconnects any existing connection.
* Returns immediately but runs in the background. Results are through pubsub.
* @param[in] ap
* @param[in] remember whether to save the ap data to the settings upon successful connection
*/
void connect(const settings::WifiApSettings* ap, bool remember);
/** @brief Disconnect from the access point. Doesn't have any effect when not connected. */
void disconnect();
/** @return true if the connection isn't unencrypted. */
bool isConnectionSecure();
/** @return the RSSI value (negative number) or return 1 when not connected. */
int getRssi();
} // namespace
@@ -1,13 +1,14 @@
#ifdef ESP_PLATFORM
#include "Wifi.h"
#include "Tactility/service/wifi/Wifi.h"
#include "TactilityHeadless.h"
#include "Timer.h"
#include "service/ServiceContext.h"
#include "WifiSettings.h"
#include "Tactility/TactilityHeadless.h"
#include "Tactility/service/ServiceContext.h"
#include "Tactility/service/wifi/WifiSettings.h"
#include "freertos/FreeRTOS.h"
#include <Tactility/Timer.h>
#include <freertos/FreeRTOS.h>
#include <atomic>
#include <cstring>
@@ -1,8 +0,0 @@
#pragma once
#define TT_WIFI_AUTO_CONNECT true // Default setting for new Wi-Fi entries
#define TT_WIFI_SCAN_RECORD_LIMIT 16 // default, can be overridden
#define TT_WIFI_SSID_LIMIT 32 // 32 characters/octets, according to IEEE 802.11-2020 spec
#define TT_WIFI_CREDENTIALS_PASSWORD_LIMIT 64 // 64 characters/octets, according to IEEE 802.11-2020 spec
@@ -1,13 +1,13 @@
#include "Wifi.h"
#include "Tactility/service/wifi/Wifi.h"
#ifndef ESP_PLATFORM
#include "Check.h"
#include "Log.h"
#include "MessageQueue.h"
#include "Mutex.h"
#include "PubSub.h"
#include "service/ServiceContext.h"
#include "Tactility/service/ServiceContext.h"
#include <Tactility/Check.h>
#include <Tactility/Log.h>
#include <Tactility/Mutex.h>
#include <Tactility/PubSub.h>
namespace tt::service::wifi {
@@ -1,4 +1,4 @@
#include "Preferences.h"
#include "Tactility/Preferences.h"
#define WIFI_PREFERENCES_NAMESPACE "wifi"
#define WIFI_PREFERENCES_KEY_ENABLE_ON_BOOT "enable_on_boot"
@@ -1,33 +0,0 @@
#pragma once
#include "WifiGlobals.h"
#include <cstdint>
namespace tt::service::wifi::settings {
/**
* This struct is stored as-is into NVS flash.
*
* The SSID and secret are increased by 1 byte to facilitate string null termination.
* This makes it easier to use the char array as a string in various places.
*/
struct WifiApSettings {
char ssid[TT_WIFI_SSID_LIMIT + 1] = { 0 };
char password[TT_WIFI_CREDENTIALS_PASSWORD_LIMIT + 1] = { 0 };
int32_t channel = 0;
bool auto_connect = true;
};
bool contains(const char* ssid);
bool load(const char* ssid, WifiApSettings* settings);
bool save(const WifiApSettings* settings);
bool remove(const char* ssid);
void setEnableOnBoot(bool enable);
bool shouldEnableOnBoot();
} // namespace
@@ -1,13 +1,14 @@
#ifdef ESP_PLATFORM
#include "WifiGlobals.h"
#include "WifiSettings.h"
#include <cstring>
#include "Tactility/service/wifi/WifiGlobals.h"
#include "Tactility/service/wifi/WifiSettings.h"
#include "nvs_flash.h"
#include "Log.h"
#include "crypt/Hash.h"
#include "crypt/Crypt.h"
#include <Tactility/Log.h>
#include <Tactility/crypt/Hash.h>
#include <Tactility/crypt/Crypt.h>
#include <nvs_flash.h>
#include <cstring>
#define TAG "wifi_settings"
#define TT_NVS_NAMESPACE "wifi_settings" // limited by NVS_KEY_NAME_MAX_SIZE
@@ -1,7 +1,6 @@
#ifndef ESP_PLATFORM
#include "WifiSettings.h"
#include "Log.h"
#include "Tactility/service/wifi/WifiSettings.h"
namespace tt::service::wifi::settings {
+6 -3
View File
@@ -1,7 +1,10 @@
#include "Tactility/time/Time.h"
#include "Tactility/kernel/SystemEvents.h"
#ifdef ESP_PLATFORM
#include <ctime>
#include "Time.h"
#include "Preferences.h"
#include "kernel/SystemEvents.h"
#include "Tactility/Preferences.h"
#endif
namespace tt::time {
-32
View File
@@ -1,32 +0,0 @@
#pragma once
#include <string>
namespace tt::time {
/**
* Set the timezone
* @param[in] name human-readable name
* @param[in] code the technical code (from timezones.csv)
*/
void setTimeZone(const std::string& name, const std::string& code);
/**
* Get the name of the timezone
*/
std::string getTimeZoneName();
/**
* Get the code of the timezone (see timezones.csv)
*/
std::string getTimeZoneCode();
/** @return true when clocks should be shown as a 24 hours one instead of 12 hours */
bool isTimeFormat24Hour();
/** Set whether clocks should be shown as a 24 hours instead of 12 hours
* @param[in] show24Hour
*/
void setTimeFormat24Hour(bool show24Hour);
}