Updated pingfuss.yaml and tabletenniscounter.yaml

This commit is contained in:
Nicolas Bachschwell 2024-05-01 12:33:02 +02:00
parent 69851b34ff
commit a837b8494a
Signed by: NBSgamesAT
GPG Key ID: 2D73288FF7AEED2F
4 changed files with 97 additions and 41 deletions

View File

@ -0,0 +1,36 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import mqtt, number
from esphome.const import CONF_ID
ws2812_table_tennis_ns = cg.esphome_ns.namespace('ws2812_table_tennis')
W2812Display = ws2812_table_tennis_ns.class_('CustomNumberDisplayComponent', mqtt.MQTTComponent, cg.Component)
DEPENDENCIES = ['mqtt', 'number']
#CONF_WS2812_PIN = "pin"
#CONF_WS2812_RGB_MODE = "rgb_mode"
CONF_RED_NUM = "red_number"
CONF_BLUE_NUM = "blue_number"
CONFIG_SCHEMA = cv.Schema({
cv.GenerateID(CONF_ID): cv.declare_id(W2812Display),
cv.Required(CONF_RED_NUM): cv.use_id(number.Number),
cv.Required(CONF_BLUE_NUM): cv.use_id(number.Number)
})
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
#yield cg.register_component(var, config)
yield mqtt.register_mqtt_component(var, config)
red = yield cg.get_variable(config[CONF_RED_NUM])
cg.add(var.set_red_number(red))
blue = yield cg.get_variable(config[CONF_BLUE_NUM])
cg.add(var.set_blue_number(blue))
cg.add_library("makuna/NeoPixelBus", "2.7.3")

View File

@ -3,6 +3,9 @@
//#include "multi_effect_handler.h" //#include "multi_effect_handler.h"
#define SEGMENT_LENGTH 5 #define SEGMENT_LENGTH 5
namespace esphome {
namespace ws2812_table_tennis {
class NbsEffect { class NbsEffect {
private: private:
int goalRed = 0, goalGreen = 0, goalBlue = 0; int goalRed = 0, goalGreen = 0, goalBlue = 0;
@ -89,10 +92,10 @@ class NbsEffect {
}; };
NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBangWs2812xMethod> nbsStrip(143, D5); NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBangWs2812xMethod> nbsStrip(143, D5);
class CustomNumberDisplayComponent : public Component, public CustomMQTTDevice { class CustomNumberDisplayComponent : public Component, public mqtt::CustomMQTTDevice {
protected:
const int middleSegment = SEGMENT_LENGTH * 14; const int middleSegment = SEGMENT_LENGTH * 14;
const int transitionLength = 500; // milliseconds const int transitionLength = 500; // milliseconds
const int middleLength = 2; const int middleLength = 2;
const double brightness = 0.17; const double brightness = 0.17;
@ -120,9 +123,22 @@ bool numbers[14][7] = {
{1, 0, 0, 1, 1, 1, 1} // b (13) {1, 0, 0, 1, 1, 1, 1} // b (13)
}; };
template_::TemplateNumber *redNum;
template_::TemplateNumber *blueNum;
public: public:
void set_red_number(template_::TemplateNumber *redNum){
this->redNum = redNum;
}
void set_blue_number(template_::TemplateNumber *blueNum){
this->blueNum = blueNum;
}
void setup() override { void setup() override {
// Segment mapping // Segment mapping
int segPixelCounter = 0; int segPixelCounter = 0;
for(int i = 0; i < 4; ++i){ for(int i = 0; i < 4; ++i){
@ -146,7 +162,7 @@ bool numbers[14][7] = {
// also supports JSON messages // also supports JSON messages
subscribe_json("tabletenniscounter/display/number/command", &CustomNumberDisplayComponent::on_json_message, 2); subscribe_json("tabletenniscounter/display/number/command", &CustomNumberDisplayComponent::on_json_message, 2);
ESP_LOGD("TableTennisCounter", "Ready");
} }
void on_json_message(const std::string &topic, JsonObject root) { void on_json_message(const std::string &topic, JsonObject root) {
@ -183,8 +199,8 @@ bool numbers[14][7] = {
int player1 = root["player1"]; int player1 = root["player1"];
int player2 = root["player2"]; int player2 = root["player2"];
id(red_num).set(player1); redNum->publish_state(player1);
id(blue_num).set(player2); blueNum->publish_state(player2);
bool player1Start = root["player1Start"]; bool player1Start = root["player1Start"];
// do something with Json Object // do something with Json Object
if(player1 > 99) { player1 = 99; } if(player1 > 99) { player1 = 99; }
@ -353,3 +369,5 @@ bool numbers[14][7] = {
} }
}; };
}
}

View File

@ -10,10 +10,11 @@ logger:
# DISABLED - We currently do not need it for operation. Maybe someday # DISABLED - We currently do not need it for operation. Maybe someday
# api: # api:
# password: !secret ttfpassword # encryption:
# key: !secret ttf_key
ota: ota:
password: !secret ttfpassword password: !secret ttf_password
wifi: wifi:
ssid: !secret wifi_ssid ssid: !secret wifi_ssid

View File

@ -2,15 +2,12 @@ esphome:
name: tabletenniscounter name: tabletenniscounter
platform: ESP8266 platform: ESP8266
board: nodemcuv2 board: nodemcuv2
includes:
- cpp-files/tableTennisDisplay.h
libraries:
- "makuna/NeoPixelBus"
custom_component: external_components:
- lambda: |- - source:
auto customNumberDisplay = new CustomNumberDisplayComponent(); type: local
return {customNumberDisplay}; path: external_components/
components: [ ws2812_table_tennis ]
# Enable logging # Enable logging
logger: logger:
@ -19,7 +16,6 @@ ota:
password: !secret ttdpassword password: !secret ttdpassword
api: api:
password: !secret ttdpassword
encryption: encryption:
key: !secret ttdkey key: !secret ttdkey
@ -49,3 +45,8 @@ mqtt:
client_id: "tableTennisCounter" client_id: "tableTennisCounter"
username: !secret mqtt_broker_1_username username: !secret mqtt_broker_1_username
password: !secret mqtt_broker_1_password password: !secret mqtt_broker_1_password
ws2812_table_tennis:
# name: Led Display
red_number: red_num
blue_number: blue_num