Sun, 27 Jul 2014 21:04:57 +0200
Small fix
/***************************************************************************** * Copyright (C) 2014 * * Michiel Broek <mbroek at mbse dot eu> * * This file is part of the mbsePi-apps * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * mbsePi-apps is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with mbsePi-apps; see the file COPYING. If not, write to the Free * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *****************************************************************************/ #include "thermferm.h" #include "lcd-buffer.h" #include "lcd-pcf8574.h" #ifdef HAVE_WIRINGPI_H int current_lines = 0; int current_offset = 0; int current_second = 0; lcd_rows *my_lcd_rows = NULL; extern int lcdHandle; extern sys_config Config; /* * Write to buffer array. Allocate more lines if needed. */ void lcd_buf_write(int row, const char *format, ...) { char buf[21 * sizeof(char)]; va_list va_ptr; lcd_rows *tmp, *newrow; int i = 0; va_start(va_ptr, format); vsnprintf(buf, 20 * sizeof(char), format, va_ptr); va_end(va_ptr); /* * Check if the line in row is allocated. If not, do it * and make sure the chain is valid. */ while (row > current_lines) { newrow = (lcd_rows *)malloc(sizeof(lcd_rows)); newrow->next = NULL; snprintf(newrow->row, 21 * sizeof(char), " "); if (my_lcd_rows == NULL) { my_lcd_rows = newrow; } else { for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { if (tmp->next == NULL) { tmp->next = newrow; current_lines++; break; } } } } /* * Now update the text */ for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { i++; if (i == row) { snprintf(tmp->row, Config.lcd_cols + 1, "%s", buf); break; } } } /* * This will be called each second. */ void lcd_buf_show(void) { int i = 0, r = 0; lcd_rows *tmp; for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { if (i == current_offset) break; i++; } lcdPosition(lcdHandle, 0, r); mb_lcdPuts(lcdHandle, tmp->row); r++; if (r < Config.lcd_rows) { if (tmp->next != NULL) tmp = tmp->next; else tmp = my_lcd_rows; lcdPosition(lcdHandle, 0, r); mb_lcdPuts(lcdHandle, tmp->row); } current_second++; if (current_second < 5) return; /* * Wrap display */ current_second = 0; if (current_offset < (current_lines - Config.lcd_rows)) current_offset = current_offset + Config.lcd_rows; else current_offset = 0; } #endif