DMX DeBUG clone source code

Dependencies:   TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
User_4574
Date:
Tue Dec 06 22:31:21 2011 +0000
Commit message:
DRAFT

Changed in this revision

DMXPacket/DMXPacket.c Show annotated file Show diff for this revision Revisions of this file
DMXPacket/DMXPacket.h Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
iface.c Show annotated file Show diff for this revision Revisions of this file
iface.h Show annotated file Show diff for this revision Revisions of this file
main.c Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
memory.c Show annotated file Show diff for this revision Revisions of this file
memory.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 64cb39e64128 DMXPacket/DMXPacket.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DMXPacket/DMXPacket.c	Tue Dec 06 22:31:21 2011 +0000
@@ -0,0 +1,87 @@
+/* DMX Packet Library
+ * Nathan Lasseter (User_4574) 2011
+ * Released unlicenced
+ * http://www.dmx512-online.com/packt.html
+ */
+
+#include "mbed.h"
+#include "DMXPacket.h"
+
+void init(DigitalOut* dmx) {
+    /* initialise */
+    *dmx = MARK;
+    return;
+}
+
+void sendBreak(DigitalOut* dmx) {
+    /* BREAK */
+    *dmx = BREAK;
+    wait_us(30 * PW);
+    return;
+}
+
+void sendMarkAfterBreak(DigitalOut* dmx) {
+    /* MARK AFTER BREAK */
+    *dmx = MARK;
+    wait_us(3 * PW);
+    return;
+}
+
+void sendStartCode(DigitalOut* dmx) {
+    /* 1 START 8 DATA */
+    *dmx = BREAK;
+    wait_us(9 * PW);
+    
+    /* 2 STOP */
+    *dmx = MARK;
+    wait_us(2 * PW);
+    return;
+}
+
+void sendChannelData(DigitalOut* dmx, char* channelData) {
+    char i, data = *channelData;
+    /* 1 START */
+    *dmx = BREAK;
+    wait_us(PW);
+    
+    /* 8 DATA */
+    for(i = 0xF0; i; i >>= 1) {
+        *dmx = ((data & i) ? MARK : BREAK);
+        wait_us(PW);
+    }
+    
+    /* 2 STOP */
+    *dmx = MARK;
+    wait_us(2 * PW);
+    return;
+}
+
+void writePacket(DigitalOut* dmx, char* channelData, int channelCount) {
+    int i;
+    
+    /* BREAK */
+    sendBreak(dmx);
+    
+    /* MARK AFTER BREAK */
+    sendMarkAfterBreak(dmx);
+    
+    /* START CODE */
+    sendStartCode(dmx);
+    
+    /* CHANNEL DATA */
+    for(i=0; i<channelCount; i++) {
+    
+        /* MARK TIME BETWEEN FRAMES */
+        *dmx = MARK;
+        wait_us(MTBF * PW);
+        
+        /* CHANNEL DATA */
+        sendChannelData(dmx, channelData + i);
+    }
+    
+    /* MARK TIME BETWEEN PACKETS */
+    /* AND RETURN TO IDLE */
+    *dmx = MARK;
+    wait_us(MTBP * PW);
+    return;
+}
\ No newline at end of file
diff -r 000000000000 -r 64cb39e64128 DMXPacket/DMXPacket.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DMXPacket/DMXPacket.h	Tue Dec 06 22:31:21 2011 +0000
@@ -0,0 +1,10 @@
+#include "mbed.h"
+#define MARK 1
+#define BREAK 0
+
+#define PW 4
+#define MTBF 1
+#define MTBP 1
+
+void init(DigitalOut*);
+void writePacket(DigitalOut*, char*, int);
\ No newline at end of file
diff -r 000000000000 -r 64cb39e64128 TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Tue Dec 06 22:31:21 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r 000000000000 -r 64cb39e64128 iface.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/iface.c	Tue Dec 06 22:31:21 2011 +0000
@@ -0,0 +1,88 @@
+#include "mbed.h"
+#include "iface.h"
+#include "memory.h"
+
+Timeout timer;
+char keydown = 0;
+
+extern I2C io;
+extern int channelPointer;
+extern char* channelData;
+extern int waddr;
+extern int raddr;
+
+void nextChannel() {
+    if (channelPointer < (CHANNELCOUNT - 1)) channelPointer++;
+}
+void previousChannel() {
+    if (channelPointer > 0) channelPointer--;
+}
+void incrementValue() {
+    if (channelData[channelPointer] < 255) channelData[channelPointer]++;
+}
+void decrementValue() {
+    if (channelData[channelPointer] > 0) channelData[channelPointer]--;
+}
+void homeChannel() {
+    channelPointer = 0;
+}
+void zeroValue() {
+    channelData[channelPointer] = 0;
+}
+void maxValue() {
+    channelData[channelPointer] = 255;
+}
+
+void handle(char key) {
+    switch(key) {
+        case 0x11:
+            homeChannel();
+            break;
+        case 0x42:
+            nextChannel();
+            break;
+        case 0x12:
+            previousChannel();
+            break;
+        case 0x21:
+            incrementValue();
+            break;
+        case 0x24:
+            decrementValue();
+            break;
+        case 0x48:
+            maxValue();
+            break;
+        case 0x18:
+            zeroValue();
+            break;
+        case 0x14:
+            saveMemory();
+            break;
+        case 0x44:
+            loadMemory();
+            break;
+    }
+}
+
+void keyhandle() {
+    if(keydown) {
+        handle(keydown);
+        timer.attach_us(&keyhandle, 20000);
+    }
+}
+
+void keypress() {
+    char byte0f, bytef0;
+    io.read(raddr, &byte0f, 1);
+    bytef0 = 0xF0;
+    io.write(waddr, &bytef0, 1);
+    io.read(raddr, &bytef0, 1);
+    keydown = ~(byte0f | bytef0);
+    if(keydown) {
+        handle(keydown);
+        if((keydown != 0x14) && (keydown != 0x44)) timer.attach_us(&keyhandle, 500000);
+    }
+    byte0f = 0x0F;
+    io.write(waddr, &byte0f, 1);
+}
\ No newline at end of file
diff -r 000000000000 -r 64cb39e64128 iface.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/iface.h	Tue Dec 06 22:31:21 2011 +0000
@@ -0,0 +1,4 @@
+#define KEY_COUNT 4
+#define CHANNELCOUNT 512
+
+void keypress();
\ No newline at end of file
diff -r 000000000000 -r 64cb39e64128 main.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.c	Tue Dec 06 22:31:21 2011 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+#include "DMXPacket.h"
+#include "iface.h"
+#include "TextLCD.h"
+
+DigitalOut dmx(p20);
+InterruptIn intr(p29);
+I2C io(p28, p27);
+
+TextLCD lcd(p16, p15, p13, p12, p11, p10); // rs, e, d4-d7
+
+int channelPointer = 0;
+char* channelData = (char*) calloc(CHANNELCOUNT, sizeof(char));
+int waddr = 0x40;
+int raddr = waddr+1;
+
+int main() {
+    char byte[1];
+    io.frequency(100000);
+    byte[0]=0x0F;
+    io.write(waddr, byte, 1);
+    
+    intr.fall(&keypress);
+    
+    init(&dmx);
+    
+    lcd.cls();
+    lcd.printf("   Welcome to\n ** DMXDebug! **");
+    wait(2);
+    lcd.cls();
+    
+    //printf("\r\nWelcome to DMXDebug!\r\n");
+    while (1) {
+        //printf("\rChannel: %03d\t\tData: %03d", channelPointer, channelData[channelPointer]);
+        lcd.locate(0, 0);
+        lcd.printf("Channel : %03d\n   Data : %03d", channelPointer, channelData[channelPointer]);
+        writePacket(&dmx, channelData, CHANNELCOUNT);
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 64cb39e64128 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Dec 06 22:31:21 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912
diff -r 000000000000 -r 64cb39e64128 memory.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/memory.c	Tue Dec 06 22:31:21 2011 +0000
@@ -0,0 +1,27 @@
+#include "mbed.h"
+#include "iface.h"
+#include "memory.h"
+
+LocalFileSystem local("local");
+
+extern int channelPointer;
+extern char* channelData;
+
+void saveMemory() {
+    int chan;
+    FILE* mem = fopen("/local/memory.txt", "w");
+    for(chan = 0; chan < CHANNELCOUNT; chan++)
+        if(channelData[chan])
+            fprintf(mem, "%03d %03hhd\r\n", chan, channelData[chan]);
+    fclose(mem);
+}
+
+void loadMemory() {
+    int chan;
+    char val;
+    for(chan = 0; chan < CHANNELCOUNT; chan++) channelData[channelPointer] = 0;
+    FILE* mem = fopen("/local/memory.txt", "r");
+    while(fscanf(mem, "%d %hhd ", &chan, &val) != EOF) channelData[chan] = val;
+    fclose(mem);
+    channelPointer = 0;
+}
\ No newline at end of file
diff -r 000000000000 -r 64cb39e64128 memory.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/memory.h	Tue Dec 06 22:31:21 2011 +0000
@@ -0,0 +1,2 @@
+void saveMemory();
+void loadMemory();
\ No newline at end of file