|
|
|
/**
|
|
|
|
* TODO file description
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <hardware/gpio.h>
|
|
|
|
#include <hardware/adc.h>
|
|
|
|
#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_RE1, four);
|
|
|
|
}
|
|
|
|
|
|
|
|
void open_valve(uint8_t num)
|
|
|
|
{
|
|
|
|
gpio_put(PIN_RE1, num == 1);
|
|
|
|
gpio_put(PIN_RE2, num == 2);
|
|
|
|
gpio_put(PIN_RE3, num == 3);
|
|
|
|
gpio_put(PIN_RE4, num == 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|