summaryrefslogtreecommitdiff
path: root/devel/libg19/files/patch-libg19.c
blob: 08ddda41b265eb4ffbecf4eca103a4922c0b6ae6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--- libg19.c.orig	2010-04-13 04:13:54.000000000 +0200
+++ libg19.c	2011-04-16 08:25:58.000000000 +0200
@@ -20,6 +20,7 @@
 #include <libusb.h>
 #include <pthread.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
@@ -353,52 +354,54 @@
 }
 
 /**
- * Sends raw data to the lcd without formatting
+ * Sends the data to screen
  * 
  * @param data pointer to the screen data
- * @param len amount of data to be written in bytes
+ * @param size size of the data to be written in bytes
+ * @param flags options for the function to use for updating
  **/
-void g19_update_lcd(unsigned char * data, int len)
+void g19_update_lcd(unsigned char * data, size_t size, unsigned int flags)
 {
-	struct libusb_transfer * lcd_transfer = libusb_alloc_transfer(0);
-	lcd_transfer -> flags = LIBUSB_TRANSFER_FREE_TRANSFER;
-	
-	libusb_fill_bulk_transfer(lcd_transfer, g19_devh, 0x02, data, len, NULL, NULL, 0);
-	libusb_submit_transfer(lcd_transfer);
-}
-
-/**
- * Prepends the header data to the screen data
- * Formats the bitmap data
- * Writes the result to the screen
- * 
- * @param data pointer to the bitmap data
- * @param len amount of data to be written in bytes
- **/
-void g19_update_lcd_bmp(unsigned char * data, int len)
-{
-	unsigned char bits[G19_BMP_SIZE];
-	
-	if(g19_devh == NULL)
+	if((g19_devh == NULL) || (size < 1))
 		return;
 	
-	memset(&bits, 0x00, sizeof(bits));
-	memcpy(&bits, &hdata, sizeof(hdata));
+	struct libusb_transfer * lcd_transfer;
+	size_t bsize = G19_BMP_SIZE;
+	unsigned char * bits = malloc(bsize);
 	
+	lcd_transfer = libusb_alloc_transfer(0);
+	lcd_transfer -> flags = LIBUSB_TRANSFER_FREE_TRANSFER;
 	
-	int i, d;
-	unsigned int color;
+	memset(bits, 0x00, bsize);
 	
-	for(i = sizeof(hdata); (i < G19_BMP_SIZE) && (d < len); i += 2, d += 4)
+	if((flags & G19_PREPEND_HDATA) || (flags & G19_DATA_TYPE_BMP))
 	{
-		color = (data[d] / 8) << 11;
-		color |= (data[d + 1] / 4) << 5;
-		color |= data[d + 2] / 8;
+		lcd_transfer -> flags |= LIBUSB_TRANSFER_FREE_BUFFER;
+		memcpy(bits, hdata, sizeof(hdata));
+		
+		if(flags & G19_DATA_TYPE_BMP)
+		{
+			int i, d;
+			unsigned int color;
+			
+			for(i = sizeof(hdata), d = 0; (i < bsize) && (d < size); i += 2, d += 4)
+			{
+				color = (data[d] / 8) << 11;
+				color |= (data[d + 1] / 4) << 5;
+				color |= data[d + 2] / 8;
+				
+				memcpy(bits + i, &color, 2);
+			}
+		}
+		else if(flags & G19_PREPEND_HDATA)
+			memcpy(bits + sizeof(hdata), data, ((size + sizeof(hdata)) > bsize) ? (bsize - sizeof(hdata)) : size);
 		
-		memcpy(bits + i, &color, 2);
+		libusb_fill_bulk_transfer(lcd_transfer, g19_devh, 0x02, bits, bsize, NULL, NULL, 0);
 	}
+	else
+		libusb_fill_bulk_transfer(lcd_transfer, g19_devh, 0x02, data, size, NULL, NULL, 0);
 	
-	g19_update_lcd(bits, G19_BMP_SIZE);
+	libusb_submit_transfer(lcd_transfer);
 }
 
 /**
@@ -410,7 +413,7 @@
  * 
  * @return non zero on error
  **/
-int g19_set_backlight(int r, int g, int b)
+int g19_set_backlight(unsigned char r, unsigned char g, unsigned char b)
 {
 	if(g19_devh == NULL)
 		return -1;