python_mpython.min.js 233 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709
  1. goog.provide('Blockly.Python.CocoRobo');
  2. goog.require('Blockly.Python');
  3. Blockly.BlockSvg.SEP_SPACE_X = 8;
  4. Array.prototype.indexOf = function(a) {
  5. for (var b = 0; b < this.length; b++)
  6. if (this[b] == a)
  7. return b;
  8. return -1
  9. };
  10. Array.prototype.remove = function(a) {
  11. a = this.indexOf(a); -
  12. 1 < a && this.splice(a, 1)
  13. };
  14. var writeUTF = function(a, b) {
  15. for (var c = [], d = 0, e = 0; e < a.length; e++) {
  16. var f = a.charCodeAt(e);
  17. if (0 <= f && 127 >= f)
  18. d += 1,
  19. c.push(f);
  20. else if (128 <= f && 2047 >= f)
  21. d += 2,
  22. c.push(192 | 31 & f >> 6),
  23. c.push(128 | 63 & f);
  24. else if (2048 <= f && 55295 >= f || 57344 <= f && 65535 >= f)
  25. d += 3,
  26. c.push(224 | 15 & f >> 12),
  27. c.push(128 | 63 & f >> 6),
  28. c.push(128 | 63 & f)
  29. }
  30. for (e = 0; e < c.length; e++)
  31. c[e] &= 255;
  32. return b ? c : 255 >= d ? [0, d].concat(c) : [d >> 8, d & 255].concat(c)
  33. },
  34. toUTF8Hex = function(a) {
  35. a = writeUTF(a, !0);
  36. for (var b = "", c = 0; c < a.length; c++) {
  37. var d = (a[c] & 255).toString(16);
  38. 1 === d.length && (d = "0" + d);
  39. b += d
  40. }
  41. return b
  42. };
  43. Blockly.Python.i2c_pin = function(a) {
  44. return ["" + a.getFieldValue("i2c_pin"), Blockly.Python.ORDER_ATOMIC]
  45. };
  46. Blockly.Python.uart_rx_pin = function(a) {
  47. return ["" + a.getFieldValue("uart_rx_pin"), Blockly.Python.ORDER_ATOMIC]
  48. };
  49. Blockly.Python.uart_tx_pin = function(a) {
  50. return ["" + a.getFieldValue("uart_tx_pin"), Blockly.Python.ORDER_ATOMIC]
  51. };
  52. Blockly.Python.dh11_hum_tem_pin = function(a) {
  53. return ["" + a.getFieldValue("dh11_hum_tem_pin"), Blockly.Python.ORDER_ATOMIC]
  54. };
  55. Blockly.Python.pwm_pin = function(a) {
  56. return ["" + a.getFieldValue("pwm_pin"), Blockly.Python.ORDER_ATOMIC]
  57. };
  58. Blockly.Python.all_pin = function(a) {
  59. return ["" + a.getFieldValue("all_pin"), Blockly.Python.ORDER_ATOMIC]
  60. };
  61. Blockly.Python.set_analog = function(a) {
  62. return ["" + a.getFieldValue("set_analog"), Blockly.Python.ORDER_ATOMIC]
  63. };
  64. Blockly.Python.set_digital = function(a) {
  65. return ["" + a.getFieldValue("set_digital"), Blockly.Python.ORDER_ATOMIC]
  66. };
  67. Blockly.Python.read_analog_pin = function(a) {
  68. return ["" + a.getFieldValue("read_analog_pin"), Blockly.Python.ORDER_ATOMIC]
  69. };
  70. Blockly.Python.input_pin = function(a) {
  71. return ["" + a.getFieldValue("input_pin"), Blockly.Python.ORDER_ATOMIC]
  72. };
  73. Blockly.Python.output_pin = function(a) {
  74. return ["" + a.getFieldValue("output_pin"), Blockly.Python.ORDER_ATOMIC]
  75. };
  76. Blockly.Python.china_city = function(a) {
  77. var b = a.getFieldValue("province");
  78. a = a.getFieldValue("city");
  79. return ['"' + CITYS_DATA[b][a].pinyin + '"', Blockly.Python.ORDER_ATOMIC]
  80. };
  81. Blockly.Python.china_city_town = function(a) {
  82. var b = a.getFieldValue("province"),
  83. c = a.getFieldValue("city"),
  84. d = a.getFieldValue("town");
  85. a = a.getFieldValue("type");
  86. return ['"' + getCityInfo(b, c, d, a) + '"', Blockly.Python.ORDER_ATOMIC]
  87. };
  88. Blockly.Python.math_on_list = function(a) {
  89. var b = a.getFieldValue("OP");
  90. a = Blockly.Python.valueToCode(a, "LIST", Blockly.Python.ORDER_NONE) || "[]";
  91. switch (b) {
  92. case "SUM":
  93. b = "sum(" + a + ")";
  94. break;
  95. case "MIN":
  96. b = "min(" + a + ")";
  97. break;
  98. case "MAX":
  99. b = "max(" + a + ")";
  100. break;
  101. case "AVERAGE":
  102. b = Blockly.Python.provideFunction_("math_mean", ["def " + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + "(myList):", " return float(sum(myList)) / len(myList)"]);
  103. b = b + "(" + a + ")";
  104. break;
  105. case "MEDIAN":
  106. b = Blockly.Python.provideFunction_("math_median", ["def " + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + "(myList):", " localList \x3d sorted(myList)", " if not localList: return", " if len(localList) % 2 \x3d\x3d 0:", " return (localList[len(localList) // 2 - 1] + localList[len(localList) // 2]) / 2.0", " else:", " return localList[(len(localList) - 1) // 2]"]);
  107. b = b + "(" + a + ")";
  108. break;
  109. case "MODE":
  110. b = Blockly.Python.provideFunction_("math_modes", ["def " + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + "(some_list):", " modes \x3d []", " # Using a lists of [item, count] to keep count rather than dict", ' # to avoid "unhashable" errors when the counted item is itself a list or dict.', " counts \x3d []", " maxCount \x3d 1", " for item in some_list:", " found \x3d False", " for count in counts:", " if count[0] \x3d\x3d item:", " count[1] +\x3d 1", " maxCount \x3d max(maxCount, count[1])", " found \x3d True", " if not found:", " counts.append([item, 1])", " for counted_item, item_count in counts:", " if item_count \x3d\x3d maxCount:", " modes.append(counted_item)", " return modes"]);
  111. b = b + "(" + a + ")";
  112. break;
  113. case "STD_DEV":
  114. Blockly.Python.definitions_.import_math = "import math";
  115. b = Blockly.Python.provideFunction_("math_standard_deviation", ["def " + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + "(numbers):", " n \x3d len(numbers)", " if n \x3d\x3d 0: return", " mean \x3d float(sum(numbers)) / n", " variance \x3d sum((x - mean) ** 2 for x in numbers) / n", " return math.sqrt(variance)"]);
  116. b = b + "(" + a + ")";
  117. break;
  118. case "RANDOM":
  119. Blockly.Python.definitions_.import_random = "import random";
  120. b = "random.choice(" + a + ")";
  121. break;
  122. default:
  123. throw "Unknown operator: " + b;
  124. }
  125. return [b, Blockly.Python.ORDER_FUNCTION_CALL]
  126. };
  127. Blockly.Python.int_to_chr = function(a) {
  128. return ["str(" + Blockly.Python.valueToCode(a, "_int", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
  129. };
  130. Blockly.Python.CocoRobo_hcsr04_obj = function(a) {
  131. Blockly.Python.definitions_.from_hcsr04_import_HCSR04 = "from hcsr04 import HCSR04";
  132. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  133. var b = a.getFieldValue("hcsr04_name"),
  134. c = Blockly.Python.valueToCode(a, "trigger", Blockly.Python.ORDER_ATOMIC);
  135. a = Blockly.Python.valueToCode(a, "echo", Blockly.Python.ORDER_ATOMIC);
  136. Blockly.Python.definitions_["CocoRobo_hcsr04_object" + b] = b + " \x3d HCSR04(trigger_pin\x3dPin.P" + c + ", echo_pin\x3dPin.P" + a + ")";
  137. return "\n"
  138. };
  139. Blockly.Python.CocoRobo_hcsr04_distance = function(a) {
  140. Blockly.Python.definitions_.from_hcsr04_import_HCSR04 = "from hcsr04 import HCSR04";
  141. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  142. var b = a.getFieldValue("hcsr04_name");
  143. a = a.getFieldValue("unit");
  144. return [b + ".distance_" + a + "()", Blockly.Python.ORDER_ATOMIC]
  145. };
  146. Blockly.Python.CocoRobo_hcsr04_distance_mm = function(a) {
  147. Blockly.Python.definitions_.from_hcsr04_import_HCSR04 = "from hcsr04 import HCSR04";
  148. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  149. return [a.getFieldValue("hcsr04_name") + ".distance_mm()", Blockly.Python.ORDER_ATOMIC]
  150. };
  151. Blockly.Python.CocoRobo_pm2_5_MIC = function (a) {
  152. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  153. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  154. var b = Blockly.Python.valueToCode(a, "rx", Blockly.Python.ORDER_ATOMIC);
  155. Blockly.Python.codeFunctions_.CocoRobo_pm2_5 = "uart\x3dUART(1, baudrate\x3d9600, rx\x3dPin.P" + b + ", timeout\x3d200)\n_pm_data \x3d [None, None, None, None, None, None, None, None, None]\ndef timer13_tick(_):\n global _pm_data\n try:\n if uart.any():\n d \x3d uart.read(0x42)\n if d[0] \x3d\x3d 0x42 and d[1] \x3d\x3d 0x4d:\n _pm_data \x3d [d[5], d[7], d[9], d[17], d[19], d[21], d[23], d[25], d[27]]\n except: pass\n\ntim13 \x3d Timer(13)\ntim13.init(period\x3d1000, mode\x3dTimer.PERIODIC, callback\x3dtimer13_tick)";
  156. return [a.getFieldValue("unit"), Blockly.Python.ORDER_ATOMIC]
  157. };
  158. Blockly.Python.CocoRobo_pm2_5_LitresAir = function (a) {
  159. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  160. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  161. var b = Blockly.Python.valueToCode(a, "rx", Blockly.Python.ORDER_ATOMIC);
  162. Blockly.Python.codeFunctions_.CocoRobo_pm2_5 = "uart\x3dUART(1, baudrate\x3d9600, rx\x3dPin.P" + b + ", timeout\x3d200)\n_pm_data \x3d [None, None, None, None, None, None, None, None, None]\ndef timer13_tick(_):\n global _pm_data\n try:\n if uart.any():\n d \x3d uart.read(0x42)\n if d[0] \x3d\x3d 0x42 and d[1] \x3d\x3d 0x4d:\n _pm_data \x3d [d[5], d[7], d[9], d[17], d[19], d[21], d[23], d[25], d[27]]\n except: pass\n\ntim13 \x3d Timer(13)\ntim13.init(period\x3d1000, mode\x3dTimer.PERIODIC, callback\x3dtimer13_tick)";
  163. return [a.getFieldValue("unit"), Blockly.Python.ORDER_ATOMIC]
  164. };
  165. Blockly.Python.CocoRobo_mac_address = function(a) {
  166. Blockly.Python.definitions_.import_machine = "import machine";
  167. Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
  168. return ["ubinascii.hexlify(machine.unique_id()).decode().upper()", Blockly.Python.ORDER_ATOMIC]
  169. };
  170. Blockly.Python.CocoRobo_ujson_loads = function(a) {
  171. Blockly.Python.definitions_.import_ujson = "import json";
  172. return ["json.loads(" + Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
  173. };
  174. Blockly.Python.CocoRobo_code_annotation = function(a) {
  175. var code = Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC);
  176. return "# " + code.replace('"','').replace('"','') + "\n";
  177. };
  178. Blockly.Python.CocoRobo_ujson_dumps = function(a) {
  179. Blockly.Python.definitions_.import_ujson = "import json";
  180. return ["json.dumps(" + Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
  181. };
  182. Blockly.Python.CocoRobo_base64_to_data = function(a) {
  183. Blockly.Python.definitions_.v831_import_base64 = "import base64";
  184. return ["base64.b64decode(" + Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
  185. };
  186. Blockly.Python.CocoRobo_data_to_base64 = function(a) {
  187. Blockly.Python.definitions_.v831_import_base64 = "import base64";
  188. return ["base64.b64encode("+Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC) + ".encode('utf-8'))", Blockly.Python.ORDER_ATOMIC]
  189. };
  190. Blockly.Python.CocoRobo_hex_to_bin_str = function(a) {
  191. return ["bytes.fromhex(" + Blockly.Python.valueToCode(a, "convert_chr", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
  192. };
  193. Blockly.Python.CocoRobo_str_to_hex = function(a) {
  194. return [Blockly.Python.valueToCode(a, "convert_chr", Blockly.Python.ORDER_ATOMIC)+".encode().hex()", Blockly.Python.ORDER_ATOMIC]
  195. };
  196. Blockly.Python.CocoRobo_chr_to_int = function(a) {
  197. return ["ord(" + Blockly.Python.valueToCode(a, "convert_chr", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
  198. };
  199. Blockly.Python.CocoRobo_int_to_chr = function(a) {
  200. return ["chr(" + Blockly.Python.valueToCode(a, "convert_num", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
  201. };
  202. Blockly.Python.CocoRobo_ten_converted_to_bytes = function(a) {
  203. Blockly.Python.definitions_.import_struct = "import struct";
  204. var b = Blockly.Python.valueToCode(a, "convert_num", Blockly.Python.ORDER_ATOMIC);
  205. return ["struct.pack(" + a.getFieldValue("convert_choice") + ", " + b + ")", Blockly.Python.ORDER_ATOMIC]
  206. };
  207. Blockly.Python.CocoRobo_convert_to_ten = function(a) {
  208. var b = Blockly.Python.valueToCode(a, "convert_str", Blockly.Python.ORDER_ATOMIC);
  209. a = a.getFieldValue("convert_choice");
  210. return ["int(" + b + ", " + a + ")", Blockly.Python.ORDER_ATOMIC]
  211. };
  212. Blockly.Python.CocoRobo_ten_convert_to = function(a) {
  213. var b = Blockly.Python.valueToCode(a, "int_num", Blockly.Python.ORDER_ATOMIC);
  214. return [a.getFieldValue("ten_convert_to") + "(" + b + ")", Blockly.Python.ORDER_ATOMIC]
  215. };
  216. Blockly.Python.CocoRobo_high_low = function(a) {
  217. return [a.getFieldValue("high_low"), Blockly.Python.ORDER_ATOMIC]
  218. };
  219. Blockly.Python.CocoRobo_baudrate = function(a) {
  220. return [a.getFieldValue("baudrate"), Blockly.Python.ORDER_ATOMIC]
  221. };
  222. Blockly.Python.CocoRobo_start_new_thread = function(a) {
  223. Blockly.Python.definitions_.import_thread = "import _thread";
  224. var b = a.getFieldValue("thread_name"),
  225. c = Blockly.Python.statementToCode(a, "DO"),
  226. c = Blockly.Python.addLoopTrap(c, a.id) || Blockly.Python.PASS;
  227. Blockly.Python.codeFunctions_["thread_" + b] = "def thread_" + b + "():\n" + c;
  228. return "_thread.start_new_thread(thread_" + b + ", ())\n"
  229. };
  230. Blockly.Python.text_is_number = function(a) {
  231. var b = Blockly.Python.valueToCode(a, "TEXT", Blockly.Python.ORDER_ATOMIC);
  232. a = a.getFieldValue("TYPE");
  233. return [b + a, Blockly.Python.ORDER_ATOMIC]
  234. };
  235. Blockly.Python.CocoRobo_lock_object_acquire_lock = function(a) {
  236. Blockly.Python.definitions_.import_thread = "import _thread";
  237. a = a.getFieldValue("thread_lock_object");
  238. Blockly.Python.definitions_.def_thread_lock_object = a + " \x3d _thread.allocate_lock()";
  239. return a + ".acquire()\n"
  240. };
  241. Blockly.Python.text_format = function(a) {
  242. var b = Blockly.Python.valueToCode(a, "FORMAT", Blockly.Python.ORDER_ATOMIC);
  243. a = Blockly.Python.valueToCode(a, "CONTENT", Blockly.Python.ORDER_ATOMIC);
  244. return [b + " % " + a, Blockly.Python.ORDER_ATOMIC]
  245. };
  246. Blockly.Python.text_format2 = function(a) {
  247. var b = Blockly.Python.valueToCode(a, "FORMAT", Blockly.Python.ORDER_ATOMIC);
  248. a = Blockly.Python.valueToCode(a, "CONTENT", Blockly.Python.ORDER_ATOMIC);
  249. return [b + ".format" + a, Blockly.Python.ORDER_ATOMIC]
  250. };
  251. Blockly.Python.CocoRobo_bytes_decode = function(a) {
  252. return [Blockly.Python.valueToCode(a, "bytes_decode", Blockly.Python.ORDER_ATOMIC) + ".decode('UTF-8','ignore')", Blockly.Python.ORDER_ATOMIC]
  253. };
  254. Blockly.Python.text_to_byte = function(a) {
  255. return ["bytes(" + Blockly.Python.valueToCode(a, "TEXT", Blockly.Python.ORDER_ATOMIC) + ", 'utf-8')", Blockly.Python.ORDER_ATOMIC]
  256. };
  257. Blockly.Python.other_to_byte = function(a) {
  258. return ["bytes(" + Blockly.Python.valueToCode(a, "input_var", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
  259. };
  260. Blockly.Python.bit_inversion = function(a) {
  261. return ["~" + Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC), Blockly.Python.ORDER_ATOMIC]
  262. };
  263. Blockly.Python.CocoRobo_try_except = function(a) {
  264. var b = Blockly.Python.statementToCode(a, "TRY") || Blockly.Python.PASS;
  265. a = Blockly.Python.statementToCode(a, "EXCEPT") || Blockly.Python.PASS;
  266. return "try:\n" + b + "except:\n" + a
  267. };
  268. Blockly.Python.CocoRobo_try_except_finally = function(a) {
  269. var b = Blockly.Python.statementToCode(a, "TRY") || Blockly.Python.PASS,
  270. c = Blockly.Python.statementToCode(a, "EXCEPT") || Blockly.Python.PASS;
  271. a = Blockly.Python.statementToCode(a, "FINALLY") || Blockly.Python.PASS;
  272. return "try:\n" + b + "except:\n" + c + "finally:\n" + a
  273. };
  274. Blockly.Python.text_append_text = function(a) {
  275. var b = Blockly.Python.valueToCode(a, "text_abc", Blockly.Python.ORDER_ATOMIC);
  276. a = Blockly.Python.valueToCode(a, "append_text", Blockly.Python.ORDER_ATOMIC);
  277. return ["str(" + b + ") + str(" + a + ")", Blockly.Python.ORDER_ATOMIC]
  278. };
  279. Blockly.Python.CocoRobo_custom_code = function(a) {
  280. var b = a.getFieldValue("custom_type");
  281. a = a.getFieldValue("custom_code");
  282. return "topping" == b ? (Blockly.Python.definitions_.import_custom = a,
  283. "") : a + "\n"
  284. };
  285. Blockly.Python.CocoRobo_machine_reset = function (a) {
  286. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  287. Blockly.Python.definitions_.import_machine = "import machine";
  288. return "machine.reset()\n"
  289. };
  290. Blockly.Python.math_random_randrange = function(a) {
  291. Blockly.Python.definitions_.import_time = "import time";
  292. // Blockly.Python.codeFunctions_.random_seed = "random.seed(time.ticks_cpu())";
  293. Blockly.Python.definitions_.import_random = "import random";
  294. var b = Blockly.Python.valueToCode(a, "start", Blockly.Python.ORDER_ATOMIC),
  295. c = Blockly.Python.valueToCode(a, "stop", Blockly.Python.ORDER_ATOMIC);
  296. a = Blockly.Python.valueToCode(a, "step", Blockly.Python.ORDER_ATOMIC);
  297. return ["random.randrange(" + b + ", " + c + ", " + a + ")", Blockly.Python.ORDER_ATOMIC]
  298. };
  299. Blockly.Python.math_angle = function(a) {
  300. return [a.getFieldValue("angle"), Blockly.Python.ORDER_ATOMIC]
  301. };
  302. Blockly.Python.math_keep_decimal = function(a) {
  303. var b = Blockly.Python.valueToCode(a, "NUM", Blockly.Python.ORDER_ATOMIC);
  304. a = Blockly.Python.valueToCode(a, "PLACE", Blockly.Python.ORDER_ATOMIC);
  305. return ["round(" + b + ", " + a + ")", Blockly.Python.ORDER_ATOMIC]
  306. };
  307. Blockly.Python.labplus_mapping = function(a) {
  308. Blockly.Python.definitions_.import_CocoRobo_mapping = "" +
  309. "def numberMap(value, leftMin, leftMax, rightMin, rightMax):\n" +
  310. " leftSpan = leftMax - leftMin\n" +
  311. " rightSpan = rightMax - rightMin\n" +
  312. " valueScaled = float(value - leftMin) / float(leftSpan)\n" +
  313. " return rightMin + (valueScaled * rightSpan)\n" +
  314. "";
  315. var b = Blockly.Python.valueToCode(a, "inputNum", Blockly.Python.ORDER_ATOMIC);
  316. Blockly.Python.valueToCode(a, "outputNum", Blockly.Python.ORDER_ATOMIC);
  317. var c = Blockly.Python.valueToCode(a, "bMin", Blockly.Python.ORDER_ATOMIC),
  318. d = Blockly.Python.valueToCode(a, "bMax", Blockly.Python.ORDER_ATOMIC),
  319. e = Blockly.Python.valueToCode(a, "cMin", Blockly.Python.ORDER_ATOMIC);
  320. a = Blockly.Python.valueToCode(a, "cMax", Blockly.Python.ORDER_ATOMIC);
  321. return ["numberMap(" + b + "," + c + "," + d + "," + e + "," + a + ")", Blockly.Python.ORDER_ATOMIC]
  322. };
  323. Blockly.Python.CocoRobo_Timer = function(a) {
  324. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  325. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  326. b = b.length ? " global " + b.join(", ") + "\n" : "";
  327. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  328. var c = Blockly.Python.valueToCode(a, "Num", Blockly.Python.ORDER_ATOMIC),
  329. d = Blockly.Python.valueToCode(a, "period", Blockly.Python.ORDER_ATOMIC),
  330. e = a.getFieldValue("Timer_mode"),
  331. f = Blockly.Python.statementToCode(a, "DO"),
  332. f = Blockly.Python.addLoopTrap(f, a.id) || Blockly.Python.PASS;
  333. Blockly.Python.definitions_["timer" + c + "_tick"] = "def timer" + c + "_tick(_):\n" + b + f;
  334. Blockly.Python.definitions_["def_Timer" + c] = "tim" + c + " \x3d Timer(" + c + ")";
  335. return "tim" + c + ".init(period\x3d" + d + ", mode\x3dTimer." + e + ", callback\x3dtimer" + c + "_tick)\n"
  336. };
  337. Blockly.Python.CocoRobo_timer_option = function(a) {
  338. return [a.getFieldValue("Timer_num"), Blockly.Python.ORDER_ATOMIC]
  339. };
  340. Blockly.Python.CocoRobo_event_option = Blockly.Python.CocoRobo_timer_option;
  341. Blockly.Python.CocoRobo_Timer_value = function(a) {
  342. return ["tim" + Blockly.Python.valueToCode(a, "Timer_num", Blockly.Python.ORDER_ATOMIC) + ".value()", Blockly.Python.ORDER_ATOMIC]
  343. };
  344. Blockly.Python.CocoRobo_Timer_deinit = function(a) {
  345. return "tim" + Blockly.Python.valueToCode(a, "Timer_num", Blockly.Python.ORDER_ATOMIC) + ".deinit()\n"
  346. };
  347. Blockly.Python.CocoRobo_Interrupt_pin = function(a) {
  348. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  349. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  350. b = b.length ? " global " + b.join(", ") + "\n" : "";
  351. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  352. var c = Blockly.Python.valueToCode(a, "Interrupt_pin", Blockly.Python.ORDER_ATOMIC),
  353. d = a.getFieldValue("action"),
  354. e = Blockly.Python.statementToCode(a, "DO"),
  355. e = Blockly.Python.addLoopTrap(e, a.id) || Blockly.Python.PASS;
  356. Blockly.Python.definitions_["PinMode_IN" + c] = "p" + c + " \x3d CocoRoboPin(" + c + ", PinMode.IN)";
  357. Blockly.Python.definitions_["on_pin" + c] = "def on_pin" + c + "(_):\n if 0 \x3d\x3d _.value():\n on_pin" + c + "_to_low(_)\n else:\n on_pin" + c + "_to_high(_)";
  358. Blockly.Python.definitions_["on_pin" + c + "_" + d] = "def on_pin" + c + "_" + d + "(_):\n" + b + e;
  359. Blockly.Python.codeFunctions_["Interrupt_pin" + c] = "p" + c + ".irq(trigger\x3dPin." + ("to_high" == d ? "IRQ_RISING" : "IRQ_FALLING") + ", handler\x3don_pin" + c + "_" + d + ")";
  360. "to_high" == d ? Blockly.Python.definitions_["on_pin" + c + "_to_low"] ? Blockly.Python.codeFunctions_["Interrupt_pin" + c] = "p" + c + ".irq(trigger\x3d(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler\x3don_pin" + c + ")" : Blockly.Python.definitions_["on_pin" + c] = "" : Blockly.Python.definitions_["on_pin" + c + "_to_high"] ? Blockly.Python.codeFunctions_["Interrupt_pin" + c] = "p" + c + ".irq(trigger\x3d(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler\x3don_pin" + c + ")" : Blockly.Python.definitions_["on_pin" + c] = "";
  361. return ""
  362. };
  363. Blockly.Python.CocoRobo_Interrupt_AB = function(a) {
  364. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  365. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  366. b = b.length ? " global " + b.join(", ") + "\n" : "";
  367. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  368. Blockly.Python.definitions_.import_time = "import time";
  369. var c = a.getFieldValue("button"),
  370. d = a.getFieldValue("action"),
  371. e = Blockly.Python.statementToCode(a, "DO"),
  372. e = Blockly.Python.addLoopTrap(e, a.id) || Blockly.Python.PASS;
  373. Blockly.Python.definitions_["on_" + c] = "def on_" + c + "(_):\n if 0 \x3d\x3d _.value():\n on_" + c + "_down(_)\n else:\n on_" + c + "_up(_)";
  374. Blockly.Python.definitions_["on_" + c + "_" + d] = "def on_" + c + "_" + d + "(_):\n" + b + (" time.sleep_ms(10)\n if " + c + ".value() \x3d\x3d " + ("down" == d ? "1" : "0") + ": return\n") + e;
  375. Blockly.Python.codeFunctions_["Interrupt_" + c] = c + ".irq(trigger\x3dPin." + ("down" == d ? "IRQ_FALLING" : "IRQ_RISING") + ", handler\x3don_" + c + "_" + d + ")";
  376. "down" == d ? Blockly.Python.definitions_["on_" + c + "_up"] ? Blockly.Python.codeFunctions_["Interrupt_" + c] = c + ".irq(trigger\x3d(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler\x3don_" + c + ")" : Blockly.Python.definitions_["on_" + c] = "" : Blockly.Python.definitions_["on_" + c + "_down"] ? Blockly.Python.codeFunctions_["Interrupt_" + c] = c + ".irq(trigger\x3d(Pin.IRQ_FALLING | Pin.IRQ_RISING), handler\x3don_" + c + ")" : Blockly.Python.definitions_["on_" + c] = "";
  377. return ""
  378. };
  379. Blockly.Python.CocoRobo_is_tilted = function (a) {
  380. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  381. switch (a.getFieldValue("direction")) {
  382. case "forward":
  383. return ["accelerometer.get_x() \x3c -0.3", Blockly.Python.ORDER_ATOMIC];
  384. case "back":
  385. return ["accelerometer.get_x() \x3e 0.3", Blockly.Python.ORDER_ATOMIC];
  386. case "right":
  387. return ["accelerometer.get_y() \x3c -0.3", Blockly.Python.ORDER_ATOMIC];
  388. case "left":
  389. return ["accelerometer.get_y() \x3e 0.3", Blockly.Python.ORDER_ATOMIC];
  390. default:
  391. return ""
  392. }
  393. };
  394. Blockly.Python.CocoRobo_tilt_detector = function(a) {
  395. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  396. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  397. b = b.length ? " global " + b.join(", ") + "\n" : "";
  398. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  399. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  400. var c = a.getFieldValue("direction"),
  401. d = Blockly.Python.statementToCode(a, "DO"),
  402. d = Blockly.Python.addLoopTrap(d, a.id) || Blockly.Python.PASS;
  403. Blockly.Python.definitions_.def_dir = "_dir \x3d ''\ndef on_tilt_forward():pass\ndef on_tilt_back():pass\ndef on_tilt_right():pass\ndef on_tilt_left():pass\ndef on_tilt_none():pass\n";
  404. Blockly.Python.definitions_.def_Timer14 = "tim14 \x3d Timer(14)";
  405. Blockly.Python.definitions_.timer14_tick = "def timer14_tick(_):\n global _dir\n if accelerometer.get_x() \x3c -0.3:\n if 'F' !\x3d _dir:_dir \x3d 'F';on_tilt_forward()\n elif accelerometer.get_x() \x3e 0.3:\n if 'B' !\x3d _dir:_dir \x3d 'B';on_tilt_back()\n elif accelerometer.get_y() \x3c -0.3:\n if 'R' !\x3d _dir:_dir \x3d 'R';on_tilt_right()\n elif accelerometer.get_y() \x3e 0.3:\n if 'L' !\x3d _dir:_dir \x3d 'L';on_tilt_left()\n else:\n if '' !\x3d _dir:_dir \x3d '';on_tilt_none()\n";
  406. Blockly.Python.definitions_.timer14_init = "tim14.init(period\x3d200, mode\x3dTimer.PERIODIC, callback\x3dtimer14_tick)\n";
  407. Blockly.Python.definitions_["on_tilt_" + c] = "def on_tilt_" + c + "():\n" + b + d;
  408. return ""
  409. };
  410. Blockly.Python.CocoRobo_is_shaked = function(a) {
  411. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  412. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  413. b.length && b.join(", ");
  414. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  415. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  416. Blockly.Python.definitions_.def_shake_variable = "_is_shaked \x3d _is_thrown \x3d False\n_last_x \x3d _last_y \x3d _last_z \x3d _count_shaked \x3d _count_thrown \x3d 0\ndef on_shaked():pass\ndef on_thrown():pass\n";
  417. Blockly.Python.definitions_.def_Timer11 = "tim11 \x3d Timer(11)";
  418. Blockly.Python.definitions_.timer11_tick = "def timer11_tick(_):\n global _is_shaked, _is_thrown, _last_x, _last_y, _last_z, _count_shaked, _count_thrown\n if _is_shaked:\n _count_shaked +\x3d 1\n if _count_shaked \x3d\x3d 5: _count_shaked \x3d 0\n if _is_thrown:\n _count_thrown +\x3d 1\n if _count_thrown \x3d\x3d 10: _count_thrown \x3d 0\n if _count_thrown \x3e 0: return\n x\x3daccelerometer.get_x(); y\x3daccelerometer.get_y(); z\x3daccelerometer.get_z()\n _is_thrown \x3d (x * x + y * y + z * z \x3c 0.25)\n if _is_thrown: on_thrown();return\n if _last_x \x3d\x3d 0 and _last_y \x3d\x3d 0 and _last_z \x3d\x3d 0:\n _last_x \x3d x; _last_y \x3d y; _last_z \x3d z; return\n diff_x \x3d x - _last_x; diff_y \x3d y - _last_y; diff_z \x3d z - _last_z\n _last_x \x3d x; _last_y \x3d y; _last_z \x3d z\n if _count_shaked \x3e 0: return\n _is_shaked \x3d (diff_x * diff_x + diff_y * diff_y + diff_z * diff_z \x3e 1)\n if _is_shaked: on_shaked()\n";
  419. Blockly.Python.definitions_.timer11_init = "tim11.init(period\x3d100, mode\x3dTimer.PERIODIC, callback\x3dtimer11_tick)\n";
  420. return "thrown" == a.getFieldValue("action") ? ["_is_thrown", Blockly.Python.ORDER_ATOMIC] : ["_is_shaked", Blockly.Python.ORDER_ATOMIC]
  421. };
  422. Blockly.Python.CocoRobo_shake_detector = function(a) {
  423. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  424. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  425. b = b.length ? " global " + b.join(", ") + "\n" : "";
  426. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  427. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  428. c = Blockly.Python.statementToCode(a, "DO");
  429. c = Blockly.Python.addLoopTrap(c, a.id) || Blockly.Python.PASS;
  430. Blockly.Python.definitions_.def_shake_variable = "_is_shaked \x3d _is_thrown \x3d False\n_last_x \x3d _last_y \x3d _last_z \x3d _count_shaked \x3d _count_thrown \x3d 0\ndef on_shaked():pass\ndef on_thrown():pass\n";
  431. Blockly.Python.definitions_.def_Timer11 = "tim11 \x3d Timer(11)";
  432. Blockly.Python.definitions_.timer11_tick = "def timer11_tick(_):\n global _is_shaked, _is_thrown, _last_x, _last_y, _last_z, _count_shaked, _count_thrown\n if _is_shaked:\n _count_shaked +\x3d 1\n if _count_shaked \x3d\x3d 5: _count_shaked \x3d 0\n if _is_thrown:\n _count_thrown +\x3d 1\n if _count_thrown \x3d\x3d 10: _count_thrown \x3d 0\n if _count_thrown \x3e 0: return\n x\x3daccelerometer.get_x(); y\x3daccelerometer.get_y(); z\x3daccelerometer.get_z()\n _is_thrown \x3d (x * x + y * y + z * z \x3c 0.25)\n if _is_thrown: on_thrown();return\n if _last_x \x3d\x3d 0 and _last_y \x3d\x3d 0 and _last_z \x3d\x3d 0:\n _last_x \x3d x; _last_y \x3d y; _last_z \x3d z; return\n diff_x \x3d x - _last_x; diff_y \x3d y - _last_y; diff_z \x3d z - _last_z\n _last_x \x3d x; _last_y \x3d y; _last_z \x3d z\n if _count_shaked \x3e 0: return\n _is_shaked \x3d (diff_x * diff_x + diff_y * diff_y + diff_z * diff_z \x3e 1)\n if _is_shaked: on_shaked()\n";
  433. Blockly.Python.definitions_.timer11_init = "tim11.init(period\x3d100, mode\x3dTimer.PERIODIC, callback\x3dtimer11_tick)\n";
  434. "thrown" == a.getFieldValue("action") ? Blockly.Python.definitions_.on_thrown_event = "def on_thrown():\n" + b + c : Blockly.Python.definitions_.on_shaked_event = "def on_shaked():\n" + b + c;
  435. return ""
  436. };
  437. Blockly.Python.CocoRobo_touch_event = function(a) {
  438. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  439. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  440. b = b.length ? " global " + b.join(", ") + "\n" : "";
  441. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  442. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  443. var c = a.getFieldValue("touchPad"),
  444. d = a.getFieldValue("action"),
  445. e = Blockly.Python.statementToCode(a, "DO"),
  446. e = Blockly.Python.addLoopTrap(e, a.id) || Blockly.Python.PASS;
  447. Blockly.Python.definitions_.def_touch_status = "_status_p \x3d _status_y \x3d _status_t \x3d _status_h \x3d _status_o \x3d _status_n \x3d 0\ndef on_touchpad_P_pressed():pass\ndef on_touchpad_P_unpressed():pass\ndef on_touchpad_Y_pressed():pass\ndef on_touchpad_Y_unpressed():pass\ndef on_touchpad_T_pressed():pass\ndef on_touchpad_T_unpressed():pass\ndef on_touchpad_H_pressed():pass\ndef on_touchpad_H_unpressed():pass\ndef on_touchpad_O_pressed():pass\ndef on_touchpad_O_unpressed():pass\ndef on_touchpad_N_pressed():pass\ndef on_touchpad_N_unpressed():pass";
  448. Blockly.Python.definitions_.def_Timer12 = "tim12 \x3d Timer(12)";
  449. Blockly.Python.definitions_.timer12_tick = "def timer12_tick(_):\n global _status_p, _status_y, _status_t, _status_h, _status_o, _status_n\n try:\n touchPad_P.read();pass\n except:\n return\n if touchPad_P.read() \x3c 400:\n if 1 !\x3d _status_p:_status_p \x3d 1;on_touchpad_P_pressed()\n elif 0 !\x3d _status_p:_status_p \x3d 0;on_touchpad_P_unpressed()\n if touchPad_Y.read() \x3c 400:\n if 1 !\x3d _status_y:_status_y \x3d 1;on_touchpad_Y_pressed()\n elif 0 !\x3d _status_y:_status_y \x3d 0;on_touchpad_Y_unpressed()\n if touchPad_T.read() \x3c 400:\n if 1 !\x3d _status_t:_status_t \x3d 1;on_touchpad_T_pressed()\n elif 0 !\x3d _status_t:_status_t \x3d 0;on_touchpad_T_unpressed()\n if touchPad_H.read() \x3c 400:\n if 1 !\x3d _status_h:_status_h \x3d 1;on_touchpad_H_pressed()\n elif 0 !\x3d _status_h:_status_h \x3d 0;on_touchpad_H_unpressed()\n if touchPad_O.read() \x3c 400:\n if 1 !\x3d _status_o:_status_o \x3d 1;on_touchpad_O_pressed()\n elif 0 !\x3d _status_o:_status_o \x3d 0;on_touchpad_O_unpressed()\n if touchPad_N.read() \x3c 400:\n if 1 !\x3d _status_n:_status_n \x3d 1;on_touchpad_N_pressed()\n elif 0 !\x3d _status_n:_status_n \x3d 0;on_touchpad_N_unpressed()";
  450. Blockly.Python.definitions_.timer12_init = "tim12.init(period\x3d100, mode\x3dTimer.PERIODIC, callback\x3dtimer12_tick)\n";
  451. Blockly.Python.definitions_["on_touchpad_" + c + "_" + d] = "def on_touchpad_" + c + "_" + d + "():\n" + b + e;
  452. return ""
  453. };
  454. Blockly.Python.CocoRobo_custom_event = function(a) {
  455. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  456. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  457. b = b.length ? " global " + b.join(", ") + "\n" : "";
  458. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  459. var d = Blockly.Python.statementToCode(a, "DO"),
  460. d = Blockly.Python.addLoopTrap(d, a.id) || Blockly.Python.PASS,
  461. c = Blockly.Python.valueToCode(a, "index", Blockly.Python.ORDER_ATOMIC);
  462. Blockly.Python.definitions_["def_event_" + c] = "_event_changed_" + c + " \x3d False";
  463. a = Blockly.Python.valueToCode(a, "condition", Blockly.Python.ORDER_ATOMIC);
  464. Blockly.Python.definitions_["def_Timer" + c] = "tim" + c + " \x3d Timer(" + c + ")";
  465. Blockly.Python.definitions_["timer" + c + "_tick"] = "def timer" + c + "_tick(_):\n global _event_changed_" + c + "\n if " + a + ":\n if not _event_changed_" + c + ": _event_changed_" + c + " \x3d True; on_custom_event_" + c + "()\n else: _event_changed_" + c + " \x3d False";
  466. Blockly.Python.definitions_["on_custom_event_" + c] = "def on_custom_event_" + c + "():\n" + b + d;
  467. return "tim" + c + ".init(period\x3d100, mode\x3dTimer.PERIODIC, callback\x3dtimer" + c + "_tick)\n"
  468. };
  469. Blockly.Python.CocoRobo_music_range_pitch = function(a) {
  470. Blockly.Python.definitions_.import_music = "import music";
  471. var b = Blockly.Python.valueToCode(a, "start", Blockly.Python.ORDER_ATOMIC),
  472. c = Blockly.Python.valueToCode(a, "end", Blockly.Python.ORDER_ATOMIC),
  473. d = Blockly.Python.valueToCode(a, "step", Blockly.Python.ORDER_ATOMIC),
  474. e = Blockly.Python.valueToCode(a, "time", Blockly.Python.ORDER_ATOMIC);
  475. a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
  476. return "6" == a ? "for freq in range(" + b + ", " + c + ", " + d + "):\n music.pitch(freq, " + e + ")\n" : "for freq in range(" + b + ", " + c + ", " + d + "):\n music.pitch(freq, " + e + ", pin\x3dPin.P" + a + ")\n"
  477. };
  478. Blockly.Python.CocoRobo_music_pin_p6 = function(a) {
  479. return ["" + a.getFieldValue("music_pin"), Blockly.Python.ORDER_ATOMIC]
  480. };
  481. Blockly.Python.CocoRobo_time_ticks = function(a) {
  482. Blockly.Python.definitions_.import_time = "import time";
  483. return ["time." + a.getFieldValue("time_ticks") + "()", Blockly.Python.ORDER_ATOMIC]
  484. };
  485. Blockly.Python.CocoRobo_time_localtime = function(a) {
  486. Blockly.Python.definitions_.import_time = "import time";
  487. return ["time.localtime()[" + a.getFieldValue("time_localtime") + "]", Blockly.Python.ORDER_ATOMIC]
  488. };
  489. Blockly.Python.CocoRobo_sway_xyz = function (a) {
  490. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  491. return ["button_" + a.getFieldValue("direction_group") + ".value() \x3d\x3d 0", Blockly.Python.ORDER_ATOMIC]
  492. };
  493. Blockly.Python.CocoRobo_sleep_ms = function(a) {
  494. Blockly.Python.definitions_.import_time = "import time";
  495. var b = Blockly.Python.valueToCode(a, "duration", Blockly.Python.ORDER_ATOMIC);
  496. a = a.getFieldValue("ms_us");
  497. switch (a) {
  498. case "ms":
  499. case "us":
  500. return "time.sleep_" + a + "(" + b + ")\n";
  501. case "s":
  502. return "time.sleep(" + b + ")\n";
  503. default:
  504. return ""
  505. }
  506. };
  507. Blockly.Python.CocoRobo_time_difference = function(a) {
  508. Blockly.Python.definitions_.import_time = "import time";
  509. var b = Blockly.Python.valueToCode(a, "time1", Blockly.Python.ORDER_ATOMIC);
  510. a = Blockly.Python.valueToCode(a, "time2", Blockly.Python.ORDER_ATOMIC);
  511. return ["time.ticks_diff(" + b + ", " + a + ")", Blockly.Python.ORDER_ATOMIC]
  512. };
  513. Blockly.Python.CocoRobo_servo_angle0 = function (a) {
  514. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  515. Blockly.Python.definitions_.import_servo = "from servo import Servo";
  516. var b = Blockly.Python.valueToCode(a, "pwm_pin", Blockly.Python.ORDER_ATOMIC);
  517. a = Blockly.Python.valueToCode(a, "servo_angle", Blockly.Python.ORDER_ATOMIC);
  518. Blockly.Python.codeFunctions_["Servo_define" + b] = "servo_" + b + " \x3d Servo(" + b + ", min_us\x3d750, max_us\x3d2250, actuation_range\x3d180)";
  519. return "servo_" + b + ".write_angle(" + a + ")\n"
  520. };
  521. Blockly.Python.CocoRobo_servo_angle = function (a) {
  522. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  523. Blockly.Python.definitions_.import_servo = "from servo import Servo";
  524. var b = Blockly.Python.valueToCode(a, "pwm_pin", Blockly.Python.ORDER_ATOMIC),
  525. c = Blockly.Python.valueToCode(a, "min_us", Blockly.Python.ORDER_ATOMIC),
  526. d = Blockly.Python.valueToCode(a, "max_us", Blockly.Python.ORDER_ATOMIC),
  527. e = Blockly.Python.valueToCode(a, "actuation_range", Blockly.Python.ORDER_ATOMIC);
  528. a = Blockly.Python.valueToCode(a, "servo_angle", Blockly.Python.ORDER_ATOMIC);
  529. Blockly.Python.codeFunctions_["Servo_define" + b] = "servo_" + b + " \x3d Servo(" + b + ", min_us\x3d" + c + ", max_us\x3d" + d + ", actuation_range\x3d" + e + ")";
  530. return "servo_" + b + ".write_angle(" + a + ")\n"
  531. };
  532. Blockly.Python.CocoRobo_dh11_hum_tem = function (a) {
  533. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  534. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  535. Blockly.Python.definitions_.import_dht = "import dht";
  536. var b = Blockly.Python.valueToCode(a, "dh11_hum_tem_pin", Blockly.Python.ORDER_ATOMIC);
  537. a = a.getFieldValue("hum_tem");
  538. Blockly.Python.definitions_.dh11_define = "dht11 \x3d dht.DHT11(Pin(Pin.P" + b + "))";
  539. Blockly.Python.definitions_.def_Timer13 = "tim13 \x3d Timer(13)";
  540. Blockly.Python.definitions_.timer13_tick = "def timer13_tick(_):\n try: dht11.measure()\n except: pass\n";
  541. Blockly.Python.definitions_.timer13_init = "tim13.init(period\x3d1000, mode\x3dTimer.PERIODIC, callback\x3dtimer13_tick)\n";
  542. return ["dht11." + a + "()", Blockly.Python.ORDER_ATOMIC]
  543. };
  544. Blockly.Python.CocoRobo_dh22_hum_tem = function (a) {
  545. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  546. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  547. Blockly.Python.definitions_.import_dht = "import dht";
  548. var b = Blockly.Python.valueToCode(a, "dh22_hum_tem_pin", Blockly.Python.ORDER_ATOMIC);
  549. a = a.getFieldValue("hum_tem");
  550. Blockly.Python.definitions_.dh22_define = "dht22 \x3d dht.DHT22(Pin(Pin.P" + b + "))";
  551. Blockly.Python.definitions_.def_Timer13 = "tim13 \x3d Timer(13)";
  552. Blockly.Python.definitions_.timer13_tick = "def timer13_tick(_):\n try: dht22.measure()\n except: pass\n";
  553. Blockly.Python.definitions_.timer13_init = "tim13.init(period\x3d1000, mode\x3dTimer.PERIODIC, callback\x3dtimer13_tick)\n";
  554. return ["dht22." + a + "()", Blockly.Python.ORDER_ATOMIC]
  555. };
  556. Blockly.Python.CocoRobo_music_note = function(a) {
  557. var b = a.getFieldValue("gamut"),
  558. c = Blockly.Python.valueToCode(a, "num1", Blockly.Python.ORDER_ATOMIC);
  559. a = Blockly.Python.valueToCode(a, "num2", Blockly.Python.ORDER_ATOMIC);
  560. return ["'" + b + c + ":" + a + "'", Blockly.Python.ORDER_ATOMIC]
  561. };
  562. Blockly.Python.CocoRobo_def_clock = function (a) {
  563. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  564. var b = a.getFieldValue("clock_name"),
  565. c = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  566. d = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
  567. a = Blockly.Python.valueToCode(a, "radius", Blockly.Python.ORDER_ATOMIC);
  568. Blockly.Python.codeFunctions_["def_clock" + b] = b + " \x3d Clock(lcd, " + c + ", " + d + ", " + a + ")";
  569. return ""
  570. };
  571. Blockly.Python.CocoRobo_settime_clock = function (a) {
  572. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  573. return a.getFieldValue("clock_name") + ".settime()\n"
  574. };
  575. Blockly.Python.CocoRobo_draw_clear_clock = function (a) {
  576. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  577. var b = a.getFieldValue("draw_clear_clock");
  578. return a.getFieldValue("clock_name") + "." + b + "()\n"
  579. };
  580. Blockly.Python.CocoRobo_button_is_pressed = function (a) {
  581. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  582. a = a.getFieldValue("button");
  583. return ["A+B" === a ? "button_a.value() \x3d\x3d 0 and button_b.value() \x3d\x3d 0" : "button_" + a + ".value() \x3d\x3d 0", Blockly.Python.ORDER_ATOMIC]
  584. };
  585. Blockly.Python.CocoRobo_button_both_pressed = function (a) {
  586. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  587. return ["button_a.value() \x3d\x3d 0 and button_b.value() \x3d\x3d 0", Blockly.Python.ORDER_ATOMIC]
  588. };
  589. Blockly.Python.CocoRobo_touchPad_value = function (a) {
  590. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  591. return ["touchPad_" + a.getFieldValue("touchPad") + ".read() \x3c 400", Blockly.Python.ORDER_ATOMIC]
  592. };
  593. Blockly.Python.CocoRobo_touchPad_value_num = function (a) {
  594. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  595. return ["touchPad_" + a.getFieldValue("touchPad") + ".read()", Blockly.Python.ORDER_ATOMIC]
  596. };
  597. Blockly.Python.CocoRobo_read_digital = function (a) {
  598. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  599. a = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC);
  600. Blockly.Python.definitions_["set_PinMode_in_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.IN)";
  601. return ["p" + a + ".read_digital()", Blockly.Python.ORDER_ATOMIC]
  602. };
  603. Blockly.Python.CocoRobo_read_ds18b20 = function (a) {
  604. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  605. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  606. Blockly.Python.definitions_.import_onewire = "import onewire";
  607. Blockly.Python.definitions_.import_ds18x20 = "import ds18x20";
  608. a = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC);
  609. Blockly.Python.definitions_.ds18x20_list_define = "_ds18x20_list \x3d []";
  610. Blockly.Python.definitions_.def_Timer13 = "tim13 \x3d Timer(13)";
  611. Blockly.Python.definitions_.timer13_tick = 'def timer13_tick(_):\n for p in _ds18x20_list:\n try:\n eval("ds_" + p + ".convert_temp()")\n for rom in eval("roms_" + p):\n t \x3d eval("ds_" + p).read_temp(rom)\n eval("set_ds_value_" + p + "(" + str(t) + ")")\n break\n except: pass\n';
  612. Blockly.Python.definitions_.timer13_init = "tim13.init(period\x3d1000, mode\x3dTimer.PERIODIC, callback\x3dtimer13_tick)\n";
  613. Blockly.Python.codeFunctions_["set_ds_value_" + a] = "def set_ds_value_" + a + "(_t):\n global _ds18x20_value_" + a + "\n _ds18x20_value_" + a + " \x3d _t\n";
  614. Blockly.Python.codeFunctions_["ds18x20_value" + a] = "ow_" + a + " \x3d onewire.OneWire(Pin(Pin.P" + a + "))\nds_" + a + " \x3d ds18x20.DS18X20(ow_" + a + ")\nroms_" + a + " \x3d ds_" + a + ".scan()\n_ds18x20_value_" + a + " \x3d 0\n_ds18x20_list.append(str(" + a + "))\n";
  615. return ["_ds18x20_value_" + a, Blockly.Python.ORDER_ATOMIC]
  616. };
  617. Blockly.Python.CocoRobo_set_digital = function (a) {
  618. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  619. var b = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC);
  620. a = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC);
  621. Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.OUT)";
  622. return "p" + a + ".write_digital(" + b + ")\n"
  623. };
  624. Blockly.Python.CocoRobo_set_pin_mode = function (a) {
  625. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  626. var b = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC),
  627. c = a.getFieldValue("in_out"),
  628. d = a.getFieldValue("pin_up_down_pull");
  629. a = Blockly.Python.valueToCode(a, "pin_value", Blockly.Python.ORDER_ATOMIC);
  630. Blockly.Python.codeFunctions_["set_PinMode" + b] = "p" + b + " \x3d CocoRoboPin(" + b + ", PinMode." + c + ", " + d + ")";
  631. return "p" + b + ".write_digital(" + a + ")\n"
  632. };
  633. Blockly.Python.CocoRobo_type = function(a) {
  634. return ["type(" + (Blockly.Python.valueToCode(a, "VAR", Blockly.Python.ORDER_ATOMIC) || "None") + ")", Blockly.Python.ORDER_ATOMIC]
  635. };
  636. Blockly.Python.CocoRobo_type_is = function(a) {
  637. var b = Blockly.Python.valueToCode(a, "VAR", Blockly.Python.ORDER_ATOMIC) || "None";
  638. a = a.getFieldValue("TYPE");
  639. return ["type(" + b + ") \x3d\x3d " + a, Blockly.Python.ORDER_ATOMIC]
  640. };
  641. Blockly.Python.CocoRobo_eval = function(a) {
  642. return ["eval(" + (Blockly.Python.valueToCode(a, "VAR", Blockly.Python.ORDER_ATOMIC) || "None") + ")", Blockly.Python.ORDER_ATOMIC]
  643. };
  644. Blockly.Python.CocoRobo_return = function(a) {
  645. return "return " + (Blockly.Python.valueToCode(a, "VAR", Blockly.Python.ORDER_ATOMIC) || "None") + "\n"
  646. };
  647. Blockly.Python.CocoRobo_read_analog = function (a) {
  648. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  649. a = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC);
  650. Blockly.Python.definitions_["set_PinMode_in_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.ANALOG)";
  651. return ["p" + a + ".read_analog()", Blockly.Python.ORDER_ATOMIC]
  652. };
  653. Blockly.Python.CocoRobo_set_analog = function (a) {
  654. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  655. var b = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC);
  656. a = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC);
  657. Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.PWM)";
  658. return "p" + a + ".write_analog(" + b + ")\n"
  659. };
  660. Blockly.Python.CocoRobo_rgb_list = function(a) {
  661. return [a.getFieldValue("rgb_list"), Blockly.Python.ORDER_ATOMIC]
  662. };
  663. Blockly.Python.CocoRobo_set_rgb_list_color = function (a) {
  664. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  665. Blockly.Python.definitions_.import_time = "import time";
  666. var b = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC);
  667. a = a.getFieldValue("COLOUR");
  668. var c = 0,
  669. d = 0,
  670. e = 0;
  671. try {
  672. 7 == a.length && (c = parseInt(a.substring(1, 3), 16),
  673. d = parseInt(a.substring(3, 5), 16),
  674. e = parseInt(a.substring(5, 7), 16))
  675. } catch (f) {}
  676. switch (b) {
  677. case "0":
  678. case "1":
  679. case "2":
  680. return "rgb[" + b + "] \x3d (int(" + c + "), int(" + d + "), int(" + e + "))\nrgb.write()\ntime.sleep_ms(1)\n";
  681. case "-1":
  682. return "rgb.fill((int(" + c + "), int(" + d + "), int(" + e + ")))\nrgb.write()\ntime.sleep_ms(1)\n";
  683. default:
  684. return "rgb[" + b + "] \x3d (int(" + c + "), int(" + d + "), int(" + e + "))\nrgb.write()\ntime.sleep_ms(1)\n"
  685. }
  686. };
  687. Blockly.Python.CocoRobo_set_rgb_list_number = function (a) {
  688. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  689. Blockly.Python.definitions_.import_time = "import time";
  690. var b = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC),
  691. c = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
  692. d = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC);
  693. a = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
  694. switch (b) {
  695. case "0":
  696. case "1":
  697. case "2":
  698. return "rgb[" + b + "] \x3d (int(" + c + "), int(" + d + "), int(" + a + "))\nrgb.write()\ntime.sleep_ms(1)\n";
  699. case "-1":
  700. return "rgb.fill( (int(" + c + "), int(" + d + "), int(" + a + ")) )\nrgb.write()\ntime.sleep_ms(1)\n";
  701. default:
  702. return "rgb[" + b + "] \x3d (int(" + c + "), int(" + d + "), int(" + a + "))\nrgb.write()\ntime.sleep_ms(1)\n"
  703. }
  704. };
  705. Blockly.Python.CocoRobo_off_rgb_list = function (a) {
  706. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  707. Blockly.Python.definitions_.import_time = "import time";
  708. a = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC);
  709. switch (a) {
  710. case "0":
  711. case "1":
  712. case "2":
  713. return "rgb[" + a + "] \x3d (0, 0, 0)\nrgb.write()\ntime.sleep_ms(1)\n";
  714. case "-1":
  715. return "rgb.fill( (0, 0, 0) )\nrgb.write()\ntime.sleep_ms(1)\n";
  716. default:
  717. return "rgb[" + a + "] \x3d (0, 0, 0)\nrgb.write()\ntime.sleep_ms(1)\n"
  718. }
  719. };
  720. Blockly.Python.CocoRobo_set_RGB_color = function (a) {
  721. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  722. Blockly.Python.definitions_.import_time = "import time";
  723. var b = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC);
  724. a = a.getFieldValue("COLOUR");
  725. var c = 0,
  726. d = 0,
  727. e = 0;
  728. try {
  729. 7 == a.length && (c = parseInt(a.substring(1, 3), 16),
  730. d = parseInt(a.substring(3, 5), 16),
  731. e = parseInt(a.substring(5, 7), 16))
  732. } catch (f) {}
  733. return "rgb[" + b + "] \x3d (int(" + c + "/30), int(" + d + "/30), int(" + e + "/30))\nrgb.write()\ntime.sleep_ms(1)\n"
  734. };
  735. Blockly.Python.CocoRobo_set_RGB_color_all = function (a) {
  736. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  737. Blockly.Python.definitions_.import_time = "import time";
  738. a = a.getFieldValue("COLOUR");
  739. var b = 0,
  740. c = 0,
  741. d = 0;
  742. try {
  743. 7 == a.length && (b = parseInt(a.substring(1, 3), 16),
  744. c = parseInt(a.substring(3, 5), 16),
  745. d = parseInt(a.substring(5, 7), 16))
  746. } catch (e) {}
  747. return "rgb[0] \x3d (int(" + b + "/30), int(" + c + "/30), int(" + d + "/30))\nrgb[1] \x3d (int(" + b + "/30), int(" + c + "/30), int(" + d + "/30))\nrgb[2] \x3d (int(" + b + "/30), int(" + c + "/30), int(" + d + "/30))\nrgb.write()\ntime.sleep_ms(1)\n"
  748. };
  749. Blockly.Python.CocoRobo_set_RGB = function (a) {
  750. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  751. Blockly.Python.definitions_.import_time = "import time";
  752. var b = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC),
  753. c = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
  754. d = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC);
  755. a = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
  756. return "rgb[" + b + "] \x3d (int(" + c + "/30), int(" + d + "/30), int(" + a + "/30))\nrgb.write()\ntime.sleep_ms(1)\n"
  757. };
  758. Blockly.Python.CocoRobo_set_RGB_all = function (a) {
  759. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  760. Blockly.Python.definitions_.import_time = "import time";
  761. var b = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
  762. c = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC);
  763. a = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
  764. return "rgb[0] \x3d (int(" + b + "/30), int(" + c + "/30), int(" + a + "/30))\nrgb[1] \x3d (int(" + b + "/30), int(" + c + "/30), int(" + a + "/30))\nrgb[2] \x3d (int(" + b + "/30), int(" + c + "/30), int(" + a + "/30))\nrgb.write()\ntime.sleep_ms(1)\n"
  765. };
  766. Blockly.Python.CocoRobo_fresh_RGB = function (a) {
  767. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  768. Blockly.Python.definitions_.import_time = "import time";
  769. return ""
  770. };
  771. Blockly.Python.CocoRobo_off_RGB = function (a) {
  772. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  773. Blockly.Python.definitions_.import_time = "import time";
  774. return "rgb.fill( (0, 0, 0) )\nrgb.write()\ntime.sleep_ms(1)\n"
  775. };
  776. Blockly.Python.CocoRobo_buzz_state = function(a) {
  777. Blockly.Python.definitions_.import_music = "import music";
  778. return "music.stop()\n"
  779. };
  780. Blockly.Python.CocoRobo_buzz_freq = function(a) {
  781. Blockly.Python.definitions_.import_music = "import music";
  782. var b = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
  783. a = Blockly.Python.valueToCode(a, "freq", Blockly.Python.ORDER_ATOMIC);
  784. return "6" == b ? "music.pitch(" + a + ")\n" : "music.pitch(" + a + ", -1, pin\x3dPin.P" + b + ")\n"
  785. };
  786. Blockly.Python.CocoRobo_buzz_tone = function(a) {
  787. Blockly.Python.definitions_.import_music = "import music";
  788. return "music.pitch(" + a.getFieldValue("buzz_tone") + ")\n"
  789. };
  790. Blockly.Python.CocoRobo_music_tone_tempo = function (a) {
  791. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  792. Blockly.Python.definitions_.import_music = "import music";
  793. var b = Blockly.Python.valueToCode(a, "musical_note", Blockly.Python.ORDER_ATOMIC);
  794. a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
  795. return "6" == a ? "music.play(" + b + ")\n" : "music.play(" + b + ", pin\x3dPin.P" + a + ")\n"
  796. };
  797. Blockly.Python.CocoRobo_music_tone = function(a) {
  798. Blockly.Python.definitions_.import_music = "import music";
  799. return [a.getFieldValue("music_tone"), Blockly.Python.ORDER_ATOMIC]
  800. };
  801. Blockly.Python.CocoRobo_music_musical_note = function(a) {
  802. Blockly.Python.definitions_.import_music = "import music";
  803. var b = a.getFieldValue("musical_note");
  804. a = a.getFieldValue("music_tick");
  805. return ["'" + b + ":" + a + "'", Blockly.Python.ORDER_ATOMIC]
  806. };
  807. Blockly.Python.CocoRobo_4_lines = function(a) {
  808. return [a.getFieldValue("CocoRobo_4_lines"), Blockly.Python.ORDER_ATOMIC]
  809. };
  810. Blockly.Python.CocoRobo_music_tick = function(a) {
  811. Blockly.Python.definitions_.import_music = "import music";
  812. return [a.getFieldValue("music_tick"), Blockly.Python.ORDER_ATOMIC]
  813. };
  814. Blockly.Python.CocoRobo_read_sound = function (a) {
  815. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  816. return ["sound.read()", Blockly.Python.ORDER_ATOMIC]
  817. };
  818. Blockly.Python.CocoRobo_read_light = function (a) {
  819. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  820. return ["light.read()", Blockly.Python.ORDER_ATOMIC]
  821. };
  822. Blockly.Python.CocoRobo_accelerometer_get = function (a) {
  823. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  824. switch (a.getFieldValue("axis")) {
  825. case "X":
  826. a = "accelerometer.get_values()['AcX']";
  827. break;
  828. case "Y":
  829. a = "accelerometer.get_values()['AcY']";
  830. break;
  831. case "Z":
  832. a = "accelerometer.get_values()['AcZ']";
  833. break;
  834. default:
  835. return ""
  836. }
  837. return [a, Blockly.Python.ORDER_ATOMIC]
  838. };
  839. Blockly.Python.CocoRobo_accelerometer_get_x = function (a) {
  840. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  841. return ["accelerometer.get_x()", Blockly.Python.ORDER_ATOMIC]
  842. };
  843. Blockly.Python.CocoRobo_accelerometer_get_y = function (a) {
  844. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  845. return ["accelerometer.get_y()", Blockly.Python.ORDER_ATOMIC]
  846. };
  847. Blockly.Python.CocoRobo_accelerometer_get_z = function (a) {
  848. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  849. return ["accelerometer.get_z()", Blockly.Python.ORDER_ATOMIC]
  850. };
  851. Blockly.Python.CocoRobo_accelerometer_set_range = function (a) {
  852. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  853. return "accelerometer.set_range(accelerometer." + a.getFieldValue("range") + ")\n"
  854. };
  855. Blockly.Python.CocoRobo_accelerometer_set_resolustion = function (a) {
  856. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  857. return "accelerometer.set_resolustion(accelerometer." + a.getFieldValue("resolustion") + ")\n"
  858. };
  859. Blockly.Python.CocoRobo_accelerometer_set_offset = function (a) {
  860. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  861. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  862. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
  863. a = Blockly.Python.valueToCode(a, "z", Blockly.Python.ORDER_ATOMIC);
  864. return "accelerometer.set_offset(" + b + ", " + c + ", " + a + ")\n"
  865. };
  866. Blockly.Python.CocoRobo_tilt_angle = function (a) {
  867. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  868. Blockly.Python.definitions_.import_math = "import math";
  869. a = a.getFieldValue("axis");
  870. //Blockly.Python.codeFunctions_.get_tilt_angle = "def get_tilt_angle(_axis):\n _Ax \x3d accelerometer.get_x()\n _Ay \x3d accelerometer.get_y()\n _Az \x3d accelerometer.get_z()\n if 'X' \x3d\x3d _axis:\n _T \x3d math.sqrt(_Ay ** 2 + _Az ** 2)\n if _Az \x3c 0: return math.degrees(math.atan2(_Ax , _T))\n else: return 180 - math.degrees(math.atan2(_Ax , _T))\n elif 'Y' \x3d\x3d _axis:\n _T \x3d math.sqrt(_Ax ** 2 + _Az ** 2)\n if _Az \x3c 0: return math.degrees(math.atan2(_Ay , _T))\n else: return 180 - math.degrees(math.atan2(_Ay , _T))\n elif 'Z' \x3d\x3d _axis:\n _T \x3d math.sqrt(_Ax ** 2 + _Ay ** 2)\n if (_Ax + _Ay) \x3c 0: return 180 - math.degrees(math.atan2(_T , _Az))\n else: return math.degrees(math.atan2(_T , _Az)) - 180\n return 0";
  871. switch (a) {
  872. case "X":
  873. a = "mpu_get_tilt_angle('X')";
  874. break;
  875. case "Y":
  876. a = "mpu_get_tilt_angle('Y')";
  877. break;
  878. case "Z":
  879. a = "mpu_get_tilt_angle('Z')";
  880. break;
  881. default:
  882. a = "0"
  883. }
  884. return [a, Blockly.Python.ORDER_ATOMIC]
  885. };
  886. Blockly.Python.CocoRobo_random_choice = function(a) {
  887. // Blockly.Python.definitions_.import_time = "import time";
  888. // Blockly.Python.codeFunctions_.random_seed = "random.seed(time.ticks_cpu())";
  889. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  890. Blockly.Python.definitions_.import_random = "import random";
  891. return ["str(random.choice(" + Blockly.Python.valueToCode(a, "list", Blockly.Python.ORDER_ATOMIC) + "))", Blockly.Python.ORDER_ATOMIC]
  892. };
  893. Blockly.Python.machine_time_pulse_us = function(a) {
  894. Blockly.Python.definitions_.import_machine = "import machine";
  895. var b = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
  896. a = Blockly.Python.valueToCode(a, "pulse", Blockly.Python.ORDER_ATOMIC);
  897. return ["machine.time_pulse_us(Pin(Pin.P" + b + "), " + a + ", timeout_us\x3d1000000)", Blockly.Python.ORDER_ATOMIC]
  898. };
  899. Blockly.Python.CocoRobo_print = function(a) {
  900. return "print(" + Blockly.Python.valueToCode(a, "CONTENT", Blockly.Python.ORDER_ATOMIC) + ")\n"
  901. };
  902. Blockly.Python.CocoRobo_print_to_chart = function(a) {
  903. for (var b = Array(a.itemCount_), c = 0; c < a.itemCount_; c++)
  904. b[c] = Blockly.Python.valueToCode(a, "ADD" + c, Blockly.Python.ORDER_NONE) || "None";
  905. return 1 == a.itemCount_ ? "print((" + b[0] + ",))\n" : "print((" + b.join(", ") + "))\n"
  906. };
  907. Blockly.Python.CocoRobo_init_chart = function(a) {
  908. Blockly.Python.definitions_.import_time = "import time";
  909. var b = Array(a.itemCount_ + 1);
  910. b[0] = "'__TITLE'";
  911. for (var c = 0; c < a.itemCount_; c++)
  912. b[c + 1] = Blockly.Python.valueToCode(a, "ADD" + c, Blockly.Python.ORDER_NONE) || "None";
  913. return "time.sleep_ms(50);print((" + b.join(", ") + "));time.sleep_ms(50)\n"
  914. };
  915. Blockly.Python.CocoRobo_ir_remote_recv = function (a) {
  916. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  917. Blockly.Python.definitions_.import_ir_remote_recv = "from ir_remote import IRDecode";
  918. var b = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
  919. Blockly.Python.definitions_.define_ir_remote_recv = "remote \x3d IRDecode(Pin.P" + b + ")";
  920. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  921. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  922. try {
  923. b.remove("_address")
  924. } catch (d) {}
  925. try {
  926. b.remove("_command")
  927. } catch (d) {}
  928. b = b.length ? " global " + b.join(", ") + "\n" : "";
  929. a = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
  930. Blockly.Python.codeFunctions_.def_ir_remote_recv = "def remote_callback(_address, _command):\n" + b + a;
  931. return "remote.set_callback(remote_callback)\n"
  932. };
  933. Blockly.Python.CocoRobo_ir_remote_send = function (a) {
  934. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  935. Blockly.Python.definitions_.import_ir_remote_send = "from ir_remote import IRTransmit";
  936. var b = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
  937. Blockly.Python.definitions_.define_ir_remote_send = "ir \x3d IRTransmit(Pin.P" + b + ")";
  938. b = Blockly.Python.valueToCode(a, "address", Blockly.Python.ORDER_ATOMIC);
  939. a = Blockly.Python.valueToCode(a, "command", Blockly.Python.ORDER_ATOMIC);
  940. return "ir.send(" + b + ", " + a + ")\n"
  941. };
  942. Blockly.Python.CocoRobo_bme280_hum_tem_pre = function (a) {
  943. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  944. return ["bme280." + a.getFieldValue("hum_tem_pre") + "()", Blockly.Python.ORDER_ATOMIC]
  945. };
  946. Blockly.Python.CocoRobo_compass_get_axis = function (a) {
  947. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  948. switch (a.getFieldValue("axis")) {
  949. case "X":
  950. a = "compass.get_x()";
  951. break;
  952. case "Y":
  953. a = "compass.get_y()";
  954. break;
  955. case "Z":
  956. a = "compass.get_z()";
  957. break;
  958. default:
  959. return ""
  960. }
  961. return [a, Blockly.Python.ORDER_ATOMIC]
  962. };
  963. Blockly.Python.CocoRobo_compass_get_angle = function (a) {
  964. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  965. return ["compass.get_angle()", Blockly.Python.ORDER_ATOMIC]
  966. };
  967. Blockly.Python.CocoRobo_audio_set_volume = function(a) {
  968. Blockly.Python.definitions_.import_audio = "import audio";
  969. return "audio.set_volume(" + Blockly.Python.valueToCode(a, "volume", Blockly.Python.ORDER_ATOMIC) + ")\n"
  970. };
  971. Blockly.Python.CocoRobo_audio_xunfei_tts = function(a) {
  972. Blockly.Python.definitions_.import_audio = "import audio";
  973. return "audio.xunfei_tts(" + Blockly.Python.valueToCode(a, "TEXT", Blockly.Python.ORDER_ATOMIC) + ")\n"
  974. };
  975. Blockly.Python.CocoRobo_audio_xunfei_tts_config = function(a) {
  976. Blockly.Python.definitions_.import_audio = "import audio";
  977. var b = Blockly.Python.valueToCode(a, "APPID", Blockly.Python.ORDER_ATOMIC);
  978. return "audio.xunfei_tts_config(" + Blockly.Python.valueToCode(a, "API_KEY", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
  979. };
  980. Blockly.Python.CocoRobo_audio_play = function(a) {
  981. Blockly.Python.definitions_.import_audio = "import audio";
  982. return "audio.play(" + Blockly.Python.valueToCode(a, "url", Blockly.Python.ORDER_ATOMIC) + ")\n"
  983. };
  984. Blockly.Python.CocoRobo_audio_cmd = function(a) {
  985. Blockly.Python.definitions_.import_audio = "import audio";
  986. return "audio." + a.getFieldValue("cmd") + "()\n"
  987. };
  988. Blockly.Python.CocoRobo_audio_deinit = function(a) {
  989. Blockly.Python.definitions_.import_audio = "import audio";
  990. return "audio.player_deinit()\n"
  991. };
  992. Blockly.Python.CocoRobo_audio_init = function(a) {
  993. Blockly.Python.definitions_.import_audio = "import audio";
  994. return "audio.player_init()\n"
  995. };
  996. Blockly.Python.CocoRobo_record_init = function(a) {
  997. Blockly.Python.definitions_.import_audio = "import audio";
  998. return "audio.recorder_init()\n"
  999. };
  1000. Blockly.Python.CocoRobo_record_deinit = function(a) {
  1001. Blockly.Python.definitions_.import_audio = "import audio";
  1002. return "audio.recorder_deinit()\n"
  1003. };
  1004. Blockly.Python.CocoRobo_record_wav = function(a) {
  1005. Blockly.Python.definitions_.import_audio = "import audio";
  1006. var b = Blockly.Python.valueToCode(a, "file_name", Blockly.Python.ORDER_ATOMIC);
  1007. a = Blockly.Python.valueToCode(a, "record_time", Blockly.Python.ORDER_ATOMIC);
  1008. return "audio.record(" + b + ", " + a + ")\n"
  1009. };
  1010. Blockly.Python.CocoRobo_asr = function(a) {
  1011. Blockly.Python.definitions_.import_audio = "import audio";
  1012. Blockly.Python.definitions_.import_urequests = "import urequests";
  1013. Blockly.Python.definitions_.import_json = "import json";
  1014. Blockly.Python.definitions_.import_machine = "import machine";
  1015. Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
  1016. Blockly.Python.codeFunctions_.CocoRobo_get_asr = 'def get_asr_result():\n audio.recorder_init()\n audio.record("temp.wav", 2)\n audio.recorder_deinit()\n _response \x3d urequests.post("http://203.195.229.133:8895/v1/deviceai/asr",\n files\x3d{"file":("temp.wav", "audio/wav")},\n params\x3d{"appid":"1", "mediatype":"2", "deviceid":ubinascii.hexlify(machine.unique_id()).decode().upper()})\n rsp_json \x3d _response.json()\n _response.close()\n if "text" in rsp_json:\n return rsp_json["text"]\n elif "Code" in rsp_json:\n return "Code:%s" % rsp_json["Code"]\n else:\n return rsp_json';
  1017. return ["get_asr_result()", Blockly.Python.ORDER_ATOMIC]
  1018. };
  1019. Blockly.Python.xunfei_speech_tts = function(a) {
  1020. Blockly.Python.definitions_.import_xunfei = "from xunfei import *";
  1021. var b = Blockly.Python.valueToCode(a, "APPID", Blockly.Python.ORDER_ATOMIC),
  1022. c = Blockly.Python.valueToCode(a, "APISecret", Blockly.Python.ORDER_ATOMIC),
  1023. d = Blockly.Python.valueToCode(a, "APIKey", Blockly.Python.ORDER_ATOMIC),
  1024. e = Blockly.Python.valueToCode(a, "Text", Blockly.Python.ORDER_ATOMIC);
  1025. a = Blockly.Python.valueToCode(a, "AudioFile", Blockly.Python.ORDER_ATOMIC);
  1026. return "speech_tts \x3d Xunfei_speech(" + b + ", " + d + ", " + c + ", mode\x3dMODE_TTS, AudioFile\x3d" + a + ", Text\x3d" + e + ')\nprint("Processing, please wait....")\nspeech_tts.tts()\n'
  1027. };
  1028. Blockly.Python.xunfei_speech_iat = function(a) {
  1029. Blockly.Python.definitions_.import_xunfei = "from xunfei import *";
  1030. var b = Blockly.Python.valueToCode(a, "APPID", Blockly.Python.ORDER_ATOMIC),
  1031. c = Blockly.Python.valueToCode(a, "APISecret", Blockly.Python.ORDER_ATOMIC),
  1032. d = Blockly.Python.valueToCode(a, "APIKey", Blockly.Python.ORDER_ATOMIC);
  1033. a = Blockly.Python.valueToCode(a, "AudioFile", Blockly.Python.ORDER_ATOMIC);
  1034. return "speech_iat \x3d Xunfei_speech(" + b + ", " + d + ", " + c + ", mode\x3dMODE_IAT, AudioFile\x3d" + a + ")\n"
  1035. };
  1036. Blockly.Python.xunfei_speech_iat_result = function(a) {
  1037. Blockly.Python.definitions_.import_xunfei = "from xunfei import *";
  1038. return ["speech_iat.iat()", Blockly.Python.ORDER_ATOMIC]
  1039. };
  1040. Blockly.Python.CocoRobo_bluebit_lcd_bmp = function(a) {
  1041. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1042. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1043. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  1044. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  1045. d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
  1046. e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
  1047. a = Blockly.Python.valueToCode(a, "bmp", Blockly.Python.ORDER_ATOMIC);
  1048. return "b_oled.Bitmap(" + b + ", " + c + ", " + a + ", " + d + ", " + e + ", 1)\nb_oled.show()\n"
  1049. };
  1050. Blockly.Python.CocoRobo_bluebit_lcd_clear = function(a) {
  1051. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1052. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1053. return "b_oled.clear()\nb_oled.show()\n"
  1054. };
  1055. Blockly.Python.CocoRobo_bluebit_lcd_init = function(a) {
  1056. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1057. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1058. var b = Blockly.Python.valueToCode(a, "tx", Blockly.Python.ORDER_ATOMIC);
  1059. a = Blockly.Python.valueToCode(a, "rx", Blockly.Python.ORDER_ATOMIC);
  1060. Blockly.Python.definitions_.CocoRobo_bluebit_OLCD = "b_oled \x3d OLCDBit(rx\x3dPin.P" + a + ", tx\x3dPin.P" + b + ")\n";
  1061. return "\n"
  1062. };
  1063. Blockly.Python.CocoRobo_bluebit_lcd_print = function(a) {
  1064. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1065. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1066. var b = Blockly.Python.valueToCode(a, "_print", Blockly.Python.ORDER_ATOMIC),
  1067. c = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC);
  1068. a = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
  1069. return "b_oled.Print(" + b + ", " + c + ", " + a + ")\n"
  1070. };
  1071. Blockly.Python.CocoRobo_ir_recv = function(a) {
  1072. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1073. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1074. a = Blockly.Python.valueToCode(a, "rx", Blockly.Python.ORDER_ATOMIC);
  1075. Blockly.Python.definitions_["irrecv_object" + a] = "irrecv" + a + " \x3d IRRecv(rx\x3dPin.P" + a + ")";
  1076. return ["irrecv" + a + ".recv()", Blockly.Python.ORDER_ATOMIC]
  1077. };
  1078. Blockly.Python.CocoRobo_ir_trans = function(a) {
  1079. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1080. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1081. var b = Blockly.Python.valueToCode(a, "tx", Blockly.Python.ORDER_ATOMIC);
  1082. Blockly.Python.definitions_["irtrans_object" + b] = "irtrans" + b + " \x3d IRTrans(tx\x3dPin.P" + b + ")";
  1083. a = Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC);
  1084. return "irtrans" + b + ".transmit(bytes(" + a + ", 'utf-8'))\n"
  1085. };
  1086. Blockly.Python.CocoRobo_lcd_move = function(a) {
  1087. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1088. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1089. return "lcd.move_" + a.getFieldValue("move") + "()\n"
  1090. };
  1091. Blockly.Python.CocoRobo_lcd_text_direction = function(a) {
  1092. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1093. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1094. return "lcd.text_direction \x3d LCD1602." + a.getFieldValue("text_direction") + "\n"
  1095. };
  1096. Blockly.Python.CocoRobo_lcd_clear = function(a) {
  1097. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1098. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1099. return "lcd.Clear()\n"
  1100. };
  1101. Blockly.Python.CocoRobo_lcd_set_cursor = function(a) {
  1102. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1103. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1104. var b = Blockly.Python.valueToCode(a, "row", Blockly.Python.ORDER_ATOMIC);
  1105. return "lcd.setCursor(" + Blockly.Python.valueToCode(a, "column", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
  1106. };
  1107. Blockly.Python.CocoRobo_lcd_cursor = function(a) {
  1108. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1109. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1110. return "lcd." + a.getFieldValue("cursor_cmd") + "\n"
  1111. };
  1112. Blockly.Python.CocoRobo_lcd_home = function(a) {
  1113. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1114. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1115. return "lcd.Home()\n"
  1116. };
  1117. Blockly.Python.CocoRobo_lcd_print = function(a) {
  1118. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1119. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1120. return "lcd.Print(" + Blockly.Python.valueToCode(a, "display_str", Blockly.Python.ORDER_ATOMIC) + ")\n"
  1121. };
  1122. Blockly.Python.CocoRobo_lcd_object = function(a) {
  1123. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1124. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1125. Blockly.Python.definitions_.i2c_object_100k = "i2c \x3d I2C(scl\x3dPin(Pin.P19), sda\x3dPin(Pin.P20), freq\x3d100000)";
  1126. Blockly.Python.definitions_.LCD1602_object = "lcd \x3d LCD1602(i2c\x3di2c)";
  1127. return ""
  1128. };
  1129. Blockly.Python.CocoRobo_bluebit_extio_writeio = function (a) {
  1130. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1131. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1132. var b = Blockly.Python.valueToCode(a, "io_value", Blockly.Python.ORDER_ATOMIC);
  1133. a = a.getFieldValue("IO");
  1134. Blockly.Python.codeFunctions_.init_extIO = "extio \x3d extIO(i2c)";
  1135. return "extio.writeIO(" + a + ", " + b + ")\n"
  1136. };
  1137. Blockly.Python.CocoRobo_bluebit_extio_readio = function (a) {
  1138. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1139. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1140. a = a.getFieldValue("IO");
  1141. Blockly.Python.codeFunctions_.init_extIO = "extio \x3d extIO(i2c)";
  1142. return ["extio.readIO(" + a + ")", Blockly.Python.ORDER_ATOMIC]
  1143. };
  1144. Blockly.Python.CocoRobo_bluebit_extio_iomode = function (a) {
  1145. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1146. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1147. var b = a.getFieldValue("mode");
  1148. a = a.getFieldValue("IO");
  1149. Blockly.Python.codeFunctions_.init_extIO = "extio \x3d extIO(i2c)";
  1150. return "extio.IOInit(" + a + ", " + b + ")\n"
  1151. };
  1152. Blockly.Python.CocoRobo_bluebit_mp3_singleLoop = function (a) {
  1153. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1154. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1155. return "mp3.singleLoop(" + a.getFieldValue("singleLoop") + ")\n"
  1156. };
  1157. Blockly.Python.CocoRobo_bluebit_mp3_cmd = function (a) {
  1158. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1159. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1160. return "mp3." + a.getFieldValue("cmd") + "()\n"
  1161. };
  1162. Blockly.Python.CocoRobo_bluebit_mp3_play_song = function (a) {
  1163. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1164. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1165. return "mp3.play_song(" + Blockly.Python.valueToCode(a, "song_order", Blockly.Python.ORDER_ATOMIC) + ")\n"
  1166. };
  1167. Blockly.Python.CocoRobo_bluebit_mp3_volume_plus = function (a) {
  1168. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1169. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1170. return "mp3." + a.getFieldValue("volume_plus") + "()\n"
  1171. };
  1172. Blockly.Python.CocoRobo_bluebit_mp3_init = function (a) {
  1173. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1174. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1175. a = Blockly.Python.valueToCode(a, "mp3_tx", Blockly.Python.ORDER_ATOMIC);
  1176. Blockly.Python.codeFunctions_.init_mp3 = "mp3 \x3d MP3(Pin.P" + a + ")";
  1177. return ""
  1178. };
  1179. Blockly.Python.CocoRobo_bluebit_mp3_volume = function (a) {
  1180. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1181. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1182. return "mp3.volume \x3d " + Blockly.Python.valueToCode(a, "volume_level", Blockly.Python.ORDER_ATOMIC) + "\n"
  1183. };
  1184. Blockly.Python.CocoRobo_bluebit_matrix_show = function (a) {
  1185. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1186. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1187. Blockly.Python.codeFunctions_.init_matrix = "matrix \x3d Matrix()";
  1188. return "matrix.show()\n"
  1189. };
  1190. Blockly.Python.CocoRobo_bluebit_matrix_bitmap = function (a) {
  1191. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1192. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1193. Blockly.Python.codeFunctions_.init_matrix = "matrix \x3d Matrix()";
  1194. var b = "TRUE" == a.getFieldValue("00") ? "1" : "0",
  1195. c = "TRUE" == a.getFieldValue("01") ? "1" : "0",
  1196. d = "TRUE" == a.getFieldValue("02") ? "1" : "0",
  1197. e = "TRUE" == a.getFieldValue("03") ? "1" : "0",
  1198. f = "TRUE" == a.getFieldValue("04") ? "1" : "0",
  1199. g = "TRUE" == a.getFieldValue("05") ? "1" : "0",
  1200. h = "TRUE" == a.getFieldValue("06") ? "1" : "0",
  1201. k = "TRUE" == a.getFieldValue("07") ? "1" : "0",
  1202. l = "TRUE" == a.getFieldValue("10") ? "1" : "0",
  1203. u = "TRUE" == a.getFieldValue("11") ? "1" : "0",
  1204. v = "TRUE" == a.getFieldValue("12") ? "1" : "0",
  1205. w = "TRUE" == a.getFieldValue("13") ? "1" : "0",
  1206. x = "TRUE" == a.getFieldValue("14") ? "1" : "0",
  1207. y = "TRUE" == a.getFieldValue("15") ? "1" : "0",
  1208. z = "TRUE" == a.getFieldValue("16") ? "1" : "0",
  1209. A = "TRUE" == a.getFieldValue("17") ? "1" : "0",
  1210. m = "TRUE" == a.getFieldValue("20") ? "1" : "0",
  1211. B = "TRUE" == a.getFieldValue("21") ? "1" : "0",
  1212. C = "TRUE" == a.getFieldValue("22") ? "1" : "0",
  1213. D = "TRUE" == a.getFieldValue("23") ? "1" : "0",
  1214. E = "TRUE" == a.getFieldValue("24") ? "1" : "0",
  1215. F = "TRUE" == a.getFieldValue("25") ? "1" : "0",
  1216. G = "TRUE" == a.getFieldValue("26") ? "1" : "0",
  1217. H = "TRUE" == a.getFieldValue("27") ? "1" : "0",
  1218. n = "TRUE" == a.getFieldValue("30") ? "1" : "0",
  1219. I = "TRUE" == a.getFieldValue("31") ? "1" : "0",
  1220. J = "TRUE" == a.getFieldValue("32") ? "1" : "0",
  1221. K = "TRUE" == a.getFieldValue("33") ? "1" : "0",
  1222. L = "TRUE" == a.getFieldValue("34") ? "1" : "0",
  1223. M = "TRUE" == a.getFieldValue("35") ? "1" : "0",
  1224. N = "TRUE" == a.getFieldValue("36") ? "1" : "0",
  1225. O = "TRUE" == a.getFieldValue("37") ? "1" : "0",
  1226. p = "TRUE" == a.getFieldValue("40") ? "1" : "0",
  1227. P = "TRUE" == a.getFieldValue("41") ? "1" : "0",
  1228. Q = "TRUE" == a.getFieldValue("42") ? "1" : "0",
  1229. R = "TRUE" == a.getFieldValue("43") ? "1" : "0",
  1230. S = "TRUE" == a.getFieldValue("44") ? "1" : "0",
  1231. T = "TRUE" == a.getFieldValue("45") ? "1" : "0",
  1232. U = "TRUE" == a.getFieldValue("46") ? "1" : "0",
  1233. V = "TRUE" == a.getFieldValue("47") ? "1" : "0",
  1234. q = "TRUE" == a.getFieldValue("50") ? "1" : "0",
  1235. W = "TRUE" == a.getFieldValue("51") ? "1" : "0",
  1236. X = "TRUE" == a.getFieldValue("52") ? "1" : "0",
  1237. Y = "TRUE" == a.getFieldValue("53") ? "1" : "0",
  1238. Z = "TRUE" == a.getFieldValue("54") ? "1" : "0",
  1239. aa = "TRUE" == a.getFieldValue("55") ? "1" : "0",
  1240. ba = "TRUE" == a.getFieldValue("56") ? "1" : "0",
  1241. ca = "TRUE" == a.getFieldValue("57") ? "1" : "0",
  1242. r = "TRUE" == a.getFieldValue("60") ? "1" : "0",
  1243. da = "TRUE" == a.getFieldValue("61") ? "1" : "0",
  1244. ea = "TRUE" == a.getFieldValue("62") ? "1" : "0",
  1245. fa = "TRUE" == a.getFieldValue("63") ? "1" : "0",
  1246. ga = "TRUE" == a.getFieldValue("64") ? "1" : "0",
  1247. ha = "TRUE" == a.getFieldValue("65") ? "1" : "0",
  1248. ia = "TRUE" == a.getFieldValue("66") ? "1" : "0",
  1249. ja = "TRUE" == a.getFieldValue("67") ? "1" : "0",
  1250. t = "TRUE" == a.getFieldValue("70") ? "1" : "0",
  1251. ka = "TRUE" == a.getFieldValue("71") ? "1" : "0",
  1252. la = "TRUE" == a.getFieldValue("72") ? "1" : "0",
  1253. ma = "TRUE" == a.getFieldValue("73") ? "1" : "0",
  1254. na = "TRUE" == a.getFieldValue("74") ? "1" : "0",
  1255. oa = "TRUE" == a.getFieldValue("75") ? "1" : "0",
  1256. pa = "TRUE" == a.getFieldValue("76") ? "1" : "0";
  1257. a = "TRUE" == a.getFieldValue("77") ? "1" : "0";
  1258. b = parseInt(b + c + d + e + f + g + h + k, 2);
  1259. l = parseInt(l + u + v + w + x + y + z + A, 2);
  1260. m = parseInt(m + B + C + D + E + F + G + H, 2);
  1261. n = parseInt(n + I + J + K + L + M + N + O, 2);
  1262. p = parseInt(p + P + Q + R + S + T + U + V, 2);
  1263. q = parseInt(q + W + X + Y + Z + aa + ba + ca, 2);
  1264. r = parseInt(r + da + ea + fa + ga + ha + ia + ja, 2);
  1265. t = parseInt(t + ka + la + ma + na + oa + pa + a, 2);
  1266. return "matrix.bitmap(bytearray([" + b + ", " + l + ", " + m + ", " + n + ", " + p + ", " + q + ", " + r + ", " + t + "]))\nmatrix.show()\n"
  1267. };
  1268. Blockly.Python.CocoRobo_bluebit_matrix_fill = function (a) {
  1269. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1270. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1271. a = a.getFieldValue("fill_clear");
  1272. Blockly.Python.codeFunctions_.init_matrix = "matrix \x3d Matrix()";
  1273. return "matrix.fill(" + a + ")\nmatrix.show()\n"
  1274. };
  1275. Blockly.Python.CocoRobo_bluebit_matrix_brightness = function (a) {
  1276. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1277. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1278. Blockly.Python.codeFunctions_.init_matrix = "matrix \x3d Matrix()";
  1279. return "matrix.brightness(" + Blockly.Python.valueToCode(a, "brightness_level", Blockly.Python.ORDER_ATOMIC) + ")\n"
  1280. };
  1281. Blockly.Python.CocoRobo_bluebit_midi_play = function (a) {
  1282. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1283. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1284. var b = a.getFieldValue("play_stop");
  1285. return "midi.note(" + Blockly.Python.valueToCode(a, "play_note", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
  1286. };
  1287. Blockly.Python.CocoRobo_bluebit_midi_instrument = function (a) {
  1288. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1289. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1290. return "midi.instrument \x3d " + a.getFieldValue("midi_instrument") + "\n"
  1291. };
  1292. Blockly.Python.CocoRobo_bluebit_midi_volume = function (a) {
  1293. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1294. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1295. return "midi.volume \x3d " + Blockly.Python.valueToCode(a, "midi_volume", Blockly.Python.ORDER_ATOMIC) + "\n"
  1296. };
  1297. Blockly.Python.CocoRobo_bluebit_init_midi = function (a) {
  1298. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1299. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1300. a = Blockly.Python.valueToCode(a, "midi_tx", Blockly.Python.ORDER_ATOMIC);
  1301. Blockly.Python.codeFunctions_.init_midi = "midi \x3d MIDI(Pin.P" + a + ")";
  1302. return ""
  1303. };
  1304. Blockly.Python.CocoRobo_bluebit_get_all_color = function (a) {
  1305. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1306. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1307. Blockly.Python.codeFunctions_.init_color = "color \x3d Color()";
  1308. return ["color.getRGB()", Blockly.Python.ORDER_ATOMIC]
  1309. };
  1310. Blockly.Python.CocoRobo_bluebit_get_color = function (a) {
  1311. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1312. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1313. Blockly.Python.codeFunctions_.init_color = "color \x3d Color()";
  1314. return ["color.getRGB()[" + a.getFieldValue("r_g_b") + "]", Blockly.Python.ORDER_ATOMIC]
  1315. };
  1316. Blockly.Python.CocoRobo_bluebit_get_all_color_hsv = function (a) {
  1317. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1318. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1319. Blockly.Python.codeFunctions_.init_color = "color \x3d Color()";
  1320. return ["color.getHSV()", Blockly.Python.ORDER_ATOMIC]
  1321. };
  1322. Blockly.Python.CocoRobo_bluebit_get_color_hsv = function (a) {
  1323. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1324. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1325. Blockly.Python.codeFunctions_.init_color = "color \x3d Color()";
  1326. return ["color.getHSV()[" + a.getFieldValue("hsv") + "]", Blockly.Python.ORDER_ATOMIC]
  1327. };
  1328. Blockly.Python.CocoRobo_bluebit_get_force_measure = function (a) {
  1329. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1330. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1331. a = a.getFieldValue("measure");
  1332. Blockly.Python.codeFunctions_["init_delveBit_force" + a] = "delveBit_force_" + ("0X64" === a ? "0" : "0X65" === a ? "1" : "0X66" === a ? "2" : "3") + " \x3d DelveBit(" + a + ")";
  1333. return ["delveBit_force_" + ("0X64" === a ? "0" : "0X65" === a ? "1" : "0X66" === a ? "2" : "3") + ".common_measure()", Blockly.Python.ORDER_ATOMIC]
  1334. };
  1335. Blockly.Python.CocoRobo_bluebit_get_electricity_measure = function (a) {
  1336. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1337. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1338. a = a.getFieldValue("measure");
  1339. Blockly.Python.codeFunctions_["init_delveBit_electricity" + a] = "delveBit_electricity_" + ("0X60" === a ? "0" : "0X61" === a ? "1" : "0X62" === a ? "2" : "3") + " \x3d DelveBit(" + a + ")";
  1340. return ["delveBit_electricity_" + ("0X60" === a ? "0" : "0X61" === a ? "1" : "0X62" === a ? "2" : "3") + ".common_measure()", Blockly.Python.ORDER_ATOMIC]
  1341. };
  1342. Blockly.Python.CocoRobo_bluebit_get_voltage_measure = function (a) {
  1343. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1344. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1345. a = a.getFieldValue("measure");
  1346. Blockly.Python.codeFunctions_["init_delveBit_voltage" + a] = "delveBit_voltage_" + ("0X6A" === a ? "0" : "0X6B" === a ? "1" : "0X6C" === a ? "2" : "3") + " \x3d DelveBit(" + a + ")";
  1347. return ["delveBit_voltage_" + ("0X6A" === a ? "0" : "0X6B" === a ? "1" : "0X6C" === a ? "2" : "3") + ".common_measure()", Blockly.Python.ORDER_ATOMIC]
  1348. };
  1349. Blockly.Python.CocoRobo_bluebit_get_magnetic_measure = function (a) {
  1350. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1351. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1352. a = a.getFieldValue("measure");
  1353. Blockly.Python.codeFunctions_["init_delveBit_magnetic" + a] = "delveBit_magnetic_" + ("0X58" === a ? "0" : "0X59" === a ? "1" : "0X5A" === a ? "2" : "3") + " \x3d DelveBit(" + a + ")";
  1354. return ["delveBit_magnetic_" + ("0X58" === a ? "0" : "0X59" === a ? "1" : "0X5A" === a ? "2" : "3") + ".common_measure()", Blockly.Python.ORDER_ATOMIC]
  1355. };
  1356. Blockly.Python.CocoRobo_bluebit_get_PH_measure = function (a) {
  1357. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1358. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1359. a = a.getFieldValue("measure");
  1360. Blockly.Python.codeFunctions_["init_delveBit_PH" + a] = "delveBit_PH_" + ("0X54" === a ? "0" : "1") + " \x3d DelveBit(" + a + ")";
  1361. return ["delveBit_PH_" + ("0X54" === a ? "0" : "1") + ".common_measure()", Blockly.Python.ORDER_ATOMIC]
  1362. };
  1363. Blockly.Python.CocoRobo_bluebit_get_tds_measure = function (a) {
  1364. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1365. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1366. a = a.getFieldValue("measure");
  1367. Blockly.Python.codeFunctions_["init_delveBit_tds" + a] = "delveBit_tds_" + ("0X68" === a ? "0" : "1") + " \x3d DelveBit(" + a + ")";
  1368. return ["delveBit_tds_" + ("0X68" === a ? "0" : "1") + ".common_measure()", Blockly.Python.ORDER_ATOMIC]
  1369. };
  1370. Blockly.Python.CocoRobo_bluebit_get_pressure_measure = function (a) {
  1371. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1372. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1373. a = a.getFieldValue("measure");
  1374. Blockly.Python.codeFunctions_["init_delveBit_pressure" + a] = "delveBit_pressure_" + ("0X5C" === a ? "0" : "0X5D" === a ? "1" : "0X5E" === a ? "2" : "3") + " \x3d DelveBit(" + a + ")";
  1375. return ["delveBit_pressure_" + ("0X5C" === a ? "0" : "0X5D" === a ? "1" : "0X5E" === a ? "2" : "3") + ".common_measure()", Blockly.Python.ORDER_ATOMIC]
  1376. };
  1377. Blockly.Python.CocoRobo_bluebit_get_photogate_timer_measure = function (a) {
  1378. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1379. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1380. a = a.getFieldValue("measure");
  1381. Blockly.Python.codeFunctions_["init_delveBit_photo" + a] = "delveBit_photo_" + ("0X50" === a ? "0" : "1") + " \x3d DelveBit(" + a + ")";
  1382. return ["delveBit_photo_" + ("0X50" === a ? "0" : "1") + ".photo_gate()", Blockly.Python.ORDER_ATOMIC]
  1383. };
  1384. Blockly.Python.CocoRobo_init_assistant_wifi = function (a) {
  1385. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1386. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1387. Blockly.Python.definitions_.CocoRobo_bluebit_assistant_wifi = "def wifi_config(ssid, password):\n data_len_L \x3d 96 \x26 0xff\n data_len_H \x3d 96 \x3e\x3e 8\n checkSum \x3d data_len_L + data_len_H + 0x01 + 0x01\n n1 \x3d [0xff, 0x55, data_len_L, data_len_H, 0x01, 0x01]\n wifi_ssid \x3d bytes(ssid, 'utf-8')\n list_wifi_ssid \x3d [0]*32\n for i in range(0, len(wifi_ssid)):\n list_wifi_ssid[i] \x3d wifi_ssid[i]\n for i in range(0, 32):\n checkSum +\x3d list_wifi_ssid[i]\n wifi_pwd \x3d bytes(password, 'utf-8')\n list_wifi_pwd \x3d [0]*64\n for i in range(0, len(wifi_pwd)):\n list_wifi_pwd[i] \x3d wifi_pwd[i]\n for i in range(0, 64):\n checkSum +\x3d list_wifi_pwd[i]\n n \x3d n1 + list_wifi_ssid + list_wifi_pwd\n n.append(checkSum \x26 0xff)\n return bytes(n)\n";
  1388. var b = Blockly.Python.valueToCode(a, "ssid", Blockly.Python.ORDER_ATOMIC);
  1389. a = Blockly.Python.valueToCode(a, "password", Blockly.Python.ORDER_ATOMIC);
  1390. return ["wifi_config(" + b + ", " + a + ")", Blockly.Python.ORDER_ATOMIC]
  1391. };
  1392. Blockly.Python.CocoRobo_init_assistant_profile = function(a) {
  1393. Blockly.Python.definitions_.CocoRobo_bluebit_assistant_profile = "def dueros_profile_config(duer_profile):\n data_len_L \x3d len(duer_profile) \x26 0xff\n data_len_H \x3d len(duer_profile) \x3e\x3e 8\n checkSum \x3d data_len_L + data_len_H + 0x02 + 0x02\n n1 \x3d [0xff, 0x55, data_len_L, data_len_H, 0x02, 0x02]\n for i in range(0, len(duer_profile)):\n checkSum +\x3d duer_profile[i]\n n \x3d n1 + list(duer_profile)\n n.append(checkSum \x26 0xff)\n return bytes(n)\n";
  1394. return "f \x3d open(" + Blockly.Python.valueToCode(a, "file_path", Blockly.Python.ORDER_ATOMIC) + ", 'rb')\nduer_profile \x3d f.read()\nprofile \x3d dueros_profile_config(duer_profile)\nf.close()\nuart1.write(profile)\n"
  1395. };
  1396. Blockly.Python.CocoRobo_bluebit_seg_clear = function (a) {
  1397. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1398. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1399. Blockly.Python.codeFunctions_.init_seg = "seg \x3d SEGdisplay()";
  1400. return "seg.Clear()\n"
  1401. };
  1402. Blockly.Python.CocoRobo_bluebit_seg_display = function (a) {
  1403. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1404. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1405. Blockly.Python.codeFunctions_.init_seg = "seg \x3d SEGdisplay()";
  1406. return "seg.numbers(" + Blockly.Python.valueToCode(a, "seg_num", Blockly.Python.ORDER_ATOMIC) + ")\n"
  1407. };
  1408. Blockly.Python.CocoRobo_bluebit_ambientlight = function (a) {
  1409. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1410. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1411. Blockly.Python.codeFunctions_.init_AmbientLight = "ambientLight \x3d AmbientLight()";
  1412. return ["ambientLight.getLight()", Blockly.Python.ORDER_ATOMIC]
  1413. };
  1414. Blockly.Python.CocoRobo_bluebit_hum_tem = function (a) {
  1415. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1416. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1417. Blockly.Python.codeFunctions_.init_SHT20 = "sht20 \x3d SHT20()";
  1418. return ["sht20." + a.getFieldValue("hum_tem") + "()", Blockly.Python.ORDER_ATOMIC]
  1419. };
  1420. Blockly.Python.CocoRobo_bluebit_ultrasonic = function (a) {
  1421. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1422. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1423. Blockly.Python.codeFunctions_.init_Ultrasonic = "ultrasonic \x3d Ultrasonic()";
  1424. return ["ultrasonic.distance()", Blockly.Python.ORDER_ATOMIC]
  1425. };
  1426. Blockly.Python.CocoRobo_bluebit_read_digital = function (a) {
  1427. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1428. a = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC);
  1429. Blockly.Python.definitions_["set_PinMode_in_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.IN)";
  1430. Blockly.Python.codeFunctions_["boolean_P" + a] = "def boolean_P" + a + "():\n return p" + a + ".read_digital() \x3d\x3d 1";
  1431. return ["boolean_P" + a + "()", Blockly.Python.ORDER_ATOMIC]
  1432. };
  1433. Blockly.Python.CocoRobo_bluebit_line_follower = function (a) {
  1434. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1435. a = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC);
  1436. Blockly.Python.definitions_["set_PinMode_in_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.IN)";
  1437. Blockly.Python.codeFunctions_["boolean_P" + a] = "def boolean_P" + a + "():\n return p" + a + ".read_digital() \x3d\x3d 1";
  1438. return ["boolean_P" + a + "()", Blockly.Python.ORDER_ATOMIC]
  1439. };
  1440. Blockly.Python.CocoRobo_bluebit_set_true = function (a) {
  1441. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1442. a = Blockly.Python.valueToCode(a, "set_digital_P", Blockly.Python.ORDER_ATOMIC);
  1443. Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.OUT)";
  1444. return "p" + a + ".write_digital(1)\n"
  1445. };
  1446. Blockly.Python.CocoRobo_bluebit_set_false = function (a) {
  1447. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1448. a = Blockly.Python.valueToCode(a, "set_digital_P", Blockly.Python.ORDER_ATOMIC);
  1449. Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.OUT)";
  1450. return "p" + a + ".write_digital(0)\n"
  1451. };
  1452. Blockly.Python.CocoRobo_bluebit_read_analog = function (a) {
  1453. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1454. Blockly.Python.definitions_.import_math = "import math";
  1455. var b = a.getFieldValue("analog_senor");
  1456. a = Blockly.Python.valueToCode(a, "read_analog_P", Blockly.Python.ORDER_ATOMIC);
  1457. Blockly.Python.definitions_["set_PinMode_in_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.ANALOG)";
  1458. return ["_LM35" == b ? "p" + a + ".read_analog() * (3/40.96)" : "_NTC" == b ? "1/(math.log(4096/p" + a + ".read_analog()-1)/3935+1/298)-273" : "p" + a + ".read_analog()", Blockly.Python.ORDER_ATOMIC]
  1459. };
  1460. Blockly.Python.CocoRobo_bluebit_set_analog = function (a) {
  1461. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1462. var b = Blockly.Python.valueToCode(a, "analog_value", Blockly.Python.ORDER_ATOMIC);
  1463. a = Blockly.Python.valueToCode(a, "set_analog_P", Blockly.Python.ORDER_ATOMIC);
  1464. Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.PWM)";
  1465. return "p" + a + ".write_analog(" + b + ")\n"
  1466. };
  1467. Blockly.Python.CocoRobo_bluebit_voice_record_on = function (a) {
  1468. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1469. var b = a.getFieldValue("func"),
  1470. c = Blockly.Python.valueToCode(a, "rec", Blockly.Python.ORDER_ATOMIC);
  1471. a = Blockly.Python.valueToCode(a, "play", Blockly.Python.ORDER_ATOMIC);
  1472. Blockly.Python.definitions_["set_PinMode_out_" + c] = "p" + c + " \x3d CocoRoboPin(" + c + ", PinMode.OUT)";
  1473. Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.OUT)";
  1474. return "play" == b ? "p" + c + ".write_digital(0)\np" + a + ".write_digital(1)\n" : "p" + a + ".write_digital(0)\np" + c + ".write_digital(1)\n"
  1475. };
  1476. Blockly.Python.CocoRobo_bluebit_voice_record_off = function (a) {
  1477. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1478. var b = Blockly.Python.valueToCode(a, "rec", Blockly.Python.ORDER_ATOMIC);
  1479. a = Blockly.Python.valueToCode(a, "play", Blockly.Python.ORDER_ATOMIC);
  1480. Blockly.Python.definitions_["set_PinMode_out_" + b] = "p" + b + " \x3d CocoRoboPin(" + b + ", PinMode.OUT)";
  1481. Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.OUT)";
  1482. return "p" + b + ".write_digital(0)\np" + a + ".write_digital(0)\n"
  1483. };
  1484. Blockly.Python.CocoRobo_m1m2_led_on = function(a) {
  1485. Blockly.Python.definitions_.import_parrot = "import parrot";
  1486. var b = a.getFieldValue("m1m2");
  1487. a = Blockly.Python.valueToCode(a, "brightness", Blockly.Python.ORDER_ATOMIC);
  1488. return "parrot.set_speed(parrot.MOTOR_" + b + ", -" + a + ")\n"
  1489. };
  1490. Blockly.Python.CocoRobo_m1m2_led_off = function(a) {
  1491. Blockly.Python.definitions_.import_parrot = "import parrot";
  1492. return "parrot.led_off(parrot.MOTOR_" + a.getFieldValue("m1m2") + ")\n"
  1493. };
  1494. Blockly.Python.CocoRobo_bluebit_motor_on = function (a) {
  1495. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1496. var b = Blockly.Python.valueToCode(a, "ain1", Blockly.Python.ORDER_ATOMIC),
  1497. c = Blockly.Python.valueToCode(a, "ain2", Blockly.Python.ORDER_ATOMIC);
  1498. Blockly.Python.definitions_["set_PinMode_out_" + b] = "p" + b + " \x3d CocoRoboPin(" + b + ", PinMode.PWM)";
  1499. Blockly.Python.definitions_["set_PinMode_out_" + c] = "p" + c + " \x3d CocoRoboPin(" + c + ", PinMode.PWM)";
  1500. var d = a.getFieldValue("status");
  1501. a = Blockly.Python.valueToCode(a, "speed", Blockly.Python.ORDER_ATOMIC);
  1502. 0 >= a && (a = 1);
  1503. return "1" == d ? "speed \x3d " + a + "\nspeed \x3d int(numberMap(speed, 0, 100, 0, 1023))\np" + b + ".write_analog(speed)\nsleep_ms(2)\np" + c + ".write_analog(0)\nsleep_ms(2)\n" : "speed \x3d " + a + "\nspeed \x3d int(numberMap(speed, 0, 100, 0, 1023))\np" + c + ".write_analog(speed)\nsleep_ms(2)\np" + b + ".write_analog(0)\nsleep_ms(2)\n"
  1504. };
  1505. Blockly.Python.CocoRobo_bluebit_motor_off = function (a) {
  1506. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1507. var b = Blockly.Python.valueToCode(a, "ain1", Blockly.Python.ORDER_ATOMIC);
  1508. a = Blockly.Python.valueToCode(a, "ain2", Blockly.Python.ORDER_ATOMIC);
  1509. Blockly.Python.definitions_["set_PinMode_out_" + b] = "p" + b + " \x3d CocoRoboPin(" + b + ", PinMode.PWM)";
  1510. Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.PWM)";
  1511. return "p" + b + ".write_analog(0)\nsleep_ms(2)\np" + a + ".write_analog(0)\nsleep_ms(2)\n"
  1512. };
  1513. Blockly.Python.CocoRobo_bluebit_get_motorpeed = function(a) {
  1514. Blockly.Python.definitions_.import_parrot = "import parrot";
  1515. return ["parrot.get_speed(parrot.MOTOR_" + a.getFieldValue("left_right_interface") + ")", Blockly.Python.ORDER_ATOMIC]
  1516. };
  1517. Blockly.Python.CocoRobo_bluebit_set_Fan = function(a) {
  1518. Blockly.Python.definitions_.import_parrot = "import parrot";
  1519. return "parrot.set_speed(parrot.MOTOR_" + a.getFieldValue("left_right_interface") + ", -100)\n"
  1520. };
  1521. Blockly.Python.CocoRobo_bluebit_set_Fan_off = function(a) {
  1522. Blockly.Python.definitions_.import_parrot = "import parrot";
  1523. return "parrot.set_speed(parrot.MOTOR_" + a.getFieldValue("left_right_interface") + ", 0)\n"
  1524. };
  1525. Blockly.Python.CocoRobo_bluebit_4button = function (a) {
  1526. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1527. Blockly.Python.definitions_.CocoRobo_bluebit_4button = "def get4ButtonVal(index, pin):\n val \x3d pin.read_analog()\n btn \x3d 0\n if val \x3c 100:\n btn \x3d 'A'\n elif val \x3e 600 and val \x3c 1023:\n btn \x3d 'B'\n elif val \x3e 1700 and val \x3c 2048:\n btn \x3d 'C'\n elif val \x3e 2700 and val \x3c 3200:\n btn \x3d 'D'\n return btn \x3d\x3d index\n";
  1528. var b = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
  1529. a = a.getFieldValue("button_val");
  1530. Blockly.Python.definitions_["set_PinMode_in_" + b] = "p" + b + " \x3d CocoRoboPin(" + b + ", PinMode.ANALOG)";
  1531. return ["get4ButtonVal(" + a + ", p" + b + ")", Blockly.Python.ORDER_ATOMIC]
  1532. };
  1533. Blockly.Python.CocoRobo_bluebit_joystick = function (a) {
  1534. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1535. var b = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC),
  1536. c = Blockly.Python.valueToCode(a, "pin1", Blockly.Python.ORDER_ATOMIC);
  1537. Blockly.Python.definitions_["set_PinMode_in_" + b] = "p" + b + " \x3d CocoRoboPin(" + b + ", PinMode.ANALOG)";
  1538. Blockly.Python.definitions_["set_PinMode_in_" + c] = "p" + c + " \x3d CocoRoboPin(" + c + ", PinMode.ANALOG)";
  1539. return ["p" + ("X" == a.getFieldValue("axis") ? c : b) + ".read_analog()", Blockly.Python.ORDER_ATOMIC]
  1540. };
  1541. Blockly.Python.CocoRobo_bluebit_motor_on_i2c = function(a) {
  1542. Blockly.Python.definitions_.import_parrot = "import parrot";
  1543. var b = a.getFieldValue("left_right_interface"),
  1544. c = a.getFieldValue("status");
  1545. a = Blockly.Python.valueToCode(a, "speed", Blockly.Python.ORDER_ATOMIC);
  1546. switch (b) {
  1547. case "M1":
  1548. var d = "parrot.set_speed(parrot.MOTOR_1";
  1549. break;
  1550. case "M2":
  1551. d = "parrot.set_speed(parrot.MOTOR_2"
  1552. }
  1553. switch (c) {
  1554. case "CLOCKWISE":
  1555. var e = ", ";
  1556. break;
  1557. case "ANTICLOCKWISE":
  1558. e = ", -"
  1559. }
  1560. return d + e + a + ")\n"
  1561. };
  1562. Blockly.Python.CocoRobo_bluebit_motor_off_i2c = function(a) {
  1563. Blockly.Python.definitions_.import_parrot = "import parrot";
  1564. return "parrot.set_speed(parrot.MOTOR_1, 0)\nparrot.set_speed(parrot.MOTOR_2, 0)\n"
  1565. };
  1566. Blockly.Python.CocoRobo_bluebit_coded_three_motor_on_i2c = function(a) {
  1567. Blockly.Python.tops_.import_machine = "import machine\np19 \x3d machine.Pin(machine.Pin.P19, machine.Pin.OPEN_DRAIN, None, value\x3d0)";
  1568. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1569. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1570. var b = Blockly.Python.valueToCode(a, "speed1", Blockly.Python.ORDER_ATOMIC),
  1571. c = Blockly.Python.valueToCode(a, "speed2", Blockly.Python.ORDER_ATOMIC),
  1572. d = a.getFieldValue("Dial_code");
  1573. a = a.getFieldValue("pattern");
  1574. Blockly.Python.codeFunctions_["init_encoderMotor_pwm" + d] = "encoderMotor_pwm_" + ("0X10" === d ? "0" : "0X11" === d ? "1" : "0X12" === d ? "2" : "3") + " \x3d EncoderMotor(" + d + ")";
  1575. return "encoderMotor_pwm_" + ("0X10" === d ? "0" : "0X11" === d ? "1" : "0X12" === d ? "2" : "3") + "." + a + "(" + b + ", " + c + ")\n"
  1576. };
  1577. Blockly.Python.CocoRobo_bluebit_coded_stop_motor_on_i2c = function(a) {
  1578. Blockly.Python.tops_.import_machine = "import machine\np19 \x3d machine.Pin(machine.Pin.P19, machine.Pin.OPEN_DRAIN, None, value\x3d0)";
  1579. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1580. Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
  1581. a = a.getFieldValue("coded_stop");
  1582. Blockly.Python.codeFunctions_["init_encoderMotor_stop" + a] = "encoderMotor_stop_" + ("0X10" === a ? "0" : "0X11" === a ? "1" : "0X12" === a ? "2" : "3") + " \x3d EncoderMotor(" + a + ")";
  1583. return "encoderMotor_stop_" + ("0X10" === a ? "0" : "0X11" === a ? "1" : "0X12" === a ? "2" : "3") + ".motor_stop()\n"
  1584. };
  1585. Blockly.Python.CocoRobo_init_bluetooth = function (a) {
  1586. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1587. Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
  1588. a = Blockly.Python.valueToCode(a, "init_bluetooth", Blockly.Python.ORDER_ATOMIC);
  1589. Blockly.Python.definitions_.bluetooth_define = "ble.init(" + a + ")";
  1590. return ""
  1591. };
  1592. Blockly.Python.CocoRobo_OnOff_bluetooth = function (a) {
  1593. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1594. Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
  1595. return "ble." + a.getFieldValue("OnOff_bluetooth") + "_advertising()\n"
  1596. };
  1597. Blockly.Python.CocoRobo_HID_consumer_bluetooth = function (a) {
  1598. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1599. var b = a.getFieldValue("status_bar");
  1600. return "ble.hidd_send_consumer(" + a.getFieldValue("type") + ", " + b + ")\n"
  1601. };
  1602. Blockly.Python.CocoRobo_HID_keyboard_bluetooth = function (a) {
  1603. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1604. Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
  1605. return "ble.hidd_send_keyboard([" + a.getFieldValue("HID_keyboard_bluetooth") + "])\n"
  1606. };
  1607. Blockly.Python.CocoRobo_HID_release_keyboard_bluetooth = function (a) {
  1608. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1609. Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
  1610. return "ble.hidd_send_keyboard([0])\n"
  1611. };
  1612. Blockly.Python.CocoRobo_HID_mouse_bluetooth = function (a) {
  1613. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1614. Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
  1615. return "ble.hidd_send_mouse(" + a.getFieldValue("HID_mouse") + ")\n"
  1616. };
  1617. Blockly.Python.CocoRobo_HID_release_mouse_bluetooth = function (a) {
  1618. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1619. Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
  1620. return "ble.hidd_send_mouse([0])\n"
  1621. };
  1622. Blockly.Python.CocoRobo_HID_mouse_pointer_bluetooth = function (a) {
  1623. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1624. Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
  1625. var b = Blockly.Python.valueToCode(a, "row", Blockly.Python.ORDER_ATOMIC);
  1626. return "ble.hidd_send_mouse(" + Blockly.Python.valueToCode(a, "column", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
  1627. };
  1628. Blockly.Python.CocoRobo_HID_keyboard_group_bluetooth = function (a) {
  1629. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1630. Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
  1631. var b = Blockly.Python.valueToCode(a, "group", Blockly.Python.ORDER_ATOMIC);
  1632. return "ble.hidd_send_keyboard([" + a.getFieldValue("HID_keyboard_bluetooth") + "]," + b + ")\n"
  1633. };
  1634. Blockly.Python.CocoRobo_HID_keyboard_part_bluetooth = function (a) {
  1635. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1636. Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
  1637. return [a.getFieldValue("HID_keyboard_group"), Blockly.Python.ORDER_ATOMIC]
  1638. };
  1639. Blockly.Python.dict_create_with_items_insert = function() {
  1640. for (var a = Array(this.itemCount_), b = 0; b < this.itemCount_; b++) {
  1641. var c = this.getFieldValue("KEY" + b);
  1642. a[b] = '"' + c + '":' + (Blockly.Python.valueToCode(this, "ADD" + b, Blockly.Python.ORDER_NONE) || "0")
  1643. }
  1644. a = "{" + a.join(", ") + "}";
  1645. return [a, Blockly.Python.ORDER_ATOMIC]
  1646. };
  1647. Blockly.Python.pinyin_dict_create_with_items_insert = function() {
  1648. for (var a = Array(this.itemCount_), b = 0; b < this.itemCount_; b++) {
  1649. var c = this.getFieldValue("KEY" + b);
  1650. a[b] = '"' + c + '":' + (Blockly.Python.valueToCode(this, "ADD" + b, Blockly.Python.ORDER_NONE) || "0")
  1651. }
  1652. a = "{" + a.join(", ") + "}";
  1653. return [a, Blockly.Python.ORDER_ATOMIC]
  1654. };
  1655. Blockly.Python.robot_dog_pinyin_dict_create_with_items_insert = function() {
  1656. for (var a = Array(this.itemCount_), b = 0; b < this.itemCount_; b++) {
  1657. var c = this.getFieldValue("KEY" + b);
  1658. a[b] = '"' + c + '":' + (Blockly.Python.valueToCode(this, "ADD" + b, Blockly.Python.ORDER_NONE) || "0")
  1659. }
  1660. a = "{" + a.join(", ") + "}";
  1661. return [a, Blockly.Python.ORDER_ATOMIC]
  1662. };
  1663. Blockly.Python.dict_create_with = function(a) {
  1664. var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC);
  1665. a = Blockly.Python.valueToCode(a, "dict_items", Blockly.Python.ORDER_ATOMIC);
  1666. return b + " \x3d " + a + "\n"
  1667. };
  1668. Blockly.Python.dict_key_value = function(a) {
  1669. var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC);
  1670. a = Blockly.Python.valueToCode(a, "dict_items", Blockly.Python.ORDER_ATOMIC);
  1671. return [b + ".get(" + a + ")", Blockly.Python.ORDER_ATOMIC]
  1672. };
  1673. Blockly.Python.add_dict_key_value = function(a) {
  1674. var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC),
  1675. c = Blockly.Python.valueToCode(a, "dict_items", Blockly.Python.ORDER_ATOMIC);
  1676. a = Blockly.Python.valueToCode(a, "add_value", Blockly.Python.ORDER_ATOMIC);
  1677. return b + "[" + c + "] \x3d " + a + "\n"
  1678. };
  1679. Blockly.Python.dict_length = function(a) {
  1680. return ["len(" + Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
  1681. };
  1682. Blockly.Python.dict_key_exist = function(a) {
  1683. var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC);
  1684. return [Blockly.Python.valueToCode(a, "dict_items", Blockly.Python.ORDER_ATOMIC) + " in " + b, Blockly.Python.ORDER_ATOMIC]
  1685. };
  1686. Blockly.Python.dict_key_or_val_list = function(a) {
  1687. var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC);
  1688. a = a.getFieldValue("key_or_val");
  1689. return ["list(" + b + "." + a + "())", Blockly.Python.ORDER_ATOMIC]
  1690. };
  1691. Blockly.Python.CocoRobo_input = function(a) {
  1692. return ["input(" + Blockly.Python.valueToCode(a, "imports", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
  1693. };
  1694. Blockly.Python.file_to_list = function(a) {
  1695. var b = Blockly.Python.valueToCode(a, "file_path", Blockly.Python.ORDER_ATOMIC);
  1696. a = a.getFieldValue("separator");
  1697. "ENTER" == a && (a = "\\r\\n");
  1698. Blockly.Python.definitions_.def_get_list_from_file = "def get_list_from_file(_path, _sep):\n f \x3d open(_path, 'r')\n result \x3d f.read().split(_sep)\n f.close()\n return result\n";
  1699. return ["get_list_from_file(" + b + ", '" + a + "')", Blockly.Python.ORDER_ATOMIC]
  1700. };
  1701. Blockly.Python.file_to_bin = function(a) {
  1702. a = Blockly.Python.valueToCode(a, "file_path", Blockly.Python.ORDER_ATOMIC);
  1703. Blockly.Python.definitions_.def_get_bin_from_file = "def get_bin_from_file(_path):\n f \x3d open(_path, 'rb')\n result \x3d f.read()\n f.close()\n return result\n";
  1704. return ["get_bin_from_file(" + a + ")", Blockly.Python.ORDER_ATOMIC]
  1705. };
  1706. Blockly.Python.CocoRobo_init_file = function(a) {
  1707. a = Blockly.Python.valueToCode(a, "file_path", Blockly.Python.ORDER_ATOMIC);
  1708. Blockly.Python.definitions_.def_init_text_file = "def init_text_file(_path):\n f \x3d open(_path, 'w')\n f.close()\n";
  1709. return "init_text_file(" + a + ")\n"
  1710. };
  1711. Blockly.Python.CocoRobo_write_file = function(a) {
  1712. var b = Blockly.Python.valueToCode(a, "file_path", Blockly.Python.ORDER_ATOMIC),
  1713. c = Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC);
  1714. a = a.getFieldValue("separator");
  1715. "ENTER" == a && (a = "\\r\\n");
  1716. Blockly.Python.definitions_.def_write_data_to_file = "def write_data_to_file(_path, _data, _sep):\n f \x3d open(_path, 'a')\n f.write(_data + _sep)\n f.close()\n";
  1717. return code = "write_data_to_file(" + b + ", " + c + ", '" + a + "')\n"
  1718. };
  1719. Blockly.Python.CocoRobo_sdcard_init = function (a) {
  1720. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1721. Blockly.Python.definitions_.import_machine = "import machine";
  1722. Blockly.Python.definitions_.import_sdcard = "import sdcard";
  1723. Blockly.Python.definitions_.sdcard_init = "spi \x3d machine.SPI(1, baudrate\x3d10000000, polarity\x3d0, phase\x3d0, sck\x3dPin(Pin.P13), mosi\x3dPin(Pin.P15), miso\x3dPin(Pin.P14))\nsd \x3d sdcard.SDCard(spi, Pin(Pin.P16))\n";
  1724. return ""
  1725. };
  1726. Blockly.Python.CocoRobo_sdcard_mount = function(a) {
  1727. Blockly.Python.definitions_.import_os = "import os";
  1728. return "os.mount(sd, " + Blockly.Python.valueToCode(a, "sd_path", Blockly.Python.ORDER_ATOMIC) + ")\n"
  1729. };
  1730. Blockly.Python.CocoRobo_dev_i2c_init = function (a) {
  1731. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1732. var b = Blockly.Python.valueToCode(a, "scl", Blockly.Python.ORDER_ATOMIC),
  1733. c = Blockly.Python.valueToCode(a, "sda", Blockly.Python.ORDER_ATOMIC);
  1734. a = Blockly.Python.valueToCode(a, "freq", Blockly.Python.ORDER_ATOMIC);
  1735. return "i2c \x3d I2C(scl\x3dPin(Pin.P" + b + "), sda\x3dPin(Pin.P" + c + "), freq\x3d" + a + ")\n"
  1736. };
  1737. Blockly.Python.CocoRobo_i2c_init = function (a) {
  1738. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1739. return "i2c \x3d I2C(scl\x3dPin(Pin.P19), sda\x3dPin(Pin.P20), freq\x3d" + Blockly.Python.valueToCode(a, "freq", Blockly.Python.ORDER_ATOMIC) + ")\n"
  1740. };
  1741. Blockly.Python.CocoRobo_i2c_read_write = function (a) {
  1742. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1743. var b = Blockly.Python.valueToCode(a, "adr", Blockly.Python.ORDER_ATOMIC);
  1744. a = Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC);
  1745. return "i2c.writeto(" + b + ", " + a + ")\n"
  1746. };
  1747. Blockly.Python.CocoRobo_i2c_readfrom = function (a) {
  1748. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  1749. var b = Blockly.Python.valueToCode(a, "adr", Blockly.Python.ORDER_ATOMIC);
  1750. a = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC);
  1751. return "str(i2c.readfrom(" + b + ", " + a + "))\n"
  1752. };
  1753. Blockly.Python.mqtt_common_setup = function(a) {
  1754. Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
  1755. var b = Blockly.Python.valueToCode(a, "client_id", Blockly.Python.ORDER_ATOMIC),
  1756. c = Blockly.Python.valueToCode(a, "server", Blockly.Python.ORDER_ATOMIC),
  1757. d = Blockly.Python.valueToCode(a, "port", Blockly.Python.ORDER_ATOMIC),
  1758. e = Blockly.Python.valueToCode(a, "user", Blockly.Python.ORDER_ATOMIC),
  1759. f = Blockly.Python.valueToCode(a, "password", Blockly.Python.ORDER_ATOMIC);
  1760. a = Blockly.Python.valueToCode(a, "keepalive", Blockly.Python.ORDER_ATOMIC);
  1761. Blockly.Python.definitions_.mqtt_setup = "mqtt \x3d MQTTClient(" + b + ", " + c + ", " + d + ", " + e + ", " + f + ", " + a + ")";
  1762. return ""
  1763. };
  1764. Blockly.Python.mqtt_tencent_setup = function(a) {
  1765. Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
  1766. Blockly.Python.definitions_.import_urequests = "import urequests";
  1767. Blockly.Python.definitions_.import_json = "import json";
  1768. var b = Blockly.Python.valueToCode(a, "Url", Blockly.Python.ORDER_ATOMIC),
  1769. c = Blockly.Python.valueToCode(a, "Port", Blockly.Python.ORDER_ATOMIC),
  1770. d = Blockly.Python.valueToCode(a, "AppId", Blockly.Python.ORDER_ATOMIC);
  1771. a = Blockly.Python.valueToCode(a, "Device", Blockly.Python.ORDER_ATOMIC);
  1772. Blockly.Python.definitions_.mqtt_tencent_setup = '_response \x3d urequests.post("https://ocpdev.learn.tencent.com/v1/device/login/get_tls_key", data\x3djson.dumps({"AppId":' + d + ', "Device":' + a + '}))\ntry:\n _Rsp \x3d _response.json()\n if "Response" in _Rsp:\n _RspData \x3d _Rsp.get("Response").get("Data")\n _ClientId \x3d _RspData.get("ClientId")\n _UserName \x3d _RspData.get("UserName")\n _Password \x3d _RspData.get("Password")\n _ReportTopic \x3d _RspData.get("ReportTopic")\n _ControlTopic \x3d _RspData.get("ControlTopic")\n _CA\x3d_RspData.get("CA")\n _ShadowResultTopic\x3d_RspData.get("ShadowResultTopic")\n _ShadowTopic\x3d_RspData.get("ShadowTopic")\n _TLSCert\x3d_RspData.get("TLSCert")\n _TLSKey\x3d_RspData.get("TLSKey")\n mqtt \x3d MQTTClient(client_id \x3d _ClientId , server \x3d ' + b + ", port\x3d" + c + ', user\x3d_UserName , password \x3d" " , keepalive\x3d10000, ssl\x3dTrue, ssl_params\x3d{ "server_side":False, "key":_TLSKey, "cert":_TLSCert})\n elif "Error" in Rsp:\n print(_Rsp.get("Error"))\nexcept:\n print("error");';
  1773. return ""
  1774. };
  1775. Blockly.Python.mqtt_setup = function(a) {
  1776. Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
  1777. var b = Blockly.Python.valueToCode(a, "Server", Blockly.Python.ORDER_ATOMIC),
  1778. c = Blockly.Python.valueToCode(a, "Iot_id", Blockly.Python.ORDER_ATOMIC),
  1779. d = Blockly.Python.valueToCode(a, "Iot_pwd", Blockly.Python.ORDER_ATOMIC);
  1780. a = Blockly.Python.valueToCode(a, "Client_ID", Blockly.Python.ORDER_ATOMIC);
  1781. Blockly.Python.definitions_.mqtt_setup = "mqtt \x3d MQTTClient(" + a + ", " + b + ", 1883, " + c + ", " + d + ", keepalive\x3d30)";
  1782. return ""
  1783. };
  1784. Blockly.Python.mqtt_connect = function(a) {
  1785. Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
  1786. Blockly.Python.definitions_.mqtt_connect = "\ntry:\n mqtt.connect()\n print('Connected')\nexcept:\n print('Disconnected')\n";
  1787. return ""
  1788. };
  1789. Blockly.Python.mqtt_publish = function(a) {
  1790. Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
  1791. var b = Blockly.Python.valueToCode(a, "msg", Blockly.Python.ORDER_ATOMIC);
  1792. return "mqtt.publish(" + Blockly.Python.valueToCode(a, "topic", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
  1793. };
  1794. Blockly.Python.mqtt_rec_from_topic = function(a) {
  1795. Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
  1796. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  1797. Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
  1798. var b = a.getFieldValue("topic"); -
  1799. 1 != b.search("/") && b.replace(/\//g, "_");
  1800. var c = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
  1801. a = a.workspace.variableList;
  1802. for (var d = a.length - 1; 0 <= d; d--)
  1803. a[d] = Blockly.Python.variableDB_.getName(a[d], Blockly.Variables.NAME_TYPE);
  1804. try {
  1805. a.remove("_msg")
  1806. } catch (e) {}
  1807. a = a.length ? " global " + a.join(", ") + "\n" : "";
  1808. d = toUTF8Hex(b);
  1809. Blockly.Python.definitions_["mqtt_recv_topic_" + d] = "def mqtt_topic_" + d + "(_msg):\n" + a + c;
  1810. Blockly.Python.codeFunctions_.mqtt_callback = "\ndef mqtt_callback(topic, msg):\n try: \n topic \x3d topic.decode('utf-8', 'ignore')\n _msg \x3d msg.decode('utf-8', 'ignore')\n eval('mqtt_topic_' + bytes.decode(ubinascii.hexlify(topic)) + '(\"' + _msg + '\")')\n except: print((topic, msg))\n";
  1811. Blockly.Python.codeFunctions_.mqtt_set_callback = "mqtt.set_callback(mqtt_callback)";
  1812. Blockly.Python.codeFunctions_["mqtt_subscribe" + b] = 'mqtt.subscribe("' + b + '")';
  1813. Blockly.Python.codeFunctions_.mqtt_timer14 = "\ndef timer14_tick(_):\n mqtt.ping()\n \ntim14 \x3d Timer(14) \ntim14.init(period\x3d20000, mode\x3dTimer.PERIODIC, callback\x3dtimer14_tick)\n";
  1814. return ""
  1815. };
  1816. Blockly.Python.mqtt_receive = function(a) {
  1817. Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
  1818. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  1819. Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
  1820. var b = Blockly.Python.valueToCode(a, "topic", Blockly.Python.ORDER_ATOMIC),
  1821. c = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
  1822. a = a.workspace.variableList;
  1823. for (var d = a.length - 1; 0 <= d; d--)
  1824. a[d] = Blockly.Python.variableDB_.getName(a[d], Blockly.Variables.NAME_TYPE);
  1825. try {
  1826. a.remove("_msg")
  1827. } catch (e) {}
  1828. a = a.length ? " global " + a.join(", ") + "\n" : "";
  1829. Blockly.Python.definitions_.mqtt_callback = "\n_mqtt_topic_list \x3d []\ndef mqtt_callback(topic, msg):\n try: \n topic \x3d topic.decode('utf-8', 'ignore')\n _msg \x3d msg.decode('utf-8', 'ignore')\n for t in _mqtt_topic_list:\n if eval(t) \x3d\x3d topic: eval('mqtt_recv_' + t + '(\"' + _msg + '\")')\n except: print((topic, msg))\n";
  1830. Blockly.Python.codeFunctions_["mqtt_recv_topic_" + b] = '_mqtt_topic_list.append("' + b + '")\ndef mqtt_recv_' + b + "(_msg):\n" + a + c;
  1831. Blockly.Python.codeFunctions_.mqtt_set_callback = "mqtt.set_callback(mqtt_callback)";
  1832. Blockly.Python.codeFunctions_.mqtt_timer14 = "\ndef timer14_tick(_):\n mqtt.ping()\n \ntim14 \x3d Timer(14) \ntim14.init(period\x3d20000, mode\x3dTimer.PERIODIC, callback\x3dtimer14_tick)\n";
  1833. return "mqtt.subscribe(" + b + ")\n"
  1834. };
  1835. Blockly.Python.mqtt_wait_msg = function(a) {
  1836. Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
  1837. return "unblock" == a.getFieldValue("mode") ? "mqtt.check_msg()\n" : "mqtt.wait_msg()\n"
  1838. };
  1839. Blockly.Python.mqtt_disconnect = function(a) {
  1840. Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
  1841. return "mqtt.disconnect()\n"
  1842. };
  1843. Blockly.Python.mqtt_last_will = function(a) {
  1844. Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
  1845. var b = Blockly.Python.valueToCode(a, "topic", Blockly.Python.ORDER_ATOMIC);
  1846. a = Blockly.Python.valueToCode(a, "msg", Blockly.Python.ORDER_ATOMIC);
  1847. Blockly.Python.definitions_["mqtt_set_last_will" + b] = "mqtt.set_last_will(" + b + ", " + a + ")";
  1848. return ""
  1849. };
  1850. Blockly.Python.CocoRobo_onenet_option_boards = function(a) {
  1851. a.getFieldValue("option_boards");
  1852. return ""
  1853. };
  1854. Blockly.Python.CocoRobo_onenet_setup = function(a) {
  1855. Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
  1856. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  1857. Blockly.Python.definitions_.import_machine = "import machine";
  1858. Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
  1859. var b = Blockly.Python.valueToCode(a, "server", Blockly.Python.ORDER_ATOMIC),
  1860. c = Blockly.Python.valueToCode(a, "device_id", Blockly.Python.ORDER_ATOMIC),
  1861. d = Blockly.Python.valueToCode(a, "product_id", Blockly.Python.ORDER_ATOMIC);
  1862. a = Blockly.Python.valueToCode(a, "product_APIKey", Blockly.Python.ORDER_ATOMIC);
  1863. Blockly.Python.definitions_.def_onenet_callback = "def OneNET_recv(_msg):pass\n_OneNET_msg_list \x3d []\ndef OneNET_callback(_topic, _msg):\n global _OneNET_msg_list\n try: _msg \x3d _msg.decode('utf-8', 'ignore')\n except: print(_msg);return\n OneNET_recv(_msg)\n if _msg in _OneNET_msg_list:\n eval('OneNET_recv_' + bytes.decode(ubinascii.hexlify(_msg)) + '()')";
  1864. Blockly.Python.definitions_.def_Timer14 = "tim14 \x3d Timer(14)";
  1865. Blockly.Python.definitions_.timer14_tick = "_iot_count \x3d 0\ndef timer14_tick(_):\n global _iot, _iot_count\n _iot_count \x3d _iot_count + 1\n if _iot_count \x3d\x3d 1000: _iot.ping(); _iot_count \x3d 0\n try: _iot.check_msg()\n except: machine.reset()\n";
  1866. Blockly.Python.definitions_.def_onenet_setup = "_iot \x3d None\ndef OneNET_setup():\n global _iot\n _iot \x3d MQTTClient(" + c + ", " + b + ", 6002, " + d + ", " + a + ", keepalive\x3d300)\n _iot.set_callback(OneNET_callback)\n if 1 \x3d\x3d _iot.connect(): print('Successfully connected to MQTT server.')\n tim14.init(period\x3d200, mode\x3dTimer.PERIODIC, callback\x3dtimer14_tick)\n";
  1867. return "OneNET_setup()\n"
  1868. };
  1869. Blockly.Python.CocoRobo_onenet_setup_wechat_app = function(a) {
  1870. Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
  1871. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  1872. Blockly.Python.definitions_.import_machine = "import machine";
  1873. Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
  1874. var b = Blockly.Python.valueToCode(a, "server", Blockly.Python.ORDER_ATOMIC),
  1875. c = Blockly.Python.valueToCode(a, "device_id", Blockly.Python.ORDER_ATOMIC),
  1876. d = Blockly.Python.valueToCode(a, "product_id", Blockly.Python.ORDER_ATOMIC);
  1877. a = Blockly.Python.valueToCode(a, "product_APIKey", Blockly.Python.ORDER_ATOMIC);
  1878. Blockly.Python.definitions_.def_onenet_callback = "def OneNET_recv(_msg):pass\n_OneNET_msg_list \x3d []\ndef OneNET_callback(_topic, _msg):\n global _OneNET_msg_list\n try: _msg \x3d _msg.decode('utf-8', 'ignore')\n except: print(_msg);return\n OneNET_recv(_msg)\n if _msg in _OneNET_msg_list:\n eval('OneNET_recv_' + bytes.decode(ubinascii.hexlify(_msg)) + '()')";
  1879. Blockly.Python.definitions_.def_Timer14 = "tim14 \x3d Timer(14)";
  1880. Blockly.Python.definitions_.timer14_tick = "_iot_count \x3d 0\ndef timer14_tick(_):\n global _iot, _iot_count\n _iot_count \x3d _iot_count + 1\n if _iot_count \x3d\x3d 1000: _iot.ping(); _iot_count \x3d 0\n try: _iot.check_msg()\n except: machine.reset()\n";
  1881. Blockly.Python.definitions_.def_onenet_setup = "_iot \x3d None\ndef OneNET_setup():\n global _iot\n _iot \x3d MQTTClient(" + c + ", " + b + ", 6002, " + d + ", " + a + ", keepalive\x3d300)\n _iot.set_callback(OneNET_callback)\n if 1 \x3d\x3d _iot.connect(): print('Successfully connected to MQTT server.')\n tim14.init(period\x3d200, mode\x3dTimer.PERIODIC, callback\x3dtimer14_tick)\n";
  1882. return "OneNET_setup()\n"
  1883. };
  1884. Blockly.Python.CocoRobo_onenet_recv = function(a) {
  1885. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  1886. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  1887. try {
  1888. b.remove("_msg")
  1889. } catch (d) {}
  1890. try {
  1891. b.remove("_name")
  1892. } catch (d) {}
  1893. try {
  1894. b.remove("_value")
  1895. } catch (d) {}
  1896. b = b.length ? " global " + b.join(", ") + "\n" : "";
  1897. a = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
  1898. Blockly.Python.codeFunctions_.def_onenet_recv = "def OneNET_recv(_msg):\n" + b + a;
  1899. return ""
  1900. };
  1901. Blockly.Python.CocoRobo_onenet_recv_from_wechat_app = function(a) {
  1902. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  1903. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  1904. try {
  1905. b.remove("_msg")
  1906. } catch (d) {}
  1907. try {
  1908. b.remove("_name")
  1909. } catch (d) {}
  1910. try {
  1911. b.remove("_value")
  1912. } catch (d) {}
  1913. b = b.length ? " global " + b.join(", ") + "\n" : "";
  1914. Blockly.Python.definitions_.import_ujson = "import json";
  1915. a = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
  1916. Blockly.Python.codeFunctions_.def_onenet_recv_from_wechat_app = "def OneNET_recv(_msg):\n" + b + " try:\n _msgObj \x3d json.loads(_msg)\n _name \x3d _msgObj.get('name')\n _value \x3d _msgObj.get('value')\n except: return\n" + a;
  1917. return ""
  1918. };
  1919. Blockly.Python.CocoRobo_onenet_recv_msg = function(a) {
  1920. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  1921. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  1922. try {
  1923. b.remove("_msg")
  1924. } catch (e) {}
  1925. try {
  1926. b.remove("_name")
  1927. } catch (e) {}
  1928. try {
  1929. b.remove("_value")
  1930. } catch (e) {}
  1931. var b = b.length ? " global " + b.join(", ") + "\n" : "",
  1932. c = a.getFieldValue("message"),
  1933. d = toUTF8Hex(c);
  1934. a = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
  1935. Blockly.Python.codeFunctions_["def_onenet_recv_" + d] = "_OneNET_msg_list.append('" + c + "')\ndef OneNET_recv_" + d + "():\n" + b + a;
  1936. return ""
  1937. };
  1938. Blockly.Python.CocoRobo_onenet_pub_value = function(a) {
  1939. Blockly.Python.definitions_.import_json = "import json";
  1940. Blockly.Python.definitions_.def_onenet_pubdata = "def pubdata(_dic):\n print(_dic)\n _list \x3d []\n for _key in list(_dic.keys()):\n _d \x3d {'id':_key,'datapoints':[{'value':_dic[_key]}]}\n _list.append(_d)\n _data \x3d {'datastreams': _list}\n j_d \x3d json.dumps(_data)\n j_l \x3d len(j_d)\n arr \x3d bytearray(j_l + 3)\n arr[0] \x3d 1\n arr[1] \x3d int(j_l / 256)\n arr[2] \x3d j_l % 256\n arr[3:] \x3d j_d.encode('ascii')\n return arr\n";
  1941. var b = Blockly.Python.valueToCode(a, "NAME", Blockly.Python.ORDER_ATOMIC);
  1942. a = Blockly.Python.valueToCode(a, "VALUE", Blockly.Python.ORDER_ATOMIC);
  1943. return "_iot.publish('$dp', pubdata({" + b + ":" + a + "}))\n"
  1944. };
  1945. Blockly.Python.CocoRobo_onenet_pub_value_wechat_app = function(a) {
  1946. Blockly.Python.definitions_.import_json = "import json";
  1947. Blockly.Python.definitions_.def_onenet_pubdata = "def pubdata(_dic):\n print(_dic)\n _list \x3d []\n for _key in list(_dic.keys()):\n _d \x3d {'id':_key,'datapoints':[{'value':_dic[_key]}]}\n _list.append(_d)\n _data \x3d {'datastreams': _list}\n j_d \x3d json.dumps(_data)\n j_l \x3d len(j_d)\n arr \x3d bytearray(j_l + 3)\n arr[0] \x3d 1\n arr[1] \x3d int(j_l / 256)\n arr[2] \x3d j_l % 256\n arr[3:] \x3d j_d.encode('ascii')\n return arr\n";
  1948. var b = Blockly.Python.valueToCode(a, "NAME", Blockly.Python.ORDER_ATOMIC);
  1949. a = Blockly.Python.valueToCode(a, "VALUE", Blockly.Python.ORDER_ATOMIC);
  1950. return "_iot.publish('$dp', pubdata({" + b + ":" + a + "}))\n"
  1951. };
  1952. Blockly.Python.CocoRobo_onenet_pub_dict = function(a) {
  1953. Blockly.Python.definitions_.import_json = "import json";
  1954. Blockly.Python.definitions_.def_onenet_pubdata = "def pubdata(_dic):\n print(_dic)\n _list \x3d []\n for _key in list(_dic.keys()):\n _d \x3d {'id':_key,'datapoints':[{'value':_dic[_key]}]}\n _list.append(_d)\n _data \x3d {'datastreams': _list}\n j_d \x3d json.dumps(_data)\n j_l \x3d len(j_d)\n arr \x3d bytearray(j_l + 3)\n arr[0] \x3d 1\n arr[1] \x3d int(j_l / 256)\n arr[2] \x3d j_l % 256\n arr[3:] \x3d j_d.encode('ascii')\n return arr\n";
  1955. return "_iot.publish('$dp', pubdata(" + Blockly.Python.valueToCode(a, "DICT", Blockly.Python.ORDER_ATOMIC) + "))\n"
  1956. };
  1957. Blockly.Python.CocoRobo_onenet_disconnect = function(a) {
  1958. return "tim14.deinit()\n_iot.disconnect()\nprint('Disconnected from MQTT server.')\n"
  1959. };
  1960. Blockly.Python.CocoRobo_blynk_terminal_widget_vpin = function(a) {
  1961. a = Blockly.Python.valueToCode(a, "virtual_pin", Blockly.Python.ORDER_ATOMIC);
  1962. Blockly.Python.codeFunctions_["terminal_widget_vpin_" + a] = "\nALLOWED_COMMANDS_LIST \x3d ['ls', 'lsusb', 'ip a', 'ip abc']\n\n@blynk.handle_event('write V" + a + "')\ndef write_handler(pin, _values):\n header \x3d ''\n result \x3d ''\n delimiter \x3d '{}\\n'.format('\x3d' * 30)\n if _values and _values[0] in ALLOWED_COMMANDS_LIST:\n cmd_params \x3d _values[0].split(' ')\n try:\n result \x3d subprocess.check_output(cmd_params).decode('utf-8')\n header \x3d '[output]\\n'\n except subprocess.CalledProcessError as exe_err:\n header \x3d '[error]\\n'\n result \x3d 'Return Code: {}\\n'.format(exe_err.returncode)\n except Exception as g_err:\n print(\"Command caused '{}'\".format(g_err))\n elif _values and _values[0] \x3d\x3d 'help':\n header \x3d '[help -\x3e allowed commands]\\n'\n result \x3d '{}\\n'.format('\\n'.join(ALLOWED_COMMANDS_LIST))\n\n # communicate with terminal if help or some allowed command\n if result:\n output \x3d '{}{}{}{}'.format(header, delimiter, result, delimiter)\n print(output)\n blynk.virtual_write(pin, output)\n blynk.virtual_write(pin, '\\n')\n";
  1963. return ""
  1964. };
  1965. Blockly.Python.CocoRobo_blynk_sync_virtual = function(a) {
  1966. return "blynk.virtual_sync(" + Blockly.Python.valueToCode(a, "virtual_pin", Blockly.Python.ORDER_ATOMIC) + ")\n"
  1967. };
  1968. Blockly.Python.CocoRobo_blynk_on_disconnected = function(a) {
  1969. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  1970. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  1971. try {
  1972. b.remove("_value")
  1973. } catch (d) {}
  1974. b = b.length ? " global " + b.join(", ") + "\n" : "";
  1975. c = Blockly.Python.statementToCode(a, "DO");
  1976. c = Blockly.Python.addLoopTrap(c, a.id) || Blockly.Python.PASS;
  1977. Blockly.Python.definitions_.blynk_on_disconnected = '@blynk.handle_event("disconnect")\ndef connect_handler():\n' + b + " print('Blynk disconnected')\n" + c;
  1978. return ""
  1979. };
  1980. Blockly.Python.CocoRobo_blynk_on_connected = function(a) {
  1981. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  1982. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  1983. try {
  1984. b.remove("_value")
  1985. } catch (d) {}
  1986. b = b.length ? " global " + b.join(", ") + "\n" : "";
  1987. c = Blockly.Python.statementToCode(a, "DO");
  1988. c = Blockly.Python.addLoopTrap(c, a.id) || Blockly.Python.PASS;
  1989. Blockly.Python.definitions_.blynk_on_connected = '@blynk.handle_event("connect")\ndef connect_handler():\n' + b + " print('Blynk connected')\n" + c;
  1990. return ""
  1991. };
  1992. Blockly.Python.CocoRobo_blynktimer_run = function(a) {
  1993. return "blynk_timer.run()\n"
  1994. };
  1995. Blockly.Python.CocoRobo_blynk_run = function(a) {
  1996. return "blynk.run()\n"
  1997. };
  1998. Blockly.Python.CocoRobo_blynk_app_notify = function(a) {
  1999. return "blynk.notify(" + Blockly.Python.valueToCode(a, "notification", Blockly.Python.ORDER_ATOMIC) + ")\n"
  2000. };
  2001. Blockly.Python.CocoRobo_blynk_stop_timers = function(a) {
  2002. Blockly.Python.definitions_.import_blynktimer = "import blynktimer";
  2003. Blockly.Python.definitions_.def_blynktimer = "blynk_timer \x3d blynktimer.Timer(no_timers_err\x3dFalse)";
  2004. a = Blockly.Python.valueToCode(a, "timer_num", Blockly.Python.ORDER_ATOMIC);
  2005. return "blynk_timer.stop('" + a + "_blynk_timer" + a + "')\n"
  2006. };
  2007. Blockly.Python.CocoRobo_blynk_get_timers = function(a) {
  2008. Blockly.Python.definitions_.import_blynktimer = "import blynktimer";
  2009. Blockly.Python.definitions_.def_blynktimer = "blynk_timer \x3d blynktimer.Timer(no_timers_err\x3dFalse)";
  2010. return ["blynk_timer.get_timers()", Blockly.Python.ORDER_ATOMIC]
  2011. };
  2012. Blockly.Python.CocoRobo_blynktimer = function(a) {
  2013. Blockly.Python.definitions_.import_blynktimer = "import blynktimer";
  2014. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  2015. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  2016. try {
  2017. b.remove("_value")
  2018. } catch (g) {}
  2019. var b = b.length ? " global " + b.join(", ") + "\n" : "",
  2020. c = Blockly.Python.valueToCode(a, "Num", Blockly.Python.ORDER_ATOMIC),
  2021. d = Blockly.Python.valueToCode(a, "period", Blockly.Python.ORDER_ATOMIC),
  2022. e = a.getFieldValue("Timer_mode"),
  2023. f = Blockly.Python.statementToCode(a, "DO"),
  2024. f = Blockly.Python.addLoopTrap(f, a.id) || Blockly.Python.PASS;
  2025. Blockly.Python.definitions_.def_blynktimer = "blynk_timer \x3d blynktimer.Timer(no_timers_err\x3dFalse)";
  2026. Blockly.Python.definitions_["blynktimer_event" + c] = "\n@blynk_timer.register(interval\x3d" + d + ", run_once\x3d" + e + ")\ndef blynk_timer" + c + "():\n" + b + f;
  2027. return ""
  2028. };
  2029. Blockly.Python.CocoRobo_blynk_sensor_data_to_app = function(a) {
  2030. var b = Blockly.Python.valueToCode(a, "sensor_data", Blockly.Python.ORDER_ATOMIC);
  2031. return "blynk.virtual_write(" + Blockly.Python.valueToCode(a, "virtual_pin", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
  2032. };
  2033. Blockly.Python.CocoRobo_blynk_app_data = function(a) {
  2034. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  2035. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  2036. try {
  2037. b.remove("_value")
  2038. } catch (e) {}
  2039. var b = b.length ? " global " + b.join(", ") + "\n" : "",
  2040. c = Blockly.Python.valueToCode(a, "virtual_pin", Blockly.Python.ORDER_ATOMIC),
  2041. d = Blockly.Python.statementToCode(a, "DO"),
  2042. d = Blockly.Python.addLoopTrap(d, a.id) || Blockly.Python.PASS;
  2043. Blockly.Python.definitions_["blynk_VIRTUAL_WRITE_" + c] = "@blynk.handle_event('write V" + c + "')\ndef write_virtual_pin_handler(pin, _value):\n" + b + " for i in range(0, len(_value)):\n try: _value[i] \x3d eval(_value[i])\n except: pass\n if len(_value) \x3d\x3d 1: _value \x3d _value[0]\n" + d;
  2044. return ""
  2045. };
  2046. Blockly.Python.CocoRobo_blynk_email = function(a) {
  2047. var b = Blockly.Python.valueToCode(a, "body", Blockly.Python.ORDER_ATOMIC);
  2048. return 'blynk.email("", ' + Blockly.Python.valueToCode(a, "subject", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
  2049. };
  2050. Blockly.Python.CocoRobo_blynk_set_property = function(a) {
  2051. var b = Blockly.Python.valueToCode(a, "attribute_value", Blockly.Python.ORDER_ATOMIC);
  2052. return "blynk.set_property(pin, " + Blockly.Python.valueToCode(a, "attribute_name", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
  2053. };
  2054. Blockly.Python.CocoRobo_blynk_setup = function(a) {
  2055. Blockly.Python.definitions_.import_BlynkLib = "import blynklib";
  2056. var b = Blockly.Python.valueToCode(a, "server", Blockly.Python.ORDER_ATOMIC),
  2057. c = Blockly.Python.valueToCode(a, "auth", Blockly.Python.ORDER_ATOMIC);
  2058. a = Blockly.Python.valueToCode(a, "port", Blockly.Python.ORDER_ATOMIC);
  2059. Blockly.Python.definitions_.CocoRobo_blynk_setup = "blynk \x3d blynklib.Blynk(" + c + ", server\x3d" + b + ", port\x3d" + a + ")";
  2060. Blockly.Python.definitions_.blynk_on_connected = "\n@blynk.handle_event(\"connect\")\ndef connect_handler():\n print('Blynk connected')\n";
  2061. Blockly.Python.definitions_.blynk_on_disconnected = "\n@blynk.handle_event(\"disconnect\")\ndef connect_handler():\n print('Blynk disconnected')\n";
  2062. return ""
  2063. };
  2064. Blockly.Python.CocoRobo_tinywebio_start = function (a) {
  2065. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2066. Blockly.Python.definitions_.import_tinywebio = "from tinywebio import appserver, appclient";
  2067. return "0" == a.getFieldValue("tinywebio_mode") ? "appserver.start()\n" : "appserver.start_foreground()\n"
  2068. };
  2069. Blockly.Python.CocoRobo_tinywebio_client_setup = function (a) {
  2070. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2071. Blockly.Python.definitions_.import_tinywebio = "from tinywebio import appserver, appclient";
  2072. var b = Blockly.Python.valueToCode(a, "db_server", Blockly.Python.ORDER_ATOMIC),
  2073. c = Blockly.Python.valueToCode(a, "send_items", Blockly.Python.ORDER_ATOMIC),
  2074. d = Blockly.Python.valueToCode(a, "recv_items", Blockly.Python.ORDER_ATOMIC);
  2075. a = Blockly.Python.valueToCode(a, "interval", Blockly.Python.ORDER_ATOMIC);
  2076. return "appclient.setup(" + b + ",\n" + c + ",\n" + d + ", " + a + ")\n"
  2077. };
  2078. Blockly.Python.CocoRobo_tinywebio_client_action = function (a) {
  2079. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2080. Blockly.Python.definitions_.import_tinywebio = "from tinywebio import appserver, appclient";
  2081. return "appclient." + a.getFieldValue("action_mode") + "()\n"
  2082. };
  2083. Blockly.Python.list_first_index = function(a) {
  2084. var b = Blockly.Python.valueToCode(a, "elem", Blockly.Python.ORDER_ATOMIC),
  2085. c = Blockly.Python.valueToCode(a, "my_list", Blockly.Python.ORDER_ATOMIC);
  2086. a = a.getFieldValue("last_or_first");
  2087. Blockly.Python.codeFunctions_.list_first_index = "def first_index(my_list, elem):\n try: index \x3d my_list.index(elem)\n except: index \x3d 0\n return index";
  2088. Blockly.Python.codeFunctions_.list_last_index = "def last_index(my_list, elem):\n try: index \x3d len(my_list) - my_list[::-1].index(elem) - 1\n except: index \x3d 0\n return index";
  2089. return [a + "_index(" + c + ", " + b + ")", Blockly.Python.ORDER_ATOMIC]
  2090. };
  2091. Blockly.Python.CocoRobo_return_list = function(a) {
  2092. var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC);
  2093. a = Blockly.Python.valueToCode(a, "list_items", Blockly.Python.ORDER_ATOMIC);
  2094. return b + " \x3d " + a + "\n"
  2095. };
  2096. Blockly.Python.lists_append = function(a) {
  2097. var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC);
  2098. a = Blockly.Python.valueToCode(a, "last_item", Blockly.Python.ORDER_ATOMIC);
  2099. return b + ".append(" + a + ")\n"
  2100. };
  2101. Blockly.Python.lists_extend = function(a) {
  2102. var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC);
  2103. a = Blockly.Python.valueToCode(a, "extend_list", Blockly.Python.ORDER_ATOMIC);
  2104. return b + ".extend(" + a + ")\n"
  2105. };
  2106. Blockly.Python.lists_clear = function(a) {
  2107. return Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC) + ".clear()\n"
  2108. };
  2109. Blockly.Python.parts_of_list = function(a) {
  2110. var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC),
  2111. c = a.getFieldValue("list_start_order"),
  2112. d = a.getFieldValue("list_end_order"),
  2113. e = Blockly.Python.valueToCode(a, "start_item", Blockly.Python.ORDER_ATOMIC);
  2114. a = Blockly.Python.valueToCode(a, "end_item", Blockly.Python.ORDER_ATOMIC);
  2115. switch (d) {
  2116. case ":":
  2117. var f = parseInt(a) + 1;
  2118. break;
  2119. case ":-":
  2120. f = a - 1
  2121. }
  2122. return [b + c + e + d + f + "]", Blockly.Python.ORDER_ATOMIC]
  2123. };
  2124. Blockly.Python.list_to_tuple = function(a) {
  2125. return ["tuple(" + Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
  2126. };
  2127. Blockly.Python.list_order_item = function(a) {
  2128. var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC),
  2129. c = a.getFieldValue("list_order");
  2130. a = Blockly.Python.valueToCode(a, "list_order_item", Blockly.Python.ORDER_ATOMIC);
  2131. return [b + c + a + "]", Blockly.Python.ORDER_ATOMIC]
  2132. };
  2133. Blockly.Python.set_list_order_item = function(a) {
  2134. var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC),
  2135. c = a.getFieldValue("list_order"),
  2136. d = Blockly.Python.valueToCode(a, "list_order_item", Blockly.Python.ORDER_ATOMIC);
  2137. a = Blockly.Python.valueToCode(a, "set_value", Blockly.Python.ORDER_ATOMIC);
  2138. return b + c + d + "] \x3d " + a + "\n"
  2139. };
  2140. Blockly.Python.insert_list_order_item = function(a) {
  2141. var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC),
  2142. c = a.getFieldValue("list_order"),
  2143. d = Blockly.Python.valueToCode(a, "list_order_item", Blockly.Python.ORDER_ATOMIC);
  2144. a = Blockly.Python.valueToCode(a, "set_value", Blockly.Python.ORDER_ATOMIC);
  2145. return b + ".insert" + c + d + ", " + a + ")\n"
  2146. };
  2147. Blockly.Python.list_item_exist = function(a) {
  2148. var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC);
  2149. return [Blockly.Python.valueToCode(a, "list_item", Blockly.Python.ORDER_ATOMIC) + " in " + b, Blockly.Python.ORDER_ATOMIC]
  2150. };
  2151. Blockly.Python.addReservedWords("music");
  2152. var _microbit_music_default_pin = 0;
  2153. Blockly.Python.CocoRobo_music_play = function (a) {
  2154. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2155. Blockly.Python.definitions_.import_music = "import music";
  2156. var b = a.getFieldValue("melody");
  2157. a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
  2158. return "6" == a ? "music.play(music." + b + ", wait\x3dFalse, loop\x3dFalse)\n" : "music.play(music." + b + ", pin\x3dPin.P" + a + ", wait\x3dFalse, loop\x3dFalse)\n"
  2159. };
  2160. Blockly.Python.CocoRobo_music_play_until_end = function (a) {
  2161. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2162. Blockly.Python.definitions_.import_music = "import music";
  2163. var b = a.getFieldValue("melody");
  2164. a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
  2165. return "6" == a ? "music.play(music." + b + ", wait\x3dTrue, loop\x3dFalse)\n" : "music.play(music." + b + ", pin\x3dPin.P" + a + ", wait\x3dTrue, loop\x3dFalse)\n"
  2166. };
  2167. Blockly.Python.microbit_music_play_built_in = function (a) {
  2168. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2169. Blockly.Python.definitions_.import_music = "import music";
  2170. var b = a.getFieldValue("melody"),
  2171. c = "TRUE" == a.getFieldValue("wait") ? "True" : "False",
  2172. d = "TRUE" == a.getFieldValue("loop") ? "True" : "False";
  2173. a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
  2174. return "6" == a ? "music.play(music." + b + ", wait\x3d" + c + ", loop\x3d" + d + ")\n" : "music.play(music." + b + ", pin\x3dPin.P" + a + ", wait\x3d" + c + ", loop\x3d" + d + ")\n"
  2175. };
  2176. Blockly.Python.microbit_music_pitch = function (a) {
  2177. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2178. Blockly.Python.definitions_.import_music = "import music";
  2179. var b = Blockly.Python.valueToCode(a, "pitch", Blockly.Python.ORDER_ATOMIC),
  2180. c = Blockly.Python.valueToCode(a, "duration", Blockly.Python.ORDER_ATOMIC);
  2181. a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
  2182. return "6" == a ? "music.pitch(" + b + ", " + c + ")\n" : "music.pitch(" + b + ", " + c + ", pin\x3dPin.P" + a + ")\n"
  2183. };
  2184. Blockly.Python.microbit_music_play_list_of_notes = function (a) {
  2185. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2186. Blockly.Python.definitions_.import_music = "import music";
  2187. var b = Blockly.Python.valueToCode(a, "notes", Blockly.Python.ORDER_ATOMIC),
  2188. c = "TRUE" == a.getFieldValue("wait") ? "True" : "False",
  2189. d = "TRUE" == a.getFieldValue("loop") ? "True" : "False";
  2190. a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
  2191. return "6" == a ? "music.play(" + b + ", wait\x3d" + c + ", loop\x3d" + d + ")\n" : "music.play(" + b + ", pin\x3dPin.P" + a + ", wait\x3d" + c + ", loop\x3d" + d + ")\n"
  2192. };
  2193. Blockly.Python.microbit_music_reset = function(a) {
  2194. Blockly.Python.definitions_.import_music = "import music";
  2195. return "music.reset()\n"
  2196. };
  2197. Blockly.Python.microbit_music_stop = function (a) {
  2198. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2199. Blockly.Python.definitions_.import_music = "import music";
  2200. a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
  2201. return "6" == a ? "music.stop()\n" : "music.stop(Pin.P" + a + ")\n"
  2202. };
  2203. Blockly.Python.microbit_music_set_tempo = function(a) {
  2204. Blockly.Python.definitions_.import_music = "import music";
  2205. var b = Blockly.Python.valueToCode(a, "ticks", Blockly.Python.ORDER_ATOMIC);
  2206. a = Blockly.Python.valueToCode(a, "bpm", Blockly.Python.ORDER_ATOMIC);
  2207. return "music.set_tempo(ticks\x3d" + b + ", bpm\x3d" + a + ")\n"
  2208. };
  2209. Blockly.Python.microbit_music_set_tempo_speed = function(a) {
  2210. Blockly.Python.definitions_.import_music = "import music";
  2211. return "music.set_tempo(ticks\x3d 4, bpm\x3d" + 120 * Blockly.Python.valueToCode(a, "bpm", Blockly.Python.ORDER_ATOMIC) + ")\n"
  2212. };
  2213. Blockly.Python.microbit_music_get_tempo = function(a) {
  2214. Blockly.Python.definitions_.import_music = "import music";
  2215. return ["music.get_tempo()", Blockly.Python.ORDER_MEMBER]
  2216. };
  2217. Blockly.Python.microbit_set_music_pin = function(a) {
  2218. _microbit_music_default_pin = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
  2219. return ""
  2220. };
  2221. Blockly.Python.CocoRobo_neopixel_init = function (a) {
  2222. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2223. Blockly.Python.definitions_.import_neopixel = "import neopixel";
  2224. var b = a.getFieldValue("neopixel_name"),
  2225. c = Blockly.Python.valueToCode(a, "n", Blockly.Python.ORDER_ATOMIC);
  2226. a = Blockly.Python.valueToCode(a, "analogP_IO", Blockly.Python.ORDER_ATOMIC);
  2227. Blockly.Python.definitions_["def_neopixel" + b] = b + " \x3d neopixel.NeoPixel(Pin(Pin.P" + a + "), n\x3d" + c + ", bpp\x3d3, timing\x3d1)";
  2228. return ""
  2229. };
  2230. Blockly.Python.CocoRobo_neopixel_rainbow = function (a) {
  2231. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2232. Blockly.Python.definitions_.import_neopixel = "import neopixel";
  2233. var b = a.getFieldValue("neopixel_name"),
  2234. c = Blockly.Python.valueToCode(a, "n", Blockly.Python.ORDER_ATOMIC),
  2235. d = Blockly.Python.valueToCode(a, "bright", Blockly.Python.ORDER_ATOMIC);
  2236. a = Blockly.Python.valueToCode(a, "offset", Blockly.Python.ORDER_ATOMIC);
  2237. Blockly.Python.definitions_.def_make_rainbow = "def make_rainbow(_neopixel, _num, _bright, _offset):\n _rgb \x3d ((255,0,0), (255,127,0), (255,255,0), (0,255,0), (0,255,255), (0,0,255), (136,0,255), (255,0,0))\n for i in range(_num):\n t \x3d 7 * i / _num\n t0 \x3d int(t)\n r \x3d round((_rgb[t0][0] + (t-t0)*(_rgb[t0+1][0]-_rgb[t0][0]))*_bright)\x3e\x3e8\n g \x3d round((_rgb[t0][1] + (t-t0)*(_rgb[t0+1][1]-_rgb[t0][1]))*_bright)\x3e\x3e8\n b \x3d round((_rgb[t0][2] + (t-t0)*(_rgb[t0+1][2]-_rgb[t0][2]))*_bright)\x3e\x3e8\n _neopixel[(i + _offset) % _num] \x3d (r, g, b)\n";
  2238. return "make_rainbow(" + b + ", " + c + ", " + d + ", " + a + ")\n"
  2239. };
  2240. Blockly.Python.CocoRobo_neopixel_single = function (a) {
  2241. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2242. Blockly.Python.definitions_.import_neopixel = "import neopixel";
  2243. var b = a.getFieldValue("neopixel_name"),
  2244. c = Blockly.Python.valueToCode(a, "order", Blockly.Python.ORDER_ATOMIC),
  2245. d = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
  2246. e = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC);
  2247. a = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
  2248. return b + "[" + c + "] \x3d (" + d + ", " + e + ", " + a + ")\n"
  2249. };
  2250. Blockly.Python.CocoRobo_neopixel_single_gui = function (a) {
  2251. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2252. Blockly.Python.definitions_.import_neopixel = "import neopixel";
  2253. var b = a.getFieldValue("neopixel_name"),
  2254. c = Blockly.Python.valueToCode(a, "order", Blockly.Python.ORDER_ATOMIC);
  2255. a = a.getFieldValue("COLOUR");
  2256. var d = 0,
  2257. e = 0,
  2258. f = 0;
  2259. try {
  2260. 7 == a.length && (d = parseInt(a.substring(1, 3), 16),
  2261. e = parseInt(a.substring(3, 5), 16),
  2262. f = parseInt(a.substring(5, 7), 16))
  2263. } catch (g) {}
  2264. return b + "[" + c + "] \x3d (" + d + ", " + e + ", " + f + ")\n"
  2265. };
  2266. Blockly.Python.CocoRobo_neopixel_show = function (a) {
  2267. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2268. Blockly.Python.definitions_.import_neopixel = "import neopixel";
  2269. return a.getFieldValue("neopixel_name") + ".write()\n"
  2270. };
  2271. Blockly.Python.CocoRobo_neopixel_off = function (a) {
  2272. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2273. Blockly.Python.definitions_.import_neopixel = "import neopixel";
  2274. a = a.getFieldValue("neopixel_name");
  2275. return a + ".fill( (0, 0, 0) )\n" + a + ".write()\n"
  2276. };
  2277. Blockly.Python.CocoRobo_neopixel_all = function (a) {
  2278. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2279. Blockly.Python.definitions_.import_neopixel = "import neopixel";
  2280. var b = a.getFieldValue("neopixel_name"),
  2281. c = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
  2282. d = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC);
  2283. a = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
  2284. return b + ".fill( (" + c + ", " + d + ", " + a + ") )\n"
  2285. };
  2286. Blockly.Python.CocoRobo_neopixel_all_gui = function (a) {
  2287. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2288. Blockly.Python.definitions_.import_neopixel = "import neopixel";
  2289. var b = a.getFieldValue("neopixel_name");
  2290. a = a.getFieldValue("COLOUR");
  2291. var c = 0,
  2292. d = 0,
  2293. e = 0;
  2294. try {
  2295. 7 == a.length && (c = parseInt(a.substring(1, 3), 16),
  2296. d = parseInt(a.substring(3, 5), 16),
  2297. e = parseInt(a.substring(5, 7), 16))
  2298. } catch (f) {}
  2299. return b + ".fill( (" + c + ", " + d + ", " + e + ") )\n"
  2300. };
  2301. Blockly.Python.CocoRobo_neopixel_brightness = function (a) {
  2302. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2303. Blockly.Python.definitions_.import_neopixel = "import neopixel";
  2304. var b = a.getFieldValue("neopixel_name");
  2305. a = Blockly.Python.valueToCode(a, "bright", Blockly.Python.ORDER_ATOMIC);
  2306. return b + ".brightness(" + a + " / 100)\n"
  2307. };
  2308. Blockly.Python.CocoRobo_display_Show = function (a) {
  2309. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2310. return "lcd.show()\n"
  2311. };
  2312. Blockly.Python.CocoRobo_display_DispChar = function (a) {
  2313. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2314. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2315. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2316. d = Blockly.Python.valueToCode(a, "message", Blockly.Python.ORDER_ATOMIC);
  2317. a = a.getFieldValue("TEXTMODE");
  2318. return "lcd.DispChar(" + d + ", " + b + ", " + c + ", " + a + ")\n"
  2319. };
  2320. Blockly.Python.CocoRobo_display_DispChar_5lines = function (a) {
  2321. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2322. var b = Blockly.Python.valueToCode(a, "DispChar_5lines", Blockly.Python.ORDER_ATOMIC),
  2323. c = Blockly.Python.valueToCode(a, "message", Blockly.Python.ORDER_ATOMIC);
  2324. a = a.getFieldValue("TEXTMODE");
  2325. return "lcd.DispChar(" + c + ", 0, " + b + ", " + a + ")\n"
  2326. };
  2327. Blockly.Python.CocoRobo_clear_dispchar_5lines = function (a) {
  2328. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2329. return "lcd.fill_rect(0, " + Blockly.Python.valueToCode(a, "DispChar_5lines", Blockly.Python.ORDER_ATOMIC) + ", 128, 16, 0)\n"
  2330. };
  2331. Blockly.Python.CocoRobo_display_fill = function(a) {
  2332. Blockly.Python.definitions_.st7735 = "from st7735 import TFT";
  2333. Blockly.Python.definitions_.sysfont = "from sysfont import sysfont";
  2334. Blockly.Python.definitions_.machine = "from machine import SPI, Pin";
  2335. var _code = '' +
  2336. '_TFT_SPI = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(23), miso=Pin(12))\n' +
  2337. 'tft=TFT(_TFT_SPI,25,26,5)\n' +
  2338. '\n' +
  2339. 'tft.initr()\n' +
  2340. 'tft.rgb(False)\n' +
  2341. 'tft.rotation(1)\n' +
  2342. 'tft.fill(TFT.BLACK)\n' +
  2343. '';
  2344. return _code;
  2345. };
  2346. Blockly.Python.CocoRobo_lcd_pixel_option = function(a) {
  2347. return [a.getFieldValue("VALUE"), Blockly.Python.ORDER_ATOMIC]
  2348. };
  2349. Blockly.Python.CocoRobo_display_pixel = function (a) {
  2350. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2351. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2352. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
  2353. a = Blockly.Python.valueToCode(a, "display_pixel", Blockly.Python.ORDER_ATOMIC);
  2354. return "lcd.pixel(" + b + ", " + c + ", " + a + ")\n"
  2355. };
  2356. Blockly.Python.CocoRobo_display_hvline = function (a) {
  2357. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2358. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2359. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2360. d = Blockly.Python.valueToCode(a, "length", Blockly.Python.ORDER_ATOMIC),
  2361. e = a.getFieldValue("state");
  2362. return "lcd." + ("0" == a.getFieldValue("dir_h_v") ? "v" : "h") + "line(" + b + ", " + c + ", " + d + ", " + e + ")\n"
  2363. };
  2364. Blockly.Python.CocoRobo_display_hline = function (a) {
  2365. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2366. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2367. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2368. d = Blockly.Python.valueToCode(a, "length", Blockly.Python.ORDER_ATOMIC);
  2369. a = a.getFieldValue("state");
  2370. return "lcd.hline(" + b + ", " + c + ", " + d + ", " + a + ")\n"
  2371. };
  2372. Blockly.Python.CocoRobo_ProgressBar = function (a) {
  2373. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2374. Blockly.Python.codeFunctions_.define_UI = "myUI \x3d UI(lcd)";
  2375. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2376. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2377. d = Blockly.Python.valueToCode(a, "width", Blockly.Python.ORDER_ATOMIC),
  2378. e = Blockly.Python.valueToCode(a, "height", Blockly.Python.ORDER_ATOMIC);
  2379. a = Blockly.Python.valueToCode(a, "progress", Blockly.Python.ORDER_ATOMIC);
  2380. return "myUI.ProgressBar(" + b + ", " + c + ", " + d + ", " + e + ", " + a + ")\n"
  2381. };
  2382. Blockly.Python.CocoRobo_stripBar = function (a) {
  2383. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2384. Blockly.Python.codeFunctions_.define_UI = "myUI \x3d UI(lcd)";
  2385. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2386. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2387. d = Blockly.Python.valueToCode(a, "width", Blockly.Python.ORDER_ATOMIC),
  2388. e = Blockly.Python.valueToCode(a, "height", Blockly.Python.ORDER_ATOMIC),
  2389. f = Blockly.Python.valueToCode(a, "progress", Blockly.Python.ORDER_ATOMIC);
  2390. a = a.getFieldValue("dir_h_v");
  2391. return "myUI.stripBar(" + b + ", " + c + ", " + d + ", " + e + ", " + f + ", " + a + ", 1)\n"
  2392. };
  2393. Blockly.Python.CocoRobo_qr_code = function (a) {
  2394. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2395. Blockly.Python.codeFunctions_.define_UI = "myUI \x3d UI(lcd)";
  2396. var b = Blockly.Python.valueToCode(a, "str", Blockly.Python.ORDER_ATOMIC),
  2397. c = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2398. d = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
  2399. a = a.getFieldValue("scale");
  2400. return "myUI.qr_code(" + b + ", " + c + ", " + d + ", scale\x3d" + a + ")\n"
  2401. };
  2402. Blockly.Python.CocoRobo_display_vline = function (a) {
  2403. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2404. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2405. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2406. d = Blockly.Python.valueToCode(a, "length", Blockly.Python.ORDER_ATOMIC);
  2407. a = a.getFieldValue("state");
  2408. return "lcd.vline(" + b + ", " + c + ", " + d + ", " + a + ")\n"
  2409. };
  2410. Blockly.Python.CocoRobo_display_line = function (a) {
  2411. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2412. var b = Blockly.Python.valueToCode(a, "x1", Blockly.Python.ORDER_ATOMIC),
  2413. c = Blockly.Python.valueToCode(a, "y1", Blockly.Python.ORDER_ATOMIC),
  2414. d = Blockly.Python.valueToCode(a, "x2", Blockly.Python.ORDER_ATOMIC),
  2415. e = Blockly.Python.valueToCode(a, "y2", Blockly.Python.ORDER_ATOMIC);
  2416. a = a.getFieldValue("state");
  2417. return "lcd.line(" + b + ", " + c + ", " + d + ", " + e + ", " + a + ")\n"
  2418. };
  2419. Blockly.Python.CocoRobo_display_shape_rect = function (a) {
  2420. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2421. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2422. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2423. d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
  2424. e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC),
  2425. f = a.getFieldValue("state");
  2426. return "lcd." + a.getFieldValue("shape") + "(" + b + ", " + c + ", " + d + ", " + e + ", " + f + ")\n"
  2427. };
  2428. Blockly.Python.CocoRobo_display_rect = function (a) {
  2429. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2430. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2431. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2432. d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
  2433. e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
  2434. a = a.getFieldValue("state");
  2435. return "lcd.rect(" + b + ", " + c + ", " + d + ", " + e + ", " + a + ")\n"
  2436. };
  2437. Blockly.Python.CocoRobo_display_RoundRect = function (a) {
  2438. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2439. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2440. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2441. d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
  2442. e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC),
  2443. f = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC);
  2444. a = a.getFieldValue("state");
  2445. return "lcd.RoundRect(" + b + ", " + c + ", " + d + ", " + e + ", " + f + ", " + a + ")\n"
  2446. };
  2447. Blockly.Python.CocoRobo_display_fill_rect = function (a) {
  2448. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2449. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2450. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2451. d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
  2452. e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
  2453. a = a.getFieldValue("state");
  2454. return "lcd.fill_rect(" + b + ", " + c + ", " + d + ", " + e + ", " + a + ")\n"
  2455. };
  2456. Blockly.Python.CocoRobo_display_shape_circle = function (a) {
  2457. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2458. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2459. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2460. d = Blockly.Python.valueToCode(a, "radius", Blockly.Python.ORDER_ATOMIC),
  2461. e = a.getFieldValue("state");
  2462. return "lcd." + a.getFieldValue("shape") + "(" + b + ", " + c + ", " + d + ", " + e + ")\n"
  2463. };
  2464. Blockly.Python.CocoRobo_display_fill_circle = function (a) {
  2465. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2466. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2467. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2468. d = Blockly.Python.valueToCode(a, "radius", Blockly.Python.ORDER_ATOMIC);
  2469. a = a.getFieldValue("state");
  2470. return "lcd.fill_circle(" + b + ", " + c + ", " + d + ", " + a + ")\n"
  2471. };
  2472. Blockly.Python.CocoRobo_display_circle = function (a) {
  2473. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2474. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2475. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2476. d = Blockly.Python.valueToCode(a, "radius", Blockly.Python.ORDER_ATOMIC);
  2477. a = a.getFieldValue("state");
  2478. return "lcd.circle(" + b + ", " + c + ", " + d + ", " + a + ")\n"
  2479. };
  2480. Blockly.Python.CocoRobo_display_shape_triangle = function (a) {
  2481. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2482. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2483. c = Blockly.Python.valueToCode(a, "x2", Blockly.Python.ORDER_ATOMIC),
  2484. d = Blockly.Python.valueToCode(a, "x3", Blockly.Python.ORDER_ATOMIC),
  2485. e = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2486. f = Blockly.Python.valueToCode(a, "y2", Blockly.Python.ORDER_ATOMIC),
  2487. g = Blockly.Python.valueToCode(a, "y3", Blockly.Python.ORDER_ATOMIC),
  2488. h = a.getFieldValue("state");
  2489. return "lcd." + a.getFieldValue("shape") + "(" + b + ", " + e + ", " + c + ", " + f + ", " + d + ", " + g + ", " + h + ")\n"
  2490. };
  2491. Blockly.Python.CocoRobo_display_triangle = function (a) {
  2492. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2493. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2494. c = Blockly.Python.valueToCode(a, "x2", Blockly.Python.ORDER_ATOMIC),
  2495. d = Blockly.Python.valueToCode(a, "x3", Blockly.Python.ORDER_ATOMIC),
  2496. e = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2497. f = Blockly.Python.valueToCode(a, "y2", Blockly.Python.ORDER_ATOMIC),
  2498. g = Blockly.Python.valueToCode(a, "y3", Blockly.Python.ORDER_ATOMIC);
  2499. a = a.getFieldValue("state");
  2500. return "lcd.triangle(" + b + ", " + e + ", " + c + ", " + f + ", " + d + ", " + g + ", " + a + ")\n"
  2501. };
  2502. Blockly.Python.CocoRobo_display_fill_triangle = function (a) {
  2503. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2504. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2505. c = Blockly.Python.valueToCode(a, "x2", Blockly.Python.ORDER_ATOMIC),
  2506. d = Blockly.Python.valueToCode(a, "x3", Blockly.Python.ORDER_ATOMIC),
  2507. e = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2508. f = Blockly.Python.valueToCode(a, "y2", Blockly.Python.ORDER_ATOMIC),
  2509. g = Blockly.Python.valueToCode(a, "y3", Blockly.Python.ORDER_ATOMIC);
  2510. a = a.getFieldValue("state");
  2511. return "lcd.fill_triangle(" + b + ", " + e + ", " + c + ", " + f + ", " + d + ", " + g + ", " + a + ")\n"
  2512. };
  2513. Blockly.Python.CocoRobo_display_Bitmap = function (a) {
  2514. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2515. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2516. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2517. d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
  2518. e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC),
  2519. f = Blockly.Python.valueToCode(a, "Bitmap", Blockly.Python.ORDER_ATOMIC);
  2520. a = a.getFieldValue("state");
  2521. return "lcd.Bitmap(" + b + ", " + c + ", bytearray(" + f + "), " + d + ", " + e + ", " + a + ")\n"
  2522. };
  2523. Blockly.Python.CocoRobo_get_pbm_data = function (a) {
  2524. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2525. Blockly.Python.codeFunctions_.define_Image = "image_picture \x3d Image()";
  2526. var b = a.getFieldValue("select");
  2527. return ["image_picture.load(" + Blockly.Python.valueToCode(a, "file_path", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")", Blockly.Python.ORDER_ATOMIC]
  2528. };
  2529. Blockly.Python.CocoRobo_get_pbm_data_custom = Blockly.Python.CocoRobo_get_pbm_data;
  2530. Blockly.Python.CocoRobo_display_pbm_data = function (a) {
  2531. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2532. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2533. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
  2534. return "lcd.blit(" + Blockly.Python.valueToCode(a, "pbm_data", Blockly.Python.ORDER_ATOMIC) + ", " + b + ", " + c + ")\n"
  2535. };
  2536. Blockly.Python.CocoRobo_bitmap_from_file = function (a) {
  2537. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2538. Blockly.Python.definitions_.import_framebuf = "import framebuf";
  2539. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2540. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2541. d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
  2542. e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
  2543. return "lcd.blit(framebuf.FrameBuffer(" + Blockly.Python.valueToCode(a, "pbm_data", Blockly.Python.ORDER_ATOMIC) + "[2], " + d + ", " + e + ", framebuf.MONO_HLSB), " + b + ", " + c + ")\n"
  2544. };
  2545. Blockly.Python.CocoRobo_pbm_image = function(a) {
  2546. return ["'" + a.getFieldValue("path") + "'", Blockly.Python.ORDER_ATOMIC]
  2547. };
  2548. Blockly.Python.CocoRobo_font = function(a) {
  2549. return [a.getFieldValue("font"), Blockly.Python.ORDER_ATOMIC]
  2550. };
  2551. Blockly.Python.CocoRobo_display_font = function (a) {
  2552. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2553. Blockly.Python.definitions_.import_framebuf = "import framebuf";
  2554. var b = a.getFieldValue("font");
  2555. Blockly.Python.definitions_["import_" + b] = "import " + b;
  2556. Blockly.Python.codeFunctions_.display_font = "def display_font(_font, _str, _x, _y, _wrap, _z\x3d0):\n _start \x3d _x\n for _c in _str:\n _d \x3d _font.get_ch(_c)\n if _wrap and _x \x3e 128 - _d[2]: _x \x3d _start; _y +\x3d _d[1]\n if _c \x3d\x3d '1' and _z \x3e 0: lcd.fill_rect(_x, _y, _d[2], _d[1], 0)\n lcd.blit(framebuf.FrameBuffer(bytearray(_d[0]), _d[2], _d[1],\n framebuf.MONO_HLSB), (_x+int(_d[2]/_z)) if _c\x3d\x3d'1' and _z\x3e0 else _x, _y)\n _x +\x3d _d[2]";
  2557. var c = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  2558. d = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  2559. e = Blockly.Python.valueToCode(a, "message", Blockly.Python.ORDER_ATOMIC);
  2560. a = a.getFieldValue("wrap");
  2561. return b.startsWith("font.digiface_") ? "display_font(" + b + ", " + e + ", " + c + ", " + d + ", " + a + ", 2)\n" : "display_font(" + b + ", " + e + ", " + c + ", " + d + ", " + a + ")\n"
  2562. };
  2563. Blockly.Python.CocoRobo_display_custom_font = Blockly.Python.CocoRobo_display_font;
  2564. Blockly.Python.CocoRobo_display_FrameBuffer = function (a) {
  2565. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2566. Blockly.Python.definitions_.import_framebuf = "import framebuf";
  2567. var b = Blockly.Python.valueToCode(a, "bmp", Blockly.Python.ORDER_ATOMIC),
  2568. c = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
  2569. d = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
  2570. a = a.getFieldValue("scan_mode");
  2571. return "fb1 \x3d framebuf.FrameBuffer(" + b + ", " + c + ", " + d + ", framebuf.MONO_" + a + ")\n"
  2572. };
  2573. Blockly.Python.CocoRobo_display_blit = function (a) {
  2574. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2575. Blockly.Python.definitions_.import_framebuf = "import framebuf";
  2576. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC);
  2577. a = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
  2578. return "lcd.blit(fb1," + b + ", " + a + ")\n"
  2579. };
  2580. Blockly.Python.CocoRobo_front_reverse = function (a) {
  2581. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2582. return "lcd.invert(" + a.getFieldValue("front_reverse") + ")\n"
  2583. };
  2584. Blockly.Python.CocoRobo_images_append = function (a) {
  2585. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2586. Blockly.Python.definitions_.import_framebuf = "import framebuf";
  2587. Blockly.Python.definitions_.import_time = "import time";
  2588. var b = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC),
  2589. c = Blockly.Python.valueToCode(a, "Length", Blockly.Python.ORDER_ATOMIC),
  2590. d = Blockly.Python.valueToCode(a, "Width", Blockly.Python.ORDER_ATOMIC);
  2591. a = Blockly.Python.valueToCode(a, "period", Blockly.Python.ORDER_ATOMIC);
  2592. return "images \x3d []\nfor n in range(1," + b + "):\n with open('IMAGE.%s.pbm' % n, 'rb') as f:\n f.readline() # Magic number\n f.readline() # Creator comment\n f.readline() # Dimensions\n data \x3d bytearray(f.read())\n fbuf \x3d framebuf.FrameBuffer(data, " + c + "," + d + ", framebuf.MONO_HLSB)\n images.append(fbuf)\n\nfor i in images:\n lcd.blit(i, 0, 0)\n time.sleep(" + a + ")\n"
  2593. };
  2594. Blockly.Python.CocoRobo_radio_rec = function(a) {
  2595. Blockly.Python.definitions_.import_radio = "import radio";
  2596. return ["radio.receive()", Blockly.Python.ORDER_ATOMIC]
  2597. };
  2598. Blockly.Python.CocoRobo_radio_send = function(a) {
  2599. Blockly.Python.definitions_.import_radio = "import radio";
  2600. return "radio.send(" + Blockly.Python.valueToCode(a, "send", Blockly.Python.ORDER_ATOMIC) + ")\n"
  2601. };
  2602. Blockly.Python.CocoRobo_radio_channel = function(a) {
  2603. Blockly.Python.definitions_.import_radio = "import radio";
  2604. return "radio.config(channel\x3d" + Blockly.Python.valueToCode(a, "channel", Blockly.Python.ORDER_ATOMIC) + ")\n"
  2605. };
  2606. Blockly.Python.CocoRobo_radio_on_off = function(a) {
  2607. Blockly.Python.definitions_.import_radio = "import radio";
  2608. return "radio." + a.getFieldValue("on_off") + "()\n"
  2609. };
  2610. Blockly.Python.CocoRobo_radio_recv = function(a) {
  2611. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  2612. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  2613. try {
  2614. b.remove("_msg")
  2615. } catch (d) {}
  2616. b = b.length ? " global " + b.join(", ") + "\n" : "";
  2617. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2618. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  2619. Blockly.Python.definitions_.import_radio = "import radio";
  2620. Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
  2621. a = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
  2622. Blockly.Python.definitions_.def_radio_recv = "def radio_recv(_msg):\n" + b + a;
  2623. Blockly.Python.definitions_.def_radio_callback = "_radio_msg_list \x3d []\ndef radio_callback(_msg):\n global _radio_msg_list\n try: radio_recv(_msg)\n except: pass\n if _msg in _radio_msg_list:\n eval('radio_recv_' + bytes.decode(ubinascii.hexlify(_msg)) + '()')";
  2624. Blockly.Python.definitions_.def_Timer13 = "tim13 \x3d Timer(13)";
  2625. Blockly.Python.definitions_.timer13_tick = "def timer13_tick(_):\n _msg \x3d radio.receive()\n if not _msg: return\n radio_callback(_msg)\n";
  2626. Blockly.Python.definitions_.timer13_init = "tim13.init(period\x3d20, mode\x3dTimer.PERIODIC, callback\x3dtimer13_tick)\n";
  2627. return ""
  2628. };
  2629. Blockly.Python.CocoRobo_radio_recv_msg = function(a) {
  2630. for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
  2631. b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
  2632. try {
  2633. b.remove("_msg")
  2634. } catch (e) {}
  2635. b = b.length ? " global " + b.join(", ") + "\n" : "";
  2636. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2637. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  2638. Blockly.Python.definitions_.import_radio = "import radio";
  2639. Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
  2640. Blockly.Python.statementToCode(a, "DO");
  2641. Blockly.Python.definitions_.def_radio_callback = "_radio_msg_list \x3d []\ndef radio_callback(_msg):\n global _radio_msg_list\n try: radio_recv(_msg)\n except: pass\n if _msg in _radio_msg_list:\n eval('radio_recv_' + bytes.decode(ubinascii.hexlify(_msg)) + '()')";
  2642. Blockly.Python.definitions_.def_Timer13 = "tim13 \x3d Timer(13)";
  2643. Blockly.Python.definitions_.timer13_tick = "def timer13_tick(_):\n _msg \x3d radio.receive()\n if not _msg: return\n radio_callback(_msg)\n";
  2644. Blockly.Python.definitions_.timer13_init = "tim13.init(period\x3d20, mode\x3dTimer.PERIODIC, callback\x3dtimer13_tick)\n";
  2645. var c = a.getFieldValue("message"),
  2646. d = toUTF8Hex(c);
  2647. a = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
  2648. Blockly.Python.codeFunctions_["def_radio_recv_" + d] = "_radio_msg_list.append('" + c + "')\ndef radio_recv_" + d + "():\n" + b + a;
  2649. return ""
  2650. };
  2651. Blockly.Python.set_create_with_items_insert = function(a) {
  2652. var b = Array(a.itemCount_);
  2653. if (0 == a.itemCount_)
  2654. a = "set()";
  2655. else {
  2656. for (var c = 0; c < a.itemCount_; c++)
  2657. b[c] = Blockly.Python.valueToCode(a, "ADD" + c, Blockly.Python.ORDER_NONE) || "None";
  2658. a = "{" + b.join(", ") + "}"
  2659. }
  2660. return [a, Blockly.Python.ORDER_ATOMIC]
  2661. };
  2662. Blockly.Python.set_subset_superset = function(a) {
  2663. var b = a.getFieldValue("subset_superset"),
  2664. c = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
  2665. a = Blockly.Python.valueToCode(a, "set_1_name", Blockly.Python.ORDER_ATOMIC);
  2666. return [c + b + "(" + a + ")", Blockly.Python.ORDER_ATOMIC]
  2667. };
  2668. Blockly.Python.sets_update_ways = function(a) {
  2669. var b = a.getFieldValue("sets_update_ways"),
  2670. c = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
  2671. a = Blockly.Python.valueToCode(a, "set_1_name", Blockly.Python.ORDER_ATOMIC);
  2672. return c + b + "(" + a + ")\n"
  2673. };
  2674. Blockly.Python.get_sets_pop = function(a) {
  2675. return [Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC) + ".pop()", Blockly.Python.ORDER_ATOMIC]
  2676. };
  2677. Blockly.Python.len_of_sets = function(a) {
  2678. return ["len(" + Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
  2679. };
  2680. Blockly.Python.intersection_of_sets = function(a) {
  2681. var b = a.getFieldValue("set_operation_type"),
  2682. c = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
  2683. a = Blockly.Python.valueToCode(a, "set_1_name", Blockly.Python.ORDER_ATOMIC);
  2684. return [c + b + a, Blockly.Python.ORDER_ATOMIC]
  2685. };
  2686. Blockly.Python.set_update_with = function(a) {
  2687. var b = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
  2688. a = Blockly.Python.valueToCode(a, "set_items", Blockly.Python.ORDER_ATOMIC);
  2689. return b + ".update(" + a + ")\n"
  2690. };
  2691. Blockly.Python.set_create_with = function(a) {
  2692. var b = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
  2693. a = Blockly.Python.valueToCode(a, "set_items", Blockly.Python.ORDER_ATOMIC);
  2694. return b + " \x3d " + a + "\n"
  2695. };
  2696. Blockly.Python.text_set = function(a) {
  2697. return ["{" + Blockly.Python.quote_empty(a.getFieldValue("TEXT")) + "}", Blockly.Python.ORDER_ATOMIC]
  2698. };
  2699. Blockly.Python.create_empty_set = function(a) {
  2700. return Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC) + " \x3d set()\n"
  2701. };
  2702. Blockly.Python.set_tuple_order_item = function(a) {
  2703. var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC),
  2704. c = a.getFieldValue("tuple_order"),
  2705. d = Blockly.Python.valueToCode(a, "tuple_order_item", Blockly.Python.ORDER_ATOMIC);
  2706. a = Blockly.Python.valueToCode(a, "set_value", Blockly.Python.ORDER_ATOMIC);
  2707. return b + c + d + "] \x3d " + a + "\n"
  2708. };
  2709. Blockly.Python.tuple_create_with_items_insert = function(a) {
  2710. for (var b = Array(a.itemCount_), c = 0; c < a.itemCount_; c++)
  2711. b[c] = Blockly.Python.valueToCode(a, "ADD" + c, Blockly.Python.ORDER_NONE) || "None";
  2712. return [1 == a.itemCount_ ? "(" + b[0] + ",)" : "(" + b.join(", ") + ")", Blockly.Python.ORDER_ATOMIC]
  2713. };
  2714. Blockly.Python.tuple_create_with = function(a) {
  2715. var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC);
  2716. a = Blockly.Python.valueToCode(a, "tuple_items", Blockly.Python.ORDER_ATOMIC);
  2717. return b + " \x3d " + a + "\n"
  2718. };
  2719. Blockly.Python.tuple_order_item = function(a) {
  2720. var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC),
  2721. c = a.getFieldValue("tuple_order");
  2722. a = Blockly.Python.valueToCode(a, "tuple_order_item", Blockly.Python.ORDER_ATOMIC);
  2723. return [b + c + a + "]", Blockly.Python.ORDER_ATOMIC]
  2724. };
  2725. Blockly.Python.tuple_min_max_len = function(a) {
  2726. var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC);
  2727. return [a.getFieldValue("tuple_min_max_len") + "(" + b + ")", Blockly.Python.ORDER_ATOMIC]
  2728. };
  2729. Blockly.Python.tuple_item_exist = function(a) {
  2730. var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC);
  2731. return [Blockly.Python.valueToCode(a, "tuple_item", Blockly.Python.ORDER_ATOMIC) + " in " + b, Blockly.Python.ORDER_ATOMIC]
  2732. };
  2733. Blockly.Python.parts_of_tuple = function(a) {
  2734. var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC);
  2735. a = Blockly.Python.valueToCode(a, "tuple_item", Blockly.Python.ORDER_ATOMIC);
  2736. return [b + "[" + a + ":]", Blockly.Python.ORDER_ATOMIC]
  2737. };
  2738. Blockly.Python.parts_of_tuple2 = function(a) {
  2739. var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC),
  2740. c = a.getFieldValue("tuple_start_order"),
  2741. d = a.getFieldValue("tuple_end_order"),
  2742. e = Blockly.Python.valueToCode(a, "start_item", Blockly.Python.ORDER_ATOMIC);
  2743. a = Blockly.Python.valueToCode(a, "end_item", Blockly.Python.ORDER_ATOMIC);
  2744. switch (d) {
  2745. case ":":
  2746. var f = parseInt(a) + 1;
  2747. break;
  2748. case ":-":
  2749. f = a - 1
  2750. }
  2751. return [b + c + e + d + f + "]", Blockly.Python.ORDER_ATOMIC]
  2752. };
  2753. Blockly.Python.CocoRobo_uart_input = function(a) {
  2754. return ['input("' + a.getFieldValue("title") + '")', Blockly.Python.ORDER_ATOMIC]
  2755. };
  2756. Blockly.Python.CocoRobo_uart_write_bytes = function (a) {
  2757. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2758. var b = a.getFieldValue("uart_name");
  2759. a = Blockly.Python.valueToCode(a, "write_byte_arrays", Blockly.Python.ORDER_ATOMIC);
  2760. return b + ".write(bytes(" + a + "))\n"
  2761. };
  2762. Blockly.Python.CocoRobo_uart_get_write_bytes = function (a) {
  2763. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2764. var b = a.getFieldValue("uart_name");
  2765. a = Blockly.Python.valueToCode(a, "write_byte_arrays", Blockly.Python.ORDER_ATOMIC);
  2766. return [b + ".write(bytes(" + a + "))\n", Blockly.Python.ORDER_ATOMIC]
  2767. };
  2768. Blockly.Python.CocoRobo_uart_write_byte = function (a) {
  2769. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2770. var b = a.getFieldValue("uart_name");
  2771. a = Blockly.Python.valueToCode(a, "write_one_byte", Blockly.Python.ORDER_ATOMIC);
  2772. return b + ".write(bytes([" + a + "]))\n"
  2773. };
  2774. Blockly.Python.CocoRobo_uart_get_write_byte = function (a) {
  2775. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2776. var b = a.getFieldValue("uart_name");
  2777. a = Blockly.Python.valueToCode(a, "write_one_byte", Blockly.Python.ORDER_ATOMIC);
  2778. return [b + ".write(bytes([" + a + "]))\n", Blockly.Python.ORDER_ATOMIC]
  2779. };
  2780. Blockly.Python.CocoRobo_uart_read = function (a) {
  2781. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2782. return [a.getFieldValue("uart_name") + ".read()", Blockly.Python.ORDER_ATOMIC]
  2783. };
  2784. Blockly.Python.CocoRobo_uart_read_length = function (a) {
  2785. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2786. var b = a.getFieldValue("uart_name");
  2787. a = Blockly.Python.valueToCode(a, "read_length", Blockly.Python.ORDER_ATOMIC);
  2788. return [b + ".read(" + a + ")", Blockly.Python.ORDER_ATOMIC]
  2789. };
  2790. Blockly.Python.CocoRobo_uart_readline = function (a) {
  2791. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2792. return [a.getFieldValue("uart_name") + ".readline()", Blockly.Python.ORDER_ATOMIC]
  2793. };
  2794. Blockly.Python.CocoRobo_uart_has_data = function (a) {
  2795. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2796. return [a.getFieldValue("uart_name") + ".any()", Blockly.Python.ORDER_ATOMIC]
  2797. };
  2798. Blockly.Python.CocoRobo_uart_write_hex = function (a) {
  2799. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2800. var b = a.getFieldValue("uart_name"),
  2801. c = a.getFieldValue("data");
  2802. return "new" == a.getFieldValue("newline") ? b + ".write(hex(" + c + ') + "\\r\\n")\n' : b + ".write(hex(" + c + "))\n"
  2803. };
  2804. Blockly.Python.CocoRobo_uart_write_str = function (a) {
  2805. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2806. var b = a.getFieldValue("uart_name"),
  2807. c = Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC);
  2808. return "new" == a.getFieldValue("newline") ? b + ".write(" + c + ' + "\\r\\n")\n' : b + ".write(" + c + ")\n"
  2809. };
  2810. Blockly.Python.CocoRobo_uart_get_write_str = function (a) {
  2811. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2812. var b = a.getFieldValue("uart_name"),
  2813. c = Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC);
  2814. return ["new" == a.getFieldValue("newline") ? b + ".write(" + c + ' + "\\r\\n")\n' : b + ".write(" + c + ")\n", Blockly.Python.ORDER_ATOMIC]
  2815. };
  2816. Blockly.Python.CocoRobo_uart_init = function(a) {
  2817. Blockly.Python.definitions_.import_uart = "from machine import UART";
  2818. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2819. var b = a.getFieldValue("uart_name"),
  2820. c = b.replace("uart", ""),
  2821. d = Blockly.Python.valueToCode(a, "tx", Blockly.Python.ORDER_ATOMIC),
  2822. e = Blockly.Python.valueToCode(a, "rx", Blockly.Python.ORDER_ATOMIC);
  2823. a = Blockly.Python.valueToCode(a, "baudrate", Blockly.Python.ORDER_ATOMIC);
  2824. Blockly.Python.definitions_["uart_object" + b] = b + " \x3d UART(" + c + ", baudrate\x3d" + a + ", tx\x3dPin.P" + d + ", rx\x3dPin.P" + e + ")";
  2825. return ""
  2826. };
  2827. Blockly.Python.CocoRobo_uart_deinit = function (a) {
  2828. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2829. return a.getFieldValue("uart_name") + ".deinit()\n"
  2830. };
  2831. Blockly.Python.CocoRobo_usocket_read = function(a) {
  2832. Blockly.Python.definitions_.import_usocket = "import usocket";
  2833. var b = a.getFieldValue("socket_name");
  2834. a = Blockly.Python.valueToCode(a, "size", Blockly.Python.ORDER_ATOMIC);
  2835. return [b + ".read(" + a + ")", Blockly.Python.ORDER_ATOMIC]
  2836. };
  2837. Blockly.Python.CocoRobo_usocket_setblocking = function(a) {
  2838. Blockly.Python.definitions_.import_usocket = "import usocket";
  2839. var b = a.getFieldValue("socket_name");
  2840. a = a.getFieldValue("mode");
  2841. return b + ".setblocking(" + a + ")\n"
  2842. };
  2843. Blockly.Python.CocoRobo_usocket_settimeout = function(a) {
  2844. Blockly.Python.definitions_.import_usocket = "import usocket";
  2845. var b = a.getFieldValue("socket_name");
  2846. a = Blockly.Python.valueToCode(a, "_nums", Blockly.Python.ORDER_ATOMIC);
  2847. return b + ".settimeout(" + a + ")\n"
  2848. };
  2849. Blockly.Python.CocoRobo_usocket_recv = function(a) {
  2850. Blockly.Python.definitions_.import_usocket = "import usocket";
  2851. var b = a.getFieldValue("socket_name");
  2852. a = Blockly.Python.valueToCode(a, "_nums", Blockly.Python.ORDER_ATOMIC);
  2853. return [b + ".recv(" + a + ")", Blockly.Python.ORDER_ATOMIC]
  2854. };
  2855. Blockly.Python.CocoRobo_text_ESC = function(a) {
  2856. // Blockly.Python.definitions_.import_usocket = "import usocket";
  2857. return ['"' + a.getFieldValue("mode") + '"', Blockly.Python.ORDER_ATOMIC]
  2858. };
  2859. Blockly.Python.CocoRobo_usocket_recvfrom = function(a) {
  2860. Blockly.Python.definitions_.import_usocket = "import usocket";
  2861. var b = a.getFieldValue("socket_name");
  2862. a = Blockly.Python.valueToCode(a, "_nums", Blockly.Python.ORDER_ATOMIC);
  2863. return [b + ".recvfrom(" + a + ")", Blockly.Python.ORDER_ATOMIC]
  2864. };
  2865. Blockly.Python.CocoRobo_usocket_sendall = function(a) {
  2866. Blockly.Python.definitions_.import_usocket = "import usocket";
  2867. var b = a.getFieldValue("socket_name");
  2868. a = Blockly.Python.valueToCode(a, "_bytes", Blockly.Python.ORDER_ATOMIC);
  2869. return b + ".sendall(" + a + ")\n"
  2870. };
  2871. Blockly.Python.CocoRobo_usocket_sends = function(a) {
  2872. Blockly.Python.definitions_.import_usocket = "import usocket";
  2873. var b = a.getFieldValue("socket_name");
  2874. a = Blockly.Python.valueToCode(a, "_bytes", Blockly.Python.ORDER_ATOMIC);
  2875. return b + ".send(" + a + ")\n"
  2876. };
  2877. Blockly.Python.CocoRobo_usocket_send = function(a) {
  2878. Blockly.Python.definitions_.import_usocket = "import usocket";
  2879. var b = a.getFieldValue("socket_name");
  2880. a = Blockly.Python.valueToCode(a, "_bytes", Blockly.Python.ORDER_ATOMIC);
  2881. return [b + ".send(bytes(" + a + ", 'utf-8'))", Blockly.Python.ORDER_ATOMIC]
  2882. };
  2883. Blockly.Python.CocoRobo_usocket_sendto = function(a) {
  2884. Blockly.Python.definitions_.import_usocket = "import usocket";
  2885. var b = a.getFieldValue("socket_name"),
  2886. c = Blockly.Python.valueToCode(a, "_bytes", Blockly.Python.ORDER_ATOMIC);
  2887. a = Blockly.Python.valueToCode(a, "_address", Blockly.Python.ORDER_ATOMIC);
  2888. return b + ".sendto(bytes(" + c + ", 'utf-8'), " + a + ")\n"
  2889. };
  2890. Blockly.Python.CocoRobo_usocket_connect = function(a) {
  2891. Blockly.Python.definitions_.import_usocket = "import usocket";
  2892. var b = a.getFieldValue("socket_name"),
  2893. c = Blockly.Python.valueToCode(a, "host", Blockly.Python.ORDER_ATOMIC);
  2894. a = Blockly.Python.valueToCode(a, "port", Blockly.Python.ORDER_ATOMIC);
  2895. return b + ".connect((" + c + ", " + a + "))\n"
  2896. };
  2897. Blockly.Python.CocoRobo_usocket_getaddrinfo = function(a) {
  2898. Blockly.Python.definitions_.import_usocket = "import usocket";
  2899. var b = Blockly.Python.valueToCode(a, "host", Blockly.Python.ORDER_ATOMIC);
  2900. a = Blockly.Python.valueToCode(a, "port", Blockly.Python.ORDER_ATOMIC);
  2901. return ["(usocket.getaddrinfo(" + b + ", " + a + ")[0][-1])[0]", Blockly.Python.ORDER_ATOMIC]
  2902. };
  2903. Blockly.Python.CocoRobo_usocket_accept = function(a) {
  2904. Blockly.Python.definitions_.import_usocket = "import usocket";
  2905. return [a.getFieldValue("socket_name") + ".accept()", Blockly.Python.ORDER_ATOMIC]
  2906. };
  2907. Blockly.Python.CocoRobo_usocket_listen = function(a) {
  2908. Blockly.Python.definitions_.import_usocket = "import usocket";
  2909. var b = a.getFieldValue("socket_name");
  2910. a = Blockly.Python.valueToCode(a, "backlog", Blockly.Python.ORDER_ATOMIC);
  2911. return b + ".listen(" + a + ")\n"
  2912. };
  2913. Blockly.Python.CocoRobo_usocket_bind = function(a) {
  2914. Blockly.Python.definitions_.import_usocket = "import usocket";
  2915. var b = a.getFieldValue("socket_name"),
  2916. c = Blockly.Python.valueToCode(a, "address", Blockly.Python.ORDER_ATOMIC);
  2917. a = Blockly.Python.valueToCode(a, "port", Blockly.Python.ORDER_ATOMIC);
  2918. return b + ".bind((" + c + ", " + a + "))\n"
  2919. };
  2920. Blockly.Python.CocoRobo_usocket_init = function(a) {
  2921. Blockly.Python.definitions_.import_usocket = "import usocket";
  2922. var b = a.getFieldValue("socket_name"),
  2923. c = a.getFieldValue("af");
  2924. a = a.getFieldValue("_type");
  2925. Blockly.Python.codeFunctions_.init_usocket = b + " \x3d usocket.socket(usocket." + c + ", usocket." + a + ")";
  2926. return ""
  2927. };
  2928. Blockly.Python.CocoRobo_usocket_setsockopt = function(a) {
  2929. Blockly.Python.definitions_.import_usocket = "import usocket";
  2930. var b = a.getFieldValue("socket_name"),
  2931. c = Blockly.Python.valueToCode(a, "value", Blockly.Python.ORDER_ATOMIC);
  2932. a = a.getFieldValue("_type");
  2933. Blockly.Python.codeFunctions_.init_setsockopt = b + ".setsockopt(usocket.SOL_SOCKET, usocket." + a + ", " + c + ")";
  2934. return ""
  2935. };
  2936. Blockly.Python.CocoRobo_usocket_close = function(a) {
  2937. Blockly.Python.definitions_.import_usocket = "import usocket";
  2938. return a.getFieldValue("socket_name") + ".close()\n"
  2939. };
  2940. Blockly.Python.CocoRobo_get_post = function(a) {
  2941. Blockly.Python.definitions_.import_urequests = "import urequests";
  2942. Blockly.Python.definitions_.import_json = "import json";
  2943. var b = a.getFieldValue("get_post"),
  2944. c = Blockly.Python.valueToCode(a, "url", Blockly.Python.ORDER_ATOMIC);
  2945. a = Blockly.Python.valueToCode(a, "json", Blockly.Python.ORDER_ATOMIC) || "None";
  2946. return "None" == a ? "_response \x3d urequests." + b + "(" + c + ")\n" : "_response \x3d urequests." + b + "(" + c + ', headers\x3d{"Content-Type":"application/json"}, params\x3d' + a + ")\n"
  2947. };
  2948. Blockly.Python.CocoRobo_urequests_get_post = function(a) {
  2949. Blockly.Python.definitions_.import_urequests = "import requests";
  2950. Blockly.Python.definitions_.import_json = "import json";
  2951. var b = Blockly.Python.valueToCode(a, "url", Blockly.Python.ORDER_ATOMIC),
  2952. c = a.getFieldValue("method");
  2953. a = Blockly.Python.valueToCode(a, "json", Blockly.Python.ORDER_ATOMIC) || "None";
  2954. var code = "_SEND_HTTP_GET_ENDPOINT = " + b + "\n";
  2955. if ("None" != a) {
  2956. code += "_SEND_HTTP_POST_DATA = " + a + "\n";
  2957. }
  2958. Blockly.Python.addSetup("CocoRobo_urequests_get_post", code);
  2959. Blockly.Python.addVariable("_SEND_HTTP_REQUEST", "None");
  2960. return "None" == a ? "_SEND_HTTP_REQUEST \x3d requests." + c + "(_SEND_HTTP_GET_ENDPOINT)\n" : "_response \x3d requests." + c + "(" + b + ', headers\x3d{"Content-Type":"application/json"}, data\x3d\'' + a + "')\n";
  2961. };
  2962. Blockly.Python.CocoRobo_urequests_post_file = function(a) {
  2963. Blockly.Python.definitions_.import_urequests = "import requests";
  2964. Blockly.Python.definitions_.import_json = "import json";
  2965. var b = Blockly.Python.valueToCode(a, "url", Blockly.Python.ORDER_ATOMIC),
  2966. c = Blockly.Python.valueToCode(a, "file_name", Blockly.Python.ORDER_ATOMIC),
  2967. d = Blockly.Python.valueToCode(a, "file_type", Blockly.Python.ORDER_ATOMIC),
  2968. c = '{"file":(' + c + ", " + d + ")}";
  2969. a = Blockly.Python.valueToCode(a, "json", Blockly.Python.ORDER_ATOMIC) || "None";
  2970. return "None" == a ? "_response \x3d requests.post(" + b + ", files\x3d" + c + ")\n" : "_response \x3d requests.post(" + b + ", files\x3d" + c + ", params\x3d" + a + ")\n"
  2971. };
  2972. Blockly.Python.CocoRobo_response = function(a) {
  2973. Blockly.Python.definitions_.import_urequests = "import urequests";
  2974. return ["_response." + a.getFieldValue("response"), Blockly.Python.ORDER_ATOMIC]
  2975. };
  2976. Blockly.Python.CocoRobo_response_attribute = function(a) {
  2977. Blockly.Python.definitions_.import_urequests = "import urequests";
  2978. return ["_response." + a.getFieldValue("response_attribute"), Blockly.Python.ORDER_ATOMIC]
  2979. };
  2980. Blockly.Python.CocoRobo_init_wifi = function (a) {
  2981. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2982. Blockly.Python.definitions_.import_network = "import network";
  2983. var b = Blockly.Python.valueToCode(a, "ssid", Blockly.Python.ORDER_ATOMIC);
  2984. a = Blockly.Python.valueToCode(a, "password", Blockly.Python.ORDER_ATOMIC);
  2985. var _code = 'init_sta = network.WLAN(network.STA_IF)\n' +
  2986. 'init_ap = network.WLAN(network.AP_IF)\n' +
  2987. 'init_ap.active(False)\n' +
  2988. 'init_sta.active(True)\n' +
  2989. 'init_sta.connect(essid=' + b + ', password=' + a + ')\n';
  2990. // Blockly.Python.definitions_.wifi_define = "my_wifi \x3d wifi()";
  2991. // Blockly.Python.definitions_.my_wifi = "my_wifi.connectWiFi(" + b + ", " + a + ")\n";
  2992. return _code;
  2993. };
  2994. Blockly.Python.CocoRobo_dis_WiFi = function (a) {
  2995. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  2996. Blockly.Python.definitions_.import_network = "import network";
  2997. //Blockly.Python.codeFunctions_.wifi_define = "my_wifi \x3d wifi()";
  2998. return "init_sta.active(False)\n"
  2999. };
  3000. Blockly.Python.CocoRobo_wifi_all_config = function (a) {
  3001. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3002. Blockly.Python.definitions_.import_network = "import network";
  3003. return ["my_wifi.sta.ifconfig()", Blockly.Python.ORDER_ATOMIC]
  3004. };
  3005. Blockly.Python.CocoRobo_wifi_isconnected = function (a) {
  3006. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3007. Blockly.Python.definitions_.import_network = "import network";
  3008. return ["init_sta.isconnected()", Blockly.Python.ORDER_ATOMIC]
  3009. };
  3010. Blockly.Python.CocoRobo_WiFi_config = function (a) {
  3011. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3012. Blockly.Python.definitions_.import_network = "import network";
  3013. return ["init_sta.ifconfig()[" + a.getFieldValue("WiFi_config") + "]", Blockly.Python.ORDER_ATOMIC]
  3014. };
  3015. Blockly.Python.CocoRobo_wifi_channel = function(a) {
  3016. return [a.getFieldValue("channel"), Blockly.Python.ORDER_ATOMIC]
  3017. };
  3018. Blockly.Python.CocoRobo_enable_APWiFi = function (a) {
  3019. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3020. Blockly.Python.definitions_.import_network = "import network";
  3021. var b = Blockly.Python.valueToCode(a, "essid", Blockly.Python.ORDER_ATOMIC),
  3022. c = Blockly.Python.valueToCode(a, "password", Blockly.Python.ORDER_ATOMIC);
  3023. "" == c && (c = '""');
  3024. a = Blockly.Python.valueToCode(a, "channel", Blockly.Python.ORDER_ATOMIC);
  3025. var _code = "init_sta = network.WLAN(network.STA_IF)\n" +
  3026. "init_ap = network.WLAN(network.AP_IF)\n" +
  3027. "init_sta.active(False)\n" +
  3028. "init_ap.active(True)\n";
  3029. if (c == '""') {
  3030. _code += "init_ap.config(essid=" + b + ", authmode=0, channel=" + a + ", hidden=0, dhcp_hostname=\"CocoRobo_AP\")\n";
  3031. } else {
  3032. _code += "init_ap.config(essid=" + b + ", authmode=3, password=" + c + ", channel=" + a + ", hidden=0, dhcp_hostname=\"CocoRobo_AP\")\n";
  3033. }
  3034. return _code;
  3035. };
  3036. Blockly.Python.CocoRobo_disable_APWiFi = function (a) {
  3037. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3038. Blockly.Python.definitions_.import_network = "import network";
  3039. // Blockly.Python.codeFunctions_.wifi_define = "my_wifi \x3d wifi()";
  3040. return "init_ap.active(False)\n"
  3041. };
  3042. Blockly.Python.CocoRobo_ntptime_settime = function (a) {
  3043. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3044. Blockly.Python.definitions_.import_ntptime = "import ntptime";
  3045. return "ntptime.settime()\n";
  3046. };
  3047. Blockly.Python.CocoRobo_seniverse_city_weather = function(a) {
  3048. Blockly.Python.definitions_.import_json = "import json";
  3049. Blockly.Python.definitions_.import_urequests = "import urequests";
  3050. var b = Blockly.Python.valueToCode(a, "location", Blockly.Python.ORDER_ATOMIC);
  3051. "" == b && (b = "ip");
  3052. var c = a.getFieldValue("api");
  3053. a.getFieldValue("type");
  3054. var d = a.getFieldValue("key"),
  3055. e = a.getFieldValue("language");
  3056. a = a.getFieldValue("unit");
  3057. var f = "https://api.seniverse.com/v3/weather/now.json";
  3058. switch (c) {
  3059. case "api_2":
  3060. f = "https://api.seniverse.com/v3/weather/daily.json";
  3061. break;
  3062. case "api_3":
  3063. f = "https://api.seniverse.com/v3/life/suggestion.json"
  3064. }
  3065. Blockly.Python.codeFunctions_.get_seni_weather = 'def get_seni_weather(_url, _location):\n _url \x3d _url + "\x26location\x3d" + _location.replace(" ", "%20")\n response \x3d urequests.get(_url)\n json \x3d response.json()\n response.close()\n return json\n';
  3066. f += "?key\x3d" + d;
  3067. "zh-Hant" == e && (f += "\x26language\x3dzh-Hant");
  3068. "f" == a && "api_3" != c && (f += "\x26unit\x3df");
  3069. return ['get_seni_weather("' + f + '", ' + b + ")", Blockly.Python.ORDER_ATOMIC]
  3070. };
  3071. Blockly.Python.CocoRobo_define_seniverse_weather = function(a) {
  3072. var b = a.getFieldValue("var_name");
  3073. a = Blockly.Python.valueToCode(a, "info", Blockly.Python.ORDER_ATOMIC);
  3074. return b + " \x3d " + a + "\n"
  3075. };
  3076. Blockly.Python.CocoRobo_get_seniverse_weather_info = function(a) {
  3077. var b = a.getFieldValue("var_name");
  3078. a = a.getFieldValue("type");
  3079. switch (a) {
  3080. case "object":
  3081. break;
  3082. case "last_update":
  3083. b += '["results"][0]["last_update"]';
  3084. break;
  3085. case "last_update_date":
  3086. b += '["results"][0]["last_update"][:10]';
  3087. break;
  3088. default:
  3089. b = b + '["results"][0]["location"]["' + a + '"]'
  3090. }
  3091. return [b, Blockly.Python.ORDER_ATOMIC]
  3092. };
  3093. Blockly.Python.CocoRobo_get_seniverse_weather_info1 = function(a) {
  3094. var b = a.getFieldValue("var_name");
  3095. a = a.getFieldValue("type");
  3096. return [b + '["results"][0]["now"]["' + a + '"]', Blockly.Python.ORDER_ATOMIC]
  3097. };
  3098. Blockly.Python.CocoRobo_get_seniverse_weather_info2 = function(a) {
  3099. var b = a.getFieldValue("var_name"),
  3100. c = a.getFieldValue("date");
  3101. a = a.getFieldValue("type");
  3102. return [b + '["results"][0]["daily"][' + c + ']["' + a + '"]', Blockly.Python.ORDER_ATOMIC]
  3103. };
  3104. Blockly.Python.CocoRobo_get_seniverse_weather_info3 = function(a) {
  3105. var b = a.getFieldValue("var_name");
  3106. a = a.getFieldValue("type");
  3107. return [b + '["results"][0]["suggestion"]["' + a + '"]["brief"]', Blockly.Python.ORDER_ATOMIC]
  3108. };
  3109. Blockly.Python.CocoRobo_wifi_clock = function (a) {
  3110. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3111. Blockly.Python.definitions_.import_network = "import network";
  3112. Blockly.Python.definitions_.import_ntptime = "import ntptime";
  3113. Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
  3114. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  3115. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
  3116. a = Blockly.Python.valueToCode(a, "radius", Blockly.Python.ORDER_ATOMIC);
  3117. Blockly.Python.codeFunctions_.def_wifi_clock = 'def wifi_clock(x, y, radius):\n try:\n ntptime.settime()\n except OSError :\n lcd.DispChar("ntp\u94fe\u63a5\u8d85\u65f6,\u8bf7\u91cd\u542f!",0,20)\n lcd.show()\n else:\n clock\x3dClock(lcd, x, y, radius)\n\n def Refresh(_):\n clock.settime()\n clock.drawClock()\n lcd.show()\n clock.clear()\n\n tim1 \x3d Timer(1)\n tim1.init(period\x3d1000, mode\x3dTimer.PERIODIC, callback\x3dRefresh)\n';
  3118. return "wifi_clock(" + b + ", " + c + ", " + a + ")\n"
  3119. };
  3120. Blockly.Python.CocoRobobox_slider = function(a) {
  3121. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3122. return ["slider_res.read()", Blockly.Python.ORDER_ATOMIC]
  3123. };
  3124. Blockly.Python.CocoRobobox_5button = function(a) {
  3125. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3126. return ["get_key() \x3d\x3d {" + a.getFieldValue("button_val") + "}", Blockly.Python.ORDER_ATOMIC]
  3127. };
  3128. Blockly.Python.CocoRobobox_ultrasonic = function(a) {
  3129. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3130. return ["get_distance()", Blockly.Python.ORDER_ATOMIC]
  3131. };
  3132. Blockly.Python.CocoRobobox_Thehumanbodyinfrare = function(a) {
  3133. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3134. return ["pir.value()", Blockly.Python.ORDER_ATOMIC]
  3135. };
  3136. Blockly.Python.CocoRobobox_sound = function (a) {
  3137. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3138. Blockly.Python.codeFunctions_.init_sound = "sound.init()";
  3139. return ["sound.read()", Blockly.Python.ORDER_ATOMIC]
  3140. };
  3141. Blockly.Python.CocoRobobox_light = function (a) {
  3142. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3143. return ["light.read()", Blockly.Python.ORDER_ATOMIC]
  3144. };
  3145. Blockly.Python.CocoRobo_bme280_hum_tem_pre = function (a) {
  3146. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3147. return ["bme280." + a.getFieldValue("hum_tem_pre") + "()", Blockly.Python.ORDER_ATOMIC]
  3148. };
  3149. Blockly.Python.CocoRobobox_motor = function(a) {
  3150. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3151. return "set_motor(" + Blockly.Python.valueToCode(a, "speed", Blockly.Python.ORDER_ATOMIC) + ")\n"
  3152. };
  3153. Blockly.Python.CocoRobobox_RGB_clear = function(a) {
  3154. Blockly.Python.definitions_.import_machine_only = "import machine";
  3155. return "machine.display.clear()\n"
  3156. };
  3157. Blockly.Python.CocoRobobox_RGB_pixel = function(a) {
  3158. Blockly.Python.definitions_.import_machine_only = "import machine";
  3159. var b = Blockly.Python.valueToCode(a, "speed1", Blockly.Python.ORDER_ATOMIC),
  3160. c = Blockly.Python.valueToCode(a, "speed2", Blockly.Python.ORDER_ATOMIC),
  3161. d = Blockly.Python.valueToCode(a, "speed3", Blockly.Python.ORDER_ATOMIC),
  3162. e = Blockly.Python.valueToCode(a, "speed4", Blockly.Python.ORDER_ATOMIC);
  3163. a = Blockly.Python.valueToCode(a, "speed5", Blockly.Python.ORDER_ATOMIC);
  3164. return "machine.display.set_pixel(" + b + ", " + c + ", (" + d + ", " + e + ", " + a + "))\n"
  3165. };
  3166. Blockly.Python.CocoRobobox_RGB_get_pixel = function(a) {
  3167. Blockly.Python.definitions_.import_machine_only = "import machine";
  3168. var b = Blockly.Python.valueToCode(a, "speed1", Blockly.Python.ORDER_ATOMIC);
  3169. a = Blockly.Python.valueToCode(a, "speed2", Blockly.Python.ORDER_ATOMIC);
  3170. return ["machine.display.get_pixel(" + b + ", " + a + ")", Blockly.Python.ORDER_ATOMIC]
  3171. };
  3172. Blockly.Python.CocoRobobox_RGB_ImageText = function(a) {
  3173. Blockly.Python.definitions_.import_machinee_only = "import machine";
  3174. var b = Blockly.Python.valueToCode(a, "speed1", Blockly.Python.ORDER_ATOMIC);
  3175. a = Blockly.Python.valueToCode(a, "speed2", Blockly.Python.ORDER_ATOMIC);
  3176. return "machine.display.scroll(" + b + ", " + a + ")\n"
  3177. };
  3178. Blockly.Python.CocoRobobox_RGB_SetImage = function(a) {
  3179. Blockly.Python.definitions_.import_machine_only = "import machine";
  3180. var b = Blockly.Python.valueToCode(a, "row0", Blockly.Python.ORDER_MEMBER),
  3181. c = Blockly.Python.valueToCode(a, "row1", Blockly.Python.ORDER_MEMBER),
  3182. d = Blockly.Python.valueToCode(a, "row2", Blockly.Python.ORDER_MEMBER),
  3183. e = Blockly.Python.valueToCode(a, "row3", Blockly.Python.ORDER_MEMBER);
  3184. a = Blockly.Python.valueToCode(a, "row4", Blockly.Python.ORDER_MEMBER);
  3185. return ["machine.Image(str(" + b + ") + ':' + str(" + c + ") + ':' + str(" + d + ") + ':' + str(" + e + ") + ':' + str(" + a + "))", Blockly.Python.ORDER_MEMBER]
  3186. };
  3187. Blockly.Python.CocoRobobox_RGB_Image = function(a) {
  3188. Blockly.Python.definitions_.import_machine_only = "import machine";
  3189. return "machine.display.show(" + Blockly.Python.valueToCode(a, "image", Blockly.Python.ORDER_MEMBER) + ")\n"
  3190. };
  3191. Blockly.Python.CocoRobobox_RGB_ImageImport = function(a) {
  3192. Blockly.Python.definitions_.import_machine_only = "import machine";
  3193. return [Blockly.Python.valueToCode(a, "image", Blockly.Python.ORDER_MEMBER), Blockly.Python.ORDER_ATOMIC]
  3194. };
  3195. Blockly.Python.CocoRobobox_RGB_ImageCopy = function(a) {
  3196. Blockly.Python.definitions_.import_machine_only = "import machine";
  3197. return [Blockly.Python.valueToCode(a, "image", Blockly.Python.ORDER_MEMBER) + ".copy()", Blockly.Python.ORDER_ATOMIC]
  3198. };
  3199. Blockly.Python.CocoRobobox_RGB_ImageCot = function(a) {
  3200. Blockly.Python.definitions_.import_machine_only = "import machine";
  3201. var b = Blockly.Python.valueToCode(a, "image", Blockly.Python.ORDER_MEMBER),
  3202. c = Blockly.Python.valueToCode(a, "speed2", Blockly.Python.ORDER_ATOMIC),
  3203. d = Blockly.Python.valueToCode(a, "speed3", Blockly.Python.ORDER_ATOMIC),
  3204. e = Blockly.Python.valueToCode(a, "speed4", Blockly.Python.ORDER_ATOMIC);
  3205. a = Blockly.Python.valueToCode(a, "speed5", Blockly.Python.ORDER_ATOMIC);
  3206. return [b + ".crop(" + c + "," + d + "," + e + "," + a + ")", Blockly.Python.ORDER_ATOMIC]
  3207. };
  3208. Blockly.Python.CocoRobo_image_builtins = function(a) {
  3209. Blockly.Python.definitions_.import_machine_only = "import machine";
  3210. return ["machine.Image." + a.getFieldValue("image"), Blockly.Python.ORDER_MEMBER]
  3211. };
  3212. Blockly.Python.CocoRobobox_image_shift = function(a) {
  3213. Blockly.Python.definitions_.import_machine_only = "import machine";
  3214. var b = Blockly.Python.valueToCode(a, "image", Blockly.Python.ORDER_MEMBER),
  3215. c = a.getFieldValue("shift");
  3216. a = Blockly.Python.valueToCode(a, "pos", Blockly.Python.ORDER_ATOMIC);
  3217. switch (c) {
  3218. case "LEFT":
  3219. b = b + ".shift_left(" + a + ")";
  3220. break;
  3221. case "RIGHT":
  3222. b = b + ".shift_right(" + a + ")";
  3223. break;
  3224. case "UP":
  3225. b = b + ".shift_up(" + a + ")";
  3226. break;
  3227. case "DOWN":
  3228. b = b + ".shift_down(" + a + ")"
  3229. }
  3230. return [b, Blockly.Python.ORDER_MEMBER]
  3231. };
  3232. Blockly.Python.CocoRobobox_triaxial_acceleration = function (a) {
  3233. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3234. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3235. return ["motion.get_accel()[" + a.getFieldValue("enable") + "]", Blockly.Python.ORDER_ATOMIC]
  3236. };
  3237. Blockly.Python.CocoRobobox_triaxial_angular_velocity = function (a) {
  3238. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3239. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3240. return ["motion.get_gyro()[" + a.getFieldValue("enable") + "]", Blockly.Python.ORDER_ATOMIC]
  3241. };
  3242. Blockly.Python.CocoRobobox_euler_angle = function (a) {
  3243. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3244. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3245. return ["motion.get_euler()[" + a.getFieldValue("enable") + "]", Blockly.Python.ORDER_ATOMIC]
  3246. };
  3247. Blockly.Python.CocoRobobox_quaternion = function (a) {
  3248. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3249. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3250. return ["motion.get_quat()[" + a.getFieldValue("enable") + "]", Blockly.Python.ORDER_ATOMIC]
  3251. };
  3252. Blockly.Python.CocoRobo_AI2_Face_tracking = function (a) {
  3253. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3254. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3255. Blockly.Python.codeFunctions_.model_FACE_YOLO = "model.select_model(model.FACE_YOLO)";
  3256. return ""
  3257. };
  3258. Blockly.Python.CocoRobo_AI2_Face_photograph_tracking = function (a) {
  3259. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3260. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3261. return "result_face \x3d model.detect_yolo()\n"
  3262. };
  3263. Blockly.Python.CocoRobo_AI2_result_face = function (a) {
  3264. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3265. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3266. return ["result_face", Blockly.Python.ORDER_ATOMIC]
  3267. };
  3268. Blockly.Python.CocoRobo_AI2_result_face_x = function (a) {
  3269. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3270. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3271. return ['result_face[0]["x"]', Blockly.Python.ORDER_ATOMIC]
  3272. };
  3273. Blockly.Python.CocoRobo_AI2_result_face_y = function (a) {
  3274. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3275. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3276. return ['result_face[0]["y"]', Blockly.Python.ORDER_ATOMIC]
  3277. };
  3278. Blockly.Python.CocoRobo_AI2_result_face_w = function (a) {
  3279. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3280. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3281. return ['result_face[0]["w"]', Blockly.Python.ORDER_ATOMIC]
  3282. };
  3283. Blockly.Python.CocoRobo_AI2_result_face_h = function (a) {
  3284. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3285. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3286. return ['result_face[0]["h"]', Blockly.Python.ORDER_ATOMIC]
  3287. };
  3288. Blockly.Python.CocoRobo_AI2_result_face_value = function (a) {
  3289. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3290. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3291. return ['result_face[0]["value"]', Blockly.Python.ORDER_ATOMIC]
  3292. };
  3293. Blockly.Python.CocoRobo_AI2_result_face_objnum = function (a) {
  3294. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3295. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3296. return ['result_face[0]["objnum"]', Blockly.Python.ORDER_ATOMIC]
  3297. };
  3298. Blockly.Python.CocoRobo_AI2_20classid_tracking = function (a) {
  3299. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3300. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3301. Blockly.Python.codeFunctions_.model_CLASS_20_YOLO = "model.select_model(model.CLASS_20_YOLO)";
  3302. return ""
  3303. };
  3304. Blockly.Python.CocoRobo_AI2_20classid_photograph_tracking = function (a) {
  3305. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3306. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3307. return "result_20class \x3d model.detect_yolo()\n"
  3308. };
  3309. Blockly.Python.CocoRobo_AI2_result_20class = function (a) {
  3310. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3311. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3312. return ["result_20class", Blockly.Python.ORDER_ATOMIC]
  3313. };
  3314. Blockly.Python.CocoRobo_AI2_result_20class_x = function (a) {
  3315. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3316. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3317. return ['result_20class[0]["x"]', Blockly.Python.ORDER_ATOMIC]
  3318. };
  3319. Blockly.Python.CocoRobo_AI2_result_20class_y = function (a) {
  3320. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3321. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3322. return ['result_20class[0]["y"]', Blockly.Python.ORDER_ATOMIC]
  3323. };
  3324. Blockly.Python.CocoRobo_AI2_result_20class_w = function (a) {
  3325. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3326. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3327. return ['result_20class[0]["w"]', Blockly.Python.ORDER_ATOMIC]
  3328. };
  3329. Blockly.Python.CocoRobo_AI2_result_20class_h = function (a) {
  3330. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3331. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3332. return ['result_20class[0]["h"]', Blockly.Python.ORDER_ATOMIC]
  3333. };
  3334. Blockly.Python.CocoRobo_AI2_result_20class_value = function (a) {
  3335. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3336. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3337. return ['result_20class[0]["value"]', Blockly.Python.ORDER_ATOMIC]
  3338. };
  3339. Blockly.Python.CocoRobo_AI2_result_20class_objnum = function (a) {
  3340. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3341. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3342. return ['result_20class[0]["objnum"]', Blockly.Python.ORDER_ATOMIC]
  3343. };
  3344. Blockly.Python.CocoRobo_AI2_result_20class_classid = function (a) {
  3345. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3346. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3347. return ['result_20class[0]["classid"]', Blockly.Python.ORDER_ATOMIC]
  3348. };
  3349. Blockly.Python.CocoRobo_AI2_result_20class_index = function (a) {
  3350. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3351. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3352. return ['result_20class[0]["index"]', Blockly.Python.ORDER_ATOMIC]
  3353. };
  3354. Blockly.Python.CocoRobo_AI2_20class_tracking = function (a) {
  3355. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3356. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3357. Blockly.Python.codeFunctions_.model_CLASS_20_YOLO = "model.select_model(model.CLASS_20_YOLO)";
  3358. return "result_20class \x3d model.detect_yolo()\n"
  3359. };
  3360. Blockly.Python.CocoRobo_AI2_number_discern = function (a) {
  3361. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3362. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3363. Blockly.Python.codeFunctions_.model_MNIST_NET = "model.select_model(model.MNIST_NET)";
  3364. return ""
  3365. };
  3366. Blockly.Python.CocoRobo_AI2_number_result = function (a) {
  3367. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3368. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3369. return "discern_number \x3d model.predict_net()\n"
  3370. };
  3371. Blockly.Python.CocoRobo_AI_NumberDetect_all = function (a) {
  3372. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3373. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3374. return ["discern_number", Blockly.Python.ORDER_ATOMIC]
  3375. };
  3376. Blockly.Python.CocoRobo_AI_NumberDetect_number = function (a) {
  3377. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3378. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3379. Blockly.Python.definitions_.result_numbers = "def result_numbers():\n result_adience \x3d 0\n result_numbers \x3d 0\n for i in range(10):\n if result_adience \x3c discern_number[i]:\n result_adience \x3d discern_number[i]\n result_numbers \x3d i\n return result_numbers";
  3380. return ["result_numbers()", Blockly.Python.ORDER_ATOMIC]
  3381. };
  3382. Blockly.Python.CocoRobo_AI_NumberDetect_adience = function (a) {
  3383. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3384. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3385. Blockly.Python.definitions_.result_adience = "def result_adience():\n result_adience \x3d 0\n for i in range(10):\n if result_adience \x3c discern_number[i]:\n result_adience \x3d discern_number[i]\n return result_adience";
  3386. return ["result_adience()", Blockly.Python.ORDER_ATOMIC]
  3387. };
  3388. Blockly.Python.CocoRobo_AI_trace_color = function (a) {
  3389. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3390. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3391. var b = Blockly.Python.valueToCode(a, "area", Blockly.Python.ORDER_ATOMIC),
  3392. c = Blockly.Python.valueToCode(a, "pixel", Blockly.Python.ORDER_ATOMIC);
  3393. return ["image.find_blobs([" + Blockly.Python.valueToCode(a, "lab", Blockly.Python.ORDER_ATOMIC) + "], pixels_threshold\x3d" + c + ", area_threshold\x3d" + b + ")", Blockly.Python.ORDER_ATOMIC]
  3394. };
  3395. Blockly.Python.CocoRobo_AI_trace_color_displayten = function (a) {
  3396. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3397. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3398. return "image.draw_" + a.getFieldValue("number") + "\n"
  3399. };
  3400. Blockly.Python.CocoRobo_AI2_blob_all = function (a) {
  3401. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3402. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3403. return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC), Blockly.Python.ORDER_ATOMIC]
  3404. };
  3405. Blockly.Python.CocoRobo_AI2_blob_x = function (a) {
  3406. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3407. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3408. return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".x()", Blockly.Python.ORDER_ATOMIC]
  3409. };
  3410. Blockly.Python.CocoRobo_AI2_blob_y = function (a) {
  3411. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3412. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3413. return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".y()", Blockly.Python.ORDER_ATOMIC]
  3414. };
  3415. Blockly.Python.CocoRobo_AI2_blob_w = function (a) {
  3416. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3417. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3418. return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".w()", Blockly.Python.ORDER_ATOMIC]
  3419. };
  3420. Blockly.Python.CocoRobo_AI2_blob_h = function (a) {
  3421. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3422. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3423. return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".h()", Blockly.Python.ORDER_ATOMIC]
  3424. };
  3425. Blockly.Python.CocoRobo_AI2_blob_number = function (a) {
  3426. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3427. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3428. return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".pixels()", Blockly.Python.ORDER_ATOMIC]
  3429. };
  3430. Blockly.Python.CocoRobo_AI2_blob_center_x = function (a) {
  3431. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3432. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3433. return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".cx()", Blockly.Python.ORDER_ATOMIC]
  3434. };
  3435. Blockly.Python.CocoRobo_AI2_blob_center_y = function (a) {
  3436. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3437. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3438. return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".cy()", Blockly.Python.ORDER_ATOMIC]
  3439. };
  3440. Blockly.Python.CocoRobo_AI2_blob_orthogon = function (a) {
  3441. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3442. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3443. return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".rect()", Blockly.Python.ORDER_ATOMIC]
  3444. };
  3445. Blockly.Python.CocoRobo_AI_sensor_reset = function (a) {
  3446. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3447. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3448. Blockly.Python.codeFunctions_.camera_reset = "camera.reset()\n";
  3449. return ""
  3450. };
  3451. Blockly.Python.CocoRobo_AI_sensor_images = function (a) {
  3452. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3453. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3454. return "camera.snapshot()\n"
  3455. };
  3456. Blockly.Python.CocoRobo_AI_sensor_enable = function (a) {
  3457. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3458. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3459. return "camera.run(" + a.getFieldValue("enable") + ")\n"
  3460. };
  3461. Blockly.Python.CocoRobo_AI_sensor_return = function (a) {
  3462. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3463. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3464. return ["image." + a.getFieldValue("enable") + "()", Blockly.Python.ORDER_ATOMIC]
  3465. };
  3466. Blockly.Python.CocoRobo_AI_sensor_sets = function(a) {
  3467. var b = a.getFieldValue("pattern");
  3468. a = a.getFieldValue("number");
  3469. return "camera.set_" + b + "(" + a + ")\n"
  3470. };
  3471. Blockly.Python.CocoRobo_AI_sensor_auto_gain = function (a) {
  3472. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3473. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3474. return "camera.set_auto_gain(" + a.getFieldValue("enable") + ")\n"
  3475. };
  3476. Blockly.Python.CocoRobo_AI_sensor_auto_whitebal = function (a) {
  3477. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3478. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3479. return "camera.set_auto_whitebal(" + a.getFieldValue("enable") + ")\n"
  3480. };
  3481. Blockly.Python.CocoRobo_AI_sensor_level_MI = function (a) {
  3482. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3483. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3484. var b = a.getFieldValue("select");
  3485. a = a.getFieldValue("enable");
  3486. return "camera.set_" + b + "(" + a + ")\n"
  3487. };
  3488. Blockly.Python.CocoRobo_AI_sensor_pattern = function (a) {
  3489. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3490. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3491. a = a.getFieldValue("yolo");
  3492. Blockly.Python.codeFunctions_.set_pixformat = "camera.set_pixformat(camera." + a + ")\n";
  3493. return ""
  3494. };
  3495. Blockly.Python.CocoRobo_AI_lcd_init = function (a) {
  3496. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3497. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3498. Blockly.Python.codeFunctions_.AI_lcd_init = "lcd.init()\n";
  3499. return ""
  3500. };
  3501. Blockly.Python.CocoRobo_AI_lcd_text = function(a) {
  3502. Blockly.Python.definitions_.import_lcd = "import lcd";
  3503. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  3504. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
  3505. a = Blockly.Python.valueToCode(a, "message", Blockly.Python.ORDER_ATOMIC);
  3506. return "lcd_draw_string(lcd," + b + ", " + c + ", " + a + ", lcd.RED, lcd.BLACK)\n"
  3507. };
  3508. Blockly.Python.CocoRobo_AI_LCD_clearall = function (a) {
  3509. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3510. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3511. return "image.clear()\n"
  3512. };
  3513. Blockly.Python.CocoRobo_AI_lcd_pixel_colour = function (a) {
  3514. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3515. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3516. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  3517. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  3518. d = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
  3519. e = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC);
  3520. a = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
  3521. return "image.set_pixel(" + b + ", " + c + ", color\x3d(" + d + ", " + e + ", " + a + "))\n"
  3522. };
  3523. Blockly.Python.CocoRobo_AI_lcd_colour = function (a) {
  3524. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3525. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3526. var b = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
  3527. c = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC);
  3528. a = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
  3529. return "lcd.clear(color\x3d(" + b + ", " + c + ", " + a + "))\n"
  3530. };
  3531. Blockly.Python.CocoRobo_AI_lcd_display = function (a) {
  3532. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3533. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3534. return "lcd.display()\n"
  3535. };
  3536. Blockly.Python.CocoRobo_AI_lcd_display_size = function (a) {
  3537. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3538. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3539. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  3540. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  3541. d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC);
  3542. a = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
  3543. return "lcd.display(roi\x3d(" + b + ", " + c + ", " + d + ", " + a + "))\n"
  3544. };
  3545. Blockly.Python.CocoRobo_AI_lcd_show_image_erosion = function (a) {
  3546. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3547. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3548. return "image.dilate(" + Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC) + ", threshold\x3dFalse)\n"
  3549. };
  3550. Blockly.Python.CocoRobo_AI_lcd_show_image_middle = function (a) {
  3551. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3552. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3553. var b = Blockly.Python.valueToCode(a, "size", Blockly.Python.ORDER_ATOMIC);
  3554. a = Blockly.Python.valueToCode(a, "bias", Blockly.Python.ORDER_ATOMIC);
  3555. return "image.midpoint(" + b + ", bias\x3d" + a + ")\n"
  3556. };
  3557. Blockly.Python.CocoRobo_AI_lcd_show_image_mode = function (a) {
  3558. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3559. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3560. return "image.mode(" + Blockly.Python.valueToCode(a, "size", Blockly.Python.ORDER_ATOMIC) + ")\n"
  3561. };
  3562. Blockly.Python.CocoRobo_AI_lcd_show_image_indistinct = function (a) {
  3563. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3564. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3565. return "image.midpoint(" + Blockly.Python.valueToCode(a, "size", Blockly.Python.ORDER_ATOMIC) + ")\n"
  3566. };
  3567. Blockly.Python.CocoRobo_AI_lcd_show_image_cartoon = function (a) {
  3568. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3569. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3570. var b = Blockly.Python.valueToCode(a, "size", Blockly.Python.ORDER_ATOMIC),
  3571. c = Blockly.Python.valueToCode(a, "seed", Blockly.Python.ORDER_ATOMIC);
  3572. a = Blockly.Python.valueToCode(a, "floating", Blockly.Python.ORDER_ATOMIC);
  3573. return "image.cartoon(" + b + ", seed_threshold\x3d" + c + ", floating_threshold\x3d" + a + ")\n"
  3574. };
  3575. Blockly.Python.CocoRobo_AI_lcd_show_image_3D = function (a) {
  3576. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3577. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3578. var b = Blockly.Python.valueToCode(a, "x_rotation", Blockly.Python.ORDER_ATOMIC),
  3579. c = Blockly.Python.valueToCode(a, "y_rotation", Blockly.Python.ORDER_ATOMIC),
  3580. d = Blockly.Python.valueToCode(a, "z_rotation", Blockly.Python.ORDER_ATOMIC),
  3581. e = Blockly.Python.valueToCode(a, "x_translation", Blockly.Python.ORDER_ATOMIC),
  3582. f = Blockly.Python.valueToCode(a, "y_translation", Blockly.Python.ORDER_ATOMIC);
  3583. a = Blockly.Python.valueToCode(a, "zoom", Blockly.Python.ORDER_ATOMIC);
  3584. return "image.rotation_corr(x_rotation\x3d" + b + ", y_rotation\x3d" + c + ", z_rotation\x3d" + d + ", x_translation\x3d" + e + ", y_translation\x3d" + f + ", zoom\x3d" + a + ")\n"
  3585. };
  3586. Blockly.Python.CocoRobo_AI_LCD_show_REC = function (a) {
  3587. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3588. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3589. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  3590. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  3591. d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
  3592. e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC),
  3593. f = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
  3594. g = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC),
  3595. h = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC),
  3596. k = Blockly.Python.valueToCode(a, "thickness", Blockly.Python.ORDER_ATOMIC);
  3597. a = a.getFieldValue("solid");
  3598. return "image.draw_rectangle(" + b + ", " + c + ", " + d + ", " + e + ",color\x3d(" + f + ", " + g + ", " + h + "),thickness\x3d" + k + ", fill\x3d" + a + ")\n"
  3599. };
  3600. Blockly.Python.CocoRobo_AI_LCD_show_string = function (a) {
  3601. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3602. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3603. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  3604. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  3605. d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
  3606. e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC),
  3607. f = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
  3608. g = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC),
  3609. h = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
  3610. a = Blockly.Python.valueToCode(a, "thickness", Blockly.Python.ORDER_ATOMIC);
  3611. return "image.draw_line(" + b + ", " + c + ", " + d + ", " + e + ", color\x3d(" + f + ", " + g + ", " + h + "), thickness\x3d" + a + ")\n"
  3612. };
  3613. Blockly.Python.CocoRobo_AI_LCD_return_colour = function (a) {
  3614. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3615. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3616. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC);
  3617. a = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
  3618. return ["image.get_pixel(" + b + ", " + a + ")", Blockly.Python.ORDER_ATOMIC]
  3619. };
  3620. Blockly.Python.CocoRobo_AI_LCD_show_circle = function (a) {
  3621. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3622. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3623. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  3624. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  3625. d = Blockly.Python.valueToCode(a, "radius", Blockly.Python.ORDER_ATOMIC),
  3626. e = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
  3627. f = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC),
  3628. g = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC),
  3629. h = Blockly.Python.valueToCode(a, "thickness", Blockly.Python.ORDER_ATOMIC);
  3630. a = a.getFieldValue("fill");
  3631. return "image.draw_circle(" + b + ", " + c + ", " + d + ",color\x3d(" + e + ", " + f + ", " + g + "),thickness\x3d" + h + ", fill\x3d" + a + ")\n"
  3632. };
  3633. Blockly.Python.CocoRobo_AI_lcd_text_most = function (a) {
  3634. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3635. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3636. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  3637. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  3638. d = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
  3639. e = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC),
  3640. f = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC),
  3641. g = Blockly.Python.valueToCode(a, "scale", Blockly.Python.ORDER_ATOMIC);
  3642. a = Blockly.Python.valueToCode(a, "message", Blockly.Python.ORDER_ATOMIC);
  3643. return "image.draw_string(" + b + ", " + c + "," + a + ", color\x3d(" + d + ", " + e + ", " + f + "), scale\x3d" + g + ", x_spacing\x3d0, y_spacing\x3d0, mono_space\x3dFalse)\n"
  3644. };
  3645. Blockly.Python.CocoRobo_AI_LCD_show_ten_string = function (a) {
  3646. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3647. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3648. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  3649. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  3650. d = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
  3651. e = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC),
  3652. f = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC),
  3653. g = Blockly.Python.valueToCode(a, "size", Blockly.Python.ORDER_ATOMIC);
  3654. a = Blockly.Python.valueToCode(a, "thickness", Blockly.Python.ORDER_ATOMIC);
  3655. return "image.draw_cross(" + b + ", " + c + ", color\x3d(" + d + ", " + e + ", " + f + "), size\x3d" + g + ", thickness\x3d" + a + ")\n"
  3656. };
  3657. Blockly.Python.CocoRobo_AI_LCD_show_arrows = function (a) {
  3658. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3659. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3660. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  3661. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  3662. d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
  3663. e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC),
  3664. f = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
  3665. g = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC),
  3666. h = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
  3667. a = Blockly.Python.valueToCode(a, "thickness", Blockly.Python.ORDER_ATOMIC);
  3668. return "image.draw_arrow(" + b + "," + c + "," + d + "," + e + ",color\x3d(" + f + "," + g + "," + h + "),thickness\x3d" + a + ")\n"
  3669. };
  3670. Blockly.Python.CocoRobo_AI_lcd_show_image_picture = function (a) {
  3671. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3672. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3673. return "image.load(" + Blockly.Python.valueToCode(a, "message", Blockly.Python.ORDER_ATOMIC) + ")\n"
  3674. };
  3675. Blockly.Python.CocoRobo_AI_lcd_show_image_heat = function (a) {
  3676. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3677. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3678. return "image." + a.getFieldValue("enable") + "()\n"
  3679. };
  3680. Blockly.Python.CocoRobo_AI_lcd_show_image_descartes = function (a) {
  3681. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3682. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3683. var b = a.getFieldValue("enable");
  3684. a = a.getFieldValue("select");
  3685. return "image." + b + "(reverse\x3d" + a + ")\n"
  3686. };
  3687. Blockly.Python.CocoRobo_AI_lcd_show_ectype = function (a) {
  3688. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3689. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3690. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  3691. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  3692. d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
  3693. e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
  3694. return "image.save(" + Blockly.Python.valueToCode(a, "message", Blockly.Python.ORDER_ATOMIC) + ", roi\x3d(" + b + ", " + c + ", " + d + ", " + e + "))\n"
  3695. };
  3696. Blockly.Python.CocoRobo_AI_lcd_show_ectype_show = function (a) {
  3697. //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
  3698. Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
  3699. var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
  3700. c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
  3701. d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC);
  3702. a = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
  3703. return "image.copy(roi\x3d(" + b + ", " + c + ", " + d + ", " + a + "))\n"
  3704. };