Exemple #1
0
def tt4GetSysInf():            
    sysInfCmd=[0x04,0x00,0x05,0x00,0x2F,0x00,0x02]
    dataleng=0x0000
    while dataleng!=0x3300:
        tt4.i2cw(TT4Addr,sysInfCmd)
        try:
            #tt4.i2cw(TT4Addr,sysInfCmd)
            #tt4.delayMs(1.5)
            #if GPIO.input(bInt)==0:
            GPIO.wait_for_edge(bInt,GPIO.FALLING,timeout=300) 
            data=tt4.i2cr(TT4Addr,3)
            dataleng=(data[0]<<8)+data[1]
            if dataleng==0x3300:
                data=tt4.i2cr(TT4Addr,data[0]) 
                fwVer=(data[9]<<8)+data[10]
                fwRev=(data[11]<<16)+(data[12]<<8)+data[13]
                cfgVer=(data[14]<<8)+data[15]
                xNum=data[33]
                yNum=data[34]
                print 'fwVer :0x%04x'%fwVer
                print 'fwRev :0x%06x'%fwRev
                print 'cfgVer:0x%04x'%cfgVer
                print 'rxNum:0x%02x'%xNum
                print 'txNum:0x%02x'%yNum
                trNum=[xNum,yNum]
                return trNum
        except KeyboardInterrupt:
            tt4.ldoPowerOff()  
            GPIO.cleanup() 
Exemple #2
0
def tt4PanelScan():
    panelScan = [0x04, 0x00, 0x05, 0x00, 0x2F, 0x00, 0x2A]
    print 'start to do panel scan'
    statusResult = 0xFF
    while statusResult != 0x00:
        tt4.i2cw(TT4Addr, panelScan)
        try:
            GPIO.wait_for_edge(bInt, GPIO.FALLING, timeout=300)
            result = tt4.i2cr(TT4Addr, 6)
            statusResult = result[5]
            print result
        except KeyboardInterrupt:
            GPIO.cleanup()
Exemple #3
0
def tt4ResumeScan():
    resumeCommand = [0x04, 0x00, 0x05, 0x00, 0x2F, 0x00, 0x04]
    success = 0x2F
    tt4.delayMs(1)
    while success != 0x1F:
        tt4.i2cw(TT4Addr, resumeCommand)
        try:
            GPIO.wait_for_edge(bInt, GPIO.FALLING, timeout=300)
            result = tt4.i2cr(TT4Addr, 5)
            success = result[2]
            print 'resume scan response {0}'.format(result)
        except KeyboardInterrupt:
            GPIO.cleanup()
Exemple #4
0
def tt4SusScan():
    susCommand=[0x04,0x00,0x05,0x00,0x2F,0x00,0x03]
    success=0x2F
    #tt4.i2cw(TT4Addr,susCommand)
    tt4.delayMs(1)
    while success!=0x1F:
        tt4.i2cw(TT4Addr,susCommand)
        try:
            #tt4.i2cw(TT4Addr,susCommand)
            GPIO.wait_for_edge(bInt,GPIO.FALLING,timeout=300) 
            result=tt4.i2cr(TT4Addr,5)
            success=result[2]
            print 'suspend scan response {0}'.format(result)
        except KeyboardInterrupt:
            tt4.ldoPowerOff()  
            GPIO.cleanup()
Exemple #5
0
def tt4PanlScan():
    scanCmd=[0x04,0x00,0x05,0x00,0x2F,0x00,0x2A]
    result=0xFFFF
    print 'start to do the panel scan'
    while result!=0x1F00:
        tt4.i2cw(TT4Addr,scanCmd)
        try:
            GPIO.wait_for_edge(bInt,GPIO.FALLING,timeout=500)
            data=tt4.i2cr(TT4Addr,6)
            result=(data[2]<<8)+data[5]
            if result==0x1F00:
               print 'Scan success:0x%04x'%result
            else:
               print 'Scan Fail :0x%04x'%result          
        except KeyboardInterrupt:
            tt4.ldoPowerOff()
            GPIO.cleanup()
