Skip to content

Commit

Permalink
V0.63
Browse files Browse the repository at this point in the history
- Adds third indicator (indeicator 2 is now in the middle)
- Fixes a bug where the Eyes app wasnt reported
  • Loading branch information
Blueforcer committed May 16, 2023
1 parent 10887bc commit 19809ad
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 46 deletions.
3 changes: 2 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ or

## Colored indicators

A colored indicator is like a small notification sign wich will be shown on the upper right or lower right corner.
A colored indicator is like a small notification sign wich will be shown on the upper right (1), right side (2) and lower right corner (3).

| Topic | URL | Payload/Body | HTTP method |
| --- | --- | --- | --- |
| `[PREFIX]/indicator1` | `http://[IP]/api/indicator1` | `{"color":[255,0,0]}` | POST |
| `[PREFIX]/indicator2` | `http://[IP]/api/indicator2` | `{"color":[0,255,0]}` | POST |
| `[PREFIX]/indicator3` | `http://[IP]/api/indicator3` | `{"color":[0,255,0]}` | POST |

Instead of a RGB array you can also sent HEX color strings like `{"color":"#32a852"}`
Send the color black `{"color":[0,0,0]}` or `{"color":"0"}` or a empty payload/body to hide the indicators.
Expand Down
2 changes: 2 additions & 0 deletions src/Apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
static unsigned long lastTime = 0;
void EyesApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer)
{

CURRENT_APP = "Eyes";
if (blinkCountdown < sizeof(blinkIndex) / sizeof(blinkIndex[0]) - 1)
{
matrix->drawRGBBitmap(6 + x, 0 + y, eye[blinkIndex[blinkCountdown]], 8, 8);
Expand Down
6 changes: 5 additions & 1 deletion src/Dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ const char HAi1Icon[] PROGMEM = {"mdi:arrow-top-right-thick"};
const char HAi1Name[] PROGMEM = {"Indicator 1"};

const char HAi2ID[] PROGMEM = {"%s_ind2"};
const char HAi2Icon[] PROGMEM = {"mdi:arrow-bottom-right-thick"};
const char HAi2Icon[] PROGMEM = {"mdi:arrow-right-thick"};
const char HAi2Name[] PROGMEM = {"Indicator 2"};

const char HAi3ID[] PROGMEM = {"%s_ind3"};
const char HAi3Icon[] PROGMEM = {"mdi:arrow-bottom-right-thick"};
const char HAi3Name[] PROGMEM = {"Indicator 3"};

const char HAbriID[] PROGMEM = {"%s_bri"};
const char HAbriIcon[] PROGMEM = {"mdi:brightness-auto"};
const char HAbriName[] PROGMEM = {"Brightness mode"};
Expand Down
4 changes: 4 additions & 0 deletions src/Dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ extern const char HAi2ID[];
extern const char HAi2Icon[];
extern const char HAi2Name[];

extern const char HAi3ID[];
extern const char HAi3Icon[];
extern const char HAi3Name[];

extern const char HAbriID[];
extern const char HAbriIcon[];
extern const char HAbriName[];
Expand Down
86 changes: 64 additions & 22 deletions src/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,7 @@ void DisplayManager_::setIndicator1State(bool state)
ui->setIndicator1State(state);
}


void DisplayManager_::setIndicator2Color(uint16_t color)
{
ui->setIndicator2Color(color);
Expand All @@ -1442,20 +1443,37 @@ void DisplayManager_::setIndicator2State(bool state)
ui->setIndicator2State(state);
}

void DisplayManager_::setIndicator3Color(uint16_t color)
{
ui->setIndicator3Color(color);
}

void DisplayManager_::setIndicator3State(bool state)
{
ui->setIndicator3State(state);
}

void DisplayManager_::indicatorParser(uint8_t indicator, const char *json)
{

if (strcmp(json, "") == 0)
{
if (indicator == 1)
switch (indicator)
{
case 1:
ui->setIndicator1State(false);
MQTTManager.setIndicatorState(1, ui->indicator1State, ui->indicator1Color);
}
else
{
break;
case 2:
ui->setIndicator2State(false);
MQTTManager.setIndicatorState(2, ui->indicator2State, ui->indicator2Color);
break;
case 3:
ui->setIndicator3State(false);
MQTTManager.setIndicatorState(3, ui->indicator3State, ui->indicator3Color);
break;
default:
break;
}
return;
}
Expand All @@ -1473,54 +1491,78 @@ void DisplayManager_::indicatorParser(uint8_t indicator, const char *json)

if (col > 0)
{
if (indicator == 1)
switch (indicator)
{
case 1:
ui->setIndicator1State(true);
ui->setIndicator1Color(col);
}
else
{
break;
case 2:
ui->setIndicator2State(true);
ui->setIndicator2Color(col);
break;
case 3:
ui->setIndicator3State(true);
ui->setIndicator3Color(col);
break;
default:
break;
}
}
else
{
if (indicator == 1)
switch (indicator)
{
case 1:
ui->setIndicator1State(false);
}
else
{
break;
case 2:
ui->setIndicator2State(false);
break;
case 3:
ui->setIndicator3State(false);
break;
default:
break;
}
}
}

if (doc.containsKey("blink"))
{
if (indicator == 1)
switch (indicator)
{
case 1:
ui->setIndicator1Blink(doc["blink"].as<int>());
}
else
{
break;
case 2:
ui->setIndicator2Blink(doc["blink"].as<int>());
break;
case 3:
ui->setIndicator3Blink(doc["blink"].as<int>());
break;
default:
break;
}
}
else
{
if (indicator == 1)
switch (indicator)
{
case 1:
ui->setIndicator1Blink(0);
}
else
{
break;
case 2:
ui->setIndicator2Blink(0);
break;
case 3:
ui->setIndicator3Blink(0);
break;
default:
break;
}
}
MQTTManager.setIndicatorState(1, ui->indicator1State, ui->indicator1Color);
// MQTTManager.setIndicatorState(2, ui->indicator2State, ui->indicator2Color);
MQTTManager.setIndicatorState(indicator, ui->indicator1State, ui->indicator1Color);
}

