CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Send ascii as keyboard

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cvargcal



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

Send ascii as keyboard
PostPosted: Thu Oct 04, 2018 3:37 pm     Reply with quote

Hi, I have one buffer with this data "04C65D12FF3880CA".
But alway send 04c65d12f380ca, not send complete the array.

Code:
// convert ascii character to USB HID Keyboard scancode.
// realize that there is no difference between 'A'/'a' or '1'/'!', they
// have the same scancode.  in order to differentiate between these the SHIFT
// modifier has to be set (see kb_modifier_t).
// see kb_scancode_t for other scancodes that are not ascii.
// bit8 will be set if shift needs to be set (for upper case chars or '!' vs '1')
unsigned int16 ToHidKeyboardScancode(char c)
{
   unsigned int16 shift = 0;
   
   if ((c>='A')&&(c<='Z'))
   {
      c = tolower(c);
      shift = 0x100;
   }
   if ((c>='a')&&(c<='z'))
   {
      return(((c-='a')+4)|shift);
   }
   if ((c>='1')&&(c<='9'))
   {
      return((c-='0')+0x1D);
   }
   switch(c)
   {
      case '!':   return(0x11E);
      case '@':   return(0x11F);
      case '#':   return(0x120);
      case '$':   return(0x121);
      case '%':   return(0x122);
      case '^':   return(0x123);
      case '&':   return(0x124);
      case '*':   return(0x125);
      case '(':   return(0x126);
      case ')':   return(0x127);
      case '0':   return(0x27);
      case '\n':  return(0x28);  //enter
      case '\r':  return(0x28);  //enter
      case '\b':  return(0x2A);  //backspace
      case '\t':  return(0x2B);  //tab
      case ' ':   return(0x2C);  //space
      case '_':   return(0x12D);
      case '-':   return(0x2D);
      case '+':   return(0x12E);
      case '=':   return(0x2E);
      case '{':   return(0x12F);
      case '[':   return(0x2F);
      case '}':   return(0x130);
      case ']':   return(0x30);
      case '|':   return(0x131);
      case '\\':   return(0x31);
      case ':':   return(0x133);
      case ';':   return(0x33);
      case '"':   return(0x134);
      case '\'':   return(0x34);
      case '~':   return(0x135);
      case '`':   return(0x35);
      case '<':   return(0x136);
      case ',':   return(0x36);
      case '>':   return(0x137);
      case '.':   return(0x37);
      case '?':   return(0x138);
      case '/':   return(0x38);
   }
}


void usb_keyboard_task(void) {
      static int8 tx_msg[7]={0,0,0,0,0,0,0};
      unsigned int8 leds;
      unsigned int16 scancode;

    if ( messageReady){   // I have full the array  "04C65D12FF3880CA"
          scancode = ToHidKeyboardScancode(moduleResonseBuffer[i++]);
          //if(bit_test(scancode, 8)) tx_msg[0] = KB_MODIFIER_LEFT_SHIFT;
          tx_msg[2] = scancode;
          usb_put_packet(2,tx_msg,sizeof(tx_msg),USB_DTS_TOGGLE);   
   }

   else{
   tx_msg[2]=0;
   usb_put_packet(2,tx_msg,sizeof(tx_msg),USB_DTS_TOGGLE);


if (moduleResonseBuffer[i]==0x00 ) {
   i=0;
   messageReady=0;
   output_high(LED_CMD);         delay_ms(300);         output_low(LED_CMD);
}


   //receive NUM LOCK, CAPS LOCK, etc LED status from PC. e won't do anything with it.
   if (usb_kbhit(2))    usb_get_packet(2, &leds, 1);


}


What happened, work fine but not send all characters.
04C65D12FF3880CA
04c65d12ff3880ca

I see... no send when the "asccii" is repeated...
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Oct 04, 2018 5:25 pm     Reply with quote

1) This is not a complete PIC program so I can't see important details like 'fuses'...

2) What is the receiving device ? A PC ? If so, what program is receiving the PIC's data stream ? If I assume a 'terminal program', like RealTerm, perhaps it's not configured properly or the PC is doing 'other stuff'.

Jay
cvargcal



Joined: 17 Feb 2015
Posts: 134

View user's profile Send private message

PostPosted: Thu Oct 04, 2018 5:55 pm     Reply with quote

I have the soluction... I have send 0 after every press...
Thanks

Its very slow... How I can do more faster?
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Oct 05, 2018 2:43 pm     Reply with quote

You'd have to show us the whole program not just bits of it. You do show a delay_ms(300); though. THAT would slow it down !

If I'm reading the post correctly, you have a PC keyboard connected to a PIC that then sends the key presses via USB to a PC. If so, it should be FAST ! I did similar project 20 years ago with a 16C84 running at 4MHz.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group