/** * TODO file description */ #include #include #include #include "app_io.h" #include "pinout.h" #include "app_config.h" void set_relays(bool one, bool two, bool three, bool four) { gpio_put(PIN_RE1, one); gpio_put(PIN_RE2, two); gpio_put(PIN_RE3, three); gpio_put(PIN_RE4, four); } void open_valve(uint8_t num) { set_relays(num == 1, num == 2, num == 3, num == 4); } void set_one_relay(uint8_t num, bool on) { if (num < 1 || num > 4) { return; } if (num == 1) { gpio_put(PIN_RE1, on); } if (num == 2) { gpio_put(PIN_RE2, on); } if (num == 3) { gpio_put(PIN_RE3, on); } if (num == 4) { gpio_put(PIN_RE4, on); } } uint16_t moisture_read() { adc_select_input(ADC_NUM_MOISTURE); return adc_read(); } uint16_t moisture_convert(uint16_t moisture) { uint32_t moisture_pt; if (moisture >= app_config.moisture_dry) { moisture_pt = 0; } else if (moisture <= app_config.moisture_wet) { moisture_pt = 100; } else { moisture_pt = ((uint32_t) (app_config.moisture_dry - moisture) * 100) / (app_config.moisture_dry - app_config.moisture_wet); } return (uint16_t) moisture_pt; }