launcher icon indicating copy to clipboard operation
launcher copied to clipboard

Fix led blinking functionality in run.py

Open omgmog opened this issue 6 years ago • 2 comments

The current Gameshell code looks for the led at /proc/driver/led1

On the PocketCHIP, the white led is controllable with the following commands:

/usr/sbin/i2cset -f -y 0 0x34 0x93 0x1 #on
/usr/sbin/i2cset -f -y 0 0x34 0x93 0x0 #off

omgmog avatar Jun 14 '19 13:06 omgmog

This could be patched in with a proc LKM, as described here:

  • https://www.thegeekstuff.com/2012/04/create-proc-files/
  • https://stackoverflow.com/a/33237363

Skeleton example of a /proc/driver/XX with read/write:

#define PROC_ENTRY_NAME "driver/XX"
static struct proc_dir_entry *proc_XX;

static int XX_read_proc (char *page, char **start, off_t off, int count,
    int *eof, void *data_unused)
{
    return 0;
}
static int XX_write_proc (struct file *file, const char __user *buffer,
    unsigned long count, void *data)
{
    return 0;
}

static int __init XX_add_driver(void)
{
    if ((proc_flash = XX_entry(PROC_ENTRY_NAME, 0, NULL))) {
        proc_XX->read_proc = XX_read_proc;
        proc_XX->write_proc = XX_write_proc;
    }
...
}

static void __exit XX_remove(void)
{
    if (proc_flash)
        remove_proc_entry(PROC_ENTRY_NAME, NULL);

    return;
}

Easiest solution would be to just take the value echoed and call i2cset or i2cget as a subprocess, a bit like this: https://stackoverflow.com/a/5460448

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> /* for fork */
#include <sys/types.h> /* for pid_t */
#include <sys/wait.h> /* for wait */

int main()
{
    /*Spawn a child to run the program.*/
    pid_t pid=fork();
    if (pid==0) { /* child process */
        static char *argv[]={"echo","Foo is my name.",NULL};
        execv("/bin/echo",argv);
        exit(127); /* only if execv fails */
    }
    else { /* pid!=0; parent process */
        waitpid(pid,0,0); /* wait for child to exit */
    }
    return 0;
}

See also:

  • https://linux.die.net/man/8/i2cset
  • https://linux.die.net/man/8/i2cget

omgmog avatar Jun 23 '19 11:06 omgmog

This should probably be it's own project, then we can keep the calls to /proc/driver/led1 as they are in the launcher code

omgmog avatar Jun 23 '19 11:06 omgmog