From b55aafe702ffa38605b6342b54e94c904d17386e Mon Sep 17 00:00:00 2001
From: ft-Demo <fischertechnik-team@fischer.de>
Date: Tue, 7 Sep 2021 06:58:17 +0000
Subject: [PATCH] commit by robo pro coding

---
 lib/controller.blockly            |   2 +-
 lib/controller.py                 |   6 +-
 lib/display.qml                   |  58 ++++-----
 lib/display.xml                   |   2 +-
 test_environmental_sensor.blockly | 195 ++++++++++++------------------
 test_environmental_sensor.py      |  31 ++---
 6 files changed, 130 insertions(+), 164 deletions(-)

diff --git a/lib/controller.blockly b/lib/controller.blockly
index c8795e5..9ab2674 100644
--- a/lib/controller.blockly
+++ b/lib/controller.blockly
@@ -1,4 +1,4 @@
-<xml xmlns="https://developers.google.com/blockly/xml" version="9">
+<xml xmlns="https://developers.google.com/blockly/xml" version="11">
   <block type="txt4_controller" id="alz77~oN0~@9+5#nF!cL" x="29" y="57">
     <mutation>
       <arg type="Input" name="Input-0" value="-"/>
diff --git a/lib/controller.py b/lib/controller.py
index 778b475..d6efd1f 100644
--- a/lib/controller.py
+++ b/lib/controller.py
@@ -1,9 +1,9 @@
 import fischertechnik.factories as txt_factory
 
-
-txt_factory.init_controller_factory()
+txt_factory.init()
 txt_factory.init_i2c_factory()
 
-
 TXT = txt_factory.controller_factory.create_graphical_controller()
 TXT_I2C_1_environment_sensor = txt_factory.i2c_factory.create_environment_sensor(TXT, 1)
+
+txt_factory.initialized()
\ No newline at end of file
diff --git a/lib/display.qml b/lib/display.qml
index 6230d48..6f7f49e 100644
--- a/lib/display.qml
+++ b/lib/display.qml
@@ -14,60 +14,60 @@ TXTWindow {
   TXTLabel {
     id: txt_label_t
     text: "t"
-    font.pixelSize: 24
+    font.pixelSize: 16
     elide: Text.ElideRight
-    x: 60
+    x: 40
     y: 60
-    width: 100
-    height: 20
+    width: 180
+    height: 40
   }
   TXTLabel {
     id: txt_label_h
     text: "h"
-    font.pixelSize: 24
+    font.pixelSize: 16
     elide: Text.ElideRight
-    x: 60
-    y: 90
-    width: 100
-    height: 20
+    x: 40
+    y: 100
+    width: 180
+    height: 40
   }
   TXTLabel {
     id: txt_label_p
     text: "p"
-    font.pixelSize: 24
+    font.pixelSize: 16
     elide: Text.ElideRight
-    x: 60
-    y: 120
-    width: 100
-    height: 20
+    x: 40
+    y: 140
+    width: 180
+    height: 40
   }
   TXTLabel {
     id: txt_label_iaq
     text: "iaq"
-    font.pixelSize: 24
+    font.pixelSize: 16
     elide: Text.ElideRight
-    x: 60
-    y: 150
-    width: 100
-    height: 20
+    x: 40
+    y: 180
+    width: 180
+    height: 40
   }
   StatusIndicator {
     id: txt_status_indicator
-    color: "#ff0000"
+    color: "#00FF6C"
     active: false
-    x: 30
-    y: 10
-    width: 20
-    height: 20
+    x: 39
+    y: 20
+    width: 41
+    height: 39
   }
   TXTLabel {
     id: txt_label
-    text: "BME680 calibrated"
-    font.pixelSize: 24
+    text: "calibration"
+    font.pixelSize: 16
     elide: Text.ElideRight
-    x: 60
-    y: 10
-    width: 100
+    x: 100
+    y: 30
+    width: 120
     height: 20
   }
 }
