diff -r a08a1fce439e -r 805f1d285acd thermferm/thermferm.c --- a/thermferm/thermferm.c Thu Jun 19 15:49:29 2014 +0200 +++ b/thermferm/thermferm.c Fri Jun 20 17:42:36 2014 +0200 @@ -22,8 +22,6 @@ #include "thermferm.h" -#ifdef HAVE_WIRINGPI_H - int tempA = 80; int tempB = 80; @@ -38,17 +36,21 @@ extern bool debug; extern sys_config Config; +#ifdef HAVE_WIRINGPI_H extern int lcdHandle; extern unsigned char lcdbuf[MAX_LCDS][20][4]; +#endif int lcdupdate; int server(void); void help(void); void die(int); +#ifdef HAVE_WIRINGPI_H void sendRCswitch(char *, int); void stopLCD(void); void stopRCswitch(void); +#endif @@ -79,6 +81,7 @@ +#ifdef HAVE_WIRINGPI_H void sendRCswitch(char *address, int state) { char *cmd = NULL; @@ -95,9 +98,10 @@ syslog(LOG_NOTICE, "Switch %s rc=%d", cmd, rc); free(cmd); } +#endif - +#ifdef HAVE_WIRINGPI_H void stopLCD(void) { mb_lcdClear(lcdHandle); @@ -124,6 +128,7 @@ cmd = NULL; } } +#endif @@ -131,7 +136,9 @@ { int rc, c, i; pid_t frk; +#ifdef HAVE_WIRINGPI_H char buf[80]; +#endif while (1) { int option_index = 0; @@ -174,6 +181,7 @@ signal(i, (void (*))die); } +#ifdef HAVE_WIRINGPI_H if (wiringPiSetup () ) return 1; @@ -195,6 +203,7 @@ syslog(LOG_NOTICE, "Using 433 MHz transmitter on pin %d", Config.tx433); enableTransmit(Config.tx433); } +#endif if (debug) { /* @@ -220,7 +229,9 @@ case -1: syslog(LOG_NOTICE, "Daemon fork failed: %s", strerror(errno)); syslog(LOG_NOTICE, "Finished, rc=1"); +#ifdef HAVE_WIRINGPI_H stopLCD(); +#endif exit(1); case 0: /* * Run the daemon @@ -265,14 +276,18 @@ char buf[1024]; time_t now, last = (time_t)0; w1_therm *tmp1; +#ifdef HAVE_WIRINGPI_H rc_switch *tmp2; - int rc, run = 1, temp; + int rc; +#endif + int run = 1, temp; if (lockprog((char *)"thermferm")) { syslog(LOG_NOTICE, "Can't lock"); return 1; } +#ifdef HAVE_WIRINGPI_H rc = piThreadCreate(my_sensors_loop); if (rc) { fprintf(stderr, "my_sensors_loop thread didn't start rc=%d\n", rc); @@ -284,6 +299,7 @@ fprintf(stderr, "my_server_loop thread didn't start rc=%d\n", rc); syslog(LOG_NOTICE, "my_server_loop thread didn't start rc=%d", rc); } +#endif snprintf(buf, 1023, "tempA,coolerA,tempB,coolerB"); logger((char *)"thermferm.log", (char *)"thermferm", buf); @@ -295,17 +311,23 @@ run = 0; tmp1 = Config.w1therms; +#ifdef HAVE_WIRINGPI_H tmp2 = Config.rcswitch; +#endif if (((tmp1->lastval / 100) < (tempA - 5)) && (coolerA == 1)) { coolerA = 0; syslog(LOG_NOTICE, "Temperature A is %.1f, switched cooler off", (tmp1->lastval / 1000.0)); +#ifdef HAVE_WIRINGPI_H sendRCswitch(tmp2->address, 0); +#endif lcdupdate = TRUE; } if (((tmp1->lastval / 100) > (tempA + 5)) && (coolerA == 0)) { coolerA = 1; syslog(LOG_NOTICE, "Temperature A is %.1f, switched cooler on", (tmp1->lastval / 1000.0)); +#ifdef HAVE_WIRINGPI_H sendRCswitch(tmp2->address, 1); +#endif lcdupdate = TRUE; } if (tmp1->update) { @@ -313,17 +335,23 @@ lcdupdate = TRUE; } tmp1 = tmp1->next; +#ifdef HAVE_WIRINGPI_H tmp2 = tmp2->next; +#endif if (((tmp1->lastval / 100) < (tempB - 5)) && (coolerB == 1)) { coolerB = 0; syslog(LOG_NOTICE, "Temperature B is %.1f, switched cooler off", (tmp1->lastval / 1000.0)); +#ifdef HAVE_WIRINGPI_H sendRCswitch(tmp2->address, 0); +#endif lcdupdate = TRUE; } if (((tmp1->lastval / 100) > (tempB + 5)) && (coolerB == 0)) { coolerB = 1; syslog(LOG_NOTICE, "Temperature B is %.1f, switched cooler on", (tmp1->lastval / 1000.0)); +#ifdef HAVE_WIRINGPI_H sendRCswitch(tmp2->address, 1); +#endif lcdupdate = TRUE; } if (tmp1->update) { @@ -331,6 +359,7 @@ lcdupdate = TRUE; } +#ifdef HAVE_WIRINGPI_H if (run && lcdupdate) { lcdPosition(lcdHandle, 0, 0); tmp1 = Config.w1therms; @@ -342,6 +371,7 @@ snprintf(buf, 16, "%5.2f %cC %c %s ", tmp1->lastval / 1000.0, 0xdf, coolerB ? '-' : ' ', tmp1->alias); mb_lcdPuts(lcdHandle, buf); } +#endif now = time(NULL); if (((int)now - (int)last) > 60) { @@ -367,12 +397,14 @@ */ usleep(1500000); +#ifdef HAVE_WIRINGPI_H if (Config.tx433 != -1) { stopRCswitch(); } stopLCD(); disableTransmit(); +#endif wrconfig((char *)"thermferm.conf"); @@ -384,15 +416,3 @@ return 0; } -#else - - -int main(int argc, char *argv[]) -{ - fprintf(stderr, "Compiled on a system without a wiringPi library.\n"); - fprintf(stderr, "This program is useless and will do nothing.\n"); - return 0; -} - - -#endif