Formatting pass

This commit is contained in:
Unknown
2019-08-20 23:13:54 -04:00
parent 51e81cc8f1
commit 2b58d15d8d
20 changed files with 877 additions and 917 deletions
+9 -9
View File
@@ -6,18 +6,18 @@ Endstop::Endstop(Endstop::Config_t& config)
}
void Endstop::update() {
uint16_t gpio_pin = get_gpio_pin_by_pin(config_.gpio_num);
uint16_t gpio_pin = get_gpio_pin_by_pin(config_.gpio_num);
GPIO_TypeDef* gpio_port = get_gpio_port_by_pin(config_.gpio_num);
auto last_pin_state = pin_state_;
pin_state_ = HAL_GPIO_ReadPin(gpio_port, gpio_pin);
auto last_pin_state = pin_state_;
pin_state_ = HAL_GPIO_ReadPin(gpio_port, gpio_pin);
if (pin_state_ != last_pin_state) {
debounce_timer_ = axis_->loop_counter_ * current_meas_period;
}
if (config_.enabled) {
float now = axis_->loop_counter_ * current_meas_period;
if ((now - debounce_timer_) >= (config_.debounce_ms * 0.001f)) { // Debounce timer expired, take the new pin state
endstop_state_ = config_.is_active_high ? pin_state_ : !pin_state_; // endstop_state is the logical state
debounce_timer_ = now - (config_.debounce_ms * 0.001f); // Ensure timer doesn't have overflow issues
if ((now - debounce_timer_) >= (config_.debounce_ms * 0.001f)) { // Debounce timer expired, take the new pin state
endstop_state_ = config_.is_active_high ? pin_state_ : !pin_state_; // endstop_state is the logical state
debounce_timer_ = now - (config_.debounce_ms * 0.001f); // Ensure timer doesn't have overflow issues
} else {
endstop_state_ = endstop_state_; // Do nothing
}
@@ -30,18 +30,18 @@ bool Endstop::getEndstopState() {
return endstop_state_;
}
void Endstop::update_endstop_config(){
void Endstop::update_endstop_config() {
set_endstop_enabled(config_.enabled);
}
void Endstop::set_endstop_enabled(bool enable) {
if (config_.gpio_num != 0) {
uint16_t gpio_pin = get_gpio_pin_by_pin(config_.gpio_num);
uint16_t gpio_pin = get_gpio_pin_by_pin(config_.gpio_num);
GPIO_TypeDef* gpio_port = get_gpio_port_by_pin(config_.gpio_num);
if (enable) {
HAL_GPIO_DeInit(gpio_port, gpio_pin);
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = gpio_pin;
GPIO_InitStruct.Pin = gpio_pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = config_.is_active_high ? GPIO_PULLDOWN : GPIO_PULLUP;
HAL_GPIO_Init(gpio_port, &GPIO_InitStruct);