UNPKG

node-red-contrib-johnny-five

Version:

A set of node-red nodes for using johnny-five and IO plugins

110 lines (102 loc) 4.49 kB
<script type="text/javascript"> RED.nodes.registerType('j5-gpio-out', { category: 'johnny-five', defaults: { name: {value: ''}, state: {value: 'OUTPUT', required: true}, pin: {value: '', required: false}, i2cDelay: {value: '0', required: false}, i2cAddress: {value: '', required: false}, i2cRegister: {value: '', required: false}, outputs: {value: 0}, platform: {type: 'j5-platform', required: true} }, color: '#E2D96E', inputs: 1, outputs: 0, icon: 'j5-logo.png', align: 'right', paletteLabel: 'gpio out', label() { console.log('name', 'gpio' + (this.pin || this.i2cAddress || '')); return this.name || 'gpio' + (this.pin || this.i2cAddress || ''); }, oneditprepare() { const self = this; function showI2C() { $('#node-div-i2cAddressRow').show(); $('#node-div-i2cRegisterRow').show(); $('#node-div-i2cDelayRow').show(); $('#node-div-pinRow').hide(); $('#node-div-formTipRow').hide(); } function hideI2C() { $('#node-div-i2cAddressRow').hide(); $('#node-div-i2cRegisterRow').hide(); $('#node-div-i2cDelayRow').hide(); $('#node-div-pinRow').show(); $('#node-div-formTipRow').show(); } if (self.state === 'I2C_READ_REQUEST' || self.state === 'I2C_WRITE_REQUEST' || self.state === 'I2C_DELAY') { showI2C(); } else { hideI2C(); } const stateInput = $('#node-input-state'); stateInput.change(function () { console.log('stateInput changed', this.value); if (this.value === 'I2C_READ_REQUEST' || this.value === 'I2C_WRITE_REQUEST' || this.value === 'I2C_DELAY') { showI2C(); } else { hideI2C(); } }); }, oneditsave(a) { const stateInput = $('#node-input-state'); if (stateInput.val() === 'I2C_READ_REQUEST') { this.outputs = 1; } else { this.outputs = 0; } console.log('saving', this, a, stateInput.val()); } }); </script> <script type="text/x-red" data-template-name="j5-gpio-out"> <div class="form-row"> <label for="node-input-platform"><i class="fa fa-tasks"></i> Platform</label> <input type="text" id="node-input-platform"> </div> <div class="form-row"> <label for="node-input-state"><i class="fa fa-wrench"></i> Type</label> <select type="text" id="node-input-state" style="width: 200px;"> <option value="OUTPUT">Digital (0/1)</option> <option value="PWM">PWM (0-255)</option> <option value="SERVO">Servo (0-180)</option> <option value="I2C_READ_REQUEST">I2C Read Request</option> <option value="I2C_WRITE_REQUEST">I2C Write Request</option> <option value="I2C_DELAY">I2C Delay</option> </select> </div> <div class="form-row" id="node-div-pinRow"> <label for="node-input-pin"><i class="fa fa-circle"></i> Pin</label> <input type="text" id="node-input-pin" placeholder="13"> </div> <div class="form-row" id="node-div-i2cAddressRow"> <label for="node-input-i2cAddress"><i class="fa fa-circle"></i> I2C Address</label> <input type="text" id="node-input-i2cAddress" placeholder="13"> </div> <div class="form-row" id="node-div-i2cRegisterRow"> <label for="node-input-i2cRegister"><i class="fa fa-circle"></i> Register (optional)</label> <input type="text" id="node-input-i2cRegister"> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-tips" id="node-div-formTipRow"><b>Note:</b> You cannot use the same pin for both output and input.</div> </script> <script type="text/x-red" data-help-name="j5-gpio-out"> <p>gpio output node. A node for sending data to General Purpose Input and Outputs (GPIOs) pins though the use of johnny-five I/O Plugins</p> </script>