diff --git a/lib/display.xml b/lib/display.xml
index 49386ad..c27ab69 100644
--- a/lib/display.xml
+++ b/lib/display.xml
@@ -1 +1 @@
-<xml type="display" version="2"><item id="2" class="TXTLabel"><name>txt_label_t</name><text>t</text><geometry><x>60</x><y>60</y><width>100</width><height>20</height></geometry></item><item id="3" class="TXTLabel"><name>txt_label_h</name><text>h</text><geometry><x>60</x><y>90</y><width>100</width><height>20</height></geometry></item><item id="4" class="TXTLabel"><name>txt_label_p</name><text>p</text><geometry><x>60</x><y>120</y><width>100</width><height>20</height></geometry></item><item id="5" class="TXTLabel"><name>txt_label_iaq</name><text>iaq</text><geometry><x>60</x><y>150</y><width>100</width><height>20</height></geometry></item><item id="6" class="StatusIndicator"><name>txt_status_indicator</name><color>#ff0000</color><active>false</active><geometry><x>30</x><y>10</y><width>20</width><height>20</height></geometry></item><item id="7" class="TXTLabel"><name>txt_label</name><text>BME680 calibrated</text><geometry><x>60</x><y>10</y><width>100</width><height>20</height></geometry></item></xml>
\ No newline at end of file
+<xml type="display" version="2"><item id="2" class="TXTLabel"><name>txt_label_t</name><text>t</text><geometry><x>40</x><y>60</y><width>180</width><height>40</height></geometry></item><item id="3" class="TXTLabel"><name>txt_label_h</name><text>h</text><geometry><x>40</x><y>100</y><width>180</width><height>40</height></geometry></item><item id="4" class="TXTLabel"><name>txt_label_p</name><text>p</text><geometry><x>40</x><y>140</y><width>180</width><height>40</height></geometry></item><item id="5" class="TXTLabel"><name>txt_label_iaq</name><text>iaq</text><geometry><x>40</x><y>180</y><width>180</width><height>40</height></geometry></item><item id="6" class="StatusIndicator"><name>txt_status_indicator</name><color>#00FF6C</color><active>false</active><geometry><x>39</x><y>20</y><width>41</width><height>39</height></geometry></item><item id="7" class="TXTLabel"><name>txt_label</name><text>calibration</text><geometry><x>100</x><y>30</y><width>120</width><height>20</height></geometry></item></xml>
\ No newline at end of file
diff --git a/test_environmental_sensor.blockly b/test_environmental_sensor.blockly
index cc8e823..a4095a9 100644
--- a/test_environmental_sensor.blockly
+++ b/test_environmental_sensor.blockly
@@ -1,8 +1,9 @@
-<xml xmlns="https://developers.google.com/blockly/xml" version="9">
+<xml xmlns="https://developers.google.com/blockly/xml" version="11">
   <variables>
     <variable id="HuRd}q%zRj|l]`0]9+,v">t</variable>
-    <variable id="E#)K*ceuQH)cM);bvVSl">iaq</variable>
+    <variable id="i!Gg@y*n{VU4a9o-@?JU">aq</variable>
     <variable id="(lIqPZvC*jYE@#I.!=Wy">h</variable>
+    <variable id="E#)K*ceuQH)cM);bvVSl">iaq</variable>
     <variable id="|]?yRgy2?Z3VWuPxsG(2">p</variable>
   </variables>
   <block type="start_block" id="m4V$1bSXH=m-3c)X8_S~" deletable="false" x="0" y="0">
@@ -37,13 +38,23 @@
                       </shadow>
                     </value>
                     <next>
-                      <block type="variables_set" id="X3`Pc0WcQIxOYjMp|Mb?">
-                        <field name="VAR" id="E#)K*ceuQH)cM);bvVSl">iaq</field>
+                      <block type="variables_set" id="?$]F$(j%7nK]-!=0}*}@">
+                        <field name="VAR" id="i!Gg@y*n{VU4a9o-@?JU">aq</field>
                         <value name="VALUE">
-                          <block type="math_number" id="K]yL.U4fo#:7+w2$Mc[x">
-                            <field name="NUM">0</field>
+                          <block type="text" id="STmKuhG:|Cf{{!0-p:Cp">
+                            <field name="TEXT">-</field>
                           </block>
                         </value>
+                        <next>
+                          <block type="variables_set" id="|XrTKh.E!ExRng:x^|sr">
+                            <field name="VAR" id="E#)K*ceuQH)cM);bvVSl">iaq</field>
+                            <value name="VALUE">
+                              <block type="math_number" id="PHvvugD`da0KKn;VSre4">
+                                <field name="NUM">0</field>
+                              </block>
+                            </value>
+                          </block>
+                        </next>
                       </block>
                     </next>
                   </block>
