Difference between revisions of "Matrix - Button/zh"

From FriendlyELEC WiKi
Jump to: navigation, search
(Linux下的C示例)
(Linux下的C示例)
Line 14: Line 14:
 
===Linux下的C示例===
 
===Linux下的C示例===
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
def quickSort(arr):
+
#include <stdio.h>
     less = []
+
#include "libfahw.h"
     pivotList = []
+
 
     more = []
+
static struct sensor button[] = {
     if len(arr) <= 1:
+
        {
         return arr
+
                TINY4412_GPIO_PIN1,
     else:
+
                IRQ_TYPE_EDGE_FALLING,
 +
        }
 +
};
 +
 
 +
int main(void)
 +
{
 +
     int i;
 +
     int retSize = -1;
 +
    char value[ARRAY_SIZE(button)];
 +
     int devFD = -1;
 +
     if ((devFD =sensorInit(button, ARRAY_SIZE(button))) == -1) {
 +
        printf("Fail to init sensor\n");
 +
         return -1;
 +
     }
 +
    printf("Press the button...\n");
 +
    if (( retSize = sensorRead(devFD, value, ARRAY_SIZE(button)) ) == -1) {
 +
        printf("Fail to read sensors\n");
 +
    }
 +
    if (retSize > 0) {
 +
        i = 0;
 +
        for (i=0; i<retSize; i++) {
 +
            printf("Button[%d]:%d\n", i, value[i]);
 +
        }
 +
    }
 +
    sensorDeinit(devFD);
 +
    return 0;
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
==相关资料==
 
==相关资料==

Revision as of 07:25, 9 July 2015

1 介绍

Btn01

该按键在未按时输出高电平,按下后输出低电平。

2 特性

  • 3 PIN
  • 尺寸(TODO)

3 使用方法

3.1 连接

  • 连接到Tiny4412 SDK
将S针脚连接到GPIO PIN1即可

3.2 Linux下的C示例

#include <stdio.h>
#include "libfahw.h"
 
static struct sensor button[] = {
        {
                TINY4412_GPIO_PIN1,
                IRQ_TYPE_EDGE_FALLING,
        }
};
 
int main(void)
{
    int i;
    int retSize = -1;
    char value[ARRAY_SIZE(button)];
    int devFD = -1;
    if ((devFD =sensorInit(button, ARRAY_SIZE(button))) == -1) {
        printf("Fail to init sensor\n");
        return -1;
    }
    printf("Press the button...\n");
    if (( retSize = sensorRead(devFD, value, ARRAY_SIZE(button)) ) == -1) {
        printf("Fail to read sensors\n");
    }
    if (retSize > 0) {
        i = 0;
        for (i=0; i<retSize; i++) {
            printf("Button[%d]:%d\n", i, value[i]);
        }
    }
    sensorDeinit(devFD);
    return 0;
}

4 相关资料