I'm looking for suggestion and a bit of guidance if any of you had a similar problem. I have 2 LED (green, red, dedicated pins) that I can control. The available commands are On / Off / Toggle.
I have written a small program in C to control the LEDs, and I can run it simply in terminal FreeBSD:
- led 1 : OFF green LED
- led 2 : ON green LED
- led 3 : blink green LED
- led 4 : OFF red LED
- led 5 : ON red LED
- led 6 : blink red LED
Now when it comes to blinking it is a bit more complicated, because it stays in the loop. I can use a timer, but that's not very useful to me ('cause I don't know for how long I will need it blinking).
while (1) {
gpio_pin_high(handle, pin);
sleep(1);
gpio_pin_low(handle, pin);
sleep(1);
}
My goal is to use LED blinking when a process starts - let's say it waiting to connect to WiFi. And when connected, use LED on.
I guess I can use fork() only for the blinking function, and when I want to turn LED on after having it blinking, I should check for the child process, stop and clean it up, and then call led_on function.
Thank you in advance for any ideas