DMX_Interface
bisher rudimentäres DMX Interface über RasPi SPI 0.
This commit is contained in:
parent
4cc0bd434d
commit
9a3a59a8ef
21
DMX_Interface.cpp
Normal file
21
DMX_Interface.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
//#include "UART.h"
|
||||
#include <wiringPiSPI.h>
|
||||
#include "SPI_DMX.h"
|
||||
|
||||
# define measure_length(type) ((char *)(&type+1)-(char*)(&type))
|
||||
|
||||
/* demo.c: My first C program on a Linux */
|
||||
int main(void)
|
||||
{
|
||||
printf("Hello! This is a test prgoram.\n");
|
||||
SPI_DMX spi1(0);
|
||||
spi1.nice();
|
||||
|
||||
unsigned char message[4] = {0x55,0x66,0x55,0x66};
|
||||
//uart.TX_Bytes(message,measure_length(message));
|
||||
|
||||
spi1.TX_Bytes(message,4);
|
||||
|
||||
return 0;
|
||||
}
|
BIN
DMX_Interface_main
Normal file
BIN
DMX_Interface_main
Normal file
Binary file not shown.
77
SPI_DMX.cpp
Normal file
77
SPI_DMX.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#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);
|
||||
}
|
16
SPI_DMX.h
Normal file
16
SPI_DMX.h
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <wiringPiSPI.h>
|
||||
|
||||
|
||||
class SPI_DMX
|
||||
{
|
||||
private:
|
||||
int uart_filestream;
|
||||
unsigned char serial_port;
|
||||
unsigned char message[5000];
|
||||
public:
|
||||
SPI_DMX(unsigned char serial_port);
|
||||
~SPI_DMX();
|
||||
void TX_Bytes(unsigned char* tx_buffer, unsigned char tx_size);
|
||||
void nice() {printf("nice\n");};
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user