test ir controller for carozzeria audio

Dependencies:   mbed

IR test program for carozzeria audio

USB HID&赤外線ステアリングコントローラー

https://zeus3110.wordpress.com/2015/08/08/usb-hid%E8%B5%A4%E5%A4%96%E7%B7%9A%E3%82%B9%E3%83%86%E3%82%A2%E3%83%AA%E3%83%B3%E3%82%B0%E3%82%B3%E3%83%B3%E3%83%88%E3%83%AD%E3%83%BC%E3%83%A9%E3%83%BC/

回路図

https://zeus3110.wordpress.com/2015/08/13/usb-hid%E8%B5%A4%E5%A4%96%E7%B7%9A%E3%82%B9%E3%83%86%E3%82%A2%E3%83%AA%E3%83%B3%E3%82%B0%E3%82%B3%E3%83%B3%E3%83%88%E3%83%AD%E3%83%BC%E3%83%A9%E3%83%BC-%E5%9B%9E%E8%B7%AF%E5%9B%B3/

DEH970Ctrl.cpp

Committer:
zeus3110
Date:
2015-08-15
Revision:
0:e606807a2d4a

File content as of revision 0:e606807a2d4a:

#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);
}