# HG changeset patch # User Michiel Broek # Date 1711192694 -3600 # Node ID 49eb753a958bc7d37887b54543a62c100c2b2e1f # Parent 07cc869004730b4b35a88d2ef66fd60fa2f6f2dd All thread locks from wiringPi to standard pthreads. diff -r 07cc86900473 -r 49eb753a958b thermferm/devices.c --- a/thermferm/devices.c Sat Mar 23 09:31:01 2024 +0100 +++ b/thermferm/devices.c Sat Mar 23 12:18:14 2024 +0100 @@ -29,6 +29,7 @@ extern sys_config Config; extern int my_shutdown; +extern pthread_mutex_t mutexes[5]; #ifdef USE_SIMULATOR @@ -39,6 +40,7 @@ #endif + #ifdef HAVE_WIRINGPI_H #define MAXTIMINGS 100 @@ -299,10 +301,7 @@ return 0; now = time(NULL); - -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); for (device = Config.devices; device; device = device->next) { if (! strcmp(uuid, device->uuid)) { @@ -329,15 +328,15 @@ for (i = 0; i < strlen(buf); i++) if (buf[i] == '-') buf[i] = ','; - piUnlock(LOCK_DEVICES); + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); enableTransmit(device->gpiopin); rc = toggleSwitch(buf); disableTransmit(); - piLock(LOCK_DEVICES); + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); syslog(LOG_NOTICE, "RC433 command %s rc=%d", buf, rc); device->value = value; device->timestamp = time(NULL); - piUnlock(LOCK_DEVICES); + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); return rc; } @@ -398,17 +397,13 @@ } #endif } else { -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); return 0; } // if ((test_value != my_value) || (((int)now - (int)my_timestamp) >= 120)) } // if (! strcmp(uuid, device->uuid)) } // for (device = Config.devices; device; device = device->next) -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); return 0; } @@ -425,9 +420,7 @@ if (uuid == NULL) return 0; -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); for (device = Config.devices; device; device = device->next) { if (! strcmp(uuid, device->uuid)) { @@ -437,18 +430,13 @@ } else { tmp = 0; } -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); *value = tmp; return present; } } -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif - + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); return DEVPRESENT_NO; } @@ -552,6 +540,10 @@ closedir(fd); } + /* + * DHT11 as kernel module. + */ + #ifdef HAVE_WIRINGPI_H if (piBoardRev() == 2) { /* @@ -597,7 +589,7 @@ } else if (i == 3) { ndev->direction = DEVDIR_INTERN; ndev->inuse = 1; - ndev->comment = xstrcpy((char *)"DHT11 room sensor"); + ndev->comment = xstrcpy((char *)"DHT11 sensor"); } else if (i == PANEL_LED) { ndev->direction = DEVDIR_OUT_BIN; ndev->inuse = 1; @@ -725,11 +717,7 @@ -#ifdef HAVE_WIRINGPI_H -PI_THREAD (my_devices_loop) -#else void *my_devices_loop(void *threadid) -#endif { devices_list *device; #ifdef USE_SIMULATOR @@ -815,13 +803,9 @@ /* CRC is Ok, continue */ if (device->present != DEVPRESENT_YES) { syslog(LOG_NOTICE, "sensor %s is Ok", device->address); -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); device->present = DEVPRESENT_YES; -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } line2[strlen(line2)-1] = '\0'; @@ -829,9 +813,7 @@ p = strtok(NULL, (char *)"="); rc = sscanf(p, "%d", &temp); if ((rc == 1) && (device->value != temp)) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (temp < -55000) { syslog(LOG_NOTICE, "sensor %s value error '%d` '%s`", device->address, temp, line1); device->present = DEVPRESENT_ERROR; @@ -840,30 +822,20 @@ device->timestamp = time(NULL); device->present = DEVPRESENT_YES; } -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } } else { syslog(LOG_NOTICE, "sensor %s CRC error '%s`", device->address, line1); -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); device->present = DEVPRESENT_ERROR; -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } } else { if (device->present != DEVPRESENT_NO) { syslog(LOG_NOTICE, "sensor %s is missing", device->address); -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); device->present = DEVPRESENT_NO; -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } } free(addr); @@ -880,13 +852,9 @@ if ((access(addr, R_OK)) == 0) { if (device->present != DEVPRESENT_YES) { syslog(LOG_NOTICE, "DS2413 %s is back", device->address); -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); device->present = DEVPRESENT_YES; -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } /* * First make sure that if this device is configured as input @@ -911,9 +879,7 @@ } } if ((rc = read_w1(device->address, (char *)"state")) >= 0) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); /* * Read PIOA or PIOB pin state bits */ @@ -922,20 +888,14 @@ else if (device->subdevice == 1) device->value = (rc & 0x04) ? 0 : 1; device->timestamp = time(NULL); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } } else { if (device->present != DEVPRESENT_NO) { syslog(LOG_NOTICE, "DS2413 %s is missing", device->address); -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); device->present = DEVPRESENT_NO; -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } } free(addr); @@ -956,7 +916,7 @@ /* Read once during subdevice 0 */ dht11_pin = device->gpiopin; dht11Read(); - piLock(LOCK_DEVICES); + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (dht11_valid) { device->value = dht11_temperature * 1000; device->timestamp = time(NULL); @@ -964,10 +924,10 @@ } else { device->present = DEVPRESENT_ERROR; } - piUnlock(LOCK_DEVICES); + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } else if (device->subdevice == 1) { /* Data already present */ - piLock(LOCK_DEVICES); + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (dht11_valid) { device->value = dht11_humidity * 1000; device->timestamp = time(NULL); @@ -975,7 +935,7 @@ } else { device->present = DEVPRESENT_ERROR; } - piUnlock(LOCK_DEVICES); + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); dht11_last = now; /* Okay for a new reading. */ } } @@ -983,20 +943,18 @@ case DEVTYPE_GPIO: if (device->direction == DEVDIR_IN_BIN) { - piLock(LOCK_DEVICES); + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); device->value = digitalRead(device->gpiopin); device->offset = 0; device->timestamp = time(NULL); - piUnlock(LOCK_DEVICES); + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } break; #endif #ifdef USE_SIMULATOR case DEVTYPE_SIM: -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (Config.simulators) { simulator = Config.simulators; if (device->subdevice == 0) { @@ -1016,9 +974,7 @@ device->timestamp = time(NULL); } } -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); break; #endif default: diff -r 07cc86900473 -r 49eb753a958b thermferm/panel.c --- a/thermferm/panel.c Sat Mar 23 09:31:01 2024 +0100 +++ b/thermferm/panel.c Sat Mar 23 12:18:14 2024 +0100 @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (C) 2014 + * Copyright (C) 2014-2024 * * Michiel Broek * @@ -51,6 +51,7 @@ extern uint16_t keys; extern uint16_t leds; extern int slcdHandle; +extern pthread_mutex_t mutexes[5]; int Key_Enter = FALSE; int Key_Enter_Long = FALSE; @@ -186,13 +187,9 @@ /* * Any key is pressed. */ -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); -#endif + pthread_mutex_lock(&mutexes[LOCK_LCD]); setBacklight(1); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_LCD); -#endif + pthread_mutex_unlock(&mutexes[LOCK_LCD]); Backlight = LCD_SLEEP; menutimer = 0; } else { @@ -208,21 +205,15 @@ if (AnyKey == FALSE) { if (Backlight == 1) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); -#endif + pthread_mutex_lock(&mutexes[LOCK_LCD]); setBacklight(0); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_LCD); -#endif + pthread_mutex_unlock(&mutexes[LOCK_LCD]); } if (Backlight > 0) { Backlight--; } -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_MENU); -#endif + pthread_mutex_lock(&mutexes[LOCK_MENU]); if (setupmenu != MENU_NONE) { if (menutimer < MENU_TIMEOUT) menutimer++; @@ -230,9 +221,7 @@ setupmenu = MENU_NONE; } } -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_MENU); -#endif + pthread_mutex_unlock(&mutexes[LOCK_MENU]); } } diff -r 07cc86900473 -r 49eb753a958b thermferm/rdconfig.c --- a/thermferm/rdconfig.c Sat Mar 23 09:31:01 2024 +0100 +++ b/thermferm/rdconfig.c Sat Mar 23 12:18:14 2024 +0100 @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (C) 2014-2022 + * Copyright (C) 2014-2024 * * Michiel Broek * @@ -26,8 +26,9 @@ #include "futil.h" #include "xutil.h" -int debug = FALSE; -sys_config Config; /* System configuration */ +int debug = FALSE; +sys_config Config; /* System configuration */ +extern pthread_mutex_t mutexes[5]; #define MY_ENCODING "utf-8" @@ -401,9 +402,7 @@ if (Config.devices) { xmlTextWriterStartElement(writer, BAD_CAST "DEVICES"); -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); for (device = Config.devices; device; device = device->next) { xmlTextWriterStartElement(writer, BAD_CAST "DEVICE"); xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", device->uuid); @@ -421,9 +420,7 @@ xmlTextWriterWriteFormatElement(writer, BAD_CAST "TIMESTAMP", "%d", (int)device->timestamp); xmlTextWriterEndElement(writer); // close DEVICE } -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); xmlTextWriterEndElement(writer); // close DEVICES } diff -r 07cc86900473 -r 49eb753a958b thermferm/server.c --- a/thermferm/server.c Sat Mar 23 09:31:01 2024 +0100 +++ b/thermferm/server.c Sat Mar 23 12:18:14 2024 +0100 @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (C) 2008-2022 + * Copyright (C) 2008-2024 * * Michiel Broek * @@ -41,6 +41,7 @@ extern const char DEVPRESENT[4][6]; extern const char DEVDIR[7][11]; extern const char PROFSTATE[5][6]; +extern pthread_mutex_t mutexes[5]; int s; /* connected socket */ @@ -166,18 +167,14 @@ for (device = Config.devices; device; device = device->next) { if (strcmp(device->uuid, uuid) == 0) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (plus == TRUE) { device->inuse++; } else { if (device->inuse) device->inuse--; } -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } } } @@ -371,9 +368,7 @@ device->description = xstrcpy((char *)"Describe me here"); device->comment = xstrcpy((char *)"Comment here"); -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (Config.devices == NULL) { Config.devices = device; } else { @@ -384,9 +379,7 @@ } } } -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); syslog(LOG_NOTICE, "Device %s added", device->uuid); srv_send((char *)"211 Device %s added", device->uuid); return 1; @@ -399,13 +392,9 @@ if (strcmp(opt, (char *)"DEL") == 0) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); rc = delete_Device(param); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); if (rc) { syslog(LOG_NOTICE, "Device %s deleted", param); srv_send((char *)"211 Device %s deleted", param); @@ -419,14 +408,10 @@ if (strcmp(opt, (char *)"GET") == 0) { for (device = Config.devices; device; device = device->next) { if (strcmp(device->uuid, param) == 0) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); int my_value = device->value; int my_timestamp = (int)device->timestamp; -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); srv_send((char *)"213 Device record follows:"); srv_send((char *)"TYPE,%s", DEVTYPE[device->type]); srv_send((char *)"ADDRESS,%s", device->address); @@ -467,15 +452,11 @@ if (strcmp(kwd, (char *)"TYPE") == 0) { for (i = 0; i < 8; i++) { if (strcmp(val, DEVTYPE[i]) == 0) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (device->type != i) syslog(LOG_NOTICE, "Device %s changed type %s to %s", device->uuid, DEVTYPE[device->type], DEVTYPE[i]); device->type = i; -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); break; } } @@ -483,128 +464,92 @@ } else if (strcmp(kwd, (char *)"DIRECTION") == 0) { for (i = 0; i < 7; i++) { if (strcmp(val, DEVDIR[i]) == 0) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (device->direction != i) syslog(LOG_NOTICE, "Device %s changed direction %s to %s", device->uuid, DEVDIR[device->type], DEVDIR[i]); device->direction = i; -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); break; } } } else if (strcmp(kwd, (char *)"VALUE") == 0) { if (sscanf(val, "%d", &ival) == 1) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (device->value != ival) syslog(LOG_NOTICE, "Device %s changed value %d to %d", device->uuid, device->value, ival); device->value = ival; -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } } else if (strcmp(kwd, (char *)"OFFSET") == 0) { if (sscanf(val, "%d", &ival) == 1) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (device->offset != ival) syslog(LOG_NOTICE, "Device %s changed offset %d to %d", device->uuid, device->offset, ival); device->offset = ival; -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } } else if (strcmp(kwd, (char *)"PRESENT") == 0) { for (i = 0; i < 4; i++) { if (strcmp(val, DEVPRESENT[i]) == 0) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (device->present != i) syslog(LOG_NOTICE, "Device %s changed present %s to %s", device->uuid, DEVPRESENT[device->present], DEVPRESENT[i]); device->present = i; -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); break; } } } else if (strcmp(kwd, (char *)"ADDRESS") == 0) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (device->address) { if (strcmp(device->address, val)) syslog(LOG_NOTICE, "Device %s changed address `%s' to `%s'", device->uuid, device->address, val); free(device->address); } device->address = xstrcpy(val); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } else if (strcmp(kwd, (char *)"SUBDEVICE") == 0) { if (sscanf(val, "%d", &ival) == 1) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (device->subdevice != ival) syslog(LOG_NOTICE, "Device %s changed subdevice %d to %d", device->uuid, device->subdevice, ival); device->subdevice = ival; -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } } else if (strcmp(kwd, (char *)"GPIOPIN") == 0) { if (sscanf(val, "%d", &ival) == 1) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (device->gpiopin != ival) syslog(LOG_NOTICE, "Device %s changed gpiopin %d to %d", device->uuid, device->gpiopin, ival); device->gpiopin = ival; -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } } else if (strcmp(kwd, (char *)"DESCRIPTION") == 0) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (device->description) { if (strcmp(device->description, val)) syslog(LOG_NOTICE, "Device %s changed description `%s' to `%s'", device->uuid, device->description, val); free(device->description); } device->description = xstrcpy(val); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } else if (strcmp(kwd, (char *)"COMMENT") == 0) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); if (device->comment) { if (strcmp(device->comment, val)) syslog(LOG_NOTICE, "Device %s changed comment `%s' to `%s'", device->uuid, device->comment, val); free(device->comment); } device->comment = xstrcpy(val); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif + pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } } diff -r 07cc86900473 -r 49eb753a958b thermferm/thermferm.c --- a/thermferm/thermferm.c Sat Mar 23 09:31:01 2024 +0100 +++ b/thermferm/thermferm.c Sat Mar 23 12:18:14 2024 +0100 @@ -50,9 +50,8 @@ units_list *current_unit = NULL; /* In panel editor this points to the current unit. */ float temp_temp = 20.0; -#ifndef HAVE_WIRINGPI_H pthread_t threads[5]; -#endif +pthread_mutex_t mutexes[5]; extern const char UNITMODE[5][8]; extern const char PROFSTATE[4][6]; @@ -141,9 +140,9 @@ { char buf[21]; + pthread_mutex_lock(&mutexes[LOCK_LCD]); + pthread_mutex_lock(&mutexes[LOCK_MENU]); #ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); - piLock(LOCK_MENU); lcdClear(lcdHandle); lcdPosition(lcdHandle, 0, 0); #endif @@ -374,25 +373,21 @@ break; } -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_MENU); - piUnlock(LOCK_LCD); -#endif + pthread_mutex_unlock(&mutexes[LOCK_MENU]); + pthread_mutex_unlock(&mutexes[LOCK_LCD]); } void stopLCD(void) { + pthread_mutex_lock(&mutexes[LOCK_LCD]); #ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); lcdClear(lcdHandle); #endif slcdClear(slcdHandle); setBacklight(0); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_LCD); -#endif + pthread_mutex_unlock(&mutexes[LOCK_LCD]); } @@ -1014,9 +1009,7 @@ int row, rc, run = 1, seconds = 0, minutes = 0, temp; int run_seconds, run_minutes, run_hours, tot_minutes, key; struct tm *tm; -#ifndef HAVE_WIRINGPI_H long t = 0; -#endif int current_step, valid_step, time_until_now, previous_fridge_mode; float previous_target_lo, previous_target_hi; float LCDair, LCDbeer, LCDspL, LCDspH; @@ -1036,61 +1029,37 @@ wrconfig(); } -#ifdef HAVE_WIRINGPI_H - rc = piThreadCreate(my_devices_loop); -#else rc = pthread_create(&threads[t], NULL, my_devices_loop, (void *)t ); -#endif if (rc) { fprintf(stderr, "my_devices_loop thread didn't start rc=%d\n", rc); syslog(LOG_NOTICE, "my_devices_loop thread didn't start rc=%d", rc); -#ifndef HAVE_WIRINGPI_H } else { t++; -#endif } -#ifdef HAVE_WIRINGPI_H - rc = piThreadCreate(my_server_loop); -#else rc = pthread_create(&threads[t], NULL, my_server_loop, (void *)t ); -#endif if (rc) { 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); -#ifndef HAVE_WIRINGPI_H } else { t++; -#endif } -#ifdef HAVE_WIRINGPI_H - rc = piThreadCreate(my_panel_loop); -#else rc = pthread_create(&threads[t], NULL, my_panel_loop, (void *)t ); -#endif if (rc) { fprintf(stderr, "my_panel_loop thread didn't start rc=%d\n", rc); syslog(LOG_NOTICE, "my_panel_loop thread didn't start rc=%d", rc); -#ifndef HAVE_WIRINGPI_H } else { t++; -#endif } #ifdef USE_SIMULATOR -#ifdef HAVE_WIRINGPI_H - rc = piThreadCreate(my_simulator_loop); -#else rc = pthread_create(&threads[t], NULL, my_simulator_loop, (void *)t ); -#endif if (rc) { fprintf(stderr, "my_simulator_loop thread didn't start rc=%d\n", rc); syslog(LOG_NOTICE, "my_simulator_loop thread didn't start rc=%d", rc); -#ifndef HAVE_WIRINGPI_H } else { t++; -#endif } #endif @@ -1132,15 +1101,10 @@ } } -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); -#endif + pthread_mutex_lock(&mutexes[LOCK_LCD]); lcd_buf_write(1, (char *)" ThermFerm "); lcd_buf_write(2, (char *)" Version %s ", VERSION); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_LCD); -#endif - + pthread_mutex_unlock(&mutexes[LOCK_LCD]); do { if (my_shutdown) @@ -1160,17 +1124,13 @@ } syslog(LOG_NOTICE, "run_pause: leaving hold state"); run_hold = FALSE; -#ifdef HAVE_WIRINGPI_H /* * In case the LCD buffers were cleared, setup the first page. */ - piLock(LOCK_LCD); -#endif + pthread_mutex_lock(&mutexes[LOCK_LCD]); lcd_buf_write(1, (char *)" ThermFerm "); lcd_buf_write(2, (char *)" Version %s ", VERSION); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_LCD); -#endif + pthread_mutex_unlock(&mutexes[LOCK_LCD]); } now = time(NULL); @@ -1183,22 +1143,14 @@ row = 3; tm = localtime(&now); -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); -#endif + pthread_mutex_lock(&mutexes[LOCK_LCD]); 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 + pthread_mutex_unlock(&mutexes[LOCK_LCD]); -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); -#endif + pthread_mutex_lock(&mutexes[LOCK_LCD]); lcd_buf_write(row, "Room temp N/A "); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_LCD); -#endif + pthread_mutex_unlock(&mutexes[LOCK_LCD]); int updateHT = 0; if (Config.temp_address) { rc = device_in(Config.temp_address, &temp); @@ -1207,13 +1159,9 @@ updateHT = 1; Config.temp_value = temp; Config.temp_state = 0; -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); -#endif + pthread_mutex_lock(&mutexes[LOCK_LCD]); lcd_buf_write(row, "Room temp %.1f%c ", Config.temp_value / 1000.0, 0x01); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_LCD); -#endif + pthread_mutex_unlock(&mutexes[LOCK_LCD]); } else if (rc == DEVPRESENT_ERROR) { Config.temp_state = 1; } else { @@ -1223,13 +1171,9 @@ } row++; -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); -#endif + pthread_mutex_lock(&mutexes[LOCK_LCD]); lcd_buf_write(row, " Humidity N/A "); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_LCD); -#endif + pthread_mutex_unlock(&mutexes[LOCK_LCD]); if (Config.hum_address) { rc = device_in(Config.hum_address, &temp); @@ -1238,13 +1182,9 @@ updateHT = 1; Config.hum_value = temp; Config.hum_state = 0; -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); -#endif + pthread_mutex_lock(&mutexes[LOCK_LCD]); lcd_buf_write(row, " Humidity %.1f%% ", Config.hum_value / 1000.0); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_LCD); -#endif + pthread_mutex_unlock(&mutexes[LOCK_LCD]); } else if (rc == DEVPRESENT_ERROR) { Config.hum_state = 1; } else { @@ -1843,9 +1783,7 @@ if (seconds == 60) { unit->mqtt_flag |= MQTT_FLAG_DATA; } -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); -#endif + pthread_mutex_lock(&mutexes[LOCK_LCD]); /* * Write 4 rows to the LCD to display the unit state */ @@ -1853,9 +1791,7 @@ lcd_buf_write(row++, "%s ", unit->product_name); lcd_buf_write(row++, "%c%5.1f\2 A%6.2f\1 ", LCDstatC, LCDspH, LCDair); lcd_buf_write(row++, "%c%5.1f\2 B%6.2f\1 ", LCDstatH, LCDspL, LCDbeer); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_LCD); -#endif + pthread_mutex_unlock(&mutexes[LOCK_LCD]); /* * Publish MQTT messages set in flag @@ -1883,21 +1819,13 @@ } } /* for units */ -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_MENU); -#endif + pthread_mutex_lock(&mutexes[LOCK_MENU]); if (setupmenu == MENU_NONE) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_LCD); -#endif + pthread_mutex_lock(&mutexes[LOCK_LCD]); lcd_buf_show(); -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_LCD); -#endif + pthread_mutex_unlock(&mutexes[LOCK_LCD]); } -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_MENU); -#endif + pthread_mutex_unlock(&mutexes[LOCK_MENU]); if (seconds == 60) { seconds = 0; diff -r 07cc86900473 -r 49eb753a958b thermferm/thermferm.h --- a/thermferm/thermferm.h Sat Mar 23 09:31:01 2024 +0100 +++ b/thermferm/thermferm.h Sat Mar 23 12:18:14 2024 +0100 @@ -37,9 +37,7 @@ #include #include #include -#ifndef HAVE_WIRINGPI_H #include -#endif #include #include #include @@ -52,6 +50,7 @@ #include #include +#endif /* * Thread locks @@ -60,8 +59,7 @@ #define LOCK_LCD 1 #define LOCK_MENU 2 #define LOCK_SPARE2 3 - -#endif +#define LOCK_SPARE3 4 /*