?? mcled.cpp
字號:
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include "mcled.h"
MCLed::MCLed() {
pthread_mutexattr_t mattr;
ShowHour=-1;
ShowMin=-1;
ShowSec=-1;
FirstShowTime=false;
pthread_mutexattr_init(&mattr);
pthread_mutex_init(&lock,&mattr);
}
MCLed::~MCLed() {
close(fd);
fclose(fp);
}
void MCLed::Log(char *text) {
struct timeval tv;
struct timezone tz;
gettimeofday(&tv,&tz);
fprintf(fp,"%ds%03dms::%s\n",tv.tv_sec,tv.tv_usec/1000,text);
}
bool MCLed::Usleep(int msec) {
// usleep(msec);
struct timeval tt;
tt.tv_sec=0;
tt.tv_usec=msec;
pthread_mutex_lock(&lock);
select(0,NULL,NULL,NULL,&tt);
pthread_mutex_unlock(&lock);
return true;
}
bool MCLed::Open() {
fp=fopen("./vfd.log","a");
fd=open("/dev/ttyS1",O_RDWR);
if (fd<0) {
return false;
}
tcgetattr(fd,&term);
term.c_lflag &= ~(ECHO|ICANON|IEXTEN|ISIG);
term.c_iflag &= ~(BRKINT|ICRNL|INPCK|ISTRIP|IXON);
term.c_cflag &= ~(CSIZE|PARENB);
term.c_cflag |= CS8;
term.c_oflag &= ~(OPOST);
term.c_cc[VMIN]=1;
term.c_cc[VTIME]=0;
if (tcsetattr(fd,TCSANOW,&term)<0)
return false;
// SetMode(STA_MODE);
// Clear();
return true;
}
bool MCLed::Clear() {
int i;
unsigned char command;
unsigned char comm[5];
char tmp[1024];
FirstShowTime=false;
comm[0]=0xa0;
comm[1]=0x04;
comm[2]=0x05;
comm[3]=0x80;
if (write(fd,comm,4)<0) {
return false;
}
sprintf(tmp,"Clear:command=%02xh %02xh %02xh %02xh",comm[0],comm[1],comm[2],comm[3]);
Log(tmp);
command=0x18;
if (!HideIcon(1,0x81,&command))
return false;
if (!HideIcon(1,0x8b,&command))
return false;
// for (i=0x81;i<=0x8b;i++)
// if (!HideIcon(1,i,&command))
// return false;
return true;
}
bool MCLed::HideIcon(unsigned char len,unsigned char section,unsigned char *data) {
unsigned char *command;
char tmp[1024];
int i;
command=(unsigned char *)malloc((len+5));
command[0]=0xa0;
command[1]=0x04;
command[2]=0x05;
command[3]=0x80+len+1;
command[4]=section;
for (i=0;i<len;i++) {
command[5+i]=data[i];
}
Usleep(DELAY);
if (write(fd,command,(len+5))<0) {
free(command);
return false;
}
switch (len) {
case 0:
sprintf(tmp,"HideIcon:command=%02xh %02xh %02xh %02xh %02xh",command[0],command[1],command[2],command[3],command[4]);
break;
case 1:
sprintf(tmp,"HideIcon:command=%02xh %02xh %02xh %02xh %02xh %02xh",command[0],command[1],command[2],command[3],command[4],command[5]);
break;
case 2:
sprintf(tmp,"HideIcon:command=%02xh %02xh %02xh %02xh %02xh %02xh %02xh",command[0],command[1],command[2],command[3],command[4],command[5],command[6]);
break;
case 3:
sprintf(tmp,"HideIcon:command=%02xh %02xh %02xh %02xh %02xh %02xh %02xh %02xh",command[0],command[1],command[2],command[3],command[4],command[5],command[6],command[7]);
break;
case 7:
sprintf(tmp,"HideIcon:command=%02xh %02xh %02xh %02xh %02xh %02xh %02xh %02xh %02xh %02xh %02xh %02xh",command[0],command[1],command[2],command[3],command[4],command[5],command[6],command[7],command[8],command[9],command[10],command[11]);
break;
default:
sprintf(tmp,"HideIcon:command=%02xh %02xh %02xh %02xh %02xh %02xh %02xh %02xh len=%d",command[0],command[1],command[2],command[3],command[4],command[5],command[6],command[7],len);
break;
}
Log(tmp);
free(command);
return true;
}
bool MCLed::ShowIcon(unsigned char len,unsigned char section,unsigned char *data) {
unsigned char *command;
char tmp[1024];
int i;
command=(unsigned char *)malloc((len+5));
command[0]=0xa0;
command[1]=0x04;
command[2]=0x00;
command[3]=0x80+len+1;
command[4]=section;
for (i=0;i<len;i++) {
command[5+i]=data[i];
}
Usleep(DELAY);
if (write(fd,command,(len+5))<0) {
free(command);
return false;
}
switch (len) {
case 0:
sprintf(tmp,"ShowIcon:command=%02xh %02xh %02xh %02xh %02xh",command[0],command[1],command[2],command[3],command[4]);
break;
case 1:
sprintf(tmp,"ShowIcon:command=%02xh %02xh %02xh %02xh %02xh %02xh",command[0],command[1],command[2],command[3],command[4],command[5]);
break;
case 2:
sprintf(tmp,"ShowIcon:command=%02xh %02xh %02xh %02xh %02xh %02xh %02xh",command[0],command[1],command[2],command[3],command[4],command[5],command[6]);
break;
case 3:
sprintf(tmp,"ShowIcon:command=%02xh %02xh %02xh %02xh %02xh %02xh %02xh %02xh",command[0],command[1],command[2],command[3],command[4],command[5],command[6],command[7]);
break;
case 7:
sprintf(tmp,"ShowIcon:command=%02xh %02xh %02xh %02xh %02xh %02xh %02xh %02xh %02xh %02xh %02xh %02xh",command[0],command[1],command[2],command[3],command[4],command[5],command[6],command[7],command[8],command[9],command[10],command[11]);
break;
default:
sprintf(tmp,"ShowIcon:command=%02xh %02xh %02xh %02xh %02xh %02xh %02xh %02xh len=%d",command[0],command[1],command[2],command[3],command[4],command[5],command[6],command[7],len);
break;
}
Log(tmp);
free(command);
return true;
}
bool MCLed::ShowAscii(unsigned char section,char data) {
unsigned char command[6];
char tmp[1024];
command[0]=0xa0;
command[1]=0x04;
command[2]=0x01;
command[3]=0x82;
command[4]=section;
command[5]=(unsigned char)data;
Usleep(DELAY);
if (write(fd,command,6)<0)
return false;
else {
sprintf(tmp,"ShowAscii:command=%02xh %02xh %02xh %02xh %02xh %02xh",command[0],command[1],command[2],command[3],command[4],command[5]);
Log(tmp);
return true;
}
}
bool MCLed::SetPCMode() {
unsigned char command[5];
command[0]=0xa0;
command[1]=0x00;
command[2]=0x63;
command[3]=0x81;
command[4]=0x01;
Usleep(DELAY);
if (write(fd,command,5)<0)
return false;
else {
Log("SetPCMode");
return true;
}
}
bool MCLed::SetMode(unsigned char mode) {
unsigned char command[5];
char tmp[1024];
command[0]=0xa0;
command[1]=0x00;
command[2]=0x31;
command[3]=0x81;
command[4]=mode;
Usleep(DELAY);
if (write(fd,command,5)<0)
return false;
else {
sprintf(tmp,"SetMode %02xh",mode);
Log(tmp);
return true;
}
}
bool MCLed::ShowPlay() {
if (!ShowPlayStatus(ST_PLAY))
return false;
else
return true;
}
bool MCLed::ShowStop() {
if (!ShowPlayStatus(ST_STOP))
return false;
else
return true;
}
bool MCLed::ShowPause() {
if (!ShowPlayStatus(ST_PAUSE))
return false;
else
return true;
}
bool MCLed::ShowFF() {
if (!ShowPlayStatus(ST_FF))
return false;
else
return true;
}
bool MCLed::ShowFB() {
if (!ShowPlayStatus(ST_FB))
return false;
else
return true;
}
bool MCLed::ShowNC() {
if (!ShowPlayStatus(ST_NC))
return false;
else
return true;
}
bool MCLed::ShowPC() {
if (!ShowPlayStatus(ST_PC))
return false;
else
return true;
}
bool MCLed::HidePlayStatus(int status) {
unsigned char *tmp;
tmp=(unsigned char *)malloc(17);
switch (status) {
case ST_PLAY:
tmp[0]=0x10;
if (!HideIcon(1,0x8b,tmp)) {
free(tmp);
return false;
}
break;
case ST_STOP:
sprintf((char *)tmp," ");
if (!ShowStringLeft((char *)tmp,5)) {
free(tmp);
return false;
}
break;
case ST_PAUSE:
tmp[0]=0x11;
if (!HideIcon(1,0x8b,tmp)) {
free(tmp);
return false;
}
break;
case ST_FF:
break;
case ST_FB:
break;
case ST_NC:
break;
case ST_PC:
break;
default:
return false;
}
return true;
}
bool MCLed::ShowPlayStatus(int status) {
unsigned char *tmp;
tmp=(unsigned char *)malloc(17);
switch (status) {
case ST_PLAY:
tmp[0]=0x10;
if (!ShowIcon(1,0x8b,tmp)) {
free(tmp);
return false;
}
break;
case ST_STOP:
sprintf((char *)tmp," STOP");
if (!ShowStringLeft((char *)tmp,5)) {
free(tmp);
return false;
}
break;
case ST_PAUSE:
tmp[0]=0x11;
if (!ShowIcon(1,0x8b,tmp)) {
free(tmp);
return false;
}
break;
case ST_FF:
// sprintf((char *)tmp," FF");
// if (!ShowString((char *)tmp)) {
// free(tmp);
// return false;
// }
break;
case ST_FB:
// sprintf((char *)tmp," FB");
// if (!ShowString((char *)tmp)) {
// free(tmp);
// return false;
// }
break;
case ST_NC:
// sprintf((char *)tmp," NEXT CH");
// if (!ShowString((char *)tmp)) {
// free(tmp);
// return false;
// }
break;
case ST_PC:
// sprintf((char *)tmp," PREV CH");
// if (!ShowString((char *)tmp)) {
// free(tmp);
// return false;
// }
break;
default:
free(tmp);
return false;
}
free(tmp);
return true;
}
bool MCLed::ShowString(char *data,int begin,int length) {
unsigned char i;
unsigned char command[16];
char tmp[1024];
if ((begin+length)>9)
length=9-begin;
command[0]=0xa0;
command[1]=0x00;
command[2]=0x80;
command[3]=0x80+begin+length;
for (i=0;i<begin;i++)
command[4+i]=0x60;
for (i=begin;i<(begin+length);i++) {
command[4+i]=data[i-begin];
}
Usleep(DELAY);
if (write(fd,command,(4+begin+length))<0)
return false;
else {
sprintf(tmp,"ShowString:command=%02xh %02xh %02xh %02xh %02xh String=|%s|",command[0],command[1],command[2],command[3],command[4],data);
Log(tmp);
return true;
}
// for (i=begin;i<(begin+length);i++) {
// if (!ShowAscii((0x8a-i),data[i-begin]))
// return false;
// }
return true;
}
bool MCLed::ShowStringLeft(char *data,int n) {
unsigned char i;
unsigned char command[16];
char tmp[1024];
if (n>9)
n=9;
command[0]=0xa0;
command[1]=0x00;
command[2]=0x80;
command[3]=0x80+n;
for (i=0;i<n;i++) {
command[4+i]=data[i];
}
Usleep(DELAY);
if (write(fd,command,(4+n))<0)
return false;
else {
sprintf(tmp,"ShowStringLeft:command=%02xh %02xh %02xh %02xh String=|%s|",command[0],command[1],command[2],command[3],data);
Log(tmp);
return true;
}
// for (i=0;i<n;i++) {
// if (!ShowAscii((0x8a-i),data[i]))
// return false;
// }
return true;
}
bool MCLed::ShowStringRight(char *data,int n) {
unsigned char i,j;
unsigned char command[16];
char tmp[1024];
if (n>9)
n=9;
command[0]=0xa0;
command[1]=0x00;
command[2]=0x80;
command[3]=0x89;
i=0;
// for (i=0;i<begin;i++)
while (i<(9-n)) {
command[4+i]=0x60;
i++;
}
j=0;
// for (i=begin;i<(begin+length);i++) {
while (i<9) {
command[4+i]=data[j];
i++;j++;
}
Usleep(DELAY);
if (write(fd,command,13)<0)
return false;
else {
sprintf(tmp,"ShowStringRight:command=%02xh %02xh %02xh %02xh String=|%s|",command[0],command[1],command[2],command[3],data);
Log(tmp);
return true;
}
// for (i=0;i<n;i++) {
// if (!ShowAscii((0x82+i),data[n-i-1]))
// return false;
// }
return true;
}
bool MCLed::ShowAC3() {
unsigned char *tmp;
tmp=(unsigned char *)malloc(17);
tmp[0]=0x01;
if (!ShowIcon(1,0x8b,tmp)) {
free(tmp);
return false;
}
free(tmp);
return true;
}
bool MCLed::ShowDTS() {
unsigned char *tmp;
tmp=(unsigned char *)malloc(17);
tmp[0]=0x02;
if (!ShowIcon(1,0x8b,tmp)) {
free(tmp);
return false;
}
free(tmp);
return true;
}
bool MCLed::HidePlay() {
if (!HidePlayStatus(ST_PLAY))
return false;
else
return true;
}
bool MCLed::HideStop() {
if (!HidePlayStatus(ST_STOP))
return false;
else
return true;
}
bool MCLed::HidePause() {
if (!HidePlayStatus(ST_PAUSE))
return false;
else
return true;
}
bool MCLed::HideFF() {
if (!HidePlayStatus(ST_FF))
return false;
else
return true;
}
bool MCLed::HideFB() {
if (!HidePlayStatus(ST_FB))
return false;
else
return true;
}
bool MCLed::HideNC() {
if (!HidePlayStatus(ST_NC))
return false;
else
return true;
}
bool MCLed::HidePC() {
if (!HidePlayStatus(ST_PC))
return false;
else
return true;
}
bool MCLed::HideAC3() {
unsigned char *tmp;
tmp=(unsigned char *)malloc(17);
tmp[0]=0x01;
if (!HideIcon(1,0x8b,tmp)) {
free(tmp);
return false;
}
free(tmp);
return true;
}
bool MCLed::HideDTS() {
unsigned char *tmp;
tmp=(unsigned char *)malloc(17);
tmp[0]=0x02;
if (!HideIcon(1,0x8b,tmp)) {
free(tmp);
return false;
}
free(tmp);
return true;
}
bool MCLed::HideTrack() {
unsigned char command;
char tmp[10];
sprintf(tmp," ");
if (!ShowStringLeft(tmp,3))
return false;
command=0x01;
if (!HideIcon(1,0x89,&command))
return false;
else
return true;
}
bool MCLed::HideTitle() {
unsigned char command;
char tmp[10];
sprintf(tmp," ");
if (!ShowStringLeft(tmp,3))
return false;
command=0x01;
if (!HideIcon(1,0x8a,&command))
return false;
else
return true;
}
bool MCLed::HideChapter() {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -