缩短Lua码灌溉定时器

缩短Lua码灌溉定时器,lua,Lua,您好,我是新的编码,并着手做一些代码的灌溉控制器上运行的控制由网络产品使用Lua 我的规格是让它按如下方式运行 为每个阀门运行时间设置一个寄存器。然后触发序列,让它们一个接一个地浇水 暂停序列(计时器)并关闭阀门的能力 暂停时,重新启动计时器,取消暂停时打开阀门 能够随时手动启动阀门 在同一时间内同时发生多个序列 剧本 我已经做了下面的脚本,但它是大超过8KB允许。我确信有办法使它变小,但在现阶段我无法做到 如果有人愿意试一试。我愿意付钱把这个代码修好。 干杯 乔恩 ——通过Web X

您好,我是新的编码,并着手做一些代码的灌溉控制器上运行的控制由网络产品使用Lua

我的规格是让它按如下方式运行

    • 为每个阀门运行时间设置一个寄存器。然后触发序列,让它们一个接一个地浇水

    • 暂停序列(计时器)并关闭阀门的能力 暂停时,重新启动计时器,取消暂停时打开阀门

    • 能够随时手动启动阀门

    • 在同一时间内同时发生多个序列 剧本

我已经做了下面的脚本,但它是大超过8KB允许。我确信有办法使它变小,但在现阶段我无法做到

如果有人愿意试一试。我愿意付钱把这个代码修好。 干杯 乔恩


——通过Web X600控制4个阀门和施肥的顺序计时器
--每个阀继电器的标记变量
flagV1=0——阀1
flagV2=0
flagV3=0
f=0
--阀门顺序的标志变量
g=0——序列激活
h=0——阀门1完成
i=0——阀门2完成
j=0——阀门3完成
k=0——阀门5已完成
--fert继电器的标志验证
f_搅拌=0
f_=0
--fert Sequence的标志性病毒
旗杆耳轴=0
flagAgitateFin=0
FlagFin=0
尽管如此
打印(“flagV1”,flagV1)
打印(“flagV2”,flagV2)
打印(“flagV3”,flagV3)
打印(“g触发器”,g)
如果reg.rArea1active==1且
reg.RTRIGGEREA1==1然后
g=1
否则,如果reg.rArea1active==0,则--重置序列
g=1
h=1
i=1
j=1
k=1
结束
结束
--起动阀1
如果g==1且reg.rrontimev1>0且
h==0然后——仅当该阀尚未运行时启动
io.valve1=1
否则,如果reg.RRUTIMEV1 0和
io.valve1==1,则
flagV1=1——阀门已打开
如果reg.t3second==0,则
reg.RTIMOTOFV1=reg.RTIMOTOFV1-.5
打印(“V1关闭时间”,reg.RTIFV1)
结束
--生蕨
如果reg.rFertV1==1且

reg.rtimetoffv1我投票将这个问题作为主题外的问题结束,因为它是关于。只需使用-s选项编译脚本,它将非常小。通过删除所有缩进,您可以将脚本大小从9953字节减少到6808字节。Lua不是Python:-)使用
unexpand
并在保持缩进的同时将其减少到7980字节。感谢您的回答,这是我第一次在这里查看代码回顾。干杯
-- Sequence Timer for the control of 4 valves and fertigation on Control By Web X600


-- Flag Variabls for each Valve relay
flagV1 = 0  --Valve 1
flagV2 = 0
flagV3 = 0
f = 0

-- Flag Variables for Valve sequence

g = 0   -- sequence active 
h = 0   -- valve 1 Finished
i = 0   -- valve 2 Finished
j = 0   -- valve 3 Finished
k = 0   -- valve 5 Finished


-- Flag Veriables for fert relays
f_Agitate = 0
f_Inject = 0

-- flag Virables for fert seqance
   flagFertRunning = 0
    flagAgitateFin = 0
     flagInjectFin = 0
while true do

    print ("flagV1 V1 ",flagV1)
    print ("flagV2 V2 ",flagV2)
    print ("flagV3 V3 ",flagV3)
    print ("g triggrer ",g)

  if reg.rArea1active == 1 and
    reg.rTriggerArea1 == 1 then
      g = 1
     else if reg.rArea1active == 0 then   -- reset the seqence
      g = 1
      h = 1
      i = 1
      j = 1
      k = 1
     end
   end

  -- start valve 1
  if g == 1 and reg.rRunTimeV1 > 0 and 
     h == 0 then -- only start if this valve hasn't already run
     io.valve1 = 1
     else if reg.rRunTimeV1 <= 0 then
     h = 1
     end
  end

