Skip to content

Commit

Permalink
Remove pin state reading (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
TillFleisch authored Jan 25, 2024
1 parent ba94c5d commit fb8dd71
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
6 changes: 3 additions & 3 deletions components/philips_power_switch/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ namespace esphome
{
if (should_power_trip_ && millis() - last_power_trip_ > power_trip_delay_ + POWER_TRIP_RETRY_DELAY)
{
if (power_trip_count_ > MAX_POWER_TRIP_COUNT)
if (power_trip_count_ >= MAX_POWER_TRIP_COUNT)
{
should_power_trip_ = false;
ESP_LOGE(TAG, "Power tripping display failed!");
return;
}

// Perform power trip (invert state twice)
power_pin_->digital_write(!power_pin_->digital_read());
power_pin_->digital_write(!(*initial_state_));
delay(power_trip_delay_);
power_pin_->digital_write(!power_pin_->digital_read());
power_pin_->digital_write(*initial_state_);

last_power_trip_ = millis();
power_trip_count_++;
Expand Down
12 changes: 12 additions & 0 deletions components/philips_power_switch/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ namespace esphome
cleaning_ = cleaning;
}

/**
* @brief Sets the initial state reference on this power switch
*
* @param initial_state hub components initial state reference
*/
void set_initial_state(bool *initial_state)
{
initial_state_ = initial_state;
}

/**
* @brief Processes and publish the new switch state.
*/
Expand All @@ -91,6 +101,8 @@ namespace esphome
long last_power_trip_ = 0;
/// @brief nr of power performed power trips
int power_trip_count_ = 0;
/// @brief initial power state reference
bool *initial_state_;
};

} // namespace power_switch
Expand Down
2 changes: 1 addition & 1 deletion components/philips_series_2200/philips_series_2200.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace esphome
{
power_pin_->setup();
power_pin_->pin_mode(gpio::FLAG_OUTPUT);
power_pin_->digital_write(!invert_);
power_pin_->digital_write(initial_pin_state_);
}

void PhilipsSeries2200::loop()
Expand Down
7 changes: 4 additions & 3 deletions components/philips_series_2200/philips_series_2200.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace esphome
*/
void set_invert_power_pin(bool invert)
{
invert_ = invert;
initial_pin_state_ = !invert;
}

void set_power_trip_delay(uint32_t time)
Expand All @@ -67,6 +67,7 @@ namespace esphome
power_switch->set_mainboard_uart(&mainboard_uart_);
power_switch->set_power_pin(power_pin_);
power_switch->set_power_trip_delay(power_trip_delay_);
power_switch->set_initial_state(&initial_pin_state_);
power_switches_.push_back(power_switch);
};

Expand Down Expand Up @@ -124,8 +125,8 @@ namespace esphome
/// @brief pin connect to display panel power transistor/mosfet
GPIOPin *power_pin_;

/// @brief indicates if the power pin should be inverted
bool invert_ = false;
/// @brief the initial power pin state (may be inverted through user configuration)
bool initial_pin_state_ = true;

/// @brief length of power outage applied to the display
uint32_t power_trip_delay_ = 500;
Expand Down

0 comments on commit fb8dd71

Please sign in to comment.