Browse Source

DMX_Interface

bisher rudimentäres DMX Interface über RasPi SPI 0.
master
Leon Bälz 2 years ago
parent
commit
9a3a59a8ef
5 changed files with 126 additions and 0 deletions
  1. 21
    0
      DMX_Interface.cpp
  2. BIN
      DMX_Interface_main
  3. 77
    0
      SPI_DMX.cpp
  4. 16
    0
      SPI_DMX.h
  5. 12
    0
      blink.cpp

+ 21
- 0
DMX_Interface.cpp View 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 View File


+ 77
- 0
SPI_DMX.cpp View 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
- 0
SPI_DMX.h View 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");};
};

+ 12
- 0
blink.cpp View File

@@ -0,0 +1,12 @@
#include <wiringPi.h>
int main (void)
{
wiringPiSetup () ;
pinMode (0, OUTPUT) ;
for (;;)
{
digitalWrite (0, HIGH) ; delay (500) ;
digitalWrite (0, LOW) ; delay (500) ;
}
return 0 ;
}

Loading…
Cancel
Save