Mon, 07 Jul 2014 21:15:44 +0200
Fixed possible one character short on LCD. Added environment air temperature sensor
#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> #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_temp; /* Air temperature * 1000 */ char *beer_address; /* DS18B20 address */ int beer_temp; /* Beer temperature * 1000 */ char *io1_address; /* DS2413 address */ char *io2_address; /* DS2413 address */ int heater_available; /* Heater available */ int heater_state; /* Heater status */ int cooler_available; /* Cooler available */ int cooler_state; /* Cooler status */ int fan_available; /* Fan available */ int fan_state; /* Fan status */ 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 */ time_t prof_started; /* Profile start time */ int prof_state; /* Profile OFF|PAUSE|RUN|DONE */ } 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 */ #define UNITIO1_HEATER 0x01 /* Heater bit */ #define UNITIO1_COOLER 0x02 /* Cooler bit */ #define UNITIO2_FAN 0x01 /* Fan bit */ #define UNITIO2_DOOR 0x02 /* Door status */ /* * 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 */ 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 */ typedef struct _w1_therm { struct _w1_therm *next; char *master; /* Master for this device */ int bus; /* Reserved for ds2482-800 */ char *name; /* Name of this device */ char *alias; /* Friendly name */ int present; /* 1=present, 0=absent */ int lastval; /* Last valid value */ int update; /* Value updated */ } w1_therm; typedef struct _sys_config { char *name; /* Configuration name */ int my_port; /* my client/server port */ unsigned char tempFormat; /* Temperature format, C or F */ char *air_address; /* 1-wire environment sensor */ w1_therm *w1therms; /* 1-wire temp sensors */ #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 */ /* ControlSettings: */ unsigned char cs_mode; /* mode */ float cs_beerSet; /* beer temperature */ float cs_fridgeSet; /* fridge temperature */ float cs_heatEstimator; float cs_coolEstimator; /* ControlConstants */ float cc_tempSetMin; float cc_tempSetMax; float cc_idleRangeH; float cc_idleRangeL; } sys_config; void killconfig(void); int rdconfig(void); int wrconfig(void); /* lock.c */ int lockprog(char *); void ulockprog(char *); /* xutil.c */ char *xmalloc(size_t); char *xstrcpy(char *); char *xstrcat(char *, char *); /* futil.c */ int mkdirs(char *, mode_t); #ifdef HAVE_WIRINGPI_H /* lcd-pcf8574.c */ // Defines for the pcf8574 Pi LCD interface board #define AF_BASE 100 #define AF_RS (AF_BASE + 0) #define AF_RW (AF_BASE + 1) #define AF_E (AF_BASE + 2) #define AF_BACKLIGHT (AF_BASE + 3) #define AF_DB4 (AF_BASE + 4) #define AF_DB5 (AF_BASE + 5) #define AF_DB6 (AF_BASE + 6) #define AF_DB7 (AF_BASE + 7) void setBacklight (int); int initLCD (int, int); void mb_lcdPutchar(const int, unsigned char); void mb_lcdPuts(const int, const char *); void mb_lcdClear(const int); #endif /* logger.c */ void logger(char *, char *, char *); #ifdef HAVE_WIRINGPI_H PI_THREAD (my_sensors_loop); #else void *my_sensors_loop(void *); #endif /* server.c */ void defaultControlSettings(void); void defaultControlConstants(void); #ifdef HAVE_WIRINGPI_H PI_THREAD (my_server_loop); #else void *my_server_loop(void *); #endif #ifdef HAVE_WIRINGPI_H PI_THREAD (my_units_loop); #else void *my_units_loop(void *); #endif #endif