#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/ioctl.h>
#include<sys/stat.h>
//디바이스 드라이버가 들어있는 경로 위치를 적어논것
#define tact "/dev/tactsw"
#define dot "/dev/dot"
void Spin_in();
void Spin_out();
void Spin_num();
void Spin_dnum();
void Spin_str();
int main()
{
int tact_d;
unsigned char data;
tact_d = open(tact , O_RDWR);
if(tact_d <0)
{
printf("no driver file\n");
exit(0);
}
while(1)
{
puts("**********JooSeok Menu**********");
puts("* 1. S P I N _ I N *");
puts("* 2. S P I N _ O U T *");
puts("* 3. S P I N _ N U M *");
puts("* 4. S P I N _ D N U M *");
puts("* 5. S P I N _ S T R *");
puts("* 12. E X I T *");
puts("********************************");
while(1)
{
read(tact_d , &data , sizeof(data));
if(data) break;
usleep(150000);
}
switch(data)
{
case 1: Spin_in(); break;
case 2: Spin_out(); break;
case 3: Spin_num(); break;
case 4: Spin_dnum(); break;
case 5: Spin_str(); break;
case 12: close(tact_d); return 0;
}
putchar('\n');
}
return 0;
}
void Spin_in()
{
int dot_d, i, j, k, cnt;
unsigned char data[8]={0, 0, 0, 0, 0, 0, 0, 0};
dot_d = open(dot, O_RDWR);
write(dot_d, &data, sizeof(data));
for(i=1; i<9; i++)
{
if(i%2==1)
{
j=5+(i/2);
for(k=3-(i/2); k<j; k++)
{ //하
data[k]|=0x10<<(i/2);
write(dot_d, &data, sizeof(data));
usleep(100000);
}
for(cnt=1; cnt<i+1; cnt++)
{ //우
data[k-1]|=(0x10<<i/2)>>cnt;
write(dot_d, &data, sizeof(data));
usleep(100000);
}
}
if(i%2==0)
{
j=2-(i/2);
for(k=2+(i/2); k>j; k--)
{ //상
data[k]|=0x10>>(i/2);
write(dot_d, &data, sizeof(data));
usleep(100000);
}
for(cnt=1; cnt<i; cnt++)
{ //좌
data[k+1]|=(0x10>>i/2)<<cnt;
write(dot_d, &data, sizeof(data));
usleep(100000);
}
}
}
close(dot_d);
}
void Spin_out()
{
int dot_d, i, j, k, cnt;
unsigned char data[8]={0, 0, 0, 0, 0, 0, 0, 0};
dot_d = open(dot, O_RDWR);
write(dot_d, &data, sizeof(data));
for(i=0; i<8; i++){
if(i%2==0){
k=i/2;
for(cnt=i/2; cnt<8-i/2; cnt++){ //우
data[k]|=0x80>>cnt;
write(dot_d, &data, sizeof(data));
usleep(100000);
}
for(k=1+(i/2); k<7-(i/2); k++){ //하
data[k]|=0x01<<(i/2);
write(dot_d, &data, sizeof(data));
usleep(100000);
}
}
if(i%2==1){
k=7-i/2;
for(cnt=i/2; cnt<8-i/2; cnt++){ //좌
data[k]|=0x01<<cnt;
write(dot_d, &data, sizeof(data));
usleep(100000);
}
for(k=6-(i/2); k>(i/2)-1; k--){ //상
data[k]|=0x80>>(i/2);
write(dot_d, &data, sizeof(data));
usleep(100000);
}
}
}
close(dot_d);
}
void Spin_num()
{
int dot_d,i=0, j, s_r=8 , s_l=1;
unsigned char temp[8] = {0,0,0,0,0,0,0,0};
unsigned char num[10][8] =
{
{0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00}, //zero
{0x18, 0x38, 0x78, 0x18, 0x18, 0x18, 0x7E, 0x00}, //one
{0x3C, 0x66, 0x06, 0x1C, 0x30, 0x60, 0x7E, 0x00}, //two
{0x3C, 0x66, 0x06, 0x1C, 0x06, 0x66, 0x3C, 0x00}, //three
{0x0C, 0x1C, 0x3C, 0X6C, 0x7E, 0x0C, 0x0C, 0x00}, //four
{0x7E, 0x60, 0x7C, 0x06, 0x06, 0x66, 0x3C, 0x00}, //five
{0x1C, 0x30, 0x60, 0x7C, 0x66, 0x66, 0x3C, 0x00}, //six
{0x7E, 0x06, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x00}, //seven
{0x3C, 0x66, 0x66, 0x3C, 0x66, 0x66, 0x3C, 0x00}, //eight
{0x3C, 0x66, 0x66, 0x3E, 0x06, 0x0C, 0x38, 0x00}, //nine
};
dot_d = open(dot, O_RDWR);
while(i <10)
{
for(j=0 ; j<8 ; ++j)
{
if(s_r >=0)
{
temp[j] = num[i][j] >> s_r;
}
else if(s_l <=9)
{
temp[j] = num[i][j] << s_l;
}
}
if(s_r >= 0)
{
s_r--;
write(dot_d , &temp , sizeof(temp));
usleep(100000);
}
else if(s_l <=9)
{
s_l++;
write(dot_d , &temp , sizeof(temp));
usleep(100000);
}
if(s_l ==10)
{
s_l=1;
s_r=8;
i++;
}
}
close(dot_d);
}
void Spin_dnum()
{
int dot_d, k ,i=0, j, s_r=8 , s_l=1 , a , divided , remain;
unsigned char temp[8] = {0,0,0,0,0,0,0,0};
unsigned char num[10][8] =
{
{0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00}, //zero
{0x18, 0x38, 0x78, 0x18, 0x18, 0x18, 0x7E, 0x00}, //one
{0x3C, 0x66, 0x06, 0x1C, 0x30, 0x60, 0x7E, 0x00}, //two
{0x3C, 0x66, 0x06, 0x1C, 0x06, 0x66, 0x3C, 0x00}, //three
{0x0C, 0x1C, 0x3C, 0X6C, 0x7E, 0x0C, 0x0C, 0x00}, //four
{0x7E, 0x60, 0x7C, 0x06, 0x06, 0x66, 0x3C, 0x00}, //five
{0x1C, 0x30, 0x60, 0x7C, 0x66, 0x66, 0x3C, 0x00}, //six
{0x7E, 0x06, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x00}, //seven
{0x3C, 0x66, 0x66, 0x3C, 0x66, 0x66, 0x3C, 0x00}, //eight
{0x3C, 0x66, 0x66, 0x3E, 0x06, 0x0C, 0x38, 0x00}, //nine
};
dot_d = open(dot, O_RDWR);
printf("Input >> ");
scanf("%d" , &a);
divided = a/10;
remain = a%10;
while(i <2)
{
if(i==0)
k=divided;
else if(i==1)
k=remain;
for(j=0 ; j<8 ; ++j)
{
if(s_r >=0)
{
temp[j] = num[k][j] >> s_r;
}
else if(s_l <=9)
{
temp[j] = num[k][j] << s_l;
}
}
if(s_r >= 0)
{
s_r--;
write(dot_d , &temp , sizeof(temp));
usleep(100000);
}
else if(s_l <=9)
{
s_l++;
write(dot_d , &temp , sizeof(temp));
usleep(100000);
}
if(s_l ==10)
{
s_l=1;
s_r=8;
i++;
}
}
close(dot_d);
}
void Spin_str()
{
int dot_d,i=0, j, s_r=8 , s_l=1;
unsigned char temp[8] = {0,0,0,0,0,0,0,0};
unsigned char num[5][8] =
{
{0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00}, //H
{0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x7E, 0x00}, //E
{0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7E, 0x00}, //L
{0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7E, 0x00}, //L
{0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00}, //O
};
dot_d = open(dot, O_RDWR);
while(i <5)
{
for(j=0 ; j<8 ; ++j)
{
if(s_r >=0)
{
temp[j] = num[i][j] >> s_r;
}
else if(s_l <=9)
{
temp[j] = num[i][j] << s_l;
}
}
if(s_r >= 0)
{
s_r--;
write(dot_d , &temp , sizeof(temp));
usleep(100000);
}
else if(s_l <=9)
{
s_l++;
write(dot_d , &temp , sizeof(temp));
usleep(100000);
}
if(s_l ==10)
{
s_l=1;
s_r=8;
i++;
}
}
close(dot_d);
}