Exemple #6
0
def tt4GetScan(txNum,rxNum,cmdNum):
    cmdNumM=cmdNum
    cmdNumS=cmdNum+3
    retriveScanDataM=[0x04,0x00,0x0A,0x00,0x2F,0x00,0x2B,0x00,0x00,0xFF,0xFF,cmdNumM]
    retriveScanDataS=[0x04,0x00,0x0A,0x00,0x2F,0x00,0x2B,0x00,0x00,0xFF,0xFF,cmdNumS]    
    totalByte=(txNum*rxNum)    
    mutual=np.zeros((1,totalByte*2))
    self=np.zeros((1,(txNum+rxNum)*2))
    
    # start to retrive data
    tt4PanlScan()
    
    print 'Start to retrive Data'    
    countByte=0
    index=0
    executeCmd=1
    while countByte<totalByte: # read Mutal data
        if executeCmd==1:
            tt4.i2cw(TT4Addr,retriveScanDataM)
        else:
           executeCmd=0
        try:
            #GPIO.wait_for_edge(bInt,GPIO.FALLING,timeout=500)            
            if GPIO.input(bInt)==0:
                result=tt4.i2cr(TT4Addr,2)
                print result
                packetLength=(result[1]<<8)+result[0]
                result=tt4.i2cr(TT4Addr,packetLength)
                thisSensByte=(result[8]<<8)+result[7]
                countByte=countByte+thisSensByte
                print 'countByte byte:{0}' .format(countByte)
                print 'This sense total byte:{0}'.format(packetLength)
                retriveScanDataM[7]=countByte&0x00FF      # offset value         
                retriveScanDataM[8]=(countByte>>8)&0xFF   # offset value
                count=0         
                while count<(thisSensByte*2):
                    val=int((result[count+11]<<8)+result[count+10])
                    if cmdNum==2:
                        val=twos_comp(val,16)
                    else: 
                        val=val
                    mutual[0][index]=val 
                    count=count+2
                    index=index+1
                tt4.delayMs(0.5)
                executeCmd=1
            else:
                tt4.delayMs(1)
                executeCmd=0                
        except KeyboardInterrupt:
            tt4.ldoPowerOff() 
            GPIO.cleanup()
# start to retrive Self data
    tt4PanlScan()    
    print 'Start to retvie self data'
    index=0
    countByte=0
    executeCmd=1
    while countByte<(txNum+rxNum):
        if executeCmd==1:
            tt4.i2cw(TT4Addr,retriveScanDataS)
        try:
            #GPIO.wait_for_edge(bInt,GPIO.FALLING)
            if GPIO.input(bInt)==0:
                result=tt4.i2cr(TT4Addr,2)
                packetLength=(result[1]<<8)+result[0]
                result=tt4.i2cr(TT4Addr,packetLength)
                thisSensByte=(result[8]<<8)+result[7]
                countByte=countByte+thisSensByte
                print 'countByte:{0}'.format(countByte)
                print 'PacketLength:{0}'.format(packetLength)
                retriveScanDataS[7]=countByte&0x00FF            
                retriveScanDataS[8]=(countByte>>8)&0xFF 
                count=0          
                while count<(thisSensByte*2):
                    val=int((result[count+11]<<8)+result[count+10])
                    if cmdNum==2:
                        val=twos_comp(val,16)
                    self[0][index]=val 
                    count=count+2
                    index=index+1
                tt4.delayMs(0.5)
                executeCmd=1
            else:
                tt4.delayMs(1)
                executeCmd=0                
        except KeyboardInterrupt:
            tt4.ldoPowerOff()
            GPIO.cleanup()
    return mutual,self    
