Translations:Полезные программы/115/ru

Материал из WebHMI Wiki
Версия от 14:23, 6 июня 2018; FuzzyBot (обсуждение | вклад) (Импортирована новая версия из внешнего источника)

(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

function TimerOnOff(bool_input, onDelay, offDelay, tmrAlias) -- bool seconds seconds string

   local outAlias = tmrAlias.."_out"
   local curTmrState = (GetReg(outAlias) == 1) ; DEBUG("curTmr  State "..tostring(curTmrState))
                                                 DEBUG("bool_input = "..tostring(bool_input))
                                               
   if (bool_input == curTmrState) then 
       WriteReg(tmrAlias, now) ;                 DEBUG("timer input match state ") 
       return curTmrState  -- as bool 
   elseif bool_input then 
                                                   DEBUG("countdown for onDelay = "..(onDelay - (now - GetReg(tmrAlias))))
        if now - GetReg(tmrAlias) > onDelay then                                              
               WriteReg(outAlias, 1)
                                                   DEBUG("detected ON state after delay ")
               return true 
         end 
   else 
                                                   DEBUG("countdown for offDelay = "..(offDelay - (now - GetReg(tmrAlias))))
       if (now - GetReg(tmrAlias) > offDelay) then                                              
               WriteReg(outAlias, 0)
                                                   DEBUG("detected OFF state after delay ")
               return false  
       end     
    end  -- 
   return  curTmrState  -- output rerurned as bool for simple usage in IFs