void DisplayManager_::gammaCorrection()
Expand Down
2 changes: 2 additions & 0 deletions src/DisplayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class DisplayManager_
void setIndicator1State(bool state);
void setIndicator2Color(uint16_t color);
void setIndicator2State(bool state);
void setIndicator3Color(uint16_t color);
void setIndicator3State(bool state);
void reorderApps(const String &jsonString);
void gammaCorrection();
void indicatorParser(uint8_t indicator, const char *json);
Expand Down
2 changes: 1 addition & 1 deletion src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ IPAddress gateway;
IPAddress subnet;
IPAddress primaryDNS;
IPAddress secondaryDNS;
const char *VERSION = "0.62";
const char *VERSION = "0.63";

String MQTT_HOST = "";
uint16_t MQTT_PORT = 1883;
Expand Down
2 changes: 1 addition & 1 deletion src/LookingEyes.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int newX = 9;
int newY = 3;
int dX = 6;
int dY = 0;
int PET_MOOD = 2;
int PET_MOOD = 0;

uint16_t eye[5][64] = {
{0, 0, 65535, 65535, 65535, 65535, 0, 0, 0, 65535, 65535, 65535, 65535, 65535, 65535, 0, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 0, 65535, 65535, 65535, 65535, 65535, 65535, 0, 0, 0, 65535, 65535, 65535, 65535, 0, 0},
Expand Down
41 changes: 39 additions & 2 deletions src/MQTTManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ WiFiClient espClient;
HADevice device;
HAMqtt mqtt(espClient, device, 25);

HALight *Matrix, *Indikator1, *Indikator2 = nullptr;
HALight *Matrix, *Indikator1, *Indikator2, *Indikator3 = nullptr;
HASelect *BriMode = nullptr;
HAButton *dismiss, *nextApp, *prevApp, *doUpdate = nullptr;
HASwitch *transition = nullptr;
Expand All @@ -23,7 +23,7 @@ HASensor *battery = nullptr;
HASensor *temperature, *humidity, *illuminance, *uptime, *strength, *version, *ram, *curApp = nullptr;
HABinarySensor *btnleft, *btnmid, *btnright = nullptr;

char matID[40], ind1ID[40], ind2ID[40], briID[40], btnAID[40], btnBID[40], btnCID[40], appID[40], tempID[40], humID[40], luxID[40], verID[40], ramID[40], upID[40], sigID[40], btnLID[40], btnMID[40], btnRID[40], transID[40], doUpdateID[40], batID[40];
char matID[40], ind1ID[40], ind2ID[40], ind3ID[40], briID[40], btnAID[40], btnBID[40], btnCID[40], appID[40], tempID[40], humID[40], luxID[40], verID[40], ramID[40], upID[40], sigID[40], btnLID[40], btnMID[40], btnRID[40], transID[40], doUpdateID[40], batID[40];

// The getter for the instantiated singleton instance
MQTTManager_ &MQTTManager_::getInstance()
Expand Down Expand Up @@ -97,6 +97,10 @@ void onRGBColorCommand(HALight::RGBColor color, HALight *sender)
{
DisplayManager.setIndicator2Color(((color.red & 0x1F) << 11) | ((color.green & 0x3F) << 5) | (color.blue & 0x1F));
}
else if (sender == Indikator3)
{
DisplayManager.setIndicator3Color(((color.red & 0x1F) << 11) | ((color.green & 0x3F) << 5) | (color.blue & 0x1F));
}
sender->setRGBColor(color); // report color back to the Home Assistant
}