-- ******control for valve 1

    -- Moves the run time into the timer if relay tuned on and timer O
            if io.valve1 == 1 and
                reg.rTimeToOffV1 == 0 and
                               flagV1 == 0 then
                               flagV1 = 1   -- Valve has been opened 
                  reg.rTimeToOffV1 = reg.rRunTimeV1
                print ("V1 if-1 ",io.valve1)
            end

    -- count down if relay on
            if reg.rTimeToOffV1 > 0 and
                io.valve1 == 1 then
                         flagV1 = 1 -- Valve has been opened 
                if reg.t3second == 0 then
                     reg.rTimeToOffV1 = reg.rTimeToOffV1-.5
              print ("V1 time to off " ,reg.rTimeToOffV1) 
              end

  -- Start fert
                  if reg.rFertV1 == 1 and
                   reg.rTimeToOffV1 <= reg.rFertStartTime then
                     reg.rRunFert = 1
                  end

            end

    -- turns relay off if timer 0
         if  reg.rTimeToOffV1 <= 0 and
                                flagV1 == 1 then
                       io.valve1 = 0
                     reg.rRunFert = 0
                reg.rTimeToOffV1 = 0
                    if io.valve1 == 0 then flagV1 = 0 -- timer finished valve closed                
                    end                
                    if g == 1 then h = 1   --valve 1 finished lock                
                    print ("V1 if-3 ",io.valve1)
                   end
          end

  -- start valve 2
   if g == 1 and reg.rRunTimeInject > 0 and 
      h == 1 and
      i == 0 then -- only start if this valve hasn't already run
      io.valve2 = 1
      else if reg.rRunTimeInject <= 0 then
      i = 1
      end
   end



-- *****control for Valve 2

    -- Moves the run time into the timer if relay tuned on and timer O
      if io.valve2 == 1 and
         reg.rTimeToOffV2 == 0 and
                            flagV2 == 0 then
                              flagV2 = 1    -- Valve has been opened 
                  reg.rTimeToOffV2 = reg.rRunTimeInject
                    print ("V2 if-1 ",io.valve2)
          end

     -- count down if relay on
             if  reg.rTimeToOffV2 > 0 and
                     io.valve2 == 1 and
                       reg.t3second == 0 then
                                   flagV2 = 1   -- Valve has been opened 
                   reg.rTimeToOffV2 = reg.rTimeToOffV2-.5

         print ("V2 time to off " ,reg.rTimeToOffV2)
     end

    -- turns relay off if timer 0
         if  reg.rTimeToOffV2 <= 0 and
                                flagV2 == 1 then
                               io.valve2 = 0
                           reg.rTimeToOffV2 = 0
                                  if io.valve2 == 0 then flagV2 = 0 -- timer finished valve closed
                                  end
                                  if g == 1 then i = 1  -- valve 2 finished lock
                                  end
                    print ("V2 if-3 ",io.valve2)
         end


-- start valve 3
   if g == 1 and reg.rRunTimeV3 > 0 and
      h == 1 and
      i == 1 and
      j == 0 then -- only start if this valve hasn't already run
    io.valve3 = 1
     else if reg.rRunTimeV3 <= 0 then
     h = 1
     end
    end

