mbed Weather Platform firmware http://mbed.org/users/okini3939/notebook/mbed-weather-platform-firmware/

Dependencies:   ChaNFSSD EthernetNetIf I2CLEDDisp Agentbed ChaNFSUSB ILinterpreter mbed BMP085 WeatherMeters ConfigFile ChaNFS I2CLCD

display.cpp

Committer:
okini3939
Date:
2011-07-04
Revision:
0:bdb53686c194
Child:
1:6c7141895545

File content as of revision 0:bdb53686c194:

#include "mbed.h"
#include "weather.h"
#ifdef USE_DISPLAY
#include "I2CLEDDisp.h"
#include "I2CLCD.h"

static I2CLEDDisp *leddisp;
static I2CLCD *lcd;
static volatile int lcd_flg = 0, leddisp_flg = 0;
static volatile int leddisp_freq = 0, leddisp_pos = -4;
static char leddisp_buf[150];
#endif

void update_display () {
#ifdef USE_DISPLAY
    char buf[128], tmp[128];

    if (leddisp_flg && cfg.getValue("LEDDISP_MESG", tmp, sizeof(tmp))) {
        format_str(tmp, leddisp_buf, sizeof(leddisp_buf));
    }

    if (lcd_flg && cfg.getValue("LCD_MESG", tmp, sizeof(tmp))) {
        format_str(tmp, buf, sizeof(buf));
        lcd->cls();
        lcd->puts(buf);
    }
#endif
}

void pool_display () {
#ifdef USE_DISPLAY
    int i, addr, len;

    // LED Display scroll
    if (leddisp_flg) {
        leddisp_freq ++;
        if (leddisp_freq > LED_FREQ) {

            len = strlen(leddisp_buf);
            leddisp->locate(0, 0);
            for (i = 0; i < 4; i ++) {
                addr = leddisp_pos + i;
                if (addr >= 0 && addr < len) {
                    leddisp->putc(leddisp_buf[addr]);
                } else {
                    leddisp->putc(' ');
                }
            }

            leddisp_pos ++;
            if (leddisp_pos >= len + 4) {
                leddisp_pos = -4;
            }

            leddisp_freq = 0;
        }
    }
#endif
}

int init_display () {
#ifdef USE_DISPLAY
    char buf[128];
    enum I2CLCDType lcdtype = LCD16x2;
    enum I2CLCDConfig lcdconf = LCDCFG_3V;

    if (cfg.getValue("LCD_MESG", buf, sizeof(buf))) {
        if (cfg.getValue("LCD_TYPE", buf, sizeof(buf))) {
            lcdtype = (enum I2CLCDType)atoi(buf);
        }
        if (cfg.getValue("LCD_CONF", buf, sizeof(buf))) {
            lcdconf = (enum I2CLCDConfig)atoi(buf);
        }
        lcd = new I2CLCD(i2c, I2CLCD_ADDR, lcdtype, lcdconf);
        if (lcd == NULL) return -1;
        lcd_flg = 1;

        strncpy(leddisp_buf, VERSION, sizeof(leddisp_buf));
    }

    if (cfg.getValue("LEDDISP_MESG", buf, sizeof(buf))) {
        leddisp = new I2CLEDDisp(i2c);
        if (leddisp == NULL) return -1;
        leddisp_flg = 1;
    }

#endif
    return 0;
}