1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709 |
- goog.provide('Blockly.Python.CocoRobo');
- goog.require('Blockly.Python');
- Blockly.BlockSvg.SEP_SPACE_X = 8;
- Array.prototype.indexOf = function(a) {
- for (var b = 0; b < this.length; b++)
- if (this[b] == a)
- return b;
- return -1
- };
- Array.prototype.remove = function(a) {
- a = this.indexOf(a); -
- 1 < a && this.splice(a, 1)
- };
- var writeUTF = function(a, b) {
- for (var c = [], d = 0, e = 0; e < a.length; e++) {
- var f = a.charCodeAt(e);
- if (0 <= f && 127 >= f)
- d += 1,
- c.push(f);
- else if (128 <= f && 2047 >= f)
- d += 2,
- c.push(192 | 31 & f >> 6),
- c.push(128 | 63 & f);
- else if (2048 <= f && 55295 >= f || 57344 <= f && 65535 >= f)
- d += 3,
- c.push(224 | 15 & f >> 12),
- c.push(128 | 63 & f >> 6),
- c.push(128 | 63 & f)
- }
- for (e = 0; e < c.length; e++)
- c[e] &= 255;
- return b ? c : 255 >= d ? [0, d].concat(c) : [d >> 8, d & 255].concat(c)
- },
- toUTF8Hex = function(a) {
- a = writeUTF(a, !0);
- for (var b = "", c = 0; c < a.length; c++) {
- var d = (a[c] & 255).toString(16);
- 1 === d.length && (d = "0" + d);
- b += d
- }
- return b
- };
- Blockly.Python.i2c_pin = function(a) {
- return ["" + a.getFieldValue("i2c_pin"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.uart_rx_pin = function(a) {
- return ["" + a.getFieldValue("uart_rx_pin"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.uart_tx_pin = function(a) {
- return ["" + a.getFieldValue("uart_tx_pin"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.dh11_hum_tem_pin = function(a) {
- return ["" + a.getFieldValue("dh11_hum_tem_pin"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.pwm_pin = function(a) {
- return ["" + a.getFieldValue("pwm_pin"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.all_pin = function(a) {
- return ["" + a.getFieldValue("all_pin"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.set_analog = function(a) {
- return ["" + a.getFieldValue("set_analog"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.set_digital = function(a) {
- return ["" + a.getFieldValue("set_digital"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.read_analog_pin = function(a) {
- return ["" + a.getFieldValue("read_analog_pin"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.input_pin = function(a) {
- return ["" + a.getFieldValue("input_pin"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.output_pin = function(a) {
- return ["" + a.getFieldValue("output_pin"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.china_city = function(a) {
- var b = a.getFieldValue("province");
- a = a.getFieldValue("city");
- return ['"' + CITYS_DATA[b][a].pinyin + '"', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.china_city_town = function(a) {
- var b = a.getFieldValue("province"),
- c = a.getFieldValue("city"),
- d = a.getFieldValue("town");
- a = a.getFieldValue("type");
- return ['"' + getCityInfo(b, c, d, a) + '"', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.math_on_list = function(a) {
- var b = a.getFieldValue("OP");
- a = Blockly.Python.valueToCode(a, "LIST", Blockly.Python.ORDER_NONE) || "[]";
- switch (b) {
- case "SUM":
- b = "sum(" + a + ")";
- break;
- case "MIN":
- b = "min(" + a + ")";
- break;
- case "MAX":
- b = "max(" + a + ")";
- break;
- case "AVERAGE":
- b = Blockly.Python.provideFunction_("math_mean", ["def " + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + "(myList):", " return float(sum(myList)) / len(myList)"]);
- b = b + "(" + a + ")";
- break;
- case "MEDIAN":
- 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]"]);
- b = b + "(" + a + ")";
- break;
- case "MODE":
- 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"]);
- b = b + "(" + a + ")";
- break;
- case "STD_DEV":
- Blockly.Python.definitions_.import_math = "import math";
- 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)"]);
- b = b + "(" + a + ")";
- break;
- case "RANDOM":
- Blockly.Python.definitions_.import_random = "import random";
- b = "random.choice(" + a + ")";
- break;
- default:
- throw "Unknown operator: " + b;
- }
- return [b, Blockly.Python.ORDER_FUNCTION_CALL]
- };
- Blockly.Python.int_to_chr = function(a) {
- return ["str(" + Blockly.Python.valueToCode(a, "_int", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_hcsr04_obj = function(a) {
- Blockly.Python.definitions_.from_hcsr04_import_HCSR04 = "from hcsr04 import HCSR04";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("hcsr04_name"),
- c = Blockly.Python.valueToCode(a, "trigger", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "echo", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["CocoRobo_hcsr04_object" + b] = b + " \x3d HCSR04(trigger_pin\x3dPin.P" + c + ", echo_pin\x3dPin.P" + a + ")";
- return "\n"
- };
- Blockly.Python.CocoRobo_hcsr04_distance = function(a) {
- Blockly.Python.definitions_.from_hcsr04_import_HCSR04 = "from hcsr04 import HCSR04";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("hcsr04_name");
- a = a.getFieldValue("unit");
- return [b + ".distance_" + a + "()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_hcsr04_distance_mm = function(a) {
- Blockly.Python.definitions_.from_hcsr04_import_HCSR04 = "from hcsr04 import HCSR04";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return [a.getFieldValue("hcsr04_name") + ".distance_mm()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_pm2_5_MIC = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- var b = Blockly.Python.valueToCode(a, "rx", Blockly.Python.ORDER_ATOMIC);
- 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)";
- return [a.getFieldValue("unit"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_pm2_5_LitresAir = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- var b = Blockly.Python.valueToCode(a, "rx", Blockly.Python.ORDER_ATOMIC);
- 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)";
- return [a.getFieldValue("unit"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_mac_address = function(a) {
- Blockly.Python.definitions_.import_machine = "import machine";
- Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
- return ["ubinascii.hexlify(machine.unique_id()).decode().upper()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_ujson_loads = function(a) {
- Blockly.Python.definitions_.import_ujson = "import json";
- return ["json.loads(" + Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_code_annotation = function(a) {
- var code = Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC);
- return "# " + code.replace('"','').replace('"','') + "\n";
- };
- Blockly.Python.CocoRobo_ujson_dumps = function(a) {
- Blockly.Python.definitions_.import_ujson = "import json";
- return ["json.dumps(" + Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_base64_to_data = function(a) {
- Blockly.Python.definitions_.v831_import_base64 = "import base64";
- return ["base64.b64decode(" + Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_data_to_base64 = function(a) {
- Blockly.Python.definitions_.v831_import_base64 = "import base64";
- return ["base64.b64encode("+Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC) + ".encode('utf-8'))", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_hex_to_bin_str = function(a) {
- return ["bytes.fromhex(" + Blockly.Python.valueToCode(a, "convert_chr", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_str_to_hex = function(a) {
- return [Blockly.Python.valueToCode(a, "convert_chr", Blockly.Python.ORDER_ATOMIC)+".encode().hex()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_chr_to_int = function(a) {
- return ["ord(" + Blockly.Python.valueToCode(a, "convert_chr", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_int_to_chr = function(a) {
- return ["chr(" + Blockly.Python.valueToCode(a, "convert_num", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_ten_converted_to_bytes = function(a) {
- Blockly.Python.definitions_.import_struct = "import struct";
- var b = Blockly.Python.valueToCode(a, "convert_num", Blockly.Python.ORDER_ATOMIC);
- return ["struct.pack(" + a.getFieldValue("convert_choice") + ", " + b + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_convert_to_ten = function(a) {
- var b = Blockly.Python.valueToCode(a, "convert_str", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("convert_choice");
- return ["int(" + b + ", " + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_ten_convert_to = function(a) {
- var b = Blockly.Python.valueToCode(a, "int_num", Blockly.Python.ORDER_ATOMIC);
- return [a.getFieldValue("ten_convert_to") + "(" + b + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_high_low = function(a) {
- return [a.getFieldValue("high_low"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_baudrate = function(a) {
- return [a.getFieldValue("baudrate"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_start_new_thread = function(a) {
- Blockly.Python.definitions_.import_thread = "import _thread";
- var b = a.getFieldValue("thread_name"),
- c = Blockly.Python.statementToCode(a, "DO"),
- c = Blockly.Python.addLoopTrap(c, a.id) || Blockly.Python.PASS;
- Blockly.Python.codeFunctions_["thread_" + b] = "def thread_" + b + "():\n" + c;
- return "_thread.start_new_thread(thread_" + b + ", ())\n"
- };
- Blockly.Python.text_is_number = function(a) {
- var b = Blockly.Python.valueToCode(a, "TEXT", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("TYPE");
- return [b + a, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_lock_object_acquire_lock = function(a) {
- Blockly.Python.definitions_.import_thread = "import _thread";
- a = a.getFieldValue("thread_lock_object");
- Blockly.Python.definitions_.def_thread_lock_object = a + " \x3d _thread.allocate_lock()";
- return a + ".acquire()\n"
- };
- Blockly.Python.text_format = function(a) {
- var b = Blockly.Python.valueToCode(a, "FORMAT", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "CONTENT", Blockly.Python.ORDER_ATOMIC);
- return [b + " % " + a, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.text_format2 = function(a) {
- var b = Blockly.Python.valueToCode(a, "FORMAT", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "CONTENT", Blockly.Python.ORDER_ATOMIC);
- return [b + ".format" + a, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bytes_decode = function(a) {
- return [Blockly.Python.valueToCode(a, "bytes_decode", Blockly.Python.ORDER_ATOMIC) + ".decode('UTF-8','ignore')", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.text_to_byte = function(a) {
- return ["bytes(" + Blockly.Python.valueToCode(a, "TEXT", Blockly.Python.ORDER_ATOMIC) + ", 'utf-8')", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.other_to_byte = function(a) {
- return ["bytes(" + Blockly.Python.valueToCode(a, "input_var", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.bit_inversion = function(a) {
- return ["~" + Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_try_except = function(a) {
- var b = Blockly.Python.statementToCode(a, "TRY") || Blockly.Python.PASS;
- a = Blockly.Python.statementToCode(a, "EXCEPT") || Blockly.Python.PASS;
- return "try:\n" + b + "except:\n" + a
- };
- Blockly.Python.CocoRobo_try_except_finally = function(a) {
- var b = Blockly.Python.statementToCode(a, "TRY") || Blockly.Python.PASS,
- c = Blockly.Python.statementToCode(a, "EXCEPT") || Blockly.Python.PASS;
- a = Blockly.Python.statementToCode(a, "FINALLY") || Blockly.Python.PASS;
- return "try:\n" + b + "except:\n" + c + "finally:\n" + a
- };
- Blockly.Python.text_append_text = function(a) {
- var b = Blockly.Python.valueToCode(a, "text_abc", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "append_text", Blockly.Python.ORDER_ATOMIC);
- return ["str(" + b + ") + str(" + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_custom_code = function(a) {
- var b = a.getFieldValue("custom_type");
- a = a.getFieldValue("custom_code");
- return "topping" == b ? (Blockly.Python.definitions_.import_custom = a,
- "") : a + "\n"
- };
- Blockly.Python.CocoRobo_machine_reset = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_machine = "import machine";
- return "machine.reset()\n"
- };
- Blockly.Python.math_random_randrange = function(a) {
- Blockly.Python.definitions_.import_time = "import time";
- // Blockly.Python.codeFunctions_.random_seed = "random.seed(time.ticks_cpu())";
- Blockly.Python.definitions_.import_random = "import random";
- var b = Blockly.Python.valueToCode(a, "start", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "stop", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "step", Blockly.Python.ORDER_ATOMIC);
- return ["random.randrange(" + b + ", " + c + ", " + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.math_angle = function(a) {
- return [a.getFieldValue("angle"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.math_keep_decimal = function(a) {
- var b = Blockly.Python.valueToCode(a, "NUM", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "PLACE", Blockly.Python.ORDER_ATOMIC);
- return ["round(" + b + ", " + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.labplus_mapping = function(a) {
- Blockly.Python.definitions_.import_CocoRobo_mapping = "" +
- "def numberMap(value, leftMin, leftMax, rightMin, rightMax):\n" +
- " leftSpan = leftMax - leftMin\n" +
- " rightSpan = rightMax - rightMin\n" +
- " valueScaled = float(value - leftMin) / float(leftSpan)\n" +
- " return rightMin + (valueScaled * rightSpan)\n" +
- "";
- var b = Blockly.Python.valueToCode(a, "inputNum", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.valueToCode(a, "outputNum", Blockly.Python.ORDER_ATOMIC);
- var c = Blockly.Python.valueToCode(a, "bMin", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "bMax", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "cMin", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "cMax", Blockly.Python.ORDER_ATOMIC);
- return ["numberMap(" + b + "," + c + "," + d + "," + e + "," + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_Timer = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- b = b.length ? " global " + b.join(", ") + "\n" : "";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- var c = Blockly.Python.valueToCode(a, "Num", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "period", Blockly.Python.ORDER_ATOMIC),
- e = a.getFieldValue("Timer_mode"),
- f = Blockly.Python.statementToCode(a, "DO"),
- f = Blockly.Python.addLoopTrap(f, a.id) || Blockly.Python.PASS;
- Blockly.Python.definitions_["timer" + c + "_tick"] = "def timer" + c + "_tick(_):\n" + b + f;
- Blockly.Python.definitions_["def_Timer" + c] = "tim" + c + " \x3d Timer(" + c + ")";
- return "tim" + c + ".init(period\x3d" + d + ", mode\x3dTimer." + e + ", callback\x3dtimer" + c + "_tick)\n"
- };
- Blockly.Python.CocoRobo_timer_option = function(a) {
- return [a.getFieldValue("Timer_num"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_event_option = Blockly.Python.CocoRobo_timer_option;
- Blockly.Python.CocoRobo_Timer_value = function(a) {
- return ["tim" + Blockly.Python.valueToCode(a, "Timer_num", Blockly.Python.ORDER_ATOMIC) + ".value()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_Timer_deinit = function(a) {
- return "tim" + Blockly.Python.valueToCode(a, "Timer_num", Blockly.Python.ORDER_ATOMIC) + ".deinit()\n"
- };
- Blockly.Python.CocoRobo_Interrupt_pin = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- b = b.length ? " global " + b.join(", ") + "\n" : "";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var c = Blockly.Python.valueToCode(a, "Interrupt_pin", Blockly.Python.ORDER_ATOMIC),
- d = a.getFieldValue("action"),
- e = Blockly.Python.statementToCode(a, "DO"),
- e = Blockly.Python.addLoopTrap(e, a.id) || Blockly.Python.PASS;
- Blockly.Python.definitions_["PinMode_IN" + c] = "p" + c + " \x3d CocoRoboPin(" + c + ", PinMode.IN)";
- 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(_)";
- Blockly.Python.definitions_["on_pin" + c + "_" + d] = "def on_pin" + c + "_" + d + "(_):\n" + b + e;
- Blockly.Python.codeFunctions_["Interrupt_pin" + c] = "p" + c + ".irq(trigger\x3dPin." + ("to_high" == d ? "IRQ_RISING" : "IRQ_FALLING") + ", handler\x3don_pin" + c + "_" + d + ")";
- "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] = "";
- return ""
- };
- Blockly.Python.CocoRobo_Interrupt_AB = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- b = b.length ? " global " + b.join(", ") + "\n" : "";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_time = "import time";
- var c = a.getFieldValue("button"),
- d = a.getFieldValue("action"),
- e = Blockly.Python.statementToCode(a, "DO"),
- e = Blockly.Python.addLoopTrap(e, a.id) || Blockly.Python.PASS;
- Blockly.Python.definitions_["on_" + c] = "def on_" + c + "(_):\n if 0 \x3d\x3d _.value():\n on_" + c + "_down(_)\n else:\n on_" + c + "_up(_)";
- 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;
- Blockly.Python.codeFunctions_["Interrupt_" + c] = c + ".irq(trigger\x3dPin." + ("down" == d ? "IRQ_FALLING" : "IRQ_RISING") + ", handler\x3don_" + c + "_" + d + ")";
- "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] = "";
- return ""
- };
- Blockly.Python.CocoRobo_is_tilted = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- switch (a.getFieldValue("direction")) {
- case "forward":
- return ["accelerometer.get_x() \x3c -0.3", Blockly.Python.ORDER_ATOMIC];
- case "back":
- return ["accelerometer.get_x() \x3e 0.3", Blockly.Python.ORDER_ATOMIC];
- case "right":
- return ["accelerometer.get_y() \x3c -0.3", Blockly.Python.ORDER_ATOMIC];
- case "left":
- return ["accelerometer.get_y() \x3e 0.3", Blockly.Python.ORDER_ATOMIC];
- default:
- return ""
- }
- };
- Blockly.Python.CocoRobo_tilt_detector = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- b = b.length ? " global " + b.join(", ") + "\n" : "";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- var c = a.getFieldValue("direction"),
- d = Blockly.Python.statementToCode(a, "DO"),
- d = Blockly.Python.addLoopTrap(d, a.id) || Blockly.Python.PASS;
- 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";
- Blockly.Python.definitions_.def_Timer14 = "tim14 \x3d Timer(14)";
- 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";
- Blockly.Python.definitions_.timer14_init = "tim14.init(period\x3d200, mode\x3dTimer.PERIODIC, callback\x3dtimer14_tick)\n";
- Blockly.Python.definitions_["on_tilt_" + c] = "def on_tilt_" + c + "():\n" + b + d;
- return ""
- };
- Blockly.Python.CocoRobo_is_shaked = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- b.length && b.join(", ");
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- 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";
- Blockly.Python.definitions_.def_Timer11 = "tim11 \x3d Timer(11)";
- 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";
- Blockly.Python.definitions_.timer11_init = "tim11.init(period\x3d100, mode\x3dTimer.PERIODIC, callback\x3dtimer11_tick)\n";
- return "thrown" == a.getFieldValue("action") ? ["_is_thrown", Blockly.Python.ORDER_ATOMIC] : ["_is_shaked", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_shake_detector = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- b = b.length ? " global " + b.join(", ") + "\n" : "";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- c = Blockly.Python.statementToCode(a, "DO");
- c = Blockly.Python.addLoopTrap(c, a.id) || Blockly.Python.PASS;
- 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";
- Blockly.Python.definitions_.def_Timer11 = "tim11 \x3d Timer(11)";
- 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";
- Blockly.Python.definitions_.timer11_init = "tim11.init(period\x3d100, mode\x3dTimer.PERIODIC, callback\x3dtimer11_tick)\n";
- "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;
- return ""
- };
- Blockly.Python.CocoRobo_touch_event = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- b = b.length ? " global " + b.join(", ") + "\n" : "";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- var c = a.getFieldValue("touchPad"),
- d = a.getFieldValue("action"),
- e = Blockly.Python.statementToCode(a, "DO"),
- e = Blockly.Python.addLoopTrap(e, a.id) || Blockly.Python.PASS;
- 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";
- Blockly.Python.definitions_.def_Timer12 = "tim12 \x3d Timer(12)";
- 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()";
- Blockly.Python.definitions_.timer12_init = "tim12.init(period\x3d100, mode\x3dTimer.PERIODIC, callback\x3dtimer12_tick)\n";
- Blockly.Python.definitions_["on_touchpad_" + c + "_" + d] = "def on_touchpad_" + c + "_" + d + "():\n" + b + e;
- return ""
- };
- Blockly.Python.CocoRobo_custom_event = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- b = b.length ? " global " + b.join(", ") + "\n" : "";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- var d = Blockly.Python.statementToCode(a, "DO"),
- d = Blockly.Python.addLoopTrap(d, a.id) || Blockly.Python.PASS,
- c = Blockly.Python.valueToCode(a, "index", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["def_event_" + c] = "_event_changed_" + c + " \x3d False";
- a = Blockly.Python.valueToCode(a, "condition", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["def_Timer" + c] = "tim" + c + " \x3d Timer(" + c + ")";
- 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";
- Blockly.Python.definitions_["on_custom_event_" + c] = "def on_custom_event_" + c + "():\n" + b + d;
- return "tim" + c + ".init(period\x3d100, mode\x3dTimer.PERIODIC, callback\x3dtimer" + c + "_tick)\n"
- };
- Blockly.Python.CocoRobo_music_range_pitch = function(a) {
- Blockly.Python.definitions_.import_music = "import music";
- var b = Blockly.Python.valueToCode(a, "start", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "end", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "step", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "time", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
- 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"
- };
- Blockly.Python.CocoRobo_music_pin_p6 = function(a) {
- return ["" + a.getFieldValue("music_pin"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_time_ticks = function(a) {
- Blockly.Python.definitions_.import_time = "import time";
- return ["time." + a.getFieldValue("time_ticks") + "()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_time_localtime = function(a) {
- Blockly.Python.definitions_.import_time = "import time";
- return ["time.localtime()[" + a.getFieldValue("time_localtime") + "]", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_sway_xyz = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return ["button_" + a.getFieldValue("direction_group") + ".value() \x3d\x3d 0", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_sleep_ms = function(a) {
- Blockly.Python.definitions_.import_time = "import time";
- var b = Blockly.Python.valueToCode(a, "duration", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("ms_us");
- switch (a) {
- case "ms":
- case "us":
- return "time.sleep_" + a + "(" + b + ")\n";
- case "s":
- return "time.sleep(" + b + ")\n";
- default:
- return ""
- }
- };
- Blockly.Python.CocoRobo_time_difference = function(a) {
- Blockly.Python.definitions_.import_time = "import time";
- var b = Blockly.Python.valueToCode(a, "time1", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "time2", Blockly.Python.ORDER_ATOMIC);
- return ["time.ticks_diff(" + b + ", " + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_servo_angle0 = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_servo = "from servo import Servo";
- var b = Blockly.Python.valueToCode(a, "pwm_pin", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "servo_angle", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.codeFunctions_["Servo_define" + b] = "servo_" + b + " \x3d Servo(" + b + ", min_us\x3d750, max_us\x3d2250, actuation_range\x3d180)";
- return "servo_" + b + ".write_angle(" + a + ")\n"
- };
- Blockly.Python.CocoRobo_servo_angle = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_servo = "from servo import Servo";
- var b = Blockly.Python.valueToCode(a, "pwm_pin", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "min_us", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "max_us", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "actuation_range", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "servo_angle", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.codeFunctions_["Servo_define" + b] = "servo_" + b + " \x3d Servo(" + b + ", min_us\x3d" + c + ", max_us\x3d" + d + ", actuation_range\x3d" + e + ")";
- return "servo_" + b + ".write_angle(" + a + ")\n"
- };
- Blockly.Python.CocoRobo_dh11_hum_tem = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- Blockly.Python.definitions_.import_dht = "import dht";
- var b = Blockly.Python.valueToCode(a, "dh11_hum_tem_pin", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("hum_tem");
- Blockly.Python.definitions_.dh11_define = "dht11 \x3d dht.DHT11(Pin(Pin.P" + b + "))";
- Blockly.Python.definitions_.def_Timer13 = "tim13 \x3d Timer(13)";
- Blockly.Python.definitions_.timer13_tick = "def timer13_tick(_):\n try: dht11.measure()\n except: pass\n";
- Blockly.Python.definitions_.timer13_init = "tim13.init(period\x3d1000, mode\x3dTimer.PERIODIC, callback\x3dtimer13_tick)\n";
- return ["dht11." + a + "()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_dh22_hum_tem = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- Blockly.Python.definitions_.import_dht = "import dht";
- var b = Blockly.Python.valueToCode(a, "dh22_hum_tem_pin", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("hum_tem");
- Blockly.Python.definitions_.dh22_define = "dht22 \x3d dht.DHT22(Pin(Pin.P" + b + "))";
- Blockly.Python.definitions_.def_Timer13 = "tim13 \x3d Timer(13)";
- Blockly.Python.definitions_.timer13_tick = "def timer13_tick(_):\n try: dht22.measure()\n except: pass\n";
- Blockly.Python.definitions_.timer13_init = "tim13.init(period\x3d1000, mode\x3dTimer.PERIODIC, callback\x3dtimer13_tick)\n";
- return ["dht22." + a + "()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_music_note = function(a) {
- var b = a.getFieldValue("gamut"),
- c = Blockly.Python.valueToCode(a, "num1", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "num2", Blockly.Python.ORDER_ATOMIC);
- return ["'" + b + c + ":" + a + "'", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_def_clock = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("clock_name"),
- c = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "radius", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.codeFunctions_["def_clock" + b] = b + " \x3d Clock(lcd, " + c + ", " + d + ", " + a + ")";
- return ""
- };
- Blockly.Python.CocoRobo_settime_clock = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return a.getFieldValue("clock_name") + ".settime()\n"
- };
- Blockly.Python.CocoRobo_draw_clear_clock = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("draw_clear_clock");
- return a.getFieldValue("clock_name") + "." + b + "()\n"
- };
- Blockly.Python.CocoRobo_button_is_pressed = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- a = a.getFieldValue("button");
- 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]
- };
- Blockly.Python.CocoRobo_button_both_pressed = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return ["button_a.value() \x3d\x3d 0 and button_b.value() \x3d\x3d 0", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_touchPad_value = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return ["touchPad_" + a.getFieldValue("touchPad") + ".read() \x3c 400", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_touchPad_value_num = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return ["touchPad_" + a.getFieldValue("touchPad") + ".read()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_read_digital = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- a = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_in_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.IN)";
- return ["p" + a + ".read_digital()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_read_ds18b20 = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- Blockly.Python.definitions_.import_onewire = "import onewire";
- Blockly.Python.definitions_.import_ds18x20 = "import ds18x20";
- a = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_.ds18x20_list_define = "_ds18x20_list \x3d []";
- Blockly.Python.definitions_.def_Timer13 = "tim13 \x3d Timer(13)";
- 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';
- Blockly.Python.definitions_.timer13_init = "tim13.init(period\x3d1000, mode\x3dTimer.PERIODIC, callback\x3dtimer13_tick)\n";
- 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";
- 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";
- return ["_ds18x20_value_" + a, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_set_digital = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.OUT)";
- return "p" + a + ".write_digital(" + b + ")\n"
- };
- Blockly.Python.CocoRobo_set_pin_mode = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC),
- c = a.getFieldValue("in_out"),
- d = a.getFieldValue("pin_up_down_pull");
- a = Blockly.Python.valueToCode(a, "pin_value", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.codeFunctions_["set_PinMode" + b] = "p" + b + " \x3d CocoRoboPin(" + b + ", PinMode." + c + ", " + d + ")";
- return "p" + b + ".write_digital(" + a + ")\n"
- };
- Blockly.Python.CocoRobo_type = function(a) {
- return ["type(" + (Blockly.Python.valueToCode(a, "VAR", Blockly.Python.ORDER_ATOMIC) || "None") + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_type_is = function(a) {
- var b = Blockly.Python.valueToCode(a, "VAR", Blockly.Python.ORDER_ATOMIC) || "None";
- a = a.getFieldValue("TYPE");
- return ["type(" + b + ") \x3d\x3d " + a, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_eval = function(a) {
- return ["eval(" + (Blockly.Python.valueToCode(a, "VAR", Blockly.Python.ORDER_ATOMIC) || "None") + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_return = function(a) {
- return "return " + (Blockly.Python.valueToCode(a, "VAR", Blockly.Python.ORDER_ATOMIC) || "None") + "\n"
- };
- Blockly.Python.CocoRobo_read_analog = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- a = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_in_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.ANALOG)";
- return ["p" + a + ".read_analog()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_set_analog = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.PWM)";
- return "p" + a + ".write_analog(" + b + ")\n"
- };
- Blockly.Python.CocoRobo_rgb_list = function(a) {
- return [a.getFieldValue("rgb_list"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_set_rgb_list_color = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_time = "import time";
- var b = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("COLOUR");
- var c = 0,
- d = 0,
- e = 0;
- try {
- 7 == a.length && (c = parseInt(a.substring(1, 3), 16),
- d = parseInt(a.substring(3, 5), 16),
- e = parseInt(a.substring(5, 7), 16))
- } catch (f) {}
- switch (b) {
- case "0":
- case "1":
- case "2":
- return "rgb[" + b + "] \x3d (int(" + c + "), int(" + d + "), int(" + e + "))\nrgb.write()\ntime.sleep_ms(1)\n";
- case "-1":
- return "rgb.fill((int(" + c + "), int(" + d + "), int(" + e + ")))\nrgb.write()\ntime.sleep_ms(1)\n";
- default:
- return "rgb[" + b + "] \x3d (int(" + c + "), int(" + d + "), int(" + e + "))\nrgb.write()\ntime.sleep_ms(1)\n"
- }
- };
- Blockly.Python.CocoRobo_set_rgb_list_number = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_time = "import time";
- var b = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
- switch (b) {
- case "0":
- case "1":
- case "2":
- return "rgb[" + b + "] \x3d (int(" + c + "), int(" + d + "), int(" + a + "))\nrgb.write()\ntime.sleep_ms(1)\n";
- case "-1":
- return "rgb.fill( (int(" + c + "), int(" + d + "), int(" + a + ")) )\nrgb.write()\ntime.sleep_ms(1)\n";
- default:
- return "rgb[" + b + "] \x3d (int(" + c + "), int(" + d + "), int(" + a + "))\nrgb.write()\ntime.sleep_ms(1)\n"
- }
- };
- Blockly.Python.CocoRobo_off_rgb_list = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_time = "import time";
- a = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC);
- switch (a) {
- case "0":
- case "1":
- case "2":
- return "rgb[" + a + "] \x3d (0, 0, 0)\nrgb.write()\ntime.sleep_ms(1)\n";
- case "-1":
- return "rgb.fill( (0, 0, 0) )\nrgb.write()\ntime.sleep_ms(1)\n";
- default:
- return "rgb[" + a + "] \x3d (0, 0, 0)\nrgb.write()\ntime.sleep_ms(1)\n"
- }
- };
- Blockly.Python.CocoRobo_set_RGB_color = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_time = "import time";
- var b = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("COLOUR");
- var c = 0,
- d = 0,
- e = 0;
- try {
- 7 == a.length && (c = parseInt(a.substring(1, 3), 16),
- d = parseInt(a.substring(3, 5), 16),
- e = parseInt(a.substring(5, 7), 16))
- } catch (f) {}
- return "rgb[" + b + "] \x3d (int(" + c + "/30), int(" + d + "/30), int(" + e + "/30))\nrgb.write()\ntime.sleep_ms(1)\n"
- };
- Blockly.Python.CocoRobo_set_RGB_color_all = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_time = "import time";
- a = a.getFieldValue("COLOUR");
- var b = 0,
- c = 0,
- d = 0;
- try {
- 7 == a.length && (b = parseInt(a.substring(1, 3), 16),
- c = parseInt(a.substring(3, 5), 16),
- d = parseInt(a.substring(5, 7), 16))
- } catch (e) {}
- 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"
- };
- Blockly.Python.CocoRobo_set_RGB = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_time = "import time";
- var b = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
- return "rgb[" + b + "] \x3d (int(" + c + "/30), int(" + d + "/30), int(" + a + "/30))\nrgb.write()\ntime.sleep_ms(1)\n"
- };
- Blockly.Python.CocoRobo_set_RGB_all = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_time = "import time";
- var b = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
- 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"
- };
- Blockly.Python.CocoRobo_fresh_RGB = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_time = "import time";
- return ""
- };
- Blockly.Python.CocoRobo_off_RGB = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_time = "import time";
- return "rgb.fill( (0, 0, 0) )\nrgb.write()\ntime.sleep_ms(1)\n"
- };
- Blockly.Python.CocoRobo_buzz_state = function(a) {
- Blockly.Python.definitions_.import_music = "import music";
- return "music.stop()\n"
- };
- Blockly.Python.CocoRobo_buzz_freq = function(a) {
- Blockly.Python.definitions_.import_music = "import music";
- var b = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "freq", Blockly.Python.ORDER_ATOMIC);
- return "6" == b ? "music.pitch(" + a + ")\n" : "music.pitch(" + a + ", -1, pin\x3dPin.P" + b + ")\n"
- };
- Blockly.Python.CocoRobo_buzz_tone = function(a) {
- Blockly.Python.definitions_.import_music = "import music";
- return "music.pitch(" + a.getFieldValue("buzz_tone") + ")\n"
- };
- Blockly.Python.CocoRobo_music_tone_tempo = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_music = "import music";
- var b = Blockly.Python.valueToCode(a, "musical_note", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
- return "6" == a ? "music.play(" + b + ")\n" : "music.play(" + b + ", pin\x3dPin.P" + a + ")\n"
- };
- Blockly.Python.CocoRobo_music_tone = function(a) {
- Blockly.Python.definitions_.import_music = "import music";
- return [a.getFieldValue("music_tone"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_music_musical_note = function(a) {
- Blockly.Python.definitions_.import_music = "import music";
- var b = a.getFieldValue("musical_note");
- a = a.getFieldValue("music_tick");
- return ["'" + b + ":" + a + "'", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_4_lines = function(a) {
- return [a.getFieldValue("CocoRobo_4_lines"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_music_tick = function(a) {
- Blockly.Python.definitions_.import_music = "import music";
- return [a.getFieldValue("music_tick"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_read_sound = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return ["sound.read()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_read_light = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return ["light.read()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_accelerometer_get = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- switch (a.getFieldValue("axis")) {
- case "X":
- a = "accelerometer.get_values()['AcX']";
- break;
- case "Y":
- a = "accelerometer.get_values()['AcY']";
- break;
- case "Z":
- a = "accelerometer.get_values()['AcZ']";
- break;
- default:
- return ""
- }
- return [a, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_accelerometer_get_x = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return ["accelerometer.get_x()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_accelerometer_get_y = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return ["accelerometer.get_y()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_accelerometer_get_z = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return ["accelerometer.get_z()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_accelerometer_set_range = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return "accelerometer.set_range(accelerometer." + a.getFieldValue("range") + ")\n"
- };
- Blockly.Python.CocoRobo_accelerometer_set_resolustion = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return "accelerometer.set_resolustion(accelerometer." + a.getFieldValue("resolustion") + ")\n"
- };
- Blockly.Python.CocoRobo_accelerometer_set_offset = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "z", Blockly.Python.ORDER_ATOMIC);
- return "accelerometer.set_offset(" + b + ", " + c + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_tilt_angle = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_math = "import math";
- a = a.getFieldValue("axis");
- //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";
- switch (a) {
- case "X":
- a = "mpu_get_tilt_angle('X')";
- break;
- case "Y":
- a = "mpu_get_tilt_angle('Y')";
- break;
- case "Z":
- a = "mpu_get_tilt_angle('Z')";
- break;
- default:
- a = "0"
- }
- return [a, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_random_choice = function(a) {
- // Blockly.Python.definitions_.import_time = "import time";
- // Blockly.Python.codeFunctions_.random_seed = "random.seed(time.ticks_cpu())";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_random = "import random";
- return ["str(random.choice(" + Blockly.Python.valueToCode(a, "list", Blockly.Python.ORDER_ATOMIC) + "))", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.machine_time_pulse_us = function(a) {
- Blockly.Python.definitions_.import_machine = "import machine";
- var b = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "pulse", Blockly.Python.ORDER_ATOMIC);
- return ["machine.time_pulse_us(Pin(Pin.P" + b + "), " + a + ", timeout_us\x3d1000000)", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_print = function(a) {
- return "print(" + Blockly.Python.valueToCode(a, "CONTENT", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_print_to_chart = function(a) {
- for (var b = Array(a.itemCount_), c = 0; c < a.itemCount_; c++)
- b[c] = Blockly.Python.valueToCode(a, "ADD" + c, Blockly.Python.ORDER_NONE) || "None";
- return 1 == a.itemCount_ ? "print((" + b[0] + ",))\n" : "print((" + b.join(", ") + "))\n"
- };
- Blockly.Python.CocoRobo_init_chart = function(a) {
- Blockly.Python.definitions_.import_time = "import time";
- var b = Array(a.itemCount_ + 1);
- b[0] = "'__TITLE'";
- for (var c = 0; c < a.itemCount_; c++)
- b[c + 1] = Blockly.Python.valueToCode(a, "ADD" + c, Blockly.Python.ORDER_NONE) || "None";
- return "time.sleep_ms(50);print((" + b.join(", ") + "));time.sleep_ms(50)\n"
- };
- Blockly.Python.CocoRobo_ir_remote_recv = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_ir_remote_recv = "from ir_remote import IRDecode";
- var b = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_.define_ir_remote_recv = "remote \x3d IRDecode(Pin.P" + b + ")";
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- try {
- b.remove("_address")
- } catch (d) {}
- try {
- b.remove("_command")
- } catch (d) {}
- b = b.length ? " global " + b.join(", ") + "\n" : "";
- a = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
- Blockly.Python.codeFunctions_.def_ir_remote_recv = "def remote_callback(_address, _command):\n" + b + a;
- return "remote.set_callback(remote_callback)\n"
- };
- Blockly.Python.CocoRobo_ir_remote_send = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_ir_remote_send = "from ir_remote import IRTransmit";
- var b = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_.define_ir_remote_send = "ir \x3d IRTransmit(Pin.P" + b + ")";
- b = Blockly.Python.valueToCode(a, "address", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "command", Blockly.Python.ORDER_ATOMIC);
- return "ir.send(" + b + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_bme280_hum_tem_pre = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return ["bme280." + a.getFieldValue("hum_tem_pre") + "()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_compass_get_axis = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- switch (a.getFieldValue("axis")) {
- case "X":
- a = "compass.get_x()";
- break;
- case "Y":
- a = "compass.get_y()";
- break;
- case "Z":
- a = "compass.get_z()";
- break;
- default:
- return ""
- }
- return [a, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_compass_get_angle = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return ["compass.get_angle()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_audio_set_volume = function(a) {
- Blockly.Python.definitions_.import_audio = "import audio";
- return "audio.set_volume(" + Blockly.Python.valueToCode(a, "volume", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_audio_xunfei_tts = function(a) {
- Blockly.Python.definitions_.import_audio = "import audio";
- return "audio.xunfei_tts(" + Blockly.Python.valueToCode(a, "TEXT", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_audio_xunfei_tts_config = function(a) {
- Blockly.Python.definitions_.import_audio = "import audio";
- var b = Blockly.Python.valueToCode(a, "APPID", Blockly.Python.ORDER_ATOMIC);
- return "audio.xunfei_tts_config(" + Blockly.Python.valueToCode(a, "API_KEY", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
- };
- Blockly.Python.CocoRobo_audio_play = function(a) {
- Blockly.Python.definitions_.import_audio = "import audio";
- return "audio.play(" + Blockly.Python.valueToCode(a, "url", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_audio_cmd = function(a) {
- Blockly.Python.definitions_.import_audio = "import audio";
- return "audio." + a.getFieldValue("cmd") + "()\n"
- };
- Blockly.Python.CocoRobo_audio_deinit = function(a) {
- Blockly.Python.definitions_.import_audio = "import audio";
- return "audio.player_deinit()\n"
- };
- Blockly.Python.CocoRobo_audio_init = function(a) {
- Blockly.Python.definitions_.import_audio = "import audio";
- return "audio.player_init()\n"
- };
- Blockly.Python.CocoRobo_record_init = function(a) {
- Blockly.Python.definitions_.import_audio = "import audio";
- return "audio.recorder_init()\n"
- };
- Blockly.Python.CocoRobo_record_deinit = function(a) {
- Blockly.Python.definitions_.import_audio = "import audio";
- return "audio.recorder_deinit()\n"
- };
- Blockly.Python.CocoRobo_record_wav = function(a) {
- Blockly.Python.definitions_.import_audio = "import audio";
- var b = Blockly.Python.valueToCode(a, "file_name", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "record_time", Blockly.Python.ORDER_ATOMIC);
- return "audio.record(" + b + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_asr = function(a) {
- Blockly.Python.definitions_.import_audio = "import audio";
- Blockly.Python.definitions_.import_urequests = "import urequests";
- Blockly.Python.definitions_.import_json = "import json";
- Blockly.Python.definitions_.import_machine = "import machine";
- Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
- 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';
- return ["get_asr_result()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.xunfei_speech_tts = function(a) {
- Blockly.Python.definitions_.import_xunfei = "from xunfei import *";
- var b = Blockly.Python.valueToCode(a, "APPID", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "APISecret", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "APIKey", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "Text", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "AudioFile", Blockly.Python.ORDER_ATOMIC);
- 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'
- };
- Blockly.Python.xunfei_speech_iat = function(a) {
- Blockly.Python.definitions_.import_xunfei = "from xunfei import *";
- var b = Blockly.Python.valueToCode(a, "APPID", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "APISecret", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "APIKey", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "AudioFile", Blockly.Python.ORDER_ATOMIC);
- return "speech_iat \x3d Xunfei_speech(" + b + ", " + d + ", " + c + ", mode\x3dMODE_IAT, AudioFile\x3d" + a + ")\n"
- };
- Blockly.Python.xunfei_speech_iat_result = function(a) {
- Blockly.Python.definitions_.import_xunfei = "from xunfei import *";
- return ["speech_iat.iat()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_lcd_bmp = function(a) {
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "bmp", Blockly.Python.ORDER_ATOMIC);
- return "b_oled.Bitmap(" + b + ", " + c + ", " + a + ", " + d + ", " + e + ", 1)\nb_oled.show()\n"
- };
- Blockly.Python.CocoRobo_bluebit_lcd_clear = function(a) {
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return "b_oled.clear()\nb_oled.show()\n"
- };
- Blockly.Python.CocoRobo_bluebit_lcd_init = function(a) {
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "tx", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "rx", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_.CocoRobo_bluebit_OLCD = "b_oled \x3d OLCDBit(rx\x3dPin.P" + a + ", tx\x3dPin.P" + b + ")\n";
- return "\n"
- };
- Blockly.Python.CocoRobo_bluebit_lcd_print = function(a) {
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "_print", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
- return "b_oled.Print(" + b + ", " + c + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_ir_recv = function(a) {
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- a = Blockly.Python.valueToCode(a, "rx", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["irrecv_object" + a] = "irrecv" + a + " \x3d IRRecv(rx\x3dPin.P" + a + ")";
- return ["irrecv" + a + ".recv()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_ir_trans = function(a) {
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "tx", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["irtrans_object" + b] = "irtrans" + b + " \x3d IRTrans(tx\x3dPin.P" + b + ")";
- a = Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC);
- return "irtrans" + b + ".transmit(bytes(" + a + ", 'utf-8'))\n"
- };
- Blockly.Python.CocoRobo_lcd_move = function(a) {
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return "lcd.move_" + a.getFieldValue("move") + "()\n"
- };
- Blockly.Python.CocoRobo_lcd_text_direction = function(a) {
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return "lcd.text_direction \x3d LCD1602." + a.getFieldValue("text_direction") + "\n"
- };
- Blockly.Python.CocoRobo_lcd_clear = function(a) {
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return "lcd.Clear()\n"
- };
- Blockly.Python.CocoRobo_lcd_set_cursor = function(a) {
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "row", Blockly.Python.ORDER_ATOMIC);
- return "lcd.setCursor(" + Blockly.Python.valueToCode(a, "column", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
- };
- Blockly.Python.CocoRobo_lcd_cursor = function(a) {
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return "lcd." + a.getFieldValue("cursor_cmd") + "\n"
- };
- Blockly.Python.CocoRobo_lcd_home = function(a) {
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return "lcd.Home()\n"
- };
- Blockly.Python.CocoRobo_lcd_print = function(a) {
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return "lcd.Print(" + Blockly.Python.valueToCode(a, "display_str", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_lcd_object = function(a) {
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.i2c_object_100k = "i2c \x3d I2C(scl\x3dPin(Pin.P19), sda\x3dPin(Pin.P20), freq\x3d100000)";
- Blockly.Python.definitions_.LCD1602_object = "lcd \x3d LCD1602(i2c\x3di2c)";
- return ""
- };
- Blockly.Python.CocoRobo_bluebit_extio_writeio = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- var b = Blockly.Python.valueToCode(a, "io_value", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("IO");
- Blockly.Python.codeFunctions_.init_extIO = "extio \x3d extIO(i2c)";
- return "extio.writeIO(" + a + ", " + b + ")\n"
- };
- Blockly.Python.CocoRobo_bluebit_extio_readio = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- a = a.getFieldValue("IO");
- Blockly.Python.codeFunctions_.init_extIO = "extio \x3d extIO(i2c)";
- return ["extio.readIO(" + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_extio_iomode = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- var b = a.getFieldValue("mode");
- a = a.getFieldValue("IO");
- Blockly.Python.codeFunctions_.init_extIO = "extio \x3d extIO(i2c)";
- return "extio.IOInit(" + a + ", " + b + ")\n"
- };
- Blockly.Python.CocoRobo_bluebit_mp3_singleLoop = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- return "mp3.singleLoop(" + a.getFieldValue("singleLoop") + ")\n"
- };
- Blockly.Python.CocoRobo_bluebit_mp3_cmd = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- return "mp3." + a.getFieldValue("cmd") + "()\n"
- };
- Blockly.Python.CocoRobo_bluebit_mp3_play_song = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- return "mp3.play_song(" + Blockly.Python.valueToCode(a, "song_order", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_bluebit_mp3_volume_plus = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- return "mp3." + a.getFieldValue("volume_plus") + "()\n"
- };
- Blockly.Python.CocoRobo_bluebit_mp3_init = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- a = Blockly.Python.valueToCode(a, "mp3_tx", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.codeFunctions_.init_mp3 = "mp3 \x3d MP3(Pin.P" + a + ")";
- return ""
- };
- Blockly.Python.CocoRobo_bluebit_mp3_volume = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- return "mp3.volume \x3d " + Blockly.Python.valueToCode(a, "volume_level", Blockly.Python.ORDER_ATOMIC) + "\n"
- };
- Blockly.Python.CocoRobo_bluebit_matrix_show = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- Blockly.Python.codeFunctions_.init_matrix = "matrix \x3d Matrix()";
- return "matrix.show()\n"
- };
- Blockly.Python.CocoRobo_bluebit_matrix_bitmap = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- Blockly.Python.codeFunctions_.init_matrix = "matrix \x3d Matrix()";
- var b = "TRUE" == a.getFieldValue("00") ? "1" : "0",
- c = "TRUE" == a.getFieldValue("01") ? "1" : "0",
- d = "TRUE" == a.getFieldValue("02") ? "1" : "0",
- e = "TRUE" == a.getFieldValue("03") ? "1" : "0",
- f = "TRUE" == a.getFieldValue("04") ? "1" : "0",
- g = "TRUE" == a.getFieldValue("05") ? "1" : "0",
- h = "TRUE" == a.getFieldValue("06") ? "1" : "0",
- k = "TRUE" == a.getFieldValue("07") ? "1" : "0",
- l = "TRUE" == a.getFieldValue("10") ? "1" : "0",
- u = "TRUE" == a.getFieldValue("11") ? "1" : "0",
- v = "TRUE" == a.getFieldValue("12") ? "1" : "0",
- w = "TRUE" == a.getFieldValue("13") ? "1" : "0",
- x = "TRUE" == a.getFieldValue("14") ? "1" : "0",
- y = "TRUE" == a.getFieldValue("15") ? "1" : "0",
- z = "TRUE" == a.getFieldValue("16") ? "1" : "0",
- A = "TRUE" == a.getFieldValue("17") ? "1" : "0",
- m = "TRUE" == a.getFieldValue("20") ? "1" : "0",
- B = "TRUE" == a.getFieldValue("21") ? "1" : "0",
- C = "TRUE" == a.getFieldValue("22") ? "1" : "0",
- D = "TRUE" == a.getFieldValue("23") ? "1" : "0",
- E = "TRUE" == a.getFieldValue("24") ? "1" : "0",
- F = "TRUE" == a.getFieldValue("25") ? "1" : "0",
- G = "TRUE" == a.getFieldValue("26") ? "1" : "0",
- H = "TRUE" == a.getFieldValue("27") ? "1" : "0",
- n = "TRUE" == a.getFieldValue("30") ? "1" : "0",
- I = "TRUE" == a.getFieldValue("31") ? "1" : "0",
- J = "TRUE" == a.getFieldValue("32") ? "1" : "0",
- K = "TRUE" == a.getFieldValue("33") ? "1" : "0",
- L = "TRUE" == a.getFieldValue("34") ? "1" : "0",
- M = "TRUE" == a.getFieldValue("35") ? "1" : "0",
- N = "TRUE" == a.getFieldValue("36") ? "1" : "0",
- O = "TRUE" == a.getFieldValue("37") ? "1" : "0",
- p = "TRUE" == a.getFieldValue("40") ? "1" : "0",
- P = "TRUE" == a.getFieldValue("41") ? "1" : "0",
- Q = "TRUE" == a.getFieldValue("42") ? "1" : "0",
- R = "TRUE" == a.getFieldValue("43") ? "1" : "0",
- S = "TRUE" == a.getFieldValue("44") ? "1" : "0",
- T = "TRUE" == a.getFieldValue("45") ? "1" : "0",
- U = "TRUE" == a.getFieldValue("46") ? "1" : "0",
- V = "TRUE" == a.getFieldValue("47") ? "1" : "0",
- q = "TRUE" == a.getFieldValue("50") ? "1" : "0",
- W = "TRUE" == a.getFieldValue("51") ? "1" : "0",
- X = "TRUE" == a.getFieldValue("52") ? "1" : "0",
- Y = "TRUE" == a.getFieldValue("53") ? "1" : "0",
- Z = "TRUE" == a.getFieldValue("54") ? "1" : "0",
- aa = "TRUE" == a.getFieldValue("55") ? "1" : "0",
- ba = "TRUE" == a.getFieldValue("56") ? "1" : "0",
- ca = "TRUE" == a.getFieldValue("57") ? "1" : "0",
- r = "TRUE" == a.getFieldValue("60") ? "1" : "0",
- da = "TRUE" == a.getFieldValue("61") ? "1" : "0",
- ea = "TRUE" == a.getFieldValue("62") ? "1" : "0",
- fa = "TRUE" == a.getFieldValue("63") ? "1" : "0",
- ga = "TRUE" == a.getFieldValue("64") ? "1" : "0",
- ha = "TRUE" == a.getFieldValue("65") ? "1" : "0",
- ia = "TRUE" == a.getFieldValue("66") ? "1" : "0",
- ja = "TRUE" == a.getFieldValue("67") ? "1" : "0",
- t = "TRUE" == a.getFieldValue("70") ? "1" : "0",
- ka = "TRUE" == a.getFieldValue("71") ? "1" : "0",
- la = "TRUE" == a.getFieldValue("72") ? "1" : "0",
- ma = "TRUE" == a.getFieldValue("73") ? "1" : "0",
- na = "TRUE" == a.getFieldValue("74") ? "1" : "0",
- oa = "TRUE" == a.getFieldValue("75") ? "1" : "0",
- pa = "TRUE" == a.getFieldValue("76") ? "1" : "0";
- a = "TRUE" == a.getFieldValue("77") ? "1" : "0";
- b = parseInt(b + c + d + e + f + g + h + k, 2);
- l = parseInt(l + u + v + w + x + y + z + A, 2);
- m = parseInt(m + B + C + D + E + F + G + H, 2);
- n = parseInt(n + I + J + K + L + M + N + O, 2);
- p = parseInt(p + P + Q + R + S + T + U + V, 2);
- q = parseInt(q + W + X + Y + Z + aa + ba + ca, 2);
- r = parseInt(r + da + ea + fa + ga + ha + ia + ja, 2);
- t = parseInt(t + ka + la + ma + na + oa + pa + a, 2);
- return "matrix.bitmap(bytearray([" + b + ", " + l + ", " + m + ", " + n + ", " + p + ", " + q + ", " + r + ", " + t + "]))\nmatrix.show()\n"
- };
- Blockly.Python.CocoRobo_bluebit_matrix_fill = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- a = a.getFieldValue("fill_clear");
- Blockly.Python.codeFunctions_.init_matrix = "matrix \x3d Matrix()";
- return "matrix.fill(" + a + ")\nmatrix.show()\n"
- };
- Blockly.Python.CocoRobo_bluebit_matrix_brightness = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- Blockly.Python.codeFunctions_.init_matrix = "matrix \x3d Matrix()";
- return "matrix.brightness(" + Blockly.Python.valueToCode(a, "brightness_level", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_bluebit_midi_play = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- var b = a.getFieldValue("play_stop");
- return "midi.note(" + Blockly.Python.valueToCode(a, "play_note", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
- };
- Blockly.Python.CocoRobo_bluebit_midi_instrument = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- return "midi.instrument \x3d " + a.getFieldValue("midi_instrument") + "\n"
- };
- Blockly.Python.CocoRobo_bluebit_midi_volume = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- return "midi.volume \x3d " + Blockly.Python.valueToCode(a, "midi_volume", Blockly.Python.ORDER_ATOMIC) + "\n"
- };
- Blockly.Python.CocoRobo_bluebit_init_midi = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- a = Blockly.Python.valueToCode(a, "midi_tx", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.codeFunctions_.init_midi = "midi \x3d MIDI(Pin.P" + a + ")";
- return ""
- };
- Blockly.Python.CocoRobo_bluebit_get_all_color = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- Blockly.Python.codeFunctions_.init_color = "color \x3d Color()";
- return ["color.getRGB()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_get_color = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- Blockly.Python.codeFunctions_.init_color = "color \x3d Color()";
- return ["color.getRGB()[" + a.getFieldValue("r_g_b") + "]", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_get_all_color_hsv = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- Blockly.Python.codeFunctions_.init_color = "color \x3d Color()";
- return ["color.getHSV()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_get_color_hsv = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- Blockly.Python.codeFunctions_.init_color = "color \x3d Color()";
- return ["color.getHSV()[" + a.getFieldValue("hsv") + "]", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_get_force_measure = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- a = a.getFieldValue("measure");
- Blockly.Python.codeFunctions_["init_delveBit_force" + a] = "delveBit_force_" + ("0X64" === a ? "0" : "0X65" === a ? "1" : "0X66" === a ? "2" : "3") + " \x3d DelveBit(" + a + ")";
- return ["delveBit_force_" + ("0X64" === a ? "0" : "0X65" === a ? "1" : "0X66" === a ? "2" : "3") + ".common_measure()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_get_electricity_measure = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- a = a.getFieldValue("measure");
- Blockly.Python.codeFunctions_["init_delveBit_electricity" + a] = "delveBit_electricity_" + ("0X60" === a ? "0" : "0X61" === a ? "1" : "0X62" === a ? "2" : "3") + " \x3d DelveBit(" + a + ")";
- return ["delveBit_electricity_" + ("0X60" === a ? "0" : "0X61" === a ? "1" : "0X62" === a ? "2" : "3") + ".common_measure()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_get_voltage_measure = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- a = a.getFieldValue("measure");
- Blockly.Python.codeFunctions_["init_delveBit_voltage" + a] = "delveBit_voltage_" + ("0X6A" === a ? "0" : "0X6B" === a ? "1" : "0X6C" === a ? "2" : "3") + " \x3d DelveBit(" + a + ")";
- return ["delveBit_voltage_" + ("0X6A" === a ? "0" : "0X6B" === a ? "1" : "0X6C" === a ? "2" : "3") + ".common_measure()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_get_magnetic_measure = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- a = a.getFieldValue("measure");
- Blockly.Python.codeFunctions_["init_delveBit_magnetic" + a] = "delveBit_magnetic_" + ("0X58" === a ? "0" : "0X59" === a ? "1" : "0X5A" === a ? "2" : "3") + " \x3d DelveBit(" + a + ")";
- return ["delveBit_magnetic_" + ("0X58" === a ? "0" : "0X59" === a ? "1" : "0X5A" === a ? "2" : "3") + ".common_measure()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_get_PH_measure = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- a = a.getFieldValue("measure");
- Blockly.Python.codeFunctions_["init_delveBit_PH" + a] = "delveBit_PH_" + ("0X54" === a ? "0" : "1") + " \x3d DelveBit(" + a + ")";
- return ["delveBit_PH_" + ("0X54" === a ? "0" : "1") + ".common_measure()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_get_tds_measure = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- a = a.getFieldValue("measure");
- Blockly.Python.codeFunctions_["init_delveBit_tds" + a] = "delveBit_tds_" + ("0X68" === a ? "0" : "1") + " \x3d DelveBit(" + a + ")";
- return ["delveBit_tds_" + ("0X68" === a ? "0" : "1") + ".common_measure()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_get_pressure_measure = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- a = a.getFieldValue("measure");
- Blockly.Python.codeFunctions_["init_delveBit_pressure" + a] = "delveBit_pressure_" + ("0X5C" === a ? "0" : "0X5D" === a ? "1" : "0X5E" === a ? "2" : "3") + " \x3d DelveBit(" + a + ")";
- return ["delveBit_pressure_" + ("0X5C" === a ? "0" : "0X5D" === a ? "1" : "0X5E" === a ? "2" : "3") + ".common_measure()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_get_photogate_timer_measure = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- a = a.getFieldValue("measure");
- Blockly.Python.codeFunctions_["init_delveBit_photo" + a] = "delveBit_photo_" + ("0X50" === a ? "0" : "1") + " \x3d DelveBit(" + a + ")";
- return ["delveBit_photo_" + ("0X50" === a ? "0" : "1") + ".photo_gate()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_init_assistant_wifi = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- 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";
- var b = Blockly.Python.valueToCode(a, "ssid", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "password", Blockly.Python.ORDER_ATOMIC);
- return ["wifi_config(" + b + ", " + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_init_assistant_profile = function(a) {
- 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";
- 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"
- };
- Blockly.Python.CocoRobo_bluebit_seg_clear = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- Blockly.Python.codeFunctions_.init_seg = "seg \x3d SEGdisplay()";
- return "seg.Clear()\n"
- };
- Blockly.Python.CocoRobo_bluebit_seg_display = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- Blockly.Python.codeFunctions_.init_seg = "seg \x3d SEGdisplay()";
- return "seg.numbers(" + Blockly.Python.valueToCode(a, "seg_num", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_bluebit_ambientlight = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- Blockly.Python.codeFunctions_.init_AmbientLight = "ambientLight \x3d AmbientLight()";
- return ["ambientLight.getLight()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_hum_tem = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- Blockly.Python.codeFunctions_.init_SHT20 = "sht20 \x3d SHT20()";
- return ["sht20." + a.getFieldValue("hum_tem") + "()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_ultrasonic = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- Blockly.Python.codeFunctions_.init_Ultrasonic = "ultrasonic \x3d Ultrasonic()";
- return ["ultrasonic.distance()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_read_digital = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- a = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_in_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.IN)";
- Blockly.Python.codeFunctions_["boolean_P" + a] = "def boolean_P" + a + "():\n return p" + a + ".read_digital() \x3d\x3d 1";
- return ["boolean_P" + a + "()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_line_follower = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- a = Blockly.Python.valueToCode(a, "allPin", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_in_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.IN)";
- Blockly.Python.codeFunctions_["boolean_P" + a] = "def boolean_P" + a + "():\n return p" + a + ".read_digital() \x3d\x3d 1";
- return ["boolean_P" + a + "()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_set_true = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- a = Blockly.Python.valueToCode(a, "set_digital_P", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.OUT)";
- return "p" + a + ".write_digital(1)\n"
- };
- Blockly.Python.CocoRobo_bluebit_set_false = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- a = Blockly.Python.valueToCode(a, "set_digital_P", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.OUT)";
- return "p" + a + ".write_digital(0)\n"
- };
- Blockly.Python.CocoRobo_bluebit_read_analog = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_math = "import math";
- var b = a.getFieldValue("analog_senor");
- a = Blockly.Python.valueToCode(a, "read_analog_P", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_in_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.ANALOG)";
- 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]
- };
- Blockly.Python.CocoRobo_bluebit_set_analog = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "analog_value", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "set_analog_P", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.PWM)";
- return "p" + a + ".write_analog(" + b + ")\n"
- };
- Blockly.Python.CocoRobo_bluebit_voice_record_on = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("func"),
- c = Blockly.Python.valueToCode(a, "rec", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "play", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_out_" + c] = "p" + c + " \x3d CocoRoboPin(" + c + ", PinMode.OUT)";
- Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.OUT)";
- 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"
- };
- Blockly.Python.CocoRobo_bluebit_voice_record_off = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "rec", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "play", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_out_" + b] = "p" + b + " \x3d CocoRoboPin(" + b + ", PinMode.OUT)";
- Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.OUT)";
- return "p" + b + ".write_digital(0)\np" + a + ".write_digital(0)\n"
- };
- Blockly.Python.CocoRobo_m1m2_led_on = function(a) {
- Blockly.Python.definitions_.import_parrot = "import parrot";
- var b = a.getFieldValue("m1m2");
- a = Blockly.Python.valueToCode(a, "brightness", Blockly.Python.ORDER_ATOMIC);
- return "parrot.set_speed(parrot.MOTOR_" + b + ", -" + a + ")\n"
- };
- Blockly.Python.CocoRobo_m1m2_led_off = function(a) {
- Blockly.Python.definitions_.import_parrot = "import parrot";
- return "parrot.led_off(parrot.MOTOR_" + a.getFieldValue("m1m2") + ")\n"
- };
- Blockly.Python.CocoRobo_bluebit_motor_on = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "ain1", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "ain2", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_out_" + b] = "p" + b + " \x3d CocoRoboPin(" + b + ", PinMode.PWM)";
- Blockly.Python.definitions_["set_PinMode_out_" + c] = "p" + c + " \x3d CocoRoboPin(" + c + ", PinMode.PWM)";
- var d = a.getFieldValue("status");
- a = Blockly.Python.valueToCode(a, "speed", Blockly.Python.ORDER_ATOMIC);
- 0 >= a && (a = 1);
- 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"
- };
- Blockly.Python.CocoRobo_bluebit_motor_off = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "ain1", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "ain2", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_out_" + b] = "p" + b + " \x3d CocoRoboPin(" + b + ", PinMode.PWM)";
- Blockly.Python.definitions_["set_PinMode_out_" + a] = "p" + a + " \x3d CocoRoboPin(" + a + ", PinMode.PWM)";
- return "p" + b + ".write_analog(0)\nsleep_ms(2)\np" + a + ".write_analog(0)\nsleep_ms(2)\n"
- };
- Blockly.Python.CocoRobo_bluebit_get_motorpeed = function(a) {
- Blockly.Python.definitions_.import_parrot = "import parrot";
- return ["parrot.get_speed(parrot.MOTOR_" + a.getFieldValue("left_right_interface") + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_set_Fan = function(a) {
- Blockly.Python.definitions_.import_parrot = "import parrot";
- return "parrot.set_speed(parrot.MOTOR_" + a.getFieldValue("left_right_interface") + ", -100)\n"
- };
- Blockly.Python.CocoRobo_bluebit_set_Fan_off = function(a) {
- Blockly.Python.definitions_.import_parrot = "import parrot";
- return "parrot.set_speed(parrot.MOTOR_" + a.getFieldValue("left_right_interface") + ", 0)\n"
- };
- Blockly.Python.CocoRobo_bluebit_4button = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- 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";
- var b = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("button_val");
- Blockly.Python.definitions_["set_PinMode_in_" + b] = "p" + b + " \x3d CocoRoboPin(" + b + ", PinMode.ANALOG)";
- return ["get4ButtonVal(" + a + ", p" + b + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_joystick = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "pin1", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["set_PinMode_in_" + b] = "p" + b + " \x3d CocoRoboPin(" + b + ", PinMode.ANALOG)";
- Blockly.Python.definitions_["set_PinMode_in_" + c] = "p" + c + " \x3d CocoRoboPin(" + c + ", PinMode.ANALOG)";
- return ["p" + ("X" == a.getFieldValue("axis") ? c : b) + ".read_analog()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bluebit_motor_on_i2c = function(a) {
- Blockly.Python.definitions_.import_parrot = "import parrot";
- var b = a.getFieldValue("left_right_interface"),
- c = a.getFieldValue("status");
- a = Blockly.Python.valueToCode(a, "speed", Blockly.Python.ORDER_ATOMIC);
- switch (b) {
- case "M1":
- var d = "parrot.set_speed(parrot.MOTOR_1";
- break;
- case "M2":
- d = "parrot.set_speed(parrot.MOTOR_2"
- }
- switch (c) {
- case "CLOCKWISE":
- var e = ", ";
- break;
- case "ANTICLOCKWISE":
- e = ", -"
- }
- return d + e + a + ")\n"
- };
- Blockly.Python.CocoRobo_bluebit_motor_off_i2c = function(a) {
- Blockly.Python.definitions_.import_parrot = "import parrot";
- return "parrot.set_speed(parrot.MOTOR_1, 0)\nparrot.set_speed(parrot.MOTOR_2, 0)\n"
- };
- Blockly.Python.CocoRobo_bluebit_coded_three_motor_on_i2c = function(a) {
- Blockly.Python.tops_.import_machine = "import machine\np19 \x3d machine.Pin(machine.Pin.P19, machine.Pin.OPEN_DRAIN, None, value\x3d0)";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- var b = Blockly.Python.valueToCode(a, "speed1", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "speed2", Blockly.Python.ORDER_ATOMIC),
- d = a.getFieldValue("Dial_code");
- a = a.getFieldValue("pattern");
- Blockly.Python.codeFunctions_["init_encoderMotor_pwm" + d] = "encoderMotor_pwm_" + ("0X10" === d ? "0" : "0X11" === d ? "1" : "0X12" === d ? "2" : "3") + " \x3d EncoderMotor(" + d + ")";
- return "encoderMotor_pwm_" + ("0X10" === d ? "0" : "0X11" === d ? "1" : "0X12" === d ? "2" : "3") + "." + a + "(" + b + ", " + c + ")\n"
- };
- Blockly.Python.CocoRobo_bluebit_coded_stop_motor_on_i2c = function(a) {
- Blockly.Python.tops_.import_machine = "import machine\np19 \x3d machine.Pin(machine.Pin.P19, machine.Pin.OPEN_DRAIN, None, value\x3d0)";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluebit = "from bluebit import *";
- a = a.getFieldValue("coded_stop");
- Blockly.Python.codeFunctions_["init_encoderMotor_stop" + a] = "encoderMotor_stop_" + ("0X10" === a ? "0" : "0X11" === a ? "1" : "0X12" === a ? "2" : "3") + " \x3d EncoderMotor(" + a + ")";
- return "encoderMotor_stop_" + ("0X10" === a ? "0" : "0X11" === a ? "1" : "0X12" === a ? "2" : "3") + ".motor_stop()\n"
- };
- Blockly.Python.CocoRobo_init_bluetooth = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
- a = Blockly.Python.valueToCode(a, "init_bluetooth", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_.bluetooth_define = "ble.init(" + a + ")";
- return ""
- };
- Blockly.Python.CocoRobo_OnOff_bluetooth = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
- return "ble." + a.getFieldValue("OnOff_bluetooth") + "_advertising()\n"
- };
- Blockly.Python.CocoRobo_HID_consumer_bluetooth = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("status_bar");
- return "ble.hidd_send_consumer(" + a.getFieldValue("type") + ", " + b + ")\n"
- };
- Blockly.Python.CocoRobo_HID_keyboard_bluetooth = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
- return "ble.hidd_send_keyboard([" + a.getFieldValue("HID_keyboard_bluetooth") + "])\n"
- };
- Blockly.Python.CocoRobo_HID_release_keyboard_bluetooth = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
- return "ble.hidd_send_keyboard([0])\n"
- };
- Blockly.Python.CocoRobo_HID_mouse_bluetooth = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
- return "ble.hidd_send_mouse(" + a.getFieldValue("HID_mouse") + ")\n"
- };
- Blockly.Python.CocoRobo_HID_release_mouse_bluetooth = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
- return "ble.hidd_send_mouse([0])\n"
- };
- Blockly.Python.CocoRobo_HID_mouse_pointer_bluetooth = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
- var b = Blockly.Python.valueToCode(a, "row", Blockly.Python.ORDER_ATOMIC);
- return "ble.hidd_send_mouse(" + Blockly.Python.valueToCode(a, "column", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
- };
- Blockly.Python.CocoRobo_HID_keyboard_group_bluetooth = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
- var b = Blockly.Python.valueToCode(a, "group", Blockly.Python.ORDER_ATOMIC);
- return "ble.hidd_send_keyboard([" + a.getFieldValue("HID_keyboard_bluetooth") + "]," + b + ")\n"
- };
- Blockly.Python.CocoRobo_HID_keyboard_part_bluetooth = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_bluetooth = "from bluetooth import ble";
- return [a.getFieldValue("HID_keyboard_group"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.dict_create_with_items_insert = function() {
- for (var a = Array(this.itemCount_), b = 0; b < this.itemCount_; b++) {
- var c = this.getFieldValue("KEY" + b);
- a[b] = '"' + c + '":' + (Blockly.Python.valueToCode(this, "ADD" + b, Blockly.Python.ORDER_NONE) || "0")
- }
- a = "{" + a.join(", ") + "}";
- return [a, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.pinyin_dict_create_with_items_insert = function() {
- for (var a = Array(this.itemCount_), b = 0; b < this.itemCount_; b++) {
- var c = this.getFieldValue("KEY" + b);
- a[b] = '"' + c + '":' + (Blockly.Python.valueToCode(this, "ADD" + b, Blockly.Python.ORDER_NONE) || "0")
- }
- a = "{" + a.join(", ") + "}";
- return [a, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.robot_dog_pinyin_dict_create_with_items_insert = function() {
- for (var a = Array(this.itemCount_), b = 0; b < this.itemCount_; b++) {
- var c = this.getFieldValue("KEY" + b);
- a[b] = '"' + c + '":' + (Blockly.Python.valueToCode(this, "ADD" + b, Blockly.Python.ORDER_NONE) || "0")
- }
- a = "{" + a.join(", ") + "}";
- return [a, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.dict_create_with = function(a) {
- var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "dict_items", Blockly.Python.ORDER_ATOMIC);
- return b + " \x3d " + a + "\n"
- };
- Blockly.Python.dict_key_value = function(a) {
- var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "dict_items", Blockly.Python.ORDER_ATOMIC);
- return [b + ".get(" + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.add_dict_key_value = function(a) {
- var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "dict_items", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "add_value", Blockly.Python.ORDER_ATOMIC);
- return b + "[" + c + "] \x3d " + a + "\n"
- };
- Blockly.Python.dict_length = function(a) {
- return ["len(" + Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.dict_key_exist = function(a) {
- var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC);
- return [Blockly.Python.valueToCode(a, "dict_items", Blockly.Python.ORDER_ATOMIC) + " in " + b, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.dict_key_or_val_list = function(a) {
- var b = Blockly.Python.valueToCode(a, "dict_name", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("key_or_val");
- return ["list(" + b + "." + a + "())", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_input = function(a) {
- return ["input(" + Blockly.Python.valueToCode(a, "imports", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.file_to_list = function(a) {
- var b = Blockly.Python.valueToCode(a, "file_path", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("separator");
- "ENTER" == a && (a = "\\r\\n");
- 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";
- return ["get_list_from_file(" + b + ", '" + a + "')", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.file_to_bin = function(a) {
- a = Blockly.Python.valueToCode(a, "file_path", Blockly.Python.ORDER_ATOMIC);
- 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";
- return ["get_bin_from_file(" + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_init_file = function(a) {
- a = Blockly.Python.valueToCode(a, "file_path", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_.def_init_text_file = "def init_text_file(_path):\n f \x3d open(_path, 'w')\n f.close()\n";
- return "init_text_file(" + a + ")\n"
- };
- Blockly.Python.CocoRobo_write_file = function(a) {
- var b = Blockly.Python.valueToCode(a, "file_path", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("separator");
- "ENTER" == a && (a = "\\r\\n");
- 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";
- return code = "write_data_to_file(" + b + ", " + c + ", '" + a + "')\n"
- };
- Blockly.Python.CocoRobo_sdcard_init = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_machine = "import machine";
- Blockly.Python.definitions_.import_sdcard = "import sdcard";
- 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";
- return ""
- };
- Blockly.Python.CocoRobo_sdcard_mount = function(a) {
- Blockly.Python.definitions_.import_os = "import os";
- return "os.mount(sd, " + Blockly.Python.valueToCode(a, "sd_path", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_dev_i2c_init = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "scl", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "sda", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "freq", Blockly.Python.ORDER_ATOMIC);
- return "i2c \x3d I2C(scl\x3dPin(Pin.P" + b + "), sda\x3dPin(Pin.P" + c + "), freq\x3d" + a + ")\n"
- };
- Blockly.Python.CocoRobo_i2c_init = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return "i2c \x3d I2C(scl\x3dPin(Pin.P19), sda\x3dPin(Pin.P20), freq\x3d" + Blockly.Python.valueToCode(a, "freq", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_i2c_read_write = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "adr", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC);
- return "i2c.writeto(" + b + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_i2c_readfrom = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "adr", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC);
- return "str(i2c.readfrom(" + b + ", " + a + "))\n"
- };
- Blockly.Python.mqtt_common_setup = function(a) {
- Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
- var b = Blockly.Python.valueToCode(a, "client_id", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "server", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "port", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "user", Blockly.Python.ORDER_ATOMIC),
- f = Blockly.Python.valueToCode(a, "password", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "keepalive", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_.mqtt_setup = "mqtt \x3d MQTTClient(" + b + ", " + c + ", " + d + ", " + e + ", " + f + ", " + a + ")";
- return ""
- };
- Blockly.Python.mqtt_tencent_setup = function(a) {
- Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
- Blockly.Python.definitions_.import_urequests = "import urequests";
- Blockly.Python.definitions_.import_json = "import json";
- var b = Blockly.Python.valueToCode(a, "Url", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "Port", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "AppId", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "Device", Blockly.Python.ORDER_ATOMIC);
- 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");';
- return ""
- };
- Blockly.Python.mqtt_setup = function(a) {
- Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
- var b = Blockly.Python.valueToCode(a, "Server", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "Iot_id", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "Iot_pwd", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "Client_ID", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_.mqtt_setup = "mqtt \x3d MQTTClient(" + a + ", " + b + ", 1883, " + c + ", " + d + ", keepalive\x3d30)";
- return ""
- };
- Blockly.Python.mqtt_connect = function(a) {
- Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
- Blockly.Python.definitions_.mqtt_connect = "\ntry:\n mqtt.connect()\n print('Connected')\nexcept:\n print('Disconnected')\n";
- return ""
- };
- Blockly.Python.mqtt_publish = function(a) {
- Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
- var b = Blockly.Python.valueToCode(a, "msg", Blockly.Python.ORDER_ATOMIC);
- return "mqtt.publish(" + Blockly.Python.valueToCode(a, "topic", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
- };
- Blockly.Python.mqtt_rec_from_topic = function(a) {
- Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
- var b = a.getFieldValue("topic"); -
- 1 != b.search("/") && b.replace(/\//g, "_");
- var c = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
- a = a.workspace.variableList;
- for (var d = a.length - 1; 0 <= d; d--)
- a[d] = Blockly.Python.variableDB_.getName(a[d], Blockly.Variables.NAME_TYPE);
- try {
- a.remove("_msg")
- } catch (e) {}
- a = a.length ? " global " + a.join(", ") + "\n" : "";
- d = toUTF8Hex(b);
- Blockly.Python.definitions_["mqtt_recv_topic_" + d] = "def mqtt_topic_" + d + "(_msg):\n" + a + c;
- 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";
- Blockly.Python.codeFunctions_.mqtt_set_callback = "mqtt.set_callback(mqtt_callback)";
- Blockly.Python.codeFunctions_["mqtt_subscribe" + b] = 'mqtt.subscribe("' + b + '")';
- 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";
- return ""
- };
- Blockly.Python.mqtt_receive = function(a) {
- Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
- var b = Blockly.Python.valueToCode(a, "topic", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
- a = a.workspace.variableList;
- for (var d = a.length - 1; 0 <= d; d--)
- a[d] = Blockly.Python.variableDB_.getName(a[d], Blockly.Variables.NAME_TYPE);
- try {
- a.remove("_msg")
- } catch (e) {}
- a = a.length ? " global " + a.join(", ") + "\n" : "";
- 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";
- Blockly.Python.codeFunctions_["mqtt_recv_topic_" + b] = '_mqtt_topic_list.append("' + b + '")\ndef mqtt_recv_' + b + "(_msg):\n" + a + c;
- Blockly.Python.codeFunctions_.mqtt_set_callback = "mqtt.set_callback(mqtt_callback)";
- 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";
- return "mqtt.subscribe(" + b + ")\n"
- };
- Blockly.Python.mqtt_wait_msg = function(a) {
- Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
- return "unblock" == a.getFieldValue("mode") ? "mqtt.check_msg()\n" : "mqtt.wait_msg()\n"
- };
- Blockly.Python.mqtt_disconnect = function(a) {
- Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
- return "mqtt.disconnect()\n"
- };
- Blockly.Python.mqtt_last_will = function(a) {
- Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
- var b = Blockly.Python.valueToCode(a, "topic", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "msg", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["mqtt_set_last_will" + b] = "mqtt.set_last_will(" + b + ", " + a + ")";
- return ""
- };
- Blockly.Python.CocoRobo_onenet_option_boards = function(a) {
- a.getFieldValue("option_boards");
- return ""
- };
- Blockly.Python.CocoRobo_onenet_setup = function(a) {
- Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- Blockly.Python.definitions_.import_machine = "import machine";
- Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
- var b = Blockly.Python.valueToCode(a, "server", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "device_id", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "product_id", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "product_APIKey", Blockly.Python.ORDER_ATOMIC);
- 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)) + '()')";
- Blockly.Python.definitions_.def_Timer14 = "tim14 \x3d Timer(14)";
- 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";
- 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";
- return "OneNET_setup()\n"
- };
- Blockly.Python.CocoRobo_onenet_setup_wechat_app = function(a) {
- Blockly.Python.definitions_.import_simple = "from umqtt.simple import MQTTClient";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- Blockly.Python.definitions_.import_machine = "import machine";
- Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
- var b = Blockly.Python.valueToCode(a, "server", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "device_id", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "product_id", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "product_APIKey", Blockly.Python.ORDER_ATOMIC);
- 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)) + '()')";
- Blockly.Python.definitions_.def_Timer14 = "tim14 \x3d Timer(14)";
- 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";
- 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";
- return "OneNET_setup()\n"
- };
- Blockly.Python.CocoRobo_onenet_recv = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- try {
- b.remove("_msg")
- } catch (d) {}
- try {
- b.remove("_name")
- } catch (d) {}
- try {
- b.remove("_value")
- } catch (d) {}
- b = b.length ? " global " + b.join(", ") + "\n" : "";
- a = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
- Blockly.Python.codeFunctions_.def_onenet_recv = "def OneNET_recv(_msg):\n" + b + a;
- return ""
- };
- Blockly.Python.CocoRobo_onenet_recv_from_wechat_app = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- try {
- b.remove("_msg")
- } catch (d) {}
- try {
- b.remove("_name")
- } catch (d) {}
- try {
- b.remove("_value")
- } catch (d) {}
- b = b.length ? " global " + b.join(", ") + "\n" : "";
- Blockly.Python.definitions_.import_ujson = "import json";
- a = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
- 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;
- return ""
- };
- Blockly.Python.CocoRobo_onenet_recv_msg = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- try {
- b.remove("_msg")
- } catch (e) {}
- try {
- b.remove("_name")
- } catch (e) {}
- try {
- b.remove("_value")
- } catch (e) {}
- var b = b.length ? " global " + b.join(", ") + "\n" : "",
- c = a.getFieldValue("message"),
- d = toUTF8Hex(c);
- a = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
- Blockly.Python.codeFunctions_["def_onenet_recv_" + d] = "_OneNET_msg_list.append('" + c + "')\ndef OneNET_recv_" + d + "():\n" + b + a;
- return ""
- };
- Blockly.Python.CocoRobo_onenet_pub_value = function(a) {
- Blockly.Python.definitions_.import_json = "import json";
- 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";
- var b = Blockly.Python.valueToCode(a, "NAME", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "VALUE", Blockly.Python.ORDER_ATOMIC);
- return "_iot.publish('$dp', pubdata({" + b + ":" + a + "}))\n"
- };
- Blockly.Python.CocoRobo_onenet_pub_value_wechat_app = function(a) {
- Blockly.Python.definitions_.import_json = "import json";
- 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";
- var b = Blockly.Python.valueToCode(a, "NAME", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "VALUE", Blockly.Python.ORDER_ATOMIC);
- return "_iot.publish('$dp', pubdata({" + b + ":" + a + "}))\n"
- };
- Blockly.Python.CocoRobo_onenet_pub_dict = function(a) {
- Blockly.Python.definitions_.import_json = "import json";
- 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";
- return "_iot.publish('$dp', pubdata(" + Blockly.Python.valueToCode(a, "DICT", Blockly.Python.ORDER_ATOMIC) + "))\n"
- };
- Blockly.Python.CocoRobo_onenet_disconnect = function(a) {
- return "tim14.deinit()\n_iot.disconnect()\nprint('Disconnected from MQTT server.')\n"
- };
- Blockly.Python.CocoRobo_blynk_terminal_widget_vpin = function(a) {
- a = Blockly.Python.valueToCode(a, "virtual_pin", Blockly.Python.ORDER_ATOMIC);
- 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";
- return ""
- };
- Blockly.Python.CocoRobo_blynk_sync_virtual = function(a) {
- return "blynk.virtual_sync(" + Blockly.Python.valueToCode(a, "virtual_pin", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_blynk_on_disconnected = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- try {
- b.remove("_value")
- } catch (d) {}
- b = b.length ? " global " + b.join(", ") + "\n" : "";
- c = Blockly.Python.statementToCode(a, "DO");
- c = Blockly.Python.addLoopTrap(c, a.id) || Blockly.Python.PASS;
- Blockly.Python.definitions_.blynk_on_disconnected = '@blynk.handle_event("disconnect")\ndef connect_handler():\n' + b + " print('Blynk disconnected')\n" + c;
- return ""
- };
- Blockly.Python.CocoRobo_blynk_on_connected = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- try {
- b.remove("_value")
- } catch (d) {}
- b = b.length ? " global " + b.join(", ") + "\n" : "";
- c = Blockly.Python.statementToCode(a, "DO");
- c = Blockly.Python.addLoopTrap(c, a.id) || Blockly.Python.PASS;
- Blockly.Python.definitions_.blynk_on_connected = '@blynk.handle_event("connect")\ndef connect_handler():\n' + b + " print('Blynk connected')\n" + c;
- return ""
- };
- Blockly.Python.CocoRobo_blynktimer_run = function(a) {
- return "blynk_timer.run()\n"
- };
- Blockly.Python.CocoRobo_blynk_run = function(a) {
- return "blynk.run()\n"
- };
- Blockly.Python.CocoRobo_blynk_app_notify = function(a) {
- return "blynk.notify(" + Blockly.Python.valueToCode(a, "notification", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_blynk_stop_timers = function(a) {
- Blockly.Python.definitions_.import_blynktimer = "import blynktimer";
- Blockly.Python.definitions_.def_blynktimer = "blynk_timer \x3d blynktimer.Timer(no_timers_err\x3dFalse)";
- a = Blockly.Python.valueToCode(a, "timer_num", Blockly.Python.ORDER_ATOMIC);
- return "blynk_timer.stop('" + a + "_blynk_timer" + a + "')\n"
- };
- Blockly.Python.CocoRobo_blynk_get_timers = function(a) {
- Blockly.Python.definitions_.import_blynktimer = "import blynktimer";
- Blockly.Python.definitions_.def_blynktimer = "blynk_timer \x3d blynktimer.Timer(no_timers_err\x3dFalse)";
- return ["blynk_timer.get_timers()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_blynktimer = function(a) {
- Blockly.Python.definitions_.import_blynktimer = "import blynktimer";
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- try {
- b.remove("_value")
- } catch (g) {}
- var b = b.length ? " global " + b.join(", ") + "\n" : "",
- c = Blockly.Python.valueToCode(a, "Num", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "period", Blockly.Python.ORDER_ATOMIC),
- e = a.getFieldValue("Timer_mode"),
- f = Blockly.Python.statementToCode(a, "DO"),
- f = Blockly.Python.addLoopTrap(f, a.id) || Blockly.Python.PASS;
- Blockly.Python.definitions_.def_blynktimer = "blynk_timer \x3d blynktimer.Timer(no_timers_err\x3dFalse)";
- Blockly.Python.definitions_["blynktimer_event" + c] = "\n@blynk_timer.register(interval\x3d" + d + ", run_once\x3d" + e + ")\ndef blynk_timer" + c + "():\n" + b + f;
- return ""
- };
- Blockly.Python.CocoRobo_blynk_sensor_data_to_app = function(a) {
- var b = Blockly.Python.valueToCode(a, "sensor_data", Blockly.Python.ORDER_ATOMIC);
- return "blynk.virtual_write(" + Blockly.Python.valueToCode(a, "virtual_pin", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
- };
- Blockly.Python.CocoRobo_blynk_app_data = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- try {
- b.remove("_value")
- } catch (e) {}
- var b = b.length ? " global " + b.join(", ") + "\n" : "",
- c = Blockly.Python.valueToCode(a, "virtual_pin", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.statementToCode(a, "DO"),
- d = Blockly.Python.addLoopTrap(d, a.id) || Blockly.Python.PASS;
- 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;
- return ""
- };
- Blockly.Python.CocoRobo_blynk_email = function(a) {
- var b = Blockly.Python.valueToCode(a, "body", Blockly.Python.ORDER_ATOMIC);
- return 'blynk.email("", ' + Blockly.Python.valueToCode(a, "subject", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
- };
- Blockly.Python.CocoRobo_blynk_set_property = function(a) {
- var b = Blockly.Python.valueToCode(a, "attribute_value", Blockly.Python.ORDER_ATOMIC);
- return "blynk.set_property(pin, " + Blockly.Python.valueToCode(a, "attribute_name", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")\n"
- };
- Blockly.Python.CocoRobo_blynk_setup = function(a) {
- Blockly.Python.definitions_.import_BlynkLib = "import blynklib";
- var b = Blockly.Python.valueToCode(a, "server", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "auth", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "port", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_.CocoRobo_blynk_setup = "blynk \x3d blynklib.Blynk(" + c + ", server\x3d" + b + ", port\x3d" + a + ")";
- Blockly.Python.definitions_.blynk_on_connected = "\n@blynk.handle_event(\"connect\")\ndef connect_handler():\n print('Blynk connected')\n";
- Blockly.Python.definitions_.blynk_on_disconnected = "\n@blynk.handle_event(\"disconnect\")\ndef connect_handler():\n print('Blynk disconnected')\n";
- return ""
- };
- Blockly.Python.CocoRobo_tinywebio_start = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_tinywebio = "from tinywebio import appserver, appclient";
- return "0" == a.getFieldValue("tinywebio_mode") ? "appserver.start()\n" : "appserver.start_foreground()\n"
- };
- Blockly.Python.CocoRobo_tinywebio_client_setup = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_tinywebio = "from tinywebio import appserver, appclient";
- var b = Blockly.Python.valueToCode(a, "db_server", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "send_items", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "recv_items", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "interval", Blockly.Python.ORDER_ATOMIC);
- return "appclient.setup(" + b + ",\n" + c + ",\n" + d + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_tinywebio_client_action = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_tinywebio = "from tinywebio import appserver, appclient";
- return "appclient." + a.getFieldValue("action_mode") + "()\n"
- };
- Blockly.Python.list_first_index = function(a) {
- var b = Blockly.Python.valueToCode(a, "elem", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "my_list", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("last_or_first");
- 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";
- 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";
- return [a + "_index(" + c + ", " + b + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_return_list = function(a) {
- var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "list_items", Blockly.Python.ORDER_ATOMIC);
- return b + " \x3d " + a + "\n"
- };
- Blockly.Python.lists_append = function(a) {
- var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "last_item", Blockly.Python.ORDER_ATOMIC);
- return b + ".append(" + a + ")\n"
- };
- Blockly.Python.lists_extend = function(a) {
- var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "extend_list", Blockly.Python.ORDER_ATOMIC);
- return b + ".extend(" + a + ")\n"
- };
- Blockly.Python.lists_clear = function(a) {
- return Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC) + ".clear()\n"
- };
- Blockly.Python.parts_of_list = function(a) {
- var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC),
- c = a.getFieldValue("list_start_order"),
- d = a.getFieldValue("list_end_order"),
- e = Blockly.Python.valueToCode(a, "start_item", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "end_item", Blockly.Python.ORDER_ATOMIC);
- switch (d) {
- case ":":
- var f = parseInt(a) + 1;
- break;
- case ":-":
- f = a - 1
- }
- return [b + c + e + d + f + "]", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.list_to_tuple = function(a) {
- return ["tuple(" + Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.list_order_item = function(a) {
- var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC),
- c = a.getFieldValue("list_order");
- a = Blockly.Python.valueToCode(a, "list_order_item", Blockly.Python.ORDER_ATOMIC);
- return [b + c + a + "]", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.set_list_order_item = function(a) {
- var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC),
- c = a.getFieldValue("list_order"),
- d = Blockly.Python.valueToCode(a, "list_order_item", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "set_value", Blockly.Python.ORDER_ATOMIC);
- return b + c + d + "] \x3d " + a + "\n"
- };
- Blockly.Python.insert_list_order_item = function(a) {
- var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC),
- c = a.getFieldValue("list_order"),
- d = Blockly.Python.valueToCode(a, "list_order_item", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "set_value", Blockly.Python.ORDER_ATOMIC);
- return b + ".insert" + c + d + ", " + a + ")\n"
- };
- Blockly.Python.list_item_exist = function(a) {
- var b = Blockly.Python.valueToCode(a, "list_name", Blockly.Python.ORDER_ATOMIC);
- return [Blockly.Python.valueToCode(a, "list_item", Blockly.Python.ORDER_ATOMIC) + " in " + b, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.addReservedWords("music");
- var _microbit_music_default_pin = 0;
- Blockly.Python.CocoRobo_music_play = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_music = "import music";
- var b = a.getFieldValue("melody");
- a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
- 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"
- };
- Blockly.Python.CocoRobo_music_play_until_end = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_music = "import music";
- var b = a.getFieldValue("melody");
- a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
- 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"
- };
- Blockly.Python.microbit_music_play_built_in = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_music = "import music";
- var b = a.getFieldValue("melody"),
- c = "TRUE" == a.getFieldValue("wait") ? "True" : "False",
- d = "TRUE" == a.getFieldValue("loop") ? "True" : "False";
- a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
- 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"
- };
- Blockly.Python.microbit_music_pitch = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_music = "import music";
- var b = Blockly.Python.valueToCode(a, "pitch", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "duration", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
- return "6" == a ? "music.pitch(" + b + ", " + c + ")\n" : "music.pitch(" + b + ", " + c + ", pin\x3dPin.P" + a + ")\n"
- };
- Blockly.Python.microbit_music_play_list_of_notes = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_music = "import music";
- var b = Blockly.Python.valueToCode(a, "notes", Blockly.Python.ORDER_ATOMIC),
- c = "TRUE" == a.getFieldValue("wait") ? "True" : "False",
- d = "TRUE" == a.getFieldValue("loop") ? "True" : "False";
- a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
- 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"
- };
- Blockly.Python.microbit_music_reset = function(a) {
- Blockly.Python.definitions_.import_music = "import music";
- return "music.reset()\n"
- };
- Blockly.Python.microbit_music_stop = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_music = "import music";
- a = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
- return "6" == a ? "music.stop()\n" : "music.stop(Pin.P" + a + ")\n"
- };
- Blockly.Python.microbit_music_set_tempo = function(a) {
- Blockly.Python.definitions_.import_music = "import music";
- var b = Blockly.Python.valueToCode(a, "ticks", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "bpm", Blockly.Python.ORDER_ATOMIC);
- return "music.set_tempo(ticks\x3d" + b + ", bpm\x3d" + a + ")\n"
- };
- Blockly.Python.microbit_music_set_tempo_speed = function(a) {
- Blockly.Python.definitions_.import_music = "import music";
- return "music.set_tempo(ticks\x3d 4, bpm\x3d" + 120 * Blockly.Python.valueToCode(a, "bpm", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.microbit_music_get_tempo = function(a) {
- Blockly.Python.definitions_.import_music = "import music";
- return ["music.get_tempo()", Blockly.Python.ORDER_MEMBER]
- };
- Blockly.Python.microbit_set_music_pin = function(a) {
- _microbit_music_default_pin = Blockly.Python.valueToCode(a, "pin", Blockly.Python.ORDER_ATOMIC);
- return ""
- };
- Blockly.Python.CocoRobo_neopixel_init = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_neopixel = "import neopixel";
- var b = a.getFieldValue("neopixel_name"),
- c = Blockly.Python.valueToCode(a, "n", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "analogP_IO", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["def_neopixel" + b] = b + " \x3d neopixel.NeoPixel(Pin(Pin.P" + a + "), n\x3d" + c + ", bpp\x3d3, timing\x3d1)";
- return ""
- };
- Blockly.Python.CocoRobo_neopixel_rainbow = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_neopixel = "import neopixel";
- var b = a.getFieldValue("neopixel_name"),
- c = Blockly.Python.valueToCode(a, "n", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "bright", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "offset", Blockly.Python.ORDER_ATOMIC);
- 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";
- return "make_rainbow(" + b + ", " + c + ", " + d + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_neopixel_single = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_neopixel = "import neopixel";
- var b = a.getFieldValue("neopixel_name"),
- c = Blockly.Python.valueToCode(a, "order", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
- return b + "[" + c + "] \x3d (" + d + ", " + e + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_neopixel_single_gui = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_neopixel = "import neopixel";
- var b = a.getFieldValue("neopixel_name"),
- c = Blockly.Python.valueToCode(a, "order", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("COLOUR");
- var d = 0,
- e = 0,
- f = 0;
- try {
- 7 == a.length && (d = parseInt(a.substring(1, 3), 16),
- e = parseInt(a.substring(3, 5), 16),
- f = parseInt(a.substring(5, 7), 16))
- } catch (g) {}
- return b + "[" + c + "] \x3d (" + d + ", " + e + ", " + f + ")\n"
- };
- Blockly.Python.CocoRobo_neopixel_show = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_neopixel = "import neopixel";
- return a.getFieldValue("neopixel_name") + ".write()\n"
- };
- Blockly.Python.CocoRobo_neopixel_off = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_neopixel = "import neopixel";
- a = a.getFieldValue("neopixel_name");
- return a + ".fill( (0, 0, 0) )\n" + a + ".write()\n"
- };
- Blockly.Python.CocoRobo_neopixel_all = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_neopixel = "import neopixel";
- var b = a.getFieldValue("neopixel_name"),
- c = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
- return b + ".fill( (" + c + ", " + d + ", " + a + ") )\n"
- };
- Blockly.Python.CocoRobo_neopixel_all_gui = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_neopixel = "import neopixel";
- var b = a.getFieldValue("neopixel_name");
- a = a.getFieldValue("COLOUR");
- var c = 0,
- d = 0,
- e = 0;
- try {
- 7 == a.length && (c = parseInt(a.substring(1, 3), 16),
- d = parseInt(a.substring(3, 5), 16),
- e = parseInt(a.substring(5, 7), 16))
- } catch (f) {}
- return b + ".fill( (" + c + ", " + d + ", " + e + ") )\n"
- };
- Blockly.Python.CocoRobo_neopixel_brightness = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_neopixel = "import neopixel";
- var b = a.getFieldValue("neopixel_name");
- a = Blockly.Python.valueToCode(a, "bright", Blockly.Python.ORDER_ATOMIC);
- return b + ".brightness(" + a + " / 100)\n"
- };
- Blockly.Python.CocoRobo_display_Show = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return "lcd.show()\n"
- };
- Blockly.Python.CocoRobo_display_DispChar = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "message", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("TEXTMODE");
- return "lcd.DispChar(" + d + ", " + b + ", " + c + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_display_DispChar_5lines = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "DispChar_5lines", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "message", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("TEXTMODE");
- return "lcd.DispChar(" + c + ", 0, " + b + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_clear_dispchar_5lines = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return "lcd.fill_rect(0, " + Blockly.Python.valueToCode(a, "DispChar_5lines", Blockly.Python.ORDER_ATOMIC) + ", 128, 16, 0)\n"
- };
- Blockly.Python.CocoRobo_display_fill = function(a) {
- Blockly.Python.definitions_.st7735 = "from st7735 import TFT";
- Blockly.Python.definitions_.sysfont = "from sysfont import sysfont";
- Blockly.Python.definitions_.machine = "from machine import SPI, Pin";
- var _code = '' +
- '_TFT_SPI = SPI(2, baudrate=20000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(23), miso=Pin(12))\n' +
- 'tft=TFT(_TFT_SPI,25,26,5)\n' +
- '\n' +
- 'tft.initr()\n' +
- 'tft.rgb(False)\n' +
- 'tft.rotation(1)\n' +
- 'tft.fill(TFT.BLACK)\n' +
- '';
- return _code;
- };
- Blockly.Python.CocoRobo_lcd_pixel_option = function(a) {
- return [a.getFieldValue("VALUE"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_display_pixel = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "display_pixel", Blockly.Python.ORDER_ATOMIC);
- return "lcd.pixel(" + b + ", " + c + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_display_hvline = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "length", Blockly.Python.ORDER_ATOMIC),
- e = a.getFieldValue("state");
- return "lcd." + ("0" == a.getFieldValue("dir_h_v") ? "v" : "h") + "line(" + b + ", " + c + ", " + d + ", " + e + ")\n"
- };
- Blockly.Python.CocoRobo_display_hline = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "length", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("state");
- return "lcd.hline(" + b + ", " + c + ", " + d + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_ProgressBar = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.codeFunctions_.define_UI = "myUI \x3d UI(lcd)";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "width", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "height", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "progress", Blockly.Python.ORDER_ATOMIC);
- return "myUI.ProgressBar(" + b + ", " + c + ", " + d + ", " + e + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_stripBar = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.codeFunctions_.define_UI = "myUI \x3d UI(lcd)";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "width", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "height", Blockly.Python.ORDER_ATOMIC),
- f = Blockly.Python.valueToCode(a, "progress", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("dir_h_v");
- return "myUI.stripBar(" + b + ", " + c + ", " + d + ", " + e + ", " + f + ", " + a + ", 1)\n"
- };
- Blockly.Python.CocoRobo_qr_code = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.codeFunctions_.define_UI = "myUI \x3d UI(lcd)";
- var b = Blockly.Python.valueToCode(a, "str", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("scale");
- return "myUI.qr_code(" + b + ", " + c + ", " + d + ", scale\x3d" + a + ")\n"
- };
- Blockly.Python.CocoRobo_display_vline = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "length", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("state");
- return "lcd.vline(" + b + ", " + c + ", " + d + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_display_line = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x1", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y1", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "x2", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "y2", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("state");
- return "lcd.line(" + b + ", " + c + ", " + d + ", " + e + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_display_shape_rect = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC),
- f = a.getFieldValue("state");
- return "lcd." + a.getFieldValue("shape") + "(" + b + ", " + c + ", " + d + ", " + e + ", " + f + ")\n"
- };
- Blockly.Python.CocoRobo_display_rect = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("state");
- return "lcd.rect(" + b + ", " + c + ", " + d + ", " + e + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_display_RoundRect = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC),
- f = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("state");
- return "lcd.RoundRect(" + b + ", " + c + ", " + d + ", " + e + ", " + f + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_display_fill_rect = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("state");
- return "lcd.fill_rect(" + b + ", " + c + ", " + d + ", " + e + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_display_shape_circle = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "radius", Blockly.Python.ORDER_ATOMIC),
- e = a.getFieldValue("state");
- return "lcd." + a.getFieldValue("shape") + "(" + b + ", " + c + ", " + d + ", " + e + ")\n"
- };
- Blockly.Python.CocoRobo_display_fill_circle = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "radius", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("state");
- return "lcd.fill_circle(" + b + ", " + c + ", " + d + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_display_circle = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "radius", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("state");
- return "lcd.circle(" + b + ", " + c + ", " + d + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_display_shape_triangle = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "x2", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "x3", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- f = Blockly.Python.valueToCode(a, "y2", Blockly.Python.ORDER_ATOMIC),
- g = Blockly.Python.valueToCode(a, "y3", Blockly.Python.ORDER_ATOMIC),
- h = a.getFieldValue("state");
- return "lcd." + a.getFieldValue("shape") + "(" + b + ", " + e + ", " + c + ", " + f + ", " + d + ", " + g + ", " + h + ")\n"
- };
- Blockly.Python.CocoRobo_display_triangle = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "x2", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "x3", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- f = Blockly.Python.valueToCode(a, "y2", Blockly.Python.ORDER_ATOMIC),
- g = Blockly.Python.valueToCode(a, "y3", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("state");
- return "lcd.triangle(" + b + ", " + e + ", " + c + ", " + f + ", " + d + ", " + g + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_display_fill_triangle = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "x2", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "x3", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- f = Blockly.Python.valueToCode(a, "y2", Blockly.Python.ORDER_ATOMIC),
- g = Blockly.Python.valueToCode(a, "y3", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("state");
- return "lcd.fill_triangle(" + b + ", " + e + ", " + c + ", " + f + ", " + d + ", " + g + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_display_Bitmap = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC),
- f = Blockly.Python.valueToCode(a, "Bitmap", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("state");
- return "lcd.Bitmap(" + b + ", " + c + ", bytearray(" + f + "), " + d + ", " + e + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_get_pbm_data = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.codeFunctions_.define_Image = "image_picture \x3d Image()";
- var b = a.getFieldValue("select");
- return ["image_picture.load(" + Blockly.Python.valueToCode(a, "file_path", Blockly.Python.ORDER_ATOMIC) + ", " + b + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_get_pbm_data_custom = Blockly.Python.CocoRobo_get_pbm_data;
- Blockly.Python.CocoRobo_display_pbm_data = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
- return "lcd.blit(" + Blockly.Python.valueToCode(a, "pbm_data", Blockly.Python.ORDER_ATOMIC) + ", " + b + ", " + c + ")\n"
- };
- Blockly.Python.CocoRobo_bitmap_from_file = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_framebuf = "import framebuf";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
- return "lcd.blit(framebuf.FrameBuffer(" + Blockly.Python.valueToCode(a, "pbm_data", Blockly.Python.ORDER_ATOMIC) + "[2], " + d + ", " + e + ", framebuf.MONO_HLSB), " + b + ", " + c + ")\n"
- };
- Blockly.Python.CocoRobo_pbm_image = function(a) {
- return ["'" + a.getFieldValue("path") + "'", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_font = function(a) {
- return [a.getFieldValue("font"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_display_font = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_framebuf = "import framebuf";
- var b = a.getFieldValue("font");
- Blockly.Python.definitions_["import_" + b] = "import " + b;
- 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]";
- var c = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "message", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("wrap");
- return b.startsWith("font.digiface_") ? "display_font(" + b + ", " + e + ", " + c + ", " + d + ", " + a + ", 2)\n" : "display_font(" + b + ", " + e + ", " + c + ", " + d + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_display_custom_font = Blockly.Python.CocoRobo_display_font;
- Blockly.Python.CocoRobo_display_FrameBuffer = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_framebuf = "import framebuf";
- var b = Blockly.Python.valueToCode(a, "bmp", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("scan_mode");
- return "fb1 \x3d framebuf.FrameBuffer(" + b + ", " + c + ", " + d + ", framebuf.MONO_" + a + ")\n"
- };
- Blockly.Python.CocoRobo_display_blit = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_framebuf = "import framebuf";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
- return "lcd.blit(fb1," + b + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobo_front_reverse = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return "lcd.invert(" + a.getFieldValue("front_reverse") + ")\n"
- };
- Blockly.Python.CocoRobo_images_append = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_framebuf = "import framebuf";
- Blockly.Python.definitions_.import_time = "import time";
- var b = Blockly.Python.valueToCode(a, "num", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "Length", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "Width", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "period", Blockly.Python.ORDER_ATOMIC);
- 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"
- };
- Blockly.Python.CocoRobo_radio_rec = function(a) {
- Blockly.Python.definitions_.import_radio = "import radio";
- return ["radio.receive()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_radio_send = function(a) {
- Blockly.Python.definitions_.import_radio = "import radio";
- return "radio.send(" + Blockly.Python.valueToCode(a, "send", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_radio_channel = function(a) {
- Blockly.Python.definitions_.import_radio = "import radio";
- return "radio.config(channel\x3d" + Blockly.Python.valueToCode(a, "channel", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_radio_on_off = function(a) {
- Blockly.Python.definitions_.import_radio = "import radio";
- return "radio." + a.getFieldValue("on_off") + "()\n"
- };
- Blockly.Python.CocoRobo_radio_recv = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- try {
- b.remove("_msg")
- } catch (d) {}
- b = b.length ? " global " + b.join(", ") + "\n" : "";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- Blockly.Python.definitions_.import_radio = "import radio";
- Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
- a = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
- Blockly.Python.definitions_.def_radio_recv = "def radio_recv(_msg):\n" + b + a;
- 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)) + '()')";
- Blockly.Python.definitions_.def_Timer13 = "tim13 \x3d Timer(13)";
- Blockly.Python.definitions_.timer13_tick = "def timer13_tick(_):\n _msg \x3d radio.receive()\n if not _msg: return\n radio_callback(_msg)\n";
- Blockly.Python.definitions_.timer13_init = "tim13.init(period\x3d20, mode\x3dTimer.PERIODIC, callback\x3dtimer13_tick)\n";
- return ""
- };
- Blockly.Python.CocoRobo_radio_recv_msg = function(a) {
- for (var b = a.workspace.variableList, c = b.length - 1; 0 <= c; c--)
- b[c] = Blockly.Python.variableDB_.getName(b[c], Blockly.Variables.NAME_TYPE);
- try {
- b.remove("_msg")
- } catch (e) {}
- b = b.length ? " global " + b.join(", ") + "\n" : "";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- Blockly.Python.definitions_.import_radio = "import radio";
- Blockly.Python.definitions_.import_ubinascii = "import ubinascii";
- Blockly.Python.statementToCode(a, "DO");
- 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)) + '()')";
- Blockly.Python.definitions_.def_Timer13 = "tim13 \x3d Timer(13)";
- Blockly.Python.definitions_.timer13_tick = "def timer13_tick(_):\n _msg \x3d radio.receive()\n if not _msg: return\n radio_callback(_msg)\n";
- Blockly.Python.definitions_.timer13_init = "tim13.init(period\x3d20, mode\x3dTimer.PERIODIC, callback\x3dtimer13_tick)\n";
- var c = a.getFieldValue("message"),
- d = toUTF8Hex(c);
- a = Blockly.Python.statementToCode(a, "DO") || Blockly.Python.PASS;
- Blockly.Python.codeFunctions_["def_radio_recv_" + d] = "_radio_msg_list.append('" + c + "')\ndef radio_recv_" + d + "():\n" + b + a;
- return ""
- };
- Blockly.Python.set_create_with_items_insert = function(a) {
- var b = Array(a.itemCount_);
- if (0 == a.itemCount_)
- a = "set()";
- else {
- for (var c = 0; c < a.itemCount_; c++)
- b[c] = Blockly.Python.valueToCode(a, "ADD" + c, Blockly.Python.ORDER_NONE) || "None";
- a = "{" + b.join(", ") + "}"
- }
- return [a, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.set_subset_superset = function(a) {
- var b = a.getFieldValue("subset_superset"),
- c = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "set_1_name", Blockly.Python.ORDER_ATOMIC);
- return [c + b + "(" + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.sets_update_ways = function(a) {
- var b = a.getFieldValue("sets_update_ways"),
- c = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "set_1_name", Blockly.Python.ORDER_ATOMIC);
- return c + b + "(" + a + ")\n"
- };
- Blockly.Python.get_sets_pop = function(a) {
- return [Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC) + ".pop()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.len_of_sets = function(a) {
- return ["len(" + Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC) + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.intersection_of_sets = function(a) {
- var b = a.getFieldValue("set_operation_type"),
- c = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "set_1_name", Blockly.Python.ORDER_ATOMIC);
- return [c + b + a, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.set_update_with = function(a) {
- var b = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "set_items", Blockly.Python.ORDER_ATOMIC);
- return b + ".update(" + a + ")\n"
- };
- Blockly.Python.set_create_with = function(a) {
- var b = Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "set_items", Blockly.Python.ORDER_ATOMIC);
- return b + " \x3d " + a + "\n"
- };
- Blockly.Python.text_set = function(a) {
- return ["{" + Blockly.Python.quote_empty(a.getFieldValue("TEXT")) + "}", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.create_empty_set = function(a) {
- return Blockly.Python.valueToCode(a, "set_name", Blockly.Python.ORDER_ATOMIC) + " \x3d set()\n"
- };
- Blockly.Python.set_tuple_order_item = function(a) {
- var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC),
- c = a.getFieldValue("tuple_order"),
- d = Blockly.Python.valueToCode(a, "tuple_order_item", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "set_value", Blockly.Python.ORDER_ATOMIC);
- return b + c + d + "] \x3d " + a + "\n"
- };
- Blockly.Python.tuple_create_with_items_insert = function(a) {
- for (var b = Array(a.itemCount_), c = 0; c < a.itemCount_; c++)
- b[c] = Blockly.Python.valueToCode(a, "ADD" + c, Blockly.Python.ORDER_NONE) || "None";
- return [1 == a.itemCount_ ? "(" + b[0] + ",)" : "(" + b.join(", ") + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.tuple_create_with = function(a) {
- var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "tuple_items", Blockly.Python.ORDER_ATOMIC);
- return b + " \x3d " + a + "\n"
- };
- Blockly.Python.tuple_order_item = function(a) {
- var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC),
- c = a.getFieldValue("tuple_order");
- a = Blockly.Python.valueToCode(a, "tuple_order_item", Blockly.Python.ORDER_ATOMIC);
- return [b + c + a + "]", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.tuple_min_max_len = function(a) {
- var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC);
- return [a.getFieldValue("tuple_min_max_len") + "(" + b + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.tuple_item_exist = function(a) {
- var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC);
- return [Blockly.Python.valueToCode(a, "tuple_item", Blockly.Python.ORDER_ATOMIC) + " in " + b, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.parts_of_tuple = function(a) {
- var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "tuple_item", Blockly.Python.ORDER_ATOMIC);
- return [b + "[" + a + ":]", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.parts_of_tuple2 = function(a) {
- var b = Blockly.Python.valueToCode(a, "tuple_name", Blockly.Python.ORDER_ATOMIC),
- c = a.getFieldValue("tuple_start_order"),
- d = a.getFieldValue("tuple_end_order"),
- e = Blockly.Python.valueToCode(a, "start_item", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "end_item", Blockly.Python.ORDER_ATOMIC);
- switch (d) {
- case ":":
- var f = parseInt(a) + 1;
- break;
- case ":-":
- f = a - 1
- }
- return [b + c + e + d + f + "]", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_uart_input = function(a) {
- return ['input("' + a.getFieldValue("title") + '")', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_uart_write_bytes = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("uart_name");
- a = Blockly.Python.valueToCode(a, "write_byte_arrays", Blockly.Python.ORDER_ATOMIC);
- return b + ".write(bytes(" + a + "))\n"
- };
- Blockly.Python.CocoRobo_uart_get_write_bytes = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("uart_name");
- a = Blockly.Python.valueToCode(a, "write_byte_arrays", Blockly.Python.ORDER_ATOMIC);
- return [b + ".write(bytes(" + a + "))\n", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_uart_write_byte = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("uart_name");
- a = Blockly.Python.valueToCode(a, "write_one_byte", Blockly.Python.ORDER_ATOMIC);
- return b + ".write(bytes([" + a + "]))\n"
- };
- Blockly.Python.CocoRobo_uart_get_write_byte = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("uart_name");
- a = Blockly.Python.valueToCode(a, "write_one_byte", Blockly.Python.ORDER_ATOMIC);
- return [b + ".write(bytes([" + a + "]))\n", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_uart_read = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return [a.getFieldValue("uart_name") + ".read()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_uart_read_length = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("uart_name");
- a = Blockly.Python.valueToCode(a, "read_length", Blockly.Python.ORDER_ATOMIC);
- return [b + ".read(" + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_uart_readline = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return [a.getFieldValue("uart_name") + ".readline()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_uart_has_data = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return [a.getFieldValue("uart_name") + ".any()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_uart_write_hex = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("uart_name"),
- c = a.getFieldValue("data");
- return "new" == a.getFieldValue("newline") ? b + ".write(hex(" + c + ') + "\\r\\n")\n' : b + ".write(hex(" + c + "))\n"
- };
- Blockly.Python.CocoRobo_uart_write_str = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("uart_name"),
- c = Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC);
- return "new" == a.getFieldValue("newline") ? b + ".write(" + c + ' + "\\r\\n")\n' : b + ".write(" + c + ")\n"
- };
- Blockly.Python.CocoRobo_uart_get_write_str = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("uart_name"),
- c = Blockly.Python.valueToCode(a, "data", Blockly.Python.ORDER_ATOMIC);
- return ["new" == a.getFieldValue("newline") ? b + ".write(" + c + ' + "\\r\\n")\n' : b + ".write(" + c + ")\n", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_uart_init = function(a) {
- Blockly.Python.definitions_.import_uart = "from machine import UART";
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- var b = a.getFieldValue("uart_name"),
- c = b.replace("uart", ""),
- d = Blockly.Python.valueToCode(a, "tx", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "rx", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "baudrate", Blockly.Python.ORDER_ATOMIC);
- Blockly.Python.definitions_["uart_object" + b] = b + " \x3d UART(" + c + ", baudrate\x3d" + a + ", tx\x3dPin.P" + d + ", rx\x3dPin.P" + e + ")";
- return ""
- };
- Blockly.Python.CocoRobo_uart_deinit = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return a.getFieldValue("uart_name") + ".deinit()\n"
- };
- Blockly.Python.CocoRobo_usocket_read = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = a.getFieldValue("socket_name");
- a = Blockly.Python.valueToCode(a, "size", Blockly.Python.ORDER_ATOMIC);
- return [b + ".read(" + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_usocket_setblocking = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = a.getFieldValue("socket_name");
- a = a.getFieldValue("mode");
- return b + ".setblocking(" + a + ")\n"
- };
- Blockly.Python.CocoRobo_usocket_settimeout = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = a.getFieldValue("socket_name");
- a = Blockly.Python.valueToCode(a, "_nums", Blockly.Python.ORDER_ATOMIC);
- return b + ".settimeout(" + a + ")\n"
- };
- Blockly.Python.CocoRobo_usocket_recv = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = a.getFieldValue("socket_name");
- a = Blockly.Python.valueToCode(a, "_nums", Blockly.Python.ORDER_ATOMIC);
- return [b + ".recv(" + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_text_ESC = function(a) {
- // Blockly.Python.definitions_.import_usocket = "import usocket";
- return ['"' + a.getFieldValue("mode") + '"', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_usocket_recvfrom = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = a.getFieldValue("socket_name");
- a = Blockly.Python.valueToCode(a, "_nums", Blockly.Python.ORDER_ATOMIC);
- return [b + ".recvfrom(" + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_usocket_sendall = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = a.getFieldValue("socket_name");
- a = Blockly.Python.valueToCode(a, "_bytes", Blockly.Python.ORDER_ATOMIC);
- return b + ".sendall(" + a + ")\n"
- };
- Blockly.Python.CocoRobo_usocket_sends = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = a.getFieldValue("socket_name");
- a = Blockly.Python.valueToCode(a, "_bytes", Blockly.Python.ORDER_ATOMIC);
- return b + ".send(" + a + ")\n"
- };
- Blockly.Python.CocoRobo_usocket_send = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = a.getFieldValue("socket_name");
- a = Blockly.Python.valueToCode(a, "_bytes", Blockly.Python.ORDER_ATOMIC);
- return [b + ".send(bytes(" + a + ", 'utf-8'))", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_usocket_sendto = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = a.getFieldValue("socket_name"),
- c = Blockly.Python.valueToCode(a, "_bytes", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "_address", Blockly.Python.ORDER_ATOMIC);
- return b + ".sendto(bytes(" + c + ", 'utf-8'), " + a + ")\n"
- };
- Blockly.Python.CocoRobo_usocket_connect = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = a.getFieldValue("socket_name"),
- c = Blockly.Python.valueToCode(a, "host", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "port", Blockly.Python.ORDER_ATOMIC);
- return b + ".connect((" + c + ", " + a + "))\n"
- };
- Blockly.Python.CocoRobo_usocket_getaddrinfo = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = Blockly.Python.valueToCode(a, "host", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "port", Blockly.Python.ORDER_ATOMIC);
- return ["(usocket.getaddrinfo(" + b + ", " + a + ")[0][-1])[0]", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_usocket_accept = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- return [a.getFieldValue("socket_name") + ".accept()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_usocket_listen = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = a.getFieldValue("socket_name");
- a = Blockly.Python.valueToCode(a, "backlog", Blockly.Python.ORDER_ATOMIC);
- return b + ".listen(" + a + ")\n"
- };
- Blockly.Python.CocoRobo_usocket_bind = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = a.getFieldValue("socket_name"),
- c = Blockly.Python.valueToCode(a, "address", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "port", Blockly.Python.ORDER_ATOMIC);
- return b + ".bind((" + c + ", " + a + "))\n"
- };
- Blockly.Python.CocoRobo_usocket_init = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = a.getFieldValue("socket_name"),
- c = a.getFieldValue("af");
- a = a.getFieldValue("_type");
- Blockly.Python.codeFunctions_.init_usocket = b + " \x3d usocket.socket(usocket." + c + ", usocket." + a + ")";
- return ""
- };
- Blockly.Python.CocoRobo_usocket_setsockopt = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- var b = a.getFieldValue("socket_name"),
- c = Blockly.Python.valueToCode(a, "value", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("_type");
- Blockly.Python.codeFunctions_.init_setsockopt = b + ".setsockopt(usocket.SOL_SOCKET, usocket." + a + ", " + c + ")";
- return ""
- };
- Blockly.Python.CocoRobo_usocket_close = function(a) {
- Blockly.Python.definitions_.import_usocket = "import usocket";
- return a.getFieldValue("socket_name") + ".close()\n"
- };
- Blockly.Python.CocoRobo_get_post = function(a) {
- Blockly.Python.definitions_.import_urequests = "import urequests";
- Blockly.Python.definitions_.import_json = "import json";
- var b = a.getFieldValue("get_post"),
- c = Blockly.Python.valueToCode(a, "url", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "json", Blockly.Python.ORDER_ATOMIC) || "None";
- return "None" == a ? "_response \x3d urequests." + b + "(" + c + ")\n" : "_response \x3d urequests." + b + "(" + c + ', headers\x3d{"Content-Type":"application/json"}, params\x3d' + a + ")\n"
- };
- Blockly.Python.CocoRobo_urequests_get_post = function(a) {
- Blockly.Python.definitions_.import_urequests = "import requests";
- Blockly.Python.definitions_.import_json = "import json";
- var b = Blockly.Python.valueToCode(a, "url", Blockly.Python.ORDER_ATOMIC),
- c = a.getFieldValue("method");
- a = Blockly.Python.valueToCode(a, "json", Blockly.Python.ORDER_ATOMIC) || "None";
- var code = "_SEND_HTTP_GET_ENDPOINT = " + b + "\n";
- if ("None" != a) {
- code += "_SEND_HTTP_POST_DATA = " + a + "\n";
- }
- Blockly.Python.addSetup("CocoRobo_urequests_get_post", code);
- Blockly.Python.addVariable("_SEND_HTTP_REQUEST", "None");
- 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";
- };
- Blockly.Python.CocoRobo_urequests_post_file = function(a) {
- Blockly.Python.definitions_.import_urequests = "import requests";
- Blockly.Python.definitions_.import_json = "import json";
- var b = Blockly.Python.valueToCode(a, "url", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "file_name", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "file_type", Blockly.Python.ORDER_ATOMIC),
- c = '{"file":(' + c + ", " + d + ")}";
- a = Blockly.Python.valueToCode(a, "json", Blockly.Python.ORDER_ATOMIC) || "None";
- return "None" == a ? "_response \x3d requests.post(" + b + ", files\x3d" + c + ")\n" : "_response \x3d requests.post(" + b + ", files\x3d" + c + ", params\x3d" + a + ")\n"
- };
- Blockly.Python.CocoRobo_response = function(a) {
- Blockly.Python.definitions_.import_urequests = "import urequests";
- return ["_response." + a.getFieldValue("response"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_response_attribute = function(a) {
- Blockly.Python.definitions_.import_urequests = "import urequests";
- return ["_response." + a.getFieldValue("response_attribute"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_init_wifi = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_network = "import network";
- var b = Blockly.Python.valueToCode(a, "ssid", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "password", Blockly.Python.ORDER_ATOMIC);
- var _code = 'init_sta = network.WLAN(network.STA_IF)\n' +
- 'init_ap = network.WLAN(network.AP_IF)\n' +
- 'init_ap.active(False)\n' +
- 'init_sta.active(True)\n' +
- 'init_sta.connect(essid=' + b + ', password=' + a + ')\n';
- // Blockly.Python.definitions_.wifi_define = "my_wifi \x3d wifi()";
- // Blockly.Python.definitions_.my_wifi = "my_wifi.connectWiFi(" + b + ", " + a + ")\n";
- return _code;
- };
- Blockly.Python.CocoRobo_dis_WiFi = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_network = "import network";
- //Blockly.Python.codeFunctions_.wifi_define = "my_wifi \x3d wifi()";
- return "init_sta.active(False)\n"
- };
- Blockly.Python.CocoRobo_wifi_all_config = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_network = "import network";
- return ["my_wifi.sta.ifconfig()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_wifi_isconnected = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_network = "import network";
- return ["init_sta.isconnected()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_WiFi_config = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_network = "import network";
- return ["init_sta.ifconfig()[" + a.getFieldValue("WiFi_config") + "]", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_wifi_channel = function(a) {
- return [a.getFieldValue("channel"), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_enable_APWiFi = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_network = "import network";
- var b = Blockly.Python.valueToCode(a, "essid", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "password", Blockly.Python.ORDER_ATOMIC);
- "" == c && (c = '""');
- a = Blockly.Python.valueToCode(a, "channel", Blockly.Python.ORDER_ATOMIC);
- var _code = "init_sta = network.WLAN(network.STA_IF)\n" +
- "init_ap = network.WLAN(network.AP_IF)\n" +
- "init_sta.active(False)\n" +
- "init_ap.active(True)\n";
- if (c == '""') {
- _code += "init_ap.config(essid=" + b + ", authmode=0, channel=" + a + ", hidden=0, dhcp_hostname=\"CocoRobo_AP\")\n";
- } else {
- _code += "init_ap.config(essid=" + b + ", authmode=3, password=" + c + ", channel=" + a + ", hidden=0, dhcp_hostname=\"CocoRobo_AP\")\n";
- }
- return _code;
- };
- Blockly.Python.CocoRobo_disable_APWiFi = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_network = "import network";
- // Blockly.Python.codeFunctions_.wifi_define = "my_wifi \x3d wifi()";
- return "init_ap.active(False)\n"
- };
- Blockly.Python.CocoRobo_ntptime_settime = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_ntptime = "import ntptime";
- return "ntptime.settime()\n";
- };
- Blockly.Python.CocoRobo_seniverse_city_weather = function(a) {
- Blockly.Python.definitions_.import_json = "import json";
- Blockly.Python.definitions_.import_urequests = "import urequests";
- var b = Blockly.Python.valueToCode(a, "location", Blockly.Python.ORDER_ATOMIC);
- "" == b && (b = "ip");
- var c = a.getFieldValue("api");
- a.getFieldValue("type");
- var d = a.getFieldValue("key"),
- e = a.getFieldValue("language");
- a = a.getFieldValue("unit");
- var f = "https://api.seniverse.com/v3/weather/now.json";
- switch (c) {
- case "api_2":
- f = "https://api.seniverse.com/v3/weather/daily.json";
- break;
- case "api_3":
- f = "https://api.seniverse.com/v3/life/suggestion.json"
- }
- 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';
- f += "?key\x3d" + d;
- "zh-Hant" == e && (f += "\x26language\x3dzh-Hant");
- "f" == a && "api_3" != c && (f += "\x26unit\x3df");
- return ['get_seni_weather("' + f + '", ' + b + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_define_seniverse_weather = function(a) {
- var b = a.getFieldValue("var_name");
- a = Blockly.Python.valueToCode(a, "info", Blockly.Python.ORDER_ATOMIC);
- return b + " \x3d " + a + "\n"
- };
- Blockly.Python.CocoRobo_get_seniverse_weather_info = function(a) {
- var b = a.getFieldValue("var_name");
- a = a.getFieldValue("type");
- switch (a) {
- case "object":
- break;
- case "last_update":
- b += '["results"][0]["last_update"]';
- break;
- case "last_update_date":
- b += '["results"][0]["last_update"][:10]';
- break;
- default:
- b = b + '["results"][0]["location"]["' + a + '"]'
- }
- return [b, Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_get_seniverse_weather_info1 = function(a) {
- var b = a.getFieldValue("var_name");
- a = a.getFieldValue("type");
- return [b + '["results"][0]["now"]["' + a + '"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_get_seniverse_weather_info2 = function(a) {
- var b = a.getFieldValue("var_name"),
- c = a.getFieldValue("date");
- a = a.getFieldValue("type");
- return [b + '["results"][0]["daily"][' + c + ']["' + a + '"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_get_seniverse_weather_info3 = function(a) {
- var b = a.getFieldValue("var_name");
- a = a.getFieldValue("type");
- return [b + '["results"][0]["suggestion"]["' + a + '"]["brief"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_wifi_clock = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_network = "import network";
- Blockly.Python.definitions_.import_ntptime = "import ntptime";
- Blockly.Python.definitions_.machine_Timer = "from machine import Timer";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "radius", Blockly.Python.ORDER_ATOMIC);
- 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';
- return "wifi_clock(" + b + ", " + c + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobobox_slider = function(a) {
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ["slider_res.read()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobobox_5button = function(a) {
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ["get_key() \x3d\x3d {" + a.getFieldValue("button_val") + "}", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobobox_ultrasonic = function(a) {
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ["get_distance()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobobox_Thehumanbodyinfrare = function(a) {
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ["pir.value()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobobox_sound = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.codeFunctions_.init_sound = "sound.init()";
- return ["sound.read()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobobox_light = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return ["light.read()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_bme280_hum_tem_pre = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- return ["bme280." + a.getFieldValue("hum_tem_pre") + "()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobobox_motor = function(a) {
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "set_motor(" + Blockly.Python.valueToCode(a, "speed", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobobox_RGB_clear = function(a) {
- Blockly.Python.definitions_.import_machine_only = "import machine";
- return "machine.display.clear()\n"
- };
- Blockly.Python.CocoRobobox_RGB_pixel = function(a) {
- Blockly.Python.definitions_.import_machine_only = "import machine";
- var b = Blockly.Python.valueToCode(a, "speed1", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "speed2", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "speed3", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "speed4", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "speed5", Blockly.Python.ORDER_ATOMIC);
- return "machine.display.set_pixel(" + b + ", " + c + ", (" + d + ", " + e + ", " + a + "))\n"
- };
- Blockly.Python.CocoRobobox_RGB_get_pixel = function(a) {
- Blockly.Python.definitions_.import_machine_only = "import machine";
- var b = Blockly.Python.valueToCode(a, "speed1", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "speed2", Blockly.Python.ORDER_ATOMIC);
- return ["machine.display.get_pixel(" + b + ", " + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobobox_RGB_ImageText = function(a) {
- Blockly.Python.definitions_.import_machinee_only = "import machine";
- var b = Blockly.Python.valueToCode(a, "speed1", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "speed2", Blockly.Python.ORDER_ATOMIC);
- return "machine.display.scroll(" + b + ", " + a + ")\n"
- };
- Blockly.Python.CocoRobobox_RGB_SetImage = function(a) {
- Blockly.Python.definitions_.import_machine_only = "import machine";
- var b = Blockly.Python.valueToCode(a, "row0", Blockly.Python.ORDER_MEMBER),
- c = Blockly.Python.valueToCode(a, "row1", Blockly.Python.ORDER_MEMBER),
- d = Blockly.Python.valueToCode(a, "row2", Blockly.Python.ORDER_MEMBER),
- e = Blockly.Python.valueToCode(a, "row3", Blockly.Python.ORDER_MEMBER);
- a = Blockly.Python.valueToCode(a, "row4", Blockly.Python.ORDER_MEMBER);
- return ["machine.Image(str(" + b + ") + ':' + str(" + c + ") + ':' + str(" + d + ") + ':' + str(" + e + ") + ':' + str(" + a + "))", Blockly.Python.ORDER_MEMBER]
- };
- Blockly.Python.CocoRobobox_RGB_Image = function(a) {
- Blockly.Python.definitions_.import_machine_only = "import machine";
- return "machine.display.show(" + Blockly.Python.valueToCode(a, "image", Blockly.Python.ORDER_MEMBER) + ")\n"
- };
- Blockly.Python.CocoRobobox_RGB_ImageImport = function(a) {
- Blockly.Python.definitions_.import_machine_only = "import machine";
- return [Blockly.Python.valueToCode(a, "image", Blockly.Python.ORDER_MEMBER), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobobox_RGB_ImageCopy = function(a) {
- Blockly.Python.definitions_.import_machine_only = "import machine";
- return [Blockly.Python.valueToCode(a, "image", Blockly.Python.ORDER_MEMBER) + ".copy()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobobox_RGB_ImageCot = function(a) {
- Blockly.Python.definitions_.import_machine_only = "import machine";
- var b = Blockly.Python.valueToCode(a, "image", Blockly.Python.ORDER_MEMBER),
- c = Blockly.Python.valueToCode(a, "speed2", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "speed3", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "speed4", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "speed5", Blockly.Python.ORDER_ATOMIC);
- return [b + ".crop(" + c + "," + d + "," + e + "," + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_image_builtins = function(a) {
- Blockly.Python.definitions_.import_machine_only = "import machine";
- return ["machine.Image." + a.getFieldValue("image"), Blockly.Python.ORDER_MEMBER]
- };
- Blockly.Python.CocoRobobox_image_shift = function(a) {
- Blockly.Python.definitions_.import_machine_only = "import machine";
- var b = Blockly.Python.valueToCode(a, "image", Blockly.Python.ORDER_MEMBER),
- c = a.getFieldValue("shift");
- a = Blockly.Python.valueToCode(a, "pos", Blockly.Python.ORDER_ATOMIC);
- switch (c) {
- case "LEFT":
- b = b + ".shift_left(" + a + ")";
- break;
- case "RIGHT":
- b = b + ".shift_right(" + a + ")";
- break;
- case "UP":
- b = b + ".shift_up(" + a + ")";
- break;
- case "DOWN":
- b = b + ".shift_down(" + a + ")"
- }
- return [b, Blockly.Python.ORDER_MEMBER]
- };
- Blockly.Python.CocoRobobox_triaxial_acceleration = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ["motion.get_accel()[" + a.getFieldValue("enable") + "]", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobobox_triaxial_angular_velocity = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ["motion.get_gyro()[" + a.getFieldValue("enable") + "]", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobobox_euler_angle = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ["motion.get_euler()[" + a.getFieldValue("enable") + "]", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobobox_quaternion = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ["motion.get_quat()[" + a.getFieldValue("enable") + "]", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_Face_tracking = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- Blockly.Python.codeFunctions_.model_FACE_YOLO = "model.select_model(model.FACE_YOLO)";
- return ""
- };
- Blockly.Python.CocoRobo_AI2_Face_photograph_tracking = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "result_face \x3d model.detect_yolo()\n"
- };
- Blockly.Python.CocoRobo_AI2_result_face = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ["result_face", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_result_face_x = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ['result_face[0]["x"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_result_face_y = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ['result_face[0]["y"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_result_face_w = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ['result_face[0]["w"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_result_face_h = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ['result_face[0]["h"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_result_face_value = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ['result_face[0]["value"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_result_face_objnum = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ['result_face[0]["objnum"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_20classid_tracking = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- Blockly.Python.codeFunctions_.model_CLASS_20_YOLO = "model.select_model(model.CLASS_20_YOLO)";
- return ""
- };
- Blockly.Python.CocoRobo_AI2_20classid_photograph_tracking = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "result_20class \x3d model.detect_yolo()\n"
- };
- Blockly.Python.CocoRobo_AI2_result_20class = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ["result_20class", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_result_20class_x = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ['result_20class[0]["x"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_result_20class_y = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ['result_20class[0]["y"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_result_20class_w = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ['result_20class[0]["w"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_result_20class_h = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ['result_20class[0]["h"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_result_20class_value = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ['result_20class[0]["value"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_result_20class_objnum = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ['result_20class[0]["objnum"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_result_20class_classid = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ['result_20class[0]["classid"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_result_20class_index = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ['result_20class[0]["index"]', Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_20class_tracking = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- Blockly.Python.codeFunctions_.model_CLASS_20_YOLO = "model.select_model(model.CLASS_20_YOLO)";
- return "result_20class \x3d model.detect_yolo()\n"
- };
- Blockly.Python.CocoRobo_AI2_number_discern = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- Blockly.Python.codeFunctions_.model_MNIST_NET = "model.select_model(model.MNIST_NET)";
- return ""
- };
- Blockly.Python.CocoRobo_AI2_number_result = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "discern_number \x3d model.predict_net()\n"
- };
- Blockly.Python.CocoRobo_AI_NumberDetect_all = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ["discern_number", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI_NumberDetect_number = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- 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";
- return ["result_numbers()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI_NumberDetect_adience = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- 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";
- return ["result_adience()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI_trace_color = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "area", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "pixel", Blockly.Python.ORDER_ATOMIC);
- 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]
- };
- Blockly.Python.CocoRobo_AI_trace_color_displayten = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "image.draw_" + a.getFieldValue("number") + "\n"
- };
- Blockly.Python.CocoRobo_AI2_blob_all = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC), Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_blob_x = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".x()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_blob_y = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".y()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_blob_w = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".w()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_blob_h = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".h()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_blob_number = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".pixels()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_blob_center_x = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".cx()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_blob_center_y = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".cy()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI2_blob_orthogon = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return [Blockly.Python.valueToCode(a, "variables", Blockly.Python.ORDER_ATOMIC) + ".rect()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI_sensor_reset = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- Blockly.Python.codeFunctions_.camera_reset = "camera.reset()\n";
- return ""
- };
- Blockly.Python.CocoRobo_AI_sensor_images = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "camera.snapshot()\n"
- };
- Blockly.Python.CocoRobo_AI_sensor_enable = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "camera.run(" + a.getFieldValue("enable") + ")\n"
- };
- Blockly.Python.CocoRobo_AI_sensor_return = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return ["image." + a.getFieldValue("enable") + "()", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI_sensor_sets = function(a) {
- var b = a.getFieldValue("pattern");
- a = a.getFieldValue("number");
- return "camera.set_" + b + "(" + a + ")\n"
- };
- Blockly.Python.CocoRobo_AI_sensor_auto_gain = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "camera.set_auto_gain(" + a.getFieldValue("enable") + ")\n"
- };
- Blockly.Python.CocoRobo_AI_sensor_auto_whitebal = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "camera.set_auto_whitebal(" + a.getFieldValue("enable") + ")\n"
- };
- Blockly.Python.CocoRobo_AI_sensor_level_MI = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = a.getFieldValue("select");
- a = a.getFieldValue("enable");
- return "camera.set_" + b + "(" + a + ")\n"
- };
- Blockly.Python.CocoRobo_AI_sensor_pattern = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- a = a.getFieldValue("yolo");
- Blockly.Python.codeFunctions_.set_pixformat = "camera.set_pixformat(camera." + a + ")\n";
- return ""
- };
- Blockly.Python.CocoRobo_AI_lcd_init = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- Blockly.Python.codeFunctions_.AI_lcd_init = "lcd.init()\n";
- return ""
- };
- Blockly.Python.CocoRobo_AI_lcd_text = function(a) {
- Blockly.Python.definitions_.import_lcd = "import lcd";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "message", Blockly.Python.ORDER_ATOMIC);
- return "lcd_draw_string(lcd," + b + ", " + c + ", " + a + ", lcd.RED, lcd.BLACK)\n"
- };
- Blockly.Python.CocoRobo_AI_LCD_clearall = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "image.clear()\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_pixel_colour = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
- return "image.set_pixel(" + b + ", " + c + ", color\x3d(" + d + ", " + e + ", " + a + "))\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_colour = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
- return "lcd.clear(color\x3d(" + b + ", " + c + ", " + a + "))\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_display = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "lcd.display()\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_display_size = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
- return "lcd.display(roi\x3d(" + b + ", " + c + ", " + d + ", " + a + "))\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_show_image_erosion = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "image.dilate(" + Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC) + ", threshold\x3dFalse)\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_show_image_middle = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "size", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "bias", Blockly.Python.ORDER_ATOMIC);
- return "image.midpoint(" + b + ", bias\x3d" + a + ")\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_show_image_mode = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "image.mode(" + Blockly.Python.valueToCode(a, "size", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_show_image_indistinct = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "image.midpoint(" + Blockly.Python.valueToCode(a, "size", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_show_image_cartoon = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "size", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "seed", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "floating", Blockly.Python.ORDER_ATOMIC);
- return "image.cartoon(" + b + ", seed_threshold\x3d" + c + ", floating_threshold\x3d" + a + ")\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_show_image_3D = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "x_rotation", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y_rotation", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "z_rotation", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "x_translation", Blockly.Python.ORDER_ATOMIC),
- f = Blockly.Python.valueToCode(a, "y_translation", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "zoom", Blockly.Python.ORDER_ATOMIC);
- 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"
- };
- Blockly.Python.CocoRobo_AI_LCD_show_REC = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC),
- f = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
- g = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC),
- h = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC),
- k = Blockly.Python.valueToCode(a, "thickness", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("solid");
- return "image.draw_rectangle(" + b + ", " + c + ", " + d + ", " + e + ",color\x3d(" + f + ", " + g + ", " + h + "),thickness\x3d" + k + ", fill\x3d" + a + ")\n"
- };
- Blockly.Python.CocoRobo_AI_LCD_show_string = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC),
- f = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
- g = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC),
- h = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "thickness", Blockly.Python.ORDER_ATOMIC);
- return "image.draw_line(" + b + ", " + c + ", " + d + ", " + e + ", color\x3d(" + f + ", " + g + ", " + h + "), thickness\x3d" + a + ")\n"
- };
- Blockly.Python.CocoRobo_AI_LCD_return_colour = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC);
- return ["image.get_pixel(" + b + ", " + a + ")", Blockly.Python.ORDER_ATOMIC]
- };
- Blockly.Python.CocoRobo_AI_LCD_show_circle = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "radius", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
- f = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC),
- g = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC),
- h = Blockly.Python.valueToCode(a, "thickness", Blockly.Python.ORDER_ATOMIC);
- a = a.getFieldValue("fill");
- return "image.draw_circle(" + b + ", " + c + ", " + d + ",color\x3d(" + e + ", " + f + ", " + g + "),thickness\x3d" + h + ", fill\x3d" + a + ")\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_text_most = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC),
- f = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC),
- g = Blockly.Python.valueToCode(a, "scale", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "message", Blockly.Python.ORDER_ATOMIC);
- 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"
- };
- Blockly.Python.CocoRobo_AI_LCD_show_ten_string = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC),
- f = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC),
- g = Blockly.Python.valueToCode(a, "size", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "thickness", Blockly.Python.ORDER_ATOMIC);
- return "image.draw_cross(" + b + ", " + c + ", color\x3d(" + d + ", " + e + ", " + f + "), size\x3d" + g + ", thickness\x3d" + a + ")\n"
- };
- Blockly.Python.CocoRobo_AI_LCD_show_arrows = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC),
- f = Blockly.Python.valueToCode(a, "r", Blockly.Python.ORDER_ATOMIC),
- g = Blockly.Python.valueToCode(a, "g", Blockly.Python.ORDER_ATOMIC),
- h = Blockly.Python.valueToCode(a, "b", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "thickness", Blockly.Python.ORDER_ATOMIC);
- return "image.draw_arrow(" + b + "," + c + "," + d + "," + e + ",color\x3d(" + f + "," + g + "," + h + "),thickness\x3d" + a + ")\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_show_image_picture = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "image.load(" + Blockly.Python.valueToCode(a, "message", Blockly.Python.ORDER_ATOMIC) + ")\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_show_image_heat = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- return "image." + a.getFieldValue("enable") + "()\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_show_image_descartes = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = a.getFieldValue("enable");
- a = a.getFieldValue("select");
- return "image." + b + "(reverse\x3d" + a + ")\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_show_ectype = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC),
- e = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
- return "image.save(" + Blockly.Python.valueToCode(a, "message", Blockly.Python.ORDER_ATOMIC) + ", roi\x3d(" + b + ", " + c + ", " + d + ", " + e + "))\n"
- };
- Blockly.Python.CocoRobo_AI_lcd_show_ectype_show = function (a) {
- //Blockly.Python.definitions_.import_CocoRobo = "from CocoRobo import *";
- Blockly.Python.definitions_.import_CocoRobo_classroom_kit = "from CocoRobo_classroom_kit import *";
- var b = Blockly.Python.valueToCode(a, "x", Blockly.Python.ORDER_ATOMIC),
- c = Blockly.Python.valueToCode(a, "y", Blockly.Python.ORDER_ATOMIC),
- d = Blockly.Python.valueToCode(a, "w", Blockly.Python.ORDER_ATOMIC);
- a = Blockly.Python.valueToCode(a, "h", Blockly.Python.ORDER_ATOMIC);
- return "image.copy(roi\x3d(" + b + ", " + c + ", " + d + ", " + a + "))\n"
- };
|