The code below works nice, but if I include it in my main source it doesn't wont to work.
These are the errors :
It looks like the timer isn't started but still made, until trying to remove it (as it doesn't run) ???[11:29:45] Executable started.
[11:29:45] [WARNING] UB Connect Check.pb (Line: 1)
[11:29:45] [WARNING] GLib-GIO (DEBUG): _g_io_module_get_default: Found default implementation gvfs (GDaemonVfs) for âgio-vfsâ
[11:30:07] [WARNING] UB Timers.pbi (Line: 53)
[11:30:07] [WARNING] GLib (CRITICAL): Source ID 792 was not found when attempting to remove it
I wont to have a time function which doesn't get delay by other system things, like moving the window around or so ...
In windows this is done with timeSetEvent_(..., ..., @Timer_Callback(), TimerID, #TIME_PERIODIC)
In Ubuntu (later on the Raspberry PI) I use that g_timeout_add_full_(...), is That the wright one or what else ?
Thanks
Code: Select all
;************************************************************************************************************************
;{***********************************************************************************************************************
; http://library.gnome.org/devel/glib/stable/glib-The-Main-Event-Loop.html#g-timeout-add
;https://www.gtk-server.org/gtk1/glib/glib-the-main-event-loop.html#G-TIMEOUT-ADD-FULL
;https://www.purebasic.fr/english/viewtopic.php?p=235856&hilit=timer#p235856
; Registers a function To be called periodically. The function will be called repeatedly after interval milliseconds
;Until it returns FALSE at which point the timeout is destroyed And will Not be called again.
;
; interval : The time between calls To the function, in milliseconds (1/1000ths of a second.)
; function :The function To call periodically.
; Data : The Data To pass To the function.
; Returns : A unique id For the event source.
#G_PRIORITY_HIGH = -100
#G_PRIORITY_DEFAULT = 0
#G_PRIORITY_HIGH_IDLE = 100
#G_PRIORITY_DEFAULT_IDLE = 200
#G_PRIORITY_LOW = 300
;Use this for high priority event sources. It is not used within GLib or GTK+.
;G_PRIORITY_DEFAULT
;Use this for default priority event sources. In GLib this priority is used when adding timeout functions with g_timeout_add(). In GDK this priority is used for events from the X Windows server.
;G_PRIORITY_HIGH_IDLE
;Use this for high priority idle functions. GTK+ uses G_PRIORITY_HIGH_IDLE + 10 for resizing operations, and G_PRIORITY_HIGH_IDLE + 20 for redrawing operations. (This is done to ensure that any pending resizes are processed before any pending redraws, so that widgets are not redrawn twice unnecessarily.)
;G_PRIORITY_DEFAULT_IDLE
;Use this for default priority idle functions. In GLib this priority is used when adding idle functions with g_idle_add().
;G_PRIORITY_LOW
;************************************************************************************************************************
Structure TIMER_SETUP
res.i ;MINIMUM RESOLUTIE VAN DE TIMER (wPeriodMin in TIMECAPS)
tik.i ;RESOLUTIE IN MILLISECONDS VOOR DE TIMER
index.i ;TIMER INDEX
priority.i ;DOOR TE GEVEN WAARDE AAN TIMER
adr.i ;TIMER PROC ADRES
info_adr.i ;TIMER PROC ADRES
running.a ;TIMER GESTART OF NIET
EndStructure
Global TM.TIMER_SETUP
;}************************************************************************************************************************
;************************************************************************************************************************
Procedure Timer_Setup(*p.TIMER_SETUP,res.i, priority.i, adr.i, info_adr.i=0)
With *p
\res=res
\priority=priority
\adr=adr
\info_adr=info_adr
\index=0
EndWith
EndProcedure
Procedure.i Timer_Remove(*p.TIMER_SETUP)
If *p\index
If g_source_remove_( *p\index)
*p\index=0
ProcedureReturn #False
EndIf
EndIf
EndProcedure
Procedure.i Full_Timer_Start(*p.TIMER_SETUP) ;timer met priority setting
If *p\index
Timer_Remove(*p)
Else
*p\index=g_timeout_add_full_( *p\priority, *p\res, *p\adr, *p\info_adr, #Null)
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
Procedure.i Timer_Start(*p.TIMER_SETUP) ;timer zonder priority setting, kan door events vertraagd worden
If *p\index
Timer_Remove(*p)
Else
*p\index=g_timeout_add_(*p\res, *p\adr, #Null)
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
;************************************************************************************************************************
CompilerIf #PB_Compiler_IsMainFile
Procedure MyTimeOutFunction(*pdata)
Debug "hello"
If stoptimer = #False
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
If OpenWindow(0, 0, 0, 300, 50, "TimeOut example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(1, 10, 10, 280, 30, "Stop timer")
Timer_Setup(@TM, 300,#G_PRIORITY_HIGH, @MyTimeOutFunction())
Full_Timer_Start(@TM)
;Timer_Start(@TM)
Repeat
If EventGadget() = 1
Timer_Remove(@TM)
Debug TM\index
DisableGadget(1, 1)
EndIf
Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
CompilerEndIf
;************************************************************************************************************************