Skip to content

Commit

Permalink
ESP-DASH Pro NG
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Nov 28, 2024
1 parent 58e8d90 commit ad2a2fc
Show file tree
Hide file tree
Showing 17 changed files with 969 additions and 924 deletions.
5 changes: 3 additions & 2 deletions include/YaSolR.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ extern Mycila::RouterRelay routerRelay2;
extern Mycila::TrafficLight lights;

extern Mycila::TaskManager coreTaskManager;
extern Mycila::Task dashboardTask;
extern Mycila::Task dashboardInitTask;
extern Mycila::Task dashboardUpdateTask;
extern Mycila::Task debugTask;
extern Mycila::Task networkConfigTask;
extern Mycila::Task networkManagerTask;
Expand Down Expand Up @@ -128,7 +129,7 @@ extern Mycila::Task routingTask;
extern Mycila::Task bootTask;
extern Mycila::Task initConfigTask;
extern Mycila::Task initCoreTask;
extern Mycila::Task initDashboardCards;
extern Mycila::Task initDashboard;
extern Mycila::Task initEventsTask;
extern Mycila::Task initLoggingTask;
extern Mycila::Task initMqttSubscribersTask;
Expand Down
24 changes: 13 additions & 11 deletions include/YaSolRDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,27 @@
#define YASOLR_ADMIN_USERNAME "admin"
#define YASOLR_DISPLAY_LINE_SIZE 21
#define YASOLR_DISPLAY_LINES 5
#define YASOLR_GRAPH_POINTS 120
#define YASOLR_HIDDEN_PWD "********"
#define YASOLR_MQTT_KEEPALIVE 60
#define YASOLR_MQTT_MEASUREMENT_EXPIRATION 60000
#define YASOLR_MQTT_SERVER_CERT_FILE "/mqtt-server.pem"
#define YASOLR_MQTT_WILL_TOPIC "/status"
#define YASOLR_PID_D_MODE_1 YASOLR_PID_P_MODE_1
#define YASOLR_PID_D_MODE_2 YASOLR_PID_P_MODE_2
#define YASOLR_PID_IC_MODE_0 "0: Off"
#define YASOLR_PID_IC_MODE_1 "1: Clamp"
#define YASOLR_PID_IC_MODE_2 "2: Advanced"
#define YASOLR_PID_P_MODE_1 "1: On Error"
#define YASOLR_PID_P_MODE_2 "2: On Input"
#define YASOLR_PID_P_MODE_3 "3: Both"
#define YASOLR_PZEM_ADDRESS_OUTPUT1 0x01
#define YASOLR_PZEM_ADDRESS_OUTPUT2 0x02
#define YASOLR_RELAY_TYPE_NC "NC"
#define YASOLR_RELAY_TYPE_NO "NO"
#define YASOLR_SERIAL_BAUDRATE 115200
#define YASOLR_WEEK_DAYS "sun,mon,tue,wed,thu,fri,sat"
#define YASOLR_GRAPH_POINTS 120
#define YASOLR_PID_P_MODE_1 "1: On Error"
#define YASOLR_PID_P_MODE_2 "2: On Input"
#define YASOLR_PID_P_MODE_3 "3: Both"
#define YASOLR_PID_D_MODE_1 YASOLR_PID_P_MODE_1
#define YASOLR_PID_D_MODE_2 YASOLR_PID_P_MODE_2
#define YASOLR_PID_IC_MODE_0 "0: Off"
#define YASOLR_PID_IC_MODE_1 "1: Clamp"
#define YASOLR_PID_IC_MODE_2 "2: Advanced"
#define YASOLR_MQTT_MEASUREMENT_EXPIRATION 60000
#define YASOLR_MQTT_SERVER_CERT_FILE "/mqtt-server.pem"
#define YASOLR_WEEK_DAYS_EMPTY "none"

// UDP communication

