Rename functions name for better code clarity
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
//#define VASE_NUM 0
|
||||
|
||||
#define MOISTURE_SENSOR_A0 PC0
|
||||
#define MOISTURE_SENSOR_A1 PC1
|
||||
#define MOISTURE_SENSOR_A2 PC2
|
||||
@@ -12,6 +14,12 @@
|
||||
//#define MOISTURE_SENSOR_A6 PC6
|
||||
//#define MOISTURE_SENSOR_A7 PC7
|
||||
|
||||
// You may connect only the number of pumps that actually are needed in the vase
|
||||
#define PUMP_D3 PD3
|
||||
#define PUMP_D4 PD4
|
||||
#define PUMP_D5 PD5
|
||||
#define PUMP_D6 PD6
|
||||
#define PUMP_D7 PD7
|
||||
|
||||
#define SENSOR_READINGS 5
|
||||
#define SENSORS_NUM 6
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void initMoistureSensors(void);
|
||||
void triggerSensorsRead(void);
|
||||
int16_t moistureSensorsAverage(int8_t sensorPin);
|
||||
int16_t readMoisture(void);
|
||||
void sensorsInit(void);
|
||||
void triggerRead(void);
|
||||
int16_t moistureAverage(int8_t sensorPin);
|
||||
int16_t moistureRead(void);
|
||||
|
||||
extern volatile bool readSensors;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "adc.h"
|
||||
|
||||
ISR(WDT_vect) {
|
||||
triggerSensorsRead();
|
||||
triggerRead();
|
||||
}
|
||||
|
||||
void watchdogs(void) {
|
||||
@@ -27,7 +27,8 @@ void enterSleep(void) {
|
||||
|
||||
void setup(void) {
|
||||
adcInit();
|
||||
initMoistureSensors();
|
||||
//pumpsInit();
|
||||
sensorsInit();
|
||||
watchdogs();
|
||||
}
|
||||
|
||||
@@ -36,12 +37,10 @@ int main(void) {
|
||||
|
||||
while(true) {
|
||||
if (readSensors) {
|
||||
int16_t result = readMoisture();
|
||||
|
||||
//TODO: send result to esp32
|
||||
int16_t result = moistureRead();
|
||||
//espSend(VASE_NUM, result)
|
||||
}
|
||||
// readFromEsp()
|
||||
// if esp tells to water plants: waterPlants()
|
||||
// if(espGet("ask if i need to water plants") == true) {trigger()}
|
||||
enterSleep();
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
volatile bool readSensors = false;
|
||||
|
||||
void initMoistureSensors(void) {
|
||||
void sensorsInit(void) {
|
||||
// Set as input
|
||||
DDRC &= ~((1 << MOISTURE_SENSOR_A0) |
|
||||
(1 << MOISTURE_SENSOR_A1) |
|
||||
@@ -29,11 +29,11 @@ void initMoistureSensors(void) {
|
||||
//(1 << MOISTURE_SENSOR_A7));
|
||||
}
|
||||
|
||||
void triggerSensorsRead(void) {
|
||||
void triggerRead(void) {
|
||||
readSensors = true;
|
||||
}
|
||||
|
||||
int16_t moistureSensorsAverage(int8_t sensorPin) {
|
||||
int16_t moistureAverage(int8_t sensorPin) {
|
||||
int16_t sum = 0;
|
||||
for (int i = 0; i < SENSOR_READINGS; i++) {
|
||||
sum += adcRead(sensorPin);
|
||||
@@ -44,7 +44,7 @@ int16_t moistureSensorsAverage(int8_t sensorPin) {
|
||||
return sum / SENSOR_READINGS;
|
||||
}
|
||||
|
||||
int16_t readMoisture(void) {
|
||||
int16_t moistureRead(void) {
|
||||
uint8_t sensorPins[SENSORS_NUM] = { MOISTURE_SENSOR_A0, MOISTURE_SENSOR_A1,
|
||||
MOISTURE_SENSOR_A2, MOISTURE_SENSOR_A3,
|
||||
MOISTURE_SENSOR_A4, MOISTURE_SENSOR_A5 };
|
||||
@@ -53,7 +53,7 @@ int16_t readMoisture(void) {
|
||||
int16_t overallSum = 0;
|
||||
|
||||
for (int i = 0; i < SENSORS_NUM; i++) {
|
||||
int16_t sensorAverage = moistureSensorsAverage(sensorPins[i]);
|
||||
int16_t sensorAverage = moistureAverage(sensorPins[i]);
|
||||
//TODO: if a sensor gives 0 or 1023, discard that sensor entirely (means it is disconnected or not working)
|
||||
overallSum += sensorAverage;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user