mirror of
https://github.com/m5stack/UIFlowLessons.git
synced 2026-05-20 11:02:19 -07:00
1 line
6.2 KiB
Plaintext
1 line
6.2 KiB
Plaintext
{"category":"Dallas18B20","color":"#333333","blocks":["__Dallas18B20_import","__Dallas18B20_Init","__Dallas18B20_TemperatureC"],"jscode":"// Block __Dallas18B20_import\nvar __Dallas18B20_import_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"import 18B20\"\n }\n ],\n \"colour\": \"#333333\"\n};\n\nwindow['Blockly'].Blocks['__Dallas18B20_import'] = {\n init: function() {\n this.jsonInit(__Dallas18B20_import_json);\n }\n};\n\nwindow['Blockly'].Python['__Dallas18B20_import'] = function(block) {\n return `# A fork has been made from https://github.com/stonatm/UiFlow-custom-blocks/tree/master/ds18b20\n\nfrom machine import Pin\nimport _onewire\n\nclass Dallas18B20:\n pin = None\n ready = False\n \n def __init__(self, pin):\n self.pin = Pin(pin, Pin.OPEN_DRAIN, Pin.PULL_UP)\n self.ready = True\n \n def convert(self):\n if self.ready == True:\n _onewire.reset(self.pin)\n _onewire.writebyte(self.pin, 0xcc)\n _onewire.writebyte(self.pin, 0x44)\n \n def read(self):\n temp = 0\n if self.ready == True:\n self.convert()\n _onewire.reset(self.pin)\n _onewire.writebyte(self.pin, 0xcc)\n _onewire.writebyte(self.pin, 0xbe)\n tlo = _onewire.readbyte(self.pin)\n thi = _onewire.readbyte(self.pin)\n _onewire.reset(self.pin)\n temp = tlo + thi * 256\n if temp > 32767:\n temp = temp - 65536\n temp = temp * 0.0625\n return temp\n` + \"\\n\";\n};\n\n// Block __Dallas18B20_Init\nvar __Dallas18B20_Init_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"Init\"\n }\n ],\n \"message1\": \"%1 %2\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \"name\"\n },\n {\n \"type\": \"field_input\",\n \"text\": \"\",\n \"spellcheck\": false,\n \"name\": \"name\"\n }\n ],\n \"message2\": \"%1 %2\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \"pin\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"pin\"\n }\n ],\n \"colour\": \"#333333\"\n};\n\nwindow['Blockly'].Blocks['__Dallas18B20_Init'] = {\n init: function() {\n this.jsonInit(__Dallas18B20_Init_json);\n }\n};\n\nwindow['Blockly'].Python['__Dallas18B20_Init'] = function(block) {\n var name = block.getFieldValue('name');\nvar pin = Blockly.Python.valueToCode(block, 'pin', Blockly.Python.ORDER_NONE);\n return `${name} = Dallas18B20(${pin})\n` + \"\\n\";\n};\n\n// Block __Dallas18B20_TemperatureC\nvar __Dallas18B20_TemperatureC_json = {\n \"output\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"TemperatureC\"\n }\n ],\n \"message1\": \"%1 %2\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \"name\"\n },\n {\n \"type\": \"field_input\",\n \"text\": \"\",\n \"spellcheck\": false,\n \"name\": \"name\"\n }\n ],\n \"colour\": \"#333333\"\n};\n\nwindow['Blockly'].Blocks['__Dallas18B20_TemperatureC'] = {\n init: function() {\n this.jsonInit(__Dallas18B20_TemperatureC_json);\n }\n};\n\nwindow['Blockly'].Python['__Dallas18B20_TemperatureC'] = function(block) {\n var name = block.getFieldValue('name');\n return [`${name}.read()\n`, Blockly.Python.ORDER_CONDITIONAL]\n};\n\n","code":{"import":["window['Blockly'].Python['__Dallas18B20_import'] = function(block) {\n return `# A fork has been made from https://github.com/stonatm/UiFlow-custom-blocks/tree/master/ds18b20\n\nfrom machine import Pin\nimport _onewire\n\nclass Dallas18B20:\n pin = None\n ready = False\n \n def __init__(self, pin):\n self.pin = Pin(pin, Pin.OPEN_DRAIN, Pin.PULL_UP)\n self.ready = True\n \n def convert(self):\n if self.ready == True:\n _onewire.reset(self.pin)\n _onewire.writebyte(self.pin, 0xcc)\n _onewire.writebyte(self.pin, 0x44)\n \n def read(self):\n temp = 0\n if self.ready == True:\n self.convert()\n _onewire.reset(self.pin)\n _onewire.writebyte(self.pin, 0xcc)\n _onewire.writebyte(self.pin, 0xbe)\n tlo = _onewire.readbyte(self.pin)\n thi = _onewire.readbyte(self.pin)\n _onewire.reset(self.pin)\n temp = tlo + thi * 256\n if temp > 32767:\n temp = temp - 65536\n temp = temp * 0.0625\n return temp\n` + \"\\n\";\n};\n\n","# A fork has been made from https://github.com/stonatm/UiFlow-custom-blocks/tree/master/ds18b20\n\nfrom machine import Pin\nimport _onewire\n\nclass Dallas18B20:\n pin = None\n ready = False\n \n def __init__(self, pin):\n self.pin = Pin(pin, Pin.OPEN_DRAIN, Pin.PULL_UP)\n self.ready = True\n \n def convert(self):\n if self.ready == True:\n _onewire.reset(self.pin)\n _onewire.writebyte(self.pin, 0xcc)\n _onewire.writebyte(self.pin, 0x44)\n \n def read(self):\n temp = 0\n if self.ready == True:\n self.convert()\n _onewire.reset(self.pin)\n _onewire.writebyte(self.pin, 0xcc)\n _onewire.writebyte(self.pin, 0xbe)\n tlo = _onewire.readbyte(self.pin)\n thi = _onewire.readbyte(self.pin)\n _onewire.reset(self.pin)\n temp = tlo + thi * 256\n if temp > 32767:\n temp = temp - 65536\n temp = temp * 0.0625\n return temp\n"],"Init":["window['Blockly'].Python['__Dallas18B20_Init'] = function(block) {\n var name = block.getFieldValue('name');\nvar pin = Blockly.Python.valueToCode(block, 'pin', Blockly.Python.ORDER_NONE);\n return `${name} = Dallas18B20(${pin})\n` + \"\\n\";\n};\n\n","${name} = Dallas18B20(${pin})\n"],"TemperatureC":["window['Blockly'].Python['__Dallas18B20_TemperatureC'] = function(block) {\n var name = block.getFieldValue('name');\n return [`${name}.read()\n`, Blockly.Python.ORDER_CONDITIONAL]\n};\n\n","${name}.read()\n"]}} |