diff --git a/SEN0395_distance.h b/SEN0395_distance.h deleted file mode 100644 index b74e80a..0000000 --- a/SEN0395_distance.h +++ /dev/null @@ -1,102 +0,0 @@ -#include "esphome.h" -#include - -class Sen0395Distance : public Component, public UARTDevice { -public: - Sen0395Distance(UARTComponent *parent) : UARTDevice(parent) {} - - float t_snr[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - float t_distance[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - bool t_active[10] = {false, false, false, false, false, false, false, false, false, false}; - - void setup() override { - // nothing to do here - } - - int readline(int readch, char *buffer, int len) { - static int pos = 0; - int rpos; - - if (readch > 0) { - switch (readch) { - case '\n': // Ignore new-lines - break; - case '\r': // Return on CR - rpos = pos; - pos = 0; // Reset position index ready for next time - return rpos; - default: - if (pos < len - 1) { - buffer[pos++] = readch; - buffer[pos] = 0; - } - } - } - // No end of line has been found, so return -1. - return -1; - } - - void loop() override { - const int max_line_length = 40; - static char buffer[max_line_length]; - - while (available()) { - if (readline(read(), buffer, max_line_length) >= 4) { - std::string line = buffer; - - if (line.substr(0, 6) == "$JYRPO") { - std::string vline = line.substr(6); - std::vector v; - for (int i = 0; i < vline.length(); i++) { - if (vline[i] == ',') { - v.push_back(""); - } else { - v.back() += vline[i]; - } - } - int target_count = parse_number(v[0]).value(); - int target_index = parse_number(v[1]).value(); - float target_distance = parse_number(v[2]).value(); - float target_snr = parse_number(v[4]).value(); - - // Update the SNR, distance, and active status for the current target index - t_snr[target_index] = target_snr; - t_distance[target_index] = target_distance; - t_active[target_index] = true; - - if (target_count == target_index) { - // Publish the data for each target without sorting - for (int i = 1; i <= target_count; i++) { - auto get_sensors = App.get_sensors(); - for (int j = 0; j < get_sensors.size(); j++) { - std::string name = get_sensors[j]->get_name(); - if (name == "Target " + std::to_string(i) + " Distance") { - get_sensors[j]->publish_state(t_distance[i]); - } else if (name == "Target " + std::to_string(i) + " SNR") { - get_sensors[j]->publish_state(t_snr[i]); - } - } - } - - // Publish the state of the binary sensor for each target - for (int i = 1; i <= 10; i++) { - auto get_binary_sensors = App.get_binary_sensors(); - for (int j = 0; j < get_binary_sensors.size(); j++) { - std::string name = get_binary_sensors[j]->get_name(); - if (name == "Target " + std::to_string(i) + " Active") { - get_binary_sensors[j]->publish_state(t_active[i]); - } - } - } - - for (int i = target_count + 1; i <= 9; i++) { - t_active[i] = false; - } - - //ESP_LOGD("custom", "Target %d Distance: %f, SNR: %f", i, t_distance[i], t_snr[i]); - } - } - } - } - } -}; \ No newline at end of file diff --git a/components/SEN0395/SEN0395_distance.h b/components/SEN0395/SEN0395_distance.h deleted file mode 100644 index 1cce15c..0000000 --- a/components/SEN0395/SEN0395_distance.h +++ /dev/null @@ -1,102 +0,0 @@ -#include "esphome.h" -#include - -class Sen0395Distance : public Component, public UARTDevice { -public: - Sen0395Distance(UARTComponent *parent) : UARTDevice(parent) {} - - float t_snr[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - float t_distance[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - bool t_active[10] = {false, false, false, false, false, false, false, false, false, false}; - - void setup() override { - // nothing to do here - } - - int readline(int readch, char *buffer, int len) { - static int pos = 0; - int rpos; - - if (readch > 0) { - switch (readch) { - case '\n': // Ignore new-lines - break; - case '\r': // Return on CR - rpos = pos; - pos = 0; // Reset position index ready for next time - return rpos; - default: - if (pos < len - 1) { - buffer[pos++] = readch; - buffer[pos] = 0; - } - } - } - // No end of line has been found, so return -1. - return -1; - } - - void loop() override { - const int max_line_length = 40; - static char buffer[max_line_length]; - - while (available()) { - if (readline(read(), buffer, max_line_length) >= 4) { - std::string line = buffer; - - if (line.substr(0, 6) == "$JYRPO") { - std::string vline = line.substr(6); - std::vector v; - for (int i = 0; i < vline.length(); i++) { - if (vline[i] == ',') { - v.push_back(""); - } else { - v.back() += vline[i]; - } - } - int target_count = parse_number(v[0]).value(); - int target_index = parse_number(v[1]).value(); - float target_distance = parse_number(v[2]).value(); - float target_snr = parse_number(v[4]).value(); - - // Update the SNR, distance, and active status for the current target index - t_snr[target_index] = target_snr; - t_distance[target_index] = target_distance; - t_active[target_index] = true; - - if (target_count == target_index) { - // Publish the data for each target without sorting - for (int i = 1; i <= target_count; i++) { - auto get_sensors = App.get_sensors(); - for (int j = 0; j < get_sensors.size(); j++) { - std::string name = get_sensors[j]->get_name(); - if (name == "Target " + std::to_string(i) + " Distance") { - get_sensors[j]->publish_state(t_distance[i]); - } else if (name == "Target " + std::to_string(i) + " SNR") { - get_sensors[j]->publish_state(t_snr[i]); - } - } - } - - // Publish the state of the binary sensor for each target - for (int i = 1; i <= 10; i++) { - auto get_binary_sensors = App.get_binary_sensors(); - for (int j = 0; j < get_binary_sensors.size(); j++) { - std::string name = get_binary_sensors[j]->get_name(); - if (name == "Target " + std::to_string(i) + " Active") { - get_binary_sensors[j]->publish_state(t_active[i]); - } - } - } - - for (int i = target_count + 1; i <= 9; i++) { - t_active[i] = false; - } - - //ESP_LOGD("custom", "Target %d Distance: %f, SNR: %f", i, t_distance[i], t_snr[i]); - } - } - } - } - } -}; diff --git a/components/SEN0395/__init__.py b/components/SEN0395/__init__.py deleted file mode 100644 index 314b9fa..0000000 --- a/components/SEN0395/__init__.py +++ /dev/null @@ -1 +0,0 @@ -#__init__.py diff --git a/components/SEN0395_distance.h b/components/SEN0395_distance.h deleted file mode 100644 index 1cce15c..0000000 --- a/components/SEN0395_distance.h +++ /dev/null @@ -1,102 +0,0 @@ -#include "esphome.h" -#include - -class Sen0395Distance : public Component, public UARTDevice { -public: - Sen0395Distance(UARTComponent *parent) : UARTDevice(parent) {} - - float t_snr[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - float t_distance[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - bool t_active[10] = {false, false, false, false, false, false, false, false, false, false}; - - void setup() override { - // nothing to do here - } - - int readline(int readch, char *buffer, int len) { - static int pos = 0; - int rpos; - - if (readch > 0) { - switch (readch) { - case '\n': // Ignore new-lines - break; - case '\r': // Return on CR - rpos = pos; - pos = 0; // Reset position index ready for next time - return rpos; - default: - if (pos < len - 1) { - buffer[pos++] = readch; - buffer[pos] = 0; - } - } - } - // No end of line has been found, so return -1. - return -1; - } - - void loop() override { - const int max_line_length = 40; - static char buffer[max_line_length]; - - while (available()) { - if (readline(read(), buffer, max_line_length) >= 4) { - std::string line = buffer; - - if (line.substr(0, 6) == "$JYRPO") { - std::string vline = line.substr(6); - std::vector v; - for (int i = 0; i < vline.length(); i++) { - if (vline[i] == ',') { - v.push_back(""); - } else { - v.back() += vline[i]; - } - } - int target_count = parse_number(v[0]).value(); - int target_index = parse_number(v[1]).value(); - float target_distance = parse_number(v[2]).value(); - float target_snr = parse_number(v[4]).value(); - - // Update the SNR, distance, and active status for the current target index - t_snr[target_index] = target_snr; - t_distance[target_index] = target_distance; - t_active[target_index] = true; - - if (target_count == target_index) { - // Publish the data for each target without sorting - for (int i = 1; i <= target_count; i++) { - auto get_sensors = App.get_sensors(); - for (int j = 0; j < get_sensors.size(); j++) { - std::string name = get_sensors[j]->get_name(); - if (name == "Target " + std::to_string(i) + " Distance") { - get_sensors[j]->publish_state(t_distance[i]); - } else if (name == "Target " + std::to_string(i) + " SNR") { - get_sensors[j]->publish_state(t_snr[i]); - } - } - } - - // Publish the state of the binary sensor for each target - for (int i = 1; i <= 10; i++) { - auto get_binary_sensors = App.get_binary_sensors(); - for (int j = 0; j < get_binary_sensors.size(); j++) { - std::string name = get_binary_sensors[j]->get_name(); - if (name == "Target " + std::to_string(i) + " Active") { - get_binary_sensors[j]->publish_state(t_active[i]); - } - } - } - - for (int i = target_count + 1; i <= 9; i++) { - t_active[i] = false; - } - - //ESP_LOGD("custom", "Target %d Distance: %f, SNR: %f", i, t_distance[i], t_snr[i]); - } - } - } - } - } -}; diff --git a/components/__init__.py b/components/__init__.py deleted file mode 100644 index 8b13789..0000000 --- a/components/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/static/images/sen0395.png b/static/images/sen0395.png new file mode 100644 index 0000000..70dca85 Binary files /dev/null and b/static/images/sen0395.png differ diff --git a/static/images/sen0609.png b/static/images/sen0609.png new file mode 100644 index 0000000..958d075 Binary files /dev/null and b/static/images/sen0609.png differ diff --git a/static/updating.md b/static/updating.md index 8f94687..c0e76ad 100644 --- a/static/updating.md +++ b/static/updating.md @@ -50,7 +50,32 @@ After clicking the "Connect" button, if you do not see a "USB Serial" port liste - + + -