diff -r 2723893dc865 -r 7fd00015f62f graphlcd-base/glcddrivers/picctl.c --- a/graphlcd-base/glcddrivers/picctl.c Mon Mar 30 18:40:54 2009 +0200 +++ b/graphlcd-base/glcddrivers/picctl.c Thu Apr 23 19:10:12 2009 +0200 @@ -13,6 +13,7 @@ #include #include #include +#include #include "common.h" #include "config.h" @@ -60,25 +61,6 @@ const unsigned char CMD_BOOT = 0x80; -// globals... -uint8_t cDriverPICCtl::buf[255]; -uint8_t cDriverPICCtl::buf_pos; -uint8_t cDriverPICCtl::buf_cmd_start; -bool cDriverPICCtl::buf_flag_escape; - -// singleton -cDriverPICCtl* cDriverPICCtl::instance = NULL; - -cDriverPICCtl* cDriverPICCtl::getInstance(cDriverConfig * config) -{ - if (!instance) - instance = new cDriverPICCtl(config); - return instance; -} -// end singleton-pattern - - - cDriverPICCtl::cDriverPICCtl(cDriverConfig * config) : config(config) { @@ -95,36 +77,59 @@ buf_pos = 0; buf_cmd_start = 255; buf_flag_escape = false; + + keys_pos = 0; + keys_pos_ = 0; } cDriverPICCtl::~cDriverPICCtl() { - instance = NULL; - delete port; port = NULL; delete oldConfig; oldConfig = NULL; } -void cDriverPICCtl::SignalHandler(int signal) -{ - //uint8_t i; - +bool cDriverPICCtl::HasKeys() +{ + return true; +} + +int cDriverPICCtl::GetKey() +{ + InputHandler(); + + if (keys_pos != keys_pos_) + { + keys_pos_ = keys_pos; + return(keys[keys_pos-1]); + } + else + { + return(-1); + } + +} + +void cDriverPICCtl::InputHandler() +{ // read all available data (always get single bytes...) - while (instance->port->ReadData(&buf[buf_pos]) > 0) + while (port->ReadData(&buf[buf_pos]) > 0) { // search for SYNC byte if ((buf[buf_pos] == CMD_SYNC_RECV) && (!buf_flag_escape)) { if (buf_cmd_start != 255) { - /*printf("Damaged Packet: "); + #ifdef DEBUG + uint8_t i; + printf("Damaged Packet: "); for (i=buf_cmd_start; iDecodeCmd(&buf[buf_cmd_start],buf_pos); + DecodeCmd(&buf[buf_cmd_start],buf_pos); buf_pos = 0; buf_cmd_start = 255; } @@ -163,21 +165,25 @@ } } - void cDriverPICCtl::DecodeCmd(uint8_t * cmd, uint8_t len) { -/* uint8_t i; + #ifdef DEBUG + uint8_t i; printf("cmd(%2d): ",len); for (i=0; iname.c_str(), cmd[CMD_DATA_START+1], cmd[CMD_DATA_START]); - //printf(" %s: incoming Key-Event 0x%02x (Source 0x%02x)\n",config->name.c_str(), cmd[CMD_DATA_START+1], cmd[CMD_DATA_START]); + case CMD_SYS_IR: keys[keys_pos] = 256 * cmd[CMD_DATA_START] + cmd[CMD_DATA_START+1]; + keys_pos++; + #ifdef DEBUG + printf(" %s: recieved IR Command 0x%x \n",config->name.c_str(), cmd[CMD_DATA_START+1]); + #endif break; default: syslog(LOG_INFO," %s: recieved Message 0x%x \n",config->name.c_str(), cmd[CMD_HDR_COMMAND]); @@ -226,7 +232,7 @@ { return -1; } - if (port->Open(config->device.c_str(), SignalHandler) != 0) + if (port->Open(config->device.c_str()) != 0) return -1; *oldConfig = *config; @@ -235,7 +241,6 @@ Clear(); CmdDispClearScreen(); CmdDispSetManaged(); -// CmdDispSetBrightness(50); syslog(LOG_INFO, "%s: PICCtl initialized.\n", config->name.c_str()); return 0; @@ -244,6 +249,10 @@ int cDriverPICCtl::DeInit() { int y; + + CmdDispSetUnManaged(); + CmdDispClearScreen(); + // free lcd array (wanted state) if (newLCD) { @@ -263,7 +272,6 @@ delete[] oldLCD; } - CmdDispSetUnManaged(); if (port->Close() != 0) return -1; @@ -362,21 +370,29 @@ CmdDispSetBrightness(percent); } -void cDriverPICCtl::SetClock(unsigned int percent) -{ - CmdDispSetBrightness(percent); -} - int cDriverPICCtl::WaitForAck(void) { int timeout; for (timeout=0; timeout<1000; timeout++) { + InputHandler(); usleep(100); if (ack_flag) return 0; } syslog(LOG_INFO, "%s: PICCtl missed a ACK packet!\n", config->name.c_str()); + + +#ifdef DEBUG + int i; + printf("%s: PICCtl missed a ACK packet!\n", config->name.c_str()); + for (i=0; i