Thu, 31 Jul 2014 21:04:06 +0200
Added Raspberry GPIO devices
--- a/thermferm/devices.c Thu Jul 31 19:29:54 2014 +0200 +++ b/thermferm/devices.c Thu Jul 31 21:04:06 2014 +0200 @@ -37,12 +37,14 @@ int devices_detect(void) { struct dirent *de; -// FILE *fp; DIR *fd; devices_list *device, *ndev; int found, subdevices, i, rc = 0; - char family[3]; + char buf[40]; uuid_t uu; +#ifdef HAVE_WIRINGPI_H + int pin; +#endif /* * Scan for 1-wire devices @@ -59,12 +61,12 @@ } if (found == FALSE) { - strncpy(family, de->d_name, 2); - family[2] = '\0'; + strncpy(buf, de->d_name, 2); + buf[2] = '\0'; subdevices = 1; - if (strcmp(family, (char *)"29") == 0) + if (strcmp(buf, (char *)"29") == 0) subdevices = 8; - if (strcmp(family, (char *)"3a") == 0) + if (strcmp(buf, (char *)"3a") == 0) subdevices = 2; for (i = 0; i < subdevices; i++) { ndev = (devices_list *)malloc(sizeof(devices_list)); @@ -75,21 +77,21 @@ uuid_unparse(uu, ndev->uuid); ndev->type = DEVTYPE_W1; ndev->direction = DEVDIR_UNDEF; - if (strcmp(family, (char *)"10") == 0) { + if (strcmp(buf, (char *)"10") == 0) { ndev->direction = DEVDIR_IN_ANALOG; - ndev->description = xstrcpy((char *)"18S20,Digital thermometer"); - } else if (strcmp(family, (char *)"28") == 0) { + ndev->description = xstrcpy((char *)"DS18S20 Digital thermometer"); + } else if (strcmp(buf, (char *)"28") == 0) { ndev->direction = DEVDIR_IN_ANALOG; - ndev->description = xstrcpy((char *)"18B20,Digital thermometer"); - } else if (strcmp(family, (char *)"29") == 0) { - ndev->description = xstrcpy((char *)"2408,8 Channel addressable switch/LCD"); - } else if (strcmp(family, (char *)"3a") == 0) { - ndev->description = xstrcpy((char *)"2413,Dual channel addressable switch"); - } else if (strcmp(family, (char *)"w1") == 0) { + ndev->description = xstrcpy((char *)"DS18B20 Digital thermometer"); + } else if (strcmp(buf, (char *)"29") == 0) { + ndev->description = xstrcpy((char *)"DS2408 8 Channel addressable switch/LCD"); + } else if (strcmp(buf, (char *)"3a") == 0) { + ndev->description = xstrcpy((char *)"DS2413 Dual channel addressable switch"); + } else if (strcmp(buf, (char *)"w1") == 0) { ndev->description = xstrcpy((char *)"Master System device"); } else { ndev->description = xstrcpy((char *)"Unknown device family "); - ndev->description = xstrcat(ndev->description, family); + ndev->description = xstrcat(ndev->description, buf); } ndev->value = ndev->inuse = 0; ndev->present = DEVPRESENT_YES; @@ -116,6 +118,72 @@ } } +#ifdef HAVE_WIRINGPI_H + if (piBoardRev() == 2) { + /* + * Support rev B boards only + */ + found = FALSE; + for (device = Config.devices; device; device = device->next) { + if (device->type == DEVTYPE_GPIO) { + found = TRUE; + break; + } + } + + if (found == FALSE) { + /* + * There were no GPIO devices found. + */ + subdevices = 12; + pin = 0; + for (i = 0; i < subdevices; i++) { + if (i == 8) + pin = 17; + + 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_GPIO; + ndev->value = digitalRead(pin); + ndev->present = DEVPRESENT_YES; + snprintf(buf, 39, "GPIO%d", i); + ndev->address = xstrcpy(buf); + snprintf(buf, 39, "Raspberry GPIO %d", i); + ndev->description = xstrcpy(buf); + ndev->subdevice = i; + ndev->gpiopin = pin; + ndev->timestamp = time(NULL); + if (i == 7) { + ndev->direction = DEVDIR_INTERN; + ndev->inuse = 1; + ndev->comment = xstrcpy((char *)"1-Wire bus"); + } else { + ndev->direction = DEVDIR_IN_BIN; + ndev->inuse = 0; + ndev->comment = xstrcpy((char *)"Raspberry GPIO"); + } + pin++; + + 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; }
--- a/thermferm/rdconfig.c Thu Jul 31 19:29:54 2014 +0200 +++ b/thermferm/rdconfig.c Thu Jul 31 21:04:06 2014 +0200 @@ -37,7 +37,7 @@ const char PROFSTATE[4][6] = { "OFF", "PAUSE", "RUN", "DONE" }; const char DEVTYPE[7][6] = { "NA", "W1", "GPIO", "RC433", "DHT", "I2C", "SPI" }; const char DEVPRESENT[4][6] = { "UNDEF", "NO", "YES", "ERROR" }; -const char DEVDIR[6][11] = { "UNDEF", "IN_BIN", "OUT_BIN", "IN_ANALOG", "OUT_ANALOG", "OUT_PWM" }; +const char DEVDIR[7][11] = { "UNDEF", "IN_BIN", "OUT_BIN", "IN_ANALOG", "OUT_ANALOG", "OUT_PWM", "INTERN" }; @@ -1131,7 +1131,7 @@ } if ((!xmlStrcmp(cur->name, (const xmlChar *)"DIRECTION"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - for (i = 0; i < 6; i++) { + for (i = 0; i < 7; i++) { if (! xmlStrcmp(key, (const xmlChar *)DEVDIR[i])) { device->direction = i; break;
--- a/thermferm/thermferm.h Thu Jul 31 19:29:54 2014 +0200 +++ b/thermferm/thermferm.h Thu Jul 31 21:04:06 2014 +0200 @@ -100,12 +100,6 @@ #define UNITMODE_BEER 3 /* Unit acts as beer cooler */ #define UNITMODE_PROFILE 4 /* Unit runs in profile mode */ -#define UNITIO1_HEATER 0x01 /* Heater bit */ -#define UNITIO1_COOLER 0x02 /* Cooler bit */ -#define UNITIO2_FAN 0x01 /* Fan bit */ -#define UNITIO2_DOOR 0x02 /* Door status */ - - /* * Fermenting steps @@ -174,7 +168,7 @@ #define DEVDIR_IN_ANALOG 3 /* Temperature input etc. */ #define DEVDIR_OUT_ANALOG 4 /* Analog steering */ #define DEVDIR_OUT_PWM 5 /* PWM outout */ - +#define DEVDIR_INTERN 6 /* Internal function */ typedef struct _w1_therm { struct _w1_therm *next;