Was playing around with timers and came up with a function call that incorporates all three.
made a series of buttons to test
pass the amount of time and the mode, does some minor error checking and resets the mode.
sleep(.5,0) would get you a 1/2 second delay converts it to a 500 millisecond sleep
not really that functional but it shows how to pass variables and do some calculations and toggle button actions
local inst = mc.mcGetInstance()
local butstate = 0;
butstate = scr.GetProperty('togTimer(0)', 'Button State', 0);
if (butstate == '1') then
sleep(1,0);
end
function sleep(howlong, mode)
local millitime = howlong;
local microtime = howlong * 1000;
if (mode == 0 and howlong < 1) then
mode = 1
millitime = howlong * 1000;
elseif (mode == 2 and howlong < 1000) then
mode = 1
microtime = howlong;
end
if (mode == 0) then
wx.wxSleep(howlong);
-- mc.mcCntlSetLastError(inst, 'seconds = ' .. tostring(howlong));
scr.SetProperty('togTimer(0)', 'Button State', '0');
elseif (mode == 1) then
-- mc.mcCntlSetLastError(inst, 'milliseconds = ' .. tostring(millitime));
wx.wxMilliSleep(millitime);
scr.SetProperty('togTimer(1)', 'Button State', '0');
scr.SetProperty('togTimer(3)', 'Button State', '0');
scr.SetProperty('togTimer(4)', 'Button State', '0');
elseif (mode == 2) then
-- mc.mcCntlSetLastError(inst, 'microseconds = ' .. tostring(microtime));
wx.wxMicroSleep(microtime);
scr.SetProperty('togTimer(2)', 'Button State', '0');
else
mc.mcCntlSetLastError(inst, 'Ya screwed up the delay time');
end
end