Initial commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
@@ -0,0 +1,79 @@
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
// Messages on the pump command topic have format
|
||||
// {"id" : <id> , "enable" : <enable> , "timeout" : <timeout>}
|
||||
// Allows external control of the pumps
|
||||
#define TOPIC_PUMP_COMMAND "home/devices/autowaterer/pump_command"
|
||||
#define TOPIC_COMMAND_RESULT "home/devices/autowaterer/command_result"
|
||||
|
||||
#define CMD_OK "0"
|
||||
#define PUMP_CMD_ERR_INVALID_JSON "1"
|
||||
#define PUMP_CMD_ERR_INVALID_PUMP_ID "2"
|
||||
#define PUMP_CMD_ERR_TOO_MANY_PUMPS "3"
|
||||
#define PUMP_CMD_ERR_PUMP_ALREADY_ON "4"
|
||||
#define BURST_CMD_TOO_MANY_ITERATIONS "5"
|
||||
#define CALRST_CMD_INVALID_SENSOR_ID "6"
|
||||
|
||||
// Messages on the moisture sensor topic have format
|
||||
/*
|
||||
* {
|
||||
* "sensor_a" : {"level" : <level%>},
|
||||
* "sensor_b" : {"level" : <level%>},
|
||||
* "sensor_c" : {"level" : <level%>},
|
||||
* "sensor_d" : {"level" : <level%>},
|
||||
* "sensor_e" : {"level" : <level%>},
|
||||
* "sensor_f" : {"level" : <level%>},
|
||||
* }
|
||||
*/
|
||||
|
||||
#define TOPIC_LOG "home/devices/autowaterer/log" // General log messages
|
||||
|
||||
#define MAX_PUMP_TIMEOUT 30
|
||||
|
||||
#define GPIO_PUMPS_PORT GPIO_EXPANDER_PORT_A
|
||||
#define GPIO_PUMP_ENABLE_1 0
|
||||
#define GPIO_PUMP_ENABLE_2 1
|
||||
#define GPIO_PUMP_ENABLE_3 2
|
||||
#define GPIO_PUMP_ENABLE_4 3
|
||||
#define GPIO_PUMP_ENABLE_5 4
|
||||
#define GPIO_PUMP_ENABLE_6 5
|
||||
#define PUMPS_COUNT 8
|
||||
#define MAX_ACTIVE_PUMPS 4
|
||||
|
||||
#define TOPIC_MOISTURE_SENSORS "home/devices/autowaterer/moisture_sensors/" // Topic stub for publishing availability and values of sensors
|
||||
#define SENSOR_A_ADDR 0x61
|
||||
#define SENSOR_B_ADDR 0x62
|
||||
#define SENSOR_C_ADDR 0x63
|
||||
#define SENSOR_D_ADDR 0x64
|
||||
#define SENSOR_E_ADDR 0x65
|
||||
#define SENSOR_F_ADDR 0x66
|
||||
#define SENSOR_ADDR_START 'a'
|
||||
#define SENSORS_COUNT 6
|
||||
#define SENSORS_UPDATE_INTERVAL 60
|
||||
|
||||
#define TOPIC_SENSOR_BURST "home/devices/autowaterer/moisture_sensors/burst" // Publishing a number n here will cause the device to read sensors faster for n loop cycles
|
||||
#define TOPIC_CALIBRATION_RESET "home/devices/autowaterer/moisture_sensors/cal_reset" // Publishing an address here will reset the min/max values for the sensor at that address
|
||||
|
||||
#define ONLINE 1
|
||||
#define OFFLINE 0
|
||||
|
||||
#define GPIO_EXPANDER_ADDR 0x20
|
||||
#define GPIO_EXPANDER_PORT_A 0x12
|
||||
#define GPIO_EXPANDER_PORT_B 0x13
|
||||
#define GPIO_EXPANDER_DIR_A 0x00
|
||||
#define GPIO_EXPANDER_DIR_B 0x01
|
||||
|
||||
#define I2C_SUCCESS 0
|
||||
#define I2C_ADDRESS_NACK 2
|
||||
#define I2C_DATA_NACK 3
|
||||
|
||||
#define RS485_OUTPUT_ENABLE D5
|
||||
#define RS485_ERROR_TIMEOUT 0xFFFF
|
||||
#define RS485_MAX_INT 0x0FFF
|
||||
|
||||
#define NTP_OFFSET 60 * 60 // In seconds
|
||||
#define NTP_INTERVAL 60 * 1000 // In miliseconds
|
||||
#define NTP_ADDRESS "europe.pool.ntp.org"
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user