DMX DeBUG clone source code

Dependencies:   TextLCD mbed

Committer:
User_4574
Date:
Tue Dec 06 22:31:21 2011 +0000
Revision:
0:64cb39e64128
DRAFT

Who changed what in which revision?

UserRevisionLine numberNew contents of line
User_4574 0:64cb39e64128 1 /* DMX Packet Library
User_4574 0:64cb39e64128 2 * Nathan Lasseter (User_4574) 2011
User_4574 0:64cb39e64128 3 * Released unlicenced
User_4574 0:64cb39e64128 4 * http://www.dmx512-online.com/packt.html
User_4574 0:64cb39e64128 5 */
User_4574 0:64cb39e64128 6
User_4574 0:64cb39e64128 7 #include "mbed.h"
User_4574 0:64cb39e64128 8 #include "DMXPacket.h"
User_4574 0:64cb39e64128 9
User_4574 0:64cb39e64128 10 void init(DigitalOut* dmx) {
User_4574 0:64cb39e64128 11 /* initialise */
User_4574 0:64cb39e64128 12 *dmx = MARK;
User_4574 0:64cb39e64128 13 return;
User_4574 0:64cb39e64128 14 }
User_4574 0:64cb39e64128 15
User_4574 0:64cb39e64128 16 void sendBreak(DigitalOut* dmx) {
User_4574 0:64cb39e64128 17 /* BREAK */
User_4574 0:64cb39e64128 18 *dmx = BREAK;
User_4574 0:64cb39e64128 19 wait_us(30 * PW);
User_4574 0:64cb39e64128 20 return;
User_4574 0:64cb39e64128 21 }
User_4574 0:64cb39e64128 22
User_4574 0:64cb39e64128 23 void sendMarkAfterBreak(DigitalOut* dmx) {
User_4574 0:64cb39e64128 24 /* MARK AFTER BREAK */
User_4574 0:64cb39e64128 25 *dmx = MARK;
User_4574 0:64cb39e64128 26 wait_us(3 * PW);
User_4574 0:64cb39e64128 27 return;
User_4574 0:64cb39e64128 28 }
User_4574 0:64cb39e64128 29
User_4574 0:64cb39e64128 30 void sendStartCode(DigitalOut* dmx) {
User_4574 0:64cb39e64128 31 /* 1 START 8 DATA */
User_4574 0:64cb39e64128 32 *dmx = BREAK;
User_4574 0:64cb39e64128 33 wait_us(9 * PW);
User_4574 0:64cb39e64128 34
User_4574 0:64cb39e64128 35 /* 2 STOP */
User_4574 0:64cb39e64128 36 *dmx = MARK;
User_4574 0:64cb39e64128 37 wait_us(2 * PW);
User_4574 0:64cb39e64128 38 return;
User_4574 0:64cb39e64128 39 }
User_4574 0:64cb39e64128 40
User_4574 0:64cb39e64128 41 void sendChannelData(DigitalOut* dmx, char* channelData) {
User_4574 0:64cb39e64128 42 char i, data = *channelData;
User_4574 0:64cb39e64128 43 /* 1 START */
User_4574 0:64cb39e64128 44 *dmx = BREAK;
User_4574 0:64cb39e64128 45 wait_us(PW);
User_4574 0:64cb39e64128 46
User_4574 0:64cb39e64128 47 /* 8 DATA */
User_4574 0:64cb39e64128 48 for(i = 0xF0; i; i >>= 1) {
User_4574 0:64cb39e64128 49 *dmx = ((data & i) ? MARK : BREAK);
User_4574 0:64cb39e64128 50 wait_us(PW);
User_4574 0:64cb39e64128 51 }
User_4574 0:64cb39e64128 52
User_4574 0:64cb39e64128 53 /* 2 STOP */
User_4574 0:64cb39e64128 54 *dmx = MARK;
User_4574 0:64cb39e64128 55 wait_us(2 * PW);
User_4574 0:64cb39e64128 56 return;
User_4574 0:64cb39e64128 57 }
User_4574 0:64cb39e64128 58
User_4574 0:64cb39e64128 59 void writePacket(DigitalOut* dmx, char* channelData, int channelCount) {
User_4574 0:64cb39e64128 60 int i;
User_4574 0:64cb39e64128 61
User_4574 0:64cb39e64128 62 /* BREAK */
User_4574 0:64cb39e64128 63 sendBreak(dmx);
User_4574 0:64cb39e64128 64
User_4574 0:64cb39e64128 65 /* MARK AFTER BREAK */
User_4574 0:64cb39e64128 66 sendMarkAfterBreak(dmx);
User_4574 0:64cb39e64128 67
User_4574 0:64cb39e64128 68 /* START CODE */
User_4574 0:64cb39e64128 69 sendStartCode(dmx);
User_4574 0:64cb39e64128 70
User_4574 0:64cb39e64128 71 /* CHANNEL DATA */
User_4574 0:64cb39e64128 72 for(i=0; i<channelCount; i++) {
User_4574 0:64cb39e64128 73
User_4574 0:64cb39e64128 74 /* MARK TIME BETWEEN FRAMES */
User_4574 0:64cb39e64128 75 *dmx = MARK;
User_4574 0:64cb39e64128 76 wait_us(MTBF * PW);
User_4574 0:64cb39e64128 77
User_4574 0:64cb39e64128 78 /* CHANNEL DATA */
User_4574 0:64cb39e64128 79 sendChannelData(dmx, channelData + i);
User_4574 0:64cb39e64128 80 }
User_4574 0:64cb39e64128 81
User_4574 0:64cb39e64128 82 /* MARK TIME BETWEEN PACKETS */
User_4574 0:64cb39e64128 83 /* AND RETURN TO IDLE */
User_4574 0:64cb39e64128 84 *dmx = MARK;
User_4574 0:64cb39e64128 85 wait_us(MTBP * PW);
User_4574 0:64cb39e64128 86 return;
User_4574 0:64cb39e64128 87 }