feature: Pictogram illumination queue
This commit is contained in:
+86
-49
@@ -32,14 +32,14 @@ void app_main(void);
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct DeviceState {
|
struct DeviceState {
|
||||||
uint8_t minJumps;
|
uint8_t minJumps{6};
|
||||||
uint8_t maxJumps;
|
uint8_t maxJumps{32};
|
||||||
uint8_t profile;
|
uint8_t profile{};
|
||||||
uint8_t restTime;
|
uint8_t restTime{};
|
||||||
float speed = 1.0; // Rad/sec
|
float speed = 1.0; // Rad/sec
|
||||||
float accel = 1.0; // Rad/sec^2
|
float accel = 1.0; // Rad/sec^2
|
||||||
Color color{16, 16, 16};
|
Color color{0x80, 0x80, 0x80};
|
||||||
uint8_t pictogram;
|
uint8_t pictogram{};
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class MoveType {
|
enum class MoveType {
|
||||||
@@ -51,7 +51,12 @@ struct MoveCommand {
|
|||||||
MoveType type;
|
MoveType type;
|
||||||
uint8_t pos;
|
uint8_t pos;
|
||||||
};
|
};
|
||||||
|
struct PictoIllumCommand {
|
||||||
|
uint8_t pos; // 0 for none / Valid indexes 1 .. 6
|
||||||
|
};
|
||||||
|
|
||||||
static fos::Queue<MoveCommand> commandQueue(8);
|
static fos::Queue<MoveCommand> commandQueue(8);
|
||||||
|
static fos::Queue<PictoIllumCommand> pictoIllumQue(2);
|
||||||
|
|
||||||
DeviceState activeState;
|
DeviceState activeState;
|
||||||
static const char *TAG = "Watch";
|
static const char *TAG = "Watch";
|
||||||
@@ -83,6 +88,19 @@ void getConfig(Cli::CArgs args) {
|
|||||||
pShell->write(key + ": " + val + "\n");
|
pShell->write(key + ": " + val + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testPictoIllum(Cli::CArgs args) {
|
||||||
|
if (args.size() != 1) {
|
||||||
|
pShell->write("Needs position argument for illuminated position 0 for off, 1..6 for pictograms'\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
int p = std::stoi(args[0]);
|
||||||
|
pictoIllumQue.enqueue(std::make_unique<PictoIllumCommand>(p));
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
ESP_LOGI(TAG, "Failed to parse %s and %s", args[0].c_str(), args[1].c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setConfig(Cli::CArgs args) {
|
void setConfig(Cli::CArgs args) {
|
||||||
if (args.size() != 2) {
|
if (args.size() != 2) {
|
||||||
pShell->write("Needs string key and value'\n");
|
pShell->write("Needs string key and value'\n");
|
||||||
@@ -180,6 +198,10 @@ static void telnetSocketTask(int addrFamily) {
|
|||||||
pShell->addBinding(
|
pShell->addBinding(
|
||||||
{"move", "start movement (profile-idx,steps) as integers ",
|
{"move", "start movement (profile-idx,steps) as integers ",
|
||||||
[](Cli::CArgs a) { triggerMovement(a); }});
|
[](Cli::CArgs a) { triggerMovement(a); }});
|
||||||
|
|
||||||
|
pShell->addBinding(
|
||||||
|
{"tstIllum", "test illumination command 0=off /1..6",
|
||||||
|
[](Cli::CArgs a) { testPictoIllum(a); }});
|
||||||
},
|
},
|
||||||
[](TcpSession &session) {
|
[](TcpSession &session) {
|
||||||
pShell->process();
|
pShell->process();
|
||||||
@@ -233,13 +255,10 @@ static void UniverseCallback(const uint8_t *data, const uint16_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void moveToSubs(std::string data) {
|
void moveToSubs(std::string data) {
|
||||||
// Syslog::logv(Syslog::Severity::Notice,
|
|
||||||
// "Running Stepper by %i steps with prof=%i a=%.2f w=%.2f",
|
|
||||||
// delta, profile, activeState.accel, activeState.speed);
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "MoveTo command '%s'", data.c_str());
|
ESP_LOGI(TAG, "MoveTo command '%s'", data.c_str());
|
||||||
try {
|
try {
|
||||||
int p = std::stoi(data);
|
int p = std::stoi(data);
|
||||||
|
Syslog::logv(Syslog::Severity::Informational, "got MoveTo-Cmd->%i", p);
|
||||||
commandQueue.enqueue(std::make_unique<MoveCommand>(MoveType::StepTo, p));
|
commandQueue.enqueue(std::make_unique<MoveCommand>(MoveType::StepTo, p));
|
||||||
auto &client = MqttClient::getInstance();
|
auto &client = MqttClient::getInstance();
|
||||||
client.publish("watch/inPosition", data + "Picto");
|
client.publish("watch/inPosition", data + "Picto");
|
||||||
@@ -252,6 +271,7 @@ void startShuffle(std::string data) {
|
|||||||
ESP_LOGI(TAG, "StartShuffle command %s", data.c_str());
|
ESP_LOGI(TAG, "StartShuffle command %s", data.c_str());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Syslog::logv(Syslog::Severity::Informational, "got Shuffle-Command");
|
||||||
commandQueue.enqueue(std::make_unique<MoveCommand>(MoveType::Shuffle, 0));
|
commandQueue.enqueue(std::make_unique<MoveCommand>(MoveType::Shuffle, 0));
|
||||||
auto &client = MqttClient::getInstance();
|
auto &client = MqttClient::getInstance();
|
||||||
client.publish("watch/changingPosition", "....");
|
client.publish("watch/changingPosition", "....");
|
||||||
@@ -419,7 +439,7 @@ void LightingTask() {
|
|||||||
// static PmwExpanderPca9685 pca9685(master);
|
// static PmwExpanderPca9685 pca9685(master);
|
||||||
static PmwExpanderPca9685 ledDriver1(master, /*iverted=*/false);
|
static PmwExpanderPca9685 ledDriver1(master, /*iverted=*/false);
|
||||||
static PmwExpanderPca9685 ledDriver2(master, /*iverted=*/false, 0x41);
|
static PmwExpanderPca9685 ledDriver2(master, /*iverted=*/false, 0x41);
|
||||||
PmwExpanderPca9685::GrayValues values[2];
|
PmwExpanderPca9685::GrayValues values[2]{};
|
||||||
|
|
||||||
OutputPort pwmEnable(GPIO_NUM_1, GpioPort::Logic::Inverted);
|
OutputPort pwmEnable(GPIO_NUM_1, GpioPort::Logic::Inverted);
|
||||||
pwmEnable.write(true);
|
pwmEnable.write(true);
|
||||||
@@ -432,35 +452,62 @@ void LightingTask() {
|
|||||||
Effect::EffectProcessor(8),
|
Effect::EffectProcessor(8),
|
||||||
Effect::EffectProcessor(8),
|
Effect::EffectProcessor(8),
|
||||||
Effect::EffectProcessor(8)};
|
Effect::EffectProcessor(8)};
|
||||||
processors[0].setEffect(Effect::macDemoStart, &colorSource, 16);
|
processors[0].setEffect(Effect::macDark, &colorSource, 0);
|
||||||
processors[1].setEffect(Effect::macDemoStart, &colorSource, 32);
|
processors[1].setEffect(Effect::macDark, &colorSource, 0);
|
||||||
processors[2].setEffect(Effect::macDemoPulse, &colorSource, 48);
|
processors[2].setEffect(Effect::macDark, &colorSource, 0);
|
||||||
processors[3].setEffect(Effect::macDemoPulse, &colorSource, 64);
|
processors[3].setEffect(Effect::macDark, &colorSource, 0);
|
||||||
processors[4].setEffect(Effect::macStartFlicker, &colorSource, 80);
|
processors[4].setEffect(Effect::macDark, &colorSource, 0);
|
||||||
processors[5].setEffect(Effect::macStartIdle, &colorSource, 96);
|
processors[5].setEffect(Effect::macDark, &colorSource, 0);
|
||||||
|
|
||||||
// processors[1].setEffect(Effect::macDark, &colorSource, 32);
|
const std::array<Effect::Macro, 6> PictoEffects{
|
||||||
// processors[2].setEffect(Effect::macDark, &colorSource, 48);
|
Effect::macDemoPulse,
|
||||||
// processors[3].setEffect(Effect::macDark, &colorSource, 64);
|
Effect::macDemoPulse,
|
||||||
// processors[4].setEffect(Effect::macDark, &colorSource, 80);
|
Effect::macDemoPulse,
|
||||||
// processors[1].setEffect(Effect::macDemoStart, &colorSource, 32);
|
Effect::macDemoPulse,
|
||||||
// processors[2].setEffect(Effect::macDemoPulse, &colorSource, 48);
|
Effect::macDemoPulse,
|
||||||
// processors[3].setEffect(Effect::macDemoPulse, &colorSource, 64);
|
Effect::macStartFlicker};
|
||||||
// processors[4].setEffect(Effect::macStartFlicker, &colorSource, 80);
|
|
||||||
|
uint8_t lastPicto = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
values[0].fill(0);
|
auto onPos = pictoIllumQue.dequeue(0);
|
||||||
values[1].fill(0);
|
if (onPos) {
|
||||||
|
ESP_LOGI(TAG, "Changing picto-Illum to pos = %i", onPos->pos);
|
||||||
|
ESP_LOGI(TAG, "Current color set r%i g%i b%i ",
|
||||||
|
activeState.color.getRed(), activeState.color.getGreen(), activeState.color.getBlue());
|
||||||
|
auto pos = onPos->pos;
|
||||||
|
if (pos == 0) {
|
||||||
|
Syslog::logv(Syslog::Severity::Informational,
|
||||||
|
"Dimming picto-illum pos:%i ", lastPicto);
|
||||||
|
processors[lastPicto-1].setEffect(Effect::macDark, &colorSource, 0);
|
||||||
|
} else if ((pos >= 1) && (pos <= 6)) {
|
||||||
|
auto idx = pos - 1;
|
||||||
|
Syslog::logv(Syslog::Severity::Informational,
|
||||||
|
"Firing picto-illum pos:%i ", pos);
|
||||||
|
processors[idx].setEffect(PictoEffects[idx], &colorSource, 0);
|
||||||
|
lastPicto = pos;
|
||||||
|
} else {
|
||||||
|
Syslog::logv(Syslog::Severity::Error,
|
||||||
|
"Got invalid index for illuminated pictogram =%i ", pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// values[x][4] = 0x200; // Actually first
|
std::array<uint16_t *, 6> startPoints{
|
||||||
values[0][4] = activeState.color.getRed() * 257;
|
&(values[0][4]),
|
||||||
values[0][5] = activeState.color.getGreen() * 257;
|
&(values[0][8]),
|
||||||
values[0][6] = activeState.color.getBlue() * 257;
|
&(values[0][12]),
|
||||||
|
&(values[1][4]),
|
||||||
// values[1][4] = 0x100; // Actually first
|
&(values[1][8]),
|
||||||
values[1][4] = activeState.color.getRed() * 257;
|
&(values[1][12]),
|
||||||
values[1][5] = activeState.color.getGreen() * 257;
|
};
|
||||||
values[1][6] = activeState.color.getBlue() * 257;
|
for (size_t i = 0; i < processors.size(); i++) {
|
||||||
|
auto col = processors[i].tick();
|
||||||
|
auto sp = startPoints[i];
|
||||||
|
sp[0] = (uint16_t)(col.getWhite()) << 7;
|
||||||
|
sp[1] = (uint16_t)(col.getBlue()) << 7;
|
||||||
|
sp[2] = (uint16_t)(col.getGreen()) << 7;
|
||||||
|
sp[3] = (uint16_t)(col.getRed()) << 7;
|
||||||
|
}
|
||||||
|
|
||||||
ledDriver1.sendImage(values[0]);
|
ledDriver1.sendImage(values[0]);
|
||||||
ledDriver2.sendImage(values[1]);
|
ledDriver2.sendImage(values[1]);
|
||||||
@@ -495,6 +542,8 @@ void MovementTask() {
|
|||||||
ESP_LOGI(TAG, "Fist Position is %f.2", stepper.getScaledPos() * 6);
|
ESP_LOGI(TAG, "Fist Position is %f.2", stepper.getScaledPos() * 6);
|
||||||
fos::Task::delayMs(1000);
|
fos::Task::delayMs(1000);
|
||||||
|
|
||||||
|
activeState.pictogram = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
ESP_LOGD(TAG, "Waiting for command");
|
ESP_LOGD(TAG, "Waiting for command");
|
||||||
auto cmd = commandQueue.dequeue();
|
auto cmd = commandQueue.dequeue();
|
||||||
@@ -537,17 +586,6 @@ void MovementTask() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IoTest() {
|
|
||||||
ESP_LOGI(TAG, "Start IO");
|
|
||||||
InputPort in2(GPIO_NUM_19);
|
|
||||||
OutputPort nReset(GPIO_NUM_9);
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
nReset.write(in2.read());
|
|
||||||
fos::Task::delayMs(100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void app_main(void) {
|
void app_main(void) {
|
||||||
esp_err_t ret = nvs_flash_init();
|
esp_err_t ret = nvs_flash_init();
|
||||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
@@ -557,9 +595,8 @@ void app_main(void) {
|
|||||||
ESP_ERROR_CHECK(ret);
|
ESP_ERROR_CHECK(ret);
|
||||||
initialize_ethernet();
|
initialize_ethernet();
|
||||||
NvsApi::init();
|
NvsApi::init();
|
||||||
// static fos::Task lightingTask(LightingTask, "Lights", 0x4000uL);
|
static fos::Task lightingTask(LightingTask, "Lights", 0x4000uL);
|
||||||
// static fos::Task movementTask(MovementTask, "Motor", 0x4000uL);
|
// static fos::Task movementTask(MovementTask, "Motor", 0x4000uL);
|
||||||
// static fos::Task ioTask(IoTest, "IO", 0x4000uL);
|
|
||||||
|
|
||||||
etherActive.take();
|
etherActive.take();
|
||||||
ESP_LOGI(TAG, "Start net services");
|
ESP_LOGI(TAG, "Start net services");
|
||||||
|
|||||||
Reference in New Issue
Block a user