matdombrock / potatojuce

0 stars 0 forks source link

GPIO to MIDI Driver #1

Open matdombrock opened 1 year ago

matdombrock commented 1 year ago

Basic Idea

We need to make a driver that talks to our GPIO pins and turns them into MIDI CC messages which will be sent to JUCE.

The main priorities are:

GPIO Header Info:

https://www.libre.computer/blogs/gpio-headers-reference-for-aml-s905x-cc/

image (source)

Example Code?

Reading a rotary encoder in C++ might be as simple as this:

#include <wiringPi.h>

int main(void)
{
    wiringPiSetup();
    pinMode(0, INPUT);
    pinMode(1, INPUT);
    int lastState = 0;
    int currentState = 0;
    int count = 0;

    while(1)
    {
        currentState = digitalRead(0);
        if(currentState != lastState)
        {
            if(digitalRead(1) != currentState)
            {
                count++;
            }
            else
            {
                count--;
            }
            lastState = currentState;
            printf("Count: %d\n", count);
        }
    }
    return 0;
}

(Untested code generated by GPT4)

The key thing here is the wiringPi library. If we can get that running I think we have a good starting point to do a lot of what we will need.

wiringPI website

Should Drivers Run Standalone?

We should also think about whether or not the driver code should actually run as part of the main JUCE code or as it's own thing managed by systemd or something like that. I think I'm leaning towards treating the driver code as it's own thing outside of the main JUCE code. This could simplify things a lot.