123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649 |
- 'use strict';
- goog.provide('Blockly.Blocks.screen');
- goog.require('Blockly.Blocks');
- goog.require('Blockly.Types');
- Blockly.Blocks['lcd_setup'] = {
- init: function() {
- this.appendDummyInput()
- // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_oledScreen.png", 140, 40, "0"));
- .appendField(new Blockly.FieldImage("./../blockly/media/main-screen.png", 50, 40, "0"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_SETUP);
- this.setColour(245);
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['lcd_set_width_height'] = {
- init: function() {
- this.appendValueInput("WIDTH")
- .setCheck("Number")
- .appendField(Blockly.Msg.OLCD_WIDTH);
- this.appendValueInput("HEIGHT")
- .setCheck("Number")
- .appendField(Blockly.Msg.OLCD_HEIGHT);
- this.setOutput(true, "String");
- this.setInputsInline(true);
- this.setColour("#5bb2d6");
- this.setTooltip("");
- this.setHelpUrl("");
- }
- };
- Blockly.Blocks['lcd_set_bool'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.ARD_TYPE_BOOL)
- .appendField(new Blockly.FieldCheckbox("TRUE"), "BOOL");
- this.setOutput(true, "Boolean");
- this.setColour("#5bb2d6");
- this.setTooltip("");
- this.setHelpUrl("");
- }
- };
- Blockly.Blocks['lcd_get_WH'] = {
- init: function() {
- this.jsonInit({
- colour: CategoryColors.Show,
- args0: [{
- name: "display_fill",
- options: [
- [Blockly.Msg.LED_WIDTH, "0"],
- [Blockly.Msg.LED_HEIGHT, "1"]
- ],
- type: "field_dropdown"
- }],
- nextStatement: null,
- previousStatement: null,
- helpUrl: "",
- tooltip: "",
- message0: Blockly.Msg.GLCDD
- })
- }
- };
- Blockly.Python['lcd_get_WH'] = function(a) {
- var _text = a.getFieldValue("display_fill");
- return "tft.size()[" + _text + "]";
- };
- Blockly.Blocks['lcd_set_position'] = {
- init: function() {
- this.appendValueInput("POSX")
- .setCheck("Number")
- .appendField("X:");
- this.appendValueInput("POSY")
- .setCheck("Number")
- .appendField("Y:");
- this.setOutput(true, "String");
- this.setInputsInline(true);
- this.setColour("#5bb2d6");
- this.setTooltip("");
- this.setHelpUrl("");
- }
- };
- Blockly.Blocks['lcd_set_width'] = {
- init: function() {
- this.appendValueInput("Width")
- .setCheck("Number")
- .appendField("Width:");
- this.setOutput(true, "String");
- this.setInputsInline(true);
- this.setColour("#5bb2d6");
- this.setTooltip("");
- this.setHelpUrl("");
- }
- };
- Blockly.Blocks['lcd_set_Scale'] = {
- init: function() {
- this.appendValueInput("Scale")
- .setCheck("Number")
- .appendField(Blockly.Msg.OLCD_SCALE);
- this.setOutput(true, "String");
- this.setInputsInline(true);
- this.setColour("#5bb2d6");
- this.setTooltip("");
- this.setHelpUrl("");
- }
- };
- Blockly.Blocks['lcd_screen'] = {
- init: function() {
- // this.appendDummyInput()
- // .appendField(
- // new Blockly.FieldImage("./../blockly/media/line.png", 25, 25, "15"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_DRAW + Blockly.Msg.OLCD_SCREEN)
- .appendField(Blockly.Msg.PROCEDURES_BEFORE_PARAMS)
- .appendField(new Blockly.FieldColour("#ff0000"), "COLOR");
- // this.appendValueInput("COLOR")
- // .setCheck("String")
- // .appendField(Blockly.Msg.OLCD_COLOR);
- // this.appendValueInput("POSA")
- // .setCheck("String")
- // .appendField(Blockly.Msg.OLCD_LINE_START);
- // this.appendValueInput("POSB")
- // .setCheck("String")
- // .appendField(Blockly.Msg.OLCD_LINE_END);
- //this.setInputsInline(false);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour("#5bb2d6");
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Python['lcd_screen'] = function(a) {
- a = a.getFieldValue("COLOR") || Blockly.Python.valueToCode(a, 'COLOR', Blockly.Python.ORDER_ATOMIC);
- 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) {}
- // var _code = "FS_RGB = (" + d + "," + e + "," + f + ")\n";
- // _code += "FS_COLOR = ((FS_RGB[0] & 0xF8) << 8) | ((FS_RGB[1] & 0xFC) << 3) | (FS_RGB[2] >> 3)\n";
- // _code += "tft.fill(FS_COLOR)\n";
- //var _code = "tft.fill(TFT.TFTColor(0x" + d + ", 0x" + e + ", 0x" + f + "))\n";
- var _code = "(" + d + "," + e + "," + f + ")";
- return _code;
- };
- Blockly.Blocks['lcd_drawline'] = {
- init: function() {
- // this.appendDummyInput()
- // .appendField(
- // new Blockly.FieldImage("./../blockly/media/line.png", 25, 25, "15"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_DRAW + Blockly.Msg.OLCD_LINE);
- this.appendValueInput("COLOR")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_COLOR);
- this.appendValueInput("POSA")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_LINE_START);
- this.appendValueInput("POSB")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_LINE_END);
- this.setInputsInline(false);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour("#5bb2d6");
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['lcd_drawvhline'] = {
- init: function() {
- // this.appendDummyInput()
- // .appendField(
- // new Blockly.FieldImage("./../blockly/media/line.png", 25, 25, "15"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_DRAW)
- .appendField(new Blockly.FieldDropdown([
- [Blockly.Msg.OLCD_FULL, "fillrect"],
- [Blockly.Msg.OLCD_CIRCLE, "rect"]
- ]), "rect_type")
- .appendField(Blockly.Msg.OLCD_LINE)
- this.appendValueInput("COLOR")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_COLOR);
- this.appendValueInput("POSA")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_COORDINATE);
- this.appendValueInput("POSB")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_SIZE);
- this.setInputsInline(false);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour("#5bb2d6");
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['ai_lcd_drawvhtext'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.LCDDT);
- this.appendValueInput("POSA")
- .setCheck("String")
- .appendField(Blockly.Msg.LED_COORDINATE);
- this.appendValueInput("CONTENT")
- .setCheck("String")
- .appendField(Blockly.Msg.WIFISERVER_SERVERSEND_CONTENT);
- this.appendValueInput("COLOR")
- .setCheck("String")
- .appendField(Blockly.Msg.LCDDT_C);
- this.appendValueInput("BCOLOR")
- .setCheck("String")
- .appendField(Blockly.Msg.LCDDT_BC);
- this.setInputsInline(false);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour("#5bb2d6");
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['lcd_drawlinelen'] = {
- init: function() {
- // this.appendDummyInput()
- // .appendField(
- // new Blockly.FieldImage("./../blockly/media/line.png", 25, 25, "15"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_DRAW)
- .appendField(new Blockly.FieldDropdown([
- [Blockly.Msg.OLCD_VLINE, "vline"],
- [Blockly.Msg.OLCD_HEIGHT, "hline"]
- ]), "rect_type")
- .appendField(Blockly.Msg.OLCD_LINE)
- this.appendValueInput("COLOR")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_COLOR);
- this.appendValueInput("POSA")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_LINE_START);
- this.appendValueInput("POSB")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_LENGTHIS);
- this.setInputsInline(false);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour("#5bb2d6");
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['lcd_color'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.COLOR)
- .appendField(new Blockly.FieldColour("#ff0000"), "COLOR");
- this.setOutput(true, null);
- this.setColour("#5bb2d6");
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Python['lcd_color'] = function(a) {
- // a = a.getFieldValue("COLOR");
- // var d = 0
- // , e = 0
- // , f = 0;
- // try {
- // 7 == a.length && (d = a.substring(1, 3),
- // e = a.substring(3, 5),
- // f = a.substring(5, 7));
- // }
- // catch (g) { }
- var _code = Blockly.Python['lcd_screen'](a);
- _code = "_TFTColor" + _code + "";
- //_code += "tft.fill(TFT.TFTColor(FS_COLOR))\n";
- return _code;
- };
- Blockly.Blocks['lcd_drawrect'] = {
- init: function() {
- //this.appendDummyInput()
- // .appendField(
- // new Blockly.FieldImage("./../blockly/media/rect.png", 25, 25, "15"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_DRAW)
- // .appendField(new Blockly.FieldDropdown([
- // [Blockly.Msg.OLCD_FULL, "fill"],
- // [Blockly.Msg.OLCD_STROKED, "draw"]
- // ]), "rect_type")
- .appendField(Blockly.Msg.LED_PIXEL);
- this.appendValueInput("COLOR")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_COLOR);
- // this.appendValueInput("SIZE")
- // .setCheck("String")
- // .appendField(Blockly.Msg.OLCD_SIZE);
- this.appendValueInput("POS")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_COORDINATE);
- this.setInputsInline(false);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour("#5bb2d6");
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['lcd_drawcircle'] = {
- init: function() {
- // this.appendDummyInput()
- // .appendField(
- // new Blockly.FieldImage("./../blockly/media/circle.png", 25, 25, "15"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_DRAW)
- .appendField(new Blockly.FieldDropdown([
- [Blockly.Msg.OLCD_FULL, "fillcircle"],
- [Blockly.Msg.OLCD_STROKED, "circle"]
- ]), "circle_type")
- .appendField(Blockly.Msg.OLCD_CIRCLE);
- this.appendValueInput("COLOR")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_COLOR);
- this.appendValueInput("POSA")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_CENTER_POS);
- this.appendValueInput("RADIUS")
- .setCheck("Number")
- .appendField(Blockly.Msg.OLCD_RADIUS);
- this.setInputsInline(false);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour("#5bb2d6");
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['lcd_drawqrcode'] = {
- init: function() {
- // this.appendDummyInput()
- // .appendField(
- // new Blockly.FieldImage("./../blockly/media/circle.png", 25, 25, "15"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_DRAW + Blockly.Msg.LCDRQ);
- this.appendValueInput("POSA")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_SET_POS);
- this.appendValueInput("CONTENT")
- .setCheck("String")
- .appendField(Blockly.Msg.WIFISERVER_SERVERSEND_CONTENT);
- this.appendValueInput("WIDTH")
- .setCheck("Number")
- .appendField(Blockly.Msg.OLCD_WT);
- this.setInputsInline(false);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour("#5bb2d6");
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['lcd_drawtext'] = {
- init: function() {
- // this.appendDummyInput()
- // .appendField(
- // new Blockly.FieldImage("./../blockly/media/circle.png", 25, 25, "15"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_DRAW + Blockly.Msg.ARD_TYPE_TEXT);
- this.appendValueInput("COLOR")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_COLOR);
- this.appendValueInput("POSA")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_CENTER_POS);
- this.appendValueInput("CONTENT")
- .setCheck("String")
- .appendField(Blockly.Msg.WIFISERVER_SERVERSEND_CONTENT);
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_SCALE)
- .appendField(new Blockly.FieldNumber(1), 'TextContnet');
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_WT)
- .appendField(new Blockly.FieldCheckbox('TRUE'), 'TextCheckBox');
- this.setInputsInline(false);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour("#5bb2d6");
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['lcd_drawtriangle'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(
- new Blockly.FieldImage("./../blockly/media/triangle.png", 25, 25, "15"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_DRAW)
- .appendField(new Blockly.FieldDropdown([
- [Blockly.Msg.OLCD_FULL, "fill"],
- [Blockly.Msg.OLCD_STROKED, "draw"]
- ]), "triangle_type")
- .appendField(Blockly.Msg.OLCD_TRIANGLE);
- this.appendValueInput("COLOR")
- .setCheck(null)
- .appendField(Blockly.Msg.OLCD_COLOR);
- this.appendValueInput("POSA")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_POINT + ' A');
- this.appendValueInput("POSB")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_POINT + ' B');
- this.appendValueInput("POSC")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_POINT + ' C');
- this.setInputsInline(false);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour(245);
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['lcd_text'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(
- new Blockly.FieldImage("./../blockly/media/text.png", 25, 25, "15"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_TEXTNEWLINE)
- .appendField(new Blockly.FieldDropdown([
- [Blockly.Msg.OLCD_TRUE, "println"],
- [Blockly.Msg.OLCD_FALSE, "print"]
- ]), "print_type");
- this.appendValueInput("INPUT")
- .setCheck(null)
- .appendField(Blockly.Msg.OLCD_TEXT);
- this.appendValueInput("COLOR")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_COLOR);
- this.appendValueInput("POS")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_COORDINATE);
- this.appendValueInput("SIZE")
- .setCheck("Number")
- .appendField(Blockly.Msg.OLCD_SIZE);
- this.setInputsInline(false);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour(245);
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['lcd_clear'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_CLEAR);
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- this.setColour(245);
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['lcd_rotation'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_SETROTATION)
- .appendField(new Blockly.FieldDropdown([
- ["0°", "1"],
- ["90°", "2"],
- ["180°", "3"],
- ["270°", "0"]
- ]), "DEGREE")
- .appendField(Blockly.Msg.OLCD_SETROTATION_DEGREE)
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- this.setColour("#5bb2d6");
- this.setTooltip('');
- this.setHelpUrl('');
- }
- }
- Blockly.Blocks['ai_lcd_invertcanvas'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.LCDSCIC)
- .appendField(new Blockly.FieldVariable("canvas"), "varitem")
- .appendField(Blockly.Msg.LCDSCIC_I)
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- this.setColour("#5bb2d6");
- this.setTooltip('');
- this.setHelpUrl('');
- }
- }
- Blockly.Python.ai_lcd_invertcanvas = function(block) {
- var variable_name = Blockly.Python.variableDB_.getName(block.getFieldValue('varitem'), Blockly.Variables.NAME_TYPE);
- var _code = variable_name + " = canvas.invert()\n";
- return _code;;
- }
- Blockly.Blocks['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("");
- this.setHelpUrl("");
- }
- };
- Blockly.Blocks['lcd_set_colortext'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.COLOR)
- .appendField(new Blockly.FieldDropdown([
- ["黑色", "BLACK"],
- ["紅色", "RED"],
- ["綠色", "GREEN"],
- ["藍色", "BLUE"],
- ["紫色", "PURPLE"],
- ["青色", "CYAN"],
- ["橙色", "ORANGE"],
- ["黃色", "YELLOW"]
- ]), "COLOR");
- this.setOutput(true, "String");
- this.setColour("#5bb2d6");
- this.setTooltip("");
- this.setHelpUrl("");
- }
- };
- Blockly.Blocks['lcd_set_colorRGB'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.COLOR);
- this.appendValueInput("RED_VAL")
- .setCheck(null)
- .appendField(Blockly.Msg.RED);
- this.appendValueInput("GREEN_VAL")
- .setCheck(null)
- .appendField(Blockly.Msg.GREEN);
- this.appendValueInput("BLUE_VAL")
- .setCheck(null)
- .appendField(Blockly.Msg.BLUE);
- this.setInputsInline(true);
- this.setOutput(true, "String");
- this.setColour(245);
- this.setTooltip("");
- this.setHelpUrl("http://help.cocorobo.cn/#/cocomod/color-analyzer?id=rgb-%E5%8F%96%E8%89%B2%E5%99%A8");
- }
- }
- Blockly.Blocks['ai_lcd_drawrect'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.OLCD_DRAW)
- .appendField(Blockly.Msg.LED_PIXEL);
- this.appendValueInput("COLOR")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_COLOR);
- this.appendValueInput("POS")
- .setCheck("String")
- .appendField(Blockly.Msg.OLCD_COORDINATE);
- this.setInputsInline(false);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour("#5bb2d6");
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['ai_camera_filp'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.LCDMF)
- .appendField(new Blockly.FieldCheckbox('TRUE'), 'TextCheckBox');
- this.setInputsInline(true);
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- this.setColour("#5bb2d6");
- this.setTooltip('');
- this.setHelpUrl('');
- }
- }
- Blockly.Python.ai_camera_filp = function(block) {
- var _tf = block.getFieldValue('TextCheckBox') == 'TRUE' ? "True" : "False";
- var _code = "lcd.mirror(" + _tf + ")\n";
- return _code;
- }
|