Sending commands to system with variables using custom controls


I would like to implement simple custom control with slider, that would use the value in a command that is sent to the system.

The command would be: v4l2-ctl -d /dev/video0 -c brightness=xxx

where xxx would be variable set by the slicer.

I've checked around, but I have not seen a solution that would mention the ability to use variables in system commands.

Is there a way how to do this?

Thank you

Custom controls only work with either

  • Individual gcode commands
  • Gcode scripts
  • Javascript snippets

You may be able to work around this, by some kind of magic work with the 'gcode system commands' plugin:

However this will still not do what you want with the sliders.

Your best bet to get something this custom, would be to write your own plugin that injected the code. I appreciate this is quite a lot more complicated, but there is only so far custom controls can go.

Hello, thank you for the reply.

The GCODE System Commands does not support variables, at least ot my knowledge, therefore it indeed can't do what I want.

I tried using a simple static command to change the brightness, but that did not work either and at this point I dont know what am I doing wrong using these:

- children:
  - command: OCTO911
    confirm: null
    enabled: true
    name: Test Command 1
  layout: vertical
  name: Camera Control 1


    - command: v4l2-ctl -c brightness=1
      id: '911'

EDIT: Actually scratch the part about it not working, it works only when the printer is connected even though the command is in theory not meant for the printer.
When I connect the printer, it works as expected.

Yep, the commands can only be sent if there is a printer connected. You might be able to create say 5 buttons, 0%, 25%, 50%, 75%, 100%, etc. to work around this. Not exactly what you were hoping for, but maybe it will get close.

Yes, this was the less flexible option.

The idea was to have something less complex than what /webcam/control.htm offers, but placed on the "Controls" page. Bonus of that would be that I could also import these controls into OctoRemote.

Instead I'll most probably just create two presets, one for daytime and one for nighttime.

1 Like

Yeah, to be able to do it without a printer connected I think you would have to create a custom plugin and utilize simplApiPlugin mixin. Here's an example of sliders for custom controls.

These sliders are however not sending commands to the PI.

right, but with the proper tweaks it would be possible I think to use the same sliders with javascript commands instead of gcode commands and a single file simpleApiPlugin mixin implementation. Can't remember if JavaScript buttons are locked while not connected or not. Then you would use the command OctoPrint.SimpleApiCommand("pluginid","command", {parameter: get_value_from_parameter}). Would have to double check that javascript commands would support the parameters though. It might even be possible to wrap the whole thing in a plugin using a settings_overlay in the single file plugin. Would be a good challenge for @Charlie_Powell.

nix that, javascript type doesn't allow for passing parameters so it would be a little trickier with some jQuery selector magic to get the parameters.

OctoPrint.SimpleApiCommand("pluginid","command", {parameter: $(selector).val()}) or something like that.

BTW, if your control has a property of enabled set to true it will always be enabled I think.

-   children:
    -   additionalClasses: row-fluid
        -   default: 100
            enabled: true
            parameter: feed_rate
                max: 200
                min: 0
                step: 1
        javascript: 'OctoPrint.simpleApiCommand("my_endpoint", "my_command", {"parameter":
            $("#control-jog-custom > div > div > div > form > div > input[type=number]").val()});'
        name: Test Button
        type: javascript
        width: 3
    layout: horizontal_grid
    name: Test

It does have it enabled, however it didnt work, since I was using GCode system command.

And I think we are trying to reinvent the wheel. Obviously /webcam/control.htm knows how to exactly this, except it is on separate webpage.

1 Like