@@ -57,20 +68,25 @@
                       </shadow>
                     </value>
                     <next>
-                      <block type="variables_set" id="=ENOyx.]2f.HCie@~QdP">
-                        <field name="VAR" id="E#)K*ceuQH)cM);bvVSl">iaq</field>
+                      <block type="variables_set" id="v6F7Y94yR(,-AeBZ9e((">
+                        <field name="VAR" id="i!Gg@y*n{VU4a9o-@?JU">aq</field>
                         <value name="VALUE">
-                          <block type="math_round" id="MsbIsS_?ky0FnXf:j^=Q">
-                            <field name="OP">ROUND</field>
-                            <field name="DECIMALS">0</field>
-                            <value name="NUM">
-                              <block type="i2c_environment_sensor_get_iaq" id="mM_#]89u;09P}dCIy;DS">
+                          <block type="i2c_environment_sensor_get_iaq" id="Zb]!55US.e%bO(^|)g,7">
+                            <field name="instance_name">TXT_I2C_1_environment_sensor</field>
+                            <field name="dropdown_event">text</field>
+                          </block>
+                        </value>
+                        <next>
+                          <block type="variables_set" id="[d!%je!,86f*-QZ7ML-C">
+                            <field name="VAR" id="E#)K*ceuQH)cM);bvVSl">iaq</field>
+                            <value name="VALUE">
+                              <block type="i2c_environment_sensor_get_iaq" id="BM[K)-|:(4E@C$~V0km8">
                                 <field name="instance_name">TXT_I2C_1_environment_sensor</field>
                                 <field name="dropdown_event">number</field>
                               </block>
                             </value>
                           </block>
-                        </value>
+                        </next>
                       </block>
                     </next>
                   </block>
@@ -79,42 +95,24 @@
                   <block type="variables_set" id="/*`sbu=``h|;*`X9omR;">
                     <field name="VAR" id="HuRd}q%zRj|l]`0]9+,v">t</field>
                     <value name="VALUE">
-                      <block type="math_round" id="b3X1)3VP1U01,+i%|X1=">
-                        <field name="OP">ROUND</field>
-                        <field name="DECIMALS">1</field>
-                        <value name="NUM">
-                          <block type="i2c_environment_sensor_get_temperature" id="buatR#.x9UN7cRK)|.?5">
-                            <field name="instance_name">TXT_I2C_1_environment_sensor</field>
-                          </block>
-                        </value>
+                      <block type="i2c_environment_sensor_get_temperature" id="buatR#.x9UN7cRK)|.?5">
+                        <field name="instance_name">TXT_I2C_1_environment_sensor</field>
                       </block>
                     </value>
                     <next>
                       <block type="variables_set" id="T_slPv%+zMa/4}/9^}=9">
                         <field name="VAR" id="(lIqPZvC*jYE@#I.!=Wy">h</field>
                         <value name="VALUE">
-                          <block type="math_round" id="m1Y/ZEo8QIBh7*:rL}ph">
-                            <field name="OP">ROUND</field>
-                            <field name="DECIMALS">1</field>
-                            <value name="NUM">
-                              <block type="i2c_environment_sensor_get_humidity" id="6kbvrH9kQDDc/%#bBP6Y">
-                                <field name="instance_name">TXT_I2C_1_environment_sensor</field>
-                              </block>
-                            </value>
+                          <block type="i2c_environment_sensor_get_humidity" id="6kbvrH9kQDDc/%#bBP6Y">
+                            <field name="instance_name">TXT_I2C_1_environment_sensor</field>
                           </block>
                         </value>
                         <next>
                           <block type="variables_set" id=".17Gj!~lHCQ!{`z$t^VY">
                             <field name="VAR" id="|]?yRgy2?Z3VWuPxsG(2">p</field>
                             <value name="VALUE">
