1import{TutorialBlockly}from"../tutorial/blockly_api.js";import{BlocklyTutorialBlocks}from"../tutorial/blockly_blocks.js";import{categories,code}from"../tutorial/tutorial_blocks.js";import{util}from"../util_general.js";import{msg}from"../msg/messages.js";import{vexiq_state as iqst}from"../interfaces/vexiq_state.js";const NONE=msg.NONE_SQB;export class VexIQBlocklyTutorialBlocks extends BlocklyTutorialBlocks{async createCategoryDefs(){await import("../blockly/blocks_vexiq_b.js");let e="";function t(t){e+=`<block type="${t}"/>`,Blockly.JavaScript[t]=code.getWidgetValue}t("vexiq_bumper_pressing"),t("vexiq_touchled_pressing"),t("vexiq_colorsensor_colorname3"),t("vexiq_colorsensor_colorname12"),e+='\n <block type="vexiq_ColorHue_get_name">\n <value name="p0">\n <shadow type="math_number">\n <field name="NUM">0</field>\n </shadow>\n </value>\n </block>',Blockly.JavaScript.vexiq_ColorHue_get_name=codeiq.colorGetName,t("vexiq_colorsensor_grayscale"),t("vexiq_sonar_distance"),t("vexiq_gyro_heading"),t("vexiq_gyro_rotation"),t("vexiq_motor_rotation"),t("vexiq_motor_velocity"),e+=`\n <block type="vexiq_motor_spin">\n <field name="WIDGET_ID">${NONE}</field>\n <field name="p0">FWD</field>\n <field name="p2">PCT</field>\n <value name="p1">\n <shadow type="math_number">\n <field name="NUM">100</field>\n </shadow>\n </value>\n </block>`,Blockly.JavaScript.vexiq_motor_spin=codeiq.motorSpin,e+=`\n <block type="vexiq_motor_stop">\n <field name="WIDGET_ID">${NONE}</field>\n <field name="p0">HOLD</field>\n </block>`,Blockly.JavaScript.vexiq_motor_stop=codeiq.motorStop,e+=`\n <block type="vexiq_touchled_on">\n <field name="WIDGET_ID">${NONE}</field>\n <field name="p0">#FF8800</field>\n <field name="p1">100</field>\n </block>`,Blockly.JavaScript.vexiq_touchled_on=codeiq.ledOn,e+=`\n <block type="vexiq_touchled_off">\n <field name="WIDGET_ID">${NONE}</field>\n </block>`,Blockly.JavaScript.vexiq_touchled_off=codeiq.ledOff;const o={uiName:msg.blockly.DEVICES,toolboxXml:e},r=await super.createCategoryDefs();return util.insertBefore(r,categories.logic,o),r}}var convert;!function(e){e.color12=function(e,t){return t?e<=iqst.LedOutput.RedOrange?iqst.LedOutput.Red:e<=iqst.LedOutput.Green?iqst.LedOutput.Green:e<=iqst.LedOutput.Violet?iqst.LedOutput.Blue:iqst.LedOutput.Red:e},e.distanceRaw=function(e,t){switch(t){case"MM":return.4*e;case"CM":return.04*e;case"IN":return.015748*e;default:throw new Error("Invalid distance unit: "+t)}},e.gyroAngleDeg=function(e,t){switch(t){case"DEG":return e;case"REV":return e/360;case"RAW":return e/360*65536;default:throw new Error("Invalid gyro angle unit: "+t)}},e.motorRotationDeg=function(e,t){switch(t){case"REV":return e/360;case"RAW":return e/.375;case"DEG":return e;default:throw new Error("Invalid motor rotation unit: "+t)}},e.velocity=function(e,t,o){return t===o?e:function(e,t){switch(t){case"RPM":return Math.trunc(e/6);case"PCT":return Math.trunc(e/7.2);case"RAW":return Math.trunc(e/5.714285714);case"DPS":return e;default:throw new Error("Invalid velocity unit: "+t)}}(function(e,t){switch(t){case"RPM":return Math.trunc(6*e);case"PCT":return Math.trunc(7.2*e);case"RAW":return Math.trunc(5.714285714*e);case"DPS":return e;default:throw new Error("Invalid velocity unit: "+t)}}(e,t),o)}}(convert||(convert={}));export class TutorialVexIQBlockly extends TutorialBlockly{vexiq_bumper_pressing(e){return this.getDeviceValue(e)}vexiq_touchled_pressing(e){return this.getDeviceValue(e).pressed}vexiq_colorsensor_grayscale(e){return this.getDeviceValue(e).grayscale}vexiq_colorsensor_colorname3(e){const t=this.getDeviceValue(e);return convert.color12(t.namedColor,!0)}vexiq_colorsensor_colorname12(e){const t=this.getDeviceValue(e);return convert.color12(t.namedColor,!1)}vexiq_sonar_distance(e,t){let o=this.getDeviceValue(e);return o/=.04,convert.distanceRaw(o,t)}vexiq_gyro_heading(e,t){let o=this.getDeviceValue(e);return o>360?o%=360:o<0&&(o=o%360+360),convert.gyroAngleDeg(o,t)}vexiq_gyro_rotation(e,t){const o=this.getDeviceValue(e);return convert.gyroAngleDeg(o,t)}vexiq_motor_rotation(e,t){const o=this.getDeviceValue(e);return convert.motorRotationDeg(o.position,t)}vexiq_motor_velocity(e,t){const o=this.getDeviceValue(e);return convert.velocity(o.velocity,"DPS",t)}vexiq_ColorHue_get_name(e){return ColorNames[e]}vexiq_motor_spin(e,t,o,r){if(0===o)return void this.vexiq_motor_stop(e,"HOLD");"UNDEFINED"!==t&&(o="FWD"===t?o:-o);const i=convert.velocity(o,r,"DPS"),n=this.getWidget(e),l=n.type===iqst.VexDeviceType.motor_rp;n.setValueProperty("reverse",l),n.setValueProperty("setVelocity",i),n.setValueProperty("targetPosition",null),n.setValueProperty("holdPosition",null),n.setValueProperty("flagReachedTarget",!1)}vexiq_motor_stop(e,t){const o=this.getWidget(e),r=o.type===iqst.VexDeviceType.motor_rp;o.setValueProperty("reverse",r),o.setValueProperty("setVelocity",0),o.setValueProperty("targetPosition",null),o.setValueProperty("holdPosition",null),o.setValueProperty("flagReachedTarget",!1)}vexiq_touchled_on(e,t,o){const r=this.getWidget(e),i={r:parseInt(t.substring(1,3),16),g:parseInt(t.substring(3,5),16),b:parseInt(t.substring(5,7),16),bri:o};r.setValueProperty("color",i),r.setValueProperty("isOn",o>0),r.setValueProperty("isBlinking",void 0)}vexiq_touchled_off(e){const t=this.getWidget(e);t.setValueProperty("isOn",void 0),t.setValueProperty("isBlinking",void 0)}}const ColorNames=["NONE","RED","RED_ORANGE","ORANGE","YELLOW_ORANGE","YELLOW","YELLOW_GREEN","GREEN","BLUE_GREEN","BLUE","BLUE_VIOLET","VIOLET","RED_VIOLET","WHITE"];var codeiq;!function(e){function t(e,...t){return`tut.${e}(${t?t.join(", "):""})`}e.colorGetName=function(e){const o=Blockly.JavaScript.valueToCode(e,"p0",Blockly.JavaScript.ORDER_ATOMIC);return code.returnValue(t("vexiq_ColorHue_get_name",o))},e.motorSpin=function(e){const o=code.getValueStr(e,"WIDGET_ID"),r=code.getValueStr(e,"p0","FWD"),i=Blockly.JavaScript.valueToCode(e,"p1",Blockly.JavaScript.ORDER_ATOMIC)||0,n=code.getValueStr(e,"p2","PCT");return code.lines(t("vexiq_motor_spin",o,r,i,n))},e.motorStop=function(e){const o=code.getValueStr(e,"WIDGET_ID"),r=code.getValueStr(e,"p0","HOLD");return code.lines(t("vexiq_motor_stop",o,r))},e.ledOn=function(e){const o=code.getValueStr(e,"WIDGET_ID"),r=code.getValueStr(e,"p0","#FF8800"),i=code.getValueNum(e,"p1","100");return code.lines(t("vexiq_touchled_on",o,r,i))},e.ledOff=function(e){const o=code.getValueStr(e,"WIDGET_ID");return code.lines(t("vexiq_touchled_off",o))}}(codeiq||(codeiq={}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.