📄 evttsk.c
字号:
/* *---------------------------------------------------------------------- * T-Kernel / Standard Extension * * Copyright (C) 2006 by Ken Sakamura. All rights reserved. * T-Kernel / Standard Extension is distributed * under the T-License for T-Kernel / Standard Extension. *---------------------------------------------------------------------- * * Version: 1.00.00 * Released by T-Engine Forum(http://www.t-engine.org) at 2006/8/11. * *---------------------------------------------------------------------- *//* * evttsk.c (event) * * Event management * Device event receiving task */#include "evtmgr.h"#include <extension/message.h>LOCAL BOOL putEvt( W type, EVDATA *evdat, EmDevEvt *dev, W devsz );LOCAL BOOL putEvt_Key( W type, KeyEvt *kevt );LOCAL void chgMetaState( MetaBut meta );LOCAL BOOL putEvt_Pd( PdEvt *pevt );LOCAL BOOL putEvt_PdExt( PdEvt2 *pevt );LOCAL void chgPdState( MetaBut meta );LOCAL BOOL putEvt_Device( EmDevEvt *dev, W devsz );LOCAL BOOL putEvt_Exdev( EmDevEvt *dev, W devsz );LOCAL BOOL rcvDevEvt( EmDevEvt *devEvt, W evtsz );LOCAL void updateState( void );/* * PD state related things from among the metakey/PD button state. */#define ES_PD ((ES_BASICBTN)|(ES_EXTBTN)|(ES_NODSP))#define ES_PDSTATE (ES_PDSIM)#define TSD_RDE_TYP_0X0100 0x0100#define TSD_PEV_MIN_0X30 0x30#define TSD_PEV_MAX_0X80 0x80#define TSD_RDE_TYP_0X0080 0x0080/* * Register in the event queue. * Call the EmInfo with it being locked. */LOCAL BOOL putEvt( W type, EVDATA *evdat, EmDevEvt *dev, W devsz ){ EmEvt *ep, tmp; SYSTIME now; BOOL msgonly; /* Ignore if the system event mask is 0. */ if ( !isMatchEvtMsk(type) ) { return FALSE; } /* Device event type 0x30 - 0x7f is not stored in the event queue. Perform only the event message sending. */ msgonly = ( (type == EV_DEVICE) && ((evdat->dev.kind >= TSD_PEV_MIN_0X30) && (evdat->dev.kind < TSD_PEV_MAX_0X80)) ); if ( !msgonly ) { /* Reserve free entry for the queue. */ ep = newEmEvt(); if ( ep == NULL ) { /* The queue is full. */ SYSLOG((LOG_WARNING, "EvtMgr: queue overflow, lost event type %d.", type)); /* Even if the event queue is full, send the event message. */ ep = &tmp; } } else { ep = &tmp; } /* Event setting */ ep->evt.type = type; ep->evt.time = getEvtTime(&now); ep->evt.pos = evtque.pos; ep->evt.data = *evdat; ep->evt.stat = evtque.stat; if ( type == EV_EXDEV ) { memcpy(ep->evt.exdat, dev->ex.h.exdat, (size_t)sizeof(ep->evt.exdat)); } else { memset(ep->evt.exdat, 0, (size_t)sizeof(ep->evt.exdat)); } if ( !msgonly ) { if ( ep != &tmp ) { /* Add to the event queue. */ putEmEvt(ep); } setLastEvt(type, now); } /* Send the event message. */ (void)emSendEvtMsg(&ep->evt, dev, devsz); return msgonly;}/* * Process the key event. */LOCAL BOOL putEvt_Key( W type, KeyEvt *kevt ){ BOOL msgonly = FALSE; EVDATA evdat; Enter; if ( type == EV_KEYDWN ) { /* Record the pressed keys. */ evtque.keytop = kevt->keytop; evtque.code = kevt->code; evtque.pressKey = TRUE; } else { if ( evtque.keytop == kevt->keytop ) { /* Stop the repeat. */ (void)emSetKeyRepeat(0, 0, FALSE); evtque.pressKey = FALSE; } } if ( kevt->code != 0 ) { /* Set the key event. */ evdat.key.keytop = kevt->keytop; evdat.key.code = kevt->code; msgonly = putEvt(type, &evdat, NULL, 0); } Return (msgonly);}/* * Update the metakey state. */LOCAL void chgMetaState( MetaBut meta ){ Enter; evtque.stat &= ~(UW)ES_META; evtque.stat |= *(UW*)&meta & ES_META; evtque.chgMeta = TRUE; Exit;}/* * Process the PD event. */LOCAL BOOL putEvt_Pd( PdEvt *pevt ){ UW stat; UW but, esmsk; BOOL msgonly = FALSE; Enter; /* Move the PD position. */ evtque.pos.x = pevt->stat.xpos; evtque.pos.y = pevt->stat.ypos; evtque.chgPos = TRUE; esmsk = ( pevt->h.evttyp == (W)TDE_PDMOVE )? ES_NODSP: ES_PD; /* Update the PD button state/non-display state. */ stat = evtque.stat; evtque.stat &= ~esmsk; evtque.stat |= *(UW*)&pevt->stat.stat & esmsk; /* Whether the PD basic button changed. */ but = (evtque.stat ^ stat) & (ES_BASICBTN | ES_EXTBTN); if ( but != 0U ) { W type; EVDATA evdat; /* PD button event occurred. */ type = ( (evtque.stat & (ES_BASICBTN | ES_EXTBTN)) != 0U ) ? EV_BUTDWN: EV_BUTUP; evdat.info = 0; msgonly = putEvt(type, &evdat, NULL, 0); } Return (msgonly);}/* * Process the PD extended event. */LOCAL BOOL putEvt_PdExt( PdEvt2 *pevt ){ SYSTIME now, life; Enter; /* Ignore if the system event mask is 0. */ if ( (evtque.sysEvtMsk & EM_AUTKEY) == 0U ) { Return (FALSE); } getEvtTime(&now); if ( evtque.wheel != 0 ) { /* Because a previous wheel event remains, if the event is before automatic expiration and the rotation direction is same, total up the amount of wheel rotations. */ life = ll_add(evtque.lastWheel, ltoll(emInfo.evtLifeTime)); if ( (ll_cmp(life, now) >= (longlong)0) && ((evtque.wheel >= 0) == (pevt->wheel >= 0)) ) { pevt->wheel += evtque.wheel; } } evtque.wheel = pevt->wheel; evtque.lastWheel = now; setLastEvt(EV_AUTKEY, now); Return (FALSE);}/* * Update the PD state. */LOCAL void chgPdState( MetaBut meta ){ Enter; evtque.stat &= ~(UW)ES_PDSTATE; evtque.stat |= *(UW*)&meta & ES_PDSTATE; evtque.chgPdStat = TRUE; Exit;}/* * Process the device event(EV_DEVICE). */LOCAL BOOL putEvt_Device( EmDevEvt *dev, W devsz ){ EVDATA evdat; BOOL msgonly; /* Device event occurred. */ evdat.dev.kind = dev->c.evttyp; evdat.dev.devno = (H)dev->c.devid; LOCK_EM( msgonly = putEvt(EV_DEVICE, &evdat, dev, devsz) ); return msgonly;}/* * Process the expand device event(EV_EXDEV) */LOCAL BOOL putEvt_Exdev( EmDevEvt *dev, W devsz ){ EVDATA evdat; BOOL msgonly; /* Expand device event occurred */ evdat.dev.kind = dev->ex.h.evttyp; evdat.dev.devno = (H)dev->ex.h.devid; LOCK_EM( msgonly = putEvt(EV_EXDEV, &evdat, dev, devsz) ); return msgonly;}/* * Device event received */LOCAL BOOL rcvDevEvt( EmDevEvt *devEvt, W evtsz ){ BOOL msgonly = FALSE; switch ( devEvt->c.evttyp ) { case TDE_KEYDOWN: msgonly = putEvt_Key(EV_KEYDWN, &devEvt->k); break; case TDE_KEYUP: msgonly = putEvt_Key(EV_KEYUP, &devEvt->k); break; case TDE_KEYMETA: chgMetaState(devEvt->k.stat); break; case TDE_PDBUT: case TDE_PDMOVE: msgonly = putEvt_Pd(&devEvt->p); break; case TDE_PDSTATE: chgPdState(devEvt->p.stat.stat); break; case TDE_PDEXT: msgonly = putEvt_PdExt(&devEvt->p2); break; default: /* Other events : Device event */ if ( devEvt->c.evttyp < TSD_RDE_TYP_0X0080) { /* Device event */ msgonly = putEvt_Device(devEvt, evtsz); } else if ( devEvt->c.evttyp < TSD_RDE_TYP_0X0100) { /* Extended device event */ msgonly = putEvt_Exdev(devEvt, evtsz); } else { /* User Event: There is no processing. */ } break; } return msgonly;}/* * Move the PD / Display the metakey state. */LOCAL void updateState( void ){ BOOL chgPos, chgPdStat, chgMeta; PNT pos; UW stat; SYSTIME now; LOCK_EM( /* Current time */ getEvtTime(&now); /* PD / Metakey state */ pos = evtque.pos; stat = evtque.stat; chgPos = evtque.chgPos; chgPdStat = evtque.chgPdStat; chgMeta = evtque.chgMeta; /* Reset the state change flag. */ evtque.chgPos = FALSE; evtque.chgPdStat = FALSE; evtque.chgMeta = FALSE; /* Record the state change as the time of the last event occurrence. */ if ( chgPos || chgPdStat ) { setLastEvt(EV_BUTDWN, now); setLastEvt(EV_BUTUP, now); } if ( chgMeta != 0 ) { setLastEvt(EV_KEYDWN, now); setLastEvt(EV_KEYUP, now); } );}/* * Device event receiving task */EXPORT void emEventReceiveTask( void ){ EmDevEvt devEvt; INT msgsz; BOOL msgonly; TMO tmout = TMO_FEVR; ER er; for ( ;; ) { /* It does not end by itself. */ /* Device event received */ msgsz = er = tk_rcv_mbf(emInfo.evtRcvMbf, &devEvt, tmout); if ( er >= E_OK ) { /* Event receiving processing */ msgonly = rcvDevEvt(&devEvt, msgsz); /* Notify the message management of the event occurrence. */ if (!msgonly) { tkse_brk_msg(); } tmout = TMO_POL; } else if ( er == E_TMOUT ) { /* Move the PD / Display the metakey state. */ updateState(); tmout = TMO_FEVR; } else { DEBUG_PRINT(("trcv_mbf er = %d\n", er)); tmout = TMO_FEVR; } } tk_exd_tsk();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -