現在以下的程序是用LUA進行編輯的,在以24小時的定時功能上出現了,由0:00-8:00的中斷(定時功能不起作用)。各位大俠們請為我指導!謝謝!
function exe_timer()
--print("timer version=2");
local fields,action,timer_str;
local time = rtctime.epoch2cal(rtctime.get())
local nowtime=string.format("%04d-%02d-%02d %02d:%02d",time["year"], time["mon"], time["day"],time["hour"] + time_zone,time["min"]);
local repeatTime=0;
local end_time=0;
for i=1,#timer_array do
fields = string_split(timer_array[i],",")
if(#fields>=5) then
local timer_time=rtctime.epoch2cal(tonumber(fields[5])/1000);
if(#fields>=6) then
repeatTime=1;
end_time=tonumber(fields[6])/1000;
end
timer_str=string.format("%04d-%02d-%02d",timer_time["year"], timer_time["mon"], timer_time["day"]).." "..fields[3];
action=fields[4];
if(repeatTime==1 and end_time>0) then
nowtime=string.format("%02d:%02d",time["hour"] + time_zone,time["min"]);
local ck_sec, ck_usec, ck_rate = rtctime.get()
print("ck_end_time ="..ck_sec.. " end time="..end_time.." timer_str="..fields[3].." nowtime="..nowtime);
if(fields[3]==nowtime and ck_sec<=end_time) then
turn_by_index(tonumber(fields[2]),action);
end
else
if(timer_str==nowtime) then
turn_by_index(tonumber(fields[2]),action);
end
end
end
end
end
function check_timer(ids)
local find=0;
local fields;
local c_fields=string_split(ids,",");
local del_list={}
if(ids=="") then
while #timer_array ~= 0 do rawset(timer_array, #timer_array, nil) end
print("delete all timer,timer count="..#timer_array)
else
for i=1,#timer_array do
fields = string_split(timer_array[i],",")
find=0
for p =1,#c_fields do
if(c_fields[p]==fields[1]) then
find=1
break;
end
end
if(find==0) then
del_list[#del_list+1]=fields[1];
end
end
for i=1,#del_list do
print("del timer,index="..del_list[i]);
for j=1,#timer_array do
fields = string_split(timer_array[j],",")
if(del_list[i]==fields[1]) then
table.remove(timer_array,j);
break
end
end
end
print("timer count="..#timer_array);
end
timer_change=1
end
function put_timer(timer_string)
local ta;
local fields;
local new_timer_fields=string_split(timer_string,",")
local find=0;
for i=1,#timer_array do
ta=timer_array[i];
fields = string_split(ta,",")
if(ta==timer_string) then
find=1;
break;
end
if(fields[1]==new_timer_fields[1]) then
timer_change=1;
table.remove(timer_array,i);
break;
end
end
if(find==0) then
timer_array[#timer_array+1]=timer_string
timer_change=1
end
end
function save_timer()
local srcFile = file.open("timers.txt", "w")
for i=1,#timer_array do
srcFile:writeline(timer_array[i])
end
srcFile:close();
srcFile=nil;
end
function read_timer()
local ta
local inpFile = file.open("timers.txt", "r")
if(inpFile==nil) then
return;
end
while true do
ta = inpFile:readline()
if(ta ==nil) then
break;
end
print("timer:"..ta)
ta=string.gsub(ta, "\n", "")
timer_array[#timer_array+1]=ta
break;
end
inpFile:close()
inpFile=nil;
end
|