Browse Source

„SPI_DMX.cpp“ löschen

master
Lars Mewes 2 years ago
parent
commit
005c3fe61f
1 changed files with 0 additions and 77 deletions
  1. 0
    77
      SPI_DMX.cpp

+ 0
- 77
SPI_DMX.cpp View File

@@ -1,77 +0,0 @@
#include "SPI_DMX.h"

#define SPI_FREQHz (8.0*8.0e5)
#define SPI_BYTEus ((8.0e6/SPI_FREQHz)*1.6) //weird translation factor idk
#define DMX_BITus 4
#define BREAKus (25*DMX_BITus)
#define MABus (3*DMX_BITus)
#define STARTus (DMX_BITus)
#define STOPus (2*DMX_BITus)

#define BY_HIGH 0x00
#define BY_LOW 0xFF



SPI_DMX::SPI_DMX(unsigned char serial_port)
{
this->serial_port = serial_port;
for(int i = 0; i < BREAKus/SPI_BYTEus; i++)
{
this->message[i] = BY_LOW;
}
for(int i = BREAKus/SPI_BYTEus; i < (BREAKus+MABus)/SPI_BYTEus; i++)
{
this->message[i] = BY_HIGH;
}
wiringPiSPISetup(serial_port,SPI_FREQHz);
printf("%f\n",SPI_FREQHz);
}

SPI_DMX::~SPI_DMX()
{
}

void SPI_DMX::TX_Bytes(unsigned char* tx_buffer, unsigned char tx_size)
{
//unsigned int SPIbits = (BREAKus+MABus+(size*(STARTus+8*DMX_BITus+STOPus)))/SPI_BITus;
//unsigned char message[SPIbits];
int messind = (BREAKus+MABus)/SPI_BYTEus;
printf("%i\n",messind);
for(int b = 0; b < tx_size; b++)
{
for(int i = 0; i < STARTus/SPI_BYTEus; i++)
{
message[messind++] = BY_LOW;
}
for(int i = 0; i < 8; i++)
{
unsigned char txbit = tx_buffer[b];
txbit = ~((((txbit >> i) & 0x01) ^ 0x01) * 0xFF); //NEEDS TO BE ADJUSTED IF LOGIC LEVEL IS REVERSED
for(int i = 0; i < DMX_BITus/SPI_BYTEus; i++)
{
message[messind++] = txbit;
}
}
for(int i = 0; i < STOPus/SPI_BYTEus; i++)
{
message[messind++] = BY_HIGH;
}
}
printf("%i\n",messind);
/*messind = 0;
for(int i = 0; i < 8; i++)
{
unsigned char txbit = tx_buffer[0];
txbit = ((txbit >> i) & 0x01) * 0xFF;
for(int i = 0; i < DMX_BITus/SPI_BYTEus; i++)
{
message[messind++] = txbit;
}
printf("%u %u %f %i \n",tx_buffer[0],txbit,DMX_BITus/SPI_BYTEus,messind);
} */
wiringPiSPIDataRW(this->serial_port, message, messind-1);
}

Loading…
Cancel
Save