--[[
{***************************************************************************}
{ S4_logic01                                                11/10/2012      }
{                                                                           }
{	Eelectron S.p.A.                                                        }
{   Via Magenta 77/22                                                       }
{   I-20017 Rho(MI)                                                         }
{   Web: www.eelectron.com                                                  }
{                                                                           }
{ The source code is given as is, WITHOUT WARRANTY OF ANY KIND.             }
{ The author is not responsible for any possible damage done due to the     }
{ use of this code.                                                         }
{***************************************************************************}
--]]


-- ***************************
-- init variables
-- ***************************
in_hvac = {};
for i=0, 2 do
  in_hvac[i] = 0;
end

inSP_val = 0.0;
outSP_id = 0;

-- ***************************
-- 
-- ***************************
function myLogic(x)
-- 
-- store last HVAC mode received
--
  if (( x >= 232 ) and ( x <= 234 ))   then
    outSP_id = x-232;
	in_hvac[outSP_id] = knx.get_integer(x);
	
--  ccheck valid HVAC mode 1=cmfort 2=Standby 3=Eco
	if ((in_hvac[outSP_id] > 3) or (in_hvac[outSP_id] < 1)) then 
	  in_hvac[outSP_id] = 0;
	end
  end
  

-- 
-- update received SP
--
  if (( x == 240 ) or ( x == 244 ) or ( x == 248 ))   then
    inSP_val = knx.get_integer(x);
 	
	if ( x == 240 ) then
	  outSP_id = 0;
	end
	if ( x == 244 ) then
	  outSP_id = 1;
	end
	if ( x == 248 ) then
	  outSP_id = 2;
	end
	
	if (in_hvac[outSP_id] ~= 0) then
--	  knx.set_float(x+in_hvac[outSP_id],inSP_val);
	  knx.set_integer(x+in_hvac[outSP_id],2,inSP_val);
	end	
  end	
end

-- ***************************
-- call back for value changed
-- ***************************
function knx_value_changed(x)
  myLogic(x);
end

-- ***************************
-- call back for value update
-- ***************************
function knx_value_update(x)
  myLogic(x);
end


--[[
  EOF 
--]]
