[Armadillo:01408] Re: タクトスイッチが押されている時間の計測

Yasushi SHOJI email@hidden
2006年 11月 28日 (火) 23:19:48 JST


At Tue, 28 Nov 2006 21:37:38 +0900,
Yasushi SHOJI wrote:
> 
> At Sun, 26 Nov 2006 10:41:24 +0900,
> Okazaki wrote:
> > 
> > 作成しているソフトの仕様上、タクトSWの押されている時間を取得したいと思ってい
> > ます
> > writefbd.cを参考にして、タクトSWONイベントは取得できているのですが、OFFのイ
> > ベントが取得できていません
> 
> read()でスイッチの状態が読めないということでしょうか?
> 
> どれくらいの精度が必要なのかにもよりますが、現状のスイッチドライバは押
> したときに割り込みが入ることで select()が使えるようになります。
> 
> もし精度が低くても良いのであれば、select()を使わずread()だけを使って
> 一定周期でポーリングするというのはどうでしょうか?

ポーリングのsample codeです。

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char * argv[])
{
	int fd;
	unsigned char status;
	int ret;
	fd = open("/dev/sw", O_RDONLY);
	if (fd < 0)
		return -1;
	while (1) {
		sleep(1);
		ret = read(fd, &status, 1);
		if (ret != 1)
			return -1;
		printf("%#x\n", status);
	}
        return 0;
}



armadillo メーリングリストの案内