diff -r e02393b29733 -r b7c967359771 thermferm/devices.c --- a/thermferm/devices.c Wed Aug 20 22:15:12 2014 +0200 +++ b/thermferm/devices.c Fri Aug 22 17:12:42 2014 +0200 @@ -213,6 +213,11 @@ if ((device->type == DEVTYPE_W1) && (device->direction == DEVDIR_OUT_BIN) && (device->present == DEVPRESENT_YES)) { } +#ifdef USE_SIMULATOR + if ((device->type == DEVTYPE_SIM) && (device->direction == DEVDIR_OUT_BIN) && (device->present == DEVPRESENT_YES)) { + + } +#endif } else { return 0; } @@ -393,6 +398,70 @@ } #endif +#ifdef USE_SIMULATOR + found = FALSE; + for (device = Config.devices; device; device = device->next) { + if (device->type == DEVTYPE_SIM) { + found = TRUE; + break; + } + } + + if (found == FALSE) { + subdevices = 5; + for (i = 0; i < subdevices; i++) { + ndev = (devices_list *)malloc(sizeof(devices_list)); + ndev->next = NULL; + ndev->version = 1; + ndev->uuid = malloc(37); + uuid_generate(uu); + uuid_unparse(uu, ndev->uuid); + ndev->type = DEVTYPE_SIM; + ndev->value = ndev->offset = 0; + ndev->present = DEVPRESENT_YES; + ndev->subdevice = i; + ndev->gpiopin = -1; + ndev->comment = xstrcpy((char *)"Auto detected device"); + ndev->timestamp = time(NULL); + ndev->inuse = 0; + switch (i) { + case 0: ndev->direction = DEVDIR_IN_ANALOG; + ndev->address = xstrcpy((char *)"SimRoomTemp"); + ndev->description = xstrcpy((char *)"Simulated room temperature"); + break; + case 1: ndev->direction = DEVDIR_IN_ANALOG; + ndev->address = xstrcpy((char *)"SimAirTemp"); + ndev->description = xstrcpy((char *)"Simulated air temperature"); + break; + case 2: ndev->direction = DEVDIR_IN_ANALOG; + ndev->address = xstrcpy((char *)"SimBeerTemp"); + ndev->description = xstrcpy((char *)"Simulated beer temperature"); + break; + case 3: ndev->direction = DEVDIR_OUT_ANALOG; + ndev->address = xstrcpy((char *)"SimHeater"); + ndev->description = xstrcpy((char *)"Simulated heater"); + break; + case 4: ndev->direction = DEVDIR_OUT_ANALOG; + ndev->address = xstrcpy((char *)"SimCooler"); + ndev->description = xstrcpy((char *)"Simulated cooler"); + break; + } + + if (Config.devices == NULL) { + Config.devices = ndev; + } else { + for (device = Config.devices; device; device = device->next) { + if (device->next == NULL) { + device->next = ndev; + break; + } + } + } + rc++; + } + } +#endif + return rc; } @@ -536,7 +605,26 @@ } break; #endif - +#ifdef USE_SIMULATOR + case DEVTYPE_SIM: +#ifdef HAVE_WIRINGPI_H + piLock(LOCK_DEVICES); +#endif + if (device->subdevice == 0) { + device->value = 20000; + device->timestamp = time(NULL); + } else if (device->subdevice == 1) { + device->value = 20125; + device->timestamp = time(NULL); + } else if (device->subdevice == 2) { + device->value = 20250; + device->timestamp = time(NULL); + } +#ifdef HAVE_WIRINGPI_H + piUnlock(LOCK_DEVICES); +#endif + break; +#endif default: break; }