summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--anzeige.c49
-rw-r--r--input_gadgets.c18
-rw-r--r--input_gadgets.h4
3 files changed, 47 insertions, 24 deletions
diff --git a/anzeige.c b/anzeige.c
index 7e50547..31e036f 100644
--- a/anzeige.c
+++ b/anzeige.c
@@ -20,7 +20,7 @@ int main(int argc, char **argv)
pthread_t thread_id;
t_display_data display_data;
int ret_val;
- char *text_buffer;
+ unsigned char *text_buffer;
// Set up gpi pointer for direct register access
ret_val = multiplexer_setup_root();
@@ -30,13 +30,6 @@ int main(int argc, char **argv)
// Drop root privileges
drop_privileges();
- ret_val = gadgets_retrieve_temperature(&text_buffer);
- if (ret_val)
- exit(ret_val);
- printf("<<%s>>", text_buffer);
- free(text_buffer);
- return 0;
-
/************************************************************************\
* You are about to change the GPIO settings of your computer. *
* Mess this up and it will stop working! *
@@ -47,13 +40,45 @@ int main(int argc, char **argv)
// configure the gpio pins and start the multiplexer thread
thread_id = multiplexer_setup_non_root(&display_data);
- for (int i=0; i<20; i++) {
- usleep(2500000);
- for (int j=0; j<39; j++)
- display_data.buf[(display_data.should_buf+1)%3][j] = symbols[(40*i+j)%sizeof(symbols)];
+ int i,j,k;
+
+ text_buffer = malloc(8);
+ if (text_buffer == NULL) {
+ fprintf(stderr, "malloc failed to allocate 8 bytes\n");
+ exit(EXIT_FAILURE);
+ }
+
+ for (i=0; i<20; i++) {
+// usleep(2500000);
+// if (i & 0x01) {
+ ret_val = gadgets_retrieve_temperature(text_buffer,sizeof(text_buffer));
+ if (ret_val) {
+ free(text_buffer);
+ exit(ret_val);
+ }
+ for (j=0; j<39; j++)
+ display_data.buf[(display_data.should_buf+1)%3][j] = 0x00;
+ for (j=0; (j<7) && (text_buffer[j]); j++) {
+ text_buffer[j] = text_buffer[j] & 0xff;
+ printf("%02x %c\n",text_buffer[j],text_buffer[j]);
+ if (text_buffer[j] >= 0x7f) {
+ if (text_buffer[j] <= 0xaf)
+ continue;
+ text_buffer[j] -= 0xaf - 0x7f + 1;
+ }
+ text_buffer[j] -= 0x20;
+ if ((text_buffer[j] < 0) || (text_buffer[j] >= (sizeof(symbols)/5))) {
+ printf("EXCESS: %d %d %d\n", text_buffer[j], (text_buffer[j] < 0), (text_buffer[j] >= (sizeof(symbols)/5)));
+ continue;
+ }
+ for (k=0; k<5; k++)
+ display_data.buf[(display_data.should_buf+1)%3][6*j+k] = symbols[5*(text_buffer[j])+k];
+// }
+ }
display_data.should_buf = (display_data.should_buf+1)%3;
}
+ free(text_buffer);
display_data.keep_running = 0;
pthread_join(thread_id, NULL);
diff --git a/input_gadgets.c b/input_gadgets.c
index 7aeb09a..00a2d36 100644
--- a/input_gadgets.c
+++ b/input_gadgets.c
@@ -28,7 +28,7 @@ WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
return realsize;
}
-int gadgets_retrieve_temperature(char **output)
+int gadgets_retrieve_temperature(unsigned char *output, int max_len)
{
CURL *curl_handle;
CURLcode res;
@@ -78,15 +78,13 @@ int gadgets_retrieve_temperature(char **output)
return EXIT_FAILURE;
}
regfree(&re);
- output[0] = malloc((int)(rm[1].rm_eo - rm[1].rm_so + 1));
- if (output[0] == NULL) {
- fprintf(stderr, "malloc failed allocating %d bytes\n", (int)(rm[1].rm_eo - rm[1].rm_so + 1));
- free(chunk.memory);
- return EXIT_FAILURE;
- }
- printf("allocated %d bytes\n", (int)(rm[1].rm_eo - rm[1].rm_so + 1));
- memmove(output[0], chunk.memory + rm[1].rm_so, (int)(rm[1].rm_eo - rm[1].rm_so));
- output[0][(int)(rm[1].rm_eo - rm[1].rm_so)] = '\0';
+ if ((int)(rm[1].rm_eo - rm[1].rm_so) < max_len - 1)
+ max_len = (int)(rm[1].rm_eo - rm[1].rm_so) + 1;
+ memmove(output, chunk.memory + rm[1].rm_so, max_len - 1);
+ output[max_len - 1] = '\0';
+ for (int i=0; i<max_len; i++)
+ if (output[i] == '.')
+ output[i] = ',';
free(chunk.memory);
return 0;
}
diff --git a/input_gadgets.h b/input_gadgets.h
index 9aef167..bedf94b 100644
--- a/input_gadgets.h
+++ b/input_gadgets.h
@@ -1,6 +1,6 @@
struct MemoryStruct {
- char *memory;
+ unsigned char *memory;
size_t size;
};
-int gadgets_retrieve_temperature(char **output);
+int gadgets_retrieve_temperature(unsigned char *output, int max_len);