lpcmanager

ee0047e58566
Parents e57cb6dc67e2
Children 5a5c481839d0
finished reworking pous libraries for RTC buzzer and backlight
--- a/Pous/pousGOT.xml Thu Sep 06 14:18:00 2018 +0200
+++ b/Pous/pousGOT.xml Tue Sep 11 16:14:13 2018 +0200
@@ -17,7 +17,7 @@
<types>
<dataTypes/>
<pous>
- <pou name="Backlight_dimmer" pouType="functionBlock">
+ <pou name="Set_Brightness" pouType="functionBlock">
<interface>
<inputVars>
<variable name="TRIG">
@@ -25,70 +25,97 @@
<BOOL/>
</type>
</variable>
- <variable name="TYPE_VALUE">
- <type>
- <INT/>
- </type>
- </variable>
- <variable name="DIMM_VALUE">
+ <variable name="PERCENT">
<type>
<INT/>
</type>
</variable>
</inputVars>
+ <outputVars>
+ <variable name="ACK">
+ <type>
+ <BOOL/>
+ </type>
+ </variable>
+ </outputVars>
<localVars>
<variable name="eval">
<type>
<derived name="python_eval"/>
</type>
</variable>
+ </localVars>
+ </interface>
+ <body>
+ <ST>
+ <xhtml:p><![CDATA[(* Set dimmer value *)
+INPUT_VALUE_CODE:=eval(
+ TRIG := TRIG,
+ CODE := CONCAT(
+ 'SetDimmerValue(',
+ INT_TO_STRING(PERCENT);
+ ')'
+ );
+ ACK => ACK
+);]]></xhtml:p>
+ </ST>
+ </body>
+ <documentation>
+ <xhtml:p><![CDATA[Set backlight brightness to PERCENT on raising edge of TRIG.]]></xhtml:p>
+ </documentation>
+ </pou>
+ <pou name="Fade_Brightness" pouType="functionBlock">
+ <interface>
+ <inputVars>
+ <variable name="TRIG">
+ <type>
+ <BOOL/>
+ </type>
+ </variable>
+ <variable name="PERCENT">
+ <type>
+ <INT/>
+ </type>
+ </variable>
+ <variable name="TIME_MS">
+ <type>
+ <INT/>
+ </type>
+ </variable>
+ </inputVars>
+ <outputVars>
<variable name="ACK">
<type>
<BOOL/>
</type>
</variable>
- <variable name="RESULT">
- <type>
- <string/>
- </type>
- </variable>
- <variable name="INPUT_ARGS">
- <type>
- <string/>
- </type>
- </variable>
- <variable name="INPUT_TYPE">
+ </outputVars>
+ <localVars>
+ <variable name="eval">
<type>
- <string/>
- </type>
- </variable>
- <variable name="INPUT_VALUE">
- <type>
- <string/>
- </type>
- </variable>
- <variable name="INPUT_VALUE_CODE">
- <type>
- <string/>
- </type>
- </variable>
- <variable name="CODE">
- <type>
- <string/>
+ <derived name="python_eval"/>
</type>
</variable>
</localVars>
</interface>
<body>
<ST>
- <xhtml:p><![CDATA[(* *)
-
-
-INPUT_TYPE:=INT_TO_STRING(TYPE_VALUE); INPUT_VALUE:=INT_TO_STRING(DIMM_VALUE); INPUT_ARGS:=CONCAT(INPUT_TYPE, ',', INPUT_VALUE); INPUT_VALUE_CODE:=CONCAT('PLCObject.MWProvider.SetDimmerValue(', INPUT_ARGS, ')'); eval(TRIG := TRIG, CODE := INPUT_VALUE_CODE, ACK => ACK, RESULT => RESULT);]]></xhtml:p>
+ <xhtml:p><![CDATA[(* Fade dimmer value *)
+INPUT_VALUE_CODE:=eval(
+ TRIG := TRIG,
+ CODE := CONCAT(
+ 'SetDimmerValue(',
+ INT_TO_STRING(PERCENT);
+ ',',
+ INT_TO_STRING(TIME_MS);
+ ')'
+ );
+ ACK => ACK
+);]]></xhtml:p>
</ST>
</body>
<documentation>
- <xhtml:p><![CDATA[Backlight_dimmer function block allows the manipulation of brightness. TYPE_VALUE ranges from 0 to 3, where 0 is no fading, 1 slowly changes brightness when lowering it, 2 slowly changes brightness when rising it and 3 slowly changes it both ways. DIMM_VALUE ranges from 0 to 26 and changes the brightness value.]]></xhtml:p>
+ <xhtml:p><![CDATA[Start fading backlight brightness on raising edge of TRIG, from current value to PERCENT, in TIME_MS miliseconds.]]></xhtml:p>
</documentation>
</pou>
<pou name="Buzzer" pouType="functionBlock">
@@ -111,24 +138,19 @@
<BOOL/>
</type>
</variable>
- <variable name="RESULT">
- <type>
- <string/>
- </type>
- </variable>
- <variable name="INPUT_VALUE_OLD">
- <type>
- <string/>
- </type>
- </variable>
<variable name="TRIG">
<type>
<BOOL/>
</type>
</variable>
- <variable name="INPUT_VALUE_CODE">
+ <variable name="APPLIED_VAL">
<type>
- <string/>
+ <BOOL/>
+ </type>
+ </variable>
+ <variable name="ORDERED_VAL">
+ <type>
+ <BOOL/>
</type>
</variable>
<variable name="CODE">
@@ -136,15 +158,48 @@
<string/>
</type>
</variable>
+ <variable name="rtrig">
+ <type>
+ <derived name="R_TRIG"/>
+ </type>
+ </variable>
+ <variable name="RACK">
+ <type>
+ <BOOL/>
+ </type>
+ </variable>
</localVars>
</interface>
<body>
<ST>
- <xhtml:p><![CDATA[TRIG :=TRUE; INPUT_VALUE_CODE:=CONCAT('PLCObject.MWProvider.SetBuzzerValue(', INT_TO_STRING(BOOL_TO_INT(INPUT_VALUE)), ')'); eval(TRIG := TRIG, CODE := INPUT_VALUE_CODE, ACK => ACK, RESULT => RESULT);]]></xhtml:p>
+ <xhtml:p><![CDATA[(* Turn buzzer on or off *)
+(* test if not already waiting for ack *)
+IF NOT(TRIG & NOT(ACK)) THEN
+ IF APPLIED_VAL <> INPUT_VALUE THEN
+ TRIG := TRUE;
+ ORDERED_VAL := INPUT_VALUE;
+ CODE:=CONCAT(
+ 'SetBuzzerValue(',
+ INT_TO_STRING(BOOL_TO_INT(INPUT_VALUE)),
+ ')'
+ );
+END_IF;
+eval(
+ TRIG := TRIG,
+ CODE := CODE,
+ ACK => ACK
+);
+rtrig(CLK := ACK, Q => RACK);
+IF RACK THEN
+ TRIG := FALSE;
+ APPLIED_VAL := ORDERED_VAL;
+END_IF;
+
+]]></xhtml:p>
</ST>
</body>
<documentation>
- <xhtml:p><![CDATA[Buzzer function block provides a buzz sound]]></xhtml:p>
+ <xhtml:p><![CDATA[Turns buzzer on or off, according to input value]]></xhtml:p>
</documentation>
</pou>
</pous>
--- a/Pous/pousRTC.xml Thu Sep 06 14:18:00 2018 +0200
+++ b/Pous/pousRTC.xml Tue Sep 11 16:14:13 2018 +0200
@@ -17,14 +17,69 @@
<types>
<dataTypes/>
<pous>
- <pou name="getRTC" pouType="functionBlock">
+ <pou name="getRTCString" pouType="functionBlock">
<interface>
+ <inputVars>
+ <variable name="TRIG">
+ <type>
+ <BOOL/>
+ </type>
+ </variable>
+ </inputVars>
<outputVars>
+ <variable name="ACK">
+ <type>
+ <BOOL/>
+ </type>
+ </variable>
<variable name="DT_STR">
<type>
<string/>
</type>
</variable>
+ </outputVars>
+ <localVars>
+ <variable name="eval">
+ <type>
+ <derived name="python_eval"/>
+ </type>
+ </variable>
+ </localVars>
+ </interface>
+ <body>
+ <ST>
+ <xhtml:p><![CDATA[(* Get time from RTC *)
+eval(TRIG:=TRIG, CODE:='GetRTC()', ACK => ACK, RESULT => DT_STR);]]></xhtml:p>
+ </ST>
+ </body>
+ <documentation>
+ <xhtml:p><![CDATA[Sample time from RTC on raising edge of TRIG. Outputs a formated string in DT_STR and sets ACK to TRUE when output is ready.
+Format:
+ YYYY-mm-dd HH:MM:SS w v
+
+Last two numbers are :
+ w: week day
+ v: valid flag
+
+Example:
+ 2018-07-28 11:24:07 6 1]]></xhtml:p>
+ </documentation>
+ </pou>
+ <pou name="getRTC" pouType="functionBlock">
+ <interface>
+ <inputVars>
+ <variable name="TRIG">
+ <type>
+ <BOOL/>
+ </type>
+ </variable>
+ </inputVars>
+ <outputVars>
+ <variable name="ACK">
+ <type>
+ <BOOL/>
+ </type>
+ </variable>
<variable name="VALID">
<type>
<BOOL/>
@@ -72,17 +127,17 @@
<derived name="python_eval"/>
</type>
</variable>
- <variable name="ACK">
+ <variable name="rtrig">
+ <type>
+ <derived name="R_TRIG"/>
+ </type>
+ </variable>
+ <variable name="COMPUTE">
<type>
<BOOL/>
</type>
</variable>
- <variable name="INPUT_VALUE_CODE">
- <type>
- <string/>
- </type>
- </variable>
- <variable name="CODE">
+ <variable name="DT_STR">
<type>
<string/>
</type>
@@ -93,21 +148,27 @@
<ST>
<xhtml:p><![CDATA[(* Get time from RTC *)
eval(TRIG:=TRIG, CODE:='GetRTC()', ACK => ACK, RESULT => DT_STR);
-IF R_TRIG(ACK) THEN
- VALID:=STRING_TO_BOOL(IN:=MID(IN:=DT_STR,L:=1,P:=23));
- YEAR:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=4,P:=1));
- MONTH:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=6));
- DAY:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=9));
- WDAY:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=1,P:=21));
- HOUR:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=12));
- MINUTE:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=15));
- SECOND:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=18));
+rtrig(CLK := ACK, Q => COMPUTE);
+IF COMPUTE OR (TRIG & ACK ) THEN
+ IF COMPUTE THEN
+ VALID:=STRING_TO_BOOL(IN:=MID(IN:=DT_STR,L:=1,P:=23));
+ YEAR:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=4,P:=1));
+ MONTH:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=6));
+ DAY:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=9));
+ WDAY:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=1,P:=21));
+ HOUR:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=12));
+ MINUTE:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=15));
+ SECOND:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=18));
+ END_IF;
+ELSE
+ VALID:=FALSE;
END_IF;
+
]]></xhtml:p>
</ST>
</body>
<documentation>
- <xhtml:p><![CDATA[Get time from RTC on raising edge of TRIG]]></xhtml:p>
+ <xhtml:p><![CDATA[Sample time from RTC on raising edge of TRIG. Outputs time as separate values and sets ACK to TRUE when output is ready. VALID is FALSE if hardware clock had a power failure and time is incorrect, TRUE otherwise.]]></xhtml:p>
</documentation>
</pou>
<pou name="setRTC" pouType="functionBlock">
@@ -150,9 +211,14 @@
</variable>
</inputVars>
<outputVars>
- <variable name="RESULT">
+ <variable name="ACK">
<type>
- <string/>
+ <BOOL/>
+ </type>
+ </variable>
+ <variable name="VALID">
+ <type>
+ <BOOL/>
</type>
</variable>
</outputVars>
@@ -162,7 +228,12 @@
<derived name="python_eval"/>
</type>
</variable>
- <variable name="ACK">
+ <variable name="rtrig">
+ <type>
+ <derived name="R_TRIG"/>
+ </type>
+ </variable>
+ <variable name="COMPUTE">
<type>
<BOOL/>
</type>
@@ -177,7 +248,7 @@
<string/>
</type>
</variable>
- <variable name="CODE">
+ <variable name="RESULT">
<type>
<string/>
</type>
@@ -187,17 +258,22 @@
<body>
<ST>
<xhtml:p><![CDATA[(* Set RTC time *)
-IF R_TRIG(TRIG) THEN
- INPUT_ARGS := CONCAT(
+rtrig(CLK := TRIG, Q => COMPUTE);
+IF COMPUTE THEN
+ INPUT_VALUE_CODE:=CONCAT(
+ 'SetRTC(',
UINT_TO_STRING(YEAR), ',',
UINT_TO_STRING(MONTH), ',',
UINT_TO_STRING(DAY), ',',
UINT_TO_STRING(HOUR), ',',
UINT_TO_STRING(MINUTE), ',',
- UINT_TO_STRING(SECOND));
- INPUT_VALUE_CODE:=CONCAT('SetRTC(', INPUT_ARGS, ')');
+ UINT_TO_STRING(SECOND), ')');
END_IF;
-eval(TRIG := TRIG, CODE := INPUT_VALUE_CODE, ACK => ACK, RESULT => RESULT);]]></xhtml:p>
+eval(TRIG := TRIG, CODE := INPUT_VALUE_CODE, ACK => ACK, RESULT => RESULT);
+IF ACK THEN
+ VALID := RESULT = 'True';
+END_IF;
+]]></xhtml:p>
</ST>
</body>
<documentation>