thermferm/devices.c

changeset 161
493e39bb0a08
parent 158
f1b7e2ef90be
child 162
6fc9e3f7962f
equal deleted inserted replaced
160:87bfa951ffc2 161:493e39bb0a08
39 struct dirent *de; 39 struct dirent *de;
40 // FILE *fp; 40 // FILE *fp;
41 DIR *fd; 41 DIR *fd;
42 devices_list *device, *ndev; 42 devices_list *device, *ndev;
43 int found, subdevices, i, rc = 0; 43 int found, subdevices, i, rc = 0;
44 char *family; 44 char family[3];
45 uuid_t uu; 45 uuid_t uu;
46 46
47 /* 47 /*
48 * Scan for 1-wire devices 48 * Scan for 1-wire devices
49 */ 49 */
50 if ((fd = opendir((char *)"/sys/bus/w1/devices"))) { 50 if ((fd = opendir((char *)"/sys/bus/w1/devices"))) {
51 while ((de = readdir(fd))) { 51 while ((de = readdir(fd))) {
52 if (de->d_name[0] != '.') { 52 if (de->d_name[0] != '.') {
53 found = FALSE; 53 found = FALSE;
54 for (device = Config.devices; device; device = device->next) { 54 for (device = Config.devices; device; device = device->next) {
55 if (strcmp(device->address ,de->d_name) == 0) { 55 if (strcmp(device->address,de->d_name) == 0) {
56 found = TRUE; 56 found = TRUE;
57 break; 57 break;
58 } 58 }
59 } 59 }
60 60
61 if (found == FALSE) { 61 if (found == FALSE) {
62 family = malloc(3);
63 strncpy(family, de->d_name, 2); 62 strncpy(family, de->d_name, 2);
63 family[2] = '\0';
64 subdevices = 1; 64 subdevices = 1;
65 if (strcmp(family, (char *)"29") == 0) 65 if (strcmp(family, (char *)"29") == 0)
66 subdevices = 8; 66 subdevices = 8;
67 if (strcmp(family, (char *)"3a") == 0) 67 if (strcmp(family, (char *)"3a") == 0)
68 subdevices = 2; 68 subdevices = 2;
101 101
102 if (Config.devices == NULL) { 102 if (Config.devices == NULL) {
103 Config.devices = ndev; 103 Config.devices = ndev;
104 } else { 104 } else {
105 for (device = Config.devices; device; device = device->next) { 105 for (device = Config.devices; device; device = device->next) {
106 if (device->next == NULL) 106 if (device->next == NULL) {
107 device->next = ndev; 107 device->next = ndev;
108 break; 108 break;
109 }
109 } 110 }
110 } 111 }
111 rc++; 112 rc++;
112 } 113 }
113 } 114 }

mercurial