ti1_key.c

来自「是一个手机功能的模拟程序」· C语言 代码 · 共 732 行 · 第 1/2 页

C
732
字号
            key += 7;
            continue;
        }
        for (i = 0; i < NUM_KPD_KEYS; i++)
        {
            if (!strcmp(key,config_map[i]))
            {
#ifdef WIN32
				kbd_putMakeAndKey(0,i);
				sig(0,0);
				kbd_putMakeAndKey(1,i);
				sig(0,0);
#else
                sig(1,i);               /* assume key down event    */
                sig(0,i);               /* add key down event       */
#endif
                key += strlen(config_map[i]);
                break;
            }
        }
        if (i < NUM_KPD_KEYS)
            continue;                   /* found config code        */

        if (*key >= '0' && *key <= '9')
        {
            number = 1;
#ifdef WIN32
			kbd_putMakeAndKey(0,(char) (*key-'0'));
			sig(0,0);
			kbd_putMakeAndKey(1,(char) (*key-'0'));
			sig(0,0);
#else
            sig(1,(char) (*key-'0'));   /* assume a dial number     */
            sig(0,(char) (*key-'0'));
#endif
        }
        key++;
    }
    if (number)
    {
#ifdef WIN32
		kbd_putMakeAndKey(0,18);
		sig(0,0);
		kbd_putMakeAndKey(1,18);
		sig(0,0);
#else
        sig(1,18);                      /* simulate CALL            */
        sig(0,18);
#endif
    }
}