Exemple #7
0
def tt4GetRawData(txNum,rxNum):
    cmSelfTestCmd=[0x04,0x00,0x06,0x00,0x2F,0x00,0x26,0x05]
    cmGetRepCmd=[0x04,0x00,0x0A,0x00,0x2F,0x00,0x27,0x00,0x00,0xFF,0xFF,0x05]
    cpSelfTestCmd=[0x04,0x00,0x06,0x00,0x2F,0x00,0x26,0x06]
    cpGetRepCmd=[0x04,0x00,0x0A,0x00,0x2F,0x00,0x27,0x00,0x00,0xFF,0xFF,0x06]
    totalByte=(txNum*rxNum*2)+2    
    cmRawData=np.zeros((1,totalByte/2))
    #icpRawData=np.zeros((1,txNum+rxNum+2))
    cpRawData=np.zeros((1,(txNum*2+rxNum*2)))
    
    # start to do Cm Self test
    print 'start to do Cm Self test'
    statusResult=0xFFFF
    while statusResult!=0x0000:
        tt4.i2cw(TT4Addr,cmSelfTestCmd)
        try:        
            GPIO.wait_for_edge(bInt,GPIO.FALLING,timeout=300) 
            result=tt4.i2cr(TT4Addr,7)
            statusResult=(result[5]<<8)+result[6]
            print result
            if statusResult==0x0000:            
                print 'Cm Self Test Status+Result:0x%04x' %statusResult
            elif result[5]==0xff:
                print 'not support Cm self test ID 0x05'
                GPIO.cleanup()
                sys.exit()
            elif result[6]==0x01:
                print 'Cm self test Fail'
                GPIO.cleanup()
                sys.exit()               
        except KeyboardInterrupt:
            tt4.ldoPowerOff()  
            GPIO.cleanup()
    
    countByte=0
    index=0
    executeCmd=1
    while countByte<totalByte: # read Cm self test raw data;
        if executeCmd==1:
            tt4.i2cw(TT4Addr,cmGetRepCmd)
        try:
            #GPIO.wait_for_edge(bInt,GPIO.FALLING,timeout=500)            
            if GPIO.input(bInt)==0:
                result=tt4.i2cr(TT4Addr,2)
                print result
                packetLength=(result[1]<<8)+result[0]
                result=tt4.i2cr(TT4Addr,packetLength)
                thisSensByte=(result[8]<<8)+result[7]
                countByte=countByte+thisSensByte
                print 'countByte byte:{0}' .format(countByte)
                print 'This sense total byte:{0}'.format(packetLength)
                cmGetRepCmd[7]=countByte&0x00FF      # offset value         
                cmGetRepCmd[8]=(countByte>>8)&0xFF   # offset value
                count=0         
                while count<(thisSensByte):
                    cmRawData[0][index]=int((result[count+11]<<8)+result[count+10]) #fF/10
                    count=count+2
                    index=index+1
                tt4.delayMs(1)
                executeCmd=1
            else:
                tt4.delayMs(2)
                executeCmd=0                
        except KeyboardInterrupt:
            tt4.ldoPowerOff()
            GPIO.clearnup()
    #Send Cp Self test start     
    statusResult=0xFFFF     
    tt4.i2cw(TT4Addr,cpSelfTestCmd)     
    try:
        while statusResult==0xFFFF:
            GPIO.wait_for_edge(bInt,GPIO.FALLING,timeout=300) 
            result=tt4.i2cr(TT4Addr,7)
            statusResult=(result[5]<<8)+result[6]
            print result
            if statusResult==0x0000:            
                print 'Cp Self Test Status+Result:0x%04x' %statusResult
            elif result[5]==0xFF:
                print 'not support Cp self test ID 0x06'
                GPIO.cleanup()
                sys.exit()
            elif result[6]==0x01:
                print 'not support Cp self test fail'
                tt4.ldoPowerOff()
                GPIO.cleanup()
                sys.exit()           
    except KeyboardInterrupt:
        tt4.ldoPowerOff()
        GPIO.cleanup()
    index=0
    countByte=0
    executeCmd=1
    while countByte<(txNum+rxNum)*4:
        index=0
        #countByte=0
        tt4.i2cw(TT4Addr,cpGetRepCmd)
        try:
            #GPIO.wait_for_edge(bInt,GPIO.FALLING)
            if GPIO.input(bInt)==0:
                result=tt4.i2cr(TT4Addr,2)
                packetLength=(result[1]<<8)+result[0]
                result=tt4.i2cr(TT4Addr,packetLength)
                thisSensByte=(result[8]<<8)+result[7]
                countByte=countByte+thisSensByte
                print 'Cp countByte:{0}'.format(countByte)
                print 'Cp PacketLength:{0}'.format(packetLength)
                cpGetRepCmd[7]=countByte&0x00FF            
                cpGetRepCmd[8]=(countByte>>8)&0xFF 
                count=0          
                while count<(thisSensByte):
                    cpRawData[0][index]=int((result[count+11]<<8)+result[count+10]) #fF/10
                    count=count+2
                    index=index+1
                tt4.delayMs(1)
                executeCmd=1
            else:
                executeCmd=0
                tt4.delayMs(2)                
        except KeyboardInterrupt:
            tt4.ldoPowerOff() 
            GPIO.cleanup()
    return cmRawData,cpRawData    
