⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textkbd.c

📁 这个是单片机4200的ui程序
💻 C
字号:
/*
 *  Start of Zoran Standard Header
 *  Copyright (c) 2005 Zoran Corporation
 *  
 *  
 *  All rights reserved.  Proprietary and confidential.
 *  
 *  DESCRIPTION for textkbd.c
 *  	Combo-board keyboard interface for text-only user-interface.
 *  
 *  NEW HISTORY COMMENT (description must be followed by a blank line)
 *  <Enter change description here>

 *  ===== HISTORY of changes in //depot/imgeng/sw/se_gw/ui/fs/comboui/textkbd.c
 *  
 *   2/Dec/05 #7  dstrauss  kybdHandler now takes an unsigned int.
 *   8/Nov/05 #6  dstrauss  Make KEYBUF_SIZE 1
 *   1/Sep/05 #5  dstrauss  Increase key-down repeat time to 3/4 second.
 *  17/Aug/05 #4  dstrauss  Reduce key-down repeat time to 1/2 second.  
 *                          Use programmable keys to generate left-, right-, 
 *                          and menu-combo key events.
 *  16/Aug/05 #3  dstrauss  Renamed KybdInit to TextKbdInit to avoid conflict.
 *  16/Aug/05 #2  dstrauss  Hook into the (new) low-level keyboard handler.
 *   5/Aug/05 #1  dstrauss  Created.  Stub routines for now.
 *  
 *  End of Zoran Standard Header
 */
#include "univ.gh"
#include "arch.h"
#include "pile.h"
#include "dbg.h"
#include "standard.h"
#include "ts.h"

#include "uimisc.h"
#include "uikbd.h"
#include "kbdif.h"
#include "textkbd.h"

#define OLDKEY_MENU       0x00
#define OLDKEY_LEFT       0x01
#define OLDKEY_RIGHT      0x02
#define OLDKEY_SELECT     0x03
#define OLDKEY_COPIES     0x04
#define OLDKEY_SCALE      0x05
#define OLDKEY_BRIGHTNESS 0x06
#define OLDKEY_PAPERTYPE  0x07
#define OLDKEY_QUALITY    0x08

#define OLDKEY_MODE       0x0a
#define OLDKEY_MONOCOPY   0x0c
#define OLDKEY_COLORCOPY  0x0d
#define OLDKEY_SCAN       0x0e
#define OLDKEY_CANCEL     0x0f



/***** START FAX_ENABLED CODE *****/
#ifdef FAX_ENABLED
#define PANEL_KEY_UP		0x20
#define PANEL_KEY_DOWN		0x21
#define PANEL_KEY_ONE		0x22
#define PANEL_KEY_TWO		0x23
#define PANEL_KEY_THREE		0x24
#define PANEL_KEY_FOUR		0x25
#define PANEL_KEY_FIVE		0x26
#define PANEL_KEY_SIX		0x27
#define PANEL_KEY_SEVEN		0x28
#define PANEL_KEY_EIGHT		0x29
#define PANEL_KEY_NINE		0x2a
#define PANEL_KEY_DOT		0x2b
#define PANEL_KEY_ZERO		0x2c
#define PANEL_KEY_HASH		0x2d
#define PANEL_KEY_SPEED1	0x2e
#define PANEL_KEY_SPEED2	0x2f
#define PANEL_KEY_SPEED3	0x30
#define PANEL_KEY_SPEED4	0x31
#define PANEL_KEY_COLORFAX	0x32
#define PANEL_KEY_MONOFAX	0x33
#define PANEL_KEY_RES		0x34
#endif
/***** END FAX_ENABLED CODE *****/
















#define KEYBUF_SIZE       1    /* MUST be a power of 2! */

static Uint8 keybuf[KEYBUF_SIZE];

static Uint32 keybufInCount;
static Uint32 keybufOutCount;
static tsSemaphore kSem;     /* old keyboard handler semaphore   */

static Uint32 keypressTime;

/******************************************************************************
* Name:        KybdGetKeyDownTime
*
* Description: Return the amount of time (in milliseconds) that the same key
*              has been pressed.
*
* Parameters:  pDownTime   - pointer to a variable to hold the key down time.
*
* Return:      API_OK   - command succeeded.
*              API_FAIL - command failed.
*                          - keyboard not initialized
*                          - unable to get or release the api semaphore
*
* Notes:       Use of this API is deprecated.
******************************************************************************/
API_RET KybdGetKeyDownTime(Uint32* pDownTime)
{
  int keycount;

  TASKSEMWAIT(kSem);
  keycount = keybufInCount - keybufOutCount;
  if (keycount || (keypressTime == 0) ) {
    /* if there are still unread key presses in the buffer, the
     * "down time" is effectively zero.
     */
    *pDownTime = 0;
  } else {
    /* repeat if the button is held down for more than 3/4 second */
    *pDownTime = (TaskGetSystemMilliTicks() - keypressTime)/750;
  }
  TASKSEMSIGNAL(kSem);
  return API_OK;
}

