void osip_usleep (int useconds) { #if defined(__PALMOS__) && (__PALMOS__ >= 0x06000000) /* This bit will work for the Protein API, but not the Palm 68K API */ nsecs_t nanoseconds = useconds * 1000; SysThreadDelay (nanoseconds, P_ABSOLUTE_TIMEOUT); #elif defined(__PALMOS__) && (__PALMOS__ < 0x06000000) UInt32 stoptime = TimGetTicks () + (useconds / 1000000) * SysTicksPerSecond (); while (stoptime > TimGetTicks ()) /* I wish there was some type of yield function here */ ; #elif defined(WIN32) Sleep (useconds / 1000); #else struct timeval delay; int sec; sec = (int) useconds / 1000000; if (sec > 0) { delay.tv_sec = sec; delay.tv_usec = 0; } else { delay.tv_sec = 0; delay.tv_usec = useconds; } select (0, 0, 0, 0, &delay); #endif }
static void EventLoop (void) { EventType event; SDWord timeout; UInt32 timer_next; Word error; do { timeout = evtWaitForever; timer_next = 0; if (needRedisplay) timeout = 0; else if (game.timer_running) { UInt32 now = TimGetTicks (); int sec = (now - game.timer_start) / sysTicksPerSecond; timer_next = ((sec + 1) * sysTicksPerSecond + game.timer_start); timeout = timer_next - now; } EvtGetEvent (&event, timeout); DIAG (("Event %d\n", event.eType)); if (timer_next && TimGetTicks () <= timer_next) DamageCount (); if (needRedisplay && event.eType == nilEvent) FrmUpdateForm (mainForm, frmRedrawUpdateCode); if (event.eType == nilEvent) continue; /* Give the system a chance to handle the event. */ if (! SysHandleEvent (&event)) { if (!MenuHandleEvent (0, &event, &error)) { /* Give the application a chance to handle the event. */ if (!ApplicationHandleEvent (&event)) { /* Let the form object provide default handling of the event. */ FrmDispatchEvent (&event); } } } } while (event.eType != appStopEvent); // ** SPECIAL NOTE ** // In order for the Emulator to exit // cleanly when the File|Quit menu option is // selected, the running application // must exit. The emulator will generate an // ÒappStopEventÓ when Quit is selected. }
void PediaMainForm::handleControlSelect(const EventType& event) { LookupManager* lookupManager = app().getLookupManager(); if (NULL != lookupManager && lookupManager->lookupInProgress()) return; bool fFullText = false; switch (event.data.ctlSelect.controlID) { case searchButton: // If button held for more than ~300msec, perform full text search. if (TimGetTicks() - lastPenDownTimestamp_ > app().ticksPerSecond()/3) fFullText = true; search(fFullText); break; case backButton: moveHistory(false); break; case forwardButton: moveHistory(true); break; default: assert(false); } }
int scGeneralGetRandStr( BYTE *data, int len ) { #if defined(HAVE_LIBCRYPT) cryptGetRandom( data, len ); #elif defined(__palmos__) SysRandom( TimGetTicks() ); while( len-- ){ *data++ = SysRandom(0) & 0xFF; } #elif defined(__linux__) FILE *fptr; fptr = fopen( "/dev/urandom", "rb" ); if( fptr==NULL ) return( SC_EXIT_UNKNOWN_ERROR ); if( fread( data, 1, len, fptr )!=len ) return( SC_EXIT_UNKNOWN_ERROR ); #else srand( time( NULL ) ); while( len-- ){ *data++ = rand() & 0xFF; } #endif /* HAVE_LIBCRYPT */ return( SC_EXIT_OK ); }
ticks_t time_ticks( void ) { #ifdef UNIX #ifdef OSX //OSX: mach_timebase_info_data_t sTimebaseInfo; if( sTimebaseInfo.denom == 0 ) { mach_timebase_info( &sTimebaseInfo ); } uint64_t t = mach_absolute_time(); return (ticks_t)( ( t * sTimebaseInfo.numer / sTimebaseInfo.denom ) / 1000000 ); #else //UNIX: timespec t; clock_gettime( CLOCK_REALTIME, &t ); return (ticks_t)( t.tv_nsec / 1000000 ) + t.tv_sec * 1000; #endif #endif #ifdef PALMOS //PALM: return (ticks_t)TimGetTicks(); #endif #if defined(WIN) || defined(WINCE) //WINDOWS: return (ticks_t)GetTickCount(); #endif }
void RunCount(UInt32 start_tik) { UInt32 tik,dtik; run=1; while(run==1) { tik = TimGetTicks(); dtik = tik - start_tik; drawCount(dtik); // call this periodically to hold off auto off if (stopWatchPrefs.disableAutoOff) EvtResetAutoOffTimer(); // delay one tenth of a sec (.09 acksherly to be sly) SysTaskDelay((90 * SysTicksPerSecond())/1000); // within loop call SysHandleEvent to // give system opportunity to break in? // /opt/palmdev/sdk-5/include/Core/UI/Event.h { UInt16 err; EventType e; EvtGetEvent(&e, 0); if (! SysHandleEvent (&e)) if (! MenuHandleEvent (NULL, &e, &err)) if (! ApplicationHandleEvent (&e)) FrmDispatchEvent (&e); } } }
// although it is not the same as gettimeofday as unix // but we only use the diffrences of tow values int CCTime::gettimeofdayCocos2d(struct cc_timeval *tp, void *tzp) { unsigned int ms = TimGetTicks(); tp->tv_sec = ms * 10 / 1000; tp->tv_usec = ms * 10 % 1000 * 1000; return 0; }
void Application_ProcessMessages(int ticks) { EventType event; UInt32 until=TimGetTicks()+ticks; UInt16 error; do { EvtGetEvent(&event, 3); if(event.eType == appStopEvent) { StopEvent=1; break; } if (! SysHandleEvent(&event)) if (! MenuHandleEvent(0, &event, &error)) if (! Application_EventHandler(&event)) FrmDispatchEvent(&event); } while(TimGetTicks()<until); }
bool PediaMainForm::handleKeyPress(const EventType& event) { bool handled = false; if (fiveWayCenterPressed(&event)) lastPenDownTimestamp_ = TimGetTicks(); switch (event.data.keyDown.chr) { case chrLineFeed: case chrCarriageReturn: lastPenDownTimestamp_ = TimGetTicks(); searchButton_.hit(); handled = true; break; } return handled; }
/* Set a new Timeout value and callback function*/ void TimeoutSet ( UInt32 ticks, void* callbackFunc ) { lastTick = TimGetTicks(); minTicks = ticks; TimeoutCallbackHandler = callbackFunc; }
static void TimerStart (void) { if (!game.timer_running) { game.timer_running = true; game.timer_start = TimGetTicks (); DamageCount (); } }
static Boolean MainFormHandleEvent (EventPtr e) { Boolean handled = false; FormPtr frm; CALLBACK_PROLOGUE switch (e->eType) { case frmOpenEvent: frm = FrmGetActiveForm(); FrmDrawForm(frm); handled = true; break; case menuEvent: MenuEraseStatus(NULL); switch(e->data.menu.itemID) { } handled = true; break; case ctlSelectEvent: switch(e->data.ctlSelect.controlID) { } break; case nilEvent: { UInt32 dt, t0 = TimGetTicks(); mainloop (); dt = TimGetTicks() - t0; timeout = (TimGetTicks() - t0 > ticks) ? 0 : ticks - dt; } break; default: break; } CALLBACK_EPILOGUE return handled; }
void osip_usleep (int useconds) { #if defined(__PALMOS__) && (__PALMOS__ >= 0x06000000) /* This bit will work for the Protein API, but not the Palm 68K API */ nsecs_t nanoseconds = useconds * 1000; SysThreadDelay (nanoseconds, P_ABSOLUTE_TIMEOUT); #elif defined(__PALMOS__) && (__PALMOS__ < 0x06000000) UInt32 stoptime = TimGetTicks () + (useconds / 1000000) * SysTicksPerSecond (); while (stoptime > TimGetTicks ()) /* I wish there was some type of yield function here */ ; #elif defined(WIN32) Sleep (useconds / 1000); #elif defined(__rtems__) rtems_task_wake_after( RTEMS_MICROSECONDS_TO_TICKS(useconds) ); #elif defined(__arc__) struct timespec req; struct timespec rem; req.tv_sec = (int) useconds / 1000000; req.tv_nsec = (int) (useconds % 1000000)*1000; nanosleep (&req, &rem); #else struct timeval delay; int sec; sec = (int) useconds / 1000000; if (sec > 0) { delay.tv_sec = sec; delay.tv_usec = 0; } else { delay.tv_sec = 0; delay.tv_usec = useconds; } select (0, 0, 0, 0, &delay); #endif }
Boolean FlickrProgressCallback(PrgCallbackData* data) { if (errNone != data->error) return FlickrErrCallback(data); FlickrSocketContext* context = (FlickrSocketContext*)data->userDataP; char buffer[32] = {chrNull}; char* text = ""; assert(context != NULL); switch (data->stage) { case stageReadingImageData: text = "Reading image data: "; PrvFormatBytes(buffer, context->imageSize); break; case stageResolvingHostAddress: text = "Resolving host address..."; break; case stageOpeningConnection: text = "Connecting..."; break; case stageUploadingImage: text = "Uploading image: "; PrvFormatPercents(buffer, ((context->sent * 1000L) + 5L)/(context->requestSize * 10L)); break; case stageReadingResponse: text = "Waiting for response..."; break; case stageFinished: text = "Upload finished"; break; default: assert(false); } UInt32 ticks = TimGetTicks(); if (ticks - FLICKR_PROGRESS_ANIMATION_TIMEOUT >= context->lastAnimationTicks) { data->bitmapId = FlickrNextProgressBitmapID(data->bitmapId); context->lastAnimationTicks = ticks; } PrvFillBuffer(data->textP, data->textLen, text, buffer); data->textChanged = true; return true; }
Boolean v4pDisplayStart() { int i ; t1 = TimGetTicks(); iBuffer = marginY * screenWidth + marginX ; //Init collides for (i = 0 ; i < 16 ; i++) { collides[i].q = 0 ; collides[i].x = 0 ; collides[i].y = 0 ; collides[i].poly = NULL ; } return success ; }
void OSystem_PalmBase::battery_handler() { // check battery level every 15secs if ((TimGetTicks() - _batCheckLast) > _batCheckTicks) { UInt16 voltage, warnThreshold, criticalThreshold; Boolean pluggedIn; voltage = SysBatteryInfoV20(false, &warnThreshold, &criticalThreshold, NULL, NULL, &pluggedIn); if (!pluggedIn) { if (voltage <= warnThreshold) { if (!_showBatLow) { _showBatLow = true; draw_osd(kDrawBatLow, _screenDest.w - 18, -16, true, 2); displayMessageOnOSD("Battery low."); } } else { if (_showBatLow) { _showBatLow = false; draw_osd(kDrawBatLow, _screenDest.w - 18, -16, false); } } if (voltage <= criticalThreshold) { ::EventType event; event.eType = keyDownEvent; event.data.keyDown.chr = vchrPowerOff; event.data.keyDown.modifiers = commandKeyMask; #if defined(COMPILE_OS5) && defined(PALMOS_ARM) SysEventAddToQueue(&event); #else EvtAddEventToQueue(&event); #endif } } _batCheckLast = TimGetTicks(); } }
OSystem_PalmBase::OSystem_PalmBase() { _overlayVisible = false; _current_shake_pos = 0; _new_shake_pos = 0; _paletteDirtyStart = 0; _paletteDirtyEnd = 0; _gfxLoaded = false; _modeChanged = false; _setMode = GFX_NORMAL; _mode = _setMode; _redawOSD = false; _setPalette = true; _offScreenH = NULL; _screenH = NULL; _offScreenP = NULL; _screenP = NULL; _screenPitch = gVars->screenPitch; _wasKey = false; _lastKeyModifier = kModifierNone; _lastKeyRepeat = 100; _useNumPad = false; _showBatLow = false; _batCheckTicks = SysTicksPerSecond() * 15; _batCheckLast = TimGetTicks(); _saveMgr = 0; _timerMgr = 0; _mixerMgr = 0; _mouseDataP = NULL; _mouseBackupP = NULL; _mouseVisible = false; _mouseDrawn = false; MemSet(&_keyExtra, sizeof(_keyExtra), 0); MemSet(&_mouseCurState, sizeof(_mouseCurState), 0); MemSet(&_mouseOldState, sizeof(_mouseOldState), 0); MemSet(&_timer, sizeof(TimerType), 0); MemSet(&_sound, sizeof(SoundType), 0); _keyExtraRepeat = 0; _keyExtraPressed = 0; _keyExtraDelay = (gVars->arrowKeys) ? computeMsecs(125) : computeMsecs(25); }
Boolean v4pDisplayEnd() { int i ; static int j=0; UInt32 t2=TimGetTicks(); tlaps-=laps[j % 4]; tlaps+=laps[j % 4]=t2-t1; j++; idebug(tlaps); // Bilan des collides for (i = 0 ; i < 16 ; i++) { if (!collides[i].q) continue ; collides[i].x /= collides[i].q ; collides[i].y /= collides[i].q ; } return success ; }
void fastPoll( void ) { RANDOM_STATE randomState; BYTE buffer[ RANDOM_BUFSIZE + 8 ]; WinHandle winHandle; Coord xCoord, yCoord; Boolean flag; uint64_t ticks; nsecs_t nsTime; initRandomData( randomState, buffer, RANDOM_BUFSIZE ); /* Get the event-available and low-level event-available flag, current pen status, and handle of the window with the input focus */ flag = EvtEventAvail(); addRandomValue( randomState, flag ); flag = EvtSysEventAvail( TRUE ); addRandomValue( randomState, flag ); EvtGetPen( &xCoord, &yCoord, &flag ); addRandomValue( randomState, xCoord ); addRandomValue( randomState, yCoord ); winHandle = EvtGetFocusWindow(); addRandomValue( randomState, winHandle ); /* Get the number of ticks of the (software) millisecond clock used by the scheduler, and the length of time in nanoseconds since the last reset */ ticks = TimGetTicks(); addRandomData( randomState, &ticks, sizeof( uint64_t ) ); nsTime = SysGetRunTime(); addRandomData( randomState, &nsTime, sizeof( nsecs_t ) ); /* Get the value of the real-time and runtime clocks in nanoseconds. One of these may just be a wrapper for SysGetRunTime(), in addition it's likely that they're hardware-specific, being CPU-level cycle counters of some kind */ nsTime = system_real_time(); addRandomData( randomState, &nsTime, sizeof( nsecs_t ) ); nsTime = system_time(); addRandomData( randomState, &nsTime, sizeof( nsecs_t ) ); /* Flush any remaining data through */ endRandomData( randomState, 5 ); }
/* Handler to decide if our minTicks waiting time has passed */ Boolean TimeoutEventHandler( void ) { Boolean handled; UInt32 now; handled = false; if ( minTicks == 0 || lastTick == 0 ) return handled; /* Sometimes while waiting for a nilEvent, we may receive one before the minTicks number of ticks has passed. Be sure to check */ now = TimGetTicks(); if ( lastTick <= ( now - minTicks ) ) { TimeoutCallbackHandler(); handled = true; lastTick = now; } return handled; }
static void NewGame (void) { int color, shape, i; DIAG (("NewGame\n")); game.seed = TimGetTicks (); RandomBoard (game.board); DamageBoard (); i = 0; for (color = RED; color <= BLUE; color = COLOR_NEXT(color)) for (shape = TARGET_TRIANGLE; shape <= TARGET_CIRCLE; shape = TARGET_NEXT(shape)) { game.targets[i++] = shape|color; } game.targets[i++] = TARGET_WHIRL|COLOR_ANY; DIAG (("Generated %d targets\n", i)); Shuffle (game.targets, i); game.ntarget = 0; DIAG (("NextTarget\n")); NextTarget (); }
bool PediaMainForm::handleEvent(EventType& event) { if (showArticle == displayMode_ && articleRenderer_.handleEventInForm(event)) return true; if (showArticle != displayMode_ && infoRenderer_.visible() && infoRenderer_.handleEventInForm(event)) return true; bool handled=false; if (ignoreEvents_) return false; switch (event.eType) { case keyDownEvent: handled=handleKeyPress(event); break; case ctlSelectEvent: handleControlSelect(event); break; case penUpEvent: if (penUpsToEat_ > 0) { --penUpsToEat_; handled = true; } break; case LookupManager::lookupFinishedEvent: handleLookupFinished(event); handled = true; break; case LookupManager::lookupStartedEvent: setControlsState(false); // No break is intentional. case LookupManager::lookupProgressEvent: update(redrawProgressIndicator); handled = true; break; case iPediaApplication::appRegisterEvent: Application::popupForm(registrationForm); handled = true; break; case iPediaApplication::appRegistrationFinished: if (showAbout == displayMode_) prepareAbout(); update(); handled = true; break; case iPediaApplication::appLangNotAvailable: // for whatever reason server told us that the language // we were using is not available. That shouldn't happen // because we only use langauges that server gives us, but // it might becaues e.g. we might disable a given language on the // server and the client might have outdated list of available // languages. In this case we switch to "en" (English) which // should always be available FrmAlert(langNotAvailableAlert); LookupManager* lookupManager = app().getLookupManager(true); if (lookupManager && !lookupManager->lookupInProgress()) lookupManager->switchDatabase("en"); handled = true; break; case iPediaApplication::appForceUpgrade: { UInt16 buttonId = FrmAlert(forceUpgradeAlert); if (0==buttonId) { // this is "Update" button so take them to a web page if ( errNone != WebBrowserCommand(false, 0, sysAppLaunchCmdGoToURL, updateCheckURL ,NULL) ) FrmAlert(noWebBrowserAlert); } handled = true; } break; case iPediaApplication::appRandomWord: randomArticle(); handled = true; break; case penDownEvent: lastPenDownTimestamp_=TimGetTicks(); break; default: handled = iPediaForm::handleEvent(event); } return handled; }
systick_t GetTimeTick() { return TimGetTicks(); }
static Boolean MainFormHandleEvent (EventPtr e) { Boolean handled = false; FormPtr frm; static UInt32 start_sec=0; static UInt32 start_tik; static UInt32 end_sec; static UInt32 end_tik; //static int run = 0; switch (e->eType) { case frmOpenEvent: frm = FrmGetActiveForm(); FrmDrawForm(frm); // resume interrupted count // note now stopWatchPrefs.tik_timestamp != stopWatchPrefs.timestamp // now this does work okay when switching away from app BUT // not when palm is turned off & on but stays in app // I think possibly GetTicks gets ticks from start of app // when palm off the ticks do not increment if (stopWatchPrefs.timestamp != 0) { stopWatchPrefs.tik_timestamp = TimGetSeconds(); start_tik = TimGetTicks(); RunCount(start_tik); } handled = true; break; case menuEvent: MenuEraseStatus(NULL); switch(e->data.menu.itemID) { // TODO add to TestTemp code //case itemBar: case itemRun: if (start_sec == 0) { stopWatchPrefs.tik_timestamp = stopWatchPrefs.timestamp = start_sec = TimGetSeconds(); start_tik = TimGetTicks(); } RunCount(start_tik); break; case itemHold: // break the run loop run = 0; break; case itemStop: // break the run loop run = 0; end_sec = TimGetSeconds(); end_tik = TimGetTicks(); break; case itemClear: // break the run loop run = 0; start_sec = 0; stopWatchPrefs.timestamp = 0; stopWatchPrefs.tik_timestamp = 0; end_tik = 0; drawCount(0); break; case itemPrefs: FrmPopupForm(PrefForm); break; case itemTest1: WinDrawLine(20,20,50,50); //void WinDrawChar (WChar theChar, Coord x, Coord y) ///void WinDrawChars (const Char *chars, Int16 len, Coord x, Coord y) //void WinPaintChar (WChar theChar, Coord x, Coord y) //void WinPaintChars (const Char *chars, Int16 len, Coord x, Coord y) ///opt/palmdev/sdk-5/include/Core/System/Window.h // Font.h WinDrawChar('X',20,50); FntSetFont(symbol11Font); WinDrawChar('Y',40,50); FntSetFont(largeFont); WinDrawChar('Z',60,50); WinDrawChars("large Font",10,80,50); FntSetFont(largeBoldFont); WinDrawChars("large Bold",10,110,50); { char buf[100]; int l=0; UInt32 t = SysTicksPerSecond(); l+=StrPrintF(buf+l, "SysTicksPerSec is %lu", t); FntSetFont(largeBoldFont); WinPaintChars(buf,l,1,20); } if (0){ digiFontType ft; ft.h = 20; ft.w = 16; ft.th = 4; ft.tw = 7; drawHSeg(11,9,ft,WinDrawLineF); drawVSeg(10,10,ft,WinDrawLineF); drawHSeg(11,36,ft,WinDrawLineF); drawVSeg(39,10,ft,WinDrawLineF); } if (0){ digiFontType ft; ft.h = 20; ft.w = 12; ft.th = 4; ft.tw = 7; drawHSeg(11,59,ft,WinDrawLineF); drawVSeg(10,60,ft,WinDrawLineF); drawVSeg(38,60,ft,WinDrawLineF); drawHSeg(11,79,ft,WinDrawLineF); drawVSeg(10,80,ft,WinDrawLineF); drawVSeg(38,80,ft,WinDrawLineF); drawHSeg(11,99,ft,WinDrawLineF); } bigDigit(5,20,'2',WinDrawLineF); bigDigit(40,20,'5',WinDrawLineF); bigDigit(5,70,'7',WinDrawLineF); break; case itemTest2: bigDigit(5,20,'8',WinEraseLineF); bigDigit(40,20,'8',WinEraseLineF); bigDigit(5,70,'8',WinEraseLineF); WinDrawChars("Hello",5,20,80); WinPaintChars("Paint",5,20,110); //Err err; err = TimInit(); { char buf[100]; int l=0; UInt32 s,t; UInt32 hour,min,sec; UInt32 day; // seconds since 1/1/1904 //void TimSetSeconds(UInt32 seconds) // ticks since power on t = TimGetTicks(); s = TimGetSeconds(); l+=StrPrintF(buf+l, "Secs %lu", s); FntSetFont(largeBoldFont); WinPaintChars(buf,l,1,20); l=0; l+=StrPrintF(buf+l, "Ticks %lu", t); FntSetFont(largeBoldFont); WinPaintChars(buf,l,1,40); day = s / (UInt32)(24 * 60 * 60); s = s - day * (24 * 60 * 60); hour = s / (60 * 60); s = s - hour * (60 * 60); min = s / 60; sec = s - min * 60; l=0; l+=StrPrintF(buf+l, "%07d:%02d:%02d:%02d", day, hour,min,sec); FntSetFont(largeBoldFont); WinPaintChars(buf,l,1,60); } break; // call this periodically to hold off auto off // Err EvtResetAutoOffTimer(void) // SystemMgr.h //Err SysTimerCreate(UInt32 *timerIDP, UInt32 *tagP, // SysTimerProcPtr timerProc, UInt32 periodicDelay, UInt32 param) //Err SysTimerDelete(UInt32 timerID) //Err SysTimerWrite(UInt32 timerID, UInt32 value) //Err SysTimerRead(UInt32 timerID, UInt32 *valueP) // SysTaskDelay((100 * SysTicksPerSecond())/1000); case itemOptHelp: FrmHelp(hlpHelp); break; //case itemOptDbgDump: //debugDump(e->eType); //break; case itemOptCopy: FrmHelp(hlpCopy); break; case itemOptAbout: FrmCustomAlert(alertInfo, "stopWatch v" VERSION " not even Alpha. " "Built " __DATE__ ", " __TIME__ ". " "James Coleman http://www.dspsrv.com/~jamesc " "copyleft me.", "", ""); break; } //DEBUGBOX("menuEvent",""); handled = true; break; case ctlSelectEvent: switch(e->data.ctlSelect.controlID) { case btnRun: if (start_sec == 0) { stopWatchPrefs.tik_timestamp = stopWatchPrefs.timestamp = start_sec = TimGetSeconds(); start_tik = TimGetTicks(); } RunCount(start_tik); break; case btnHold: // break the run loop run = 0; break; case btnStop: // break the run loop run = 0; end_sec = TimGetSeconds(); end_tik = TimGetTicks(); break; case btnClear: // break the run loop run = 0; stopWatchPrefs.timestamp = start_sec = 0; stopWatchPrefs.tik_timestamp = 0; end_tik = 0; drawCount(0); break; } break; //case ctlRepeatEvent: //break; case penDownEvent: case penMoveEvent: doPenAction( e->eType, e->screenX, e->screenY, 0, 0); //FrmCustomAlert(alertInfo, "pen down", "ARGSTR1", "ARGSTR2"); break; case penUpEvent: doPenAction( penUpEvent, e->data.penUp.start.x, e->data.penUp.start.y, e->data.penUp.end.x, e->data.penUp.end.y); break; case keyDownEvent: { char buf[1000]; int l=0; l+=StrPrintF(buf+l, "Char: %c %02x\n",e->data.keyDown.chr,e->data.keyDown.chr); buf[l]=0; DEBUGBOX("keyDownEvent",buf); } switch(e->data.keyDown.chr) { case pageUpChr: case pageDownChr: handled = true; break; case prevFieldChr: case nextFieldChr: case '\n': handled = true; break; default: if (!TxtCharIsCntrl(e->data.keyDown.chr)) { handled = true; /* Swallow event */ } break; } break; default: break; } return handled; }
static unsigned int osip_fallback_random_number () #endif { if (!random_seed_set) { unsigned int ticks; #ifdef __PALMOS__ # if __PALMOS__ < 0x06000000 SysRandom ((Int32) TimGetTicks ()); # else struct timeval tv; gettimeofday (&tv, NULL); srand (tv.tv_usec); ticks = tv.tv_sec + tv.tv_usec; # endif #elif defined(WIN32) LARGE_INTEGER lCount; QueryPerformanceCounter (&lCount); ticks = lCount.LowPart + lCount.HighPart; #elif defined(_WIN32_WCE) ticks = GetTickCount (); #elif defined(__PSOS__) #elif defined(__VXWORKS_OS__) struct timespec tp; clock_gettime (CLOCK_REALTIME, &tp); ticks = tp.tv_sec + tp.tv_nsec; #else struct timeval tv; int fd; gettimeofday (&tv, NULL); ticks = tv.tv_sec + tv.tv_usec; fd = open ("/dev/urandom", O_RDONLY); if (fd > 0) { unsigned int r; int i; for (i = 0; i < 512; i++) { read (fd, &r, sizeof (r)); ticks += r; } close (fd); } #endif #ifdef HAVE_LRAND48 srand48 (ticks); #else srand (ticks); #endif random_seed_set = 1; } #ifdef HAVE_LRAND48 return lrand48 (); #else return rand (); #endif }
/* Toggle Autoscroll */ void DoAutoscrollToggle ( AutoscrollType toggle ) { FormType* mainForm; UInt16 prevCoordSys; if ( toggle == AUTOSCROLL_OFF && ! Prefs()->autoscrollEnabled ) return; mainForm = FrmGetFormPtr( GetMainFormId() ); prevCoordSys = PalmSetCoordinateSystem( STANDARD ); if ( toggle == AUTOSCROLL_TOGGLE ) Prefs()->autoscrollEnabled = ! Prefs()->autoscrollEnabled; else if ( toggle == AUTOSCROLL_ON ) Prefs()->autoscrollEnabled = true; else Prefs()->autoscrollEnabled = false; if ( Prefs()->autoscrollEnabled ) Prefs()->autoscrollLastScrollTime = TimGetTicks(); if ( Prefs()->autoscrollEnabled && Prefs()->autoscrollDir == AUTOSCROLL_DOWN && Prefs()->autoscrollMode == AUTOSCROLL_PIXELS ) { LineCacheActivate(); } else { LineCacheRefreshCurrentScreenData(); LineCacheDeactivate(); } if ( Prefs()->toolbar != TOOLBAR_NONE && IsMainFormWinActive() ) { if ( Prefs()->autoscrollEnabled ) { if ( Prefs()->toolbar == TOOLBAR_SILK ) { /* FIXME: figure this out */ } else { FrmHideObject( mainForm, FrmGetObjectIndex( mainForm, bmpAutoscrollStart ) ); FrmShowObject( mainForm, FrmGetObjectIndex( mainForm, bmpAutoscrollStop ) ); } } else { if ( Prefs()->toolbar == TOOLBAR_SILK ) { /* FIXME: figure this out */ } else { FrmHideObject( mainForm, FrmGetObjectIndex( mainForm, bmpAutoscrollStop ) ); FrmShowObject( mainForm, FrmGetObjectIndex( mainForm, bmpAutoscrollStart ) ); } } } PalmSetCoordinateSystem( prevCoordSys ); }
Boolean CCXEGLView::EventHandler(TApplication * pApp, EventType * pEvent) { Boolean bHandled = FALSE; switch(pEvent->eType) { case EVENT_WinInit: CfgRegisterScreenSwitchNotify(GetWindowHwndId(), 0); bHandled = TRUE; break; case EVENT_WinPaint: if (CfgGetScreenStatus()) { // draw CCDirector::sharedDirector()->mainLoop(); } bHandled = TRUE; break; case EVENT_PenDown: bHandled = OnPenDown(pEvent, 0); break; case EVENT_PenMove: bHandled = OnPenMove(pEvent); break; case EVENT_PenUp: bHandled = OnPenUp(pEvent, 0); break; case EVENT_MultiTouchDown: bHandled = OnPenDown(pEvent, pEvent->lParam3); break; case EVENT_MultiTouchUp: bHandled = OnPenUp(pEvent, pEvent->lParam3); break; case EVENT_KeyCommand: { if (pEvent->sParam1 == SYS_KEY_SOFTKEY_RIGHT_UP || pEvent->sParam1 == SYS_KEY_SOFTKEY_RIGHT_LONG) { bHandled = CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeBackClicked); } else if (pEvent->sParam1 == SYS_KEY_SOFTKEY_LEFT_UP || pEvent->sParam1 == SYS_KEY_SOFTKEY_LEFT_LONG) { bHandled = CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeMenuClicked); } } break; case MESSAGE_SENSORS_DATA: { TG3SensorsDataType data; if (Sys_GetMessageBody((MESSAGE_t *)pEvent, &data, sizeof(TG3SensorsDataType)) == sizeof(TG3SensorsDataType) && TG3_SENSOR_TYPE_ACCELEROMETER == data.sensorMask) { // convert the data to iphone format UIAcceleration AccValue; AccValue.x = -(data.acceleration.x / TG3_GRAVITY_EARTH); AccValue.y = -(data.acceleration.y / TG3_GRAVITY_EARTH); AccValue.z = -(data.acceleration.z / TG3_GRAVITY_EARTH); AccValue.timestamp = (double) TimGetTicks() / 100; // call delegates' didAccelerate function UIAccelerometer::sharedAccelerometer()->didAccelerate(&AccValue); bHandled = TRUE; } } break; case EVENT_WinClose: CfgUnRegisterScreenSwitchNotify(GetWindowHwndId(), 0); // Stop the application since the main form has been closed pApp->SendStopEvent(); break; case EVENT_ScreenSwitchNotify: { bool bInBack = CCXApplication::sharedApplication()->isInBackground(); // if the app have be in background,don't handle this message CCX_BREAK_IF(bInBack); if (! pEvent->sParam1) // turn off screen { // CCDirector::sharedDirector()->pause(); CCXApplication::sharedApplication()->applicationDidEnterBackground(); CCXApplication::sharedApplication()->StopMainLoop(); } else { // CCDirector::sharedDirector()->resume(); CCXApplication::sharedApplication()->applicationWillEnterForeground(); CCXApplication::sharedApplication()->StartMainLoop(); } break; } } // { // char szType[32]; // sprintf(szType, "%d", pEvent->eType); // const char * pszType = szType; // switch (pEvent->eType) // { // case EVENT_ScreenSwitchNotify: // pszType = "EVENT_ScreenSwitchNotify"; // break; // // case EVENT_GlesUpdateNotify: // pszType = "EVENT_GlesUpdateNotify"; // break; // // case EVENT_WinPaint: // pszType = "EVENT_GlesUpdateNotify"; // break; // } // if (pszType) // { // char szMsg[256]; // sprintf(szMsg, "%d: %s: %d \r\n", TimGetTicks(), pszType, pEvent->sParam1); // #if defined (_TRANZDA_VM_) // #define LOG_FILE_NAME "d:/Work7/NEWPLUS/TDA_DATA/UserData/mesagelog.txt" // #else // #define LOG_FILE_NAME "/NEWPLUS/TDA_DATA/UserData/mesagelog.txt" // #endif // FILE * pf = fopen(LOG_FILE_NAME, "a+"); // fwrite(szMsg, 1, strlen(szMsg), pf); // fclose(pf); // } // } if (! bHandled) { return TWindow::EventHandler(pApp, pEvent); } return bHandled; }
/* Reset the timer */ void TimeoutReset( void ) { lastTick = TimGetTicks(); }
uint32 OSystem_PalmBase::getMillis() { return TimGetTicks() * 1000 / SysTicksPerSecond(); }