mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	adding frequency configuration to pwm output (#1206)
This commit is contained in:
		
				
					committed by
					
						
						Dave Conway-Jones
					
				
			
			
				
	
			
			
			
						parent
						
							5c2e7ce407
						
					
				
				
					commit
					b2390f1caf
				
			@@ -193,6 +193,10 @@
 | 
			
		||||
        </select>
 | 
			
		||||
    </div>
 | 
			
		||||
    <br/>
 | 
			
		||||
    <div class="form-row" id="node-set-freq">
 | 
			
		||||
        <label for="node-input-freq"> <span data-i18n="rpi-gpio.label.freq"></span></label>
 | 
			
		||||
        <input type="text" id="node-input-freq" placeholder="100">
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="form-row">
 | 
			
		||||
        <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
 | 
			
		||||
        <input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
 | 
			
		||||
@@ -210,6 +214,7 @@
 | 
			
		||||
    <p>When using PWM mode - expects an input value of a number 0 - 100. It can be floating point.</p>
 | 
			
		||||
    <p>PWM mode can be used to drive a servo using input values between 10 and 20 only.
 | 
			
		||||
    The GPIO2 pin is best for this as it uses hardware to do the PWM.</p>
 | 
			
		||||
    <p>Setting high PWM frequency might occupy more CPU than expected (default is 100Hz)</p>
 | 
			
		||||
    <p>Requires the RPi.GPIO python library version 0.5.10 (or better) in order to work.</p>
 | 
			
		||||
    <p><b>Note:</b> we are using the actual physical pin numbers on connector P1 as they are easier to locate.</p>
 | 
			
		||||
</script>
 | 
			
		||||
@@ -224,6 +229,7 @@
 | 
			
		||||
            pin: { value:"",required:true,validate:RED.validators.number() },
 | 
			
		||||
            set: { value:"" },
 | 
			
		||||
            level: { value:"0" },
 | 
			
		||||
            freq: {value:""},
 | 
			
		||||
            out: { value:"out" }
 | 
			
		||||
        },
 | 
			
		||||
        inputs:1,
 | 
			
		||||
@@ -297,11 +303,13 @@
 | 
			
		||||
                    $('#node-input-set').prop('checked', false);
 | 
			
		||||
                    $("#dig-tip").hide();
 | 
			
		||||
                    $("#pwm-tip").show();
 | 
			
		||||
                    $('#node-set-freq').show();
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    $('#node-set-tick').show();
 | 
			
		||||
                    $("#dig-tip").show();
 | 
			
		||||
                    $("#pwm-tip").hide();
 | 
			
		||||
                    $('#node-set-freq').hide();
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
            $("#node-input-out").change(function () { hidestate(); });
 | 
			
		||||
 
 | 
			
		||||
@@ -137,6 +137,7 @@ module.exports = function(RED) {
 | 
			
		||||
        this.pin = n.pin;
 | 
			
		||||
        this.set = n.set || false;
 | 
			
		||||
        this.level = n.level || 0;
 | 
			
		||||
        this.freq = n.freq || 100;
 | 
			
		||||
        this.out = n.out || "out";
 | 
			
		||||
        var node = this;
 | 
			
		||||
        if (!pinsInUse.hasOwnProperty(this.pin)) {
 | 
			
		||||
@@ -173,7 +174,7 @@ module.exports = function(RED) {
 | 
			
		||||
                node.child = spawn(gpioCommand, [node.out,node.pin,node.level]);
 | 
			
		||||
                node.status({fill:"green",shape:"dot",text:node.level});
 | 
			
		||||
            } else {
 | 
			
		||||
                node.child = spawn(gpioCommand, [node.out,node.pin]);
 | 
			
		||||
                node.child = spawn(gpioCommand, [node.out,node.pin,node.freq]);
 | 
			
		||||
                node.status({fill:"green",shape:"dot",text:"common.status.ok"});
 | 
			
		||||
            }
 | 
			
		||||
            node.running = true;
 | 
			
		||||
 
 | 
			
		||||
@@ -35,8 +35,13 @@ if len(sys.argv) > 2:
 | 
			
		||||
 | 
			
		||||
    if cmd == "pwm":
 | 
			
		||||
        #print "Initialised pin "+str(pin)+" to PWM"
 | 
			
		||||
        try: 
 | 
			
		||||
            freq = int(sys.argv[3])
 | 
			
		||||
        except:
 | 
			
		||||
            freq = 100
 | 
			
		||||
 | 
			
		||||
        GPIO.setup(pin,GPIO.OUT)
 | 
			
		||||
        p = GPIO.PWM(pin, 100)
 | 
			
		||||
        p = GPIO.PWM(pin, freq)
 | 
			
		||||
        p.start(0)
 | 
			
		||||
 | 
			
		||||
        while True:
 | 
			
		||||
 
 | 
			
		||||
@@ -649,7 +649,8 @@
 | 
			
		||||
            "pikeyboard": "Pi Keyboard",
 | 
			
		||||
            "left": "Left",
 | 
			
		||||
            "right": "Right",
 | 
			
		||||
            "middle": "Middle"
 | 
			
		||||
            "middle": "Middle",
 | 
			
		||||
            "freq": "Frequency (Hz)"
 | 
			
		||||
        },
 | 
			
		||||
        "resistor": {
 | 
			
		||||
            "none": "none",
 | 
			
		||||
@@ -671,7 +672,7 @@
 | 
			
		||||
            "pin": "<b>Pins in Use</b>: ",
 | 
			
		||||
            "in": "Tip: Only Digital Input is supported - input must be 0 or 1.",
 | 
			
		||||
            "dig": "Tip: For digital output - input must be 0 or 1.",
 | 
			
		||||
            "pwm": "Tip: For PWM output - input must be between 0 to 100."
 | 
			
		||||
            "pwm": "Tip: For PWM output - input must be between 0 to 100; setting high frequency might occupy more CPU than expected."
 | 
			
		||||
        },
 | 
			
		||||
        "types": {
 | 
			
		||||
            "digout": "digital output",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user