summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--anzeige.c71
1 files changed, 43 insertions, 28 deletions
diff --git a/anzeige.c b/anzeige.c
index 6f906d9..d235e10 100644
--- a/anzeige.c
+++ b/anzeige.c
@@ -68,6 +68,7 @@ int main(int argc, char **argv)
char *text_buffer;
char *text_buffer_end;
char text_buffers[OUTPUT_IDX_MAX][MAX_TEXT_OUTPUT_LEN];
+ char output_text_buffer[MAX_TEXT_OUTPUT_LEN];
char humidity_text_buffer[MAX_TEXT_OUTPUT_LEN];
double outside_temperature = 0, outside_humidity = 0, inside_temperature = 0, inside_humidity = 0;
int updated = 0;
@@ -81,9 +82,12 @@ int main(int argc, char **argv)
}
memset(text_buffer, 0, TEXT_BUFFER_LENGTH);
memset(text_buffers, 0, OUTPUT_IDX_MAX * MAX_TEXT_OUTPUT_LEN);
+ memset(output_text_buffer, 0, MAX_TEXT_OUTPUT_LEN);
- for (int i=0; i<THREAD_IDX_MAX; i++)
+ for (int i=0; i<THREAD_IDX_MAX; i++) {
input_threads[i].keep_running = 1;
+ input_threads[i].last_update = 0;
+ }
pthread_create(&input_threads[THREAD_IDX_WARNINGS].thread_id, NULL, gadgets_watch_weather_warnings, &input_threads[THREAD_IDX_WARNINGS]);
pthread_create(&input_threads[THREAD_IDX_OUTSIDE].thread_id, NULL, gadgets_watch_current_temperature, &input_threads[THREAD_IDX_OUTSIDE]);
@@ -98,35 +102,45 @@ int main(int argc, char **argv)
for (int i=0; i<THREAD_IDX_MAX; i++)
input_threads[i].force_update = 1;
}
- for (int i=0; i<THREAD_IDX_MAX; i++)
- if (input_threads[i].output_ready) {
- if (strcmp(text_buffers[i], input_threads[i].text_output)) {
- strncpy(text_buffers[i], input_threads[i].text_output, MAX_TEXT_OUTPUT_LEN);
+ for (int i=0; i<THREAD_IDX_MAX; i++) {
+ int outdated = (input_threads[i].last_update < time(NULL) - 3600);
+ if (input_threads[i].output_ready || outdated) {
+ if (outdated)
+ snprintf(output_text_buffer, MAX_TEXT_OUTPUT_LEN, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 0xEE, 0x01, 0xEE, 0x02, 0xEE, 0x01, 0xEE, 0x02, 0xEE, 0x05, 0xEE, 0x06, 0xEE, 0x05, 0xEE, 0x06);
+ else
+ strncpy(output_text_buffer, input_threads[i].text_output, MAX_TEXT_OUTPUT_LEN);
+ if (strcmp(text_buffers[i], output_text_buffer)) {
+ strncpy(text_buffers[i], output_text_buffer, MAX_TEXT_OUTPUT_LEN);
updated = 1;
}
- if (i == THREAD_IDX_OUTSIDE) {
- if (outside_temperature != input_threads[i].double_output[0])
- outside_temperature = input_threads[i].double_output[0];
- if (outside_humidity != input_threads[i].double_output[1])
- outside_humidity = input_threads[i].double_output[1];
- }
- if (i == THREAD_IDX_INSIDE) {
- if (inside_temperature != input_threads[i].double_output[0])
- inside_temperature = input_threads[i].double_output[0];
- if (inside_humidity != input_threads[i].double_output[1])
- inside_humidity = input_threads[i].double_output[1];
- }
- if (((i == THREAD_IDX_OUTSIDE) || (i == THREAD_IDX_INSIDE)) &&
- ((outside_temperature!=0) || (outside_humidity!=0)) &&
- ((inside_temperature!=0) || (inside_humidity!=0))) {
- gadgets_calculate_humidity_level(
- humidity_text_buffer,
- MAX_TEXT_OUTPUT_LEN,
- outside_temperature,
- outside_humidity,
- inside_temperature,
- inside_humidity
- );
+ if ((i == THREAD_IDX_OUTSIDE) || (i == THREAD_IDX_INSIDE)) {
+ if (outdated) {
+ snprintf(humidity_text_buffer, MAX_TEXT_OUTPUT_LEN, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 0xEE, 0x01, 0xEE, 0x02, 0xEE, 0x01, 0xEE, 0x02, 0xEE, 0x05, 0xEE, 0x06, 0xEE, 0x05, 0xEE, 0x06);
+ } else {
+ if (i == THREAD_IDX_OUTSIDE) {
+ if (outside_temperature != input_threads[i].double_output[0])
+ outside_temperature = input_threads[i].double_output[0];
+ if (outside_humidity != input_threads[i].double_output[1])
+ outside_humidity = input_threads[i].double_output[1];
+ }
+ if (i == THREAD_IDX_INSIDE) {
+ if (inside_temperature != input_threads[i].double_output[0])
+ inside_temperature = input_threads[i].double_output[0];
+ if (inside_humidity != input_threads[i].double_output[1])
+ inside_humidity = input_threads[i].double_output[1];
+ }
+ if (((outside_temperature!=0) || (outside_humidity!=0)) &&
+ ((inside_temperature!=0) || (inside_humidity!=0))) {
+ gadgets_calculate_humidity_level(
+ humidity_text_buffer,
+ MAX_TEXT_OUTPUT_LEN,
+ outside_temperature,
+ outside_humidity,
+ inside_temperature,
+ inside_humidity
+ );
+ }
+ }
if (strcmp(text_buffers[THREAD_IDX_INSIDE], humidity_text_buffer)) {
strncpy(text_buffers[THREAD_IDX_INSIDE], humidity_text_buffer, MAX_TEXT_OUTPUT_LEN);
updated = 1;
@@ -134,6 +148,7 @@ int main(int argc, char **argv)
}
input_threads[i].output_ready = 0;
}
+ }
if (updated)
updated ++;
if (updated > 15) {