1
0
mirror of https://github.com/s00500/SimpleExpressions synced 2024-11-21 23:10:54 +00:00
This commit is contained in:
Lukas Bachschwell 2017-12-12 14:15:22 +01:00
parent ea9fabe9a4
commit 8cf9d4583a
2 changed files with 111 additions and 92 deletions

View File

@ -1,11 +1,11 @@
{ {
"langs": "langs":
{ {
"en-GB": "en-GB":
{ {
"keys": "keys":
{ {
"LANG_CATEGORY_SOUND": "User Sound", "LANG_CATEGORY_SOUND": "Sound",
"LANG_SUBCATEGORY_BUZZER": "Buzzer", "LANG_SUBCATEGORY_BUZZER": "Buzzer",
"LANG_PIEZO_BUZZER": "Buzzer", "LANG_PIEZO_BUZZER": "Buzzer",
"LANG_PIEZO_BUZZER_PIN": "PIN", "LANG_PIEZO_BUZZER_PIN": "PIN",
@ -13,4 +13,4 @@
} }
} }
} }
} }

View File

@ -2,92 +2,111 @@ Facilino.LANG_COLOUR_SCREEN = '#ACCE42';
Facilino.LANG_COLOUR_SCREEN_LEDSTRIP = '#8EAC32'; Facilino.LANG_COLOUR_SCREEN_LEDSTRIP = '#8EAC32';
Blockly.Blocks['show_mouth'] = { Blockly.Blocks['show_mouth'] = {
category: Facilino.locales.getKey('LANG_CATEGORY_SCREEN'), category: Facilino.locales.getKey('LANG_CATEGORY_SCREEN'),
subcategory: Facilino.locales.getKey('LANG_SUBCATERGORY_WS2812'), subcategory: Facilino.locales.getKey('LANG_SUBCATERGORY_WS2812'),
category_colour: Facilino.LANG_COLOUR_SCREEN, category_colour: Facilino.LANG_COLOUR_SCREEN,
colour: Facilino.LANG_COLOUR_SCREEN_LEDSTRIP, colour: Facilino.LANG_COLOUR_SCREEN_LEDSTRIP,
helpUrl: Facilino.getHelpUrl('show_mouth'), helpUrl: Facilino.getHelpUrl('show_mouth'),
tags: [], tags: [],
examples: [], examples: [],
init: function() { init: function() {
this.appendDummyInput('').appendField("WS2812 7-Ring").appendField(new Blockly.FieldImage('img/blocks/led_strip.svg', 40*options.zoom, 40*options.zoom)); this.appendDummyInput('').appendField("WS2812 7-Ring").appendField(new Blockly.FieldImage('img/blocks/led_strip.svg', 40 * options.zoom, 40 * options.zoom));
this.appendValueInput('PIN').appendField(Facilino.locales.getKey('LANG_SIMPLEEXPRESSIONS_PIN')).setAlign(Blockly.ALIGN_RIGHT).setCheck(Number); this.appendValueInput('PIN').appendField(Facilino.locales.getKey('LANG_SIMPLEEXPRESSIONS_PIN')).setAlign(Blockly.ALIGN_RIGHT).setCheck(Number);
this.appendDummyInput('').appendField('Expression').appendField(new Blockly.FieldDropdown([['Zeros','zeros'],['Happy Small','happySmall'],['Happy Full','happyFull'],['Sad Small','sadSmall'],['Sad Full','sadFull'],['Neutral','neutral'],['Circle','circle'],['Center','center'],['Hook','hook'],['Upsidedown Hook','upsidedownhook'],['Kooh','kooh'],['Upsidedown Kooh','upsidedownkooh'],['Cross','cross'],['Rect','rect'],['Left Arrow','leftarrow'],['Right Arrow','rightarrow'],['Left Half','lefthalf'],['Right Half','righthalf']]),'EXPRESSION').setAlign(Blockly.ALIGN_RIGHT); this.appendDummyInput('').appendField('Expression').appendField(new Blockly.FieldDropdown([
var colour = new Blockly.FieldColour('#000000'); ['Zeros', 'zeros'],
colour.setColours(['#000000','#808080','#C0C0C0','#FFFFFF','#800000','#FF0000','#808000','#FFFF00','#008000','#00FF00','#008080','#00FFFF','#000080','#0000FF','#800080','#FF00FF']).setColumns(4); ['Happy Small', 'happySmall'],
this.appendDummyInput('').appendField('Color').appendField(colour,'COLOR').setAlign(Blockly.ALIGN_RIGHT); ['Happy Full', 'happyFull'],
this.setPreviousStatement(true,'code'); ['Sad Small', 'sadSmall'],
this.setNextStatement(true,'code'); ['Sad Full', 'sadFull'],
this.setColour(Facilino.LANG_COLOUR_SCREEN_LEDSTRIP); ['Neutral', 'neutral'],
this.setTooltip(""); ['Circle', 'circle'],
} ['Center', 'center'],
}; ['Hook', 'hook'],
['Upsidedown Hook', 'upsidedownhook'],
Blockly.Arduino['show_mouth'] = function(block) { ['Kooh', 'kooh'],
var input_expression = this.getFieldValue('EXPRESSION'); ['Upsidedown Kooh', 'upsidedownkooh'],
var input_color = this.getFieldValue('COLOR'); ['Cross', 'cross'],
var input_pin = Blockly.Arduino.valueToCode(this,'PIN',Blockly.Arduino.ORDER_ATOMIC) || ''; ['Rect', 'rect'],
Blockly.Arduino.definitions_['define_simpleexpressions_h'] = '#include <SimpleExpressions.h>'; ['Left Arrow', 'leftarrow'],
Blockly.Arduino.setups_['setup_simpleexpressions_mouth'] = 'SimpleExpressions.initMouth('+input_pin+');\n'; ['Right Arrow', 'rightarrow'],
var color_rgb=Facilino.hexToRgb(input_color); ['Left Half', 'lefthalf'],
var code='SimpleExpressions.writeMouth("'+input_expression+'",'+color_rgb.r +','+color_rgb.g+','+color_rgb.b+');\n' ; ['Right Half', 'righthalf']
code+= '\n'; ]), 'EXPRESSION').setAlign(Blockly.ALIGN_RIGHT);
return code; var colour = new Blockly.FieldColour('#000000');
colour.setColours(['#000000', '#808080', '#C0C0C0', '#FFFFFF', '#800000', '#FF0000', '#808000', '#FFFF00', '#008000', '#00FF00', '#008080', '#00FFFF', '#000080', '#0000FF', '#800080', '#FF00FF']).setColumns(4);
this.appendDummyInput('').appendField('Color').appendField(colour, 'COLOR').setAlign(Blockly.ALIGN_RIGHT);
this.setPreviousStatement(true, 'code');
this.setNextStatement(true, 'code');
this.setColour(Facilino.LANG_COLOUR_SCREEN_LEDSTRIP);
this.setTooltip("");
}
}; };
Blockly.Arduino.dyor_piezo_buzzer_predef_sounds = function() { Blockly.Arduino['show_mouth'] = function(block) {
var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN', Blockly.Arduino.ORDER_ATOMIC) || ''; var input_expression = this.getFieldValue('EXPRESSION');
var code= ''; var input_color = this.getFieldValue('COLOR');
Blockly.Arduino.definitions_['define_simpleexpressions_h'] = '#include <SimpleExpressions.h>'; var input_pin = Blockly.Arduino.valueToCode(this, 'PIN', Blockly.Arduino.ORDER_ATOMIC) || '';
Blockly.Arduino.setups_['setup_simpleexpressions_buzzer'] = 'SimpleExpressions.initBuzzer('+dropdown_pin+');\n'; Blockly.Arduino.definitions_['define_simpleexpressions_h'] = '#include <SimpleExpressions.h>';
code='SimpleExpressions.playSound('+this.getFieldValue('OPTION')+');\n'; Blockly.Arduino.setups_['setup_simpleexpressions_mouth'] = 'SimpleExpressions.initMouth(' + input_pin + ');\n';
return code; var color_rgb = Facilino.hexToRgb(input_color);
}; var code = 'SimpleExpressions.writeMouth("' + input_expression + '",' + color_rgb.r + ',' + color_rgb.g + ',' + color_rgb.b + ');\n';
code += '\n';
Blockly.Blocks.dyor_piezo_buzzer_predef_sounds = { return code;
category: Facilino.locales.getKey('LANG_CATEGORY_SOUND'), };
subcategory: Facilino.locales.getKey('LANG_SUBCATEGORY_BUZZER'),
tags: ['buzzer','sound'], Blockly.Arduino.dyor_piezo_buzzer_predef_sounds = function() {
helpUrl: Facilino.getHelpUrl('dyor_piezo_buzzer_predef_sounds'), var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN', Blockly.Arduino.ORDER_ATOMIC) || '';
examples: [''], var code = '';
category_colour: Facilino.LANG_COLOUR_SOUND, Blockly.Arduino.definitions_['define_simpleexpressions_h'] = '#include <SimpleExpressions.h>';
colour: Facilino.LANG_COLOUR_SOUND_BUZZER, Blockly.Arduino.setups_['setup_simpleexpressions_buzzer'] = 'SimpleExpressions.initBuzzer(' + dropdown_pin + ');\n';
//dyor_piezo_buzzer initialization code = 'SimpleExpressions.playSound(' + this.getFieldValue('OPTION') + ');\n';
init: function() { return code;
this.setColour(Facilino.LANG_COLOUR_SOUND_BUZZER); };
this.appendDummyInput('')
.appendField(Facilino.locales.getKey('LANG_PIEZO_BUZZER')) Blockly.Blocks.dyor_piezo_buzzer_predef_sounds = {
.appendField(new Blockly.FieldImage('img/blocks/buzzer.svg', 52*options.zoom, 35*options.zoom)); category: Facilino.locales.getKey('LANG_CATEGORY_SOUND'),
this.appendValueInput('PIN') subcategory: Facilino.locales.getKey('LANG_SUBCATEGORY_BUZZER'),
.appendField(Facilino.locales.getKey('LANG_PIEZO_BUZZER_PIN')).appendField(new Blockly.FieldImage("img/blocks/pwm_signal.svg",24*options.zoom,24*options.zoom)) tags: ['buzzer', 'sound'],
.setCheck(Number) helpUrl: Facilino.getHelpUrl('dyor_piezo_buzzer_predef_sounds'),
.setAlign(Blockly.ALIGN_RIGHT); examples: [''],
this.appendDummyInput('').appendField(new Blockly.FieldImage('img/blocks/speaker.svg', 24*options.zoom, 24*options.zoom)) category_colour: Facilino.LANG_COLOUR_SOUND,
.appendField(new Blockly.FieldDropdown([ colour: Facilino.LANG_COLOUR_SOUND_BUZZER,
['CONNECTION', '0'], //dyor_piezo_buzzer initialization
['DISCONNECTION', '1'], init: function() {
['BUTTON PUSHED', '2'], this.setColour(Facilino.LANG_COLOUR_SOUND_BUZZER);
['MODE 1', '3'], this.appendDummyInput('')
['MODE 2', '4'], .appendField(Facilino.locales.getKey('LANG_PIEZO_BUZZER'))
['MODE 3', '5'], .appendField(new Blockly.FieldImage('img/blocks/buzzer.svg', 52 * options.zoom, 35 * options.zoom));
['SURPRISE', '6'], this.appendValueInput('PIN')
['OHOOH', '7'], .appendField(Facilino.locales.getKey('LANG_PIEZO_BUZZER_PIN')).appendField(new Blockly.FieldImage("img/blocks/pwm_signal.svg", 24 * options.zoom, 24 * options.zoom))
['OHOOH2', '8'], .setCheck(Number)
['CUDDLY', '9'], .setAlign(Blockly.ALIGN_RIGHT);
['SLEEPING','10'], this.appendDummyInput('').appendField(new Blockly.FieldImage('img/blocks/speaker.svg', 24 * options.zoom, 24 * options.zoom))
['HAPPY','11'], .appendField(new Blockly.FieldDropdown([
['SUPER_HAPPY','12'], ['CONNECTION', '0'],
['HAPPY_SHORT','13'], ['DISCONNECTION', '1'],
['SAD','14'], ['BUTTON PUSHED', '2'],
['CONFUSED','15'], ['MODE 1', '3'],
['FART1','16'], ['MODE 2', '4'],
['FART2','17'], ['MODE 3', '5'],
['FART3','18'], ['SURPRISE', '6'],
['PIRATES','19'] ['OHOOH', '7'],
]), 'OPTION').setAlign(Blockly.ALIGN_RIGHT); ['OHOOH2', '8'],
this.setInputsInline(false); ['CUDDLY', '9'],
this.setPreviousStatement(true,'code'); ['SLEEPING', '10'],
this.setNextStatement(true,'code'); ['HAPPY', '11'],
this.setTooltip(Facilino.locales.getKey('LANG_PIEZO_BUZZER_PREDEF_SOUNDS_TOOLTIP')); ['SUPER_HAPPY', '12'],
} ['HAPPY_SHORT', '13'],
}; ['SAD', '14'],
['CONFUSED', '15'],
['FART1', '16'],
['FART2', '17'],
['FART3', '18'],
['PIRATES', '19']
]), 'OPTION').setAlign(Blockly.ALIGN_RIGHT);
this.setInputsInline(false);
this.setPreviousStatement(true, 'code');
this.setNextStatement(true, 'code');
this.setTooltip(Facilino.locales.getKey('LANG_PIEZO_BUZZER_PREDEF_SOUNDS_TOOLTIP'));
}
};