Exemple #8
0
def tt4GetMutual(txNum, rxNum):
    mrGetRepCmd = [
        0x04, 0x00, 0x0A, 0x00, 0x2F, 0x00, 0x2B, 0x00, 0x00, 0x7B, 0x00, 0x00
    ]
    mdGetRepCmd = [
        0x04, 0x00, 0x0A, 0x00, 0x2F, 0x00, 0x2B, 0x00, 0x00, 0x7B, 0x00, 0x02
    ]
    totalByte = (txNum * rxNum)
    mrGetData = np.zeros((1, totalByte))
    mdGetData = np.zeros((1, totalByte))

    try:
        print 'start to do get mutual raw'
        tt4PanelScan()
        tt4.delayMs(10)
        countByte = 0
        index = 0
        while countByte < totalByte:  # read mutual raw data;
            tt4.i2cw(TT4Addr, mrGetRepCmd)
            tt4.delayMs(1.5)
            if GPIO.input(bInt) == 0:
                result = tt4.i2cr(TT4Addr, 2)
                print result
                packetLength = (result[1] << 8) + result[0]
                result = tt4.i2cr(TT4Addr, packetLength)
                thisSensByte = (result[8] << 8) + result[7]
                countByte = countByte + thisSensByte
                print 'countByte byte:{0}'.format(countByte)
                print 'This sense total byte:{0}'.format(packetLength)
                mrGetRepCmd[7] = countByte & 0x00FF  # offset value
                mrGetRepCmd[8] = (countByte >> 8) & 0xFF  # offset value
                count = 0
                while count < (thisSensByte * 2):
                    mrGetData[0][index] = int((result[count + 11] << 8) +
                                              result[count + 10])  # fF/10
                    count = count + 2
                    index = index + 1

        print 'start to do get mutual diff'
        tt4PanelScan()
        tt4.delayMs(10)
        countByte = 0
        index = 0
        while countByte < totalByte:  # read mutual diff;
            tt4.i2cw(TT4Addr, mdGetRepCmd)
            tt4.delayMs(1.5)
            if GPIO.input(bInt) == 0:
                result = tt4.i2cr(TT4Addr, 2)
                print result
                packetLength = (result[1] << 8) + result[0]
                result = tt4.i2cr(TT4Addr, packetLength)
                thisSensByte = (result[8] << 8) + result[7]
                countByte = countByte + thisSensByte
                print 'countByte byte:{0}'.format(countByte)
                print 'This sense total byte:{0}'.format(packetLength)
                mdGetRepCmd[7] = countByte & 0x00FF  # offset value
                mdGetRepCmd[8] = (countByte >> 8) & 0xFF  # offset value
                count = 0
                while count < (thisSensByte * 2):
                    mdGetData[0][index] = int((result[count + 11] << 8) +
                                              result[count + 10])  # fF/10
                    if mdGetData[0][index] > 60000:
                        mdGetData[0][index] = mdGetData[0][index] - 65536
                    count = count + 2
                    index = index + 1

    except KeyboardInterrupt:
        GPIO.clearnup()

    return mrGetData, mdGetData