-                              <block type="math_round" id="^*v|VhwtvE~$)15D1v!Z">
-                                <field name="OP">ROUND</field>
-                                <field name="DECIMALS">1</field>
-                                <value name="NUM">
-                                  <block type="i2c_environment_sensor_get_pressure" id="ZQ5xtNNap]b;HAlvPg~C">
-                                    <field name="instance_name">TXT_I2C_1_environment_sensor</field>
-                                  </block>
-                                </value>
+                              <block type="i2c_environment_sensor_get_pressure" id="ZQ5xtNNap]b;HAlvPg~C">
+                                <field name="instance_name">TXT_I2C_1_environment_sensor</field>
                               </block>
                             </value>
                             <next>
@@ -124,23 +122,18 @@
                                   <shadow type="text" id=")QWt*FmIHV%mXx{e@[.M">
                                     <field name="TEXT"/>
                                   </shadow>
-                                  <block type="text_join" id="G^TGTMAB5,~w?R@u`;l(">
-                                    <mutation items="3"/>
-                                    <value name="ADD0">
-                                      <block type="text" id="Hn#Fga]jj[52Ay*xT;p@">
-                                        <field name="TEXT">t: </field>
-                                      </block>
+                                  <block type="text_format" id="]gR+)cB~?vx`7_a1_rb[">
+                                    <mutation items="1"/>
+                                    <value name="value">
+                                      <shadow type="text" id="nD}hqv)Q`[i/bAVj%z9p">
+                                        <field name="TEXT">Temperature {:.1f} °C</field>
+                                      </shadow>
                                     </value>
-                                    <value name="ADD1">
+                                    <value name="ADD0">
                                       <block type="variables_get" id="pf-oLwzQ]:]M7{ozX[3%">
                                         <field name="VAR" id="HuRd}q%zRj|l]`0]9+,v">t</field>
                                       </block>
                                     </value>
-                                    <value name="ADD2">
-                                      <block type="text" id="U9e!4NU;eJGxotKr6c2A">
-                                        <field name="TEXT"> °C</field>
-                                      </block>
-                                    </value>
                                   </block>
                                 </value>
                                 <next>
@@ -150,23 +143,18 @@
                                       <shadow type="text">
                                         <field name="TEXT"/>
                                       </shadow>
-                                      <block type="text_join" id="tMY$0.;;#A20!JC=dH4-">
-                                        <mutation items="3"/>
-                                        <value name="ADD0">
-                                          <block type="text" id="9qz/I%Q.ci#c#!RaF9;F">
-                                            <field name="TEXT"> h: </field>
-                                          </block>
+                                      <block type="text_format" id="2E56@c#E{BT#Iww?2,+c">
+                                        <mutation items="1"/>
+                                        <value name="value">
+                                          <shadow type="text" id="V{X_zH6-Hc$DZo($|=70">
+                                            <field name="TEXT">Air humidity {:.1f} %rH</field>
+                                          </shadow>
                                         </value>
-                                        <value name="ADD1">
+                                        <value name="ADD0">
                                           <block type="variables_get" id="qPiI=k#jN*#K9~xh6#y1">
                                             <field name="VAR" id="(lIqPZvC*jYE@#I.!=Wy">h</field>
                                           </block>
                                         </value>
-                                        <value name="ADD2">
-                                          <block type="text" id="4%Q%BVe9~D=x?J5#9@Dg">
-                                            <field name="TEXT"> %rH</field>
-                                          </block>
-                                        </value>
                                       </block>
                                     </value>
                                     <next>
@@ -176,23 +164,18 @@
                                           <shadow type="text">
                                             <field name="TEXT"/>
                                           </shadow>
-                                          <block type="text_join" id="@28(eWp?)`Q2;t{3y^Oi">
-                                            <mutation items="3"/>
-                                            <value name="ADD0">
-                                              <block type="text" id="`=dN8*kf3:~=CI7[}Cat">
-                                                <field name="TEXT"> p: </field>
-                                              </block>
+                                          <block type="text_format" id="W@ty0(^x;RBeq[0cf3Bp">
+                                            <mutation items="1"/>
+                                            <value name="value">
+                                              <shadow type="text" id="5Z+)QOImr3.mP4[55#vz">
+                                                <field name="TEXT">Air pressure {:.1f} hPa</field>
+                                              </shadow>
                                             </value>
-                                            <value name="ADD1">
+                                            <value name="ADD0">
                                               <block type="variables_get" id=",lFx/B@~x=fn[^Bc1c))">
                                                 <field name="VAR" id="|]?yRgy2?Z3VWuPxsG(2">p</field>
                                               </block>
                                             </value>
