Embedded/Kernel Porting
[Kernel Porting-6] H-Smart4412 Tact Switch 작동하기
by tunanut
2016. 12. 26.
작업 환경
-메인 OS : Windows 8.1K(Intel Core i5-4590)
-작업 OS : Ubuntu 14.04 64bit(VirtualBox)
-장 비 명 : H-Smart4412
1. tact.c - Tact Switch 입력 번호 띄우기
#include <termios.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <asm/ioctls.h>
#define tact_d "/dev/tactsw"
int main() { int tact; unsigned char c; if((tact = open(tact_d,O_RDWR)) < 0) { perror("open"); exit(1); } while(1) { read(tact,&c,sizeof(c)); if(c) break; } switch(c) { case 1: printf("1번 버튼\n"); break; case 2: printf("2번 버튼\n"); break; case 3: printf("3번 버튼\n"); break; case 4: printf("4번 버튼\n"); break; case 5: printf("5번 버튼\n"); break; case 6: printf("6번 버튼\n"); break; case 7: printf("7번 버튼\n"); break; case 8: printf("8번 버튼\n"); break; case 9: printf("9번 버튼\n"); break; case 10: printf("10번 버튼\n"); break; case 11: printf("11번 버튼\n"); break; case 12: printf("12번 버튼\n"); break; } close(tact); return 0; }
|
2. tact_calc.c - Tact Switch 계산기
#include <termios.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <asm/ioctls.h>
#define tact_d "/dev/tactsw"
void calc(int *num, char op);
int main() { int tact, num[2], flag=0; char op; unsigned char c;
if((tact = open(tact_d,O_RDWR)) < 0) { perror("open"); exit(1); }
while(1) { while(1) { read(tact,&c,sizeof(c)); if(c) break; }
switch(c) { case 1: num[flag] = 1; flag++; break; case 2: num[flag] = 2; flag++; break; case 3: num[flag] = 3; flag++; break; case 4: num[flag] = 4; flag++; break; case 5: num[flag] = 5; flag++; break; case 6: num[flag] = 6; flag++; break; case 7: op = '+'; break; case 8: op = '-'; break; case 9: op = '*'; break; case 10: op = '/'; break; case 11: calc(num,op); break; case 12: exit(1); }
sleep(1); c=0; }
close(tact); return 0; } void calc(int *num, char op) { switch(op) { case '+': printf("%d %c %d = %d \n",num[0],op,num[1],num[0]+num[1]); break; case '-': printf("%d %c %d = %d \n",num[0],op,num[1],num[0]-num[1]); break; case '*': printf("%d %c %d = %d \n",num[0],op,num[1],num[0]*num[1]); break; case '/': printf("%d %c %d = %d \n",num[0],op,num[1],num[0]/num[1]); break; } exit(1); }
|