1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: 16: 17: 18: 19: 20:
21:
22: #include "kbpd.h"
23:
24: 25: 26:
27: LOCAL void kpSetAutoKeyID( UW kid )
28: {
29: if ( kpMgrInfo.kb.defKeyID == 0 ) {
30: kpMgrInfo.kb.defKeyID = 1;
31: kpMgrInfo.kb.keyID = kid;
32: }
33: }
34:
35: 36: 37:
38: LOCAL void kpClrAutoKeyID( UW kid )
39: {
40: if ( kpMgrInfo.kb.defKeyID == 1
41: && kpMgrInfo.kb.keyID == kid ) {
42: kpMgrInfo.kb.defKeyID = 0;
43: kpMgrInfo.kb.keyID = KID_unknown;
44: }
45: }
46:
47: 48: 49: 50:
51: LOCAL ID registCmdFlag( FlgInput *msg )
52: {
53: ID schID, setID;
54: int i;
55:
56: if ( msg->stat.reg == 0 ) {
57:
58: schID = msg->flgid;
59: setID = InvalidID;
60: if ( msg->stat.kb != 0 ) kpClrAutoKeyID(msg->stat.kbid);
61: } else {
62:
63: schID = InvalidID;
64: setID = msg->flgid;
65: if ( msg->stat.kb != 0 ) kpSetAutoKeyID(msg->stat.kbid);
66: }
67:
68: for ( i = 0; i < MaxCmd; ++i ) {
69: if ( kpMgrInfo.cmdFlg[i] == schID ) {
70: kpMgrInfo.cmdFlg[i] = setID;
71: return setID;
72: }
73: }
74:
75: return InvalidID;
76: }
77:
78:
79:
80: 81: 82:
83: LOCAL ER kpNotifyPdInput2( PdInput2 *msg )
84: {
85: static PdEvt2 evt = { {TDE_PDEXT} };
86: ER err;
87:
88:
89: if ( msg->stat.err != DEV_OK ) return E_OK;
90:
91:
92: if ( !kpMgrInfo.pd.pdMode.attr.wheel ) return E_OK;
93:
94: evt.wheel = msg->wheel;
95:
96:
97: err = kpNotifyEvent(&evt, sizeof(evt));
98: if ( err < E_OK ) goto err_ret;
99:
100: return E_OK;
101:
102: err_ret:
103: DEBUG_PRINT(("kpNotifyPdInput2 err = %d\n", err));
104: return err;
105: }
106:
107:
108:
109: 110: 111:
112: EXPORT void kpDataReceiveTask( void )
113: {
114: ReceiveData *msg;
115: InnerEvent evt;
116: BOOL cont;
117: TMO tmout = TMO_FEVR;
118: ID flg;
119: ER ercd;
120:
121: Lock(&kpMgrInfo.lock);
122:
123:
124: kpNotifyMetaEvent();
125:
126: for ( ;; ) {
127:
128:
129: Unlock(&kpMgrInfo.lock);
130: ercd = tk_rcv_mbx(kpMgrInfo.dataMbx, (T_MSG**)&msg, tmout);
131: Lock(&kpMgrInfo.lock);
132: if ( ercd != E_OK && ercd != E_TMOUT ) {
133: DEBUG_PRINT(("tk_rcv_mbx err = %d\n", ercd));
134: continue;
135: }
136:
137: if ( ercd == E_TMOUT ) {
138:
139: kpExecPdSimRepeat(&tmout);
140: continue;
141: }
142:
143: switch ( msg->head.cmd.cmd ) {
144: case INP_FLG:
145:
146: flg = registCmdFlag(&msg->flg);
147: msg->head.cmd.read = 1;
148:
149: if ( flg != InvalidID ) {
150:
151: kpSendInitialDeviceCommand(flg);
152: }
153: break;
154:
155: case INP_PD2:
156:
157: kpNotifyPdInput2(&msg->pd2);
158: msg->head.cmd.read = 1;
159: break;
160:
161: default:
162: do {
163:
164: cont = kpExecStateMachine(&evt, msg);
165:
166:
167: kpInnerEventProcess(&evt, &tmout);
168: } while ( cont );
169: msg->head.cmd.read = 1;
170: }
171: }
172:
173: tk_exd_tsk();
174: }
175:
176: 177: 178:
179: EXPORT ER kpStartDataReceiveTask( PRI pri )
180: {
181: T_CTSK ctsk;
182: ER ercd;
183: ER err;
184:
185:
186: err = kpInitializeStateMachine();
187: if ( err != E_OK ) {
188: DEBUG_PRINT(("initialize state machine err = %d\n", err));
189: return err;
190: }
191:
192:
193: SetOBJNAME(ctsk.exinf, "kbpd");
194: ctsk.tskatr = TA_HLNG|TA_RNG0;
195: ctsk.task = kpDataReceiveTask;
196: ctsk.itskpri = pri;
197: ctsk.stksz = DefaultStkSize;
198: ercd = tk_cre_tsk(&ctsk);
199: if ( ercd < E_OK ) {
200: DEBUG_PRINT(("create dataReceiveTask. ercd = %d\n", ercd));
201: return ercd;
202: }
203: kpMgrInfo.dataReceiveTask = (ID)ercd;
204:
205: ercd = tk_sta_tsk(kpMgrInfo.dataReceiveTask, 0);
206: if ( ercd != E_OK ) {
207: DEBUG_PRINT(("start dataReceiveTask. ercd = %d\n", ercd));
208: return ercd;
209: }
210:
211: return E_OK;
212: }
213:
214: 215: 216:
217: EXPORT void kpStopDataReceiveTask( void )
218: {
219: ID id;
220:
221:
222: if ( (id = kpMgrInfo.dataReceiveTask) != InvalidID ) {
223: tk_ter_tsk(id);
224: tk_del_tsk(id);
225: }
226:
227:
228: kpFinishStateMachine();
229: }