cleaned for new home

This commit is contained in:
2025-06-23 12:40:35 +02:00
parent e426efb80f
commit 1f4970c17c
173 changed files with 16228 additions and 24225 deletions

View File

@@ -1,26 +1,5 @@
#include "esphome.h"
// protocol
#define TUYA_COVER_MAX_LEN 640 // Max length of message value
// #define TUYA_COVER_MAX_LEN 256 // Max length of message value
#define TUYA_COVER_BUFFER_LEN 6 // Length of serial buffer for header + type + length
#define TUYA_COVER_HEADER_LEN 2 // Length of fixed header
// enable/disable reversed motor direction
// Normal = header (55AA) + (00060005) + 050100010011 "(55AA00060005050100010011)
// Reversed = header (55AA) + (00060005) + 050100010112 "(55AA00060005050100010112)"
#define TUYA_COVER_DISABLE_REVERSING { 0x69, 0x01, 0x00, 0x01, 0x00 } //dpid = 105, type = bool, len = 1, value = disable
#define TUYA_COVER_ENABLE_REVERSING { 0x69, 0x01, 0x00, 0x01, 0x01 } //dpid = 105, type = bool, len = 1, value = enable
// Curtain commands
// Open = header (55AA) + (00060005) + 6604000100 "(55aa000600056604000100)"
// Close = header (55AA) + (00060005) + 6604000101 "(55aa000600056604000101)"
// Stop = header (55AA) + (00060005) + 6604000102 "(55AA000600056604000102)"
#define TUYA_COVER_OPEN { 0x66, 0x04, 0x00, 0x01, 0x00 } //dpid = 101, type = enum, len = 1, value = OPEN
#define TUYA_COVER_CLOSE { 0x66, 0x04, 0x00, 0x01, 0x01 } //dpid = 101, type = enum, len = 1, value = CLOSE
#define TUYA_COVER_STOP { 0x66, 0x04, 0x00, 0x01, 0x02 } //dpid = 101, type = enum, len = 1, value = STOP
#define TUYA_COVER_SET_POSITION { 0x65, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 } //"65020004000000" //dpid = 2, type = value, len = 4, value = 0x000000 + 1 byte (0x00-0x64)
static const char *TAG = "TUYACOVER";
static const uint16_t TUYA_COVER_HEADER = 0x55AA;
//static const uint16_t TUYA_COVER_VERSION = 0x03;
@@ -71,7 +50,7 @@ enum TUYACOVERdpidType
};
// Variables
TUYACOVERCommand command_{TUYA_COVER_HEADER, TUYA_COVER_VERSION, 0, 0, {}, 0};
//TUYACOVERCommand command_{TUYA_COVER_HEADER, TUYA_COVER_VERSION, 0, 0, {}, 0};
uint8_t uart_buffer_[TUYA_COVER_BUFFER_LEN]{0};
// Forward declarations

View File

@@ -1,6 +1,32 @@
#include <string>
#include <iostream>
std::map<std::string, std::string> moon_icon_map
{
{"first_quarter", "G"},
{"full_moon", "1"},
{"last_quarter", "T"},
{"new_moon", "0"},
{"waning_crescent", "W"},
{"waning_gibbous", "Q"},
{"waxing_crescent", "D"},
{"waxing_gibbous", "J"},
};
std::map<std::string, std::string> moon_description
{
{"first_quarter", "Eerste kwartier"},
{"full_moon", "Volle maan"},
{"last_quarter", "Laatste kwartier"},
{"new_moon", "Nieuwe maan"},
{"waning_crescent", "Afnemende halve maan"},
{"waning_gibbous", "Afnemende maan"},
{"waxing_crescent", "Wassende halve maan"},
{"waxing_gibbous", "Wassende maan"},
};
// Map weather states to MDI characters.
std::map<std::string, std::string> weather_icon_map
@@ -41,64 +67,4 @@ std::map<std::string, std::string> weather_icon_map
// #define ICON_w_clear_night "\U000F0594"
// #define ICON_w_cloudy "\U000F0590"
// #define ICON_w_fog "\U000F0591"
// #define ICON_w_hail "\U000F0592"
// #define ICON_w_lightning "\U000F0593"
// #define ICON_w_lightning_rainy "\U000F067E"
// #define ICON_w_night_partly_cloudy "\U000F0F31"
// #define ICON_w_partly_cloudy "\U000F0595"
// #define ICON_w_pouring "\U000F0596"
// #define ICON_w_rainy "\U000F0597"
// #define ICON_w_snowy "\U000F0F36"
// #define ICON_w_snowy_rainy "\U000F067F"
// #define ICON_w_sunny "\U000F0599"
// #define ICON_w_windy "\U000F059D"
// #define ICON_w_windy_variant "\U000F059E"
// #define ICON_w_exceptional "\U000F0F38"
// std::string conditionToIcon(std::string condition, bool daytime)
// {
// if (condition == "clear") return ICON_w_clear_night;
// if (condition == "clear-night") return ICON_w_clear_night;
// if (condition == "cloudy") return ICON_w_cloudy;
// if (condition == "dust") return ICON_w_fog;
// if (condition == "dusty") return ICON_w_fog;
// if (condition == "fog") return ICON_w_fog;
// if (condition == "frost") return ICON_w_snowy;
// if (condition == "hail") return ICON_w_hail;
// if (condition == "haze") return ICON_w_fog;
// if (condition == "hazy") return ICON_w_fog;
// if (condition == "heavy_shower") return ICON_w_rainy;
// if (condition == "heavy_showers") return ICON_w_rainy;
// if (condition == "light_rain") return ICON_w_rainy;
// if (condition == "light_showers") return ICON_w_rainy;
// if (condition == "light_shower") return ICON_w_rainy;
// if (condition == "lightning") return ICON_w_lightning;
// if (condition == "lightning-rainy") return ICON_w_lightning_rainy;
// if (condition == "mostly_sunny") return ICON_w_sunny;
// if (condition == "night") return ICON_w_clear_night;
// if (condition == "partlycloudy" && !daytime) return ICON_w_night_partly_cloudy;
// if (condition == "partlycloudy" && daytime) return ICON_w_partly_cloudy;
// if (condition == "partly_cloudy" && !daytime) return ICON_w_night_partly_cloudy;
// if (condition == "partly_cloudy" && daytime) return ICON_w_partly_cloudy;
// if (condition == "pouring") return ICON_w_pouring;
// if (condition == "rain") return ICON_w_rainy;
// if (condition == "rainy") return ICON_w_rainy;
// if (condition == "shower") return ICON_w_rainy;
// if (condition == "showers") return ICON_w_rainy;
// if (condition == "snow") return ICON_w_snowy;
// if (condition == "snowy") return ICON_w_snowy;
// if (condition == "snowy-rainy") return ICON_w_snowy_rainy;
// if (condition == "storm") return ICON_w_lightning_rainy;
// if (condition == "storms") return ICON_w_lightning_rainy;
// if (condition == "sunny") return ICON_w_sunny;
// if (condition == "wind") return ICON_w_windy;
// if (condition == "windy") return ICON_w_windy;
// if (condition == "windy-variant") return ICON_w_windy_variant;
// if (condition == "exceptional") return ICON_w_exceptional;
// return "";
// }

View File

@@ -0,0 +1,42 @@
int GetTextBounds(esphome::display::Display* it, esphome::font::Font *font, const char *buffer)
{
int x1 = 0; // A pointer to store the returned x coordinate of the upper left corner in.
int y1 = 0; // A pointer to store the returned y coordinate of the upper left corner in.
int width = 0; // A pointer to store the returned text width in.
int height = 0; // A pointer to store the returned text height in.
it->get_text_bounds(0, 0, buffer, font, TextAlign::TOP_LEFT, &x1, &y1, &width, &height);
return width;
}
int GetTextWidth(esphome::display::Display* it, esphome::font::Font *font, const char* formatting, const char *raw_text){
char temp_buffer[80];
sprintf(temp_buffer, formatting, raw_text);
return GetTextBounds(it, font, temp_buffer);
}
int GetTextWidth(esphome::display::Display* it, esphome::font::Font *font, const char* formatting){
char temp_buffer[80];
sprintf(temp_buffer, formatting);
return GetTextBounds(it, font, temp_buffer);
}
int GetTextWidth(esphome::display::Display* it, esphome::font::Font *font, const char* formatting, float& raw_text){
char temp_buffer[80];
sprintf(temp_buffer, formatting, raw_text);
return GetTextBounds(it, font, temp_buffer);
}
int GetTextWidth(esphome::display::Display* it, esphome::font::Font *font, const char* formatting, float& raw_text1, float& raw_text2){
char temp_buffer[80];
sprintf(temp_buffer, formatting, raw_text1, raw_text2);
return GetTextBounds(it, font, temp_buffer);
}
// Calculate the width of time format
int GetTextWidth(esphome::display::Display* it, esphome::font::Font *font, const char* formatting, esphome::ESPTime time){
auto c_tm = time.to_c_tm();
size_t buffer_length = 80;
char temp_buffer[buffer_length];
strftime(temp_buffer, buffer_length, formatting, &c_tm);
return GetTextBounds(it, font, temp_buffer);
}