hzeller / rpi-rgb-led-matrix

Controlling up to three chains of 64x64, 32x32, 16x32 or similar RGB LED displays using Raspberry Pi GPIO
GNU General Public License v2.0
3.64k stars 1.16k forks source link

Terminating a demo #684

Open D9X6 opened 6 years ago

D9X6 commented 6 years ago

Disclaimer: I'm a novice programmer.

Currently, I've set up a webpage and flask web server on my Pi. For the moment, I've 2 buttons on that HTML webpage.

<script>
    $(document).ready(function() {
      $('#led_on').click(function() {
        console.log('LED on!')
      })
      $('#led_off').click(function() {
        console.log('LED off!')
      })
    });
  </script>

That looks like this github help

Currently, I can get the Pi to display a demo (Demo 7, Conways game of life) on my panels successful using an @app.route() command. I plan on tying these buttons to this route.

@app.route("/led/<int:led_state>")
def led(led_state):
    if led_state == 1:
        pi_thing.start_led()
    elif led_state == 0:
        pi_thing.stop_led()

    return 'State: {0}'.format(led_state)

This is my start_led() command, mentioned above.

def start_led(self):
        subprocess.call(["sudo", "../rpi-rgb-led-matrix/examples-api-use/demo", "-D 7", "--led-cols=64", "--led-slowdown-gpio=2", "--led-chain=4", "--led-brightness=100", "-m", "60"])

I would like to make a stop_led() function but I am not sure how to go about doing that. How will I be able to stop the demo using a script? Is it necessary to use a script for that?

I know I can always use CTRL-C in the terminal but the point is to rely on the webpage and not a terminal to start and stop that demo.

Thank you to anyone who read this far, any help or suggestions are appreciated.

D9X6 commented 6 years ago

I'm wondering if I would somehow be able to pass a keyboard stroke (CTRL+C) to the terminal from the webpage... or would that be improper?

hzeller commented 6 years ago

You should not use subprocesses to start the LED, but rather write a little network interface which allows you to interact with the program to show different things.

Running a webserver that is able to execute sudo is very dangerous from the security perspective. It is also not very nice to start and stop the LED matrix as you might create visible glitches on the output.

w.r.t. to the question: you can send a kill command to the process.

D9X6 commented 6 years ago

Hi @hzeller! Thank you very much for your response.

...but rather write a little network interface which allows you to interact with the program to show different things.

Since I am a novice, are there any resources you can point me in the direction towards? Maybe a general Google search on the matter might suffice - what keywords should I search to learn how to go about doing this? I had a look at some of the demo programs using the Python bindings. I'm very interested in the image-scroller functionality of your library. Eventually I'd like my webpage to have an option to choose a .ppm image and have it scrolled across the panels at the press of a button.

Running a webserver that is able to execute sudo is very dangerous from the security perspective. It is also not very nice to start and stop the LED matrix as you might create visible glitches on the output.

That makes sense to me. You're right about the glitches - at one point, I had multiple demos running simultaneously on my panels.

Thank you for your time and efforts :)