/* * set alarm */ EXPORT ER kpSetAlarm( AlarmState *alm, MSEC offsetTime ) { SYSTIM time; ER ercd; /* stop alarm (necessary) */ ercd = tk_stp_alm(alm->almno); if ( ercd != E_OK ) { DEBUG_PRINT(("kpSetAlarm, tk_stp_alm err = %d\n", ercd)); return ercd; } /* current time */ ercd = tk_get_tim(&time); if ( ercd != E_OK ) { DEBUG_PRINT(("kpSetAlarm, tk_get_tim err = %d\n", ercd)); return ercd; } alm->setTime = time.lo; /* start alarm handler */ ercd = tk_sta_alm(alm->almno, offsetTime); if ( ercd != E_OK ) { DEBUG_PRINT(("kpSetAlarm, tk_sta_alm err = %d\n", ercd)); return ercd; } return E_OK; }
/* * shift key : ON wait during effective time */ LOCAL KState ssOnTime( KeyState *skey, InnerEvent *evt, ReceiveData *msg ) { SYSTIM lnow; UW now; ER err; if ( msg == NULL ) { if ( keyMode.ontime == 0 ) goto spress; /* timeout setting for ON effective time */ err = kpSetAlarm(&skey->alm, keyMode.ontime); if ( err != E_OK ) { DEBUG_PRINT(("ssOnTime, SetAlarm err = %d\n", err)); return SS_ERROR; } return SS_ONTIME; } switch ( msg->head.cmd.cmd ) { case INP_KEY: if ( msg->kb.stat.press == 0 ) return SS_RELEASE; return SS_ONTIME; case PIC_TIMEOUT: if ( !kpChkAlarm(&skey->alm, &msg->tmout) ) return SS_ONTIME; break; default: return SS_ONTIME; } spress: /* current time */ err = tk_get_tim(&lnow); if ( err != E_OK ) { DEBUG_PRINT(("ssOnTime, tk_get_tim err = %d\n", err)); return SS_ERROR; } now = lnow.lo; if ( skey->u.s.pressCount == 1 && (now - skey->u.s.pressTime) <= keyMode.dclktime ) { skey->u.s.pressCount = 2; } else { skey->u.s.pressCount = 1; skey->u.s.pressTime = now; } /* shift press event generated */ makeShiftKeyEvent(evt, IE_S_PRESS, skey->u.s.skind); return SS_PRESS; }
/* date command */ LOCAL void cmd_date(INT ac, B *av[]) { ER er; struct tm ctm; SYSTIM stm; static const B *week[] = {"sun","mon","tue","wed","thu","fri","sat"}; if (ac < 2) { /* show current date */ tk_get_tim(&stm); er = dt_localtime_ms(&stm, NULL, &ctm); if (er < E_OK) { P("dt_localtime() ERR [%#x]\n", er); } else { P("%d/%02d/%02d (%s) %02d:%02d:%02d\n", ctm.tm_year + 1900, ctm.tm_mon + 1, ctm.tm_mday, week[ctm.tm_wday], ctm.tm_hour, ctm.tm_min, ctm.tm_sec); } } else if (ac >= 4) { /* set current date */ ctm.tm_year = atoi(av[1]) - 1900; ctm.tm_mon = atoi(av[2]) - 1; ctm.tm_mday = atoi(av[3]); ctm.tm_hour = (ac >= 5) ? atoi(av[4]) : 0; ctm.tm_min = (ac >= 6) ? atoi(av[5]) : 0; ctm.tm_sec = (ac >= 7) ? atoi(av[6]) : 0; ctm.tm_usec = 0; ctm.tm_wday = -1; ctm.tm_isdst = 0; ctm.tm_yday = 0; er = dt_mktime_ms(&ctm, NULL, &stm); if (er < E_OK) { P("dt_mktime() ERR [%#x]\n", er); } else { er = tk_set_tim(&stm); if (er < E_OK) { P("tk_set_tim() ERR [%#x]\n", er); } else { rtc_get_set(&stm, TRUE); } } } else if (ac == 2 && strcmp(av[1], "init") == 0) { /* initialize current date from RTC */ init_calendar_date(); } }
/* * shift key : release status */ LOCAL KState ssRelease( KeyState *skey, InnerEvent *evt, ReceiveData *msg ) { W keykind; SYSTIM lnow; UW now; ER err; if ( msg == NULL ) return SS_RELEASE; switch ( msg->head.cmd.cmd ) { case INP_KEY: if ( msg->kb.stat.press != 0 ) break; /* no break */ default: return SS_RELEASE; } /* current time */ err = tk_get_tim(&lnow); if ( err != E_OK ) { DEBUG_PRINT(("ssRelease, tk_get_tim err = %d\n", err)); return SS_ERROR; } now = lnow.lo; /* repeated press during the time interval for double click, key type is not changed. */ if ( !(skey->u.s.pressCount == 1 && (now - skey->u.s.pressTime) <= keyMode.dclktime) ) { /* key type */ keykind = kpGetKeyKind(skey->keytop); if ( keykind <= NormalKey ) { /* enter the ordinary state machine for normal keys */ memset(&skey->u.i, 0, sizeof(skey->u.i)); return KS_RELEASE; } skey->u.s.skind = keykind; } return SS_ONTIME; }
/* * alarm handler */ LOCAL void alarmHandler( void *exinf ) { AlarmState *alm = (AlarmState*)exinf; TimeoutMsg *msg; SYSTIM time; ER ercd; int i; /* look for message buffer free space */ for ( i = 0; i < NumOfAlmMsgBuf; ++i ) { if ( alm->msg[i].stat.read != 0 ) break; } if ( i >= NumOfAlmMsgBuf ) { /* try notifying that the message buffer has become full. */ for ( i = 0; i < NumOfAlmMsgBuf; ++i ) { alm->msg[i].stat.err = DEV_OVRRUN; } DEBUG_PRINT(("alarmHandler, over run error\n")); return; } /* set up message */ msg = &alm->msg[i]; msg->stat.read = 0; msg->stat.err = DEV_OK; /* set current time */ ercd = tk_get_tim(&time); if ( ercd != E_OK ) { DEBUG_PRINT(("alarmHandler, tk_get_tim err = %d\n", ercd)); msg->stat.err = DEV_SYSERR; } msg->time = time.lo; /* send timeout message */ kpSendPseudoMsg((T_MSG*)msg); }
/* * shift key: OFF wait during effective time */ LOCAL KState ssOffTime( KeyState *skey, InnerEvent *evt, ReceiveData *msg ) { InnEvtType innEvtType; SYSTIM lnow; UW now; ER err; if ( msg == NULL ) { if ( keyMode.offtime == 0 ) goto srelease; /* time out setting for OFF effective time */ err = kpSetAlarm(&skey->alm, keyMode.offtime); if ( err != E_OK ) { DEBUG_PRINT(("ssOffTime, SetAlarm err = %d\n", err)); return SS_ERROR; } return SS_OFFTIME; } switch ( msg->head.cmd.cmd ) { case INP_KEY: if ( msg->kb.stat.press != 0 ) return SS_PRESS; return SS_OFFTIME; case PIC_TIMEOUT: if ( !kpChkAlarm(&skey->alm, &msg->tmout) ) return SS_OFFTIME; break; default: return SS_OFFTIME; } srelease: /* current time */ err = tk_get_tim(&lnow); if ( err != E_OK ) { DEBUG_PRINT(("ssOffTime, tk_get_tim err = %d\n", err)); return SS_ERROR; } now = lnow.lo; switch ( skey->u.s.pressCount ) { case 1: if ( (now - skey->u.s.pressTime) < keyMode.sclktime ) { /* single click */ innEvtType = IE_S_SCLK; } else { innEvtType = IE_S_REL; } break; case 2: if ( (now - skey->u.s.pressTime) < keyMode.dclktime ) { /* double click */ innEvtType = IE_S_DCLK; } else { innEvtType = IE_S_REL; } skey->u.s.pressCount = 0; break; default: innEvtType = IE_S_REL; skey->u.s.pressCount = 0; } /* event generated */ makeShiftKeyEvent(evt, innEvtType, skey->u.s.skind); return SS_RELEASE; }