# HG changeset patch # User Michiel Broek # Date 1407698537 -7200 # Node ID 2317b8d644faabec2ecba1849a68a7b47753080c # Parent a76cbe676bf1619092f9cd7a180eef7c2357f30e Code cleanup, streamlined error messages. diff -r a76cbe676bf1 -r 2317b8d644fa thermferm/devices.c --- a/thermferm/devices.c Sun Aug 10 20:01:17 2014 +0200 +++ b/thermferm/devices.c Sun Aug 10 21:22:17 2014 +0200 @@ -57,7 +57,7 @@ /* - * DHT11 sensor read. This should be used in a thread loop. + * DHT11 sensor read. */ void dht11Read(void) { int tries = 5; @@ -189,7 +189,6 @@ rc = 0; if ((device->type == DEVTYPE_RC433) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) { enableTransmit(device->gpiopin); -// usleep(10000); snprintf(buf, 39, "%s,%d", device->address, value ? 1:0); for (i = 0; i < strlen(buf); i++) if (buf[i] == '-') @@ -198,7 +197,6 @@ syslog(LOG_NOTICE, "RC433 command %s rc=%d", buf, rc); if (debug) fprintf(stdout, "RC433 command %s rc=%d\n", buf, rc); -// usleep(50000); disableTransmit(); device->value = value; device->timestamp = time(NULL); @@ -409,8 +407,6 @@ int temp, rc; syslog(LOG_NOTICE, "Thread my_devices_loop started"); - if (debug) - fprintf(stdout, "Thread my_devices_loop started\n"); /* * Loop forever until the external shutdown variable is set. @@ -507,9 +503,6 @@ } syslog(LOG_NOTICE, "Thread my_devices_loop stopped"); - if (debug) - fprintf(stdout, "Thread my_devices_loop stopped\n"); - return 0; } diff -r a76cbe676bf1 -r 2317b8d644fa thermferm/futil.c --- a/thermferm/futil.c Sun Aug 10 20:01:17 2014 +0200 +++ b/thermferm/futil.c Sun Aug 10 21:22:17 2014 +0200 @@ -16,7 +16,7 @@ * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with EC-65K; see the file COPYING. If not, write to the Free + * along with ThermFerm; see the file COPYING. If not, write to the Free * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *****************************************************************************/ diff -r a76cbe676bf1 -r 2317b8d644fa thermferm/lcd-buffer.c --- a/thermferm/lcd-buffer.c Sun Aug 10 20:01:17 2014 +0200 +++ b/thermferm/lcd-buffer.c Sun Aug 10 21:22:17 2014 +0200 @@ -48,7 +48,7 @@ int i = 0; va_start(va_ptr, format); - vsnprintf(buf, 20 * sizeof(char), format, va_ptr); + vsnprintf(buf, Config.lcd_cols * sizeof(char), format, va_ptr); va_end(va_ptr); /* @@ -59,7 +59,7 @@ newrow = (lcd_rows *)malloc(sizeof(lcd_rows)); newrow->next = NULL; - snprintf(newrow->row, 21 * sizeof(char), " "); + snprintf(newrow->row, (Config.lcd_cols + 1) * sizeof(char), " "); if (my_lcd_rows == NULL) { my_lcd_rows = newrow; diff -r a76cbe676bf1 -r 2317b8d644fa thermferm/lcd-pcf8574.c --- a/thermferm/lcd-pcf8574.c Sun Aug 10 20:01:17 2014 +0200 +++ b/thermferm/lcd-pcf8574.c Sun Aug 10 21:22:17 2014 +0200 @@ -39,7 +39,10 @@ int dataPins [8] ; int cx, cy ; }; + extern struct lcdDataStruct *lcds [MAX_LCDS]; +extern sys_config Config; + /* @@ -95,8 +98,8 @@ } lcdClear (lcdHandle) ; - for (x = 0; x < 20; x++) - for (y = 0; y < 4; y++) + for (x = 0; x < Config.lcd_cols; x++) + for (y = 0; y < Config.lcd_rows; y++) lcdbuf[lcdHandle][x][y] = ' '; setBacklight (1) ; @@ -133,8 +136,8 @@ int x, y; lcdClear(fd); - for (x = 0; x < 20; x++) - for (y = 0; y < 4; y++) + for (x = 0; x < Config.lcd_cols; x++) + for (y = 0; y < Config.lcd_rows; y++) lcdbuf[fd][x][y] = ' '; } diff -r a76cbe676bf1 -r 2317b8d644fa thermferm/lock.c --- a/thermferm/lock.c Sun Aug 10 20:01:17 2014 +0200 +++ b/thermferm/lock.c Sun Aug 10 21:22:17 2014 +0200 @@ -16,7 +16,7 @@ * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with EC-65K; see the file COPYING. If not, write to the Free + * along with ThermFerm; see the file COPYING. If not, write to the Free * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *****************************************************************************/ diff -r a76cbe676bf1 -r 2317b8d644fa thermferm/logger.c --- a/thermferm/logger.c Sun Aug 10 20:01:17 2014 +0200 +++ b/thermferm/logger.c Sun Aug 10 21:22:17 2014 +0200 @@ -16,7 +16,7 @@ * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with EC-65K; see the file COPYING. If not, write to the Free + * along with ThermFerm; see the file COPYING. If not, write to the Free * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *****************************************************************************/ diff -r a76cbe676bf1 -r 2317b8d644fa thermferm/panel.c --- a/thermferm/panel.c Sun Aug 10 20:01:17 2014 +0200 +++ b/thermferm/panel.c Sun Aug 10 21:22:17 2014 +0200 @@ -40,18 +40,6 @@ int previous_key = KEY_NONE; int menutimer = 0; -int Led_Off = 0; -int Led_On = 100; - - -/* - * LED flash patterns, on, off. Times in 10 mSecs. - */ -const int LED_OFF[2] = { 0, 100 }; -const int LED_ON[2] = { 100, 0 }; -const int LED_WARN[2] = { 5, 95 }; -const int LED_ALARM[2] = { 50, 50 }; - /* @@ -101,10 +89,7 @@ pinMode(PANEL_UP, INPUT); pinMode(PANEL_DOWN, INPUT); - syslog(LOG_NOTICE, "Thread my_panel_loop started"); - if (debug) - fprintf(stdout, "Thread my_panel_loop started\n"); /* * Loop forever until the external shutdown variable is set. @@ -159,16 +144,10 @@ AnyKey = FALSE; } -// if (debug && AnyKey) -// fprintf(stdout, "keys Enter=%d,%s,%s Up=%d,%s Down=%d,%s\n", -// Enter, Key_Enter ?"True":"False", Key_Enter_Long ?"True":"False", Up, Key_Up ?"True":"False", Down, Key_Down ?"True":"False"); - Now = time(NULL); if (Now != Last) { Last = Now; -// if (debug) -// fprintf(stdout, "AnyKey=%s Backlight=%d\n", AnyKey ?"True":"False", Backlight); if (AnyKey == FALSE) { if (Backlight == 1) setBacklight(0); diff -r a76cbe676bf1 -r 2317b8d644fa thermferm/rc-switch.c --- a/thermferm/rc-switch.c Sun Aug 10 20:01:17 2014 +0200 +++ b/thermferm/rc-switch.c Sun Aug 10 21:22:17 2014 +0200 @@ -19,7 +19,7 @@ * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with EC-65K; see the file COPYING. If not, write to the Free + * along with ThermFerm; see the file COPYING. If not, write to the Free * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *****************************************************************************/ @@ -583,31 +583,6 @@ -/* -void RCSwitch::send(unsigned long Code, unsigned int length) { - this->send( this->dec2binWzerofill(Code, length) ); -} - -void RCSwitch::send(char* sCodeWord) { - for (int nRepeat=0; nRepeatsend0(); - break; - case '1': - this->send1(); - break; - } - i++; - } - this->sendSync(); - } -} -*/ - - void transmit(int nFirstPulses, int nSecondPulses, int bHighFirst) { int disabled_Receive = FALSE; @@ -632,52 +607,6 @@ /* - * Sends a "0" Bit - * _ - * Waveform Protocol 1: | |___ - * _ - * Waveform Protocol 2: | |__ - * ____ - * Waveform Protocol 3: | |___________ - */ -//void send0(void) { -// if (rcProtocol == 1){ -// transmit(1,3); -// } -// else if (rcProtocol == 2) { -// transmit(1,2); -// } -// else if (rcProtocol == 3) { -// transmit(4,11); -// } -//} - - - -/* - * Sends a "1" Bit - * ___ - * Waveform Protocol 1: | |_ - * __ - * Waveform Protocol 2: | |_ - * _________ - * Waveform Protocol 3: | |______ - */ -//void send1(void) { -// if (rcProtocol == 1){ -// transmit(3,1); -// } -// else if (rcProtocol == 2) { -// transmit(2,1); -// } -// else if (rcProtocol == 3) { -// transmit(9,6); -// } -//} - - - -/* * Sends a Tri-State "0" Bit * _ _ * Waveform: | |___| |___ @@ -685,8 +614,6 @@ void sendT0(void) { transmit(ZERO_FIRST_CYCLES[rcProtocol], ZERO_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]); transmit(ZERO_FIRST_CYCLES[rcProtocol], ZERO_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]); -// transmit(1,3,true); -// transmit(1,3,true); } @@ -699,8 +626,6 @@ void sendT1(void) { transmit(ONE_FIRST_CYCLES[rcProtocol], ONE_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]); transmit(ONE_FIRST_CYCLES[rcProtocol], ONE_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]); -// transmit(3,1,true); -// transmit(3,1,true); } @@ -713,8 +638,6 @@ void sendTF(void) { transmit(ZERO_FIRST_CYCLES[rcProtocol], ZERO_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]); transmit(ONE_FIRST_CYCLES[rcProtocol], ONE_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]); -// transmit(1,3,true); -// transmit(3,1,true); } diff -r a76cbe676bf1 -r 2317b8d644fa thermferm/rc-switch.h --- a/thermferm/rc-switch.h Sun Aug 10 20:01:17 2014 +0200 +++ b/thermferm/rc-switch.h Sun Aug 10 21:22:17 2014 +0200 @@ -4,9 +4,6 @@ #ifdef HAVE_WIRINGPI_H -/* wiringPi */ -//#include - /* rc-switch.c */ int toggleSwitch(char *); @@ -33,11 +30,6 @@ char *dec2binWzerofill(unsigned long, unsigned int); -/* xutil.c */ -//char *xmalloc(size_t); -//char *xstrcpy(char *); -//char *xstrcat(char *, char *); - #endif diff -r a76cbe676bf1 -r 2317b8d644fa thermferm/rdconfig.c --- a/thermferm/rdconfig.c Sun Aug 10 20:01:17 2014 +0200 +++ b/thermferm/rdconfig.c Sun Aug 10 21:22:17 2014 +0200 @@ -16,7 +16,7 @@ * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with EC-65K; see the file COPYING. If not, write to the Free + * along with ThermFerm; see the file COPYING. If not, write to the Free * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *****************************************************************************/ diff -r a76cbe676bf1 -r 2317b8d644fa thermferm/server.c --- a/thermferm/server.c Sun Aug 10 20:01:17 2014 +0200 +++ b/thermferm/server.c Sun Aug 10 21:22:17 2014 +0200 @@ -16,7 +16,7 @@ * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with EC-65K; see the file COPYING. If not, write to the Free + * along with ThermFerm; see the file COPYING. If not, write to the Free * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *****************************************************************************/ @@ -226,13 +226,13 @@ opt = strtok(NULL, " \0"); if (opt == NULL) { - srv_send((char *)"502 Missing command option"); + srv_send((char *)"501 Subcommand missing"); return 1; } param = strtok(NULL, "\0"); if (strcmp(opt, (char *)"LIST") == 0) { - srv_send((char *)"212 bus devices:"); + srv_send((char *)"212 Devices list follows:"); for (device = Config.devices; device; device = device->next) { srv_send((char *)"%s,%s,%d,%d,%s,%s", device->uuid, device->address, device->subdevice, device->inuse, device->comment, DEVDIR[device->direction]); } @@ -241,7 +241,7 @@ } if (param == NULL) { - srv_send((char *)"502 Missing command parameter"); + srv_send((char *)"502 Parameter missing"); return 1; } @@ -279,12 +279,12 @@ } } } - syslog(LOG_NOTICE, "Device with uuid %s added", device->uuid); - srv_send((char *)"211 Device with uuid %s added", device->uuid); + syslog(LOG_NOTICE, "Device %s added", device->uuid); + srv_send((char *)"211 Device %s added", device->uuid); return 0; } else { - srv_send((char *)"506 Wrong device parameter"); + srv_send((char *)"503 Parameter error"); return 1; } } @@ -292,11 +292,11 @@ if (strcmp(opt, (char *)"DEL") == 0) { if (delete_Device(param)) { - syslog(LOG_NOTICE, "Deleted device with %s", param); + syslog(LOG_NOTICE, "Device %s deleted", param); srv_send((char *)"211 Device %s deleted", param); return 0; } else { - srv_send((char *)"440 Delete Device: No such device %s", param); + srv_send((char *)"440 No such device"); return 1; } } @@ -304,7 +304,7 @@ if (strcmp(opt, (char *)"GET") == 0) { for (device = Config.devices; device; device = device->next) { if (strcmp(device->uuid, param) == 0) { - srv_send((char *)"213 Device %s record follows:", device->uuid); + srv_send((char *)"213 Device record follows:"); srv_send((char *)"TYPE,%s", DEVTYPE[device->type]); srv_send((char *)"DIRECTION,%s", DEVDIR[device->direction]); srv_send((char *)"VALUE,%d", device->value); @@ -426,7 +426,7 @@ return 1; } - srv_send((char *)"502 Unknown command option"); + srv_send((char *)"504 Subcommand error"); return 1; } @@ -446,7 +446,7 @@ opt = strtok(NULL, "\0"); if (opt == NULL) { - srv_send((char *)"502 Missing command option"); + srv_send((char *)"501 Subcommand missing"); return 1; } @@ -556,7 +556,7 @@ } } - srv_send((char *)"502 Unknown command option"); + srv_send((char *)"504 Subcommand error"); return 1; } @@ -590,7 +590,7 @@ param = strtok(NULL, "\0"); if (param == NULL) { - srv_send((char *)"501 Parameter missing"); + srv_send((char *)"502 Parameter missing"); return 1; } @@ -628,7 +628,7 @@ return 0; } - srv_send((char *)"502 Unknown command option"); + srv_send((char *)"504 Subcommand error"); return 1; } @@ -664,7 +664,7 @@ /* * Fermenting profiles */ - srv_send((char *)"212 profiles:"); + srv_send((char *)"212 Profiles list follows:"); for (profile = Config.profiles; profile; profile = profile->next) { j = 0; for (step = profile->steps; step; step = step->next) @@ -677,7 +677,7 @@ param = strtok(NULL, "\0"); if (param == NULL) { - srv_send((char *)"501 Parameter missing"); + srv_send((char *)"502 Parameter missing"); return 1; } @@ -703,25 +703,25 @@ } } - syslog(LOG_NOTICE, "Profile \"%s\" with uuid %s added", param, profile->uuid); - srv_send((char *)"211 Profile \"%s\" with uuid %s added", param, profile->uuid); + syslog(LOG_NOTICE, "Profile %s added", profile->uuid); + srv_send((char *)"211 Profile %s added", profile->uuid); return 0; } else if (strcmp(opt, (char *)"DEL") == 0) { if (delete_Profile(param)) { - syslog(LOG_NOTICE, "Deleted Profile with %s", param); + syslog(LOG_NOTICE, "Profile %s deleted", param); srv_send((char *)"211 Profile %s deleted", param); return 0; } else { - srv_send((char *)"440 Delete Profile: No such profile%s", param); + srv_send((char *)"440 No such profile"); return 1; } } else if (strcmp(opt, (char *)"GET") == 0) { for (profile = Config.profiles; profile; profile = profile->next) { if (strcmp(profile->uuid, param) == 0) { - srv_send((char *)"213 Profile %s record follows:", profile->uuid); + srv_send((char *)"213 Profile record follows:"); srv_send((char *)"UUID,%s", profile->uuid); srv_send((char *)"NAME,%s", profile->name); srv_send((char *)"INITTEMP,%.1f", profile->inittemp); @@ -762,7 +762,7 @@ fprintf(stdout, "recv: \"%s\"\n", ibuf); } if (strcmp(ibuf, (char *)".") == 0) { - srv_send((char *)"219 Accepted Device record"); + srv_send((char *)"219 Accepted Profile record"); return 0; } kwd = strtok(ibuf, ",\0"); @@ -841,7 +841,7 @@ } if (strcmp(ibuf, (char *)".") == 0) { - srv_send((char *)"219 Accepted profile steps"); + srv_send((char *)"219 Accepted Profile steps"); return 0; } sstep = strtok(ibuf, ",\0"); @@ -880,7 +880,7 @@ return 1; } - srv_send((char *)"502 Unknown command option"); + srv_send((char *)"504 Subcommand error"); return 1; } @@ -982,13 +982,13 @@ opt = strtok(NULL, " \0"); if (opt == NULL) { - srv_send((char *)"501 Parameter missing"); + srv_send((char *)"501 Subcommand missing"); return 1; } param = strtok(NULL, "\0"); if ((strcmp(opt, (char *)"LIST") == 0) && (param == NULL)) { - srv_send((char *)"212 Fermenter Units list follows:"); + srv_send((char *)"212 Fermenter list follows:"); for (unit = Config.units; unit; unit = unit->next) { srv_send((char *)"%s,%s,%s", unit->uuid, unit->name, UNITMODE[unit->mode]); } @@ -997,7 +997,7 @@ } if (param == NULL) { - srv_send((char *)"501 Parameter missing"); + srv_send((char *)"502 Parameter missing"); return 1; } @@ -1034,18 +1034,18 @@ } } - syslog(LOG_NOTICE, "Unit with uuid %s added", unit->uuid); - srv_send((char *)"211 Unit with uuid %s added", unit->uuid); + syslog(LOG_NOTICE, "Unit %s added", unit->uuid); + srv_send((char *)"211 Unit %s added", unit->uuid); return 0; } if (strcmp(opt, (char *)"DEL") == 0) { if (delete_Unit(param)) { - syslog(LOG_NOTICE, "Deleted Unit with %s", param); + syslog(LOG_NOTICE, "Unit %s deleted", param); srv_send((char *)"211 Unit %s deleted", param); return 0; } else { - srv_send((char *)"440 Delete Unit: No such unit %s", param); + srv_send((char *)"440 No such unit"); return 1; } } @@ -1053,7 +1053,7 @@ if (strcmp(opt, (char *)"GET") == 0) { for (unit = Config.units; unit; unit = unit->next) { if (strcmp(param, unit->uuid) == 0) { - srv_send((char *)"213 Unit %s listing follows:", unit->uuid); + srv_send((char *)"213 Unit listing follows:"); srv_send((char *)"NAME,%s", unit->name); srv_send((char *)"UUID,%s", unit->uuid); srv_send((char *)"VOLUME,%2f", unit->volume); @@ -1088,7 +1088,7 @@ return 1; } } - srv_send((char *)"410 No such unit"); + srv_send((char *)"440 No such unit"); return 1; } @@ -1297,12 +1297,12 @@ } } } - srv_send((char *)"440 No such device"); + srv_send((char *)"440 No such unit"); return 1; } - srv_send((char *)"502 Unknown command option"); + srv_send((char *)"504 Subcommand error"); return 1; } @@ -1382,7 +1382,7 @@ srv_send((char *)"."); } else if (strncmp(buf, "LCD", 3) == 0) { #ifdef HAVE_WIRINGPI_H - srv_send((char *)"201 information follows"); + srv_send((char *)"201 Information follows"); for (j = 0; j < 4; j++) { sprintf(obuf, " "); obuf[20] = '\0'; @@ -1403,8 +1403,6 @@ if (cmd_unit(buf) == 0) wrconfig(); } else { - if (debug) - fprintf(stdout, "unknown command \"%s\"\n", buf); srv_send((char *)"500 Unknown command"); } } diff -r a76cbe676bf1 -r 2317b8d644fa thermferm/thermferm.c --- a/thermferm/thermferm.c Sun Aug 10 20:01:17 2014 +0200 +++ b/thermferm/thermferm.c Sun Aug 10 21:22:17 2014 +0200 @@ -16,7 +16,7 @@ * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with EC-65K; see the file COPYING. If not, write to the Free + * along with ThermFerm; see the file COPYING. If not, write to the Free * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *****************************************************************************/ @@ -33,9 +33,6 @@ #include "xutil.h" -//int tempA = 80; -//int tempB = 80; - int my_shutdown = FALSE; static pid_t pgrp, mypid; @@ -268,8 +265,6 @@ rc = devices_detect(); if (rc) { syslog(LOG_NOTICE, "Detected %d new devices", rc); - if (debug) - fprintf(stdout, "Detected %d new devices\n", rc); wrconfig(); } diff -r a76cbe676bf1 -r 2317b8d644fa thermferm/xutil.c --- a/thermferm/xutil.c Sun Aug 10 20:01:17 2014 +0200 +++ b/thermferm/xutil.c Sun Aug 10 21:22:17 2014 +0200 @@ -16,7 +16,7 @@ * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with EC-65K; see the file COPYING. If not, write to the Free + * along with ThermFerm; see the file COPYING. If not, write to the Free * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *****************************************************************************/