1012 units_list *unit; |
1007 units_list *unit; |
1013 prof_step *step; |
1008 prof_step *step; |
1014 int row, rc, run = 1, seconds = 0, minutes = 0, temp; |
1009 int row, rc, run = 1, seconds = 0, minutes = 0, temp; |
1015 int run_seconds, run_minutes, run_hours, tot_minutes, key; |
1010 int run_seconds, run_minutes, run_hours, tot_minutes, key; |
1016 struct tm *tm; |
1011 struct tm *tm; |
1017 #ifndef HAVE_WIRINGPI_H |
|
1018 long t = 0; |
1012 long t = 0; |
1019 #endif |
|
1020 int current_step, valid_step, time_until_now, previous_fridge_mode; |
1013 int current_step, valid_step, time_until_now, previous_fridge_mode; |
1021 float previous_target_lo, previous_target_hi; |
1014 float previous_target_lo, previous_target_hi; |
1022 float LCDair, LCDbeer, LCDspL, LCDspH; |
1015 float LCDair, LCDbeer, LCDspL, LCDspH; |
1023 unsigned char LCDstatC, LCDstatH; |
1016 unsigned char LCDstatC, LCDstatH; |
1024 int LCDunit; |
1017 int LCDunit; |
1034 if ((rc = devices_detect())) { |
1027 if ((rc = devices_detect())) { |
1035 syslog(LOG_NOTICE, "Detected %d new devices", rc); |
1028 syslog(LOG_NOTICE, "Detected %d new devices", rc); |
1036 wrconfig(); |
1029 wrconfig(); |
1037 } |
1030 } |
1038 |
1031 |
1039 #ifdef HAVE_WIRINGPI_H |
|
1040 rc = piThreadCreate(my_devices_loop); |
|
1041 #else |
|
1042 rc = pthread_create(&threads[t], NULL, my_devices_loop, (void *)t ); |
1032 rc = pthread_create(&threads[t], NULL, my_devices_loop, (void *)t ); |
1043 #endif |
|
1044 if (rc) { |
1033 if (rc) { |
1045 fprintf(stderr, "my_devices_loop thread didn't start rc=%d\n", rc); |
1034 fprintf(stderr, "my_devices_loop thread didn't start rc=%d\n", rc); |
1046 syslog(LOG_NOTICE, "my_devices_loop thread didn't start rc=%d", rc); |
1035 syslog(LOG_NOTICE, "my_devices_loop thread didn't start rc=%d", rc); |
1047 #ifndef HAVE_WIRINGPI_H |
|
1048 } else { |
1036 } else { |
1049 t++; |
1037 t++; |
1050 #endif |
1038 } |
1051 } |
1039 |
1052 |
|
1053 #ifdef HAVE_WIRINGPI_H |
|
1054 rc = piThreadCreate(my_server_loop); |
|
1055 #else |
|
1056 rc = pthread_create(&threads[t], NULL, my_server_loop, (void *)t ); |
1040 rc = pthread_create(&threads[t], NULL, my_server_loop, (void *)t ); |
1057 #endif |
|
1058 if (rc) { |
1041 if (rc) { |
1059 fprintf(stderr, "my_server_loop thread didn't start rc=%d\n", rc); |
1042 fprintf(stderr, "my_server_loop thread didn't start rc=%d\n", rc); |
1060 syslog(LOG_NOTICE, "my_server_loop thread didn't start rc=%d", rc); |
1043 syslog(LOG_NOTICE, "my_server_loop thread didn't start rc=%d", rc); |
1061 #ifndef HAVE_WIRINGPI_H |
|
1062 } else { |
1044 } else { |
1063 t++; |
1045 t++; |
1064 #endif |
1046 } |
1065 } |
1047 |
1066 |
|
1067 #ifdef HAVE_WIRINGPI_H |
|
1068 rc = piThreadCreate(my_panel_loop); |
|
1069 #else |
|
1070 rc = pthread_create(&threads[t], NULL, my_panel_loop, (void *)t ); |
1048 rc = pthread_create(&threads[t], NULL, my_panel_loop, (void *)t ); |
1071 #endif |
|
1072 if (rc) { |
1049 if (rc) { |
1073 fprintf(stderr, "my_panel_loop thread didn't start rc=%d\n", rc); |
1050 fprintf(stderr, "my_panel_loop thread didn't start rc=%d\n", rc); |
1074 syslog(LOG_NOTICE, "my_panel_loop thread didn't start rc=%d", rc); |
1051 syslog(LOG_NOTICE, "my_panel_loop thread didn't start rc=%d", rc); |
1075 #ifndef HAVE_WIRINGPI_H |
|
1076 } else { |
1052 } else { |
1077 t++; |
1053 t++; |
1078 #endif |
|
1079 } |
1054 } |
1080 |
1055 |
1081 #ifdef USE_SIMULATOR |
1056 #ifdef USE_SIMULATOR |
1082 #ifdef HAVE_WIRINGPI_H |
|
1083 rc = piThreadCreate(my_simulator_loop); |
|
1084 #else |
|
1085 rc = pthread_create(&threads[t], NULL, my_simulator_loop, (void *)t ); |
1057 rc = pthread_create(&threads[t], NULL, my_simulator_loop, (void *)t ); |
1086 #endif |
|
1087 if (rc) { |
1058 if (rc) { |
1088 fprintf(stderr, "my_simulator_loop thread didn't start rc=%d\n", rc); |
1059 fprintf(stderr, "my_simulator_loop thread didn't start rc=%d\n", rc); |
1089 syslog(LOG_NOTICE, "my_simulator_loop thread didn't start rc=%d", rc); |
1060 syslog(LOG_NOTICE, "my_simulator_loop thread didn't start rc=%d", rc); |
1090 #ifndef HAVE_WIRINGPI_H |
|
1091 } else { |
1061 } else { |
1092 t++; |
1062 t++; |
1093 #endif |
|
1094 } |
1063 } |
1095 #endif |
1064 #endif |
1096 |
1065 |
1097 |
1066 |
1098 /* |
1067 /* |
1181 last = now; |
1141 last = now; |
1182 seconds++; |
1142 seconds++; |
1183 |
1143 |
1184 row = 3; |
1144 row = 3; |
1185 tm = localtime(&now); |
1145 tm = localtime(&now); |
1186 #ifdef HAVE_WIRINGPI_H |
1146 pthread_mutex_lock(&mutexes[LOCK_LCD]); |
1187 piLock(LOCK_LCD); |
|
1188 #endif |
|
1189 lcd_buf_write(row++, " %02d-%02d-%04d ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900); |
1147 lcd_buf_write(row++, " %02d-%02d-%04d ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900); |
1190 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); |
1148 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); |
1191 #ifdef HAVE_WIRINGPI_H |
1149 pthread_mutex_unlock(&mutexes[LOCK_LCD]); |
1192 piUnlock(LOCK_LCD); |
1150 |
1193 #endif |
1151 pthread_mutex_lock(&mutexes[LOCK_LCD]); |
1194 |
|
1195 #ifdef HAVE_WIRINGPI_H |
|
1196 piLock(LOCK_LCD); |
|
1197 #endif |
|
1198 lcd_buf_write(row, "Room temp N/A "); |
1152 lcd_buf_write(row, "Room temp N/A "); |
1199 #ifdef HAVE_WIRINGPI_H |
1153 pthread_mutex_unlock(&mutexes[LOCK_LCD]); |
1200 piUnlock(LOCK_LCD); |
|
1201 #endif |
|
1202 int updateHT = 0; |
1154 int updateHT = 0; |
1203 if (Config.temp_address) { |
1155 if (Config.temp_address) { |
1204 rc = device_in(Config.temp_address, &temp); |
1156 rc = device_in(Config.temp_address, &temp); |
1205 if (rc == DEVPRESENT_YES) { |
1157 if (rc == DEVPRESENT_YES) { |
1206 if (Config.temp_value != temp) |
1158 if (Config.temp_value != temp) |
1207 updateHT = 1; |
1159 updateHT = 1; |
1208 Config.temp_value = temp; |
1160 Config.temp_value = temp; |
1209 Config.temp_state = 0; |
1161 Config.temp_state = 0; |
1210 #ifdef HAVE_WIRINGPI_H |
1162 pthread_mutex_lock(&mutexes[LOCK_LCD]); |
1211 piLock(LOCK_LCD); |
|
1212 #endif |
|
1213 lcd_buf_write(row, "Room temp %.1f%c ", Config.temp_value / 1000.0, 0x01); |
1163 lcd_buf_write(row, "Room temp %.1f%c ", Config.temp_value / 1000.0, 0x01); |
1214 #ifdef HAVE_WIRINGPI_H |
1164 pthread_mutex_unlock(&mutexes[LOCK_LCD]); |
1215 piUnlock(LOCK_LCD); |
|
1216 #endif |
|
1217 } else if (rc == DEVPRESENT_ERROR) { |
1165 } else if (rc == DEVPRESENT_ERROR) { |
1218 Config.temp_state = 1; |
1166 Config.temp_state = 1; |
1219 } else { |
1167 } else { |
1220 Config.temp_state = 2; |
1168 Config.temp_state = 2; |
1221 } |
1169 } |
1222 usleep(10000); |
1170 usleep(10000); |
1223 } |
1171 } |
1224 row++; |
1172 row++; |
1225 |
1173 |
1226 #ifdef HAVE_WIRINGPI_H |
1174 pthread_mutex_lock(&mutexes[LOCK_LCD]); |
1227 piLock(LOCK_LCD); |
|
1228 #endif |
|
1229 lcd_buf_write(row, " Humidity N/A "); |
1175 lcd_buf_write(row, " Humidity N/A "); |
1230 #ifdef HAVE_WIRINGPI_H |
1176 pthread_mutex_unlock(&mutexes[LOCK_LCD]); |
1231 piUnlock(LOCK_LCD); |
|
1232 #endif |
|
1233 |
1177 |
1234 if (Config.hum_address) { |
1178 if (Config.hum_address) { |
1235 rc = device_in(Config.hum_address, &temp); |
1179 rc = device_in(Config.hum_address, &temp); |
1236 if (rc == DEVPRESENT_YES) { |
1180 if (rc == DEVPRESENT_YES) { |
1237 if (Config.hum_value != temp) |
1181 if (Config.hum_value != temp) |
1238 updateHT = 1; |
1182 updateHT = 1; |
1239 Config.hum_value = temp; |
1183 Config.hum_value = temp; |
1240 Config.hum_state = 0; |
1184 Config.hum_state = 0; |
1241 #ifdef HAVE_WIRINGPI_H |
1185 pthread_mutex_lock(&mutexes[LOCK_LCD]); |
1242 piLock(LOCK_LCD); |
|
1243 #endif |
|
1244 lcd_buf_write(row, " Humidity %.1f%% ", Config.hum_value / 1000.0); |
1186 lcd_buf_write(row, " Humidity %.1f%% ", Config.hum_value / 1000.0); |
1245 #ifdef HAVE_WIRINGPI_H |
1187 pthread_mutex_unlock(&mutexes[LOCK_LCD]); |
1246 piUnlock(LOCK_LCD); |
|
1247 #endif |
|
1248 } else if (rc == DEVPRESENT_ERROR) { |
1188 } else if (rc == DEVPRESENT_ERROR) { |
1249 Config.hum_state = 1; |
1189 Config.hum_state = 1; |
1250 } else { |
1190 } else { |
1251 Config.hum_state = 2; |
1191 Config.hum_state = 2; |
1252 } |
1192 } |
1841 // unit->mqtt_flag |= MQTT_FLAG_DATA; |
1781 // unit->mqtt_flag |= MQTT_FLAG_DATA; |
1842 // } |
1782 // } |
1843 if (seconds == 60) { |
1783 if (seconds == 60) { |
1844 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1784 unit->mqtt_flag |= MQTT_FLAG_DATA; |
1845 } |
1785 } |
1846 #ifdef HAVE_WIRINGPI_H |
1786 pthread_mutex_lock(&mutexes[LOCK_LCD]); |
1847 piLock(LOCK_LCD); |
|
1848 #endif |
|
1849 /* |
1787 /* |
1850 * Write 4 rows to the LCD to display the unit state |
1788 * Write 4 rows to the LCD to display the unit state |
1851 */ |
1789 */ |
1852 lcd_buf_write(row++, "Unit %d: %s ", LCDunit, UNITMODE[unit->mode]); |
1790 lcd_buf_write(row++, "Unit %d: %s ", LCDunit, UNITMODE[unit->mode]); |
1853 lcd_buf_write(row++, "%s ", unit->product_name); |
1791 lcd_buf_write(row++, "%s ", unit->product_name); |
1854 lcd_buf_write(row++, "%c%5.1f\2 A%6.2f\1 ", LCDstatC, LCDspH, LCDair); |
1792 lcd_buf_write(row++, "%c%5.1f\2 A%6.2f\1 ", LCDstatC, LCDspH, LCDair); |
1855 lcd_buf_write(row++, "%c%5.1f\2 B%6.2f\1 ", LCDstatH, LCDspL, LCDbeer); |
1793 lcd_buf_write(row++, "%c%5.1f\2 B%6.2f\1 ", LCDstatH, LCDspL, LCDbeer); |
1856 #ifdef HAVE_WIRINGPI_H |
1794 pthread_mutex_unlock(&mutexes[LOCK_LCD]); |
1857 piUnlock(LOCK_LCD); |
|
1858 #endif |
|
1859 |
1795 |
1860 /* |
1796 /* |
1861 * Publish MQTT messages set in flag |
1797 * Publish MQTT messages set in flag |
1862 */ |
1798 */ |
1863 if (unit->mqtt_flag) { |
1799 if (unit->mqtt_flag) { |
1881 syslog(LOG_NOTICE, "Unit `%s' Alarm %d => %d", unit->alias, unit->alarm_last, unit->alarm_flag); |
1817 syslog(LOG_NOTICE, "Unit `%s' Alarm %d => %d", unit->alias, unit->alarm_last, unit->alarm_flag); |
1882 unit->alarm_last = unit->alarm_flag; |
1818 unit->alarm_last = unit->alarm_flag; |
1883 } |
1819 } |
1884 } /* for units */ |
1820 } /* for units */ |
1885 |
1821 |
1886 #ifdef HAVE_WIRINGPI_H |
1822 pthread_mutex_lock(&mutexes[LOCK_MENU]); |
1887 piLock(LOCK_MENU); |
|
1888 #endif |
|
1889 if (setupmenu == MENU_NONE) { |
1823 if (setupmenu == MENU_NONE) { |
1890 #ifdef HAVE_WIRINGPI_H |
1824 pthread_mutex_lock(&mutexes[LOCK_LCD]); |
1891 piLock(LOCK_LCD); |
|
1892 #endif |
|
1893 lcd_buf_show(); |
1825 lcd_buf_show(); |
1894 #ifdef HAVE_WIRINGPI_H |
1826 pthread_mutex_unlock(&mutexes[LOCK_LCD]); |
1895 piUnlock(LOCK_LCD); |
|
1896 #endif |
|
1897 } |
1827 } |
1898 #ifdef HAVE_WIRINGPI_H |
1828 pthread_mutex_unlock(&mutexes[LOCK_MENU]); |
1899 piUnlock(LOCK_MENU); |
|
1900 #endif |
|
1901 |
1829 |
1902 if (seconds == 60) { |
1830 if (seconds == 60) { |
1903 seconds = 0; |
1831 seconds = 0; |
1904 |
1832 |
1905 /* |
1833 /* |