Blockly.Blocks["iot_lcd_screeninit"] = { init: function () { this.appendDummyInput() .appendField(new Blockly.FieldImage("blockly/media/screen_init_header.png", 45, 45, { alt: "*", flipRtl: "FALSE" })); this.appendDummyInput() .appendField(Blockly.Msg.image_process_lcd_init); this.setInputsInline(false); this.setPreviousStatement(true); this.setNextStatement(true); this.setColour("#5cb2d6"); this.setTooltip(Blockly.Msg.Iot_Lcd_Screeninit_TOOLTIP); this.setHelpUrl(''); } } Blockly.Python.iot_lcd_screeninit = function (block) { var checkbox_name = block.getFieldValue('DEGREE'); //var dropdown_name = block.getFieldValue('TextCheckBox') == 'TRUE' ? "True" : "False"; Blockly.Python.definitions_.import_lcd = "import machine, time"; Blockly.Python.definitions_.import_image = "import st7789"; var _code = "spi = machine.SPI(2, baudrate=20000000, polarity=1, sck=machine.Pin(18), mosi=machine.Pin(23))\n"; _code += "tft = st7789.ST7789(spi, 240, 240, reset=machine.Pin(5, machine.Pin.OUT), dc=machine.Pin(19, machine.Pin.OUT))\n"; _code += "tft.init()\n"; return _code;; } Blockly.Blocks['iot_lcd_screen'] = { init: function () { this.appendDummyInput() .appendField(Blockly.Msg.image_process_set_filled_screen_color) .appendField(new Blockly.FieldDropdown([ [Blockly.Msg.image_process_set_filled_screen_color_black, "BLACK"], [Blockly.Msg.image_process_set_filled_screen_color_red, "RED"], [Blockly.Msg.image_process_set_filled_screen_color_blue, "BLUE"], [Blockly.Msg.image_process_set_filled_screen_color_cyan, "CYAN"], [Blockly.Msg.image_process_set_filled_screen_color_yellow, "YELLOW"], [Blockly.Msg.image_process_set_filled_screen_color_white, "WHITE"] ]), "COLOR"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setColour("#5bb2d6"); // this.setTooltip(''); this.setHelpUrl(''); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('COLOR'); var TOOLTIPS = { 'BLACK': Blockly.Msg.Iot_Lcd_Screen_TOOLTIP.replace('%1', Blockly.Msg.image_process_set_filled_screen_color_black), 'RED': Blockly.Msg.Iot_Lcd_Screen_TOOLTIP.replace('%1', Blockly.Msg.image_process_set_filled_screen_color_red), 'BLUE': Blockly.Msg.Iot_Lcd_Screen_TOOLTIP.replace('%1', Blockly.Msg.image_process_set_filled_screen_color_blue), 'CYAN': Blockly.Msg.Iot_Lcd_Screen_TOOLTIP.replace('%1', Blockly.Msg.image_process_set_filled_screen_color_cyan), 'YELLOW': Blockly.Msg.Iot_Lcd_Screen_TOOLTIP.replace('%1', Blockly.Msg.image_process_set_filled_screen_color_yellow), 'WHITE': Blockly.Msg.Iot_Lcd_Screen_TOOLTIP.replace('%1', Blockly.Msg.image_process_set_filled_screen_color_white) }; return TOOLTIPS[mode]; }); } }; Blockly.Python.iot_lcd_screen = function (block) { var colour_name = block.getFieldValue('COLOR'); var _code = "tft.fill(st7789." + colour_name + ")\n"; return _code; } Blockly.Blocks['iot_lcd_set_color'] = { init: function () { this.appendDummyInput() .appendField(Blockly.Msg.COLOR) .appendField(new Blockly.FieldColour("#ff0000"), "COLOR"); this.setOutput(true, "String"); this.setColour("#5bb2d6"); this.setTooltip(Blockly.Msg.Iot_Lcd_Set_Color_TOOLTIP); this.setHelpUrl(""); } }; Blockly.Python['iot_lcd_set_color'] = function (block) { var color = block.getFieldValue('COLOR'); var d = 0, e = 0, f = 0; try { 7 == color.length && (d = parseInt(color.substring(1, 3), 16), e = parseInt(color.substring(3, 5), 16), f = parseInt(color.substring(5, 7), 16)) } catch (g) { } var code = "st7789.color565(" + d + "," + e + "," + f + ")"; // TODO: Assemble Python into code variable. return [code, Blockly.Python.ORDER_NONE]; }; Blockly.Blocks['iot_lcd_fill_screen_with_rgb'] = { init: function () { this.appendDummyInput() .appendField(Blockly.Msg.image_process_set_filled_screen_color); this.appendValueInput("COLOR") .setCheck(null) .appendField(""); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setColour("#5bb2d6"); this.setTooltip(Blockly.Msg.Iot_Lcd_Fill_Screen_With_Rgb_TOOLTIP); this.setHelpUrl(""); } }; Blockly.Python['iot_lcd_fill_screen_with_rgb'] = function (block) { var color = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC); var code = 'tft.fill' + color + '\n'; // TODO: Assemble Python into code variable. return code; }; Blockly.Blocks['iot_lcd_rgb_value_input'] = { init: function () { this.appendDummyInput() .appendField(Blockly.Msg.image_process_rgb_r); this.appendValueInput("rgb_value_r") .setCheck(null) .appendField(""); this.appendDummyInput() .appendField(Blockly.Msg.image_process_rgb_g); this.appendValueInput("rgb_value_g") .setCheck(null) .appendField(""); this.appendDummyInput() .appendField(Blockly.Msg.image_process_rgb_b); this.appendValueInput("rgb_value_b") .setCheck(null) .appendField(""); this.setInputsInline(true); this.setOutput(true, null); this.setColour("#5bb2d6"); this.setTooltip(Blockly.Msg.Iot_Lcd_Rgb_Value_Input_TOOLTIP); this.setHelpUrl(""); } }; Blockly.Python['iot_lcd_rgb_value_input'] = function (block) { var value_rgb_value_r = Blockly.Python.valueToCode(block, 'rgb_value_r', Blockly.Python.ORDER_ATOMIC); var value_rgb_value_g = Blockly.Python.valueToCode(block, 'rgb_value_g', Blockly.Python.ORDER_ATOMIC); var value_rgb_value_b = Blockly.Python.valueToCode(block, 'rgb_value_b', Blockly.Python.ORDER_ATOMIC); // TODO: Assemble Python into code variable. var code = 'st7789.color565(' + value_rgb_value_r + ',' + value_rgb_value_g + ',' + value_rgb_value_b + ')'; // TODO: Change ORDER_NONE to the correct strength. return [code, Blockly.Python.ORDER_NONE]; }; Blockly.Blocks['iot_lcd_drawpixel'] = { init: function () { this.appendDummyInput() .appendField( new Blockly.FieldImage("./../blockly/media/pixel.png", 25, 25, "15")); this.appendDummyInput() .appendField(Blockly.Msg.LED_DRAW + Blockly.Msg.LED_PIXEL); this.appendValueInput("COLOR") .setCheck("String") .appendField(Blockly.Msg.image_process_text_color); this.appendValueInput("POSA") .setCheck("String") .appendField(Blockly.Msg.image_process_text_start_coord); this.setInputsInline(false); this.setPreviousStatement(true); this.setNextStatement(true); this.setColour("#5bb2d6"); this.setTooltip(Blockly.Msg.Iot_Lcd_Drawpixel_TOOLTIP); this.setHelpUrl(''); } }; Blockly.Python.iot_lcd_drawpixel = function (block) { var color = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC); var xy = Blockly.Python.valueToCode(block, 'POSA', Blockly.Python.ORDER_ATOMIC); var _code = "tft.pixel(" + xy + ", " + color.replace("(", "").replace(")", "") + ")\n"; return _code; } Blockly.Blocks['iot_lcd_linecarvas'] = { init: function () { this.appendDummyInput() .appendField(new Blockly.FieldImage("blockly/media/lcd_draw_line.png", 45, 45, { alt: "*", flipRtl: "FALSE" })); this.appendDummyInput() // .appendField(Blockly.Msg.image_process_text_on_canvas) // .appendField(new Blockly.FieldVariable("canvas"), "varitem") .appendField(Blockly.Msg.image_text_on_draw + Blockly.Msg.image_process_draw_line); this.appendValueInput("POSA") .setCheck("String") .appendField(Blockly.Msg.image_process_text_start_coord); this.appendValueInput("POSB") .setCheck("String") .appendField(Blockly.Msg.image_process_text_end_coord); this.appendValueInput("COLOR") .setCheck("String") .appendField(Blockly.Msg.image_process_text_color); // this.appendValueInput("Scale") // .setCheck("Number") // .appendField(Blockly.Msg.image_process_text_thick); this.setInputsInline(false); this.setPreviousStatement(true); this.setNextStatement(true); this.setColour("#5bb2d6"); this.setTooltip(Blockly.Msg.Iot_Lcd_Linecarvas_TOOLTIP); this.setHelpUrl(''); } }; Blockly.Python.iot_lcd_linecarvas = function (block) { var color = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC); var xy = Blockly.Python.valueToCode(block, 'POSA', Blockly.Python.ORDER_ATOMIC); var xy2 = Blockly.Python.valueToCode(block, 'POSB', Blockly.Python.ORDER_ATOMIC); var _code = "tft.line(" + xy + ", " + xy2 + ", " + color.replace("(", "").replace(")", "") + ")\n"; return _code; } Blockly.Blocks['iot_lcd_ractanglecarvas'] = { init: function () { // this.appendDummyInput() // .appendField( // new Blockly.FieldImage("./../blockly/media/line.png", 25, 25, "15")); this.appendDummyInput() .appendField(new Blockly.FieldImage("blockly/media/lcd_draw_rectangle.png", 45, 45, { alt: "*", flipRtl: "FALSE" })); this.appendDummyInput() // .appendField(Blockly.Msg.image_process_text_on_canvas) // .appendField(new Blockly.FieldVariable("canvas"), "varitem") .appendField(Blockly.Msg.image_text_on_draw) .appendField(new Blockly.FieldDropdown([ [Blockly.Msg.image_process_text_filled, "fill_rect"], [Blockly.Msg.image_process_text_stroked, "rect"] ]), "rect_type") .appendField(Blockly.Msg.image_process_draw_rectangle_text); this.appendValueInput("POSA") .setCheck("String") .appendField(Blockly.Msg.image_process_text_start_coord); this.appendValueInput("POSB") .setCheck("String") .appendField(Blockly.Msg.image_process_text_size); this.appendValueInput("COLOR") .setCheck("String") .appendField(Blockly.Msg.image_process_text_color); // this.appendValueInput("Scale") // .setCheck("Number") // .appendField(Blockly.Msg.image_process_text_thick); this.setInputsInline(false); this.setPreviousStatement(true); this.setNextStatement(true); this.setColour("#5bb2d6"); // this.setTooltip(''); this.setHelpUrl(''); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('rect_type'); var TOOLTIPS = { 'fill_rect': Blockly.Msg.Iot_Lcd_Ractanglecarvas_TOOLTIP.replace('%1', Blockly.Msg.image_process_text_filled), 'rect': Blockly.Msg.Iot_Lcd_Ractanglecarvas_TOOLTIP.replace('%1', Blockly.Msg.image_process_text_stroked) }; return TOOLTIPS[mode]; }); } }; Blockly.Python.iot_lcd_ractanglecarvas = function (block) { var type = block.getFieldValue('rect_type'); var color = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC); var xy = Blockly.Python.valueToCode(block, 'POSA', Blockly.Python.ORDER_ATOMIC); var size = Blockly.Python.valueToCode(block, 'POSB', Blockly.Python.ORDER_ATOMIC); var _code = "tft." + type + "(" + xy + ", " + size + "," + color.replace("(", "").replace(")", "") + ")\n"; return _code; } Blockly.Blocks['iot_lcd_textcarvas'] = { init: function () { this.appendDummyInput() .appendField(new Blockly.FieldImage("blockly/media/lcd_draw_text.png", 45, 45, { alt: "*", flipRtl: "FALSE" })); this.appendDummyInput() // .appendField(Blockly.Msg.image_process_text_on_canvas) // .appendField(new Blockly.FieldVariable("canvas"), "varitem") .appendField(Blockly.Msg.image_text_on_draw + Blockly.Msg.image_process_draw_text); this.appendDummyInput() .appendField(Blockly.Msg.LCD_FONT) .appendField(new Blockly.FieldDropdown([ [Blockly.Msg.SUPER_LARGE, "vga1_16x32"], [Blockly.Msg.LARGE, "vga1_16x16"], [Blockly.Msg.MIDDLE, "vga1_8x16"], [Blockly.Msg.SMALL, "vga1_8x8"], ]), "FONT"); this.appendValueInput("POSA") .setCheck("String") .appendField(Blockly.Msg.image_process_text_start_coord); this.appendValueInput("CONTENT") .setCheck("String") .appendField(Blockly.Msg.image_process_text_content); this.appendValueInput("COLOR") .setCheck("String") .appendField(Blockly.Msg.image_process_text_color); this.appendValueInput("BACKGROUNDCOLOR") .setCheck("String") .appendField(Blockly.Msg.image_process_background_color); // this.appendValueInput("Scale") // .setCheck("Number") // .appendField(Blockly.Msg.image_process_draw_text_font_size); // this.appendDummyInput() // .appendField(Blockly.Msg.image_process_draw_text_if_monospace) // .appendField(new Blockly.FieldCheckbox("FALSE"), "bool"); this.setInputsInline(false); this.setPreviousStatement(true); this.setNextStatement(true); this.setColour("#5bb2d6"); this.setTooltip(Blockly.Msg.Iot_Lcd_Textcarvas_TOOLTIP); this.setHelpUrl(''); } }; Blockly.Python.iot_lcd_textcarvas = function (block) { var fonts = block.getFieldValue('FONT'); var color = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC); var backgroundColor = Blockly.Python.valueToCode(block, 'BACKGROUNDCOLOR', Blockly.Python.ORDER_ATOMIC); var content = Blockly.Python.valueToCode(block, 'CONTENT', Blockly.Python.ORDER_ATOMIC); var xy = Blockly.Python.valueToCode(block, 'POSA', Blockly.Python.ORDER_ATOMIC); // Blockly.Python.definitions_.import_font = "import fonts." + fonts + " as font"; Blockly.Python.definitions_.import_font_set_all = ""+ "import fonts.vga1_8x8 as vga1_8x8\n"+ "import fonts.vga1_8x16 as vga1_8x16\n"+ "import fonts.vga1_16x16 as vga1_16x16\n"+ "import fonts.vga1_16x32 as vga1_16x32\n"+ ""; var _code = "tft.text("+fonts+"," + content + "," + xy + "," + color.replace("(", "").replace(")", "") + "," + backgroundColor.replace("(", "").replace(")", "") + ")\n"; return _code; } Blockly.Blocks['iot_lcd_draw_zedGraph'] = { init: function () { this.appendDummyInput() .appendField(new Blockly.FieldImage("blockly/media/lcd_draw_coordinate.png", 60, 60, { alt: "*", flipRtl: "FALSE" })); this.appendDummyInput() .appendField(Blockly.Msg.image_text_on_draw) .appendField(new Blockly.FieldDropdown([ [Blockly.Msg.image_process_statistical_chart_bar, "bar"], [Blockly.Msg.image_process_statistical_chart_broken_line, "broken_line"] // [Blockly.Msg.image_process_statistical_chart_sector, "sector"] ]), "statistical_chart") .appendField(Blockly.Msg.image_process_draw_statistical_chart); this.appendValueInput("CONTENT") .setCheck("String") .appendField(Blockly.Msg.image_process_statistical_chart_content); this.appendValueInput("PROPERTY") .setCheck("String") .appendField(Blockly.Msg.image_process_statistical_chart_y_property); this.appendDummyInput() .appendField(Blockly.Msg.image_process_sensor) .appendField(new Blockly.FieldDropdown([ [Blockly.Msg.image_process_temperature, "Temperature"], [Blockly.Msg.image_process_humidity, "Humidity"], [Blockly.Msg.image_process_Ray_value, "Ray Value"] ]), "sensor") this.appendDummyInput() .appendField(Blockly.Msg.image_process_temperature_range) .appendField(new Blockly.FieldDropdown([ ['-80~100(' + Blockly.Msg.image_process_temperature + ')', "a"], ['-20~50(' + Blockly.Msg.image_process_temperature + ')', "b"], [Blockly.Msg.image_process_nothing, "c"] ]), "temperature_range") this.setInputsInline(false); this.setPreviousStatement(true); this.setNextStatement(true); this.setColour("#5bb2d6"); var thisBlock = this; this.setTooltip(function () { var mode = thisBlock.getFieldValue('statistical_chart'); var TOOLTIPS = { 'bar': Blockly.Msg.Iot_Lcd_Draw_ZedGraph_TOOLTIP.replace('%1', Blockly.Msg.image_process_statistical_chart_bar), 'broken_line': Blockly.Msg.Iot_Lcd_Draw_ZedGraph_TOOLTIP.replace('%1', Blockly.Msg.image_process_statistical_chart_broken_line), 'sector': Blockly.Msg.Iot_Lcd_Draw_ZedGraph_TOOLTIP.replace('%1', Blockly.Msg.image_process_statistical_chart_sector) }; return TOOLTIPS[mode]; }); this.setHelpUrl(''); } }; Blockly.Python.iot_lcd_draw_zedGraph = function (block) { var a = block.getFieldValue('statistical_chart'); var b = block.getFieldValue('sensor'); var PROPERTY = Blockly.Python.valueToCode(block, 'PROPERTY', Blockly.Python.ORDER_ATOMIC); var content = Blockly.Python.valueToCode(block, 'CONTENT', Blockly.Python.ORDER_ATOMIC); Blockly.Python.definitions_.import_font = "import fonts.vga1_8x8 as font"; Blockly.Python.definitions_.import_math = "import math\ndata_value = [0]"; var _code = ""; if (a == 'bar') { if (b == 'Temperature') { var c = block.getFieldValue('temperature_range'); if (c == "a") { _code = "" + "mapping_value =" + content + "\n" + "\n" + "if(len(data_value) < 17):\n" + " data_value.append(round(mapping_value))\n" + "else:\n" + " data_value.pop(1)\n" + " data_value.append(round(mapping_value))\n" + "\n" + "for j in range(5):\n" + " tft.text(font,str(int((j+1)*100/5)),5,140-20*(j+1),st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + " tft.line(40,140-20*(j+1),45,140-20*(j+1),st7789.color565(255,255,255))\n" + "tft.text(font,'0',5,140,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + "\n" + "for j in range(4):\n" + " tft.text(font,'-'+str(int((j+1)*100/5)),5,140+20*(j+1),st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + " tft.line(40,140+20*(j+1),45,140+20*(j+1),st7789.color565(255,255,255))\n" + "\n" + "for i in range(17):\n" + " if i % 2 == 0:\n" + " if i < 18 and i > 0:\n" + " tft.line(40+(10 * i),140,40+(10 * i),135,st7789.color565(255,255,255))\n" + // " if i != 0:\n" + // " tft.text(font,str(i),40+(10 * i),150,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + "\n" + "for i in range(len(data_value) - 1):\n" + " if data_value[i + 1] >= 0:\n" + " tft.fill_rect(40+(10 * (i + 1))-3,140 - data_value[i + 1], 6,data_value[i + 1],st7789.color565(255,255,255))\n" + " else:\n" + " tft.fill_rect(40+(10 * (i + 1))-3,140, 6,(-1) * data_value[i + 1],st7789.color565(255,255,255))\n" + "\n" + "tft.line(40,20,40,230, st7789.color565(255,255,255))\n" + "tft.line(40,140,220,140, st7789.color565(255,255,255))\n" + "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n"; } else { _code = "" + "mapping_value =" + content + "\n" + "\n" + "if(len(data_value) < 17):\n" + " data_value.append(round(mapping_value))\n" + "else:\n" + " data_value.pop(1)\n" + " data_value.append(round(mapping_value))\n" + "\n" + "for j in range(5):\n" + " tft.text(font,str(int((j+1)*50/5)),5,140-20*(j+1),st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + " tft.line(40,140-20*(j+1),45,140-20*(j+1),st7789.color565(255,255,255))\n" + "tft.text(font,'0',5,140,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + "\n" + "for j in range(2):\n" + " tft.text(font,'-'+str(int((j+1)*50/5)),5,140+20*(j+1),st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + " tft.line(40,140+20*(j+1),45,140+20*(j+1),st7789.color565(255,255,255))\n" + "\n" + "for i in range(17):\n" + " if i % 2 == 0:\n" + " if i < 18 and i > 0:\n" + " tft.line(40+(10 * i),140,40+(10 * i),135,st7789.color565(255,255,255))\n" + // " if i != 0:\n" + // " tft.text(font,str(i),40+(10 * i),150,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + "\n" + "for i in range(len(data_value) - 1):\n" + " if data_value[i + 1] >= 0:\n" + " tft.fill_rect(40+(10 * (i + 1))-3,140 - data_value[i + 1] * 2, 6,data_value[i + 1] * 2,st7789.color565(255,255,255))\n" + " else:\n" + " tft.fill_rect(40+(10 * (i + 1))-3,140, 6,(-1) * data_value[i + 1] * 2,st7789.color565(255,255,255))\n" + "\n" + "tft.line(40,20,40,190, st7789.color565(255,255,255))\n" + "tft.line(40,140,220,140, st7789.color565(255,255,255))\n" + "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n"; } } else if (b == 'Humidity') { _code = "" + "mapping_value =" + content + "\n" + "\n" + "if(len(data_value) < 17):\n" + " data_value.append(round(mapping_value))\n" + "else:\n" + " data_value.pop(1)\n" + " data_value.append(round(mapping_value))\n" + "\n" + "for j in range(5):\n" + " tft.text(font,str(int((j+1)*180/5)),5,220-36*(j+1),st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + " tft.line(40,220-36*(j+1),45,220-36*(j+1),st7789.color565(255,255,255))\n" + "\n" + "for i in range(17):\n" + " if i % 2 == 0:\n" + " if i < 18 and i > 0:\n" + " tft.line(40+(10 * i),220,40+(10 * i),215,st7789.color565(255,255,255))\n" + " tft.text(font,str(i),40+(10 * i),230,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + "\n" + "for i in range(len(data_value) - 1):\n" + // " tft.line(40+(10 * i),220 - data_value[i],40+(10 * (i + 1)),220 - data_value[i + 1], st7789.color565(0,255,255))\n" + " tft.fill_rect(40+(10 * (i + 1))-3,220 - data_value[i + 1], 6,data_value[i + 1],st7789.color565(255,255,255))\n" + "\n" + "tft.line(40,20,40,220, st7789.color565(255,255,255))\n" + "tft.line(40,220,220,220, st7789.color565(255,255,255))\n" + "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n"; } else { _code = "" + "mapping_value =" + content + "\n" + "\n" + "if(len(data_value) < 17):\n" + " data_value.append(round(mapping_value))\n" + "else:\n" + " data_value.pop(1)\n" + " data_value.append(round(mapping_value))\n" + "\n" + "for j in range(5):\n" + " tft.text(font,str(int((j+1)*1080/5)),5,220-36*(j+1),st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + " tft.line(40,220-36*(j+1),45,220-36*(j+1),st7789.color565(255,255,255))\n" + "\n" + "for i in range(17):\n" + " if i % 2 == 0:\n" + " if i < 18 and i > 0:\n" + " tft.line(40+(10 * i),220,40+(10 * i),215,st7789.color565(255,255,255))\n" + " tft.text(font,str(i),40+(10 * i),230,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + "\n" + "for i in range(len(data_value) - 1):\n" + // " tft.line(40+(10 * i),220 - data_value[i] // 6,40+(10 * (i + 1)),220 - data_value[i + 1] // 6, st7789.color565(0,255,255))\n" + " tft.fill_rect(40+(10 * (i + 1))-3,220 - data_value[i + 1] // 6, 6,data_value[i + 1] // 6,st7789.color565(255,255,255))\n" + "\n" + "tft.line(40,20,40,220, st7789.color565(255,255,255))\n" + "tft.line(40,220,220,220, st7789.color565(255,255,255))\n" + "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n"; } } else if (a == 'broken_line') { if (b == 'Temperature') { var c = block.getFieldValue('temperature_range'); if (c == "a") { _code = "" + "mapping_value =" + content + "\n" + "\n" + "if(len(data_value) < 17):\n" + " data_value.append(round(mapping_value))\n" + "else:\n" + " data_value.pop(1)\n" + " data_value.append(round(mapping_value))\n" + "\n" + "for j in range(5):\n" + " tft.text(font,str(int((j+1)*100/5)),5,140-20*(j+1),st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + " tft.line(40,140-20*(j+1),45,140-20*(j+1),st7789.color565(255,255,255))\n" + "tft.text(font,'0',5,140,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + "\n" + "for j in range(4):\n" + " tft.text(font,'-'+str(int((j+1)*100/5)),5,140+20*(j+1),st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + " tft.line(40,140+20*(j+1),45,140+20*(j+1),st7789.color565(255,255,255))\n" + "\n" + "for i in range(17):\n" + " if i % 2 == 0:\n" + " if i < 18 and i > 0:\n" + " tft.line(40+(10 * i),140,40+(10 * i),135,st7789.color565(255,255,255))\n" + " if i != 0:\n" + " tft.text(font,str(i),40+(10 * i),150,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + "\n" + "for i in range(len(data_value) - 1):\n" + " tft.line(40+(10 * i),140 - data_value[i],40+(10 * (i + 1)),140 - data_value[i + 1], st7789.color565(0,255,255))\n" + "\n" + "tft.line(40,20,40,230, st7789.color565(255,255,255))\n" + "tft.line(40,140,220,140, st7789.color565(255,255,255))\n" + "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n"; } else { _code = "" + "mapping_value =" + content + "\n" + "\n" + "if(len(data_value) < 17):\n" + " data_value.append(round(mapping_value))\n" + "else:\n" + " data_value.pop(1)\n" + " data_value.append(round(mapping_value))\n" + "\n" + "for j in range(5):\n" + " tft.text(font,str(int((j+1)*50/5)),5,140-20*(j+1),st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + " tft.line(40,140-20*(j+1),45,140-20*(j+1),st7789.color565(255,255,255))\n" + "tft.text(font,'0',5,140,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + "\n" + "for j in range(2):\n" + " tft.text(font,'-'+str(int((j+1)*50/5)),5,140+20*(j+1),st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + " tft.line(40,140+20*(j+1),45,140+20*(j+1),st7789.color565(255,255,255))\n" + "\n" + "for i in range(17):\n" + " if i % 2 == 0:\n" + " if i < 18 and i > 0:\n" + " tft.line(40+(10 * i),140,40+(10 * i),135,st7789.color565(255,255,255))\n" + " if i != 0:\n" + " tft.text(font,str(i),40+(10 * i),150,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + "\n" + "for i in range(len(data_value) - 1):\n" + " tft.line(40+(10 * i),140 - data_value[i] * 2,40+(10 * (i + 1)),140 - data_value[i + 1] * 2, st7789.color565(0,255,255))\n" + "\n" + "tft.line(40,20,40,190, st7789.color565(255,255,255))\n" + "tft.line(40,140,220,140, st7789.color565(255,255,255))\n" + "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n"; } } else if (b == 'Humidity') { _code = "" + "mapping_value =" + content + "\n" + "\n" + "if(len(data_value) < 17):\n" + " data_value.append(round(mapping_value))\n" + "else:\n" + " data_value.pop(1)\n" + " data_value.append(round(mapping_value))\n" + "\n" + "for j in range(5):\n" + " tft.text(font,str(int((j+1)*180/5)),5,220-36*(j+1),st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + " tft.line(40,220-36*(j+1),45,220-36*(j+1),st7789.color565(255,255,255))\n" + "\n" + "for i in range(17):\n" + " if i % 2 == 0:\n" + " if i < 18 and i > 0:\n" + " tft.line(40+(10 * i),220,40+(10 * i),215,st7789.color565(255,255,255))\n" + " tft.text(font,str(i),40+(10 * i),230,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + "\n" + "for i in range(len(data_value) - 1):\n" + " tft.line(40+(10 * i),220 - data_value[i],40+(10 * (i + 1)),220 - data_value[i + 1], st7789.color565(0,255,255))\n" + "\n" + "tft.line(40,20,40,220, st7789.color565(255,255,255))\n" + "tft.line(40,220,220,220, st7789.color565(255,255,255))\n" + "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n"; } else { _code = "" + "mapping_value =" + content + "\n" + "\n" + "if(len(data_value) < 17):\n" + " data_value.append(round(mapping_value))\n" + "else:\n" + " data_value.pop(1)\n" + " data_value.append(round(mapping_value))\n" + "\n" + "for j in range(5):\n" + " tft.text(font,str(int((j+1)*1080/5)),5,220-36*(j+1),st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + " tft.line(40,220-36*(j+1),45,220-36*(j+1),st7789.color565(255,255,255))\n" + "\n" + "for i in range(17):\n" + " if i % 2 == 0:\n" + " if i < 18 and i > 0:\n" + " tft.line(40+(10 * i),220,40+(10 * i),215,st7789.color565(255,255,255))\n" + " tft.text(font,str(i),40+(10 * i),230,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" + "\n" + "for i in range(len(data_value) - 1):\n" + " tft.line(40+(10 * i),220 - data_value[i] // 6,40+(10 * (i + 1)),220 - data_value[i + 1] // 6, st7789.color565(0,255,255))\n" + "\n" + "tft.line(40,20,40,220, st7789.color565(255,255,255))\n" + "tft.line(40,220,220,220, st7789.color565(255,255,255))\n" + "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n"; } } else { if (b == 'Temperature') { } else if (b == 'Humidity') { } else { } } return _code; } Blockly.Blocks['iot_lcd_clear_screen'] = { init: function () { this.appendDummyInput() .appendField(Blockly.Msg.image_process_clear_lcd); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setColour("#5bb2d6"); // this.setTooltip(''); this.setHelpUrl(''); this.setTooltip(Blockly.Msg.iot_lcd_clear_screen_TOOLTIP); } }; Blockly.Python.iot_lcd_clear_screen = function (block) { var _code = "tft.fill(st7789.BLACK)\n"; return _code; };