Sun, 27 Jul 2014 21:04:57 +0200
Small fix
106 | 1 | /***************************************************************************** |
108 | 2 | * Copyright (C) 2014 |
106 | 3 | * |
4 | * Michiel Broek <mbroek at mbse dot eu> | |
5 | * | |
6 | * This file is part of the mbsePi-apps | |
7 | * | |
8 | * This is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * mbsePi-apps is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with mbsePi-apps; see the file COPYING. If not, write to the Free | |
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
21 | *****************************************************************************/ | |
22 | ||
23 | #include "thermferm.h" | |
24 | #include "lcd-buffer.h" | |
108 | 25 | #include "lcd-pcf8574.h" |
26 | ||
106 | 27 | |
28 | #ifdef HAVE_WIRINGPI_H | |
29 | ||
108 | 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 | } | |
106 | 131 | |
132 | ||
133 | ||
134 | #endif |