1.1 --- a/graphlcd-base/glcddrivers/picctl.c Wed Mar 25 17:48:05 2009 +0100
1.2 +++ b/graphlcd-base/glcddrivers/picctl.c Mon Mar 30 18:40:54 2009 +0200
1.3 @@ -67,7 +67,7 @@
1.4 bool cDriverPICCtl::buf_flag_escape;
1.5
1.6 // singleton
1.7 -cDriverPICCtl* cDriverPICCtl::instance = 0;
1.8 +cDriverPICCtl* cDriverPICCtl::instance = NULL;
1.9
1.10 cDriverPICCtl* cDriverPICCtl::getInstance(cDriverConfig * config)
1.11 {
1.12 @@ -86,8 +86,9 @@
1.13
1.14 port = new cSerialPort();
1.15
1.16 - //width = config->width;
1.17 - //height = config->height;
1.18 + width = config->width;
1.19 + height = config->height;
1.20 +
1.21 refreshCounter = 0;
1.22 ack_flag = false;
1.23
1.24 @@ -98,15 +99,19 @@
1.25
1.26 cDriverPICCtl::~cDriverPICCtl()
1.27 {
1.28 + instance = NULL;
1.29 +
1.30 delete port;
1.31 + port = NULL;
1.32 delete oldConfig;
1.33 + oldConfig = NULL;
1.34 }
1.35
1.36 void cDriverPICCtl::SignalHandler(int signal)
1.37 {
1.38 //uint8_t i;
1.39
1.40 - // read all available data
1.41 + // read all available data (always get single bytes...)
1.42 while (instance->port->ReadData(&buf[buf_pos]) > 0)
1.43 {
1.44 // search for SYNC byte
1.45 @@ -172,7 +177,7 @@
1.46 break;
1.47
1.48 case CMD_SYS_IR: syslog(LOG_INFO," %s: incoming Key-Event 0x%02x (Source 0x%02x)\n",config->name.c_str(), cmd[CMD_DATA_START+1], cmd[CMD_DATA_START]);
1.49 - printf(" %s: incoming Key-Event 0x%02x (Source 0x%02x)\n",config->name.c_str(), cmd[CMD_DATA_START+1], cmd[CMD_DATA_START]);
1.50 + //printf(" %s: incoming Key-Event 0x%02x (Source 0x%02x)\n",config->name.c_str(), cmd[CMD_DATA_START+1], cmd[CMD_DATA_START]);
1.51 break;
1.52
1.53 default: syslog(LOG_INFO," %s: recieved Message 0x%x \n",config->name.c_str(), cmd[CMD_HDR_COMMAND]);
1.54 @@ -230,7 +235,7 @@
1.55 Clear();
1.56 CmdDispClearScreen();
1.57 CmdDispSetManaged();
1.58 - CmdDispSetBrightness(0);
1.59 +// CmdDispSetBrightness(50);
1.60
1.61 syslog(LOG_INFO, "%s: PICCtl initialized.\n", config->name.c_str());
1.62 return 0;
1.63 @@ -260,11 +265,9 @@
1.64
1.65 CmdDispSetUnManaged();
1.66
1.67 - delete instance;
1.68 - instance = 0;
1.69 -
1.70 if (port->Close() != 0)
1.71 return -1;
1.72 +
1.73 return 0;
1.74 }
1.75
1.76 @@ -368,13 +371,13 @@
1.77 {
1.78 int timeout;
1.79
1.80 - for (timeout=0; timeout<10000; timeout++)
1.81 - {
1.82 - usleep(10);
1.83 - if (ack_flag) return 1;
1.84 - }
1.85 - syslog(LOG_INFO, "PICCtl: missed a ACK packet!.\n");
1.86 - return 0;
1.87 + for (timeout=0; timeout<1000; timeout++)
1.88 + {
1.89 + usleep(100);
1.90 + if (ack_flag) return 0;
1.91 + }
1.92 + syslog(LOG_INFO, "%s: PICCtl missed a ACK packet!\n", config->name.c_str());
1.93 + return 1;
1.94 }
1.95
1.96 void cDriverPICCtl::CmdDispClearScreen(void)
1.97 @@ -386,6 +389,7 @@
1.98 cmd[CMD_HDR_LENGTH] = 0;
1.99 cmd[CMD_HDR_LENGTH+1] = 0;
1.100
1.101 + ack_flag = false;
1.102 port->WriteData(cmd, 4);
1.103 WaitForAck();
1.104 }
1.105 @@ -400,6 +404,7 @@
1.106 cmd[CMD_HDR_LENGTH+1] = 1;
1.107 cmd[CMD_DATA_START] = (uint8_t) round(percent * 2.55);
1.108
1.109 + ack_flag = false;
1.110 port->WriteData(cmd, 5);
1.111 WaitForAck();
1.112 }
1.113 @@ -419,6 +424,7 @@
1.114 cmd[CMD_DATA_START+1] = (uint8_t)(address / 256); // upper address
1.115 memcpy(&cmd[CMD_DATA_START+2], data, length);
1.116
1.117 + ack_flag = false;
1.118 port->WriteData(cmd, length + 6);
1.119 WaitForAck();
1.120
1.121 @@ -436,6 +442,7 @@
1.122 cmd[CMD_HDR_LENGTH] = 0;
1.123 cmd[CMD_HDR_LENGTH+1] = 0;
1.124
1.125 + ack_flag = false;
1.126 port->WriteData(cmd,4);
1.127 WaitForAck();
1.128 }
2.1 --- a/graphlcd-base/glcddrivers/port.c Wed Mar 25 17:48:05 2009 +0100
2.2 +++ b/graphlcd-base/glcddrivers/port.c Mon Mar 30 18:40:54 2009 +0200
2.3 @@ -290,70 +290,79 @@
2.4 {
2.5 struct sigaction saio;
2.6
2.7 - if (FP == NULL)
2.8 + if (FP == NULL) {
2.9 + return -1;
2.10 + }
2.11 +
2.12 + if (Open(device) == 0) {
2.13 + // install the signal handler before making the device asynchronous/
2.14 + saio.sa_handler = FP;
2.15 + sigemptyset (&saio.sa_mask);
2.16 + saio.sa_flags = 0;
2.17 + saio.sa_restorer = NULL;
2.18 + sigaction(SIGIO,&saio,NULL);
2.19 +
2.20 + // allow the process to receive SIGIO
2.21 + fcntl(fd, F_SETOWN, getpid());
2.22 + // Make the file descriptor asynchronous
2.23 + fcntl(fd, F_SETFL, FASYNC | O_NONBLOCK);
2.24 +
2.25 + return(0);
2.26 + }
2.27 + else {
2.28 + return -1;
2.29 + }
2.30 +}
2.31 +
2.32 +int cSerialPort::Open(const char * device)
2.33 +{
2.34 + struct termios options;
2.35 +
2.36 + fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);
2.37 + if (fd == -1)
2.38 {
2.39 printf("error opening port\n");
2.40 return -1;
2.41 }
2.42
2.43 - Open(device);
2.44 -
2.45 - // install the signal handler before making the device asynchronous/
2.46 - saio.sa_handler = FP;
2.47 + tcgetattr(fd, &options);
2.48 +
2.49 + cfsetispeed(&options, B921600);
2.50 + cfsetospeed(&options, B921600);
2.51 +
2.52 + options.c_cflag &= ~PARENB;
2.53 + options.c_cflag &= ~CSTOPB;
2.54 + options.c_cflag &= ~CSIZE;
2.55 + options.c_cflag |= CS8;
2.56 +
2.57 + options.c_cflag &= ~CRTSCTS;
2.58 +
2.59 + options.c_cflag |= (CLOCAL | CREAD);
2.60 +
2.61 + options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
2.62 +
2.63 + options.c_iflag &= ~(IXON | IXOFF | IXANY);
2.64 +
2.65 + options.c_oflag &= ~OPOST;
2.66 +
2.67 + tcsetattr(fd, TCSANOW, &options);
2.68 +
2.69 + return 0;
2.70 +}
2.71 +
2.72 +int cSerialPort::Close()
2.73 +{
2.74 + struct sigaction saio;
2.75 + if (fd == -1)
2.76 + return -1;
2.77 + close(fd);
2.78 +
2.79 + saio.sa_handler = NULL;
2.80 sigemptyset (&saio.sa_mask);
2.81 saio.sa_flags = 0;
2.82 saio.sa_restorer = NULL;
2.83 sigaction(SIGIO,&saio,NULL);
2.84 -
2.85 - // allow the process to receive SIGIO
2.86 - fcntl(fd, F_SETOWN, getpid());
2.87 - // Make the file descriptor asynchronous
2.88 - fcntl(fd, F_SETFL, FASYNC | O_NONBLOCK);
2.89 -
2.90 - return(0);
2.91 -}
2.92 -
2.93 -int cSerialPort::Open(const char * device)
2.94 -{
2.95 - struct termios options;
2.96 -
2.97 - fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);
2.98 - if (fd == -1)
2.99 - {
2.100 - printf("error opening port\n");
2.101 - return -1;
2.102 - }
2.103 -
2.104 - tcgetattr(fd, &options);
2.105 -
2.106 - cfsetispeed(&options, B921600);
2.107 - cfsetospeed(&options, B921600);
2.108 -
2.109 - options.c_cflag &= ~PARENB;
2.110 - options.c_cflag &= ~CSTOPB;
2.111 - options.c_cflag &= ~CSIZE;
2.112 - options.c_cflag |= CS8;
2.113 -
2.114 - options.c_cflag &= ~CRTSCTS;
2.115 -
2.116 - options.c_cflag |= (CLOCAL | CREAD);
2.117 -
2.118 - options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
2.119 -
2.120 - options.c_iflag &= ~(IXON | IXOFF | IXANY);
2.121 -
2.122 - options.c_oflag &= ~OPOST;
2.123 -
2.124 - tcsetattr(fd, TCSANOW, &options);
2.125 -
2.126 - return 0;
2.127 -}
2.128 -
2.129 -int cSerialPort::Close()
2.130 -{
2.131 - if (fd == -1)
2.132 - return -1;
2.133 - close(fd);
2.134 +
2.135 return 0;
2.136 }
2.137
2.138 @@ -374,6 +383,7 @@
2.139 if (fd == -1)
2.140 return;
2.141 write(fd, data, length);
2.142 +// for (int x=0; x<length; x++) printf("0x%x ",data[x]);
2.143 }
2.144
2.145