iot.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. Blockly.Blocks["iot_lcd_screeninit"] = {
  2. init: function () {
  3. this.appendDummyInput()
  4. .appendField(new Blockly.FieldImage("blockly/media/screen_init_header.png", 45, 45, { alt: "*", flipRtl: "FALSE" }));
  5. this.appendDummyInput()
  6. .appendField(Blockly.Msg.image_process_lcd_init);
  7. this.setInputsInline(false);
  8. this.setPreviousStatement(true);
  9. this.setNextStatement(true);
  10. this.setColour("#5cb2d6");
  11. this.setTooltip(Blockly.Msg.Iot_Lcd_Screeninit_TOOLTIP);
  12. this.setHelpUrl('');
  13. }
  14. }
  15. Blockly.Python.iot_lcd_screeninit = function (block) {
  16. var checkbox_name = block.getFieldValue('DEGREE');
  17. //var dropdown_name = block.getFieldValue('TextCheckBox') == 'TRUE' ? "True" : "False";
  18. Blockly.Python.definitions_.import_lcd = "import machine, time";
  19. Blockly.Python.definitions_.import_image = "import st7789";
  20. var _code = "spi = machine.SPI(2, baudrate=20000000, polarity=1, sck=machine.Pin(18), mosi=machine.Pin(23))\n";
  21. _code += "tft = st7789.ST7789(spi, 240, 240, reset=machine.Pin(5, machine.Pin.OUT), dc=machine.Pin(19, machine.Pin.OUT))\n";
  22. _code += "tft.init()\n";
  23. return _code;;
  24. }
  25. Blockly.Blocks['iot_lcd_screen'] = {
  26. init: function () {
  27. this.appendDummyInput()
  28. .appendField(Blockly.Msg.image_process_set_filled_screen_color)
  29. .appendField(new Blockly.FieldDropdown([
  30. [Blockly.Msg.image_process_set_filled_screen_color_black, "BLACK"],
  31. [Blockly.Msg.image_process_set_filled_screen_color_red, "RED"],
  32. [Blockly.Msg.image_process_set_filled_screen_color_blue, "BLUE"],
  33. [Blockly.Msg.image_process_set_filled_screen_color_cyan, "CYAN"],
  34. [Blockly.Msg.image_process_set_filled_screen_color_yellow, "YELLOW"],
  35. [Blockly.Msg.image_process_set_filled_screen_color_white, "WHITE"]
  36. ]), "COLOR");
  37. this.setInputsInline(true);
  38. this.setPreviousStatement(true, null);
  39. this.setNextStatement(true, null);
  40. this.setColour("#5bb2d6");
  41. // this.setTooltip('');
  42. this.setHelpUrl('');
  43. var thisBlock = this;
  44. this.setTooltip(function () {
  45. var mode = thisBlock.getFieldValue('COLOR');
  46. var TOOLTIPS = {
  47. 'BLACK': Blockly.Msg.Iot_Lcd_Screen_TOOLTIP.replace('%1', Blockly.Msg.image_process_set_filled_screen_color_black),
  48. 'RED': Blockly.Msg.Iot_Lcd_Screen_TOOLTIP.replace('%1', Blockly.Msg.image_process_set_filled_screen_color_red),
  49. 'BLUE': Blockly.Msg.Iot_Lcd_Screen_TOOLTIP.replace('%1', Blockly.Msg.image_process_set_filled_screen_color_blue),
  50. 'CYAN': Blockly.Msg.Iot_Lcd_Screen_TOOLTIP.replace('%1', Blockly.Msg.image_process_set_filled_screen_color_cyan),
  51. 'YELLOW': Blockly.Msg.Iot_Lcd_Screen_TOOLTIP.replace('%1', Blockly.Msg.image_process_set_filled_screen_color_yellow),
  52. 'WHITE': Blockly.Msg.Iot_Lcd_Screen_TOOLTIP.replace('%1', Blockly.Msg.image_process_set_filled_screen_color_white)
  53. };
  54. return TOOLTIPS[mode];
  55. });
  56. }
  57. };
  58. Blockly.Python.iot_lcd_screen = function (block) {
  59. var colour_name = block.getFieldValue('COLOR');
  60. var _code = "tft.fill(st7789." + colour_name + ")\n";
  61. return _code;
  62. }
  63. Blockly.Blocks['iot_lcd_set_color'] = {
  64. init: function () {
  65. this.appendDummyInput()
  66. .appendField(Blockly.Msg.COLOR)
  67. .appendField(new Blockly.FieldColour("#ff0000"), "COLOR");
  68. this.setOutput(true, "String");
  69. this.setColour("#5bb2d6");
  70. this.setTooltip(Blockly.Msg.Iot_Lcd_Set_Color_TOOLTIP);
  71. this.setHelpUrl("");
  72. }
  73. };
  74. Blockly.Python['iot_lcd_set_color'] = function (block) {
  75. var color = block.getFieldValue('COLOR');
  76. var d = 0,
  77. e = 0,
  78. f = 0;
  79. try {
  80. 7 == color.length && (d = parseInt(color.substring(1, 3), 16),
  81. e = parseInt(color.substring(3, 5), 16),
  82. f = parseInt(color.substring(5, 7), 16))
  83. } catch (g) { }
  84. var code = "st7789.color565(" + d + "," + e + "," + f + ")";
  85. // TODO: Assemble Python into code variable.
  86. return [code, Blockly.Python.ORDER_NONE];
  87. };
  88. Blockly.Blocks['iot_lcd_fill_screen_with_rgb'] = {
  89. init: function () {
  90. this.appendDummyInput()
  91. .appendField(Blockly.Msg.image_process_set_filled_screen_color);
  92. this.appendValueInput("COLOR")
  93. .setCheck(null)
  94. .appendField("");
  95. this.setInputsInline(true);
  96. this.setPreviousStatement(true, null);
  97. this.setNextStatement(true, null);
  98. this.setColour("#5bb2d6");
  99. this.setTooltip(Blockly.Msg.Iot_Lcd_Fill_Screen_With_Rgb_TOOLTIP);
  100. this.setHelpUrl("");
  101. }
  102. };
  103. Blockly.Python['iot_lcd_fill_screen_with_rgb'] = function (block) {
  104. var color = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC);
  105. var code = 'tft.fill' + color + '\n';
  106. // TODO: Assemble Python into code variable.
  107. return code;
  108. };
  109. Blockly.Blocks['iot_lcd_rgb_value_input'] = {
  110. init: function () {
  111. this.appendDummyInput()
  112. .appendField(Blockly.Msg.image_process_rgb_r);
  113. this.appendValueInput("rgb_value_r")
  114. .setCheck(null)
  115. .appendField("");
  116. this.appendDummyInput()
  117. .appendField(Blockly.Msg.image_process_rgb_g);
  118. this.appendValueInput("rgb_value_g")
  119. .setCheck(null)
  120. .appendField("");
  121. this.appendDummyInput()
  122. .appendField(Blockly.Msg.image_process_rgb_b);
  123. this.appendValueInput("rgb_value_b")
  124. .setCheck(null)
  125. .appendField("");
  126. this.setInputsInline(true);
  127. this.setOutput(true, null);
  128. this.setColour("#5bb2d6");
  129. this.setTooltip(Blockly.Msg.Iot_Lcd_Rgb_Value_Input_TOOLTIP);
  130. this.setHelpUrl("");
  131. }
  132. };
  133. Blockly.Python['iot_lcd_rgb_value_input'] = function (block) {
  134. var value_rgb_value_r = Blockly.Python.valueToCode(block, 'rgb_value_r', Blockly.Python.ORDER_ATOMIC);
  135. var value_rgb_value_g = Blockly.Python.valueToCode(block, 'rgb_value_g', Blockly.Python.ORDER_ATOMIC);
  136. var value_rgb_value_b = Blockly.Python.valueToCode(block, 'rgb_value_b', Blockly.Python.ORDER_ATOMIC);
  137. // TODO: Assemble Python into code variable.
  138. var code = 'st7789.color565(' + value_rgb_value_r + ',' + value_rgb_value_g + ',' + value_rgb_value_b + ')';
  139. // TODO: Change ORDER_NONE to the correct strength.
  140. return [code, Blockly.Python.ORDER_NONE];
  141. };
  142. Blockly.Blocks['iot_lcd_drawpixel'] = {
  143. init: function () {
  144. this.appendDummyInput()
  145. .appendField(
  146. new Blockly.FieldImage("./blockly/media/pixel.png", 25, 25, "15"));
  147. this.appendDummyInput()
  148. .appendField(Blockly.Msg.LED_DRAW + Blockly.Msg.LED_PIXEL);
  149. this.appendValueInput("COLOR")
  150. .setCheck("String")
  151. .appendField(Blockly.Msg.image_process_text_color);
  152. this.appendValueInput("POSA")
  153. .setCheck("String")
  154. .appendField(Blockly.Msg.image_process_text_start_coord);
  155. this.setInputsInline(false);
  156. this.setPreviousStatement(true);
  157. this.setNextStatement(true);
  158. this.setColour("#5bb2d6");
  159. this.setTooltip(Blockly.Msg.Iot_Lcd_Drawpixel_TOOLTIP);
  160. this.setHelpUrl('');
  161. }
  162. };
  163. Blockly.Python.iot_lcd_drawpixel = function (block) {
  164. var color = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC);
  165. var xy = Blockly.Python.valueToCode(block, 'POSA', Blockly.Python.ORDER_ATOMIC);
  166. var _code = "tft.pixel(" + xy + ", " + color.replace("(", "").replace(")", "") + ")\n";
  167. return _code;
  168. }
  169. Blockly.Blocks['iot_lcd_linecarvas'] = {
  170. init: function () {
  171. this.appendDummyInput()
  172. .appendField(new Blockly.FieldImage("blockly/media/lcd_draw_line.png", 45, 45, { alt: "*", flipRtl: "FALSE" }));
  173. this.appendDummyInput()
  174. // .appendField(Blockly.Msg.image_process_text_on_canvas)
  175. // .appendField(new Blockly.FieldVariable("canvas"), "varitem")
  176. .appendField(Blockly.Msg.image_text_on_draw + Blockly.Msg.image_process_draw_line);
  177. this.appendValueInput("POSA")
  178. .setCheck("String")
  179. .appendField(Blockly.Msg.image_process_text_start_coord);
  180. this.appendValueInput("POSB")
  181. .setCheck("String")
  182. .appendField(Blockly.Msg.image_process_text_end_coord);
  183. this.appendValueInput("COLOR")
  184. .setCheck("String")
  185. .appendField(Blockly.Msg.image_process_text_color);
  186. // this.appendValueInput("Scale")
  187. // .setCheck("Number")
  188. // .appendField(Blockly.Msg.image_process_text_thick);
  189. this.setInputsInline(false);
  190. this.setPreviousStatement(true);
  191. this.setNextStatement(true);
  192. this.setColour("#5bb2d6");
  193. this.setTooltip(Blockly.Msg.Iot_Lcd_Linecarvas_TOOLTIP);
  194. this.setHelpUrl('');
  195. }
  196. };
  197. Blockly.Python.iot_lcd_linecarvas = function (block) {
  198. var color = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC);
  199. var xy = Blockly.Python.valueToCode(block, 'POSA', Blockly.Python.ORDER_ATOMIC);
  200. var xy2 = Blockly.Python.valueToCode(block, 'POSB', Blockly.Python.ORDER_ATOMIC);
  201. var _code = "tft.line(" + xy + ", " + xy2 + ", " + color.replace("(", "").replace(")", "") + ")\n";
  202. return _code;
  203. }
  204. Blockly.Blocks['iot_lcd_ractanglecarvas'] = {
  205. init: function () {
  206. // this.appendDummyInput()
  207. // .appendField(
  208. // new Blockly.FieldImage("./../blockly/media/line.png", 25, 25, "15"));
  209. this.appendDummyInput()
  210. .appendField(new Blockly.FieldImage("blockly/media/lcd_draw_rectangle.png", 45, 45, { alt: "*", flipRtl: "FALSE" }));
  211. this.appendDummyInput()
  212. // .appendField(Blockly.Msg.image_process_text_on_canvas)
  213. // .appendField(new Blockly.FieldVariable("canvas"), "varitem")
  214. .appendField(Blockly.Msg.image_text_on_draw)
  215. .appendField(new Blockly.FieldDropdown([
  216. [Blockly.Msg.image_process_text_filled, "fill_rect"],
  217. [Blockly.Msg.image_process_text_stroked, "rect"]
  218. ]), "rect_type")
  219. .appendField(Blockly.Msg.image_process_draw_rectangle_text);
  220. this.appendValueInput("POSA")
  221. .setCheck("String")
  222. .appendField(Blockly.Msg.image_process_text_start_coord);
  223. this.appendValueInput("POSB")
  224. .setCheck("String")
  225. .appendField(Blockly.Msg.image_process_text_size);
  226. this.appendValueInput("COLOR")
  227. .setCheck("String")
  228. .appendField(Blockly.Msg.image_process_text_color);
  229. // this.appendValueInput("Scale")
  230. // .setCheck("Number")
  231. // .appendField(Blockly.Msg.image_process_text_thick);
  232. this.setInputsInline(false);
  233. this.setPreviousStatement(true);
  234. this.setNextStatement(true);
  235. this.setColour("#5bb2d6");
  236. // this.setTooltip('');
  237. this.setHelpUrl('');
  238. var thisBlock = this;
  239. this.setTooltip(function () {
  240. var mode = thisBlock.getFieldValue('rect_type');
  241. var TOOLTIPS = {
  242. 'fill_rect': Blockly.Msg.Iot_Lcd_Ractanglecarvas_TOOLTIP.replace('%1', Blockly.Msg.image_process_text_filled),
  243. 'rect': Blockly.Msg.Iot_Lcd_Ractanglecarvas_TOOLTIP.replace('%1', Blockly.Msg.image_process_text_stroked)
  244. };
  245. return TOOLTIPS[mode];
  246. });
  247. }
  248. };
  249. Blockly.Python.iot_lcd_ractanglecarvas = function (block) {
  250. var type = block.getFieldValue('rect_type');
  251. var color = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC);
  252. var xy = Blockly.Python.valueToCode(block, 'POSA', Blockly.Python.ORDER_ATOMIC);
  253. var size = Blockly.Python.valueToCode(block, 'POSB', Blockly.Python.ORDER_ATOMIC);
  254. var _code = "tft." + type + "(" + xy + ", " + size + "," + color.replace("(", "").replace(")", "") + ")\n";
  255. return _code;
  256. }
  257. Blockly.Blocks['iot_lcd_textcarvas'] = {
  258. init: function () {
  259. this.appendDummyInput()
  260. .appendField(new Blockly.FieldImage("blockly/media/lcd_draw_text.png", 45, 45, { alt: "*", flipRtl: "FALSE" }));
  261. this.appendDummyInput()
  262. // .appendField(Blockly.Msg.image_process_text_on_canvas)
  263. // .appendField(new Blockly.FieldVariable("canvas"), "varitem")
  264. .appendField(Blockly.Msg.image_text_on_draw + Blockly.Msg.image_process_draw_text);
  265. this.appendDummyInput()
  266. .appendField(Blockly.Msg.LCD_FONT)
  267. .appendField(new Blockly.FieldDropdown([
  268. [Blockly.Msg.SUPER_LARGE, "vga1_16x32"],
  269. [Blockly.Msg.LARGE, "vga1_16x16"],
  270. [Blockly.Msg.MIDDLE, "vga1_8x16"],
  271. [Blockly.Msg.SMALL, "vga1_8x8"],
  272. ]), "FONT");
  273. this.appendValueInput("POSA")
  274. .setCheck("String")
  275. .appendField(Blockly.Msg.image_process_text_start_coord);
  276. this.appendValueInput("CONTENT")
  277. .setCheck("String")
  278. .appendField(Blockly.Msg.image_process_text_content);
  279. this.appendValueInput("COLOR")
  280. .setCheck("String")
  281. .appendField(Blockly.Msg.image_process_text_color);
  282. this.appendValueInput("BACKGROUNDCOLOR")
  283. .setCheck("String")
  284. .appendField(Blockly.Msg.image_process_background_color);
  285. // this.appendValueInput("Scale")
  286. // .setCheck("Number")
  287. // .appendField(Blockly.Msg.image_process_draw_text_font_size);
  288. // this.appendDummyInput()
  289. // .appendField(Blockly.Msg.image_process_draw_text_if_monospace)
  290. // .appendField(new Blockly.FieldCheckbox("FALSE"), "bool");
  291. this.setInputsInline(false);
  292. this.setPreviousStatement(true);
  293. this.setNextStatement(true);
  294. this.setColour("#5bb2d6");
  295. this.setTooltip(Blockly.Msg.Iot_Lcd_Textcarvas_TOOLTIP);
  296. this.setHelpUrl('');
  297. }
  298. };
  299. Blockly.Python.iot_lcd_textcarvas = function (block) {
  300. var fonts = block.getFieldValue('FONT');
  301. var color = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC);
  302. var backgroundColor = Blockly.Python.valueToCode(block, 'BACKGROUNDCOLOR', Blockly.Python.ORDER_ATOMIC);
  303. var content = Blockly.Python.valueToCode(block, 'CONTENT', Blockly.Python.ORDER_ATOMIC);
  304. var xy = Blockly.Python.valueToCode(block, 'POSA', Blockly.Python.ORDER_ATOMIC);
  305. // Blockly.Python.definitions_.import_font = "import fonts." + fonts + " as font";
  306. Blockly.Python.definitions_.import_font_set_all = ""+
  307. "import fonts.vga1_8x8 as vga1_8x8\n"+
  308. "import fonts.vga1_8x16 as vga1_8x16\n"+
  309. "import fonts.vga1_16x16 as vga1_16x16\n"+
  310. "import fonts.vga1_16x32 as vga1_16x32\n"+
  311. "";
  312. var _code = "tft.text("+fonts+"," + content + "," + xy + "," + color.replace("(", "").replace(")", "") + "," + backgroundColor.replace("(", "").replace(")", "") + ")\n";
  313. return _code;
  314. }
  315. Blockly.Blocks['iot_lcd_draw_zedGraph'] = {
  316. init: function () {
  317. this.appendDummyInput()
  318. .appendField(new Blockly.FieldImage("blockly/media/lcd_draw_coordinate.png", 60, 60, { alt: "*", flipRtl: "FALSE" }));
  319. this.appendDummyInput()
  320. .appendField(Blockly.Msg.image_text_on_draw)
  321. .appendField(new Blockly.FieldDropdown([
  322. [Blockly.Msg.image_process_statistical_chart_bar, "bar"],
  323. [Blockly.Msg.image_process_statistical_chart_broken_line, "broken_line"]
  324. // [Blockly.Msg.image_process_statistical_chart_sector, "sector"]
  325. ]), "statistical_chart")
  326. .appendField(Blockly.Msg.image_process_draw_statistical_chart);
  327. this.appendValueInput("CONTENT")
  328. .setCheck("String")
  329. .appendField(Blockly.Msg.image_process_statistical_chart_content);
  330. this.appendValueInput("PROPERTY")
  331. .setCheck("String")
  332. .appendField(Blockly.Msg.image_process_statistical_chart_y_property);
  333. this.appendDummyInput()
  334. .appendField(Blockly.Msg.image_process_sensor)
  335. .appendField(new Blockly.FieldDropdown([
  336. [Blockly.Msg.image_process_temperature, "Temperature"],
  337. [Blockly.Msg.image_process_humidity, "Humidity"],
  338. [Blockly.Msg.image_process_Ray_value, "Ray Value"]
  339. ]), "sensor")
  340. this.appendDummyInput()
  341. .appendField(Blockly.Msg.image_process_temperature_range)
  342. .appendField(new Blockly.FieldDropdown([
  343. ['-80~100(' + Blockly.Msg.image_process_temperature + ')', "a"],
  344. ['-20~50(' + Blockly.Msg.image_process_temperature + ')', "b"],
  345. [Blockly.Msg.image_process_nothing, "c"]
  346. ]), "temperature_range")
  347. this.setInputsInline(false);
  348. this.setPreviousStatement(true);
  349. this.setNextStatement(true);
  350. this.setColour("#5bb2d6");
  351. var thisBlock = this;
  352. this.setTooltip(function () {
  353. var mode = thisBlock.getFieldValue('statistical_chart');
  354. var TOOLTIPS = {
  355. 'bar': Blockly.Msg.Iot_Lcd_Draw_ZedGraph_TOOLTIP.replace('%1', Blockly.Msg.image_process_statistical_chart_bar),
  356. 'broken_line': Blockly.Msg.Iot_Lcd_Draw_ZedGraph_TOOLTIP.replace('%1', Blockly.Msg.image_process_statistical_chart_broken_line),
  357. 'sector': Blockly.Msg.Iot_Lcd_Draw_ZedGraph_TOOLTIP.replace('%1', Blockly.Msg.image_process_statistical_chart_sector)
  358. };
  359. return TOOLTIPS[mode];
  360. });
  361. this.setHelpUrl('');
  362. }
  363. };
  364. Blockly.Python.iot_lcd_draw_zedGraph = function (block) {
  365. var a = block.getFieldValue('statistical_chart');
  366. var b = block.getFieldValue('sensor');
  367. var PROPERTY = Blockly.Python.valueToCode(block, 'PROPERTY', Blockly.Python.ORDER_ATOMIC);
  368. var content = Blockly.Python.valueToCode(block, 'CONTENT', Blockly.Python.ORDER_ATOMIC);
  369. Blockly.Python.definitions_.import_font = "import fonts.vga1_8x8 as font";
  370. Blockly.Python.definitions_.import_math = "import math\ndata_value = [0]";
  371. var _code = "";
  372. if (a == 'bar') {
  373. if (b == 'Temperature') {
  374. var c = block.getFieldValue('temperature_range');
  375. if (c == "a") {
  376. _code = "" +
  377. "mapping_value =" + content + "\n" +
  378. "\n" +
  379. "if(len(data_value) < 17):\n" +
  380. " data_value.append(round(mapping_value))\n" +
  381. "else:\n" +
  382. " data_value.pop(1)\n" +
  383. " data_value.append(round(mapping_value))\n" +
  384. "\n" +
  385. "for j in range(5):\n" +
  386. " 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" +
  387. " tft.line(40,140-20*(j+1),45,140-20*(j+1),st7789.color565(255,255,255))\n" +
  388. "tft.text(font,'0',5,140,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" +
  389. "\n" +
  390. "for j in range(4):\n" +
  391. " 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" +
  392. " tft.line(40,140+20*(j+1),45,140+20*(j+1),st7789.color565(255,255,255))\n" +
  393. "\n" +
  394. "for i in range(17):\n" +
  395. " if i % 2 == 0:\n" +
  396. " if i < 18 and i > 0:\n" +
  397. " tft.line(40+(10 * i),140,40+(10 * i),135,st7789.color565(255,255,255))\n" +
  398. // " if i != 0:\n" +
  399. // " tft.text(font,str(i),40+(10 * i),150,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" +
  400. "\n" +
  401. "for i in range(len(data_value) - 1):\n" +
  402. " if data_value[i + 1] >= 0:\n" +
  403. " tft.fill_rect(40+(10 * (i + 1))-3,140 - data_value[i + 1], 6,data_value[i + 1],st7789.color565(255,255,255))\n" +
  404. " else:\n" +
  405. " tft.fill_rect(40+(10 * (i + 1))-3,140, 6,(-1) * data_value[i + 1],st7789.color565(255,255,255))\n" +
  406. "\n" +
  407. "tft.line(40,20,40,230, st7789.color565(255,255,255))\n" +
  408. "tft.line(40,140,220,140, st7789.color565(255,255,255))\n" +
  409. "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n";
  410. }
  411. else {
  412. _code = "" +
  413. "mapping_value =" + content + "\n" +
  414. "\n" +
  415. "if(len(data_value) < 17):\n" +
  416. " data_value.append(round(mapping_value))\n" +
  417. "else:\n" +
  418. " data_value.pop(1)\n" +
  419. " data_value.append(round(mapping_value))\n" +
  420. "\n" +
  421. "for j in range(5):\n" +
  422. " 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" +
  423. " tft.line(40,140-20*(j+1),45,140-20*(j+1),st7789.color565(255,255,255))\n" +
  424. "tft.text(font,'0',5,140,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" +
  425. "\n" +
  426. "for j in range(2):\n" +
  427. " 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" +
  428. " tft.line(40,140+20*(j+1),45,140+20*(j+1),st7789.color565(255,255,255))\n" +
  429. "\n" +
  430. "for i in range(17):\n" +
  431. " if i % 2 == 0:\n" +
  432. " if i < 18 and i > 0:\n" +
  433. " tft.line(40+(10 * i),140,40+(10 * i),135,st7789.color565(255,255,255))\n" +
  434. // " if i != 0:\n" +
  435. // " tft.text(font,str(i),40+(10 * i),150,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" +
  436. "\n" +
  437. "for i in range(len(data_value) - 1):\n" +
  438. " if data_value[i + 1] >= 0:\n" +
  439. " 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" +
  440. " else:\n" +
  441. " tft.fill_rect(40+(10 * (i + 1))-3,140, 6,(-1) * data_value[i + 1] * 2,st7789.color565(255,255,255))\n" +
  442. "\n" +
  443. "tft.line(40,20,40,190, st7789.color565(255,255,255))\n" +
  444. "tft.line(40,140,220,140, st7789.color565(255,255,255))\n" +
  445. "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n";
  446. }
  447. }
  448. else if (b == 'Humidity') {
  449. _code = "" +
  450. "mapping_value =" + content + "\n" +
  451. "\n" +
  452. "if(len(data_value) < 17):\n" +
  453. " data_value.append(round(mapping_value))\n" +
  454. "else:\n" +
  455. " data_value.pop(1)\n" +
  456. " data_value.append(round(mapping_value))\n" +
  457. "\n" +
  458. "for j in range(5):\n" +
  459. " 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" +
  460. " tft.line(40,220-36*(j+1),45,220-36*(j+1),st7789.color565(255,255,255))\n" +
  461. "\n" +
  462. "for i in range(17):\n" +
  463. " if i % 2 == 0:\n" +
  464. " if i < 18 and i > 0:\n" +
  465. " tft.line(40+(10 * i),220,40+(10 * i),215,st7789.color565(255,255,255))\n" +
  466. " tft.text(font,str(i),40+(10 * i),230,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" +
  467. "\n" +
  468. "for i in range(len(data_value) - 1):\n" +
  469. // " tft.line(40+(10 * i),220 - data_value[i],40+(10 * (i + 1)),220 - data_value[i + 1], st7789.color565(0,255,255))\n" +
  470. " tft.fill_rect(40+(10 * (i + 1))-3,220 - data_value[i + 1], 6,data_value[i + 1],st7789.color565(255,255,255))\n" +
  471. "\n" +
  472. "tft.line(40,20,40,220, st7789.color565(255,255,255))\n" +
  473. "tft.line(40,220,220,220, st7789.color565(255,255,255))\n" +
  474. "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n";
  475. }
  476. else {
  477. _code = "" +
  478. "mapping_value =" + content + "\n" +
  479. "\n" +
  480. "if(len(data_value) < 17):\n" +
  481. " data_value.append(round(mapping_value))\n" +
  482. "else:\n" +
  483. " data_value.pop(1)\n" +
  484. " data_value.append(round(mapping_value))\n" +
  485. "\n" +
  486. "for j in range(5):\n" +
  487. " 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" +
  488. " tft.line(40,220-36*(j+1),45,220-36*(j+1),st7789.color565(255,255,255))\n" +
  489. "\n" +
  490. "for i in range(17):\n" +
  491. " if i % 2 == 0:\n" +
  492. " if i < 18 and i > 0:\n" +
  493. " tft.line(40+(10 * i),220,40+(10 * i),215,st7789.color565(255,255,255))\n" +
  494. " tft.text(font,str(i),40+(10 * i),230,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" +
  495. "\n" +
  496. "for i in range(len(data_value) - 1):\n" +
  497. // " 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" +
  498. " 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" +
  499. "\n" +
  500. "tft.line(40,20,40,220, st7789.color565(255,255,255))\n" +
  501. "tft.line(40,220,220,220, st7789.color565(255,255,255))\n" +
  502. "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n";
  503. }
  504. }
  505. else if (a == 'broken_line') {
  506. if (b == 'Temperature') {
  507. var c = block.getFieldValue('temperature_range');
  508. if (c == "a") {
  509. _code = "" +
  510. "mapping_value =" + content + "\n" +
  511. "\n" +
  512. "if(len(data_value) < 17):\n" +
  513. " data_value.append(round(mapping_value))\n" +
  514. "else:\n" +
  515. " data_value.pop(1)\n" +
  516. " data_value.append(round(mapping_value))\n" +
  517. "\n" +
  518. "for j in range(5):\n" +
  519. " 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" +
  520. " tft.line(40,140-20*(j+1),45,140-20*(j+1),st7789.color565(255,255,255))\n" +
  521. "tft.text(font,'0',5,140,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" +
  522. "\n" +
  523. "for j in range(4):\n" +
  524. " 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" +
  525. " tft.line(40,140+20*(j+1),45,140+20*(j+1),st7789.color565(255,255,255))\n" +
  526. "\n" +
  527. "for i in range(17):\n" +
  528. " if i % 2 == 0:\n" +
  529. " if i < 18 and i > 0:\n" +
  530. " tft.line(40+(10 * i),140,40+(10 * i),135,st7789.color565(255,255,255))\n" +
  531. " if i != 0:\n" +
  532. " tft.text(font,str(i),40+(10 * i),150,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" +
  533. "\n" +
  534. "for i in range(len(data_value) - 1):\n" +
  535. " tft.line(40+(10 * i),140 - data_value[i],40+(10 * (i + 1)),140 - data_value[i + 1], st7789.color565(0,255,255))\n" +
  536. "\n" +
  537. "tft.line(40,20,40,230, st7789.color565(255,255,255))\n" +
  538. "tft.line(40,140,220,140, st7789.color565(255,255,255))\n" +
  539. "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n";
  540. } else {
  541. _code = "" +
  542. "mapping_value =" + content + "\n" +
  543. "\n" +
  544. "if(len(data_value) < 17):\n" +
  545. " data_value.append(round(mapping_value))\n" +
  546. "else:\n" +
  547. " data_value.pop(1)\n" +
  548. " data_value.append(round(mapping_value))\n" +
  549. "\n" +
  550. "for j in range(5):\n" +
  551. " 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" +
  552. " tft.line(40,140-20*(j+1),45,140-20*(j+1),st7789.color565(255,255,255))\n" +
  553. "tft.text(font,'0',5,140,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" +
  554. "\n" +
  555. "for j in range(2):\n" +
  556. " 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" +
  557. " tft.line(40,140+20*(j+1),45,140+20*(j+1),st7789.color565(255,255,255))\n" +
  558. "\n" +
  559. "for i in range(17):\n" +
  560. " if i % 2 == 0:\n" +
  561. " if i < 18 and i > 0:\n" +
  562. " tft.line(40+(10 * i),140,40+(10 * i),135,st7789.color565(255,255,255))\n" +
  563. " if i != 0:\n" +
  564. " tft.text(font,str(i),40+(10 * i),150,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" +
  565. "\n" +
  566. "for i in range(len(data_value) - 1):\n" +
  567. " 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" +
  568. "\n" +
  569. "tft.line(40,20,40,190, st7789.color565(255,255,255))\n" +
  570. "tft.line(40,140,220,140, st7789.color565(255,255,255))\n" +
  571. "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n";
  572. }
  573. }
  574. else if (b == 'Humidity') {
  575. _code = "" +
  576. "mapping_value =" + content + "\n" +
  577. "\n" +
  578. "if(len(data_value) < 17):\n" +
  579. " data_value.append(round(mapping_value))\n" +
  580. "else:\n" +
  581. " data_value.pop(1)\n" +
  582. " data_value.append(round(mapping_value))\n" +
  583. "\n" +
  584. "for j in range(5):\n" +
  585. " 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" +
  586. " tft.line(40,220-36*(j+1),45,220-36*(j+1),st7789.color565(255,255,255))\n" +
  587. "\n" +
  588. "for i in range(17):\n" +
  589. " if i % 2 == 0:\n" +
  590. " if i < 18 and i > 0:\n" +
  591. " tft.line(40+(10 * i),220,40+(10 * i),215,st7789.color565(255,255,255))\n" +
  592. " tft.text(font,str(i),40+(10 * i),230,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" +
  593. "\n" +
  594. "for i in range(len(data_value) - 1):\n" +
  595. " tft.line(40+(10 * i),220 - data_value[i],40+(10 * (i + 1)),220 - data_value[i + 1], st7789.color565(0,255,255))\n" +
  596. "\n" +
  597. "tft.line(40,20,40,220, st7789.color565(255,255,255))\n" +
  598. "tft.line(40,220,220,220, st7789.color565(255,255,255))\n" +
  599. "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n";
  600. }
  601. else {
  602. _code = "" +
  603. "mapping_value =" + content + "\n" +
  604. "\n" +
  605. "if(len(data_value) < 17):\n" +
  606. " data_value.append(round(mapping_value))\n" +
  607. "else:\n" +
  608. " data_value.pop(1)\n" +
  609. " data_value.append(round(mapping_value))\n" +
  610. "\n" +
  611. "for j in range(5):\n" +
  612. " 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" +
  613. " tft.line(40,220-36*(j+1),45,220-36*(j+1),st7789.color565(255,255,255))\n" +
  614. "\n" +
  615. "for i in range(17):\n" +
  616. " if i % 2 == 0:\n" +
  617. " if i < 18 and i > 0:\n" +
  618. " tft.line(40+(10 * i),220,40+(10 * i),215,st7789.color565(255,255,255))\n" +
  619. " tft.text(font,str(i),40+(10 * i),230,st7789.color565(255,255,255),st7789.color565(0,0,0))\n" +
  620. "\n" +
  621. "for i in range(len(data_value) - 1):\n" +
  622. " 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" +
  623. "\n" +
  624. "tft.line(40,20,40,220, st7789.color565(255,255,255))\n" +
  625. "tft.line(40,220,220,220, st7789.color565(255,255,255))\n" +
  626. "tft.text(font," + PROPERTY + ",40,10,st7789.color565(255,255,255),st7789.color565(0,0,0))\n";
  627. }
  628. }
  629. else {
  630. if (b == 'Temperature') {
  631. }
  632. else if (b == 'Humidity') {
  633. }
  634. else {
  635. }
  636. }
  637. return _code;
  638. }