-                                            <value name="ADD2">
-                                              <block type="text" id="Z@}vBJx[Q3p.O8R9NX~|">
-                                                <field name="TEXT"> hPa</field>
-                                              </block>
-                                            </value>
                                           </block>
                                         </value>
                                         <next>
@@ -202,11 +185,16 @@
                                               <shadow type="text">
                                                 <field name="TEXT"/>
                                               </shadow>
-                                              <block type="text_join" id="Gb.sYnEb3ToFmnrE6jP%">
+                                              <block type="text_format" id="`9_o+?T7z#H=U#VCnG-!">
                                                 <mutation items="2"/>
+                                                <value name="value">
+                                                  <shadow type="text" id="DGD$m/(syl)we_O|H6U/">
+                                                    <field name="TEXT">Air quality {} ({:.0f})</field>
+                                                  </shadow>
+                                                </value>
                                                 <value name="ADD0">
-                                                  <block type="text" id="BWsdiFW3ZD0e6!m2Sb!v">
-                                                    <field name="TEXT"> iaq: </field>
+                                                  <block type="variables_get" id="0RNa,jxv4?L!e?/y7|+o">
+                                                    <field name="VAR" id="i!Gg@y*n{VU4a9o-@?JU">aq</field>
                                                   </block>
                                                 </value>
                                                 <value name="ADD1">
@@ -219,60 +207,35 @@
                                             <next>
                                               <block type="text_print" id="Gp$I*t@d]0ynd!#E*t;O">
                                                 <value name="TEXT">
-                                                  <block type="text_join" id="1b7XyQkpVKW4B@?s#KDx">
-                                                    <mutation items="11"/>
-                                                    <value name="ADD0">
-                                                      <block type="text" id="NZK40v2]45%^NO8Y/9r9">
-                                                        <field name="TEXT">t: </field>
-                                                      </block>
+                                                  <block type="text_format" id="{.~m+j3=d:y!@8mWb1k/">
+                                                    <mutation items="5"/>
+                                                    <value name="value">
+                                                      <shadow type="text" id="C?6?/P1.a^,pAH)uYkw.">
+                                                        <field name="TEXT">T {:.1f} °C, H {:.1f} %rH, p {:.1f} hPa, iaq {} ({:.0f})</field>
+                                                      </shadow>
                                                     </value>
-                                                    <value name="ADD1">
+                                                    <value name="ADD0">
                                                       <block type="variables_get" id="paEj*~Qw;?MW/Pv-j@1T">
                                                         <field name="VAR" id="HuRd}q%zRj|l]`0]9+,v">t</field>
                                                       </block>
                                                     </value>
-                                                    <value name="ADD2">
-                                                      <block type="text" id="Sf)Tl:Pg%KqTob2#i]?S">
-                                                        <field name="TEXT"> °C</field>
-                                                      </block>
-                                                    </value>
-                                                    <value name="ADD3">
-                                                      <block type="text" id="wKbwrq8aL#*2ClQNqmhM">
-                                                        <field name="TEXT"> h: </field>
-                                                      </block>
-                                                    </value>
-                                                    <value name="ADD4">
+                                                    <value name="ADD1">
                                                       <block type="variables_get" id="Dd/hj2/Y~aeEC6-5yHkN">
                                                         <field name="VAR" id="(lIqPZvC*jYE@#I.!=Wy">h</field>
                                                       </block>
                                                     </value>
-                                                    <value name="ADD5">
-                                                      <block type="text" id="-^ConPYBj_.K=)#S`PHD">
-                                                        <field name="TEXT"> %rH</field>
-                                                      </block>
-                                                    </value>
-                                                    <value name="ADD6">
-                                                      <block type="text" id="{dk{08ze|`XD8_KiDAJ1">
-                                                        <field name="TEXT"> p: </field>
-                                                      </block>
-                                                    </value>
-                                                    <value name="ADD7">
+                                                    <value name="ADD2">
                                                       <block type="variables_get" id="U.[JTqzwL,ES)m9+L;hU">
                                                         <field name="VAR" id="|]?yRgy2?Z3VWuPxsG(2">p</field>
                                                       </block>
                                                     </value>
