Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
computergeek1507 committed Aug 7, 2023
1 parent bdb7538 commit bfc8de4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
4 changes: 2 additions & 2 deletions tasmota/include/tasmota_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ enum UserSelectablePins {
GPIO_OPTION_E, // Emulated module
GPIO_SDM230_TX, GPIO_SDM230_RX, // SDM230 Serial interface
GPIO_ADC_MQ, // Analog MQ Sensor
GPIO_ADC_WIND_DIR, // Analog Wind Direction
GPIO_CM11_TXD, GPIO_CM11_RXD, // CM11 Serial interface
GPIO_BL6523_TX, GPIO_BL6523_RX, // BL6523 based Watt meter Serial interface
GPIO_ADE7880_IRQ, // ADE7880 IRQ
Expand Down Expand Up @@ -212,6 +211,7 @@ enum UserSelectablePins {
GPIO_LOX_O2_RX, // LOX-O2 RX
GPIO_GM861_TX, GPIO_GM861_RX, // GM861 Serial interface
GPIO_DINGTIAN_OE, // New version of Dingtian relay board where PL is not shared with OE
GPIO_ADC_WIND_DIR, // Analog Wind Direction
GPIO_SENSOR_END };

// Error as warning to rethink GPIO usage with max 2045
Expand Down Expand Up @@ -435,7 +435,6 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_OPTION " E|"
D_SENSOR_SDM230_TX "|" D_SENSOR_SDM230_RX "|"
D_SENSOR_ADC_MQ "|"
D_SENSOR_ADC_WIND_DIR "|"
D_SENSOR_CM11_TX "|" D_SENSOR_CM11_RX "|"
D_SENSOR_BL6523_TX "|" D_SENSOR_BL6523_RX "|"
D_SENSOR_ADE7880_IRQ "|"
Expand Down Expand Up @@ -471,6 +470,7 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_LOX_O2_RX "|"
D_SENSOR_GM861_TX "|" D_SENSOR_GM861_RX "|"
D_GPIO_DINGTIAN_OE "|"
D_SENSOR_ADC_WIND_DIR "|"
;

const char kSensorNamesFixed[] PROGMEM =
Expand Down
66 changes: 39 additions & 27 deletions tasmota/tasmota_xsns_sensor/xsns_02_analog.ino
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@
// lenght of filter
#define ANALOG_MQ_SAMPLES 60

const char Wind_ADC_Directions[8][3] = {
{D_TX20_NORTH},
{D_TX20_NORTH_EAST},
{D_TX20_EAST},
{D_TX20_SOUTH_EAST},
{D_TX20_SOUTH},
{D_TX20_SOUTH_WEST},
{D_TX20_WEST}
{D_TX20_NORTH_WEST}};

struct {
uint8_t present = 0;
uint8_t type = 0;
Expand Down Expand Up @@ -715,36 +725,38 @@ void AdcShow(bool json) {
float dir_val = analog * ANALOG_V33 / ANALOG_RANGE;
char dir_chr[FLOATSZ];
dtostrfd(dir_val, 2, dir_chr);
String wind_chr = D_ERROR;

if(dir_val > 2.50 && dir_val < 2.70 ) {
wind_chr = D_TX20_NORTH;
}
if(dir_val > 1.30 && dir_val < 1.70 ) {
wind_chr = D_TX20_NORTH D_TX20_EAST;
}
if(dir_val > 0.20 && dir_val < 0.40 ) {
wind_chr = D_TX20_EAST;
}
if(dir_val > 0.50 && dir_val < 0.74 ) {
wind_chr = D_TX20_SOUTH D_TX20_EAST;
uint8_t dir_idx = 0;
uint16_t dir_degrees = 0;
if(dir_val > 3.00 ) {
dir_idx = 6;
dir_degrees = 270;
} else if(dir_val > 2.8 ) {
dir_idx = 7;
dir_degrees = 315;
} else if(dir_val > 2.50 ) {
dir_idx = 0;
dir_degrees = 0;
} else if(dir_val > 2.00 ) {
dir_idx = 5;
dir_degrees = 225;
} else if(dir_val > 1.30 ) {
dir_idx = 1;
dir_degrees = 45;
} else if(dir_val > 0.75 && dir_val < 1.20 ) {
dir_idx = 4;
dir_degrees = 180;
} else if(dir_val > 0.50 && dir_val < 0.74 ) {
dir_idx = 3;
dir_degrees = 135;
} else if(dir_val > 0.20 && dir_val < 0.40 ) {
dir_idx = 2;
dir_degrees = 90;
}
if(dir_val > 0.75 && dir_val < 1.20 ) {
wind_chr = D_TX20_SOUTH;
}
if(dir_val > 2.00 && dir_val < 2.20 ) {
wind_chr = D_TX20_SOUTH D_TX20_WEST;
}
if(dir_val > 3.00 && dir_val < 3.25 ) {
wind_chr = D_TX20_WEST;
}
if(dir_val > 2.8 && dir_val < 2.99 ) {
wind_chr = D_TX20_NORTH D_TX20_WEST;
}

String wind_chr = Wind_ADC_Directions[dir_idx];
if (json) {
AdcShowContinuation(&jsonflg);
ResponseAppend_P(PSTR("\"WINDDIRECTION%d\":\"%s\",\"WINDADC%d\":%s"), idx + offset, wind_chr.c_str(), idx + offset, dir_chr);
ResponseAppend_P(PSTR("\"WINDDIRECTION%d\":\"%s\",\"WINDDEGREES%d\":%d,\"WINDADC%d\":%s"),
idx + offset, wind_chr.c_str(), idx + offset, dir_degrees, idx + offset, dir_chr);
#ifdef USE_WEBSERVER
} else {
WSContentSend_PD(HTTP_SNS_WIND_DIRECTION, "", wind_chr.c_str());
Expand Down

0 comments on commit bfc8de4

Please sign in to comment.