20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
21 *****************************************************************************/ |
21 *****************************************************************************/ |
22 |
22 |
23 #include "thermferm.h" |
23 #include "thermferm.h" |
24 #include "lcd-buffer.h" |
24 #include "lcd-buffer.h" |
|
25 #include "lcd-pcf8574.h" |
|
26 |
25 |
27 |
26 #ifdef HAVE_WIRINGPI_H |
28 #ifdef HAVE_WIRINGPI_H |
27 |
29 |
|
30 int current_lines = 0; |
|
31 int current_offset = 0; |
|
32 int current_second = 0; |
|
33 lcd_rows *my_lcd_rows = NULL; |
|
34 |
|
35 extern int lcdHandle; |
|
36 extern sys_config Config; |
|
37 |
|
38 |
|
39 |
|
40 /* |
|
41 * Write to buffer array. Allocate more lines if needed. |
|
42 */ |
|
43 void lcd_buf_write(int row, const char *format, ...) |
|
44 { |
|
45 char buf[21 * sizeof(char)]; |
|
46 va_list va_ptr; |
|
47 lcd_rows *tmp, *newrow; |
|
48 int i = 0; |
|
49 |
|
50 va_start(va_ptr, format); |
|
51 vsnprintf(buf, 20 * sizeof(char), format, va_ptr); |
|
52 va_end(va_ptr); |
|
53 |
|
54 /* |
|
55 * Check if the line in row is allocated. If not, do it |
|
56 * and make sure the chain is valid. |
|
57 */ |
|
58 while (row > current_lines) { |
|
59 |
|
60 newrow = (lcd_rows *)malloc(sizeof(lcd_rows)); |
|
61 newrow->next = NULL; |
|
62 snprintf(newrow->row, 21 * sizeof(char), " "); |
|
63 |
|
64 if (my_lcd_rows == NULL) { |
|
65 my_lcd_rows = newrow; |
|
66 } else { |
|
67 for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { |
|
68 if (tmp->next == NULL) { |
|
69 tmp->next = newrow; |
|
70 current_lines++; |
|
71 break; |
|
72 } |
|
73 } |
|
74 } |
|
75 } |
|
76 |
|
77 /* |
|
78 * Now update the text |
|
79 */ |
|
80 for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { |
|
81 i++; |
|
82 if (i == row) { |
|
83 snprintf(tmp->row, Config.lcd_cols + 1, "%s", buf); |
|
84 break; |
|
85 } |
|
86 } |
|
87 } |
|
88 |
|
89 |
|
90 |
|
91 /* |
|
92 * This will be called each second. |
|
93 */ |
|
94 void lcd_buf_show(void) |
|
95 { |
|
96 int i = 0, r = 0; |
|
97 lcd_rows *tmp; |
|
98 |
|
99 for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { |
|
100 if (i == current_offset) |
|
101 break; |
|
102 i++; |
|
103 } |
|
104 |
|
105 lcdPosition(lcdHandle, 0, r); |
|
106 mb_lcdPuts(lcdHandle, tmp->row); |
|
107 |
|
108 r++; |
|
109 if (r < Config.lcd_rows) { |
|
110 if (tmp->next != NULL) |
|
111 tmp = tmp->next; |
|
112 else |
|
113 tmp = my_lcd_rows; |
|
114 lcdPosition(lcdHandle, 0, r); |
|
115 mb_lcdPuts(lcdHandle, tmp->row); |
|
116 } |
|
117 |
|
118 current_second++; |
|
119 if (current_second < 5) |
|
120 return; |
|
121 |
|
122 /* |
|
123 * Wrap display |
|
124 */ |
|
125 current_second = 0; |
|
126 if (current_offset < (current_lines - Config.lcd_rows)) |
|
127 current_offset = current_offset + Config.lcd_rows; |
|
128 else |
|
129 current_offset = 0; |
|
130 } |
28 |
131 |
29 |
132 |
30 |
133 |
31 #endif |
134 #endif |