Wed, 02 Dec 2015 17:16:41 +0100
Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.
#ifndef _BREWCO_H #define _BREWCO_H #define TRUE 1 #define FALSE 0 #include "../config.h" #include "pid.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/socket.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> #include <math.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> /* * Thread locks */ #define LOCK_DEVICES 0 #define LOCK_LCD 1 #define LOCK_MENU 2 #define LOCK_SPARE2 3 #endif /* * 1-Wire devices */ #define W1_FAMILY_DEFAULT 0 #define W1_FAMILY_SMEM_01 0x01 #define W1_FAMILY_SMEM_81 0x81 #define W1_THERM_DS18S20 0x10 #define W1_FAMILY_DS28E04 0x1C #define W1_COUNTER_DS2423 0x1D #define W1_THERM_DS1822 0x22 #define W1_EEPROM_DS2433 0x23 #define W1_THERM_DS18B20 0x28 #define W1_FAMILY_DS2408 0x29 #define W1_EEPROM_DS2431 0x2D #define W1_FAMILY_DS2760 0x30 #define W1_FAMILY_DS2780 0x32 #define W1_FAMILY_DS2413 0x3A #define W1_THERM_DS1825 0x3B #define W1_FAMILY_DS2781 0x3D #define W1_THERM_DS28EA00 0x42 #define MBSE_SS(x) (x)?(x):"(null)" /* * Sensor strcuture */ typedef struct _sensor_var { char uuid[37]; /* sensor uuid */ int state; /* sensor state */ int value; /* sensor value */ } sensor_var; /* * Switch structure */ typedef struct _switch_var { char uuid[37]; /* switch uuid */ int value; /* switch value (0..100) */ int delay; /* switch delay */ } switch_var; /* * Brewing units. The sensors of the units are connected via the 1-wire bus. * The heaters, pumps (or mixer) are connected on the Pi GPIO. The hardware * is configured in the devices lists. */ typedef struct _units_list { struct _units_list *next; int version; /* Record version */ char *uuid; /* uuid code */ char *name; /* Unit name */ int number; /* Unit number */ int active; /* 0/1 active unit */ sensor_var *hlt_sensor; /* HLT sensor */ switch_var *hlt_heater; /* HLT heater */ int hlt_heater_mltfirst; /* HLT heater MLT high priority */ sensor_var *mlt_sensor; /* MLT sensor */ switch_var *mlt_heater; /* MLT heater */ switch_var *mlt_pump; /* MLT pump */ int pump_cycle; /* 5..15 minutes */ int pump_rest; /* 1..5 minutes */ int pump_premash; /* 0/1 */ int pump_onmash; /* 0/1 */ int pump_mashout; /* 0/1 */ int pump_onboil; /* 0/1 pump during boiling */ int pump_stop; /* 80..105 C */ int skip_add; /* 0/1 skip Add phase */ int skip_remove; /* 0/1 skip Remove phase */ int skip_iodine; /* 0/1 skip Iodine test */ int iodine_time; /* 0..90 minutes */ int whirlpool; /* off/cold/hot */ pid_var *PID_hlt; /* HLT PID */ pid_var *PID_mlt; /* MLT PID */ } units_list; /* * External devices like sensors, relays, SSR. */ 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_I2C 3 /* I2C bus device */ #define DEVTYPE_SPI 4 /* SPI bus device */ #ifdef USE_SIMULATOR #define DEVTYPE_SIM 5 /* Simulated device */ #endif #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 */ /* * Recipes. */ typedef struct _mash_step { char name[21]; /* Step name */ int min; /* Minimum temperature */ int max; /* Maximum temperature */ int canskip; /* 0/1 can we skip this step */ int setpoint; /* Temperature setpoint */ int skip; /* Skip this step */ int duration; /* Step duration */ } mash_step; // mash-in 20 80 noskip // fitasi 25 55 canskip // glucanasi 35 50 canskip // proteasi 45 60 canskip // B-amilasi 50 70 canskip // A-amilasi 1 60 76 canskip // A-amilasi 2 60 76 noskip // mash-out 75 80 noskip typedef struct _hop_addition { char name[21]; /* Hop name */ int boil_duration; /* -1=fwh, 0..boiltime */ } hop_addition; typedef struct _a_recipe { char uuid[37]; /* Recipe uuid */ char code[21]; /* Recipe code */ char name[21]; /* Recipe name */ mash_step mash[8]; /* 8 mash steps */ hop_addition hops[10]; /* 10 hop additions */ int boiltime; /* 1..240 minutes */ time_t started; /* Start time */ time_t endtime; /* Ending time */ } a_recipe; #ifdef USE_SIMULATOR /* * Simulate a HLT and MLT. */ typedef struct _simulator { double room_temperature; /* Simulated envionment temp */ double hlt_temperature; /* Simulated HLT temperature */ double hlt_heater_temp; /* Maximum heater temp */ int hlt_heater_time; /* Time to reach temperature */ float hlt_heater_size; /* Size of the heater */ int hlt_heater_state; /* Heater status */ double mlt_temperature; /* Simulated MLT temperature */ double mlt_heater_temp; /* Maximum heater temp */ int mlt_heater_time; /* Time to reach temperature */ float mlt_heater_size; /* Size of the heater */ int mlt_heater_state; /* Heater status */ /* * Status values, maintained by the simulator but stored * here so they don't get lost over program restarts. */ double s_hlt_temp; /* Temp HLT */ double s_mlt_temp; /* Temp MLT */ } simulator_var; #endif typedef struct _sys_config { char *name; /* Configuration name */ int my_port; /* my client/server port */ unsigned char tempFormat; /* Temperature format, C or F */ sensor_var *roomtemp; /* Environment temperature */ int lcd_cols; /* LCD display columns */ int lcd_rows; /* LCD display rows */ int lcd_address; /* LCD display i2c address */ units_list *units; /* Brewing units */ devices_list *devices; /* Sensors and switches */ #ifdef USE_SIMULATOR simulator_var *simulator; /* Simulator */ #endif } sys_config; /* * Brewing state file ~/.brewco/var/brewing.xml * If present a brew session is running */ #define MAISH_NA 0 /* Not in any state yet */ #define MASIH_PROMPT 1 /* Prompt the user */ #define MAISH_HEATING 2 /* Heating phase */ #define MAISH_REST 3 /* Rest phase */ #define MAISH_DONE 4 /* This step is done */ typedef struct _brew_session { char *uuid_recipe; /* Brewing this recipe */ char *uuid_unit; /* Brewing unit */ int premash; /* In premash state */ int mashstep; /* In or into maishstep or -1 */ int mashstate; /* State this step is in */ int resttime; /* Rest time downcouner */ int iodine; /* Mash iodine test */ int mashremove; /* Mash remove step */ int boilheating; /* Heat for boiling */ int boiling; /* Boiling started */ int boiltimer; /* Boiling downcount */ int cooling; /* Cooling phase */ int whirlpool; /* Whirlpool phase */ int cleanup; /* Cleanup phase */ time_t starttime; /* Start of brew */ time_t endtime; /* End of brew */ } brew_session; #endif