123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608 |
- 'use strict';
- goog.provide('Blockly.Blocks.third_party');
- goog.require('Blockly.Blocks');
- Blockly.Blocks['sonar_setup'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldImage(
- // "http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_ultrasonicSensor.png", 140, 40, "15"));
- // "http://cocorobo.cn/cocoblockly/blockly/media/sensors-ultrasonic.png", 50, 40, "15"));
- "./../blockly/media/sensors-ultrasonic.png", 50, 40, "15"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.SONAR)
- .appendField(new Blockly.FieldDropdown([
- ["0", "0"],
- ["1", "1"],
- ["2", "2"],
- ["3", "3"],
- ["4", "4"],
- ["5", "5"],
- ["6", "6"],
- ["7", "7"],
- ["8", "8"],
- ["9", "9"],
- ["10", "10"]
- ]), "NUMBER")
- .appendField(Blockly.Msg.SONAR_SETUP);
- this.appendDummyInput()
- .appendField(Blockly.Msg.SONAR_SETUP_TRIGPIN)
- .appendField(new Blockly.FieldDropdown(
- Blockly.Python.Boards.selected.digitalPins.concat(Blockly.Python.Boards.selected.analogPins)), "TRIG_PIN")
- .appendField(Blockly.Msg.SONAR_SETUP_ECHOPIN)
- .appendField(new Blockly.FieldDropdown(
- Blockly.Python.Boards.selected.digitalPins.concat(Blockly.Python.Boards.selected.analogPins)), "ECHO_PIN");
- this.appendDummyInput()
- .appendField(Blockly.Msg.SONAR_SETUP_MAXDIST)
- .appendField(new Blockly.FieldNumber(50), "MAXDIST");
- this.setColour(300);
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['sonar_read_dist'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.SONAR_READ_DIST)
- .appendField(Blockly.Msg.SONAR)
- .appendField(new Blockly.FieldDropdown([
- ["0", "0"],
- ["1", "1"],
- ["2", "2"],
- ["3", "3"],
- ["4", "4"],
- ["5", "5"],
- ["6", "6"],
- ["7", "7"],
- ["8", "8"],
- ["9", "9"],
- ["10", "10"]
- ]), "NUMBER");
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(300);
- this.setTooltip('');
- this.setHelpUrl('');
- },
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- },
- };
- Blockly.Blocks['infraredRay_setup'] = {
- init: function() {
- this.appendDummyInput()
- // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_infraredRay.png", 140, 40, "0"));
- .appendField(new Blockly.FieldImage("./../blockly/media/sensors-ir_receiver.png", 50, 40, "0"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.INFRAREDRAY_SETUP);
- // this.setNextStatement(true, null);
- this.setColour(300);
- this.setTooltip('');
- this.setHelpUrl('');
- }
- };
- Blockly.Blocks['infraredRay_receive_val'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.INFRAREDRAY_RECVAL);
- this.setOutput(true, Blockly.Types.TEXT.output);
- this.setColour(300);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.TEXT;
- }
- };
- Blockly.Blocks['infraredRay_send_val'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([
- ["↑", "KEYPAD_UP"],
- ["↓", "KEYPAD_DOWN"],
- ["←", "KEYPAD_LEFT"],
- ["→", "KEYPAD_RIGHT"],
- ["OK", "KEYPAD_OK"],
- ["1", "KEYPAD_1"],
- ["2", "KEYPAD_2"],
- ["3", "KEYPAD_3"],
- ["4", "KEYPAD_4"],
- ["5", "KEYPAD_5"],
- ["6", "KEYPAD_6"],
- ["7", "KEYPAD_7"],
- ["8", "KEYPAD_8"],
- ["9", "KEYPAD_9"],
- ["0", "KEYPAD_0"],
- ["*", "KEYPAD_STAR"],
- ["#", "KEYPAD_NUMSIGN"]
- ]), "VALTYPE");
- this.setOutput(true, Blockly.Types.TEXT.output);
- this.setColour(300);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.TEXT;
- }
- };
- /* RTC
- * Setup
- */
- Blockly.Blocks['RTC_setup'] = {
- init: function() {
- this.appendDummyInput()
- // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_RTC.png", 40, 40, "0"));
- .appendField(new Blockly.FieldImage("./../blockly/media/sensors-rtc.png", 50, 40, "0"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.RTC_SETUP);
- this.setColour(340);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- };
- /* RTC
- * Set Date/Time
- */
- Blockly.Blocks['RTC_setDateTime'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.RTC_SETDATETIME);
- this.appendDummyInput()
- .appendField(Blockly.Msg.RTC_SETDATE)
- .appendField(new Blockly.FieldNumber(2018, 0, 2050), "year")
- .appendField("-")
- .appendField(new Blockly.FieldNumber(1, 0, 12), "month")
- .appendField("-")
- .appendField(new Blockly.FieldNumber(1, 0, 31), "day")
- this.appendDummyInput()
- .appendField(Blockly.Msg.RTC_SETTIME)
- .appendField(new Blockly.FieldNumber(12, 0, 24), "hour")
- .appendField(":")
- .appendField(new Blockly.FieldNumber(30, 0, 60), "minute")
- .appendField(":")
- .appendField(new Blockly.FieldNumber(10, 0, 60), "second")
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setColour(340);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- /**
- * Called whenever anything on the workspace changes.
- * It checks the number of data and time settting
- * @this Blockly.Block
- */
- onchange: function() {
- if (this.getFieldValue("year") > 2050) {
- this.setFieldValue("2019", "year");
- }
- if (this.getFieldValue("month") > 12) {
- this.setFieldValue("12", "month");
- } else if (this.getFieldValue("month") < 0) {
- this.setFieldValue("1", "month");
- }
- if (this.getFieldValue("day") > 31) {
- this.setFieldValue("31", "day");
- } else if (this.getFieldValue("day") < 0) {
- this.setFieldValue("1", "day");
- }
- if (this.getFieldValue("hour") > 24) {
- this.setFieldValue("24", "hour");
- } else if (this.getFieldValue("hour") < 0) {
- this.setFieldValue("1", "hour");
- }
- if (this.getFieldValue("minute") > 60) {
- this.setFieldValue("60", "minute");
- } else if (this.getFieldValue("minute") < 0) {
- this.setFieldValue("1", "minute");
- }
- if (this.getFieldValue("second") > 60) {
- this.setFieldValue("60", "second");
- } else if (this.getFieldValue("second") < 0) {
- this.setFieldValue("1", "second");
- }
- }
- };
- /* RTC
- * get Date
- */
- Blockly.Blocks['RTC_getDate'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.RTC_GETDATE)
- .appendField(new Blockly.FieldDropdown([
- [Blockly.Msg.RTC_YEAR, "year"],
- [Blockly.Msg.RTC_MONTH, "month"],
- [Blockly.Msg.RTC_DAY, "day"],
- ]), "date_detail")
- this.setColour(340);
- this.setOutput(true, Blockly.Types.TEXT.output);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.TEXT;
- }
- };
- /* RTC
- * get Time
- */
- Blockly.Blocks['RTC_getTime'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.RTC_GETTIME)
- .appendField(new Blockly.FieldDropdown([
- [Blockly.Msg.RTC_HOUR, "hour"],
- [Blockly.Msg.RTC_MINUTE, "minute"],
- [Blockly.Msg.RTC_SECOND, "second"],
- ]), "time_detail")
- this.setColour(340);
- this.setOutput(true, Blockly.Types.TEXT.output);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.TEXT;
- }
- };
- /* RTC
- * get Week
- */
- Blockly.Blocks['RTC_getWeek'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.RTC_GETWEEK);
- this.setColour(340);
- this.setOutput(true, Blockly.Types.TEXT.output);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.TEXT;
- }
- };
- /* PulseSensor */
- Blockly.Blocks['PulseSensor_setup'] = {
- init: function() {
- this.appendDummyInput()
- // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_pulseSensor.png", 40, 40, "0"));
- .appendField(new Blockly.FieldImage("./../blockly/media/sensors-heart_beat.png", 50, 40, "0"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.PULSESENSOR_SETUP)
- this.appendDummyInput()
- .appendField(Blockly.Msg.PULSESENSOR_SETUP_1)
- .appendField(new Blockly.FieldDropdown(Blockly.Python.Boards.selected.analogPins), "PIN");
- this.setColour(360);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- };
- /* PulseSensor */
- Blockly.Blocks['PulseSensor_getBPM'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.PULSESENSOR_GETBPM);
- this.setOutput(true, Blockly.Types.NUMBER.output);
- this.setColour(360);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.NUMBER;
- }
- }
- /* PulseSensor */
- Blockly.Blocks['PulseSensor_Heart_Beats'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.PULSESENSOR_HEARTBEAT_WHEN);
- this.setOutput(true, Blockly.Types.BOOLEAN.output);
- this.setColour(360);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.BOOLEAN;
- }
- };
- /* PulseSensor */
- Blockly.Blocks['PulseSensor_Heart_noBeats'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.PULSESENSOR_HEARTBEAT_WHENNO);
- this.setOutput(true, Blockly.Types.BOOLEAN.output);
- this.setColour(360);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.BOOLEANs;
- }
- };
- /* PulseSensor */
- Blockly.Blocks['PulseSensor_print'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.PULSESENSOR_HEARTBEAT_PRINT);
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- this.setColour(360);
- this.setTooltip("");
- this.setHelpUrl("");
- }
- };
- /*Encoder*/
- Blockly.Blocks['Encoder_Setup'] = {
- init: function() {
- this.appendDummyInput()
- // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_encoder.png", 40, 40, "0"));
- .appendField(new Blockly.FieldImage("./../blockly/media/sensors-encoder.png", 50, 40, "0"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.ENCODER_SETUP)
- this.appendDummyInput()
- .appendField(Blockly.Msg.ENCODER_SETUP_1)
- .appendField(new Blockly.FieldDropdown([
- ["2", "2"],
- ["3", "3"]
- ]), "PIN");
- this.setColour(260);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- }
- /*Encoder*/
- Blockly.Blocks['Encoder_getRotationSpeed'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.ENCODER_GETROTATIONSPEED)
- this.setOutput(true);
- this.setColour(260);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- var numString = '1';
- return Blockly.Types.identifyNumber(numString);
- }
- }
- /* RFID
- * Setup
- */
- Blockly.Blocks['RFID_Setup'] = {
- init: function() {
- this.appendDummyInput()
- // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_encoder.png", 40, 40, "0"));
- .appendField(new Blockly.FieldImage("./../blockly/media/sensors-rfid.png", 50, 40, "0"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.RFID_SETUP)
- this.setColour(230);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- }
- /* RFID
- * Read ID
- */
- Blockly.Blocks['RFID_ReadID'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.RFID_READID);
- this.setOutput(true, Blockly.Types.TEXT.output);
- this.setColour(230);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.TEXT;
- }
- }
- /* GPS
- * Setup
- */
- Blockly.Blocks['GPS_setup'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldImage("./../blockly/media/gps_header.png", 50, 40, "0"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.GPS_SETUP);
- this.setColour(210);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- }
- /* GPS
- * get latitude
- */
- Blockly.Blocks['GPS_getLatitude'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.GPS_LATITUDE);
- this.setOutput(true, Blockly.Types.TEXT.output);
- this.setColour(210);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.TEXT;
- }
- }
- /* GPS
- * get longitude
- */
- Blockly.Blocks['GPS_getLongitude'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.GPS_LONGITUDE);
- this.setOutput(true, Blockly.Types.TEXT.output);
- this.setColour(210);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.TEXT;
- }
- }
- /* Water Temperature Sensor, DS18S20
- * setup
- */
- Blockly.Blocks['water_temp_sensor_setup'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldImage("./../blockly/media/water-temp-sensor-setup.png", 70, 60, "*"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.WATERTEMP_SETUP_BLOCKNAME);
- this.appendDummyInput()
- .appendField(Blockly.Msg.WATERTEMP_SETUP_SENSORTYPE)
- .appendField(new Blockly.FieldDropdown([
- ["DS18S20", "water_temp_sensor_setup_"]
- ]), "water_temp_sensor_setup_dropdown")
- .appendField(Blockly.Msg.WATERTEMP_SETUP_SETUP);
- this.appendDummyInput()
- .appendField(Blockly.Msg.WATERTEMP_SETUP_ATTACHED_PIN)
- .appendField(new Blockly.FieldNumber(3, 0, 13, 1), "water_temp_sensor_setup_pin");
- this.setColour(0);
- this.setTooltip("");
- this.setHelpUrl("");
- }
- };
- /* Water Temperature Sensor, get value
- */
- Blockly.Blocks['water_temp_sensor_get_value'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.WATERTEMP_GET_TEMP);
- this.setOutput(true, Blockly.Types.DECIMAL.output);
- this.setColour(0);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function() {
- return Blockly.Types.DECIMAL;
- }
- };
- // CO2 sensor setup
- Blockly.Blocks['thirdparty_co2_sensor_setup'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldImage("./../blockly/media/third-party_co2_header.png", 180, 50, { alt: "*", flipRtl: "FALSE" }));
- this.appendDummyInput()
- .appendField(Blockly.Msg.CO2SENSOR_SETUP);
- this.appendDummyInput()
- .appendField(Blockly.Msg.CO2SENSOR_SETUP_SDA)
- .appendField(new Blockly.FieldDropdown([
- ["D2", "D2"]
- ]), "thirdparty_co2_sensor_setup_sdapin")
- .appendField(Blockly.Msg.CO2SENSOR_SETUP_SCL)
- .appendField(new Blockly.FieldDropdown([
- ["D3", "D3"]
- ]), "thirdparty_co2_sensor_setup_sclpin");
- this.setColour(330);
- this.setTooltip("");
- this.setHelpUrl("https://help.cocorobo.cn/");
- }
- };
- Blockly.Blocks['thirdparty_co2_sensor_get_co2'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.CO2SENSOR_GET_CO2);
- this.setOutput(true, null);
- this.setColour(330);
- this.setTooltip("");
- this.setHelpUrl("https://help.cocorobo.cn/");
- }
- };
- Blockly.Blocks['thirdparty_co2_sensor_get_tvoc'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.CO2SENSOR_GET_TVOC);
- this.setOutput(true, null);
- this.setColour(330);
- this.setTooltip("");
- this.setHelpUrl("https://help.cocorobo.cn/");
- }
- };
- // nrf module
- Blockly.Blocks['thirdparty_nrf24l01_setup'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(new Blockly.FieldImage("./../blockly/media/third-party_nrf-sensor.png", 130, 50, { alt: "*", flipRtl: "FALSE" }));
- this.appendDummyInput()
- .appendField(Blockly.Msg.NRFMODULE_SETUP_TITLE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.NRFMODULE_SETUP_CE_TEXT)
- .appendField(new Blockly.FieldDropdown([["D7","d7"]]), "thirdparty_nrf24l01_setup_dropdown_cepin")
- .appendField(Blockly.Msg.NRFMODULE_SETUP_CSN_TEXT)
- .appendField(new Blockly.FieldDropdown([["D5","d5"]]), "thirdparty_nrf24l01_setup_dropdown_csnpin");
- this.appendDummyInput()
- .appendField(Blockly.Msg.NRFMODULE_SETUP_SET_ADDRESS)
- .appendField(new Blockly.FieldTextInput("00001"), "thirdparty_nrf24l01_setup_addr");
- this.setColour(230);
- this.setTooltip("");
- this.setHelpUrl("");
- }
- };
- Blockly.Blocks['thirdparty_nrf24l01_send_data'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.NRFMODULE_SEND_DATA_TITLE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.NRFMODULE_SEND_DATA_DATA_TEXT)
- .appendField(new Blockly.FieldTextInput("Hello World"), "thirdparty_nrf24l01_send_data_data");
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- this.setColour(230);
- this.setTooltip("");
- this.setHelpUrl("");
- }
- };
- Blockly.Blocks['thirdparty_nrf24l01_receive_data'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.NRFMODULE_RECEIVING_DATA_TEXT);
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- this.setColour(230);
- this.setTooltip("");
- this.setHelpUrl("");
- }
- };
- Blockly.Blocks['thirdparty_nrf24l01_data_received'] = {
- init: function() {
- this.appendDummyInput()
- .appendField(Blockly.Msg.NRFMODULE_GET_RECEIVED_DATA);
- this.setOutput(true, null);
- this.setColour(230);
- this.setTooltip("");
- this.setHelpUrl("");
- }
- };
|