glcddrivers: made port non-blocking, fixed input-code
authorcpresser@rika
Thu, 07 Feb 2008 11:42:36 +0000
changeset 15cba463042186
parent 14 ccaf76b245ec
child 16 5bf89d28ba80
glcddrivers: made port non-blocking, fixed input-code
graphlcd-base/glcddrivers/picctl.c
graphlcd-base/glcddrivers/port.c
     1.1 --- a/graphlcd-base/glcddrivers/picctl.c	Thu Feb 07 00:45:43 2008 +0000
     1.2 +++ b/graphlcd-base/glcddrivers/picctl.c	Thu Feb 07 11:42:36 2008 +0000
     1.3 @@ -91,7 +91,7 @@
     1.4      refreshCounter = 0;
     1.5      ack_flag = false;
     1.6      
     1.7 -    buf_pos = 1;
     1.8 +    buf_pos = 0;
     1.9      buf_cmd_start = 255;
    1.10      buf_flag_escape = false;
    1.11  }
    1.12 @@ -104,10 +104,10 @@
    1.13  
    1.14  void cDriverPICCtl::SignalHandler(int signal)
    1.15  {
    1.16 -    uint8_t i;
    1.17 +//    uint8_t i;
    1.18  
    1.19      // read all available data
    1.20 -    while (instance->port->ReadData(&buf[buf_pos]))
    1.21 +    while (instance->port->ReadData(&buf[buf_pos]) > 0)
    1.22      {
    1.23          // search for SYNC byte
    1.24          if ((buf[buf_pos] == CMD_SYNC_RECV) && (!buf_flag_escape))
    1.25 @@ -116,7 +116,6 @@
    1.26  	    {
    1.27  	        // bytes = buf_cmd_start - buf_pos
    1.28                  syslog(LOG_INFO, "PICCtl received a malformed packet. Scrapped xxx bytes\n");
    1.29 -		buf_cmd_start = 0;
    1.30  		buf_pos = 0;
    1.31  		buf[buf_pos] = CMD_SYNC_RECV;
    1.32  	    }
    1.33 @@ -135,38 +134,35 @@
    1.34  /*        printf("buf: ");
    1.35          for (i=1; i<=buf_pos; i++) { printf("0x%02x ",buf[i]);}
    1.36  	printf("\n");*/
    1.37 +        
    1.38 +	buf_pos++;
    1.39  
    1.40          // we need to check for a valid packet...
    1.41 -	if (buf_pos >=CMD_DATA_START)
    1.42 +	if (buf_pos >= CMD_DATA_START)
    1.43  	{
    1.44              // if we recieved a valid packet: start decoding
    1.45  	    if (buf[CMD_HDR_LENGTH+1] == (buf_pos - CMD_DATA_START))
    1.46  	    {
    1.47 -	        instance->DecodeCmd(&buf[buf_cmd_start],(buf_pos));
    1.48 +	        instance->DecodeCmd(&buf[buf_cmd_start],buf_pos);
    1.49  		buf_pos = 0;
    1.50 -		buf_cmd_start = 0;
    1.51 +		buf_cmd_start = 255;
    1.52  	    }
    1.53  	}
    1.54  
    1.55 -        buf_pos++;
    1.56 -	printf ("still captured in while-loop\n");
    1.57 -
    1.58      }
    1.59  }
    1.60  
    1.61  
    1.62  void cDriverPICCtl::DecodeCmd(uint8_t * cmd, uint8_t len)
    1.63  {
    1.64 -    uint8_t i;
    1.65 -
    1.66 +/*    uint8_t i;
    1.67      printf("cmd(%2d): ",len);
    1.68      for (i=0; i<len; i++) { printf("0x%02x ",cmd[i]);}
    1.69 -    printf("\n");
    1.70 +    printf("\n");*/
    1.71  
    1.72      switch (cmd[CMD_HDR_COMMAND])
    1.73      {
    1.74          case CMD_SYS_ACK:	ack_flag = true;
    1.75 -				printf ("ack_!\n");
    1.76  	 			break;
    1.77  
    1.78  	case CMD_SYS_IR:	printf(" Incoming Key-Event 0x%02x (Source 0x%02x)\n",cmd[CMD_DATA_START+1],cmd[CMD_DATA_START]);
    1.79 @@ -227,6 +223,7 @@
    1.80      Clear();
    1.81      CmdDispClearScreen();
    1.82      CmdDispSetManaged();
    1.83 +    CmdDispSetBrightness(0);
    1.84  
    1.85      syslog(LOG_INFO, "%s: PICCtl initialized.\n", config->name.c_str());
    1.86      return 0;
     2.1 --- a/graphlcd-base/glcddrivers/port.c	Thu Feb 07 00:45:43 2008 +0000
     2.2 +++ b/graphlcd-base/glcddrivers/port.c	Thu Feb 07 11:42:36 2008 +0000
     2.3 @@ -291,7 +291,7 @@
     2.4      struct termios options;
     2.5      struct sigaction saio;
     2.6  
     2.7 -    fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
     2.8 +    fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);
     2.9      if (fd == -1)
    2.10      {
    2.11          printf("error opening port\n");
    2.12 @@ -309,7 +309,7 @@
    2.13      // allow the process to receive SIGIO
    2.14      fcntl(fd, F_SETOWN, getpid());
    2.15      // Make the file descriptor asynchronous 
    2.16 -    fcntl(fd, F_SETFL, FASYNC);
    2.17 +    fcntl(fd, F_SETFL, FASYNC | O_NONBLOCK);
    2.18  
    2.19      tcgetattr(fd, &options);
    2.20