Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Request) Help Porting Clickwheel Code to PocketBeagle #35

Open
ntfrueh opened this issue Apr 26, 2021 · 1 comment
Open

(Request) Help Porting Clickwheel Code to PocketBeagle #35

ntfrueh opened this issue Apr 26, 2021 · 1 comment

Comments

@ntfrueh
Copy link

ntfrueh commented Apr 26, 2021

Hey everyone,

I was holding off on posting here for a while, but I've banged my head against the wall for so long that I need a bit of guidance.

Like Guy, I had been working on a similar project since last summer, but decided to try to switch over to the PocketBeagle instead of a Raspberry Pi (mainly due to it's alleged support for very low power sleep modes).

Getting things like Wi-Fi/Bluetooth/SPI displays working on this was a battle and a half, but I managed to work through them. One thing I'm still stuck on, however, is the clickwheel code.

From what I can tell, he's got a few callback functions triggered to run whenever either the clock or data line changes, then does a bit of bit-banging. What I'm struggling with is the switch to the IOBB library to get similar behavior up and running on a PocketBeagle.

// Nate added these for PocketBeagle to make hack-y callback functions
int CURRENTCLOCKSTATE = 0;
int CURRENTDATASTATE = 0;
int PASTCLOCKSTATE = 0;
int PASTDATASTATE = 0;

iolib_init();

iolib_setdir(1, 28, DigitalIn);  // Set clock pin GPIO13 (P1,28) as input
iolib_setdir(1, 26, DigitalIn);  // Set data pin GPIO12 (P1,26) as input

// Back to Guy's code
if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) { 
    perror("socket creation failed"); 
    exit(EXIT_FAILURE); 
} 
  
memset(&servaddr, 0, sizeof(servaddr)); 
      
servaddr.sin_family = AF_INET; 
servaddr.sin_port = htons(PORT); 
servaddr.sin_addr.s_addr = INADDR_ANY;

// I also removed the pulses/haptic code, as I wasn't planning on integrating that

while(running) {
    
    CURRENTCLOCKSTATE = (is_low(1, 28)) ? 0 : 1;
    CURRENTDATASTATE = (is_low(1, 26)) ? 0 : 1;

    //printf("Did clock state change?");
    if(CURRENTCLOCKSTATE != PASTCLOCKSTATE) {
        printf("Clock state changed!\n");
        onClockEdge(28, CURRENTCLOCKSTATE);  // Runs his original functions
        PASTCLOCKSTATE = CURRENTCLOCKSTATE;
    }

    //printf("Did data state change?");
    if(CURRENTDATASTATE != PASTDATASTATE) {
        printf("Data state changed!\n");
        onDataEdge(26, CURRENTDATASTATE);  // Runs his original functions
        PASTDATASTATE = CURRENTDATASTATE;
    }
}

The idea is that I'm creating my own callback functions if the current data/clock pin state changes compared to the previous one. However, it perpetually reads the state of those pins as 0, which makes me think I'm just not polling correctly.

I'm not a programmer by trade (especially not this low level of programming), and unfortunately I've exhausted my list of resources for i2c reading/bit-banging.

@tomaculum
Copy link
Contributor

I do not know anything about the IOBB library or the PocketBeagle but I think you did not "translate" those two lines of code:

gpioSetPullUpDown(CLOCK_PIN, PI_PUD_UP);

gpioSetPullUpDown(DATA_PIN, PI_PUD_UP);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants