Example #1
0
void translate_make_code(KB_CODE_TYPE decode_mode, alt_u8 makecode, char *str) {
	unsigned idx;
	switch (decode_mode) {
	case KB_ASCII_MAKE_CODE:
		idx = get_single_byte_make_code_index(makecode);
		strcpy(str, key_table[idx]);
		break;
	case KB_BINARY_MAKE_CODE:
		idx = get_single_byte_make_code_index(makecode);
		strcpy(str, key_table[idx]);
		break;
	case KB_LONG_BINARY_MAKE_CODE:
		idx = get_multi_byte_make_code_index(makecode);
		strcpy(str, key_table[idx]);
		break;
	default:
		str = "";
		break;
	}
}
Example #2
0
DECODE_STATE get_next_state(DECODE_STATE state, 
			    alt_u8 byte,
			    KB_CODE_TYPE *decode_mode,
			    alt_u8 *buf)
{
  DECODE_STATE next_state = STATE_INIT;
  alt_u16 idx = NUM_SCAN_CODES;
  switch (state) {
  case STATE_INIT:
    if ( byte == 0xE0 ) {
      next_state = STATE_LONG_BINARY_MAKE_CODE;
    } else if (byte == 0xF0) {
      next_state = STATE_BREAK_CODE;
    } else {
      idx = get_single_byte_make_code_index(byte);
      if ( (idx < 40 || idx == 68 || idx > 79) && ( idx != NUM_SCAN_CODES ) ) {
	*decode_mode = KB_ASCII_MAKE_CODE;
	*buf= ascii_codes[idx];
      } else {
	*decode_mode = KB_BINARY_MAKE_CODE;
	*buf = byte;
      }
      next_state = STATE_DONE;
    }
    break;
  case STATE_LONG_BINARY_MAKE_CODE:
    if ( byte != 0xF0 && byte!= 0xE0) {
      *decode_mode = KB_LONG_BINARY_MAKE_CODE;
      *buf = byte;
      next_state = STATE_DONE;
    } else {
      next_state = STATE_BREAK_CODE;
    }
    break;
  case STATE_BREAK_CODE:
    if ( byte != 0xF0 && byte != 0xE0) {
      *decode_mode = KB_BREAK_CODE;
      *buf = byte;
      next_state = STATE_DONE;
    } else {
      next_state = STATE_BREAK_CODE;
    }
    break;
  default:
    *decode_mode = KB_INVALID_CODE;
    next_state = STATE_INIT;
  }
  return next_state;
}
/* FSM Diagram (Main transitions)
 * Normal bytes: bytes that are not 0xF0 or 0xE0
  +--<--+
  |     |                                   
  |     |
  V    INIT ------ 0xF0 ----> BREAK CODE
  |     |                         |
  |     |         LONG_BREAK_CODE-+
  |    0xE0      /                |
 Normal |       /                Normal
  |     |     0xF0                |
  |     V     /                   |
  |    LONG  /                    V
  |    CODE --- Normal -------> DONE
  |          (long make code)    /|\
  |                               |
  +-------------------------------|

 */
DECODE_STATE get_next_state(DECODE_STATE state, alt_u8 byte, KB_CODE_TYPE *decode_mode, alt_u8 *buf, char *ascii)
{
	DECODE_STATE next_state = STATE_INIT;
	unsigned idx = SCAN_CODE_NUM;
	*ascii = 0;
	switch (state)
	{
		case STATE_INIT:
			if ( byte == 0xE0 )
			{	
				// this could be a long break code or a long make code
				next_state = STATE_LONG_CODE;
			}
			else if (byte == 0xF0)
			{
				// it is a break code
				next_state = STATE_BREAK_CODE;
			}
			else
			{
				// it is a normal make code
				idx = get_single_byte_make_code_index(byte);
				if ( (idx < 40 || idx == 68 || idx > 79) && ( idx != SCAN_CODE_NUM ) )
				{
					*decode_mode = KB_ASCII_MAKE_CODE;
					*ascii = ascii_codes[idx];
					*buf = byte;
				}
				else 
				{
					*decode_mode = KB_BINARY_MAKE_CODE;
					*buf = byte;
				}
				next_state = STATE_DONE;
			}
			break;
		case STATE_LONG_CODE:
			if ( byte != 0xF0 && byte!= 0xE0)
			{
				*decode_mode = KB_LONG_BINARY_MAKE_CODE;
				*buf = byte;
				next_state = STATE_DONE;
			}
			else
			{
				*decode_mode = KB_BREAK_CODE;
				next_state = STATE_LONG_BREAK_CODE;
			}
			break;
		case STATE_BREAK_CODE:
			if ( byte != 0xF0 && byte != 0xE0)
			{
				*decode_mode = KB_BREAK_CODE;
				*buf = byte;
				next_state = STATE_DONE;
			}
			else
			{
				next_state = STATE_BREAK_CODE;
				*decode_mode = KB_BREAK_CODE;
			}
			break;
		case STATE_LONG_BREAK_CODE:
			if ( byte != 0xF0 && byte != 0xE0)
			{
				*decode_mode = KB_LONG_BREAK_CODE;
				*buf = byte;
				next_state = STATE_DONE;
			}
			else
			{
				next_state = STATE_LONG_BREAK_CODE;
				*decode_mode = KB_LONG_BREAK_CODE;
			}
			break;
		default:
			*decode_mode = KB_INVALID_CODE;
			next_state = STATE_INIT;
	}
	return next_state;
}