/******************************************************************************
* Name:        KybdHits
*
* Description: Check if any keys have been pressed.
*
* Parameters:  pNumKeys - pointer to a variable to hold the number of keys
*                          in the keyboard buffer.
*
* Return:      API_OK   - command succeeded.
*              API_FAIL - command failed.
*                          - keyboard not initialized
*                          - unable to get or release the api semaphore
*
* Notes:       Use of this API is deprecated.
******************************************************************************/
API_RET KybdHits(Uint8* pNumKeys)
{
  TASKSEMWAIT(kSem);
  *pNumKeys = keybufInCount - keybufOutCount;
  TASKSEMSIGNAL(kSem);
  return (API_OK);
}


/******************************************************************************
* Name:        KybdGetKey
*
* Description: Read a key code from the keyboard buffer.
*
* Parameters:  pCode    - pointer to a variable to hold the key code:
*                          - KYBD_NO_KEY (0xFF) if no key was available before
*                             timeout
*                          - key code (0..63) of the key pressed
*              timeout  - the amount of time the procedure will wait (in ticks)
*                          for a key to be pressed.  A timeout of '0' will wait
*                          forever.
*
* Return:      API_OK   - command succeeded.
*              API_FAIL - command failed.
*                          - keyboard not initialized
*                          - unable to get or release the api semaphore
*
* Notes:       Use of this API is deprecated.
******************************************************************************/
API_RET KybdGetKey(Uint8* pCode, Uint32 timeout)
{
  TASKSEMWAIT(kSem);
  if (keybufInCount > keybufOutCount) {
    *pCode = keybuf[keybufOutCount % KEYBUF_SIZE];
    keybufOutCount++;
  } else {
    *pCode = KYBD_NO_KEY;
  }
  TASKSEMSIGNAL(kSem);
  return(API_OK);
}