-                                                    <value name="ADD8">
-                                                      <block type="text" id="zLtM_xa*ZBeCtm5qt#gF">
-                                                        <field name="TEXT"> hPa</field>
-                                                      </block>
-                                                    </value>
-                                                    <value name="ADD9">
-                                                      <block type="text" id="$lZRO5Rj4^%?SZcBlp8D">
-                                                        <field name="TEXT"> iaq: </field>
+                                                    <value name="ADD3">
+                                                      <block type="variables_get" id="DRn8{EKsr`j!Gb]}UP;@">
+                                                        <field name="VAR" id="i!Gg@y*n{VU4a9o-@?JU">aq</field>
                                                       </block>
                                                     </value>
-                                                    <value name="ADD10">
-                                                      <block type="variables_get" id="p04d8I;sB=RuS5|W;yL?">
+                                                    <value name="ADD4">
+                                                      <block type="variables_get" id="CT{35f7^j-V$$/Kz))#8">
                                                         <field name="VAR" id="E#)K*ceuQH)cM);bvVSl">iaq</field>
                                                       </block>
                                                     </value>
diff --git a/test_environmental_sensor.py b/test_environmental_sensor.py
index 6cc7234..ecf76ae 100644
--- a/test_environmental_sensor.py
+++ b/test_environmental_sensor.py
@@ -1,12 +1,13 @@
+import time
+
 from lib.controller import *
 from lib.display import *
-import math
-import time
 
 
 t = None
-iaq = None
+aq = None
 h = None
+iaq = None
 p = None
 
 
@@ -14,17 +15,19 @@ if TXT_I2C_1_environment_sensor.needs_calibration():
     TXT_I2C_1_environment_sensor.calibrate()
 while True:
     if TXT_I2C_1_environment_sensor.needs_calibration():
-        display.exec_script("txt_status_indicator.active=" + str(False).lower())
+        display.set_attr("txt_status_indicator.active", str(False).lower())
+        aq = '-'
         iaq = 0
     else:
-        display.exec_script("txt_status_indicator.active=" + str(True).lower())
-        iaq = round(TXT_I2C_1_environment_sensor.get_indoor_air_quality_as_number())
-    t = round(TXT_I2C_1_environment_sensor.get_temperature(), 1)
-    h = round(TXT_I2C_1_environment_sensor.get_humidity(), 1)
-    p = round(TXT_I2C_1_environment_sensor.get_pressure(), 1)
-    display.exec_script("txt_label_t.text='%s'" % str(''.join([str(x) for x in ['t: ', t, ' °C']])))
-    display.exec_script("txt_label_h.text='%s'" % str(''.join([str(x2) for x2 in [' h: ', h, ' %rH']])))
-    display.exec_script("txt_label_p.text='%s'" % str(''.join([str(x3) for x3 in [' p: ', p, ' hPa']])))
-    display.exec_script("txt_label_iaq.text='%s'" % str(' iaq: ' + str(iaq)))
-    print(''.join([str(x4) for x4 in ['t: ', t, ' °C', ' h: ', h, ' %rH', ' p: ', p, ' hPa', ' iaq: ', iaq]]))
+        display.set_attr("txt_status_indicator.active", str(True).lower())
+        aq = TXT_I2C_1_environment_sensor.get_indoor_air_quality_as_text()
+        iaq = TXT_I2C_1_environment_sensor.get_indoor_air_quality_as_number()
+    t = TXT_I2C_1_environment_sensor.get_temperature()
+    h = TXT_I2C_1_environment_sensor.get_humidity()
+    p = TXT_I2C_1_environment_sensor.get_pressure()
+    display.set_attr("txt_label_t.text", str('Temperature {:.1f} °C'.format(t)))
+    display.set_attr("txt_label_h.text", str('Air humidity {:.1f} %rH'.format(h)))
+    display.set_attr("txt_label_p.text", str('Air pressure {:.1f} hPa'.format(p)))
+    display.set_attr("txt_label_iaq.text", str('Air quality {} ({:.0f})'.format(aq, iaq)))
+    print('T {:.1f} °C, H {:.1f} %rH, p {:.1f} hPa, iaq {} ({:.0f})'.format(t, h, p, aq, iaq))
     time.sleep(3)
-- 
GitLab