Expand All @@ -109,11 +113,17 @@ void onStateCommand(bool state, HALight *sender)
else if (sender == Indikator1)
{
DisplayManager.setIndicator1State(state);
Serial.println("I1");
}
else if (sender == Indikator2)
{
DisplayManager.setIndicator2State(state);
}
else if (sender == Indikator3)
{
Serial.println("I3");
DisplayManager.setIndicator3State(state);
}
sender->setState(state);
}

Expand Down Expand Up @@ -196,6 +206,7 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length)
delete[] payloadCopy;
return;
}

if (strTopic.equals(MQTT_PREFIX + "/doupdate"))
{
if (UpdateManager.checkUpdate(true))
Expand All @@ -205,6 +216,7 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length)
delete[] payloadCopy;
return;
}

if (strTopic.equals(MQTT_PREFIX + "/power"))
{
StaticJsonDocument<128> doc;
Expand All @@ -222,24 +234,35 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length)
delete[] payloadCopy;
return;
}

if (strTopic.equals(MQTT_PREFIX + "/indicator1"))
{
DisplayManager.indicatorParser(1, payloadCopy);
delete[] payloadCopy;
return;
}

if (strTopic.equals(MQTT_PREFIX + "/indicator2"))
{
DisplayManager.indicatorParser(2, payloadCopy);
delete[] payloadCopy;
return;
}

if (strTopic.equals(MQTT_PREFIX + "/indicator3"))
{
DisplayManager.indicatorParser(3, payloadCopy);
delete[] payloadCopy;
return;
}

if (strTopic.equals(MQTT_PREFIX + "/moodlight"))
{
DisplayManager.moodlight(payloadCopy);
delete[] payloadCopy;
return;
}

if (strTopic.equals(MQTT_PREFIX + "/reboot"))
{
DEBUG_PRINTLN("REBOOT COMMAND RECEIVED")
Expand All @@ -248,12 +271,14 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length)
delete[] payloadCopy;
return;
}

if (strTopic.equals(MQTT_PREFIX + "/sound"))
{
PeripheryManager.parseSound(payloadCopy);
delete[] payloadCopy;
return;
}

if (strTopic.startsWith(MQTT_PREFIX + "/custom"))
{
String topic_str = topic;
Expand Down Expand Up @@ -290,6 +315,7 @@ void onMqttConnected()
"/power",
"/indicator1",
"/indicator2",
"/indicator3",
"/timeformat",
"/dateformat",
"/reboot",
Expand Down Expand Up @@ -378,6 +404,13 @@ void MQTTManager_::setup()
Indikator2->onStateCommand(onStateCommand);
Indikator2->onRGBColorCommand(onRGBColorCommand);

sprintf(ind3ID, HAi3ID, macStr);
Indikator3 = new HALight(ind3ID, HALight::RGBFeature);
Indikator3->setIcon(HAi3Icon);
Indikator3->setName(HAi3Name);
Indikator3->onStateCommand(onStateCommand);
Indikator3->onRGBColorCommand(onRGBColorCommand);

sprintf(briID, HAbriID, macStr);
BriMode = new HASelect(briID);
BriMode->setOptions(HAbriOptions);
Expand Down Expand Up @@ -641,6 +674,10 @@ void MQTTManager_::setIndicatorState(uint8_t indicator, bool state, uint16_t col
Indikator2->setRGBColor(c);
Indikator2->setState(state);
break;
case 3:
Indikator3->setRGBColor(c);
Indikator3->setState(state);
break;
default:
break;
}
Expand Down
Loading

0 comments on commit 19809ad

Please sign in to comment.