graphlcd-base/glcddrivers/picctl.c
changeset 14 ccaf76b245ec
parent 10 9798f65f2f35
child 15 cba463042186
equal deleted inserted replaced
10:9798f65f2f35 14:ccaf76b245ec
   102     delete oldConfig;
   102     delete oldConfig;
   103 }
   103 }
   104 
   104 
   105 void cDriverPICCtl::SignalHandler(int signal)
   105 void cDriverPICCtl::SignalHandler(int signal)
   106 {
   106 {
       
   107     uint8_t i;
       
   108 
   107     // read all available data
   109     // read all available data
   108     while (instance->port->ReadData(&buf[buf_pos]))
   110     while (instance->port->ReadData(&buf[buf_pos]))
   109     {
   111     {
   110         // search for SYNC byte
   112         // search for SYNC byte
   111         if ((buf[buf_pos] == CMD_SYNC_RECV) && (!buf_flag_escape))
   113         if ((buf[buf_pos] == CMD_SYNC_RECV) && (!buf_flag_escape))
   122 	}
   124 	}
   123 
   125 
   124 
   126 
   125         if ((buf[buf_pos] == CMD_ESCAPE_BYTE) && (!buf_flag_escape))
   127         if ((buf[buf_pos] == CMD_ESCAPE_BYTE) && (!buf_flag_escape))
   126 	{
   128 	{
       
   129 	    // this byte was for masking only.. ignore it! 
   127 	    buf_flag_escape = true;
   130 	    buf_flag_escape = true;
   128 	    buf_pos--; // should do!!! better would be something like next();
   131 	    continue;
   129 	    // set flag...
       
   130 	    // next;
       
   131 	} 
   132 	} 
   132 	else
   133         buf_flag_escape = false;
   133 	{
   134 
   134 	    buf_flag_escape = false;
   135 /*        printf("buf: ");
   135 	}
   136         for (i=1; i<=buf_pos; i++) { printf("0x%02x ",buf[i]);}
       
   137 	printf("\n");*/
   136 
   138 
   137         // we need to check for a valid packet...
   139         // we need to check for a valid packet...
   138 	if (buf_pos >=CMD_DATA_START)
   140 	if (buf_pos >=CMD_DATA_START)
   139 	{
   141 	{
   140             // if we recieved a valid packet: start decoding
   142             // if we recieved a valid packet: start decoding
   141 	    if (buf[CMD_HDR_LENGTH+1] == (buf_pos - CMD_DATA_START))
   143 	    if (buf[CMD_HDR_LENGTH+1] == (buf_pos - CMD_DATA_START))
   142 	    {
   144 	    {
   143 	        instance->DecodeCmd(&buf[buf_cmd_start],(buf_pos-1));
   145 	        instance->DecodeCmd(&buf[buf_cmd_start],(buf_pos));
   144 		buf_pos = 0;
   146 		buf_pos = 0;
   145 		buf_cmd_start = 0;
   147 		buf_cmd_start = 0;
   146 	    }
   148 	    }
   147 	}
   149 	}
   148 
   150 
   149         buf_pos++;
   151         buf_pos++;
       
   152 	printf ("still captured in while-loop\n");
   150 
   153 
   151     }
   154     }
   152 }
   155 }
   153 
   156 
   154 
   157 
   155 void cDriverPICCtl::DecodeCmd(uint8_t * cmd, uint8_t len)
   158 void cDriverPICCtl::DecodeCmd(uint8_t * cmd, uint8_t len)
   156 {
   159 {
       
   160     uint8_t i;
       
   161 
       
   162     printf("cmd(%2d): ",len);
       
   163     for (i=0; i<len; i++) { printf("0x%02x ",cmd[i]);}
       
   164     printf("\n");
       
   165 
   157     switch (cmd[CMD_HDR_COMMAND])
   166     switch (cmd[CMD_HDR_COMMAND])
   158     {
   167     {
   159         case CMD_SYS_ACK:	instance->ack_flag = true;
   168         case CMD_SYS_ACK:	ack_flag = true;
       
   169 				printf ("ack_!\n");
   160 	 			break;
   170 	 			break;
   161 
   171 
   162 	case CMD_SYS_IR:	printf(" Incoming Key-Event 0x%02x (Source 0x%02x)\n",cmd[CMD_DATA_START+1],cmd[CMD_DATA_START]);
   172 	case CMD_SYS_IR:	printf(" Incoming Key-Event 0x%02x (Source 0x%02x)\n",cmd[CMD_DATA_START+1],cmd[CMD_DATA_START]);
   163 	  			break;
   173 	  			break;
   164 
   174 
   165 	default:		printf(" recieved Message 0x%x \n",cmd[CMD_HDR_COMMAND]);
   175 	default:		printf(" recieved Message 0x%x \n",cmd[CMD_HDR_COMMAND]);
   166     }
   176     }
       
   177 
   167 
   178 
   168 }
   179 }
   169 
   180 
   170 int cDriverPICCtl::Init()
   181 int cDriverPICCtl::Init()
   171 {
   182 {