Expand Down
173 changes: 155 additions & 18 deletions include/YaSolRWebsite.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,160 @@ namespace YaSolR {
void resetPID();

private:
void _boolConfig(Card& card, const char* key);
void _daysConfig(Card& card, const char* key);
void _floatConfig(Card& card, const char* key);
void _numConfig(Card& card, const char* key);
void _pinConfig(Card& card, const char* key);
void _passwordConfig(Card& card, const char* key);
void _sliderConfig(Card& card, const char* key);
void _percentageSlider(Card& card, const char* key);
void _textConfig(Card& card, const char* key);

void _outputDimmerSlider(Card& card, Mycila::RouterOutput& output);
void _outputBypassSwitch(Card& card, Mycila::RouterOutput& output);
void _relaySwitch(Card& card, Mycila::RouterRelay& relay);

void _pinout(Card& card, int32_t pin, std::unordered_map<int32_t, Card*>& pinout);
void _status(Card& card, const char* key, bool enabled, bool state = true, const char* err = "");
void _temperature(Card& card, Mycila::DS18& sensor);
void _temperature(Card& card, Mycila::RouterOutput& output);
void _boolConfig(dash::SwitchCard& card, const char* key) {
card.onChange([key, &card, this](bool value) {
config.setBool(key, value);
card.setValue(config.getBool(key) ? 1 : 0);
dashboard.refresh(card);
});
}

void _daysConfig(dash::WeekCard& card, const char* key) {
#ifdef APP_MODEL_PRO
card.onChange([key, &card, this](const char* value) {
config.set(key, value[0] ? value : YASOLR_WEEK_DAYS_EMPTY);
card.setValue(value);
dashboard.refresh(card);
});
#endif
}

template <typename T, std::enable_if_t<std::is_integral_v<T>, bool> = true>
void _numConfig(dash::TextInputCard<T>& card, const char* key) {
#ifdef APP_MODEL_PRO
card.onChange([key, &card](const std::optional<T>& value) {
if (value.has_value()) {
config.set(key, std::to_string(value.value()));
} else {
config.unset(key);
}
card.setValue(static_cast<T>(config.getInt(key)));
dashboard.refresh(card);
});
#endif
}

template <typename T, std::enable_if_t<std::is_integral_v<T>, bool> = true>
void _numConfig(dash::DropdownCard<T>& card, const char* key) {
#ifdef APP_MODEL_PRO
card.onChange([key, &card](const T& value) {
config.set(key, std::to_string(value));
card.setValue(config.getInt(key));
dashboard.refresh(card);
});
#endif
}

void _pinConfig(dash::FeedbackTextInputCard<int32_t>& card, const char* key) {
#ifdef APP_MODEL_PRO
card.onChange([key, &card, this](const std::optional<int32_t> value) {
if (value.has_value()) {
config.set(key, std::to_string(value.value()));
} else {
config.unset(key);
}
card.setValue(config.getInt(key));
initCards();
dashboard.refresh(card);
});
#endif
}

void _passwordConfig(Card& card, const char* key) {
#ifdef APP_MODEL_PRO
card.attachCallback([key, &card, this](const char* value) {
if (value[0]) {
config.set(key, value);
} else {
config.unset(key);
}
card.update(config.isEmpty(key) ? "" : YASOLR_HIDDEN_PWD);
dashboard.refresh(card);
});
#endif
}

template <typename T, std::enable_if_t<std::is_integral_v<T>, bool> = true>
void _sliderConfig(dash::SliderCard<T>& card, const char* key) {
card.onChange([key, &card](const T& value) {
config.set(key, std::to_string(value));
card.setValue(static_cast<T>(config.getInt(key)));
dashboard.refresh(card);
});
}

void _textConfig(Card& card, const char* key) {
#ifdef APP_MODEL_PRO
card.attachCallback([key, &card](const char* value) {
config.set(key, value);
card.update(config.get(key));
dashboard.refresh(card);
});
#endif
}

void _outputDimmerSlider(dash::SliderCard<float, 2>& card, Mycila::RouterOutput& output) {
card.onChange([&card, &output, this](float value) {
if (output.isDimmerEnabled()) {
output.setDimmerDutyCycle(value / 100);
}
card.setValue(output.getDimmerDutyCycle() * 100);
dashboard.refresh(card);
dashboardUpdateTask.requestEarlyRun();
});
}

void _outputBypassSwitch(dash::SwitchCard& card, Mycila::RouterOutput& output) {
card.onChange([&card, &output, this](bool value) {
if (output.isBypassEnabled()) {
output.setBypass(value);
}
card.setValue(output.isBypassOn());
dashboard.refresh(card);
dashboardUpdateTask.requestEarlyRun();
});
}

void _relaySwitch(dash::SwitchCard& card, Mycila::RouterRelay& relay) {
card.onChange([&card, &relay, this](bool value) {
relay.tryRelayState(value);
card.setValue(relay.isOn());
dashboard.refresh(card);
dashboardUpdateTask.requestEarlyRun();
});
}

void _pinout(dash::FeedbackTextInputCard<int32_t>& card, const char* key, std::unordered_map<int32_t, dash::FeedbackTextInputCard<int32_t>*>& pinout) {
int32_t pin = config.getInt(key);
card.setValue(pin);
if (pin == GPIO_NUM_NC) {
card.setFeedback("(" YASOLR_LBL_115 ")", dash::Status::IDLE);
} else if (pinout.find(pin) != pinout.end()) {
pinout[pin]->setFeedback("(" YASOLR_LBL_153 ")", dash::Status::DANGER);
card.setFeedback("(" YASOLR_LBL_153 ")", dash::Status::DANGER);
} else if (!GPIO_IS_VALID_GPIO(pin)) {
pinout[pin] = &card;
card.setFeedback("(" YASOLR_LBL_154 ")", dash::Status::DANGER);
} else if (!GPIO_IS_VALID_OUTPUT_GPIO(pin)) {
pinout[pin] = &card;
card.setFeedback("(" YASOLR_LBL_155 ")", dash::Status::WARNING);
} else {
pinout[pin] = &card;
card.setFeedback("(" YASOLR_LBL_156 ")", dash::Status::SUCCESS);
}
}

void _status(dash::FeedbackSwitchCard& card, const char* key, bool enabled, bool active = true, const char* err = "") {
const bool configEnabled = config.getBool(key);
card.setValue(configEnabled);
if (!configEnabled)
card.setFeedback(YASOLR_LBL_115, dash::Status::IDLE);
else if (!enabled)
card.setFeedback(YASOLR_LBL_124, dash::Status::DANGER);
else if (!active)
card.setFeedback(err, dash::Status::WARNING);
else
card.setFeedback(YASOLR_LBL_130, dash::Status::SUCCESS);
}
};
} // namespace YaSolR
52 changes: 26 additions & 26 deletions include/i18n/en.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
#define YASOLR_LBL_004 "Application: Manufacturer"
#define YASOLR_LBL_005 "Device: Boot Count"
#define YASOLR_LBL_006 "Device: Cores"
#define YASOLR_LBL_007 "Device: Heap Memory Total"
#define YASOLR_LBL_008 "Device: Heap Memory Usage"
#define YASOLR_LBL_009 "Device: Heap Memory Used"
#define YASOLR_LBL_007 "Device: Heap Memory Total (bytes)"
#define YASOLR_LBL_008 "Device: Heap Memory Usage (%)"
#define YASOLR_LBL_009 "Device: Heap Memory Used (bytes)"
#define YASOLR_LBL_010 "Device: ID"
#define YASOLR_LBL_011 "Device: Model"
#define YASOLR_LBL_012 "Device: Revision"
#define YASOLR_LBL_013 "Firmware: Build Hash"
#define YASOLR_LBL_014 "Firmware: Build Timestamp"
#define YASOLR_LBL_015 "Firmware: Filename"
#define YASOLR_LBL_016 "Grid: Energy"
#define YASOLR_LBL_017 "Grid: Energy Returned"
#define YASOLR_LBL_018 "Grid: Frequency"
#define YASOLR_LBL_016 "Grid: Energy (kWh)"
#define YASOLR_LBL_017 "Grid: Energy Returned (kWh)"
#define YASOLR_LBL_018 "Grid: Frequency (Hz)"
#define YASOLR_LBL_019 YASOLR_LBL_087 ": Hostname"
#define YASOLR_LBL_020 YASOLR_LBL_087 ": Interface"
#define YASOLR_LBL_021 YASOLR_LBL_087 ": Access Point IP Address"
Expand All @@ -32,8 +32,8 @@
#define YASOLR_LBL_025 YASOLR_LBL_087 ": WiFi IP Address"
#define YASOLR_LBL_026 YASOLR_LBL_087 ": WiFi MAC Address"
#define YASOLR_LBL_027 YASOLR_LBL_087 ": WiFi SSID"
#define YASOLR_LBL_028 YASOLR_LBL_087 ": WiFi RSSI"
#define YASOLR_LBL_029 YASOLR_LBL_087 ": WiFi Signal"
#define YASOLR_LBL_028 YASOLR_LBL_087 ": WiFi RSSI (dBm)"
#define YASOLR_LBL_029 YASOLR_LBL_087 ": WiFi Signal (%)"
#define YASOLR_LBL_034 "Time"
#define YASOLR_LBL_035 "Uptime"
#define YASOLR_LBL_036 "Routed Power"
Expand Down Expand Up @@ -62,11 +62,11 @@
#define YASOLR_LBL_059 "Energy"
#define YASOLR_LBL_060 YASOLR_LBL_050 " Automatic Control"
#define YASOLR_LBL_061 "Grid Excess Reserved"
#define YASOLR_LBL_062 YASOLR_LBL_050 " Limiter"
#define YASOLR_LBL_063 YASOLR_LBL_050 " " YASOLR_LBL_048 " Limiter"
#define YASOLR_LBL_062 YASOLR_LBL_050 " Power Limiter"
#define YASOLR_LBL_063 YASOLR_LBL_050 " " YASOLR_LBL_048 " Limiter (°C)"
#define YASOLR_LBL_064 "Bypass Automatic Control"
#define YASOLR_LBL_065 "Bypass Start " YASOLR_LBL_048
#define YASOLR_LBL_066 "Bypass Stop " YASOLR_LBL_048
#define YASOLR_LBL_065 "Bypass Start " YASOLR_LBL_048 " (°C)"
#define YASOLR_LBL_066 "Bypass Stop " YASOLR_LBL_048 " (°C)"
#define YASOLR_LBL_067 "Bypass Start Time"
#define YASOLR_LBL_068 "Bypass Stop Time"
#define YASOLR_LBL_069 "Bypass Week Days"
Expand Down Expand Up @@ -124,7 +124,7 @@
#define YASOLR_LBL_120 "LED Yellow"
#define YASOLR_LBL_121 "PZEM (TX) Serial RX"
#define YASOLR_LBL_122 "PZEM (RX) Serial TX"
#define YASOLR_LBL_123 "Pending"
// #define YASOLR_LBL_123 "Pending"
#define YASOLR_LBL_124 "Not started"
#define YASOLR_LBL_125 "Zero-Cross Detection"
#define YASOLR_LBL_126 "Hardware"
Expand All @@ -140,10 +140,10 @@
#define YASOLR_LBL_138 YASOLR_LBL_070 " Relay (Bypass)"
#define YASOLR_LBL_139 "Router DS18"
#define YASOLR_LBL_140 YASOLR_LBL_126 " Config"
#define YASOLR_LBL_141 "Nominal Grid Frequency"
#define YASOLR_LBL_141 "Nominal Grid Frequency (Hz)"
#define YASOLR_LBL_142 YASOLR_LBL_127 " Speed"
#define YASOLR_LBL_143 YASOLR_LBL_127 " Type"
#define YASOLR_LBL_144 YASOLR_LBL_127 " Rotation"
#define YASOLR_LBL_144 YASOLR_LBL_127 " Rotation (°)"
#define YASOLR_LBL_145 YASOLR_LBL_046 " Resistance (Ω)"
#define YASOLR_LBL_146 YASOLR_LBL_070 " Resistance (Ω)"
#define YASOLR_LBL_147 YASOLR_LBL_046 " PZEM Pairing"
Expand All @@ -156,7 +156,7 @@
#define YASOLR_LBL_154 "Invalid"
#define YASOLR_LBL_155 "Input Only"
#define YASOLR_LBL_156 "I/O"
#define YASOLR_LBL_157 YASOLR_LBL_128 " Remote UDP: Message Rate"
#define YASOLR_LBL_157 YASOLR_LBL_128 " Remote UDP (msg/s)"
#define YASOLR_LBL_158 "Grid Excess Remaining"
#define YASOLR_LBL_159 "PID Controller"
#define YASOLR_LBL_160 "Proportional Mode"
Expand Down Expand Up @@ -184,9 +184,9 @@
#define YASOLR_LBL_182 YASOLR_LBL_070 " " YASOLR_LBL_048 " MQTT Topic"
#define YASOLR_LBL_183 YASOLR_LBL_046 " Dimmer Min/Max Remapping"
#define YASOLR_LBL_184 YASOLR_LBL_070 " Dimmer Min/Max Remapping"
#define YASOLR_LBL_185
// #define YASOLR_LBL_185
#define YASOLR_LBL_186 "Resistance Value Detection"
#define YASOLR_LBL_187
// #define YASOLR_LBL_187
#define YASOLR_LBL_030 "Relay: " YASOLR_LBL_046 " Bypass Relay Switch Count"
#define YASOLR_LBL_031 "Relay: " YASOLR_LBL_070 " Bypass Relay Switch Count"
#define YASOLR_LBL_032 "Relay: " YASOLR_LBL_074 " Switch Count"
Expand All @@ -196,11 +196,11 @@
#define YASOLR_LBL_190 "Gateway"
#define YASOLR_LBL_191 "DNS Server"
#define YASOLR_LBL_192 "Device: Reboot Reason"
#define YASOLR_LBL_193
#define YASOLR_LBL_194
#define YASOLR_LBL_195
#define YASOLR_LBL_196
#define YASOLR_LBL_197
#define YASOLR_LBL_198
#define YASOLR_LBL_199
#define YASOLR_LBL_200
// #define YASOLR_LBL_193
// #define YASOLR_LBL_194
// #define YASOLR_LBL_195
// #define YASOLR_LBL_196
// #define YASOLR_LBL_197
// #define YASOLR_LBL_198
// #define YASOLR_LBL_199
// #define YASOLR_LBL_200
Loading

0 comments on commit ad2a2fc

Please sign in to comment.