void mfw_keystroke_long (char * key, UBYTE mode) /* long pressed key         */
{
    char i, number;

    if (!sig) return;                   /* no event handler         */
    if (!key) return;                   /* no valid key             */

    number = 0;
    while (strlen(key))
    {
      for (i = 0; i < NUM_KPD_KEYS; i++)
      {
        if (!strcmp(key,config_map[i]))
        {
          if (mode)
#ifdef WIN32
		  {
	kbd_putMakeAndKey(0,i);
	sig(0,0);
		  }
#else
            sig(1,i);               /* assume key down event    */
#endif
          else
#ifdef WIN32
		  {
	kbd_putMakeAndKey(1,i);
	sig(0,0);
		  }
#else
            sig(0,i);               /* add key down event       */
#endif
          return;
        }
      }
      return;
    }
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : ti1_key            |
| STATE   : code                        ROUTINE : kbd_callback       |
+--------------------------------------------------------------------+

  PURPOSE : Called by keyboard driver

*/

//#define hCommACI _ENTITY_PREFIXED(hCommACI)
#define hCommMMI _ENTITY_PREFIXED(hCommMMI)

static void kbdCb (drv_SignalID_Type *signal_params)
{
#if defined (NEW_FRAME)
	ULONG signal_raw;
#endif

	U16 signal_high;
	U16 signal_low;
	U8   key_code;
	U8   key_state;

	int nPresses; //Number of key presses still in the queue

#if defined (NEW_FRAME)
	signal_raw = (ULONG)signal_params->UserData;
	signal_high = (U16) (signal_raw >> 16);
	signal_low = (U16) (signal_raw & 0xFFFF);
#else
	signal_high = (U16) (signal_params->UserData >> 16);
	signal_low = (U16) (signal_params->UserData & 0xFFFF);
#endif

	key_code = (U8) (signal_low & 0xFF);
	if (signal_high == 1)
		key_state = KEY_STAT_PRS;
	else
		key_state = KEY_STAT_REL;

	//Add keypress to queue of key presses
	nPresses = kbd_getNumElements();

	kbd_putMakeAndKey( (char)key_state, (char)key_code);

	if ((!kbd_stillProcessingKeys()) && (nPresses == 0))
	{	//Only this element present - create and send message.
		sendKeyInd(key_code, key_state, 0);
	}

}

/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : ti1_key            |
| STATE   : code                        ROUTINE :  keypad_cb          |
+--------------------------------------------------------------------+

  PURPOSE : This CB function is called by the driver when a key is pressed/released
             or a status of an asynch. process is requested.

*/
void keypad_cb (void* parameter)
{
	T_KPD_KEY_EVENT_MSG* event;
	T_KPD_STATUS_MSG*    status;
	T_RV_CHECK*  check;
	int k,m;

	check = (T_RV_CHECK*)parameter;

	if (check->msg_id EQ KPD_STATUS_MSG)
	{
		//status message is used
		status = (T_KPD_STATUS_MSG*) parameter;

		if (status->status_value EQ KPD_PROCESS_OK)
		{
			//ok
		}
		else
		{
			//failed !
			return;
		}
	}
	else
	{
		int nPresses; //Number of key presses still in the queue
		//event message is used
		event = (T_KPD_KEY_EVENT_MSG*) parameter;

		//Add keypress to queue of key presses
		nPresses = kbd_getNumElements();

		if (event->key_info.press_state EQ KPD_INSIGNIFICANT_VALUE)
		{
			kbd_putMakeAndKey( (char)event->key_info.state, (char)event->key_info.virtual_key_id );
		}
		else
		{
			//key_ind->key_stat (U8):
			//        00xx 0000 = KEY_PRESSED
			//        00xx 0001 = KEY_RELEASED
			//        0000 00xx = KPD_FIRST_PRESS
			//        0001 00xx = KPD_LONG_PRESS
			//        0010 00xx = KPD_REPEAT_PRESS
			//
			//    x = anystate

			kbd_putMakeAndKey( (char)(event->key_info.state | (event->key_info.press_state << 4)),
								  (char)event->key_info.virtual_key_id );
		}
		if ((!kbd_stillProcessingKeys()) && (nPresses == 0))
		{	//Only this element present - create and send message.
			sendKeyInd(event->key_info.virtual_key_id, event->key_info.state, event->key_info.press_state);
		}

	}

	return;
}


/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : ti1_key            |
| STATE   : code                        ROUTINE :  keypad_initialize    |
+--------------------------------------------------------------------+

  PURPOSE : initialize keyboard driver

*/

UBYTE keypad_initialize (void)
{
    T_KPD_MODE          mode;
    T_KPD_VIRTUAL_KEY_TABLE   notified_keys;
    T_RV_RETURN         return_path;
    T_RV_RET            return_value;

  U16 long_press_time = 30; // 3.0s
  U16 repeat_time = 50;     // 5.0s <not used>

  T_KPD_NOTIF_LEVEL     notif_level;
  mode = KPD_DEFAULT_MODE;

  return_path.callback_func = keypad_cb;
  return_path.addr_id = 0;

  notified_keys.nb_notified_keys = KPD_NB_PHYSICAL_KEYS;

  notified_keys.notified_keys [0] = KPD_KEY_0;
  notified_keys.notified_keys [1] = KPD_KEY_1;
  notified_keys.notified_keys [2] = KPD_KEY_2;
  notified_keys.notified_keys [3] = KPD_KEY_3;
  notified_keys.notified_keys [4] = KPD_KEY_4;
  notified_keys.notified_keys [5] = KPD_KEY_5;
  notified_keys.notified_keys [6] = KPD_KEY_6;
  notified_keys.notified_keys [7] = KPD_KEY_7;
  notified_keys.notified_keys [8] = KPD_KEY_8;
  notified_keys.notified_keys [9] = KPD_KEY_9;
  notified_keys.notified_keys [10] = KPD_KEY_UP;
  notified_keys.notified_keys [11] = KPD_KEY_DOWN;
  notified_keys.notified_keys [12] = KPD_KEY_SOFT_LEFT; //KPD_KEY_LEFT;   zym
  notified_keys.notified_keys [13] = KPD_KEY_SOFT_RIGHT;  //KPD_KEY_RIGHT;  zym
  notified_keys.notified_keys [14] = KPD_KEY_CONNECT;

//zym
  notified_keys.notified_keys [15] = KPD_KEY_DISCONNECT;   //probabely bring some problem   zym
  notified_keys.notified_keys [16] = KPD_KEY_STAR;
  notified_keys.notified_keys [17] = KPD_KEY_DIESE;
  
	if (KPD_NB_PHYSICAL_KEYS > 22)
	{		
  notified_keys.notified_keys [18] = KPD_KEY_VOL_UP;
  notified_keys.notified_keys [19] = KPD_KEY_VOL_DOWN;
  notified_keys.notified_keys [20] = KPD_KEY_LEFT;
  notified_keys.notified_keys [21] = KPD_KEY_RIGHT;
  notified_keys.notified_keys [22] = KPD_KEY_ENTER;
  notified_keys.notified_keys [23] = KPD_KEY_RECORD;
	} 	

#ifndef _SIMULATION_
  return_value = kpd_subscribe (&subscriber_p, mode, &notified_keys, return_path);
#else
  return_value = RV_OK; /* do some faking here, to get it compileable */
#endif

///no  dealing  error   :zym
  if (return_value EQ RV_INTERNAL_ERR ||
     return_value EQ RV_INVALID_PARAMETER ||
     return_value EQ RV_MEMORY_ERR)
  {
    //failed

    //- RV_INTERNAL_ERR if
    //   - the max of subscriber is reached,
    //   - the software entity is not started, not yet initialized or initialization has
    //     failed
    //- RV_INVALID_PARAMETER if number of virtual keys is not correct.
    //- RV_MEMORY_ERR if memory reach its size limit.

    return 1;
  }

  //Subscribe to key press and key release (at the moment)
  //subscribe to KPD_LONG_KEY_PRESS_NOTIF once implemented.
  notif_level = KPD_FIRST_PRESS_NOTIF | KPD_RELEASE_NOTIF;

#ifndef _SIMULATION_
///notify keypad message to subscriber in order to subscribe
  return_value = kpd_define_key_notification( subscriber_p, &notified_keys, notif_level,
              long_press_time, repeat_time );
#else
  return_value = RV_OK;
#endif

  if (return_value EQ RV_INVALID_PARAMETER ||
     return_value EQ RV_MEMORY_ERR)
  { //failed
    return 1;
  }
  return 0;
}




//#define hCommMMI  _ENTITY_PREFIXED(hCommACI)
//EXTERN T_HANDLE hCommMMI;
#define hCommMMI  _ENTITY_PREFIXED(hCommACI)
EXTERN T_HANDLE hCommMMI;

/*
+--------------------------------------------------------------------+
| PROJECT : MMI-Framework (8417)        MODULE  : ti1_key            |
| STATE   : code                        ROUTINE : sendKeyInd       |
+--------------------------------------------------------------------+

  PURPOSE : Sends an MMI_KEYPAD_IND to the protocol stack
*/
void sendKeyInd( T_KPD_VIRTUAL_KEY_ID virtual_key_id,
				    T_KPD_KEY_STATE key_state,
				    T_KPD_PRESS_STATE press_state)
{

	PALLOC(key_ind,MMI_KEYPAD_IND);
	
	key_ind->key_code = (U8)0;

	key_ind->key_stat = 0;

	//PSENDX(ACI,key_ind);
	PSENDX(MMI,key_ind); //glowing,2004-05-14

	return;
}

void SendVirtualKeyToMMI(U8 status,U8 keyvalue)
{
	PALLOC(key_ind,MMI_KEYPAD_IND);
	
	key_ind->key_code = (U8) keyvalue;
	key_ind->key_stat = status;


	if(MMIStart_completed)
		//PSENDX(ACI,key_ind);
		PSENDX(MMI,key_ind);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?