Merge develop into main (#167)

- WiFi Connect app is now hidden by default, but accessible at the bottom of the WiFi Manage app when WiFi is turned on.
- WiFi service now turns on WiFi when calling connect() and WiFi is not on.
- Removed `blocking` option for `service::loader::startApp()`. This feature was unused and complex.
- Various apps: Moved private headers into Private/ folder.
- Various apps: created start() function for easy starting.
- Added documentation to all TactilityC APIs
- Refactored various `enum` into `class enum`
- Refactor M5Stack `initBoot()` (but VBus is still 0V for some reason)
This commit is contained in:
Ken Van Hoeylandt 2025-01-17 19:37:42 +01:00 committed by GitHub
parent 3ca0f8cf97
commit 3ea02d912f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
147 changed files with 1538 additions and 739 deletions

View File

@ -20,7 +20,7 @@ extern const tt::hal::Configuration lilygo_tdeck = {
tt::hal::i2c::Configuration {
.name = "Internal",
.port = I2C_NUM_0,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = false,
.hasMutableConfiguration = false,
.config = (i2c_config_t) {
@ -38,7 +38,7 @@ extern const tt::hal::Configuration lilygo_tdeck = {
tt::hal::i2c::Configuration {
.name = "External",
.port = I2C_NUM_1,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = true,
.hasMutableConfiguration = true,
.config = (i2c_config_t) {

View File

@ -56,11 +56,11 @@ TdeckPower::~TdeckPower() {
bool TdeckPower::supportsMetric(MetricType type) const {
switch (type) {
case BATTERY_VOLTAGE:
case CHARGE_LEVEL:
case MetricType::BatteryVoltage:
case MetricType::ChargeLevel:
return true;
case IS_CHARGING:
case CURRENT:
case MetricType::IsCharging:
case MetricType::Current:
return false;
}
@ -69,17 +69,17 @@ bool TdeckPower::supportsMetric(MetricType type) const {
bool TdeckPower::getMetric(Power::MetricType type, Power::MetricData& data) {
switch (type) {
case BATTERY_VOLTAGE:
case MetricType::BatteryVoltage:
return readBatteryVoltageSampled(data.valueAsUint32);
case CHARGE_LEVEL:
case MetricType::ChargeLevel:
if (readBatteryVoltageSampled(data.valueAsUint32)) {
data.valueAsUint32 = estimateChargeLevelFromVoltage(data.valueAsUint32);
return true;
} else {
return false;
}
case IS_CHARGING:
case CURRENT:
case MetricType::IsCharging:
case MetricType::Current:
return false;
}

View File

@ -18,7 +18,7 @@ std::shared_ptr<SdCard> createTdeckSdCard() {
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCard::MountBehaviourAtBoot,
SdCard::MountBehaviour::AtBoot,
tt::lvgl::getLvglSyncLockable(),
{
TDECK_RADIO_PIN_CS,

View File

@ -16,11 +16,11 @@
axp192_t axpDevice;
static int32_t axpI2cRead(TT_UNUSED void* handle, uint8_t address, uint8_t reg, uint8_t* buffer, uint16_t size) {
return tt::hal::i2c::masterRead(I2C_NUM_0, address, reg, buffer, size, 50 / portTICK_PERIOD_MS);
return tt::hal::i2c::masterReadRegister(I2C_NUM_0, address, reg, buffer, size, 50 / portTICK_PERIOD_MS);
}
static int32_t axpI2cWrite(TT_UNUSED void* handle, uint8_t address, uint8_t reg, const uint8_t* buffer, uint16_t size) {
return tt::hal::i2c::masterWrite(I2C_NUM_0, address, reg, buffer, size, 50 / portTICK_PERIOD_MS);
return tt::hal::i2c::masterWriteRegister(I2C_NUM_0, address, reg, buffer, size, 50 / portTICK_PERIOD_MS);
}
static bool initSpi2() {

View File

@ -15,7 +15,7 @@ extern const tt::hal::Configuration m5stack_core2 = {
tt::hal::i2c::Configuration {
.name = "Internal",
.port = I2C_NUM_0,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = false, // Might be set to try after trying out what it does AXP and screen
.hasMutableConfiguration = false,
.config = (i2c_config_t) {
@ -33,7 +33,7 @@ extern const tt::hal::Configuration m5stack_core2 = {
tt::hal::i2c::Configuration {
.name = "External", // (Grove)
.port = I2C_NUM_1,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = true,
.hasMutableConfiguration = true,
.config = (i2c_config_t) {

View File

@ -8,11 +8,11 @@ extern axp192_t axpDevice;
bool Core2Power::supportsMetric(MetricType type) const {
switch (type) {
case BATTERY_VOLTAGE:
case CHARGE_LEVEL:
case IS_CHARGING:
case MetricType::BatteryVoltage:
case MetricType::ChargeLevel:
case MetricType::IsCharging:
return true;
case CURRENT:
case MetricType::Current:
return false;
}
@ -21,7 +21,7 @@ bool Core2Power::supportsMetric(MetricType type) const {
bool Core2Power::getMetric(Power::MetricType type, Power::MetricData& data) {
switch (type) {
case BATTERY_VOLTAGE: {
case MetricType::BatteryVoltage: {
float voltage;
if (axp192_read(&axpDevice, AXP192_BATTERY_VOLTAGE, &voltage) == ESP_OK) {
data.valueAsUint32 = (uint32_t)TT_MAX((voltage * 1000.f), 0.0f);
@ -30,7 +30,7 @@ bool Core2Power::getMetric(Power::MetricType type, Power::MetricData& data) {
return false;
}
}
case CHARGE_LEVEL: {
case MetricType::ChargeLevel: {
float vbat, charge_current;
if (
axp192_read(&axpDevice, AXP192_BATTERY_VOLTAGE, &vbat) == ESP_OK &&
@ -51,7 +51,7 @@ bool Core2Power::getMetric(Power::MetricType type, Power::MetricData& data) {
return false;
}
}
case IS_CHARGING: {
case MetricType::IsCharging: {
float charge_current;
if (axp192_read(&axpDevice, AXP192_CHARGE_CURRENT, &charge_current) == ESP_OK) {
data.valueAsBool = charge_current > 0.001f;
@ -60,7 +60,7 @@ bool Core2Power::getMetric(Power::MetricType type, Power::MetricData& data) {
return false;
}
}
case CURRENT: {
case MetricType::Current: {
float charge_current, discharge_current;
if (
axp192_read(&axpDevice, AXP192_CHARGE_CURRENT, &charge_current) == ESP_OK &&

View File

@ -16,7 +16,7 @@ std::shared_ptr<SdCard> createSdCard() {
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCard::MountBehaviourAtBoot,
SdCard::MountBehaviour::AtBoot,
tt::lvgl::getLvglSyncLockable(),
{
CORE2_LCD_PIN_CS

View File

@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "Source" "Source/hal" "Source/Axp2101"
SRC_DIRS "Source" "Source/hal" "Source/Axp2101" "Source/Aw9523" "Source/I2cDevice"
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port esp_lcd esp_lcd_ili9341 esp_lcd_touch_ft5x06 driver vfs fatfs
)

View File

@ -0,0 +1,24 @@
#include "Aw9523.h"
#define AW9523_REGISTER_P0 0x02
#define AW9523_REGISTER_P1 0x03
bool Aw9523::readP0(uint8_t& output) const {
return readRegister8(AW9523_REGISTER_P0, output);
}
bool Aw9523::readP1(uint8_t& output) const {
return readRegister8(AW9523_REGISTER_P1, output);
}
bool Aw9523::writeP0(uint8_t value) const {
return writeRegister8(AW9523_REGISTER_P0, value);
}
bool Aw9523::writeP1(uint8_t value) const {
return writeRegister8(AW9523_REGISTER_P1, value);
}
bool Aw9523::bitOnP1(uint8_t bitmask) const {
return bitOn(AW9523_REGISTER_P1, bitmask);
}

View File

@ -0,0 +1,20 @@
#pragma once
#include "I2cDevice/I2cDevice.h"
#define AW9523_ADDRESS 0x58
class Aw9523 : I2cDevice {
public:
explicit Aw9523(i2c_port_t port) : I2cDevice(port, AW9523_ADDRESS) {}
bool readP0(uint8_t& output) const;
bool readP1(uint8_t& output) const;
bool writeP0(uint8_t value) const;
bool writeP1(uint8_t value) const;
bool bitOnP1(uint8_t bitmask) const;
};

View File

@ -1,44 +1,6 @@
#include "Axp2101.h"
#include "Log.h"
bool Axp2101::readRegister12(uint8_t reg, float& out) const {
std::uint8_t data[2] = {0};
if (tt::hal::i2c::masterRead(port, DEFAULT_ADDRESS, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
out = (data[0] & 0x0F) << 8 | data[1];
return true;
} else {
return false;
}
}
bool Axp2101::readRegister14(uint8_t reg, float& out) const {
std::uint8_t data[2] = {0};
if (tt::hal::i2c::masterRead(port, DEFAULT_ADDRESS, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
out = (data[0] & 0x3F) << 8 | data[1];
return true;
} else {
return false;
}
}
bool Axp2101::readRegister16(uint8_t reg, uint16_t& out) const {
std::uint8_t data[2] = {0};
if (tt::hal::i2c::masterRead(port, DEFAULT_ADDRESS, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
out = data[0] << 8 | data[1];
return true;
} else {
return false;
}
}
bool Axp2101::readRegister8(uint8_t reg, uint8_t& result) const {
return tt::hal::i2c::masterWriteRead(port, DEFAULT_ADDRESS, &reg, 1, &result, 1, DEFAULT_TIMEOUT);
}
bool Axp2101::writeRegister8(uint8_t reg, uint8_t value) const {
return tt::hal::i2c::masterWrite(port, DEFAULT_ADDRESS, reg, &value, 1, DEFAULT_TIMEOUT);
}
bool Axp2101::getBatteryVoltage(float& vbatMillis) const {
return readRegister14(0x34, vbatMillis);
}
@ -72,3 +34,26 @@ bool Axp2101::setChargingEnabled(bool enabled) const {
return false;
}
}
bool Axp2101::isVBus() const {
uint8_t value;
return readRegister8(0x00, value) && (value & 0x20);
}
bool Axp2101::getVBusVoltage(float& out) const {
if (!isVBus()) {
return false;
} else {
float vbus;
if (readRegister14(0x38, vbus) && vbus < 16375) {
out = vbus / 1000.0f;
return true;
} else {
return false;
}
}
}
bool Axp2101::setRegisters(uint8_t* bytePairs, size_t bytePairsSize) const {
return tt::hal::i2c::masterWriteRegisterArray(port, address, bytePairs, bytePairsSize, DEFAULT_TIMEOUT);
}

View File

@ -1,24 +1,16 @@
#pragma once
#include "hal/i2c/I2c.h"
#include "I2cDevice/I2cDevice.h"
#define AXP2101_ADDRESS 0x34
/**
* References:
* - https://github.com/m5stack/M5Unified/blob/master/src/utility/AXP2101_Class.cpp
* - http://file.whycan.com/files/members/6736/AXP2101_Datasheet_V1.0_en_3832.pdf
*/
class Axp2101 {
i2c_port_t port;
static constexpr uint8_t DEFAULT_ADDRESS = 0x34;
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;
class Axp2101 : I2cDevice {
public:
@ -28,10 +20,15 @@ public:
CHARGE_STATUS_STANDBY = 0b00
};
Axp2101(i2c_port_t port) : port(port) {}
explicit Axp2101(i2c_port_t port) : I2cDevice(port, AXP2101_ADDRESS) {}
bool setRegisters(uint8_t* bytePairs, size_t bytePairsSize) const;
bool getBatteryVoltage(float& vbatMillis) const;
bool getChargeStatus(ChargeStatus& status) const;
bool isChargingEnabled(bool& enabled) const;
bool setChargingEnabled(bool enabled) const;
bool isVBus() const;
bool getVBusVoltage(float& out) const;
};

View File

@ -0,0 +1,59 @@
#include "I2cDevice.h"
bool I2cDevice::readRegister12(uint8_t reg, float& out) const {
std::uint8_t data[2] = {0};
if (tt::hal::i2c::masterReadRegister(port, address, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
out = (data[0] & 0x0F) << 8 | data[1];
return true;
} else {
return false;
}
}
bool I2cDevice::readRegister14(uint8_t reg, float& out) const {
std::uint8_t data[2] = {0};
if (tt::hal::i2c::masterReadRegister(port, address, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
out = (data[0] & 0x3F) << 8 | data[1];
return true;
} else {
return false;
}
}
bool I2cDevice::readRegister16(uint8_t reg, uint16_t& out) const {
std::uint8_t data[2] = {0};
if (tt::hal::i2c::masterReadRegister(port, address, reg, data, 2, DEFAULT_TIMEOUT) == ESP_OK) {
out = data[0] << 8 | data[1];
return true;
} else {
return false;
}
}
bool I2cDevice::readRegister8(uint8_t reg, uint8_t& result) const {
return tt::hal::i2c::masterWriteRead(port, address, &reg, 1, &result, 1, DEFAULT_TIMEOUT);
}
bool I2cDevice::writeRegister8(uint8_t reg, uint8_t value) const {
return tt::hal::i2c::masterWriteRegister(port, address, reg, &value, 1, DEFAULT_TIMEOUT);
}
bool I2cDevice::bitOn(uint8_t reg, uint8_t bitmask) const {
uint8_t state;
if (readRegister8(reg, state)) {
state |= bitmask;
return writeRegister8(reg, state);
} else {
return false;
}
}
bool I2cDevice::bitOff(uint8_t reg, uint8_t bitmask) const {
uint8_t state;
if (readRegister8(reg, state)) {
state &= ~bitmask;
return writeRegister8(reg, state);
} else {
return false;
}
}

View File

@ -0,0 +1,25 @@
#pragma once
#include "hal/i2c/I2c.h"
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;
public:
explicit I2cDevice(i2c_port_t port, uint32_t address) : port(port), address(address) {}
};

View File

@ -3,8 +3,9 @@
#include <intr_types.h>
#include "Log.h"
#include "hal/CoreS3DisplayConstants.h"
#include "hal/i2c/I2c.h"
#include "CoreS3Constants.h"
#include "kernel/Kernel.h"
#include "Axp2101/Axp2101.h"
#include "Aw9523/Aw9523.h"
#define TAG "core2"
@ -43,62 +44,141 @@ static bool initSpi3() {
/**
* For details see https://github.com/espressif/esp-bsp/blob/master/bsp/m5stack_core_s3/m5stack_core_s3.c
* and schematic: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/datasheet/core/K128%20CoreS3/Sch_M5_CoreS3_v1.0.pdf
*/
bool initGpioExpander() {
TT_LOG_I(TAG, "Init AW9523 GPIO expander");
uint8_t aw9523_P0 = 0b10;
uint8_t aw9523_P1 = 0b10100000;
TT_LOG_I(TAG, "AW9523 init");
// Enable LCD
aw9523_P1 |= (1 << 1);
/**
* P0 pins:
* 0: Touch reset
* 1: Bus out enable
* 2: AW88298 reset (I2S)
* 3: ES7210 interrupt (Audio ADC)
* 4: SD Card SW(itch on?)
* 5: USB OTG enable
* 6: /
* 7: /
*/
/**
* P1 pins:
* 0: Cam reset
* 1: LCD reset
* 2: Touch interrupt
* 3: AW88298 interrupt (I2S)
* 4: /
* 5: /
* 6: /
* 7: Boost enable
*/
uint8_t p0_state = 0U;
uint8_t p1_state = 0U;
// Enable touch
aw9523_P0 |= (1);
p0_state |= (1U);
// Bus out enable
p0_state |= (1U << 1U);
// I2S
p0_state |= (1U << 2U);
// SD card
aw9523_P0 |= (1 << 4);
p0_state |= (1U << 4U);
if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AW9523_ADDRESS, 0x02, &aw9523_P0, 1, 1000)) {
TT_LOG_E(TAG, "Failed to enable LCD");
// Enable LCD
p1_state |= (1U << 1U);
// Boost enable
p1_state |= (1U << 7U);
Aw9523 aw(I2C_NUM_0);
if (!aw.writeP0(p0_state)) {
TT_LOG_E(TAG, "AW9523: Failed to set P0");
return false;
}
if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AW9523_ADDRESS, 0x03, &aw9523_P1, 1, 1000)) {
TT_LOG_E(TAG, "Failed to enable touch");
if (!aw.writeP1(p1_state)) {
TT_LOG_E(TAG, "AW9523: Failed to set P1");
return false;
}
Axp2101 axp(I2C_NUM_0);
if (axp.isVBus()) {
float voltage = 0.0f;
axp.getVBusVoltage(voltage);
TT_LOG_I(TAG, "AXP2101: VBus at %.2f", voltage);
} else {
TT_LOG_W(TAG, "AXP2101: VBus disabled");
}
return true;
}
bool initPowerControl() {
TT_LOG_I(TAG, "Init power control");
TT_LOG_I(TAG, "Init power control (AXP2101)");
uint8_t sdcard_3v3 = 0b00011100;
// TODO: Refactor to use Axp2101 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L62
if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x95, &sdcard_3v3, 1, 1000)) {
TT_LOG_E(TAG, "Failed to enable SD card");
Aw9523 aw(I2C_NUM_0);
// Source: https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/Power_Class.cpp#L61
aw.bitOnP1(0b10000000); // SY7088 boost enable
/** AXP2101 usage
Source: https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/README.md?plain=1#L223
| |M5Stack<BR>CoreS3<BR>CoreS3SE| |
|:---------:|:-----------------:|:---------:|
| ALDO1 |VDD 1v8 | ALDO1 |
| ALDO2 |VDDA 3v3 | ALDO2 |
| ALDO3 |CAM 3v3 | ALDO3 |
| ALDO4 |TF 3v3 | ALDO4 |
| BLDO1 |AVDD | BLDO1 |
| BLDO2 |DVDD | BLDO2 |
| DLDO1/DC1 |LCD BL | DLDO1/DC1 |
| DLDO2/DC2 | --- | DLDO2/DC2 |
| BACKUP |RTC BAT | BACKUP |
*/
/**
* 0x92 = ALD01
* 0x93 = ALD02
* 0x94 = ALD03
* 0x95 = ALD04
* 0x96 = BLD01
* 0x97 = BLD02
*
* DCDC1 : 0.7-3.5V 25mV/step 1200mA
* DCDC2 : 0.7-2.275V25mV/step 1600mA
* DCDC3 : 0.7-3.5V 25mV/step 700mA
* LDOio0: 1.8-3.3V, 100mV/step 50mA
* LDO1 : 30mA always on
* LDO2 : 1.8-3.3V 100mV/step 200mA
* LDO3 : 1.8-3.3V 100mV/step 200mA
*/
// Source: https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/Power_Class.cpp#L64
static constexpr uint8_t reg_data_array[] = {
0x90U, 0xBFU, // LDOS ON/OFF control 0 (backlight)
0x92U, 18U -5U, // ALDO1 set to 1.8v // for AW88298
0x93U, 33U -5U, // ALDO2 set to 3.3v // for ES7210
0x94U, 33U -5U, // ALDO3 set to 3.3v // for camera
0x95U, 33U -5U, // ALDO3 set to 3.3v // for TF card slot
0x27, 0x00, // PowerKey Hold=1sec / PowerOff=4sec
0x69, 0x11, // CHGLED setting
0x10, 0x30, // PMU common config
0x30, 0x0F // ADC enabled (for voltage measurement)
};
Axp2101 axp(I2C_NUM_0);
if (axp.setRegisters((uint8_t*)reg_data_array, sizeof(reg_data_array))) {
TT_LOG_I(TAG, "AXP2101 initialized with %d registers", sizeof(reg_data_array) / 2);
return true;
} else {
TT_LOG_E(TAG, "AXP2101: Failed to set registers");
return false;
}
// TODO: Refactor to use Axp2102 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L42
uint8_t axp_dld01_enable = 0xBF; // For backlight
if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x90, &axp_dld01_enable, 1, 1000)) {
TT_LOG_E(TAG, "Failed to enable display backlight");
return false;
}
// TODO: Refactor to use Axp2101 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L62
uint8_t axp_dld01_voltage = 0b00011000; // For backlight
if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &axp_dld01_voltage, 1, 1000)) {
TT_LOG_E(TAG, "Failed to set display backlight voltage");
return false;
}
return true;
}
bool initBoot() {
TT_LOG_I(TAG, "initBoot");
return initPowerControl() && initGpioExpander() && initSpi3();
TT_LOG_I(TAG, "initBoot()");
return initPowerControl() &&
initGpioExpander() &&
initSpi3();
}

View File

@ -15,7 +15,7 @@ const tt::hal::Configuration m5stack_cores3 = {
tt::hal::i2c::Configuration {
.name = "Internal",
.port = I2C_NUM_0,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = false,
.hasMutableConfiguration = false,
.config = (i2c_config_t) {
@ -33,7 +33,7 @@ const tt::hal::Configuration m5stack_cores3 = {
tt::hal::i2c::Configuration {
.name = "External", // Grove
.port = I2C_NUM_1,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = true,
.hasMutableConfiguration = true,
.config = (i2c_config_t) {

View File

@ -175,7 +175,7 @@ void CoreS3Display::setGammaCurve(uint8_t index) {
void CoreS3Display::setBacklightDuty(uint8_t backlightDuty) {
const uint8_t voltage = 20 + ((8 * backlightDuty) / 255); // [0b00000, 0b11100] - under 20 is too dark
// TODO: Refactor to use Axp2102 class with https://github.com/m5stack/M5Unified/blob/b8cfec7fed046242da7f7b8024a4e92004a51ff7/src/utility/AXP2101_Class.cpp#L42
if (!tt::hal::i2c::masterWrite(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &voltage, 1, 1000)) {
if (!tt::hal::i2c::masterWriteRegister(I2C_NUM_0, AXP2101_ADDRESS, 0x99, &voltage, 1, 1000)) { // Sets DLD01
TT_LOG_E(TAG, "Failed to set display backlight voltage");
}
}

View File

@ -5,11 +5,11 @@
bool CoreS3Power::supportsMetric(MetricType type) const {
switch (type) {
case BATTERY_VOLTAGE:
case IS_CHARGING:
case CHARGE_LEVEL:
case MetricType::BatteryVoltage:
case MetricType::IsCharging:
case MetricType::ChargeLevel:
return true;
case CURRENT:
case MetricType::Current:
return false;
}
@ -18,7 +18,7 @@ bool CoreS3Power::supportsMetric(MetricType type) const {
bool CoreS3Power::getMetric(Power::MetricType type, Power::MetricData& data) {
switch (type) {
case BATTERY_VOLTAGE: {
case MetricType::BatteryVoltage: {
float milliVolt;
if (axpDevice.getBatteryVoltage(milliVolt)) {
data.valueAsUint32 = (uint32_t)milliVolt;
@ -27,7 +27,7 @@ bool CoreS3Power::getMetric(Power::MetricType type, Power::MetricData& data) {
return false;
}
}
case CHARGE_LEVEL: {
case MetricType::ChargeLevel: {
float vbatMillis;
if (axpDevice.getBatteryVoltage(vbatMillis)) {
float vbat = vbatMillis / 1000.f;
@ -44,7 +44,7 @@ bool CoreS3Power::getMetric(Power::MetricType type, Power::MetricData& data) {
return false;
}
}
case IS_CHARGING: {
case MetricType::IsCharging: {
Axp2101::ChargeStatus status;
if (axpDevice.getChargeStatus(status)) {
data.valueAsBool = (status == Axp2101::CHARGE_STATUS_CHARGING);
@ -53,7 +53,7 @@ bool CoreS3Power::getMetric(Power::MetricType type, Power::MetricData& data) {
return false;
}
}
case CURRENT:
case MetricType::Current:
return false;
}

View File

@ -16,7 +16,7 @@ std::shared_ptr<SdCard> createSdCard() {
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCard::MountBehaviourAtBoot,
SdCard::MountBehaviour::AtBoot,
tt::lvgl::getLvglSyncLockable(),
{
CORES3_LCD_PIN_CS

View File

@ -10,8 +10,8 @@
#define TAG "lvgl_task"
// Mutex for LVGL drawing
static tt::Mutex lvgl_mutex(tt::Mutex::TypeRecursive);
static tt::Mutex task_mutex(tt::Mutex::TypeRecursive);
static tt::Mutex lvgl_mutex(tt::Mutex::Type::Recursive);
static tt::Mutex task_mutex(tt::Mutex::Type::Recursive);
static uint32_t task_max_sleep_ms = 10;
// Mutex for LVGL task state (to modify task_running state)

View File

@ -36,7 +36,7 @@ extern const tt::hal::Configuration hardware = {
tt::hal::i2c::Configuration {
.name = "Internal",
.port = I2C_NUM_0,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = false,
.hasMutableConfiguration = false,
.config = (i2c_config_t) {
@ -54,7 +54,7 @@ extern const tt::hal::Configuration hardware = {
tt::hal::i2c::Configuration {
.name = "External",
.port = I2C_NUM_1,
.initMode = tt::hal::i2c::InitByTactility,
.initMode = tt::hal::i2c::InitMode::ByTactility,
.canReinit = true,
.hasMutableConfiguration = true,
.config = (i2c_config_t) {

View File

@ -4,10 +4,10 @@
bool SimulatorPower::supportsMetric(MetricType type) const {
switch (type) {
case IS_CHARGING:
case CURRENT:
case BATTERY_VOLTAGE:
case CHARGE_LEVEL:
case MetricType::IsCharging:
case MetricType::Current:
case MetricType::BatteryVoltage:
case MetricType::ChargeLevel:
return true;
}
@ -16,16 +16,16 @@ bool SimulatorPower::supportsMetric(MetricType type) const {
bool SimulatorPower::getMetric(Power::MetricType type, Power::MetricData& data) {
switch (type) {
case IS_CHARGING:
case MetricType::IsCharging:
data.valueAsBool = true;
return true;
case CURRENT:
case MetricType::Current:
data.valueAsInt32 = 42;
return true;
case BATTERY_VOLTAGE:
case MetricType::BatteryVoltage:
data.valueAsUint32 = 4032;
return true;
case CHARGE_LEVEL:
case MetricType::ChargeLevel:
data.valueAsUint8 = 100;
return true;
}

View File

@ -8,14 +8,14 @@ class SimulatorSdCard : public SdCard {
private:
State state;
public:
SimulatorSdCard() : SdCard(MountBehaviourAtBoot), state(StateUnmounted) {}
SimulatorSdCard() : SdCard(MountBehaviour::AtBoot), state(State::Unmounted) {}
bool mount(const char* mountPath) override {
state = StateMounted;
state = State::Mounted;
return true;
}
bool unmount() override {
state = StateUnmounted;
state = State::Unmounted;
return true;
}

View File

@ -15,7 +15,7 @@ const tt::hal::Configuration yellow_board_24inch_cap = {
tt::hal::i2c::Configuration {
.name = "First",
.port = I2C_NUM_0,
.initMode = tt::hal::i2c::InitDisabled,
.initMode = tt::hal::i2c::InitMode::Disabled,
.canReinit = true,
.hasMutableConfiguration = true,
.config = (i2c_config_t) {
@ -33,7 +33,7 @@ const tt::hal::Configuration yellow_board_24inch_cap = {
tt::hal::i2c::Configuration {
.name = "Second",
.port = I2C_NUM_1,
.initMode = tt::hal::i2c::InitDisabled,
.initMode = tt::hal::i2c::InitMode::Disabled,
.canReinit = true,
.hasMutableConfiguration = true,
.config = (i2c_config_t) {

View File

@ -16,7 +16,7 @@ std::shared_ptr<SdCard> createYellowSdCard() {
GPIO_NUM_NC,
GPIO_NUM_NC,
GPIO_NUM_NC,
SdCard::MountBehaviourAtBoot,
SdCard::MountBehaviour::AtBoot,
nullptr,
std::vector<gpio_num_t>(),
SDCARD_SPI_HOST

View File

@ -37,7 +37,7 @@ class AppInstance : public AppContext {
private:
Mutex mutex = Mutex(Mutex::TypeNormal);
Mutex mutex = Mutex(Mutex::Type::Normal);
const AppManifest& manifest;
State state = StateInitial;
Flags flags = { .showStatusbar = true };

View File

@ -0,0 +1,34 @@
#pragma once
#include "./View.h"
#include "./State.h"
#include "app/AppManifest.h"
#include <lvgl.h>
#include <dirent.h>
#include <memory>
namespace tt::app::files {
class Files {
std::unique_ptr<View> view;
std::shared_ptr<State> state;
public:
Files() {
state = std::make_shared<State>();
view = std::make_unique<View>(state);
}
void onShow(lv_obj_t* parent) {
view->init(parent);
}
void onResult(Result result, const Bundle& bundle) {
view->onResult(result, bundle);
}
};
} // namespace

View File

@ -19,7 +19,7 @@ public:
private:
Mutex mutex = Mutex(Mutex::TypeRecursive);
Mutex mutex = Mutex(Mutex::Type::Recursive);
std::vector<dirent> dir_entries;
std::string current_path;
std::string selected_child_entry;

View File

@ -1,6 +1,7 @@
#pragma once
#include "State.h"
#include "./State.h"
#include "app/AppManifest.h"
#include <lvgl.h>
#include <memory>

View File

@ -0,0 +1,37 @@
#pragma once
#include <TactilityCore.h>
#include <Mutex.h>
#include <Thread.h>
#include "lvgl.h"
#include "hal/i2c/I2c.h"
#include "Timer.h"
#include <memory>
namespace tt::app::i2cscanner {
#define TAG "i2cscanner"
enum ScanState {
ScanStateInitial,
ScanStateScanning,
ScanStateStopped
};
struct Data {
// Core
Mutex mutex = Mutex(Mutex::Type::Recursive);
std::unique_ptr<Timer> scanTimer = nullptr;
// State
ScanState scanState;
i2c_port_t port = I2C_NUM_0;
std::vector<uint8_t> scannedAddresses;
// Widgets
lv_obj_t* scanButtonLabelWidget = nullptr;
lv_obj_t* portDropdownWidget = nullptr;
lv_obj_t* scanListWidget = nullptr;
};
void onScanTimerFinished(std::shared_ptr<Data> data);
}

View File

@ -1,6 +1,6 @@
#pragma once
#include "I2cScanner.h"
#include "./I2cScannerPrivate.h"
#include <memory>
namespace tt::app::i2cscanner {

View File

@ -0,0 +1,45 @@
#pragma once
#include "app/wificonnect/Bindings.h"
#include "app/wificonnect/State.h"
#include "app/wificonnect/View.h"
#include "Mutex.h"
#include "service/wifi/Wifi.h"
namespace tt::app::wificonnect {
class WifiConnect {
Mutex mutex;
State state;
Bindings bindings = {
.onConnectSsid = nullptr,
.onConnectSsidContext = nullptr
};
View view = View(&bindings, &state);
PubSubSubscription* wifiSubscription;
bool view_enabled = false;
public:
WifiConnect();
~WifiConnect();
void lock();
void unlock();
void onShow(AppContext& app, lv_obj_t* parent);
void onHide(AppContext& app);
State& getState() { return state; }
Bindings& getBindings() { return bindings; }
View& getView() { return view; }
void requestViewUpdate();
};
bool optSsidParameter(const std::shared_ptr<const Bundle>& bundle, std::string& ssid);
bool optPasswordParameter(const std::shared_ptr<const Bundle>& bundle, std::string& password);
} // namespace

View File

@ -6,12 +6,14 @@ typedef void (*OnWifiToggled)(bool enable);
typedef void (*OnConnectSsid)(const char* ssid);
typedef void (*OnDisconnect)();
typedef void (*OnShowApSettings)(const char* ssid);
typedef void (*OnConnectToHidden)();
struct Bindings{
OnWifiToggled onWifiToggled;
OnConnectSsid onConnectSsid;
OnDisconnect onDisconnect;
OnShowApSettings onShowApSettings;
OnConnectToHidden onConnectToHidden;
};
} // namespace

View File

@ -10,30 +10,30 @@ namespace tt::app::wifimanage {
*/
class State {
Mutex mutex = Mutex(Mutex::TypeRecursive);
Mutex mutex = Mutex(Mutex::Type::Recursive);
bool scanning = false;
bool scannedAfterRadioOn = false;
service::wifi::WifiRadioState radioState;
std::vector<service::wifi::WifiApRecord> apRecords;
service::wifi::RadioState radioState;
std::vector<service::wifi::ApRecord> apRecords;
std::string connectSsid;
public:
State() {}
State() = default;
void setScanning(bool isScanning);
bool isScanning() const;
bool hasScannedAfterRadioOn() const { return scannedAfterRadioOn; }
void setRadioState(service::wifi::WifiRadioState state);
service::wifi::WifiRadioState getRadioState() const;
void setRadioState(service::wifi::RadioState state);
service::wifi::RadioState getRadioState() const;
void updateApRecords();
const std::vector<service::wifi::WifiApRecord>& lockApRecords() const;
const std::vector<service::wifi::ApRecord>& lockApRecords() const;
void unlockApRecords() const;
void setConnectSsid(std::string ssid);
void setConnectSsid(const std::string& ssid);
std::string getConnectSsid() const;
};

View File

@ -1,8 +1,8 @@
#pragma once
#include "app/AppContext.h"
#include "Bindings.h"
#include "State.h"
#include "./Bindings.h"
#include "./State.h"
#include "lvgl.h"
namespace tt::app::wifimanage {
@ -19,12 +19,14 @@ private:
lv_obj_t* enable_on_boot_switch = nullptr;
lv_obj_t* scanning_spinner = nullptr;
lv_obj_t* networks_list = nullptr;
lv_obj_t* connect_to_hidden = nullptr;
void updateWifiToggle();
void updateEnableOnBootToggle();
void updateScanning();
void updateNetworkList();
void createSsidListItem(const service::wifi::WifiApRecord& record, bool isConnecting);
void updateConnectToHidden();
void createSsidListItem(const service::wifi::ApRecord& record, bool isConnecting);
public:

View File

@ -0,0 +1,35 @@
#pragma once
#include "Mutex.h"
#include "./View.h"
#include "./State.h"
#include "service/wifi/Wifi.h"
namespace tt::app::wifimanage {
class WifiManage {
PubSubSubscription* wifiSubscription = nullptr;
Mutex mutex;
Bindings bindings = { };
State state;
View view = View(&bindings, &state);
bool isViewEnabled = false;
public:
WifiManage();
void lock();
void unlock();
void onShow(AppContext& app, lv_obj_t* parent);
void onHide(AppContext& app);
Bindings& getBindings() { return bindings; }
State& getState() { return state; }
void requestViewUpdate();
};
} // namespace

View File

@ -19,7 +19,7 @@ namespace tt::service::gui {
struct Gui {
// Thread and lock
Thread* thread = nullptr;
Mutex mutex = Mutex(Mutex::TypeRecursive);
Mutex mutex = Mutex(Mutex::Type::Recursive);
PubSubSubscription* loader_pubsub_subscription = nullptr;
// Layers and Canvas

View File

@ -57,17 +57,12 @@ typedef struct {
class LoaderMessageAppStart {
public:
// This lock blocks anyone from starting an app as long
// as an app is already running via loader_start()
// This lock's lifecycle is not owned by this class.
std::shared_ptr<EventFlag> api_lock = std::make_shared<EventFlag>();
std::string id;
std::shared_ptr<const Bundle> _Nullable parameters;
LoaderMessageAppStart() = default;
LoaderMessageAppStart(LoaderMessageAppStart& other) :
api_lock(other.api_lock),
id(other.id),
parameters(other.parameters) {}
@ -77,14 +72,6 @@ public:
{}
~LoaderMessageAppStart() = default;
std::shared_ptr<EventFlag> getApiLockEventFlag() { return api_lock; }
uint32_t getApiLockEventFlagValue() { return 1; }
void onProcessed() {
api_lock->set(1);
}
};
// endregion LoaderMessage
@ -92,7 +79,7 @@ public:
struct Loader {
std::shared_ptr<PubSub> pubsubInternal = std::make_shared<PubSub>();
std::shared_ptr<PubSub> pubsubExternal = std::make_shared<PubSub>();
Mutex mutex = Mutex(Mutex::TypeRecursive);
Mutex mutex = Mutex(Mutex::Type::Recursive);
std::stack<app::AppInstance*> appStack;
/** The dispatcher thread needs a callstack large enough to accommodate all the dispatched methods.
* This includes full LVGL redraw via Gui::redraw()

View File

@ -10,7 +10,7 @@ namespace tt::app {
typedef std::unordered_map<std::string, const AppManifest*> AppManifestMap;
static AppManifestMap app_manifest_map;
static Mutex hash_mutex(Mutex::TypeNormal);
static Mutex hash_mutex(Mutex::Type::Normal);
void addApp(const AppManifest* manifest) {
TT_LOG_I(TAG, "Registering manifest %s", manifest->id.c_str());

View File

@ -19,13 +19,13 @@ namespace tt::app::alertdialog {
extern const AppManifest manifest;
void start(std::string title, std::string message, const std::vector<std::string>& buttonLabels) {
void start(const std::string& title, const std::string& message, const std::vector<std::string>& buttonLabels) {
std::string items_joined = string::join(buttonLabels, PARAMETER_ITEM_CONCATENATION_TOKEN);
auto bundle = std::make_shared<Bundle>();
bundle->putString(PARAMETER_BUNDLE_KEY_TITLE, title);
bundle->putString(PARAMETER_BUNDLE_KEY_MESSAGE, message);
bundle->putString(PARAMETER_BUNDLE_KEY_BUTTON_LABELS, items_joined);
service::loader::startApp(manifest.id, false, bundle);
service::loader::startApp(manifest.id, bundle);
}
int32_t getResultIndex(const Bundle& bundle) {

View File

@ -12,7 +12,13 @@
*/
namespace tt::app::alertdialog {
void start(std::string title, std::string message, const std::vector<std::string>& buttonLabels);
/**
* Show a dialog with the provided title, message and 0, 1 or more buttons.
* @param[in] title the title to show in the toolbar
* @param[in] message the message to display
* @param[in] buttonLabels the buttons to show
*/
void start(const std::string& title, const std::string& message, const std::vector<std::string>& buttonLabels);
/**
* Get the index of the button that the user selected.

View File

@ -10,7 +10,7 @@ namespace tt::app::applist {
static void onAppPressed(lv_event_t* e) {
const auto* manifest = static_cast<const AppManifest*>(lv_event_get_user_data(e));
service::loader::startApp(manifest->id, false);
service::loader::startApp(manifest->id);
}
static void createAppWidget(const AppManifest* manifest, void* parent) {

View File

@ -1,11 +1,11 @@
#ifdef ESP_TARGET
#include "app/crashdiagnostics/QrHelpers.h"
#include "app/crashdiagnostics/QrUrl.h"
#include "app/launcher/Launcher.h"
#include "lvgl.h"
#include "lvgl/Statusbar.h"
#include "app/launcher/Launcher.h"
#include "qrcode.h"
#include "QrHelpers.h"
#include "QrUrl.h"
#include "service/loader/Loader.h"
#define TAG "crash_diagnostics"

View File

@ -1,6 +1,5 @@
#include "app/crashdiagnostics/QrHelpers.h"
#include <cstdint>
#include <cassert>
#include "QrHelpers.h"
/**
* Maps QR version (starting at a fictitious 0) to the usable byte size for L(ow) CRC checking QR.

View File

@ -1,6 +1,6 @@
#ifdef ESP_TARGET
#include "QrUrl.h"
#include "app/crashdiagnostics/QrUrl.h"
#include "kernel/PanicHandler.h"
#include "Log.h"

View File

@ -1,4 +1,5 @@
#include "FileUtils.h"
#include "app/files/FileUtils.h"
#include "TactilityCore.h"
#include <cstring>
#include <StringUtils.h>

View File

@ -1,6 +1,8 @@
#include "Files.h"
#include "app/files/FilesPrivate.h"
#include "app/AppContext.h"
#include "Assets.h"
#include "service/loader/Loader.h"
#include <memory>
@ -37,4 +39,8 @@ extern const AppManifest manifest = {
.onResult = onResult
};
void start() {
service::loader::startApp(manifest.id);
}
} // namespace

View File

@ -10,24 +10,6 @@
namespace tt::app::files {
class Files {
std::unique_ptr<View> view;
std::shared_ptr<State> state;
public:
Files() {
state = std::make_shared<State>();
view = std::make_unique<View>(state);
}
void onShow(lv_obj_t* parent) {
view->init(parent);
}
void onResult(Result result, const Bundle& bundle) {
view->onResult(result, bundle);
}
};
void start();
} // namespace

View File

@ -1,7 +1,8 @@
#include "State.h"
#include "app/files/State.h"
#include "app/files/FileUtils.h"
#include "kernel/Kernel.h"
#include "Log.h"
#include "FileUtils.h"
#include "Partitions.h"
#include "hal/SdCard.h"

View File

@ -1,3 +1,6 @@
#include "app/files/FileUtils.h"
#include "app/files/View.h"
#include "app/alertdialog/AlertDialog.h"
#include "app/imageviewer/ImageViewer.h"
#include "app/inputdialog/InputDialog.h"
@ -6,9 +9,7 @@
#include "lvgl/Toolbar.h"
#include "lvgl/LvglSync.h"
#include "service/loader/Loader.h"
#include "FileUtils.h"
#include "Tactility.h"
#include "View.h"
#include "StringUtils.h"
#include <cstring>
#include <unistd.h>
@ -83,18 +84,14 @@ void View::viewFile(const std::string& path, const std::string& filename) {
app::startElfApp(processed_filepath);
#endif
} else if (isSupportedImageFile(filename)) {
auto bundle = std::make_shared<Bundle>();
bundle->putString(IMAGE_VIEWER_FILE_ARGUMENT, processed_filepath);
service::loader::startApp("ImageViewer", false, bundle);
app::imageviewer::start(processed_filepath);
} else if (isSupportedTextFile(filename)) {
auto bundle = std::make_shared<Bundle>();
if (kernel::getPlatform() == kernel::PlatformEsp) {
bundle->putString(TEXT_VIEWER_FILE_ARGUMENT, processed_filepath);
app::textviewer::start(processed_filepath);
} else {
// Remove forward slash, because we need a relative path
bundle->putString(TEXT_VIEWER_FILE_ARGUMENT, processed_filepath.substr(1));
app::textviewer::start(processed_filepath.substr(1));
}
service::loader::startApp("TextViewer", false, bundle);
} else {
TT_LOG_W(TAG, "opening files of this type is not supported");
}

View File

@ -96,7 +96,7 @@ void Gpio::startTask(std::shared_ptr<Gpio> ptr) {
lock();
tt_assert(timer == nullptr);
timer = std::make_unique<Timer>(
Timer::TypePeriodic,
Timer::Type::Periodic,
&onTimer,
ptr
);

View File

@ -1,4 +1,4 @@
#include "I2cHelpers.h"
#include "app/i2cscanner/I2cHelpers.h"
#include "Tactility.h"
#include "StringUtils.h"
#include <iomanip>

View File

@ -1,6 +1,6 @@
#include "I2cScanner.h"
#include "I2cScannerThread.h"
#include "I2cHelpers.h"
#include "app/i2cscanner/I2cScannerPrivate.h"
#include "app/i2cscanner/I2cScannerThread.h"
#include "app/i2cscanner/I2cHelpers.h"
#include "Assets.h"
#include "Tactility.h"
@ -50,7 +50,7 @@ static void onSelectBus(lv_event_t* event) {
TT_LOG_I(TAG, "Selected %ld", selected);
}
static void onPressScan(lv_event_t* event) {
static void onPressScan(TT_UNUSED lv_event_t* event) {
auto data = optData();
if (data != nullptr) {
if (data->scanState == ScanStateScanning) {
@ -191,4 +191,8 @@ extern const AppManifest manifest = {
.onHide = onHide
};
void start() {
service::loader::startApp(manifest.id);
}
} // namespace

View File

@ -10,28 +10,6 @@
namespace tt::app::i2cscanner {
#define TAG "i2cscanner"
enum ScanState {
ScanStateInitial,
ScanStateScanning,
ScanStateStopped
};
struct Data {
// Core
Mutex mutex = Mutex(Mutex::TypeRecursive);
std::unique_ptr<Timer> scanTimer = nullptr;
// State
ScanState scanState;
i2c_port_t port = I2C_NUM_0;
std::vector<uint8_t> scannedAddresses;
// Widgets
lv_obj_t* scanButtonLabelWidget = nullptr;
lv_obj_t* portDropdownWidget = nullptr;
lv_obj_t* scanListWidget = nullptr;
};
void onScanTimerFinished(std::shared_ptr<Data> data);
void start();
}

View File

@ -1,4 +1,4 @@
#include "I2cScannerThread.h"
#include "app/i2cscanner/I2cScannerThread.h"
#include "lvgl.h"
#include "service/loader/Loader.h"
@ -100,7 +100,7 @@ void startScanning(std::shared_ptr<Data> data) {
data->scanState = ScanStateScanning;
data->scanTimer = std::make_unique<Timer>(
Timer::TypeOnce,
Timer::Type::Once,
onScanTimer,
data
);

View File

@ -1,15 +1,16 @@
#include <TactilityCore.h>
#include "ImageViewer.h"
#include "lvgl.h"
#include "lvgl/Style.h"
#include "lvgl/Toolbar.h"
#include "StringUtils.h"
#include "service/loader/Loader.h"
namespace tt::app::imageviewer {
extern const AppManifest manifest;
#define TAG "image_viewer"
#define IMAGE_VIEWER_FILE_ARGUMENT "file"
static void onShow(AppContext& app, lv_obj_t* parent) {
auto wrapper = lv_obj_create(parent);
@ -57,4 +58,10 @@ extern const AppManifest manifest = {
.onShow = onShow
};
void start(const std::string& file) {
auto parameters = std::make_shared<Bundle>();
parameters->putString(IMAGE_VIEWER_FILE_ARGUMENT, file);
service::loader::startApp(manifest.id, parameters);
}
} // namespace

View File

@ -1,3 +1,7 @@
#pragma once
#define IMAGE_VIEWER_FILE_ARGUMENT "file"
namespace tt::app::imageviewer {
void start(const std::string& file);
};

View File

@ -24,7 +24,7 @@ void start(const std::string& title, const std::string& message, const std::stri
bundle->putString(PARAMETER_BUNDLE_KEY_TITLE, title);
bundle->putString(PARAMETER_BUNDLE_KEY_MESSAGE, message);
bundle->putString(PARAMETER_BUNDLE_KEY_PREFILLED, prefilled);
service::loader::startApp(manifest.id, false, bundle);
service::loader::startApp(manifest.id, bundle);
}
std::string getResult(const Bundle& bundle) {

View File

@ -3,13 +3,12 @@
#include "Check.h"
#include "lvgl.h"
#include "service/loader/Loader.h"
#include "Assets.h"
namespace tt::app::launcher {
static void onAppPressed(TT_UNUSED lv_event_t* e) {
auto* appId = (const char*)lv_event_get_user_data(e);
service::loader::startApp(appId, false);
service::loader::startApp(appId);
}
static lv_obj_t* createAppButton(lv_obj_t* parent, const char* title, const char* imageFile, const char* appId, int32_t buttonPaddingLeft) {

View File

@ -1,4 +1,3 @@
#include <TactilityCore.h>
#include <sstream>
#include <vector>
#include "lvgl.h"
@ -13,12 +12,12 @@
namespace tt::app::log {
struct LogAppData {
LogLevel filterLevel = LogLevelInfo;
LogLevel filterLevel = LogLevel::Info;
lv_obj_t* labelWidget = nullptr;
};
static bool shouldShowLog(LogLevel filterLevel, LogLevel logLevel) {
if (filterLevel == LogLevelNone || logLevel == LogLevelNone) {
if (filterLevel == LogLevel::None || logLevel == LogLevel::None) {
return false;
} else {
return filterLevel >= logLevel;
@ -115,19 +114,19 @@ static void onResult(AppContext& app, Result result, const Bundle& bundle) {
if (result == ResultOk) {
switch (resultIndex) {
case 0:
data->filterLevel = LogLevelVerbose;
data->filterLevel = LogLevel::Verbose;
break;
case 1:
data->filterLevel = LogLevelDebug;
data->filterLevel = LogLevel::Debug;
break;
case 2:
data->filterLevel = LogLevelInfo;
data->filterLevel = LogLevel::Info;
break;
case 3:
data->filterLevel = LogLevelWarning;
data->filterLevel = LogLevel::Warning;
break;
case 4:
data->filterLevel = LogLevelError;
data->filterLevel = LogLevel::Error;
break;
default:
break;

View File

@ -16,7 +16,7 @@ extern const AppManifest manifest;
static void onTimer(TT_UNUSED std::shared_ptr<void> context);
struct Data {
Timer update_timer = Timer(Timer::TypePeriodic, &onTimer, nullptr);
Timer update_timer = Timer(Timer::Type::Periodic, &onTimer, nullptr);
std::shared_ptr<tt::hal::Power> power = getConfiguration()->hardware->power();
lv_obj_t* enable_label = nullptr;
lv_obj_t* enable_switch = nullptr;
@ -39,7 +39,7 @@ std::shared_ptr<Data> _Nullable optData() {
static void updateUi(std::shared_ptr<Data> data) {
const char* charge_state;
hal::Power::MetricData metric_data;
if (data->power->getMetric(hal::Power::MetricType::IS_CHARGING, metric_data)) {
if (data->power->getMetric(hal::Power::MetricType::IsCharging, metric_data)) {
charge_state = metric_data.valueAsBool ? "yes" : "no";
} else {
charge_state = "N/A";
@ -47,7 +47,7 @@ static void updateUi(std::shared_ptr<Data> data) {
uint8_t charge_level;
bool charge_level_scaled_set = false;
if (data->power->getMetric(hal::Power::MetricType::CHARGE_LEVEL, metric_data)) {
if (data->power->getMetric(hal::Power::MetricType::ChargeLevel, metric_data)) {
charge_level = metric_data.valueAsUint8;
charge_level_scaled_set = true;
}
@ -57,14 +57,14 @@ static void updateUi(std::shared_ptr<Data> data) {
int32_t current;
bool current_set = false;
if (data->power->getMetric(hal::Power::MetricType::CURRENT, metric_data)) {
if (data->power->getMetric(hal::Power::MetricType::Current, metric_data)) {
current = metric_data.valueAsInt32;
current_set = true;
}
uint32_t battery_voltage;
bool battery_voltage_set = false;
if (data->power->getMetric(hal::Power::MetricType::BATTERY_VOLTAGE, metric_data)) {
if (data->power->getMetric(hal::Power::MetricType::BatteryVoltage, metric_data)) {
battery_voltage = metric_data.valueAsUint32;
battery_voltage_set = true;
}

View File

@ -2,7 +2,7 @@
#if TT_FEATURE_SCREENSHOT_ENABLED
#include "ScreenshotUi.h"
#include "app/screenshot/ScreenshotUi.h"
#include <memory>
namespace tt::app::screenshot {

View File

@ -2,7 +2,7 @@
#if TT_FEATURE_SCREENSHOT_ENABLED
#include "ScreenshotUi.h"
#include "app/screenshot/ScreenshotUi.h"
#include "TactilityCore.h"
#include "hal/SdCard.h"
@ -51,7 +51,7 @@ static void onTimerCallback(TT_UNUSED std::shared_ptr<void> context) {
}
ScreenshotUi::ScreenshotUi() {
updateTimer = std::make_unique<Timer>(Timer::TypePeriodic, onTimerCallback, nullptr);
updateTimer = std::make_unique<Timer>(Timer::Type::Periodic, onTimerCallback, nullptr);
}
ScreenshotUi::~ScreenshotUi() {
@ -146,7 +146,7 @@ void ScreenshotUi::createModeSettingWidgets(lv_obj_t* parent) {
lv_obj_align_to(modeDropdown, mode_label, LV_ALIGN_OUT_RIGHT_MID, 8, 0);
lv_obj_add_event_cb(modeDropdown, onModeSetCallback, LV_EVENT_VALUE_CHANGED, nullptr);
service::screenshot::Mode mode = service->getMode();
if (mode == service::screenshot::ScreenshotModeApps) {
if (mode == service::screenshot::Mode::Apps) {
lv_dropdown_set_selected(modeDropdown, 1);
}
@ -177,7 +177,7 @@ void ScreenshotUi::createFilePathWidgets(lv_obj_t* parent) {
lv_obj_set_flex_grow(pathTextArea, 1);
if (kernel::getPlatform() == kernel::PlatformEsp) {
auto sdcard = tt::hal::getConfiguration()->sdcard;
if (sdcard != nullptr && sdcard->getState() == hal::SdCard::StateMounted) {
if (sdcard != nullptr && sdcard->getState() == hal::SdCard::State::Mounted) {
lv_textarea_set_text(pathTextArea, "A:/sdcard");
} else {
lv_textarea_set_text(pathTextArea, "Error: no SD card");

View File

@ -18,12 +18,12 @@ namespace tt::app::selectiondialog {
extern const AppManifest manifest;
void start(std::string title, const std::vector<std::string>& items) {
void start(const std::string& title, const std::vector<std::string>& items) {
std::string items_joined = string::join(items, PARAMETER_ITEM_CONCATENATION_TOKEN);
auto bundle = std::make_shared<Bundle>();
bundle->putString(PARAMETER_BUNDLE_KEY_TITLE, title);
bundle->putString(PARAMETER_BUNDLE_KEY_ITEMS, items_joined);
service::loader::startApp(manifest.id, false, bundle);
service::loader::startApp(manifest.id, bundle);
}
int32_t getResultIndex(const Bundle& bundle) {

View File

@ -14,7 +14,7 @@
*/
namespace tt::app::selectiondialog {
void start(std::string title, const std::vector<std::string>& items);
void start(const std::string& title, const std::vector<std::string>& items);
/**
* Get the index of the item that the user selected.

View File

@ -4,8 +4,10 @@
#include "lvgl/LabelUtils.h"
#include "lvgl/Style.h"
#include "lvgl/Toolbar.h"
#include "service/loader/Loader.h"
#define TAG "text_viewer"
#define TEXT_VIEWER_FILE_ARGUMENT "file"
namespace tt::app::textviewer {
@ -45,4 +47,11 @@ extern const AppManifest manifest = {
.onShow = onShow
};
void start(const std::string& file) {
auto parameters = std::make_shared<Bundle>();
parameters->putString(TEXT_VIEWER_FILE_ARGUMENT, file);
service::loader::startApp(manifest.id, parameters);
}
} // namespace

View File

@ -1,3 +1,7 @@
#pragma once
#define TEXT_VIEWER_FILE_ARGUMENT "file"
namespace tt::app::textviewer {
void start(const std::string&file);
}

View File

@ -4,7 +4,6 @@
#include "service/loader/Loader.h"
#include "app/timezone/TimeZone.h"
#include "Assets.h"
#include "Tactility.h"
#include "time/Time.h"
#include "lvgl/LvglSync.h"
@ -15,7 +14,7 @@ namespace tt::app::timedatesettings {
extern const AppManifest manifest;
struct Data {
Mutex mutex = Mutex(Mutex::TypeRecursive);
Mutex mutex = Mutex(Mutex::Type::Recursive);
lv_obj_t* regionLabelWidget = nullptr;
};

View File

@ -224,7 +224,7 @@ static void onShow(AppContext& app, lv_obj_t* parent) {
static void onStart(AppContext& app) {
auto data = std::make_shared<Data>();
data->updateTimer = std::make_unique<Timer>(Timer::TypeOnce, onUpdateTimer, data);
data->updateTimer = std::make_unique<Timer>(Timer::Type::Once, onUpdateTimer, data);
app.setData(data);
}

View File

@ -27,7 +27,7 @@ const AppContext* _Nullable optWifiApSettingsApp() {
void start(const std::string& ssid) {
auto bundle = std::make_shared<Bundle>();
bundle->putString("ssid", ssid);
service::loader::startApp(manifest.id, false, bundle);
service::loader::startApp(manifest.id, bundle);
}
static void onPressForget(TT_UNUSED lv_event_t* event) {
@ -135,7 +135,7 @@ void onResult(TT_UNUSED AppContext& app, TT_UNUSED Result result, const Bundle&
TT_LOG_I(TAG, "Removed SSID");
if (
service::wifi::getRadioState() == service::wifi::WIFI_RADIO_CONNECTION_ACTIVE &&
service::wifi::getRadioState() == service::wifi::RadioState::ConnectionActive &&
service::wifi::getConnectionTarget() == ssid
) {
service::wifi::disconnect();

View File

@ -1,4 +0,0 @@
#pragma once
#define WIFI_CONNECT_PARAM_SSID "ssid" // String
#define WIFI_CONNECT_PARAM_PASSWORD "password" // String

View File

@ -1,4 +1,4 @@
#include "State.h"
#include "app/wificonnect/State.h"
#include "Check.h"
#include <cstring>

View File

@ -1,6 +1,5 @@
#include "View.h"
#include "State.h"
#include "Parameters.h"
#include "app/wificonnect/View.h"
#include "app/wificonnect/WifiConnectPrivate.h"
#include "WifiConnect.h"
#include "lvgl.h"
@ -186,19 +185,19 @@ void View::init(AppContext& app, lv_obj_t* parent) {
createBottomButtons(wrapper);
// Keyboard bindings
service::gui::keyboardAddTextArea(ssid_textarea);
service::gui::keyboardAddTextArea(password_textarea);
service::gui::keyboardAddTextArea(ssid_textarea);
service::gui::keyboardAddTextArea(password_textarea);
// Init from app parameters
auto bundle = app.getParameters();
if (bundle != nullptr) {
std::string ssid;
if (bundle->optString(WIFI_CONNECT_PARAM_SSID, ssid)) {
if (optSsidParameter(bundle, ssid)) {
lv_textarea_set_text(ssid_textarea, ssid.c_str());
}
std::string password;
if (bundle->optString(WIFI_CONNECT_PARAM_PASSWORD, password)) {
if (optPasswordParameter(bundle, ssid)) {
lv_textarea_set_text(password_textarea, password.c_str());
}
}

View File

@ -1,4 +1,4 @@
#include "WifiConnect.h"
#include "app/wificonnect/WifiConnectPrivate.h"
#include "app/AppContext.h"
#include "TactilityCore.h"
@ -9,6 +9,8 @@
namespace tt::app::wificonnect {
#define TAG "wifi_connect"
#define WIFI_CONNECT_PARAM_SSID "ssid" // String
#define WIFI_CONNECT_PARAM_PASSWORD "password" // String
extern const AppManifest manifest;
@ -23,18 +25,18 @@ std::shared_ptr<WifiConnect> _Nullable optWifiConnect() {
}
static void eventCallback(const void* message, void* context) {
auto* event = static_cast<const service::wifi::WifiEvent*>(message);
auto* event = static_cast<const service::wifi::Event*>(message);
auto* wifi = static_cast<WifiConnect*>(context);
State& state = wifi->getState();
switch (event->type) {
case service::wifi::WifiEventTypeConnectionFailed:
case service::wifi::EventType::ConnectionFailed:
if (state.isConnecting()) {
state.setConnecting(false);
state.setConnectionError(true);
wifi->requestViewUpdate();
}
break;
case service::wifi::WifiEventTypeConnectionSuccess:
case service::wifi::EventType::ConnectionSuccess:
if (wifi->getState().isConnecting()) {
state.setConnecting(false);
service::loader::stopApp();
@ -123,10 +125,25 @@ extern const AppManifest manifest = {
.id = "WifiConnect",
.name = "Wi-Fi Connect",
.icon = LV_SYMBOL_WIFI,
.type = TypeSettings,
.type = TypeHidden,
.onStart = &onStart,
.onShow = &onShow,
.onHide = &onHide
};
void start(const std::string& ssid, const std::string& password) {
auto parameters = std::make_shared<Bundle>();
parameters->putString(WIFI_CONNECT_PARAM_SSID, ssid);
parameters->putString(WIFI_CONNECT_PARAM_PASSWORD, password);
service::loader::startApp(manifest.id, parameters);
}
bool optSsidParameter(const std::shared_ptr<const Bundle>& bundle, std::string& ssid) {
return bundle->optString(WIFI_CONNECT_PARAM_SSID, ssid);
}
bool optPasswordParameter(const std::shared_ptr<const Bundle>& bundle, std::string& password) {
return bundle->optString(WIFI_CONNECT_PARAM_PASSWORD, password);
}
} // namespace

View File

@ -1,48 +1,12 @@
#pragma once
#include "Bindings.h"
#include "State.h"
#include "View.h"
#include "Mutex.h"
#include "service/wifi/Wifi.h"
#include <string>
namespace tt::app::wificonnect {
class WifiConnect {
Mutex mutex;
State state;
Bindings bindings = {
.onConnectSsid = nullptr,
.onConnectSsidContext = nullptr
};
View view = View(&bindings, &state);
PubSubSubscription* wifiSubscription;
bool view_enabled = false;
public:
WifiConnect();
~WifiConnect();
void lock();
void unlock();
void onShow(AppContext& app, lv_obj_t* parent);
void onHide(AppContext& app);
State& getState() { return state; }
Bindings& getBindings() { return bindings; }
View& getView() { return view; }
void requestViewUpdate();
};
void lock(WifiConnect* wifi);
void unlock(WifiConnect* wifi);
void view_update(WifiConnect* wifi);
/**
* Start the app with optional pre-filled fields.
*/
void start(const std::string& ssid = "", const std::string& password = "");
} // namespace

View File

@ -1,5 +1,5 @@
#include <Check.h>
#include "WifiManage.h"
#include "app/wifimanage/WifiManagePrivate.h"
namespace tt::app::wifimanage {
@ -10,16 +10,16 @@ void State::setScanning(bool isScanning) {
tt_check(mutex.release() == TtStatusOk);
}
void State::setRadioState(service::wifi::WifiRadioState state) {
void State::setRadioState(service::wifi::RadioState state) {
tt_check(mutex.acquire(TtWaitForever) == TtStatusOk);
radioState = state;
if (radioState == service::wifi::WIFI_RADIO_OFF) {
if (radioState == service::wifi::RadioState::Off) {
scannedAfterRadioOn = false;
}
tt_check(mutex.release() == TtStatusOk);
}
service::wifi::WifiRadioState State::getRadioState() const {
service::wifi::RadioState State::getRadioState() const {
tt_check(mutex.acquire(TtWaitForever) == TtStatusOk);
auto result = radioState;
tt_check(mutex.release() == TtStatusOk);
@ -33,7 +33,7 @@ bool State::isScanning() const {
return result;
}
const std::vector<service::wifi::WifiApRecord>& State::lockApRecords() const {
const std::vector<service::wifi::ApRecord>& State::lockApRecords() const {
tt_check(mutex.acquire(TtWaitForever) == TtStatusOk);
return apRecords;
}
@ -48,7 +48,7 @@ void State::updateApRecords() {
tt_check(mutex.release() == TtStatusOk);
}
void State::setConnectSsid(std::string ssid) {
void State::setConnectSsid(const std::string& ssid) {
tt_check(mutex.acquire(TtWaitForever) == TtStatusOk);
connectSsid = ssid;
tt_check(mutex.release() == TtStatusOk);

View File

@ -1,5 +1,5 @@
#include "View.h"
#include "WifiManage.h"
#include "app/wifimanage/View.h"
#include "app/wifimanage/WifiManagePrivate.h"
#include "Log.h"
#include "service/wifi/Wifi.h"
@ -48,6 +48,11 @@ static void on_enable_on_boot_switch_changed(lv_event_t* event) {
}
}
static void onConnectToHiddenClicked(lv_event_t* event) {
auto* bindings = (Bindings*)lv_event_get_user_data(event);
bindings->onConnectToHidden();
}
// region Secondary updates
static void connect(lv_event_t* event) {
@ -73,7 +78,7 @@ static void showDetails(lv_event_t* event) {
bindings->onShowApSettings(ssid);
}
void View::createSsidListItem(const service::wifi::WifiApRecord& record, bool isConnecting) {
void View::createSsidListItem(const service::wifi::ApRecord& record, bool isConnecting) {
lv_obj_t* wrapper = lv_obj_create(networks_list);
lv_obj_add_event_cb(wrapper, &connect, LV_EVENT_SHORT_CLICKED, bindings);
lv_obj_set_user_data(wrapper, bindings);
@ -124,20 +129,36 @@ void View::createSsidListItem(const service::wifi::WifiApRecord& record, bool is
}
}
void View::updateConnectToHidden() {
switch (state->getRadioState()) {
case service::wifi::RadioState::On:
case service::wifi::RadioState::ConnectionPending:
case service::wifi::RadioState::ConnectionActive:
lv_obj_remove_flag(connect_to_hidden, LV_OBJ_FLAG_HIDDEN);
break;
case service::wifi::RadioState::OnPending:
case service::wifi::RadioState::OffPending:
case service::wifi::RadioState::Off:
lv_obj_add_flag(connect_to_hidden, LV_OBJ_FLAG_HIDDEN);
break;
}
}
void View::updateNetworkList() {
lv_obj_clean(networks_list);
switch (state->getRadioState()) {
case service::wifi::WIFI_RADIO_ON_PENDING:
case service::wifi::WIFI_RADIO_ON:
case service::wifi::WIFI_RADIO_CONNECTION_PENDING:
case service::wifi::WIFI_RADIO_CONNECTION_ACTIVE: {
case service::wifi::RadioState::OnPending:
case service::wifi::RadioState::On:
case service::wifi::RadioState::ConnectionPending:
case service::wifi::RadioState::ConnectionActive: {
std::string connection_target = service::wifi::getConnectionTarget();
auto& ap_records = state->lockApRecords();
bool is_connected = !connection_target.empty() &&
state->getRadioState() == service::wifi::WIFI_RADIO_CONNECTION_ACTIVE;
state->getRadioState() == service::wifi::RadioState::ConnectionActive;
bool added_connected = false;
if (is_connected) {
if (!ap_records.empty()) {
@ -159,8 +180,8 @@ void View::updateNetworkList() {
if (used_ssids.find(record.ssid) == used_ssids.end()) {
bool connection_target_match = (record.ssid == connection_target);
bool is_connecting = connection_target_match
&& state->getRadioState() == service::wifi::WIFI_RADIO_CONNECTION_PENDING &&
!connection_target.empty();
&& state->getRadioState() == service::wifi::RadioState::ConnectionPending &&
!connection_target.empty();
bool skip = connection_target_match && added_connected;
if (!skip) {
createSsidListItem(record, is_connecting);
@ -180,8 +201,8 @@ void View::updateNetworkList() {
state->unlockApRecords();
break;
}
case service::wifi::WIFI_RADIO_OFF_PENDING:
case service::wifi::WIFI_RADIO_OFF: {
case service::wifi::RadioState::OffPending:
case service::wifi::RadioState::Off: {
lv_obj_add_flag(networks_list, LV_OBJ_FLAG_HIDDEN);
break;
}
@ -189,7 +210,7 @@ void View::updateNetworkList() {
}
void View::updateScanning() {
if (state->getRadioState() == service::wifi::WIFI_RADIO_ON && state->isScanning()) {
if (state->getRadioState() == service::wifi::RadioState::On && state->isScanning()) {
lv_obj_clear_flag(scanning_spinner, LV_OBJ_FLAG_HIDDEN);
} else {
lv_obj_add_flag(scanning_spinner, LV_OBJ_FLAG_HIDDEN);
@ -199,18 +220,18 @@ void View::updateScanning() {
void View::updateWifiToggle() {
lv_obj_clear_state(enable_switch, LV_STATE_ANY);
switch (state->getRadioState()) {
case service::wifi::WIFI_RADIO_ON:
case service::wifi::WIFI_RADIO_CONNECTION_PENDING:
case service::wifi::WIFI_RADIO_CONNECTION_ACTIVE:
case service::wifi::RadioState::On:
case service::wifi::RadioState::ConnectionPending:
case service::wifi::RadioState::ConnectionActive:
lv_obj_add_state(enable_switch, LV_STATE_CHECKED);
break;
case service::wifi::WIFI_RADIO_ON_PENDING:
case service::wifi::RadioState::OnPending:
lv_obj_add_state(enable_switch, LV_STATE_CHECKED | LV_STATE_DISABLED);
break;
case service::wifi::WIFI_RADIO_OFF:
case service::wifi::RadioState::Off:
lv_obj_remove_state(enable_switch, LV_STATE_CHECKED | LV_STATE_DISABLED);
break;
case service::wifi::WIFI_RADIO_OFF_PENDING:
case service::wifi::RadioState::OffPending:
lv_obj_remove_state(enable_switch, LV_STATE_CHECKED);
lv_obj_add_state(enable_switch, LV_STATE_DISABLED);
break;
@ -233,7 +254,7 @@ void View::updateEnableOnBootToggle() {
void View::init(const AppContext& app, lv_obj_t* parent) {
root = parent;
paths = std::move(app.getPaths());
paths = app.getPaths();
// Toolbar
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
@ -279,6 +300,14 @@ void View::init(const AppContext& app, lv_obj_t* parent) {
lv_obj_set_style_pad_top(networks_list, 0, 0);
lv_obj_set_style_pad_bottom(networks_list, 0, 0);
lv_obj_align(networks_list, LV_ALIGN_TOP_LEFT, 0, 44);
connect_to_hidden = lv_button_create(secondary_flex);
lv_obj_set_width(connect_to_hidden, LV_PCT(100));
lv_obj_set_style_margin_bottom(connect_to_hidden, 8, 0);
lv_obj_set_style_margin_hor(connect_to_hidden, 12, 0);
lv_obj_add_event_cb(connect_to_hidden, onConnectToHiddenClicked, LV_EVENT_SHORT_CLICKED, bindings);
auto* connect_to_hidden_label = lv_label_create(connect_to_hidden);
lv_label_set_text(connect_to_hidden_label, "Connect to hidden SSID");
}
void View::update() {
@ -286,6 +315,7 @@ void View::update() {
updateEnableOnBootToggle();
updateScanning();
updateNetworkList();
updateConnectToHidden();
}
} // namespace

View File

@ -1,14 +1,14 @@
#include "WifiManage.h"
#include "View.h"
#include "State.h"
#include "app/wifimanage/WifiManagePrivate.h"
#include "app/wifimanage/View.h"
#include "app/wifimanage/State.h"
#include "app/AppContext.h"
#include "app/wificonnect/Parameters.h"
#include "app/wifiapsettings/WifiApSettings.h"
#include "TactilityCore.h"
#include "service/loader/Loader.h"
#include "service/wifi/WifiSettings.h"
#include "lvgl/LvglSync.h"
#include "app/wificonnect/WifiConnect.h"
namespace tt::app::wifimanage {
@ -33,10 +33,7 @@ static void onConnect(const char* ssid) {
service::wifi::connect(&settings, false);
} else {
TT_LOG_I(TAG, "Starting connection dialog");
auto bundle = std::make_shared<Bundle>();
bundle->putString(WIFI_CONNECT_PARAM_SSID, ssid);
bundle->putString(WIFI_CONNECT_PARAM_PASSWORD, "");
service::loader::startApp("WifiConnect", false, bundle);
wificonnect::start(ssid);
}
}
@ -52,12 +49,17 @@ static void onWifiToggled(bool enabled) {
service::wifi::setEnabled(enabled);
}
static void onConnectToHidden() {
wificonnect::start();
}
WifiManage::WifiManage() {
bindings = (Bindings) {
.onWifiToggled = onWifiToggled,
.onConnectSsid = onConnect,
.onDisconnect = onDisconnect,
.onShowApSettings = onShowApSettings
.onShowApSettings = onShowApSettings,
.onConnectToHidden = onConnectToHidden
};
}
@ -83,19 +85,20 @@ void WifiManage::requestViewUpdate() {
}
static void wifiManageEventCallback(const void* message, void* context) {
auto* event = (service::wifi::WifiEvent*)message;
auto* event = (service::wifi::Event*)message;
auto* wifi = (WifiManage*)context;
TT_LOG_I(TAG, "Update with state %d", service::wifi::getRadioState());
wifi->getState().setRadioState(service::wifi::getRadioState());
auto radio_state = service::wifi::getRadioState();
TT_LOG_I(TAG, "Update with state %s", service::wifi::radioStateToString(radio_state));
wifi->getState().setRadioState(radio_state);
switch (event->type) {
case tt::service::wifi::WifiEventTypeScanStarted:
case tt::service::wifi::EventType::ScanStarted:
wifi->getState().setScanning(true);
break;
case tt::service::wifi::WifiEventTypeScanFinished:
case tt::service::wifi::EventType::ScanFinished:
wifi->getState().setScanning(false);
wifi->getState().updateApRecords();
break;
case tt::service::wifi::WifiEventTypeRadioStateOn:
case tt::service::wifi::EventType::RadioStateOn:
if (!service::wifi::isScanning()) {
service::wifi::scan();
}
@ -124,11 +127,11 @@ void WifiManage::onShow(AppContext& app, lv_obj_t* parent) {
view.update();
unlock();
service::wifi::WifiRadioState radio_state = service::wifi::getRadioState();
bool can_scan = radio_state == service::wifi::WIFI_RADIO_ON ||
radio_state == service::wifi::WIFI_RADIO_CONNECTION_PENDING ||
radio_state == service::wifi::WIFI_RADIO_CONNECTION_ACTIVE;
TT_LOG_I(TAG, "%d %d", radio_state, service::wifi::isScanning());
service::wifi::RadioState radio_state = service::wifi::getRadioState();
bool can_scan = radio_state == service::wifi::RadioState::On ||
radio_state == service::wifi::RadioState::ConnectionPending ||
radio_state == service::wifi::RadioState::ConnectionActive;
TT_LOG_I(TAG, "%s %d", service::wifi::radioStateToString(radio_state), (int)service::wifi::isScanning());
if (can_scan && !service::wifi::isScanning()) {
service::wifi::scan();
}
@ -172,4 +175,8 @@ extern const AppManifest manifest = {
.onHide = onHide
};
void start() {
service::loader::startApp(manifest.id);
}
} // namespace

View File

@ -1,35 +1,12 @@
#pragma once
#include "Mutex.h"
#include "View.h"
#include "State.h"
#include "app/wifimanage/View.h"
#include "app/wifimanage/State.h"
#include "service/wifi/Wifi.h"
namespace tt::app::wifimanage {
class WifiManage {
PubSubSubscription* wifiSubscription = nullptr;
Mutex mutex;
Bindings bindings = { };
State state;
View view = View(&bindings, &state);
bool isViewEnabled = false;
public:
WifiManage();
void lock();
void unlock();
void onShow(AppContext& app, lv_obj_t* parent);
void onHide(AppContext& app);
Bindings& getBindings() { return bindings; }
State& getState() { return state; }
void requestViewUpdate();
};
void start();
} // namespace

View File

@ -26,10 +26,10 @@ struct StatusbarIcon {
};
struct StatusbarData {
Mutex mutex = Mutex(Mutex::TypeRecursive);
Mutex mutex = Mutex(Mutex::Type::Recursive);
std::shared_ptr<PubSub> pubsub = std::make_shared<PubSub>();
StatusbarIcon icons[STATUSBAR_ICON_LIMIT] = {};
Timer* time_update_timer = new Timer(Timer::TypeOnce, onUpdateTime, nullptr);
Timer* time_update_timer = new Timer(Timer::Type::Once, onUpdateTime, nullptr);
uint8_t time_hours = 0;
uint8_t time_minutes = 0;
bool time_set = false;

View File

@ -17,6 +17,13 @@ namespace tt::service::loader {
#define TAG "loader"
enum class LoaderStatus {
Ok,
ErrorAppStarted,
ErrorUnknownApp,
ErrorInternal,
};
typedef struct {
LoaderEventType type;
} LoaderEventInternal;
@ -41,20 +48,11 @@ static void loader_free() {
loader_singleton = nullptr;
}
void startApp(const std::string& id, bool blocking, const std::shared_ptr<const Bundle>& parameters) {
void startApp(const std::string& id, const std::shared_ptr<const Bundle>& parameters) {
TT_LOG_I(TAG, "Start app %s", id.c_str());
tt_assert(loader_singleton);
auto message = std::make_shared<LoaderMessageAppStart>(id, parameters);
loader_singleton->dispatcherThread->dispatch(onStartAppMessage, message);
auto event_flag = message->getApiLockEventFlag();
if (blocking) {
/* TODO: Check if task id is not the LVGL one,
because otherwise this fails as the apps starting logic will try to lock lvgl
to update the UI and fail. */
event_flag->wait(message->getApiLockEventFlagValue());
}
}
void stopApp() {
@ -163,7 +161,7 @@ static LoaderStatus startAppWithManifestInternal(
auto scoped_lock = loader_singleton->mutex.scoped();
if (!scoped_lock->lock(50 / portTICK_PERIOD_MS)) {
return LoaderStatusErrorInternal;
return LoaderStatus::ErrorInternal;
}
auto previous_app = !loader_singleton->appStack.empty() ? loader_singleton->appStack.top() : nullptr;
@ -192,7 +190,7 @@ static LoaderStatus startAppWithManifestInternal(
};
tt_pubsub_publish(loader_singleton->pubsubExternal, &event_external);
return LoaderStatusOk;
return LoaderStatus::Ok;
}
static void onStartAppMessage(std::shared_ptr<void> message) {
@ -213,7 +211,7 @@ static LoaderStatus startAppInternal(
const app::AppManifest* manifest = app::findAppById(id);
if (manifest == nullptr) {
TT_LOG_E(TAG, "App not found: %s", id.c_str());
return LoaderStatusErrorUnknownApp;
return LoaderStatus::ErrorUnknownApp;
} else {
return startAppWithManifestInternal(manifest, parameters);
}

View File

@ -10,21 +10,13 @@ namespace tt::service::loader {
typedef struct Loader Loader;
typedef enum {
LoaderStatusOk,
LoaderStatusErrorAppStarted,
LoaderStatusErrorUnknownApp,
LoaderStatusErrorInternal,
} LoaderStatus;
/**
* @brief Start an app
* @param[in] id application name or id
* @param[in] blocking whether this call is blocking or not. You cannot call this from an LVGL thread.
* @param[in] parameters optional parameters to pass onto the application
*/
void startApp(const std::string& id, bool blocking = false, const std::shared_ptr<const Bundle>& _Nullable parameters = nullptr);
void startApp(const std::string& id, const std::shared_ptr<const Bundle>& _Nullable parameters = nullptr);
/** @brief Stop the currently showing app. Show the previous app if any app was still running. */
void stopApp();

View File

@ -32,7 +32,7 @@ void ScreenshotService::startApps(const char* path) {
if (task == nullptr || task->isFinished()) {
task = std::make_unique<ScreenshotTask>();
mode = ScreenshotModeApps;
mode = Mode::Apps;
task->startApps(path);
} else {
TT_LOG_W(TAG, "Screenshot task already running");
@ -48,7 +48,7 @@ void ScreenshotService::startTimed(const char* path, uint8_t delayInSeconds, uin
if (task == nullptr || task->isFinished()) {
task = std::make_unique<ScreenshotTask>();
mode = ScreenshotModeTimed;
mode = Mode::Timed;
task->startTimed(path, delayInSeconds, amount);
} else {
TT_LOG_W(TAG, "Screenshot task already running");
@ -64,17 +64,17 @@ void ScreenshotService::stop() {
if (task != nullptr) {
task = nullptr;
mode = ScreenshotModeNone;
mode = Mode::None;
} else {
TT_LOG_W(TAG, "Screenshot task not running");
}
}
Mode ScreenshotService::getMode() {
Mode ScreenshotService::getMode() const {
auto scoped_lockable = mutex.scoped();
if (!scoped_lockable->lock(50 / portTICK_PERIOD_MS)) {
TT_LOG_W(TAG, LOG_MESSAGE_MUTEX_LOCK_FAILED);
return ScreenshotModeNone;
return Mode::None;
}
return mode;

View File

@ -10,11 +10,11 @@
namespace tt::service::screenshot {
typedef enum {
ScreenshotModeNone,
ScreenshotModeTimed,
ScreenshotModeApps
} Mode;
enum class Mode {
None,
Timed,
Apps
};
class ScreenshotService {
@ -22,14 +22,14 @@ private:
Mutex mutex;
std::unique_ptr<ScreenshotTask> task;
Mode mode = ScreenshotModeNone;
Mode mode = Mode::None;
public:
bool isTaskStarted();
/** The state of the service. */
Mode getMode();
Mode getMode() const;
/** @brief Start taking screenshot whenever an app is started
* @param[in] path the path to store the screenshots at

View File

@ -25,7 +25,7 @@ class ScreenshotTask {
};
Thread* thread = nullptr;
Mutex mutex = Mutex(Mutex::TypeRecursive);
Mutex mutex = Mutex(Mutex::Type::Recursive);
bool interrupted = false;
bool finished = false;
ScreenshotTaskWork work;

View File

@ -80,17 +80,17 @@ const char* getWifiStatusIconForRssi(int rssi) {
}
}
static const char* getWifiStatusIcon(wifi::WifiRadioState state, bool secure) {
static const char* getWifiStatusIcon(wifi::RadioState state, bool secure) {
int rssi;
switch (state) {
case wifi::WIFI_RADIO_ON:
case wifi::WIFI_RADIO_ON_PENDING:
case wifi::WIFI_RADIO_CONNECTION_PENDING:
case wifi::RadioState::On:
case wifi::RadioState::OnPending:
case wifi::RadioState::ConnectionPending:
return STATUSBAR_ICON_WIFI_SCAN_WHITE;
case wifi::WIFI_RADIO_OFF_PENDING:
case wifi::WIFI_RADIO_OFF:
case wifi::RadioState::OffPending:
case wifi::RadioState::Off:
return STATUSBAR_ICON_WIFI_OFF_WHITE;
case wifi::WIFI_RADIO_CONNECTION_ACTIVE:
case wifi::RadioState::ConnectionActive:
rssi = wifi::getRssi();
return getWifiStatusIconForRssi(rssi);
default:
@ -99,7 +99,7 @@ static const char* getWifiStatusIcon(wifi::WifiRadioState state, bool secure) {
}
static void updateWifiIcon(const service::Paths* paths, const std::shared_ptr<ServiceData>& data) {
wifi::WifiRadioState radio_state = wifi::getRadioState();
wifi::RadioState radio_state = wifi::getRadioState();
bool is_secure = wifi::isConnectionSecure();
const char* desired_icon = getWifiStatusIcon(radio_state, is_secure);
if (data->wifi_last_icon != desired_icon) {
@ -120,11 +120,11 @@ static void updateWifiIcon(const service::Paths* paths, const std::shared_ptr<Se
static const char* getSdCardStatusIcon(hal::SdCard::State state) {
switch (state) {
case hal::SdCard::StateMounted:
case hal::SdCard::State::Mounted:
return STATUSBAR_ICON_SDCARD;
case hal::SdCard::StateError:
case hal::SdCard::StateUnmounted:
case hal::SdCard::StateUnknown:
case hal::SdCard::State::Error:
case hal::SdCard::State::Unmounted:
case hal::SdCard::State::Unknown:
return STATUSBAR_ICON_SDCARD_ALERT;
default:
tt_crash("Unhandled SdCard state");
@ -135,7 +135,7 @@ static void updateSdCardIcon(const service::Paths* paths, const std::shared_ptr<
auto sdcard = tt::hal::getConfiguration()->sdcard;
if (sdcard != nullptr) {
auto state = sdcard->getState();
if (state != hal::SdCard::StateUnknown) {
if (state != hal::SdCard::State::Unknown) {
auto* desired_icon = getSdCardStatusIcon(state);
if (data->sdcard_last_icon != desired_icon) {
auto icon_path = paths->getSystemPathLvgl(desired_icon);
@ -161,7 +161,7 @@ static _Nullable const char* getPowerStatusIcon() {
auto power = get_power();
hal::Power::MetricData charge_level;
if (!power->getMetric(hal::Power::MetricType::CHARGE_LEVEL, charge_level)) {
if (!power->getMetric(hal::Power::MetricType::ChargeLevel, charge_level)) {
return nullptr;
}
@ -228,7 +228,7 @@ static void onStart(ServiceContext& service) {
auto data = std::make_shared<ServiceData>();
lvgl::unlock();
data->paths = std::move(service.getPaths());
data->paths = service.getPaths();
service.setData(data);
@ -238,7 +238,7 @@ static void onStart(ServiceContext& service) {
updateSdCardIcon(data->paths.get(), data); // also updates visibility
updatePowerStatusIcon(data->paths.get(), data);
data->updateTimer = std::make_unique<Timer>(Timer::TypePeriodic, onUpdate, data);
data->updateTimer = std::make_unique<Timer>(Timer::Type::Periodic, onUpdate, data);
// We want to try and scan more often in case of startup or scan lock failure
data->updateTimer->start(1000);
}

View File

@ -6,8 +6,7 @@ extern "C" {
void tt_app_alertdialog_start(const char* title, const char* message, const char* buttonLabels[], uint32_t buttonLabelCount) {
std::vector<std::string> list;
for (int i = 0; i < buttonLabelCount; i++) {
const char* item = buttonLabels[i];
list.push_back(item);
list.emplace_back(buttonLabels[i]);
}
tt::app::alertdialog::start(title, message, list);
}

View File

@ -8,7 +8,18 @@ extern "C" {
#include <stdint.h>
/**
* Show a dialog with the provided title, message and 0, 1 or more buttons.
* @param[in] title the title to show in the toolbar
* @param[in] message the message to display
* @param[in] buttonLabels the buttons to show, or null when there are none to show
* @param[in] buttonLabelCount the amount of buttons (0 or more)
*/
void tt_app_alertdialog_start(const char* title, const char* message, const char* buttonLabels[], uint32_t buttonLabelCount);
/**
* @return the index of the button that was clicked (the index in the array when start() was called)
*/
int32_t tt_app_alertdialog_get_result_index(BundleHandle handle);
#ifdef __cplusplus

View File

@ -8,10 +8,30 @@ extern "C" {
typedef void* AppContextHandle;
/** @return the data that was attached to this app context */
void* _Nullable tt_app_context_get_data(AppContextHandle handle);
/**
* Attach data to an application context.
* Don't forget to manually delete allocated memory when onStopped() is called.
* @param[in] handle the app context handle
* @param[in] data the data to attach
*/
void tt_app_context_set_data(AppContextHandle handle, void* _Nullable data);
/** @return the bundle that belongs to this application, or null */
BundleHandle _Nullable tt_app_context_get_parameters(AppContextHandle handle);
/**
* Set the result before closing an app.
* The result and bundle are passed along to the app that launched this app, when this app is closed.
* @param[in] handle the app context handle to set the result for
* @param[in] result the result state to set
* @param[in] bundle the result bundle to set
*/
void tt_app_context_set_result(AppContextHandle handle, Result result, BundleHandle _Nullable bundle);
/** @return true if a result was set for this app context */
bool tt_app_context_has_result(AppContextHandle handle);
#ifdef __cplusplus

View File

@ -21,6 +21,16 @@ typedef void (*AppOnShow)(AppContextHandle app, lv_obj_t* parent);
typedef void (*AppOnHide)(AppContextHandle app);
typedef void (*AppOnResult)(AppContextHandle app, Result result, BundleHandle resultData);
/**
* This is used to register the manifest of an external app.
* @param[in] name the application's human-readable name
* @param[in] icon the optional application icon (you can use LV_SYMBOL_* too)
* @param[in] onStart called when the app is launched (started)
* @param[in] onStop called when the app is exited (stopped)
* @param[in] onShow called when the app is about to be shown to the user (app becomes visible)
* @param[in] onHide called when the app is about to be invisible to the user (e.g. other app was launched by this app, and this app goes to the background)
* @param[in] onResult called when the app receives a result after launching another app
*/
void tt_set_app_manifest(
const char* name,
const char* _Nullable icon,

View File

@ -6,8 +6,7 @@ extern "C" {
void tt_app_selectiondialog_start(const char* title, int argc, const char* argv[]) {
std::vector<std::string> list;
for (int i = 0; i < argc; i++) {
const char* item = argv[i];
list.push_back(item);
list.emplace_back(argv[i]);
}
tt::app::selectiondialog::start(title, list);
}

View File

@ -6,8 +6,15 @@
extern "C" {
#endif
/**
* Start an app that displays a list of items and allows the user to select one.
* @param[in] title the title to show in the toolbar
* @param[in] argc the amount of items that the list contains
* @param[in] argv the labels of the items in the list
*/
void tt_app_selectiondialog_start(const char* title, int argc, const char* argv[]);
/** @return the index of the item that was clicked by the user, or -1 when the user didn't select anything */
int32_t tt_app_selectiondialog_get_result_index(BundleHandle handle);
#ifdef __cplusplus

Some files were not shown because too many files have changed in this diff Show More