# HG changeset patch # User Michiel Broek # Date 1447017182 -3600 # Node ID 0bfe08c7ba6e1ddf58599ba90e387ec2e4639618 # Parent 9943f49fdb985b059177b4cb0bd3798cb43cc6af Reenabled code round LCD driver. diff -r 9943f49fdb98 -r 0bfe08c7ba6e thermferm/lcd-buffer.c --- a/thermferm/lcd-buffer.c Sun Nov 08 21:24:52 2015 +0100 +++ b/thermferm/lcd-buffer.c Sun Nov 08 22:13:02 2015 +0100 @@ -26,8 +26,6 @@ #include "panel.h" -#ifdef HAVE_WIRINGPI_H - int current_lines = 0; int current_offset = 0; lcd_rows *my_lcd_rows = NULL; @@ -149,8 +147,10 @@ return; } +#ifdef HAVE_WIRINGPI_H lcdPosition(lcdHandle, 0, r); lcdPuts(lcdHandle, tmp->row); +#endif r++; if (r < Config.lcd_rows) { @@ -158,11 +158,11 @@ tmp = tmp->next; else tmp = my_lcd_rows; +#ifdef HAVE_WIRINGPI_H lcdPosition(lcdHandle, 0, r); lcdPuts(lcdHandle, tmp->row); +#endif } } - -#endif diff -r 9943f49fdb98 -r 0bfe08c7ba6e thermferm/panel.h --- a/thermferm/panel.h Sun Nov 08 21:24:52 2015 +0100 +++ b/thermferm/panel.h Sun Nov 08 22:13:02 2015 +0100 @@ -2,7 +2,6 @@ #define _PANEL_H -#ifdef HAVE_WIRINGPI_H /* * GPIO pins for the frontpanel LED and push buttons. @@ -25,6 +24,8 @@ #define KEY_ALL 99 +#ifdef HAVE_WIRINGPI_H + int keycheck(void); diff -r 9943f49fdb98 -r 0bfe08c7ba6e thermferm/rdconfig.c --- a/thermferm/rdconfig.c Sun Nov 08 21:24:52 2015 +0100 +++ b/thermferm/rdconfig.c Sun Nov 08 22:13:02 2015 +0100 @@ -130,10 +130,8 @@ Config.simulators = NULL; #endif -#ifdef HAVE_WIRINGPI_H Config.lcd_cols = 16; Config.lcd_rows = 2; -#endif } @@ -241,7 +239,6 @@ return 1; } -#ifdef HAVE_WIRINGPI_H /* * Start an element named "LCDS" as child of THERMFERM. */ @@ -287,7 +284,6 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement"); return 1; } -#endif /* * Fermenter units @@ -960,7 +956,6 @@ /* * Parse one LCD display */ -#ifdef HAVE_WIRINGPI_H int parseLCD(xmlDocPtr doc, xmlNodePtr cur) { xmlChar *key; @@ -1005,7 +1000,6 @@ } return 0; } -#endif @@ -2047,11 +2041,9 @@ if ((!xmlStrcmp(cur->name, (const xmlChar *)"HUM_ADDRESS"))) { Config.hum_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } -#ifdef HAVE_WIRINGPI_H if ((!xmlStrcmp(cur->name, (const xmlChar *)"LCDS"))) { parseLCDs(doc, cur); } -#endif if ((!xmlStrcmp(cur->name, (const xmlChar *)"FERMENTERS"))) { parseFermenters(doc, cur); } diff -r 9943f49fdb98 -r 0bfe08c7ba6e thermferm/server.c --- a/thermferm/server.c Sun Nov 08 21:24:52 2015 +0100 +++ b/thermferm/server.c Sun Nov 08 22:13:02 2015 +0100 @@ -1002,10 +1002,8 @@ srv_send((char *)"HUM_ADDRESS,%s", Config.hum_address); srv_send((char *)"HUM_STATE,%s", TEMPSTATE[Config.hum_state]); srv_send((char *)"HUM_VALUE,%.0f", Config.hum_value / 1000.0); -#ifdef HAVE_WIRINGPI_H srv_send((char *)"LCD_COLS,%d", Config.lcd_cols); srv_send((char *)"LCD_ROWS,%d", Config.lcd_rows); -#endif srv_send((char *)"."); return 0; } @@ -1074,7 +1072,6 @@ } else Config.hum_address = NULL; -#ifdef HAVE_WIRINGPI_H } else if (val && (strcmp(kwd, (char *)"LCD_COLS") == 0)) { if (sscanf(val, "%d", &ival) == 1) { if (Config.lcd_cols != ival) @@ -1088,7 +1085,6 @@ syslog(LOG_NOTICE, "Global LCD rows %d to %d", Config.lcd_rows, ival); Config.lcd_rows = ival; } -#endif } } } @@ -2036,9 +2032,7 @@ } } } -#ifdef HAVE_WIRINGPI_H lcd_buf_reset(); -#endif run_pause = FALSE; syslog(LOG_NOTICE, "Unit %s added", unit->uuid); @@ -2058,9 +2052,7 @@ } rc = delete_Unit(param); -#ifdef HAVE_WIRINGPI_H lcd_buf_reset(); -#endif run_pause = FALSE; if (rc) { diff -r 9943f49fdb98 -r 0bfe08c7ba6e thermferm/thermferm.c --- a/thermferm/thermferm.c Sun Nov 08 21:24:52 2015 +0100 +++ b/thermferm/thermferm.c Sun Nov 08 22:13:02 2015 +0100 @@ -42,13 +42,11 @@ extern int debug; extern sys_config Config; -#ifdef HAVE_WIRINGPI_H extern int lcdHandle; int setupmenu = MENU_NONE; units_list *current_unit = NULL; /* In panel editor this points to the current unit. */ profiles_list *current_profile = NULL; float temp_temp = 20.0; -#endif #ifndef HAVE_WIRINGPI_H pthread_t threads[5]; @@ -60,9 +58,9 @@ int server(void); void help(void); void die(int); +void stopLCD(void); #ifdef HAVE_WIRINGPI_H void sendRCswitch(char *, int); -void stopLCD(void); void stopRCswitch(void); #endif @@ -99,14 +97,15 @@ -#ifdef HAVE_WIRINGPI_H void show_mode(void) { char buf[21]; snprintf(buf, 20, "Old mode %s", UNITMODE[current_unit->mode]); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, buf); lcdPosition(lcdHandle, 0, 1); +#endif } @@ -115,132 +114,197 @@ { char buf[21]; +#ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); piLock(LOCK_MENU); lcdClear(lcdHandle); lcdPosition(lcdHandle, 0, 0); +#endif syslog(LOG_NOTICE, "from menu %d to menu %d", setupmenu, menu); setupmenu = menu; switch (menu) { - case MENU_NONE: lcd_buf_show(); + case MENU_NONE: +#ifdef HAVE_WIRINGPI_H + lcd_buf_show(); +#endif break; - case MENU_TOP_DEFAULT: lcdPuts(lcdHandle, "Setup mode."); + case MENU_TOP_DEFAULT: +#ifdef HAVE_WIRINGPI_H + lcdPuts(lcdHandle, "Setup mode."); lcdPosition(lcdHandle, 0, 1); lcdPuts(lcdHandle, "Up&Down = Escape"); +#endif break; - case MENU_TOP_UNITS: lcdPuts(lcdHandle, "Select units"); + case MENU_TOP_UNITS: +#ifdef HAVE_WIRINGPI_H + lcdPuts(lcdHandle, "Select units"); +#endif break; - case MENU_UNITS: lcdPuts(lcdHandle, "Choose unit:"); + case MENU_UNITS: +#ifdef HAVE_WIRINGPI_H + lcdPuts(lcdHandle, "Choose unit:"); lcdPosition(lcdHandle, 0, 1); lcdPuts(lcdHandle, current_unit->name); +#endif break; case MENU_MODE_OFF: show_mode(); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, "New mode OFF"); +#endif break; case MENU_MODE_NONE: show_mode(); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, "New mode NONE"); +#endif break; case MENU_NONE_HEAT: snprintf(buf, Config.lcd_cols, "Set heater %s", current_unit->heater_state ? "OFF":"ON"); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, buf); +#endif break; case MENU_NONE_COOL: snprintf(buf, Config.lcd_cols, "Set cooler %s", current_unit->cooler_state ? "OFF":"ON"); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, buf); +#endif break; case MENU_NONE_FAN: snprintf(buf, Config.lcd_cols, "Set fan %s", current_unit->fan_state ? "OFF":"ON"); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, buf); +#endif break; case MENU_MODE_BEER: show_mode(); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, "New mode BEER"); +#endif break; - case MENU_BEER_TEMP: lcdPuts(lcdHandle, "Set beer temp"); + case MENU_BEER_TEMP: +#ifdef HAVE_WIRINGPI_H + lcdPuts(lcdHandle, "Set beer temp"); lcdPosition(lcdHandle, 0, 1); +#endif snprintf(buf, Config.lcd_cols, "Set %.1f", temp_temp); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, buf); +#endif break; case MENU_MODE_FRIDGE: show_mode(); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, "New mode FRIDGE"); +#endif break; - case MENU_FRIDGE_TEMP: lcdPuts(lcdHandle, "Set fridge temp"); + case MENU_FRIDGE_TEMP: +#ifdef HAVE_WIRINGPI_H + lcdPuts(lcdHandle, "Set fridge temp"); lcdPosition(lcdHandle, 0, 1); +#endif snprintf(buf, Config.lcd_cols, "Set %.1f", temp_temp); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, buf); +#endif break; case MENU_MODE_PROFILE: show_mode(); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, "New mode PROFILE"); +#endif break; case MENU_PROFILE_SELECT: snprintf(buf, Config.lcd_cols, "%s", current_profile->name); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, buf); lcdPosition(lcdHandle, 0, 1); lcdPuts(lcdHandle, "Select profile"); +#endif break; case MENU_PROFILE_START: snprintf(buf, Config.lcd_cols, "%s", current_profile->name); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, buf); lcdPosition(lcdHandle, 0, 1); lcdPuts(lcdHandle, "Start profile"); +#endif break; case MENU_PROFILE_PAUSE: snprintf(buf, Config.lcd_cols, "%s", current_profile->name); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, buf); lcdPosition(lcdHandle, 0, 1); lcdPuts(lcdHandle, "Pause profile"); +#endif break; case MENU_PROFILE_ABORT: snprintf(buf, Config.lcd_cols, "%s", current_profile->name); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, buf); lcdPosition(lcdHandle, 0, 1); lcdPuts(lcdHandle, "Abort profile"); +#endif break; case MENU_PROFILE_RESUME: snprintf(buf, Config.lcd_cols, "%s", current_profile->name); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, buf); lcdPosition(lcdHandle, 0, 1); lcdPuts(lcdHandle, "Resume profile"); +#endif break; case MENU_PROFILE_GOOFF: snprintf(buf, Config.lcd_cols, "%s", current_profile->name); +#ifdef HAVE_WIRINGPI_H lcdPuts(lcdHandle, buf); lcdPosition(lcdHandle, 0, 1); lcdPuts(lcdHandle, "Set profile OFF"); +#endif break; - case MENU_TOP_SYS: lcdPuts(lcdHandle, "System menu"); + case MENU_TOP_SYS: +#ifdef HAVE_WIRINGPI_H + lcdPuts(lcdHandle, "System menu"); +#endif break; - case MENU_SYS_HALT: lcdPuts(lcdHandle, "Halt system"); + case MENU_SYS_HALT: +#ifdef HAVE_WIRINGPI_H + lcdPuts(lcdHandle, "Halt system"); +#endif break; - case MENU_SYS_REBOOT: lcdPuts(lcdHandle, "Reboot system"); + case MENU_SYS_REBOOT: +#ifdef HAVE_WIRINGPI_H + lcdPuts(lcdHandle, "Reboot system"); +#endif break; } +#ifdef HAVE_WIRINGPI_H piUnlock(LOCK_MENU); piUnlock(LOCK_LCD); +#endif } void stopLCD(void) { +#ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); lcdClear(lcdHandle); setBacklight(0); piUnlock(LOCK_LCD); +#endif } @@ -275,9 +339,6 @@ } -#endif - - /* * Handle panel key events @@ -769,9 +830,7 @@ switch (frk) { case -1: syslog(LOG_NOTICE, "Daemon fork failed: %s", strerror(errno)); -#ifdef HAVE_WIRINGPI_H stopLCD(); -#endif exit(1); case 0: /* * Run the daemon @@ -819,11 +878,11 @@ units_list *unit; profiles_list *profile; prof_step *step; - int rc, run = 1, seconds = 0, minutes = 0, temp, deviation; + int row, rc, run = 1, seconds = 0, minutes = 0, temp, deviation; int run_seconds, run_minutes, run_hours, tot_minutes; + struct tm *tm; #ifdef HAVE_WIRINGPI_H - struct tm *tm; - int row, key; + int key; #else long t = 0; #endif @@ -920,8 +979,10 @@ #ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); +#endif lcd_buf_write(1, (char *)" ThermFerm "); lcd_buf_write(2, (char *)" Version %s ", VERSION); +#ifdef HAVE_WIRINGPI_H piUnlock(LOCK_LCD); #endif @@ -957,8 +1018,10 @@ * In case the LCD buffers were cleared, setup the first page. */ piLock(LOCK_LCD); +#endif lcd_buf_write(1, (char *)" ThermFerm "); lcd_buf_write(2, (char *)" Version %s ", VERSION); +#ifdef HAVE_WIRINGPI_H piUnlock(LOCK_LCD); #endif } @@ -971,12 +1034,14 @@ last = now; seconds++; -#ifdef HAVE_WIRINGPI_H row = 3; tm = localtime(&now); +#ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); +#endif lcd_buf_write(row++, " %02d-%02d-%04d ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900); lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); +#ifdef HAVE_WIRINGPI_H piUnlock(LOCK_LCD); #endif @@ -987,7 +1052,9 @@ Config.temp_state = 0; #ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); +#endif lcd_buf_write(row++, "Room temp %.1f %cC ", Config.temp_value / 1000.0, 0xdf); +#ifdef HAVE_WIRINGPI_H piUnlock(LOCK_LCD); #endif } else if (rc == DEVPRESENT_ERROR) { @@ -1004,7 +1071,9 @@ Config.hum_state = 0; #ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); +#endif lcd_buf_write(row++, " Humidity %.1f %% ", Config.hum_value / 1000.0, 0xdf); +#ifdef HAVE_WIRINGPI_H piUnlock(LOCK_LCD); #endif } else if (rc == DEVPRESENT_ERROR) { @@ -1017,8 +1086,10 @@ for (unit = Config.units; unit; unit = unit->next) { #ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); +#endif lcd_buf_write(row++, "Unit %s ", unit->name); lcd_buf_write(row++, "Mode %s ", UNITMODE[unit->mode]); +#ifdef HAVE_WIRINGPI_H piUnlock(LOCK_LCD); #endif @@ -1040,7 +1111,9 @@ unit->air_state = 0; #ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); +#endif lcd_buf_write(row++, " Air %.3f %cC ", unit->air_temperature / 1000.0, 0xdf); +#ifdef HAVE_WIRINGPI_H piUnlock(LOCK_LCD); #endif } else { @@ -1066,7 +1139,9 @@ unit->beer_state = 0; #ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); +#endif lcd_buf_write(row++, "Beer %.3f %cC ", unit->beer_temperature / 1000.0, 0xdf); +#ifdef HAVE_WIRINGPI_H piUnlock(LOCK_LCD); #endif } else { @@ -1335,18 +1410,21 @@ if (unit->light_address && unit->light_state) unit->light_usage++; + if (unit->heater_address && unit->cooler_address) { #ifdef HAVE_WIRINGPI_H - if (unit->heater_address && unit->cooler_address) { - piLock(LOCK_LCD); - if (unit->heater_state) { + piLock(LOCK_LCD); +#endif + if (unit->heater_state) { lcd_buf_write(row++, "Heater On "); } else if (unit->cooler_state) { lcd_buf_write(row++, "Cooler On "); } else { lcd_buf_write(row++, "Standby "); } +#ifdef HAVE_WIRINGPI_H piUnlock(LOCK_LCD); piLock(LOCK_LCD); +#endif switch (unit->mode) { case UNITMODE_BEER: lcd_buf_write(row++, "Target %.1f %cC ", unit->beer_set, 0xdf); break; @@ -1359,18 +1437,23 @@ break; default: lcd_buf_write(row++, "Target not set "); } +#ifdef HAVE_WIRINGPI_H piUnlock(LOCK_LCD); +#endif } else { - piLock(LOCK_LCD); +#ifdef HAVE_WIRINGPI_H + piLock(LOCK_LCD); +#endif if (unit->heater_address) { lcd_buf_write(row++, "Heat %s ", unit->heater_state ? "On ":"Off"); } if (unit->cooler_address) { lcd_buf_write(row++, "Cool %s ", unit->cooler_state ? "On ":"Off"); } +#ifdef HAVE_WIRINGPI_H piUnlock(LOCK_LCD); +#endif } -#endif /* * Interior lights @@ -1553,11 +1636,17 @@ #ifdef HAVE_WIRINGPI_H piLock(LOCK_MENU); +#endif if (setupmenu == MENU_NONE) { - piLock(LOCK_LCD); +#ifdef HAVE_WIRINGPI_H + piLock(LOCK_LCD); +#endif lcd_buf_show(); +#ifdef HAVE_WIRINGPI_H piUnlock(LOCK_LCD); +#endif } +#ifdef HAVE_WIRINGPI_H piUnlock(LOCK_MENU); #endif @@ -1676,10 +1765,7 @@ */ usleep(1500000); -#ifdef HAVE_WIRINGPI_H stopLCD(); -#endif - wrconfig(); ulockprog((char *)"thermferm"); return 0; diff -r 9943f49fdb98 -r 0bfe08c7ba6e thermferm/thermferm.h --- a/thermferm/thermferm.h Sun Nov 08 21:24:52 2015 +0100 +++ b/thermferm/thermferm.h Sun Nov 08 22:13:02 2015 +0100 @@ -55,6 +55,7 @@ #define LOCK_MENU 2 #define LOCK_SPARE2 3 +#endif /* @@ -84,7 +85,6 @@ #define MENU_SYS_HALT 31 #define MENU_SYS_REBOOT 32 -#endif /* @@ -314,11 +314,9 @@ 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 */