Skip to content

Commit

Permalink
Add step_delay option to X9C component (esphome#6890)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverhihn authored Jun 12, 2024
1 parent 2044c7e commit df52bc3
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions esphome/components/x9c/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
CONF_INC_PIN,
CONF_UD_PIN,
CONF_INITIAL_VALUE,
CONF_STEP_DELAY,
)

CODEOWNERS = ["@EtienneMD"]
Expand All @@ -26,6 +27,7 @@
cv.Optional(CONF_INITIAL_VALUE, default=1.0): cv.float_range(
min=0.01, max=1.0
),
cv.Optional(CONF_STEP_DELAY, default=1): cv.int_range(min=1, max=100),
}
)
)
Expand All @@ -44,3 +46,4 @@ async def to_code(config):
cg.add(var.set_ud_pin(ud_pin))

cg.add(var.set_initial_value(config[CONF_INITIAL_VALUE]))
cg.add(var.set_step_delay(config[CONF_STEP_DELAY]))
5 changes: 3 additions & 2 deletions esphome/components/x9c/x9c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ void X9cOutput::trim_value(int change_amount) {

for (int i = 0; i < abs(change_amount); i++) { // Move wiper
this->inc_pin_->digital_write(true);
delayMicroseconds(1);
delayMicroseconds(this->step_delay_);
this->inc_pin_->digital_write(false);
delayMicroseconds(1);
delayMicroseconds(this->step_delay_);
}

delayMicroseconds(100); // Let value settle
Expand Down Expand Up @@ -69,6 +69,7 @@ void X9cOutput::dump_config() {
LOG_PIN(" Increment Pin: ", this->inc_pin_);
LOG_PIN(" Up/Down Pin: ", this->ud_pin_);
ESP_LOGCONFIG(TAG, " Initial Value: %f", this->initial_value_);
ESP_LOGCONFIG(TAG, " Step Delay: %d", this->step_delay_);
LOG_FLOAT_OUTPUT(this);
}

Expand Down
2 changes: 2 additions & 0 deletions esphome/components/x9c/x9c.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class X9cOutput : public output::FloatOutput, public Component {
void set_inc_pin(InternalGPIOPin *pin) { inc_pin_ = pin; }
void set_ud_pin(InternalGPIOPin *pin) { ud_pin_ = pin; }
void set_initial_value(float initial_value) { initial_value_ = initial_value; }
void set_step_delay(int step_delay) { step_delay_ = step_delay; }

void setup() override;
void dump_config() override;
Expand All @@ -26,6 +27,7 @@ class X9cOutput : public output::FloatOutput, public Component {
InternalGPIOPin *ud_pin_;
float initial_value_;
float pot_value_;
int step_delay_;
};

} // namespace x9c
Expand Down
1 change: 1 addition & 0 deletions esphome/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@
CONF_STATUS = "status"
CONF_STB_PIN = "stb_pin"
CONF_STEP = "step"
CONF_STEP_DELAY = "step_delay"
CONF_STEP_MODE = "step_mode"
CONF_STEP_PIN = "step_pin"
CONF_STOP = "stop"
Expand Down
1 change: 1 addition & 0 deletions tests/components/x9c/test.esp32-c3-idf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ output:
inc_pin: 4
ud_pin: 5
initial_value: 0.5
step_delay: 50
1 change: 1 addition & 0 deletions tests/components/x9c/test.esp32-c3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ output:
inc_pin: 4
ud_pin: 5
initial_value: 0.5
step_delay: 50
1 change: 1 addition & 0 deletions tests/components/x9c/test.esp32-idf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ output:
inc_pin: 14
ud_pin: 15
initial_value: 0.5
step_delay: 50
1 change: 1 addition & 0 deletions tests/components/x9c/test.esp32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ output:
inc_pin: 14
ud_pin: 15
initial_value: 0.5
step_delay: 50
1 change: 1 addition & 0 deletions tests/components/x9c/test.esp8266.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ output:
inc_pin: 14
ud_pin: 15
initial_value: 0.5
step_delay: 50
1 change: 1 addition & 0 deletions tests/components/x9c/test.rp2040.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ output:
inc_pin: 4
ud_pin: 5
initial_value: 0.5
step_delay: 50

0 comments on commit df52bc3

Please sign in to comment.