-- ******control for Valve 3

    -- Moves the run time into the timer if relay tuned on and timer O
      if io.valve3 == 1 and
         reg.rTimeToOffV3 == 0 and
                            flagV3 == 0 then
                            flagV3 = 1  -- Valve has been opened 
                  reg.rTimeToOffV3 = reg.rRunTimeV3
    print ("V3 if-1 ",io.valve3)
          end

     -- count down if relay on
             if  reg.rTimeToOffV3 > 0 and
                     io.valve3 == 1 and
                       reg.t3second == 0 then
                                   flagV3 = 1   -- Valve has been opened 
                   reg.rTimeToOffV3 = reg.rTimeToOffV3-.5
         print ("V3 time to off " ,reg.rTimeToOffV3)
     end

    -- turns relay off if timer 0
         if  reg.rTimeToOffV3 <= 0 and
                                flagV3 == 1 then
                               io.valve3 = 0
                           reg.rTimeToOffV3 = 0
                                  if io.valve3 == 0 then flagV3 = 0 -- timer finished valve closed
                                  end
                                  if g == 1 then j = 1  -- valve 3 finished lock
                                  end
                 print ("V3 if-3 ",io.valve3)
         end

  -- reset the seqence
   if g == 1 and
      h == 1 and 
      i == 1 and
      j == 1 then
            g = 0
            h = 0
            i = 0
            j = 0
            k = 0
   end

   -- ******************Fert control ********************************************


    if reg.rFertActive == 1 and
             rRunFert  == 1 then
              flagFertRunning = 1
     else if reg.rFertActive == 0 then   -- reset the seqence
             flagFertRunning = 1
              flagAgitateFin = 1
               flagInjectFin = 1
     end
   end

  -- Start Agitate
  if flagFertRunning == 1 and reg.rRunTimeAgitate > 0 and 
     flagAgitateFin == 0 then -- only start if this valve hasn't already run
     reg.fertAgitate = 1
     else if reg.rRunTimeAgitate <= 0 then
     flagAgitateFin = 1
     end
  end

-- ******control for Agitate

    -- Moves the run time into the timer if relay tuned on and timer O
            if reg.fertAgitate == 1 and
                reg.rTimeToOffAgitate == 0 and
                               f_Agitate == 0 then
                               f_Agitate = 1    -- Valve has been opened 
                  reg.rTimeToOffAgitate = reg.rRunTimeAgitate
                print ("V1 if-1 ",reg.fertAgitate)
            end

    -- count down if relay on
            if reg.rTimeToOffAgitate > 0 and
                reg.fertAgitate == 1 then
                         f_Agitate = 1  -- Valve has been opened 
                if reg.t3second == 0 then
                     reg.rTimeToOffAgitate = reg.rTimeToOffAgitate-.5
                end
              print ("V1 time to off " ,reg.rTimeToOffAgitate) 
              end



    -- turns relay off if timer 0
         if  reg.rTimeToOffAgitate <= 0 and
                                f_Agitate == 1 then
                       reg.fertAgitate = 0
                     reg.rRunFert = 0
                reg.rTimeToOffAgitate = 0
                    if reg.fertAgitate == 0 then f_Agitate = 0 -- timer finished valve closed               
                    end                
                    if flagFertRunning == 1 then flagAgitateFin = 1   --valve 1 finished lock                
                    print ("V1 if-3 ",reg.fertAgitate)
                   end
          end

  -- ***************start Inject**********************
   if flagFertRunning == 1 and reg.rRunTimeInject > 0 and 
      flagAgitateFin == 1 and
      flagInjectFin == 0 then -- only start if this valve hasn't already run
      io.fertPump = 1
      else if reg.rRunTimeInject <= 0 then
      flagInjectFin = 1
      end
   end


-- *****control for inject *****************

    -- Moves the run time into the timer if relay tuned on and timer O
      if io.fertPump == 1 and
         reg.rTimeToOffInject == 0 and
                            f_Inject == 0 then
                            f_Inject = 1    -- Valve has been opened 
                  reg.rTimeToOffInject = reg.rRunTimeInject
                    print ("V2 if-1 ",io.fertPump)
          end

     -- count down if relay on
             if  reg.rTimeToOffInject > 0 and
                     io.fertPump == 1 and
                    reg.t3second == 0 then
                                   f_Inject = 1 -- Valve has been opened 
                       reg.rTimeToOffInject = reg.rTimeToOffInject-.5

         print ("V2 time to off " ,reg.rTimeToOffInject)
     end

    -- turns relay off if timer 0
         if  reg.rTimeToOffInject <= 0 and
                         f_Inject == 1 then
                               io.fertPump = 0
                           reg.rTimeToOffInject = 0
                                  if io.fertPump == 0 then f_Inject = 0 -- timer finishef_Inject valve closed
                                  end
                                  if flagFertRunning == 1 then flagInjectFin = 1  -- valve 2 finished lock
                                  end
                    print ("V2 if-3 ",io.fertPump)
         end




  -- reset  fert seqence
   if flagFertRunning == 1 and
      flagAgitateFin == 1 and 
      flagInjectFin == 1 then
            flagFertRunning = 0
            flagAgitateFin = 0
            flagInjectFin = 0
   end

 -- timer for count down
  print(reg.t3second)
          if reg.t3second == 0 then
              reg.t3second = 3
         end
  sleep(1000)
 end