static void kybdHandler(unsigned int keycode)
{
  Uint8 oldkey;



/***** START FAX_ENABLED CODE *****/
/*
#ifdef FAX_ENABLED
			char tmp[17];
			sprintf(tmp, "keyPressed:%d", keycode);
			LcdClrLine(0);
			LcdStr(0, 0, tmp);
#endif
*/
/***** END FAX_ENABLED CODE *****/


  /* convert new key codes into old (legacy) key codes */
  switch (keycode) {

/***** START FAX_ENABLED CODE *****/
#ifdef FAX_ENABLED
  case (KEY_UP|KEY_IS_DOWN):		oldkey = PANEL_KEY_UP;		break;
  case (KEY_DOWN|KEY_IS_DOWN):		oldkey = PANEL_KEY_DOWN;	break;
  case (KEY_ONE|KEY_IS_DOWN):		oldkey = PANEL_KEY_ONE;		break;
  case (KEY_TWO|KEY_IS_DOWN):		oldkey = PANEL_KEY_TWO;		break;
  case (KEY_THREE|KEY_IS_DOWN):		oldkey = PANEL_KEY_THREE;	break;
  case (KEY_FOUR|KEY_IS_DOWN):		oldkey = PANEL_KEY_FOUR;	break;
  case (KEY_FIVE|KEY_IS_DOWN):		oldkey = PANEL_KEY_FIVE;	break;
  case (KEY_SIX|KEY_IS_DOWN):		oldkey = PANEL_KEY_SIX;		break;
  case (KEY_SEVEN|KEY_IS_DOWN):		oldkey = PANEL_KEY_SEVEN;	break;
  case (KEY_EIGHT|KEY_IS_DOWN):		oldkey = PANEL_KEY_EIGHT;	break;
  case (KEY_NINE|KEY_IS_DOWN):		oldkey = PANEL_KEY_NINE;	break;
  case (KEY_DOT|KEY_IS_DOWN):		oldkey = PANEL_KEY_DOT;		break;
  case (KEY_ZERO|KEY_IS_DOWN):		oldkey = PANEL_KEY_ZERO;	break;
  case (KEY_HASH|KEY_IS_DOWN):		oldkey = PANEL_KEY_HASH;	break;
  case (KEY_SPEED1|KEY_IS_DOWN):	oldkey = PANEL_KEY_SPEED1;	break;
  case (KEY_SPEED2|KEY_IS_DOWN):	oldkey = PANEL_KEY_SPEED2;	break;
  case (KEY_SPEED3|KEY_IS_DOWN):	oldkey = PANEL_KEY_SPEED3;	break;
  case (KEY_SPEED4|KEY_IS_DOWN):	oldkey = PANEL_KEY_SPEED4;	break;
  case (KEY_COLORFAX|KEY_IS_DOWN):	oldkey = PANEL_KEY_COLORFAX;break;
  case (KEY_MONOFAX|KEY_IS_DOWN):	oldkey = PANEL_KEY_MONOFAX;	break;
  case (KEY_RES|KEY_IS_DOWN):		oldkey = PANEL_KEY_RES;		break;
#endif
/***** END FAX_ENABLED CODE *****/


  case (KEY_MONOCOPY|KEY_IS_DOWN):
    oldkey = OLDKEY_MONOCOPY;
    break;
  case (KEY_CANCEL|KEY_IS_DOWN):
    oldkey = OLDKEY_CANCEL;
    break;
  case (KEY_COLORCOPY|KEY_IS_DOWN):
    oldkey = OLDKEY_COLORCOPY;
    break;
  case (KEY_COLORSCAN|KEY_IS_DOWN):
    /* colorscan is the same as monoscan on the old UI */
  case (KEY_MONOSCAN|KEY_IS_DOWN):
    oldkey = OLDKEY_SCAN;
    break;
  case (KEY_QUALITY|KEY_IS_DOWN):
    oldkey = OLDKEY_QUALITY;
    break;
  case (KEY_MODE|KEY_IS_DOWN):
    oldkey = OLDKEY_MODE;
    break;
  case (KEY_COPIES|KEY_IS_DOWN):
    oldkey = OLDKEY_COPIES;
    break;
  case (KEY_SCALE|KEY_IS_DOWN):
    oldkey = OLDKEY_SCALE;
    break;
  case (KEY_BRIGHTNESS|KEY_IS_DOWN):
    oldkey = OLDKEY_BRIGHTNESS;
    break;
  case (KEY_PAPERTYPE|KEY_IS_DOWN):
    oldkey = OLDKEY_PAPERTYPE;
    break;
  case (KEY_MENU|KEY_IS_DOWN):
    oldkey = OLDKEY_MENU;
    break;
  case (KEY_LEFT|KEY_IS_DOWN):
    oldkey = OLDKEY_LEFT;
    break;
  case (KEY_RIGHT|KEY_IS_DOWN):
    oldkey = OLDKEY_RIGHT;
    break;
  case (KEY_SELECT|KEY_IS_DOWN):
    oldkey = OLDKEY_SELECT;
    break;
  case (KEY_PROG1|KEY_IS_DOWN):
    oldkey = KEY_COMBO_LEFT;
    break;
  case (KEY_PROG2|KEY_IS_DOWN):
    oldkey = KEY_COMBO_RIGHT;
    break;
  case (KEY_PROG3|KEY_IS_DOWN):
    oldkey = KEY_COMBO_MENU;
    break;



/***** START FAX_ENABLED CODE *****/
#ifdef FAX_ENABLED
  case (KEY_UP):
  case (KEY_DOWN):
  case (KEY_ONE):
  case (KEY_TWO):
  case (KEY_THREE):
  case (KEY_FOUR):
  case (KEY_FIVE):
  case (KEY_SIX):
  case (KEY_SEVEN):
  case (KEY_EIGHT):
  case (KEY_NINE):
  case (KEY_DOT):
  case (KEY_ZERO):
  case (KEY_HASH):
  case (KEY_SPEED1):
  case (KEY_SPEED2):
  case (KEY_SPEED3):
  case (KEY_SPEED4):
  case (KEY_COLORFAX):
  case (KEY_MONOFAX):
  case (KEY_RES):
#endif
/***** END FAX_ENABLED CODE *****/

  case (KEY_MONOCOPY):
  case (KEY_CANCEL):
  case (KEY_COLORCOPY):
  case (KEY_COLORSCAN):
  case (KEY_MONOSCAN):
  case (KEY_QUALITY):
  case (KEY_MODE):
  case (KEY_COPIES):
  case (KEY_SCALE):
  case (KEY_BRIGHTNESS):
  case (KEY_PAPERTYPE):
  case (KEY_MENU):
  case (KEY_LEFT):
  case (KEY_RIGHT):
  case (KEY_SELECT):
  case (KEY_PROG1):
  case (KEY_PROG2):
  case (KEY_PROG3):
    /* Assume all key-up events match a single key-down event.  This
     * isn't necessarily true but it's close enough to work for the
     * routine that checks on this.
     */
    keypressTime = 0;
  default:                      /* do nothing for all the other keys */
    return;
  }

  if ((keybufInCount - keybufOutCount) >= KEYBUF_SIZE) {
    /* drop any keys as long as the buffer is full */
    return;
  }

  /* latch the time the key was pressed */
  keypressTime = TaskGetSystemMilliTicks();
  
  /* save the key code */
  keybuf[keybufInCount % KEYBUF_SIZE] = oldkey;
  keybufInCount++;
}


/************************************************************
 * 
 ************************************************************/
void TextKbdInit(void)
{
  int retval;

  kSem = TASKSEMCREATE(1);
  retval = KBDIFRegisterKeyHandler(kybdHandler);
  ASSERT(retval == 0);
}

⌨️ 快捷键说明

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