Mon, 11 Aug 2014 18:38:57 +0200
Added profile running and steps handling.
#ifndef _MBSELIB_H #define _MBSELIB_H #define TRUE 1 #define FALSE 0 #include "../config.h" #include <stdlib.h> #include <stdio.h> #include <stdint.h> #include <stdarg.h> #include <string.h> #include <ctype.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/time.h> #include <time.h> #include <fcntl.h> #include <syslog.h> #include <unistd.h> #include <errno.h> #include <signal.h> #include <getopt.h> #include <limits.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netdb.h> #include <poll.h> #include <dirent.h> #include <uuid/uuid.h> #ifndef HAVE_WIRINGPI_H #include <pthread.h> #endif #include <libxml/xmlmemory.h> #include <libxml/parser.h> #include <libxml/encoding.h> #include <libxml/xmlwriter.h> #ifdef HAVE_WIRINGPI_H /* wiringPi */ #include <wiringPi.h> #include <pcf8574.h> #include <lcd.h> #define MENU_NONE 0 #define MENU_TOP_DEFAULT 1 #define MENU_TOP_UNITS 2 #define MENU_UNITS 21 #define MENU_MODE_OFF 211 #define MENU_MODE_NONE 212 #define MENU_NONE_HEAT 2121 #define MENU_NONE_COOL 2122 #define MENU_NONE_FAN 2123 #define MENU_MODE_BEER 213 #define MENU_BEER_TEMP 2131 #define MENU_MODE_FRIDGE 214 #define MENU_FRIDGE_TEMP 2141 #define MENU_MODE_PROFILE 215 #define MENU_PROFILE_SELECT 2151 #define MENU_PROFILE_START 2152 #define MENU_PROFILE_PAUSE 2153 #define MENU_PROFILE_ABORT 2154 #define MENU_PROFILE_RESUME 2155 #define MENU_PROFILE_GOOFF 2156 #define MENU_TOP_SYS 3 #define MENU_SYS_HALT 31 #define MENU_SYS_REBOOT 32 #define MENU_SYS_MASH 33 #define MENU_SYS_THERMS 34 #endif #define TRUE 1 #define FALSE 0 #define MBSE_SS(x) (x)?(x):"(null)" /* * Fermenter units. These units are connected via the 1-wire bus. * Each unit can have: * a DS18B20 sensor to measure the air temperature inside the unit. * a DS18B20 sensor to measure the beer temperature. * a DS2413 to turn the cooler and heater on or off. * a DS2413 to switch the fan and sense the door. */ typedef struct _units_list { struct _units_list *next; int version; /* Record version */ char *uuid; /* uid code */ char *name; /* friendly name */ float volume; /* Volume of this unit */ char *air_address; /* DS18B20 address */ int air_state; /* 0=ok, 1=missing, 2=error */ int air_temperature; /* Air temperature in C * 1000 */ char *beer_address; /* DS18B20 address */ int beer_state; /* 0=ok, 1=missing, 2=error */ int beer_temperature; /* Beer temperature in C * 1000 */ char *heater_address; /* Heater relay or PWM */ int heater_state; /* Heater status */ char *cooler_address; /* Cooler relay or PWM */ int cooler_state; /* Cooler status */ char *fan_address; /* Fan relay or PWM */ int fan_state; /* Fan status */ char *door_address; /* Door input address */ int door_state; /* Door and light status */ int mode; /* Unit mode */ float beer_set; /* Beer temperature setting */ float fridge_set; /* Fridge temperature setting */ float temp_set_min; /* Minimum temperature */ float temp_set_max; /* Maximum temperature */ float idle_rangeL; /* Idle temperature low */ float idle_rangeH; /* Idle range high */ char *profile; /* Active profile uuid */ time_t prof_started; /* Profile start time */ int prof_state; /* Profile OFF|PAUSE|RUN|DONE */ float prof_target; /* Profile current target temp */ time_t prof_paused; /* Profile total pause time */ float PID_I_err; /* PID Intergal error */ float PID_err_old; /* PID old error value */ } units_list; #define UNITMODE_OFF 0 /* Unit turned off */ #define UNITMODE_NONE 1 /* Unit on but does nothing */ #define UNITMODE_FRIDGE 2 /* Unit acts as a fridge */ #define UNITMODE_BEER 3 /* Unit acts as beer cooler */ #define UNITMODE_PROFILE 4 /* Unit runs in profile mode */ /* * Fermenting steps */ typedef struct _prof_step { struct _prof_step *next; int version; /* Version 1 */ int steptime; /* Step time to target in hours */ int resttime; /* Rest time on target in hours */ float target; /* Target temperature */ } prof_step; /* * Fermenting profiles */ typedef struct _prof_list { struct _prof_list *next; int version; /* Version 1 */ char *uuid; /* Profile uuid */ char *name; /* Profile name */ int busy; /* Profile busy == 1, free == 0 */ float inittemp; /* Temp target before start */ prof_step *steps; /* Profile steps */ } profiles_list; #define PROFILE_OFF 0 /* Profile not active */ #define PROFILE_PAUSE 1 /* Profile pause */ #define PROFILE_RUN 2 /* Profile is running */ #define PROFILE_DONE 3 /* Profile is finished */ #define PROFILE_ABORT 4 /* Profile abort */ /* * External devices like sensors, relays. */ typedef struct _dev_list { struct _dev_list *next; int version; /* Version 1 */ char *uuid; /* UUID of this device */ int type; /* Device type */ int direction; /* Device direction */ int value; /* Device value */ int offset; /* Device offset value */ int present; /* Device present */ char *address; /* Device address */ int subdevice; /* Device sub address */ int gpiopin; /* Device GPIO pin or -1 */ char *description; /* Device description */ int inuse; /* In use counter */ char *comment; /* What we think it is */ time_t timestamp; /* Last updated */ } devices_list; #define DEVTYPE_NA 0 /* Unknown device type */ #define DEVTYPE_W1 1 /* 1-Wire bus */ #define DEVTYPE_GPIO 2 /* GPIO I/O device */ #define DEVTYPE_RC433 3 /* 433 MHz device */ #define DEVTYPE_DHT 4 /* DHT type device on GPIO */ #define DEVTYPE_I2C 5 /* I2C bus device */ #define DEVTYPE_SPI 6 /* SPI bus device */ #define DEVPRESENT_UNDEF 0 /* Precence not testable */ #define DEVPRESENT_NO 1 /* Device is missing */ #define DEVPRESENT_YES 2 /* Device is detected */ #define DEVPRESENT_ERROR 3 /* Device is in error */ #define DEVDIR_UNDEF 0 /* Undefined */ #define DEVDIR_IN_BIN 1 /* Binary input */ #define DEVDIR_OUT_BIN 2 /* Binary output */ #define DEVDIR_IN_ANALOG 3 /* Temperature input etc. */ #define DEVDIR_OUT_ANALOG 4 /* Analog steering */ #define DEVDIR_OUT_PWM 5 /* PWM outout */ #define DEVDIR_INTERN 6 /* Internal function */ typedef struct _sys_config { char *name; /* Configuration name */ int my_port; /* my client/server port */ unsigned char tempFormat; /* Temperature format, C or F */ char *temp_address; /* Environment temperature */ int temp_state; /* 0=ok, 1=missing, 2=error */ int temp_value; /* Air temperature in C * 1000 */ char *hum_address; /* Environment huminity */ int hum_state; /* 0=ok, 1=missing, 2=error */ int hum_value; /* Huminity in % * 1000 */ #ifdef HAVE_WIRINGPI_H int lcd_cols; /* LCD display columns */ int lcd_rows; /* LCD display rows */ int lcd_address; /* LCD display i2c address */ #endif units_list *units; /* Fermenter units */ profiles_list *profiles; /* Ferment profiles */ devices_list *devices; /* Sensors and switches */ } sys_config; #endif