-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.blocks
1 lines (1 loc) · 23.8 KB
/
main.blocks
1
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="(C(CAv|!GZ0Y?!YgRXC=">theAnswer</variable><variable id="7#Z7_)5G9R.|E@!+HIwX">_byteWaiting</variable><variable id="mj5BQ2Q(,bs.i0O_[:oB">receivedString</variable><variable id="4VJ6(KlU%c[3Hs(:Xe[o">functionStartTime</variable><variable id="pSBhjj_CO[RA3wGq=s-9">_8266MessageWaiting</variable></variables><comment id="Sl2!9[rE$7rA@Q9QOE,_" data="0" x="952" y="20" h="120" w="480">Custom functions and blocks for MakerBitX ESP extension board. David "IowaDave" Sparks September 9, 2020</comment><block type="pxt-on-start" id="6Q}d*V=cn/V.Iyw_A{2*" x="20" y="20"><statement name="HANDLER"><block type="typescript_statement" id="(?2D)k?0y)1(^-I|mdO5" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="let receivedString = """ numlines="1" declaredvars="receivedString"></mutation><next><block type="variables_set" id="u2a4v0sRj)h%M8[y@p?#"><field name="VAR" id="pSBhjj_CO[RA3wGq=s-9">_8266MessageWaiting</field><value name="VALUE"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="logic_boolean" id="w,U)X2lRl?n8y_V3?@od"><field name="BOOL">FALSE</field></block></value><next><block type="typescript_statement" id=".^9R:+mD!|Pa:CkTf:,E" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="let _byteWaiting = 0" numlines="1" declaredvars="_byteWaiting"></mutation><next><block type="typescript_statement" id="n53Po%GjF{qvcGj#[[4K" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="enum espLowHigh {" line1=" LOW," line2=" HIGH" line3="}" numlines="4"></mutation><next><block type="typescript_statement" id="k(*%1`j2dJ-xDn1n[5Oj" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="enum espDigitalPin {" line1=" D0," line2=" D1," line3=" D2," line4=" D3," line5=" D4," line6=" D5," line7=" D6," line8=" D7," line9=" D8" line10="}" numlines="11"></mutation><next><block type="typescript_statement" id="NaBEJv^.T/=L9VAg6Pm[" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="namespace EspCompanion {" line1="" line2=" /**" line3=" * Send the ESP-device an AT-command to set a digital pin level" line4=" */" line5=" //% blockID="setESPpin" block="set ESP pin %espPin %level"" line6=" export function setESPpin(espPin: espDigitalPin, level: espLowHigh): void {" line7=" switch (espPin) {" line8=" case espDigitalPin.D0:" line9=" if (level == espLowHigh.LOW) {" line10=" serial.writeString("AT+DP0=0~");" line11=" } else {" line12=" serial.writeString("AT+DP0=1~");}" line13=" break;" line14=" case espDigitalPin.D1:" line15=" if (level == espLowHigh.LOW) {" line16=" serial.writeString("AT+DP1=0~");" line17=" } else {" line18=" serial.writeString("AT+DP1=1~");}" line19=" break;" line20=" case espDigitalPin.D2:" line21=" if (level == espLowHigh.LOW) {" line22=" serial.writeString("AT+DP2=0~");" line23=" } else {" line24=" serial.writeString("AT+DP2=1~");}" line25=" break;" line26=" case espDigitalPin.D3:" line27=" if (level == espLowHigh.LOW) {" line28=" serial.writeString("AT+DP3=0~");" line29=" } else {" line30=" serial.writeString("AT+DP3=1~");}" line31=" break;" line32=" case espDigitalPin.D4:" line33=" if (level == espLowHigh.LOW) {" line34=" serial.writeString("AT+DP4=0~");" line35=" } else {" line36=" serial.writeString("AT+DP4=1~");}" line37=" break;" line38=" case espDigitalPin.D5:" line39=" if (level == espLowHigh.LOW) {" line40=" serial.writeString("AT+DP5=0~");" line41=" } else {" line42=" serial.writeString("AT+DP5=1~");}" line43=" break;" line44=" case espDigitalPin.D6:" line45=" if (level == espLowHigh.LOW) {" line46=" serial.writeString("AT+DP6=0~");" line47=" } else {" line48=" serial.writeString("AT+DP6=1~");}" line49=" break;" line50=" case espDigitalPin.D7:" line51=" if (level == espLowHigh.LOW) {" line52=" serial.writeString("AT+DP7=0~");" line53=" } else {" line54=" serial.writeString("AT+DP7=1~");}" line55=" break;" line56=" case espDigitalPin.D8:" line57=" if (level == espLowHigh.LOW) {" line58=" serial.writeString("AT+DP8=0~");" line59=" } else {" line60=" serial.writeString("AT+DP8=1~");}" line61=" break;" line62=" default: " line63=" //" line64=" }" line65="" line66=" }" line67="" line68=" /**" line69=" * Read the value of analog pin A0" line70=" */" line71=" //% blockID="getESPpinA0" block="read ESP pin A0"" line72=" export function readEspA0 (): number {" line73=" let returnedValue = -1;" line74=" serial.writeString("AT+AP0?~");" line75=" if (espRespondsWithinMilliseconds(1000)) {" line76=" returnedValue = -2;" line77=" let analogString = readStringFromSerial();" line78=" if (analogString.indexOf("A0=") == 0) {" line79=" returnedValue = parseInt(analogString.slice(3));" line80=" }" line81=" }" line82=" return returnedValue;" line83=" }" line84="" line85=" /**" line86=" * Read the value of a digital pin" line87=" */" line88=" //% blockID="getESPdigitalPin" block="read ESP pin %thePin"" line89=" export function readEspDigitalPin (thePin: espDigitalPin): number {" line90=" switch (thePin) {" line91=" case espDigitalPin.D0:" line92=" serial.writeString("AT+DP0?~");" line93=" break;" line94=" case espDigitalPin.D1:" line95=" serial.writeString("AT+DP1?~");" line96=" break;" line97=" case espDigitalPin.D2:" line98=" serial.writeString("AT+DP2?~");" line99=" break;" line100=" case espDigitalPin.D3:" line101=" serial.writeString("AT+DP3?~");" line102=" break;" line103=" case espDigitalPin.D4:" line104=" serial.writeString("AT+DP4?~");" line105=" break;" line106=" case espDigitalPin.D5:" line107=" serial.writeString("AT+DP5?~");" line108=" break;" line109=" case espDigitalPin.D6:" line110=" serial.writeString("AT+DP6?~");" line111=" break;" line112=" case espDigitalPin.D7:" line113=" serial.writeString("AT+DP7?~");" line114=" break;" line115=" case espDigitalPin.D8:" line116=" serial.writeString("AT+DP8?~");" line117=" break; " line118=" default:" line119=" // no operation" line120=" }" line121=" if (espRespondsWithinMilliseconds(1000)) {" line122=" let digitalString = readStringFromSerial();" line123=" digitalString = digitalString.slice(3);" line124=" if (digitalString == "0") return 0;" line125=" if (digitalString == "1") return 1;" line126=" }" line127=" return -1;" line128=" }" line129="" line130=" /**" line131=" * Send the ESP-device an AT-command to set a digital pin PWM level" line132=" */" line133=" //% blockID="setESPpwm" block="set ESP pin %espPin PWM to %level"" line134=" //% level.min=0 level.max=100 level.defl=50" line135=" export function setESPpwm(espPin: espDigitalPin, level: number): void {" line136=" switch (espPin) {" line137=" case espDigitalPin.D0:" line138=" serial.writeString("AT+PWM0=" + level + "~");" line139=" break;" line140=" case espDigitalPin.D1:" line141=" serial.writeString("AT+PWM1=" + level + "~");" line142=" break;" line143=" case espDigitalPin.D2:" line144=" serial.writeString("AT+PWM2=" + level + "~");" line145=" break;" line146=" case espDigitalPin.D3:" line147=" serial.writeString("AT+PWM3=" + level + "~");" line148=" break;" line149=" case espDigitalPin.D4:" line150=" serial.writeString("AT+PWM4=" + level + "~");" line151=" break;" line152=" case espDigitalPin.D5:" line153=" serial.writeString("AT+PWM5=" + level + "~");" line154=" break;" line155=" case espDigitalPin.D6:" line156=" serial.writeString("AT+PWM6=" + level + "~");" line157=" break;" line158=" case espDigitalPin.D7:" line159=" serial.writeString("AT+PWM7=" + level + "~");" line160=" break;" line161=" case espDigitalPin.D8:" line162=" serial.writeString("AT+PWM8=" + level + "~");" line163=" break;" line164=" default:" line165=" //no operation " line166=" }" line167=" }" line168="" line169=" /**" line170=" * Read the PWM value of a digital pin" line171=" */" line172=" //% blockID="getESPpinPWM" block="ESP pin %thePin PWM value"" line173=" export function readEspPinPwmValue (thePin: espDigitalPin): number {" line174=" switch (thePin) {" line175=" case espDigitalPin.D0:" line176=" serial.writeString("AT+PWM0?~");" line177=" break;" line178=" case espDigitalPin.D1:" line179=" serial.writeString("AT+PWM1?~");" line180=" break;" line181=" case espDigitalPin.D2:" line182=" serial.writeString("AT+PWM2?~");" line183=" break;" line184=" case espDigitalPin.D3:" line185=" serial.writeString("AT+PWM3?~");" line186=" break;" line187=" case espDigitalPin.D4:" line188=" serial.writeString("AT+PWM4?~");" line189=" break;" line190=" case espDigitalPin.D5:" line191=" serial.writeString("AT+PWM5?~");" line192=" break;" line193=" case espDigitalPin.D6:" line194=" serial.writeString("AT+PWM6?~");" line195=" break;" line196=" case espDigitalPin.D7:" line197=" serial.writeString("AT+PWM7?~");" line198=" break;" line199=" case espDigitalPin.D8:" line200=" serial.writeString("AT+PWM8?~");" line201=" break;" line202=" default:" line203=" // no operation " line204=" }" line205=" let returnedValue2 = -1;" line206=" if (espRespondsWithinMilliseconds(1000)) {" line207=" returnedValue2 = -2;" line208=" let analogString2 = readStringFromSerial();" line209=" if ((analogString2.indexOf("PWM") == 0) " line210=" && (analogString2.indexOf("=") == 4)) {" line211=" returnedValue2 = parseInt(analogString2.slice(5));" line212=" }" line213=" }" line214=" return returnedValue2;" line215=" }" line216="" line217="" line218="" line219="" line220=" /**" line221=" * Send the ESP-device an AT-command to initialize the LCD" line222=" */" line223=" //% blockID="init_LCD" block="activate LCD"" line224=" export function initLCD(): void {" line225=" serial.writeString("AT+LCDI~"); " line226=" }" line227="" line228=" /**" line229=" * Send the ESP-device an AT-command to clear the LCD" line230=" */" line231=" //% blockID="clear_LCD" block="clear LCD"" line232=" export function clearLCD(): void {" line233=" serial.writeString("AT+LCDCLR~"); " line234=" }" line235="" line236=" /**" line237=" * Send the ESP-device an AT-command to set the LCD address" line238=" */" line239=" //% blockID="address_LCD" block="set LCD address to %i2caddress"" line240=" export function addressLCD(i2caddress: number): void {" line241=" serial.writeString("AT+LCDA=" + i2caddress + "~"); " line242=" }" line243="" line244=" /**" line245=" * Send the ESP-device AT-commands to print to the LCD" line246=" */" line247=" //% blockID="print_LCD" block="print %lcdText on LCD at row %lcdRow column %lcdCol"" line248=" //% lcdRow.min=0 lcdRow.max=1 lcdRow.defl=0" line249=" //% lcdCol.min=0 lcdCol.max=15 lcdCol.defl=0" line250=" export function printLCD(lcdText: string, lcdRow: number, lcdCol: number ): void {" line251=" // set the row" line252=" serial.writeString("AT+LCDY=" + lcdRow + "~");" line253=" basic.pause(50);" line254=" // set the column" line255=" serial.writeString("AT+LCDX=" + lcdCol + "~");" line256=" basic.pause(50);" line257=" // print the text" line258=" serial.writeString("AT+LCDP=" + lcdText + "~");" line259=" basic.pause(50); " line260=" }" line261="" line262="" line263="}" numlines="264"></mutation></block></next></block></next></block></next></block></next></block></next></block></statement></block><block type="function_definition" id="78:?x(m!+h:fBrtNh7_4" x="1477" y="20"><mutation name="serialMessageWaiting" functionid="GToj|5mVw;b$=WY!w~YW"/><field name="function_name">serialMessageWaiting</field><statement name="STACK"><block type="variables_set" id="y=kPbXMT)+RFNc:HD;Ot"><field name="VAR" id="(C(CAv|!GZ0Y?!YgRXC=">theAnswer</field><value name="VALUE"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="logic_boolean" id="@(0Cp.^IO~*Rr[/V$LfU"><field name="BOOL">FALSE</field></block></value><next><block type="typescript_statement" id="j+o/o[lg75$ts2r%#H8a" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="_byteWaiting = serial.read();" numlines="1"></mutation><next><block type="controls_if" id="!/hOB!P)V=82MRU_kk,3"><value name="IF0"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="logic_operation" id="_08,md%;7agln?CSRXx7"><field name="OP">AND</field><value name="A"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="logic_compare" id="9xQkSl;ptfT$6nm}?L]6"><field name="OP">GT</field><value name="A"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="variables_get" id="I?6R8Sc5J*8(W#dTMMFh"><field name="VAR" id="7#Z7_)5G9R.|E@!+HIwX">_byteWaiting</field></block></value><value name="B"><shadow type="math_number" id="u+@EX|[i{nIWCQCM2;my"><field name="NUM">31</field></shadow></value></block></value><value name="B"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="logic_compare" id="u}TkE0lMsd[|:@c?b4c$"><field name="OP">LT</field><value name="A"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="variables_get" id="U[Gqe,%wr)R!S02a7,U1"><field name="VAR" id="7#Z7_)5G9R.|E@!+HIwX">_byteWaiting</field></block></value><value name="B"><shadow type="math_number" id="2^N!A0KtJ}VEk?jY[16Q"><field name="NUM">127</field></shadow></value></block></value></block></value><statement name="DO0"><block type="variables_set" id="EvxWf[)-0rXxSZ#B}Htf"><field name="VAR" id="(C(CAv|!GZ0Y?!YgRXC=">theAnswer</field><value name="VALUE"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="logic_boolean" id="+f^c9E9H3^Z@@WTm~1vM"><field name="BOOL">TRUE</field></block></value></block></statement><next><block type="function_return" id="-z-e%9UW=*x%jr|x3~$C"><mutation xmlns="http://www.w3.org/1999/xhtml" no_return_value="false"></mutation><value name="RETURN_VALUE"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="variables_get" id="Mh*+A)k8QebQJR=#Wf];"><field name="VAR" id="(C(CAv|!GZ0Y?!YgRXC=">theAnswer</field></block></value></block></next></block></next></block></next></block></statement></block><block type="function_definition" id="bJ7fJTf,1/@f%Z.,%:S-" x="2419" y="20"><mutation name="readStringFromSerial" functionid="3)bNp{ZDmGfo%Q=*e{fr"/><field name="function_name">readStringFromSerial</field><statement name="STACK"><block type="device_while" id="R(Dn9MA@C3tmu,i$kxG6"><value name="COND"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="logic_operation" id="}[GojBmAb[_z1,mgn6De"><field name="OP">AND</field><value name="A"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="logic_compare" id="^[c]}na(t+:e|Rljo;8Y"><field name="OP">GT</field><value name="A"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="variables_get" id="b(:C75mEnEJP|YjS3B[/"><field name="VAR" id="7#Z7_)5G9R.|E@!+HIwX">_byteWaiting</field></block></value><value name="B"><shadow type="math_number" id="DRS|CF}m$-yx[;|V=^gA"><field name="NUM">0</field></shadow></value></block></value><value name="B"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="logic_compare" id="jdNJ%7HG*5isNj|%kEB$"><field name="OP">LT</field><value name="A"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="variables_get" id="E?6C=2.YN;^d)#fF-pYr"><field name="VAR" id="7#Z7_)5G9R.|E@!+HIwX">_byteWaiting</field></block></value><value name="B"><shadow type="math_number" id="};z0~.PU51A}WB8rq.S3"><field name="NUM">127</field></shadow></value></block></value></block></value><statement name="DO"><block type="controls_if" id="lH,_GeR/A/S7myX?]0#2"><value name="IF0"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="logic_compare" id="OPUv4MMdWe9-tu[xI6u*"><field name="OP">EQ</field><value name="A"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="variables_get" id="QK7(.Ei7REouCXw5:Ow2"><field name="VAR" id="7#Z7_)5G9R.|E@!+HIwX">_byteWaiting</field></block></value><value name="B"><shadow type="math_number" id="pKbIOy=Nftcvv6c78PV_"><field name="NUM">126</field></shadow></value></block></value><statement name="DO0"><block type="variables_set" id="TB7)x6uQBz)}]~^cLD~)"><field name="VAR" id="7#Z7_)5G9R.|E@!+HIwX">_byteWaiting</field><value name="VALUE"><shadow type="math_number" id="dSTzh]ECe}2?aifLbp-3"><field name="NUM">0</field></shadow></value><next><block type="function_return" id="OXNE:@K,U%$i$B9R1*F@"><mutation xmlns="http://www.w3.org/1999/xhtml" no_return_value="false"></mutation><value name="RETURN_VALUE"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="variables_get" id="UF2bJX1L_I~:(b*)`iBS"><field name="VAR" id="mj5BQ2Q(,bs.i0O_[:oB">receivedString</field></block></value></block></next></block></statement><next><block type="typescript_statement" id="_nV%$82rNDlo!/O{j@6w" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="receivedString = receivedString.concat(String.fromCharCode(_byteWaiting));" numlines="1"></mutation><next><block type="typescript_statement" id="^5ZLh#{n_Z``,Xkwr,;=" editable="false"><mutation xmlns="http://www.w3.org/1999/xhtml" line0="_byteWaiting = serial.read();" numlines="1"></mutation></block></next></block></next></block></statement><next><block type="function_return" id="[CCCR3+;QAoT.4Z~RMWk"><mutation xmlns="http://www.w3.org/1999/xhtml" no_return_value="false"></mutation><comment pinned="false" h="80" w="160">return receivedString;</comment><value name="RETURN_VALUE"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="text" id=";iv@F@0.[2f@-pm3*fXP"><field name="TEXT">NA</field></block></value></block></next></block></statement></block><block type="function_definition" id="GYicl.J$CwDko4:MmLC)" x="3346" y="20"><mutation name="espRespondsWithinMilliseconds" functionid="R}W~AloF(1Oy6d/E%Lxm"><arg name="timeAllowed" id="ash9c2ilu2nkgco9lk0l" type="number"/></mutation><field name="function_name">espRespondsWithinMilliseconds</field><comment pinned="false" h="80" w="160">I think this call to built-in MakeCode event handler is obsolete serial.onDataReceived("~", function () { _8266MessageWaiting = true; })</comment><value name="ash9c2ilu2nkgco9lk0l"><shadow type="argument_reporter_number" id="F+y|ETvxdJK:?@opxJ$F"><field name="VALUE">timeAllowed</field></shadow></value><statement name="STACK"><block type="variables_set" id="rCP.2TQTNF=WB*8hBOlJ"><field name="VAR" id="4VJ6(KlU%c[3Hs(:Xe[o">functionStartTime</field><value name="VALUE"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="device_get_running_time" id="/|/vTf8n0Hnd9yWL9Fu="/></value><next><block type="device_while" id=".d+)IymSB[ENJSoV#O1z"><value name="COND"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="logic_compare" id="`2$c2FqfSowtrg00C^C#"><field name="OP">LT</field><value name="A"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="math_arithmetic" id="Na3XWy1WDwjx!DAW{|nz"><field name="OP">MINUS</field><value name="A"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="device_get_running_time" id="R?j[J=L-h}SlxcG^1fMT"/></value><value name="B"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="variables_get" id="kXhNHem0LS-HW*Dod}tm"><field name="VAR" id="4VJ6(KlU%c[3Hs(:Xe[o">functionStartTime</field></block></value></block></value><value name="B"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="argument_reporter_number" id="6tBnC5E-m1N3SW!.$yex"><field name="VALUE">timeAllowed</field></block></value></block></value><statement name="DO"><block type="controls_if" id="t-W30XDHemDY/VfUl%Jt"><value name="IF0"><shadow type="logic_boolean"><field name="BOOL">TRUE</field></shadow><block type="function_call_output" id="a`,k^Ex}E]wys(!+1uK6"><mutation name="serialMessageWaiting" functionid="GToj|5mVw;b$=WY!w~YW"/></block></value><statement name="DO0"><block type="function_return" id="-CI@dwpxxRN2ZttKF`z#"><mutation xmlns="http://www.w3.org/1999/xhtml" no_return_value="false"></mutation><value name="RETURN_VALUE"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="logic_boolean" id="20Fby83.,kt6TMJ,:7FB"><field name="BOOL">TRUE</field></block></value></block></statement><next><block type="device_pause" id="FsfnS+5^Y1ke+doARxPQ"><value name="pause"><shadow type="timePicker" id="g7zY;DtIy0rPy@jc{(iD"><field name="ms">1</field></shadow></value></block></next></block></statement><next><block type="function_return" id="U~!9wJsS;sRS,(IT0@wF"><mutation xmlns="http://www.w3.org/1999/xhtml" no_return_value="false"></mutation><value name="RETURN_VALUE"><shadow type="math_number"><field name="NUM">0</field></shadow><block type="logic_boolean" id="tui)R)g87{O[TI{G_ieW"><field name="BOOL">FALSE</field></block></value></block></next></block></next></block></statement></block></xml>