zeus 3110
/
IRTest2
test ir controller for carozzeria audio
IR test program for carozzeria audio
USB HID&赤外線ステアリングコントローラー
回路図
Revision 0:e606807a2d4a, committed 2015-08-15
- Comitter:
- zeus3110
- Date:
- Sat Aug 15 11:05:11 2015 +0000
- Commit message:
- test
Changed in this revision
diff -r 000000000000 -r e606807a2d4a DEH970Ctrl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DEH970Ctrl.cpp Sat Aug 15 11:05:11 2015 +0000 @@ -0,0 +1,117 @@ +#include "DEH970Ctrl.h" + + +unsigned char VolPlus[DATA_LENGTH]={0xB5,0x4A,0x50,0xAF}; +//unsigned char VolPlus[DATA_LENGTH]={0x55,0xAA,0xA5,0x5A}; +unsigned char VolMinus[DATA_LENGTH]={0xB5,0x4A,0xD0,0x2F}; + +DEH970Controller::DEH970Controller(PwmOut *Port) +{ + Locked=false; + IRPort=Port; + + PwmPortInit(); +} + +DEH970Controller::~DEH970Controller() +{ + +} + +bool DEH970Controller::IsLocked() +{ + return Locked; +} + +void DEH970Controller::PwmPortInit() +{ +#ifdef DEBUG + printf("PWM Port Init\n"); +#endif + IRPort->period_us(BurstPeriod); + IRPort->write(IR_OFF); +} + +void DEH970Controller::SendSignal(unsigned char *Dp) +{ + DataBitPos=0; + DataBytePos=-1; + Data=Dp; + DataBit=false; + TimeOutIR=NULL; +#ifdef DEBUG + printf("SendSignal\n"); +#endif + SendData(); +} + +void DEH970Controller::SendData() +{ + timestamp_t WaitTime; + + if(TimeOutIR!=NULL) + delete TimeOutIR; + + TimeOutIR=new Timeout(); + DataBit=!DataBit; + +#ifdef DEBUG + printf("%d %d %d\n",DataBytePos,DataBitPos,DataBit); +#endif + // Send Leader + if(DataBytePos==-1) + { + WaitTime=DataBit?LeaderOn:LeaderOff; + IRPort->write(DataBit?IR_ON:IR_OFF); + if(!DataBit) + DataBytePos++; + } + // Send Trailer + else if(DataBytePos==DATA_LENGTH) + { + WaitTime=DataBit?TrailerOn:TrailerOff; + IRPort->write(DataBit?IR_ON:IR_OFF); + if(!DataBit) + DataBytePos++; + } + // Finish if Sent Trailer + else if(DataBytePos==DATA_LENGTH+1) + { +#ifdef DEBUG + printf("finished\n"); +#endif + return; + } + // Send Data + else + { + if(DataBit) + WaitTime=DataOn; + else + WaitTime=((((int)Data[DataBytePos])&(0x00000080>>DataBitPos))==0)?DataOff0:DataOff1; +#ifdef DEBUG2 + printf("%x\n",(((int)Data[DataBytePos])&(0x00000080>>DataBitPos))!=0); +#endif + IRPort->write(DataBit?IR_ON:IR_OFF); + if(!DataBit) + { DataBitPos=(DataBitPos+1)%8; + if(DataBitPos==0) + DataBytePos++; + } + } + + TimeOutIR->attach_us(this,&DEH970Controller::SendData,WaitTime); +} + +void DEH970Controller::SendVolPlus() +{ +#ifdef DEBUG + printf("Send Vol Plus\n"); +#endif + SendSignal(VolPlus); +} + +void DEH970Controller::SendVolMinus() +{ + SendSignal(VolMinus); +} \ No newline at end of file
diff -r 000000000000 -r e606807a2d4a DEH970Ctrl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DEH970Ctrl.h Sat Aug 15 11:05:11 2015 +0000 @@ -0,0 +1,43 @@ +#ifndef _DEH970_CTRL_H_ +#define _DEH970_CTRL_H_ + +#include "mbed.h" + +#define DATA_LENGTH 4 +#define IR_ON 0.5 +#define IR_OFF 0 + +const int BurstPeriod=26; +const timestamp_t LeaderOn=8628; +const timestamp_t LeaderOff=4137; +const timestamp_t DataOn=626; +const timestamp_t DataOff1=1488; +const timestamp_t DataOff0=424; +const timestamp_t TrailerOn=626; +const timestamp_t TrailerOff=25395; + +class DEH970Controller { +protected: +private: + bool Locked; + PwmOut *IRPort; + int DataBitPos,DataBytePos; + unsigned char *Data; + bool DataBit; + Timeout *TimeOutIR; + + +public: + bool IsLocked(); + DEH970Controller(PwmOut *Port); + ~DEH970Controller(); + void PwmPortInit(); + void SendSignal(unsigned char *Dp); + void SendLeaderOn(); + void SendData(); + + void SendVolPlus(); + void SendVolMinus(); +}; + +#endif \ No newline at end of file
diff -r 000000000000 -r e606807a2d4a main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Aug 15 11:05:11 2015 +0000 @@ -0,0 +1,18 @@ +#include "mbed.h" +#include "DEH970Ctrl.h" + +PwmOut IRPort(PTB2); + +int main() +{ + DEH970Controller DEH970Ctrl(&IRPort); + printf("begin\n"); + DEH970Ctrl.SendVolMinus(); + + while(1) + { + ; + } + printf("end\n"); + +}
diff -r 000000000000 -r e606807a2d4a mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Aug 15 11:05:11 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/b9ad9a133dc7 \ No newline at end of file