From 81ab7aa5e80e834df4189fa32dfd9b05b864ad49 Mon Sep 17 00:00:00 2001 From: Mathew Mrosko Date: Mon, 1 Feb 2010 13:30:33 -0800 Subject: [PATCH 2/3] Implement a forced bend sensor press proc entry This will require the "sender" to send a press, then a release by simply echoing a 1 (bent) then a 0 (release) to the proc entry. Force a bend: echo 1 > /proc/sense1 Relese the bend: echo 0 > /proc/sense1 Implementation: Forcing a bend and going around the debounce logic is fairly simple. Basically we store the actual switch state in the data structure and fool the debounce logic by setting our time to current time plus debounce interval. Then we will skip the sections of logic which try to jack our state. The good thing here is if the switch state actually changes, it will re-take control. --- drivers/char/chumby_sense1.c | 44 +++++++++++++++++++++++++++++++++++++++++- 1 files changed, 43 insertions(+), 1 deletions(-) diff --git a/drivers/char/chumby_sense1.c b/drivers/char/chumby_sense1.c index c7129a9..f3f9ff6 100755 --- a/drivers/char/chumby_sense1.c +++ b/drivers/char/chumby_sense1.c @@ -244,9 +244,49 @@ static int sense1_read_proc(char *page, char **start, off_t off, printk("ONMES(IMX_UART3_BASE): %08lX\n", (unsigned long)ONMES(IMX_UART3_BASE)); printk("UTS (IMX_UART3_BASE): %08lX\n", (unsigned long)UTS(IMX_UART3_BASE)); + printk("bent: %d\n", sense1task_data.bent); + return len; } +static int sense1_write_proc(struct file *file, const char *buf, + unsigned long count, void *data) +{ + unsigned long en; + /* + * Should not oops, and will easily give us 0 or 1. + * Probably returns 0 for garbage (i.e. string data) + * /dev/urandom > /proc/sense1 seemed to run fine for + * quite some time. + */ + en = simple_strtoul(buf, NULL, 0); + + /* + * Forcing a bend and going around the debounce logic is fairly simple. Basically we + * store the actual switch state in the data structure and fool the debounce logic + * by setting our time to current time plus debounce interval. Then we will skip + * the sections of logic which try to jack our state. The good thing here is if the + * switch state actually changes, it will re-take control. + */ + if (en) { + printk("bent\n"); + sense1task_data.bent = 1; + sense1task_data.lastTransitionTime = sense1task_data.currentTransitionTime + gDebounce; + sense1task_data.lastTransitionState = imx_gpio_read(GPIO_PORTKP | 0); + sense1task_data.isDebounce = 0; + } + else + { + printk("not bent\n"); + sense1task_data.bent = 0; + sense1task_data.lastTransitionTime = sense1task_data.currentTransitionTime + gDebounce; + sense1task_data.lastTransitionState = imx_gpio_read(GPIO_PORTKP | 0); + sense1task_data.isDebounce = 0; + } + + return count; +} + static int resetReason_proc(char *page, char **start, off_t off, int count, int *eof, void *data) { @@ -432,6 +472,7 @@ static int __init chumby_sense1_init(void) { dev_t dev = 0; int result, err; + struct proc_dir_entry *pde; sense1task_data.sense1_cdev = cdev_alloc(); @@ -456,7 +497,8 @@ static int __init chumby_sense1_init(void) return result; } - create_proc_read_entry("sense1", 0, 0, sense1_read_proc, NULL); + pde = create_proc_read_entry("sense1", 0, 0, sense1_read_proc, NULL); + pde->write_proc = sense1_write_proc; create_proc_read_entry("resetReason", 0, 0, resetReason_proc, NULL ); cdev_init(sense1task_data.sense1_cdev, &sense1_fops); -- 1.6.6.GIT