Writing custom IR app

I want to write a C++ app that will send three different IR signals to a device on a preset interval. I have a basic idea of how to write this, but I can’t seem to find the documentation about how to get my code to interact with the FlipperZero’s hardware. Can someone point me in that direction? I’m thinking about storing the IR values in arrays then calling on them like this

    while (true) {
        sendIRSignal(red);
        sleep(900000); // Sleep for 15 minutes (900000 milliseconds)

        sendIRSignal(purp);
        sleep(900000);

        sendIRSignal(pink);
        sleep(900000);
    }

Search for the magnifying glass on this website/forum. Search for ‘ir cli’. Get echo 'ir tx NEC 0x40 0x1A' > /dev/ttyACM0 as example.

1 Like

Interesting. So I would have to manually send a code like

ir tx RAW F:38000 DC:33 9245 4579 596 560 590 … [rest of the data]

to turn my LED lights to pink. Is there a way to automate this between three different colors? I’m thinking a simple bash script would work, like

#!/bin/bash

while true; do
    ir tx RAW F:38000 DC:33 [RAW DATA FOR Red]

    sleep 900

    ir tx RAW F:38000 DC:33 [RAW DATA FOR Purp]

    sleep 900

    ir tx RAW F:38000 DC:33 [RAW DATA FOR Pink]

    sleep 900

done

Since my example is bash and you already figured out how to send ‘type: raw’ instead of ‘type: parsed’, you are asking from initially c++ to bash how to create a loop?
I think this is pretty easy to get done with a little googeling.

The flipper cli doesn’t support running bash scripts though. So how could I get this to loop indefinitely?

I was able to accomplish this using PowerShell:

$portName = "COM3"

$serialPort = new-object System.IO.Ports.SerialPort $portName, 230400, None, 8, One
$serialPort.ReadTimeout = 2000
$serialPort.WriteTimeout = 1000

Function Send-Command($command) {
    $serialPort.DiscardInBuffer()  
    $serialPort.WriteLine($command + "`r")
    Start-Sleep -Milliseconds 1000 
}

try {
    $serialPort.Open()

    while ($true) {
        $colors = @(
            @{Name="Red";   Command="ir tx RAW F:38000 DC:33 9224 4565 621 533 620 533 621 533 618 533 619 532 621 532 620 532 593 558 616 1648 620 1648 619 1647 621 1646 619 532 620 1648 620 1648 619 1647 619 532 620 533 618 532 621 1647 619 533 621 533 618 531 621 532 619 1648 616 1647 614 1647 588 557 614 1647 617 1647 617 1646 618 1647 621 41223 9231 2275 616 96785 9166 2275 616 96777 9131 2275 614 96806 9121 2274 614 96858 9208 2282 618"},
            @{Name="Pink";  Command="ir tx RAW F:38000 DC:33 9245 4579 596 560 590 558 591 558 591 560 588 559 590 559 590 559 590 559 590 1680 591 1680 594 1679 591 1681 589 559 591 1680 592 1680 593 1680 593 1681 595 1681 594 560 594 559 595 1681 594 559 594 558 597 559 595 559 595 560 592 1681 591 1681 590 559 591 1681 590 1679 591 1681 590 41468 9159 2287 590 97307 9215 2286 595 97358 9268 2287 596 97293 9260 2288 595 97310 9243 2286 596 97293 9236 2288 593 97318 9237 2286 595 97320 9281 2286 598"},
            @{Name="Purple";Command="ir tx RAW F:38000 DC:33 9395 4581 602 559 600 560 606 561 604 560 604 557 608 561 609 562 606 561 608 1683 599 1678 601 1679 594 1678 592 557 591 1679 592 1678 597 1682 592 556 595 1678 594 556 594 557 593 1678 595 557 595 557 594 558 594 1678 604 559 601 1680 601 1679 601 560 599 1680 599 1679 595 1679 594 41501 9245 2288 597 97349 9296 2286 598"}
        )

        foreach ($color in $colors) {
            Send-Command $color.Command

            Write-Output ("Displaying " + $color.Name + " color. Next color shift in 15 minutes.")

            for ($i = 15; $i -gt 0; $i--) {
                Write-Output ("Time until next color shift: " + $i + " minutes remaining.")
                Start-Sleep -Seconds 60  
            }
        }
    }

} catch {
    Write-Error "Failed to communicate with the device on $portName"
} finally {
    if ($serialPort.IsOpen) {
        $serialPort.Close()
    }
}
2 Likes

Nice. Even if Bash or C++ would be the same. Just write a loop and execute the command.
The solution is to write the loop outside the commands.
The multidimensional array is good readable, I would use a hashtable in PS. But this is more a personal thing. You solution is easier to port to other languages.

In the logic you are testing the serial prot and have a second loop within the connection. But the tru will not catch what happen if the Flipper is disconnected. On the other hand the connection is kept alive and not opened/closed every time.

Take a look at the three colours, you’ll see purple is shorter as the other two. You can cut the other two as well, since 97358 9268 2287 596 97293 9260 2288 595 97310 9243 is just a repeat signal.
Without further analysis I can’t say if 41468 9159 [...] already can be cut or if this is the stop bit.

2 Likes