Skip to content

Commit

Permalink
v0.43
Browse files Browse the repository at this point in the history
- Expose buttons to HA
- HA Switch to control the transition
- Icons are not reloaded if its the same as before

closes #26
  • Loading branch information
Blueforcer authored Mar 30, 2023
2 parents 33647dd + 249074d commit b1f8cc1
Show file tree
Hide file tree
Showing 12 changed files with 407 additions and 137 deletions.
2 changes: 1 addition & 1 deletion docs/icons.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ To download an icon, simply enter the ID of a LaMetric or AWTRIX 2.0 icon in the
AWTRIX 2.0 icons can be found in the respective software. In a future update, non-AWTRIX 2.0 users will also get access to the database.

You can also create your own icon and place it in the "ICONS" folder via the web interface file browser.
The icon needs to be a GIF or JPEG with a resolution of 8x8.
The icon needs to be a GIF (.gif) or JPG (.jpg) with a resolution of 8x8.
12 changes: 0 additions & 12 deletions lib/MatrixUI/MatrixDisplayUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,6 @@ void MatrixDisplayUi::drawApp()
int16_t x, y, x1, y1;
switch (this->appAnimationDirection)
{
case SLIDE_LEFT:
x = -32 * progress;
y = 0;
x1 = x + 32;
y1 = 0;
break;
case SLIDE_RIGHT:
x = 32 * progress;
y = 0;
x1 = x - 32;
y1 = 0;
break;
case SLIDE_UP:
x = 0;
y = -8 * progress;
Expand Down
6 changes: 2 additions & 4 deletions lib/MatrixUI/MatrixDisplayUi.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
enum AnimationDirection
{
SLIDE_UP,
SLIDE_DOWN,
SLIDE_LEFT,
SLIDE_RIGHT
SLIDE_DOWN
};

enum AppState
Expand Down Expand Up @@ -79,7 +77,7 @@ class MatrixDisplayUi
FastLED_NeoMatrix *matrix;

// Values for the Apps
AnimationDirection appAnimationDirection = SLIDE_RIGHT;
AnimationDirection appAnimationDirection = SLIDE_DOWN;

int8_t lastTransitionDirection = 1;

Expand Down
2 changes: 1 addition & 1 deletion lib/home-assistant-integration/src/ArduinoHADefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//#define ARDUINOHA_DEBUG

// These macros allow to exclude some parts of the library to save more resources.
#define EX_ARDUINOHA_BINARY_SENSOR
//#define EX_ARDUINOHA_BINARY_SENSOR
//#define EX_ARDUINOHA_BUTTON
#define EX_ARDUINOHA_CAMERA
#define EX_ARDUINOHA_COVER
Expand Down
106 changes: 106 additions & 0 deletions src/Dictionary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include <Arduino.h>
#include "Dictionary.h"

// MQTT
const char StatsTopic[] PROGMEM = {"stats"};
const char ButtonLeftTopic[] PROGMEM = {"stats/buttonLeft"};
const char ButtonSelectTopic[] PROGMEM = {"stats/buttonSelect"};
const char ButtonRightTopic[] PROGMEM = {"stats/buttonRight"};

// Generic
const char State0[] PROGMEM = {"0"};
const char State1[] PROGMEM = {"1"};

// HA
const char HAmanufacturer[] PROGMEM = {"Blueforcer"};
const char HAmodel[] PROGMEM = {"AWTRIX Light"};
const char HAmatID[] PROGMEM = {"%s_mat"};
const char HAmatIcon[] PROGMEM = {"mdi:lightbulb"};
const char HAmatName[] PROGMEM = {"Matrix"};
const char HAbriID[] PROGMEM = {"%s_bri"};
const char HAbriIcon[] PROGMEM = {"mdi:brightness-auto"};
const char HAbriName[] PROGMEM = {"Brightness mode"};
const char HAbriOptions[] PROGMEM = {"Manual;Auto"};

const char HAbtnaID[] PROGMEM = {"%s_btna"};
const char HAbtnaIcon[] PROGMEM = {"mdi:bell-off"};
const char HAbtnaName[] PROGMEM = {"Dismiss notification"};

const char HAbtnbID[] PROGMEM = {"%s_btnb"};
const char HAbtnbIcon[] PROGMEM = {"mdi:arrow-right-bold"};
const char HAbtnbName[] PROGMEM = {"Next app"};

const char HAbtncID[] PROGMEM = {"%s_btnc"};
const char HAbtncIcon[] PROGMEM = {"mdi:arrow-left-bold"};
const char HAbtncName[] PROGMEM = {"Previous app"};

const char HAappID[] PROGMEM = {"%s_app"};
const char HAappIcon[] PROGMEM = {"mdi:apps"};
const char HAappName[] PROGMEM = {"Current app"};

const char HAtempID[] PROGMEM = {"%s_temp"};
const char HAtempIcon[] PROGMEM = {"mdi:thermometer"};
const char HAtempName[] PROGMEM = {"Temperature"};
const char HAtempClass[] PROGMEM = {"temperature"};
const char HAtempUnit[] PROGMEM = {"°C"};

const char HAhumID[] PROGMEM = {"%s_hum"};
const char HAhumIcon[] PROGMEM = {"mdi:water-percent"};
const char HAhumName[] PROGMEM = {"Humidity"};
const char HAhumClass[] PROGMEM = {"humidity"};
const char HAhumUnit[] PROGMEM = {"%"};

const char HAbatID[] PROGMEM = {"%s_bat"};
const char HAbatIcon[] PROGMEM = {"mdi:battery-90"};
const char HAbatName[] PROGMEM = {"Battery"};
const char HAbatClass[] PROGMEM = {"battery"};
const char HAbatUnit[] PROGMEM = {"%"};

const char HAluxID[] PROGMEM = {"%s_lux"};
const char HAluxIcon[] PROGMEM = {"mdi:sun-wireless"};
const char HAluxName[] PROGMEM = {"Illuminance"};
const char HAluxClass[] PROGMEM = {"illuminance"};
const char HAluxUnit[] PROGMEM = {"lx"};

const char HAverID[] PROGMEM = {"%s_ver"};
const char HAverName[] PROGMEM = {"Version"};

const char HAtransID[] PROGMEM = {"%s_tra"};
const char HAtransName[] PROGMEM = {"Transition"};
const char HAtransIcon[] PROGMEM = {"mdi:swap-vertical"};

const char HAsigID[] PROGMEM = {"%s_sig"};
const char HAsigIcon[] PROGMEM = {"mdi:sun-wireless"};
const char HAsigName[] PROGMEM = {"WiFi strength"};
const char HAsigClass[] PROGMEM = {"signal_strength"};
const char HAsigUnit[] PROGMEM = {"dB"};

const char HAupID[] PROGMEM = {"%s_up"};
const char HAupName[] PROGMEM = {"Uptime"};
const char HAupClass[] PROGMEM = {"duration"};

const char HAbtnLID[] PROGMEM = {"%s_btnL"};
const char HAbtnLName[] PROGMEM = {"Button left"};

const char HAbtnMID[] PROGMEM = {"%s_btnM"};
const char HAbtnMName[] PROGMEM = {"Button select"};

const char HAbtnRID[] PROGMEM = {"%s_btnR"};
const char HAbtnRName[] PROGMEM = {"Button right"};

const char HAramRID[] PROGMEM = {"%s_ram"};
const char HAramIcon[] PROGMEM = {"mdi:application-cog"};
const char HAramName[] PROGMEM = {"Free ram"};
const char HAramClass[] PROGMEM = {"data_size"};
const char HAramUnit[] PROGMEM = {"B"};

// JSON properites
const char BatKey[] PROGMEM = {"bat"};
const char BatRawKey[] PROGMEM = {"bat_raw"};
const char LuxKey[] PROGMEM = {"lux"};
const char LDRRawKey[] PROGMEM = {"ldr_raw"};
const char BrightnessKey[] PROGMEM = {"bri"};
const char TempKey[] PROGMEM = {"temp"};
const char HumKey[] PROGMEM = {"hum"};
const char UpTimeKey[] PROGMEM = {"uptime"};
const char SignalStrengthKey[] PROGMEM = {"wifi_signal"};
108 changes: 108 additions & 0 deletions src/Dictionary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#ifndef DICTIONARY_H
#define DICTIONARY_H

// MQTT
extern const char StatsTopic[];
extern const char ButtonLeftTopic[];
extern const char ButtonSelectTopic[];
extern const char ButtonRightTopic[];

// Generic
extern const char State0[];
extern const char State1[];

// HA
extern const char HAmanufacturer[];
extern const char HAmodel[];
extern const char HAmatID[];
extern const char HAmatIcon[];
extern const char HAmatName[];
extern const char HAbriID[];
extern const char HAbriIcon[];
extern const char HAbriName[];
extern const char HAbriOptions[];

extern const char HAbtnaID[];
extern const char HAbtnaIcon[];
extern const char HAbtnaName[];

extern const char HAbtnbID[];
extern const char HAbtnbIcon[];
extern const char HAbtnbName[];

extern const char HAbtncID[];
extern const char HAbtncIcon[];
extern const char HAbtncName[];

extern const char HAappID[];
extern const char HAappIcon[];
extern const char HAappName[];

extern const char HAtempID[];
extern const char HAtempIcon[];
extern const char HAtempName[];
extern const char HAtempClass[];
extern const char HAtempUnit[];

extern const char HAhumID[];
extern const char HAhumIcon[];
extern const char HAhumName[];
extern const char HAhumClass[];
extern const char HAhumUnit[];

extern const char HAbatID[];
extern const char HAbatIcon[];
extern const char HAbatName[];
extern const char HAbatClass[];
extern const char HAbatUnit[];

extern const char HAluxID[];
extern const char HAluxIcon[];
extern const char HAluxName[];
extern const char HAluxClass[];
extern const char HAluxUnit[];

extern const char HAverID[];
extern const char HAverName[];

extern const char HAsigID[];
extern const char HAsigIcon[];
extern const char HAsigName[];
extern const char HAsigClass[];
extern const char HAsigUnit[];

extern const char HAupID[];
extern const char HAupName[];
extern const char HAupClass[];

extern const char HAtransID[];
extern const char HAtransName[];
extern const char HAtransIcon[];

extern const char HAbtnLID[];
extern const char HAbtnLName[];

extern const char HAbtnMID[];
extern const char HAbtnMName[];

extern const char HAbtnRID[];
extern const char HAbtnRName[];

extern const char HAramRID[];
extern const char HAramIcon[];
extern const char HAramName[];
extern const char HAramClass[];
extern const char HAramUnit[];

// JSON properites
extern const char BatKey[];
extern const char BatRawKey[];
extern const char LuxKey[];
extern const char LDRRawKey[];
extern const char BrightnessKey[];
extern const char TempKey[];
extern const char HumKey[];
extern const char UpTimeKey[];
extern const char SignalStrengthKey[];

#endif
33 changes: 22 additions & 11 deletions src/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void DisplayManager_::MatrixState(bool on)

bool DisplayManager_::setAutoTransition(bool active)
{

if (ui.AppCount < 2)
{
ui.disablesetAutoTransition();
Expand Down Expand Up @@ -260,6 +261,11 @@ void DisplayManager_::generateCustomPage(String name, String payload)

CustomApp customApp;

if (customApps.find(name) != customApps.end())
{
customApp = customApps[name];
}

if (doc.containsKey("sound"))
{
customApp.sound = ("/" + doc["sound"].as<String>() + ".txt");
Expand Down Expand Up @@ -308,21 +314,26 @@ void DisplayManager_::generateCustomPage(String name, String payload)
if (doc.containsKey("icon"))
{
String iconFileName = String(doc["icon"].as<String>());

if (LittleFS.exists("/ICONS/" + iconFileName + ".jpg"))
{
customApp.isGif = false;
customApp.icon = LittleFS.open("/ICONS/" + iconFileName + ".jpg");
}
else if (LittleFS.exists("/ICONS/" + iconFileName + ".gif"))
if (customApp.icon && String(customApp.icon.name()).startsWith(iconFileName))
{
customApp.isGif = true;
customApp.icon = LittleFS.open("/ICONS/" + iconFileName + ".gif");
}
else
{
fs::File nullPointer;
customApp.icon = nullPointer;
if (LittleFS.exists("/ICONS/" + iconFileName + ".jpg"))
{
customApp.isGif = false;
customApp.icon = LittleFS.open("/ICONS/" + iconFileName + ".jpg");
}
else if (LittleFS.exists("/ICONS/" + iconFileName + ".gif"))
{
customApp.isGif = true;
customApp.icon = LittleFS.open("/ICONS/" + iconFileName + ".gif");
}
else
{
fs::File nullPointer;
customApp.icon = nullPointer;
}
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ IPAddress gateway;
IPAddress subnet;
IPAddress primaryDNS;
IPAddress secondaryDNS;
const char *VERSION = "0.42";
const char *VERSION = "0.43";
String MQTT_HOST = "";
uint16_t MQTT_PORT = 1883;
String MQTT_USER;
Expand Down
Loading

0 comments on commit b1f8cc1

Please sign in to comment.