Subversion Repositories LedShow

Rev

Rev 6 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 mjames 1
/*
2
 * dmx.c
3
 *
4
 *  Created on: 26 Jul 2019
5
 *      Author: Mike
6
 */
7
 
7 mjames 8
#include "stdint.h"
9
#include "string.h"
10
#include "dmx.h"
6 mjames 11
 
12
 
13
// DMX state variables
14
DMX_State_t DMX_State = DMX_IDLE;
15
uint8_t DMX_Buffer[512];
16
uint32_t DMX_Pointer;
17
 
7 mjames 18
void dmx_handle_state(uint8_t* Buf, uint32_t *Len)
6 mjames 19
{
20
switch (DMX_State)
21
{
22
case    DMX_IDLE:  // nothing happening
23
          break;
24
case DMX_BREAK://
25
          if(*Len > 0)
26
          {
27
                  if( Buf[0] != 0)
28
                  DMX_State = DMX_IDLE;
29
                  else
30
                  {
31
                          memcpy(DMX_Buffer,Buf+1,*Len-1);
32
                          DMX_Pointer = *Len-1;
33
                          DMX_State = DMX_BYTES;
34
                  }
35
          }
36
          break;
37
case    DMX_BYTES:
38
{
39
    int count = *Len;
40
    int newPointer  = DMX_Pointer + count;
41
    if(newPointer >= 512)
42
          count = 512-count;
43
 
44
    memcpy(DMX_Buffer+ DMX_Pointer, Buf, count);
45
    DMX_Pointer += count;
46
    if (DMX_Pointer == 512)
47
    {
48
       DMX_State = DMX_DATA;
49
    }
50
}
51
break;
52
case DMX_DATA:
53
case DMX_DONE:
54
   break;
55
}
7 mjames 56
}
6 mjames 57