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 #include "mbed.h"
User_4574 0:64cb39e64128 2 #include "iface.h"
User_4574 0:64cb39e64128 3 #include "memory.h"
User_4574 0:64cb39e64128 4
User_4574 0:64cb39e64128 5 Timeout timer;
User_4574 0:64cb39e64128 6 char keydown = 0;
User_4574 0:64cb39e64128 7
User_4574 0:64cb39e64128 8 extern I2C io;
User_4574 0:64cb39e64128 9 extern int channelPointer;
User_4574 0:64cb39e64128 10 extern char* channelData;
User_4574 0:64cb39e64128 11 extern int waddr;
User_4574 0:64cb39e64128 12 extern int raddr;
User_4574 0:64cb39e64128 13
User_4574 0:64cb39e64128 14 void nextChannel() {
User_4574 0:64cb39e64128 15 if (channelPointer < (CHANNELCOUNT - 1)) channelPointer++;
User_4574 0:64cb39e64128 16 }
User_4574 0:64cb39e64128 17 void previousChannel() {
User_4574 0:64cb39e64128 18 if (channelPointer > 0) channelPointer--;
User_4574 0:64cb39e64128 19 }
User_4574 0:64cb39e64128 20 void incrementValue() {
User_4574 0:64cb39e64128 21 if (channelData[channelPointer] < 255) channelData[channelPointer]++;
User_4574 0:64cb39e64128 22 }
User_4574 0:64cb39e64128 23 void decrementValue() {
User_4574 0:64cb39e64128 24 if (channelData[channelPointer] > 0) channelData[channelPointer]--;
User_4574 0:64cb39e64128 25 }
User_4574 0:64cb39e64128 26 void homeChannel() {
User_4574 0:64cb39e64128 27 channelPointer = 0;
User_4574 0:64cb39e64128 28 }
User_4574 0:64cb39e64128 29 void zeroValue() {
User_4574 0:64cb39e64128 30 channelData[channelPointer] = 0;
User_4574 0:64cb39e64128 31 }
User_4574 0:64cb39e64128 32 void maxValue() {
User_4574 0:64cb39e64128 33 channelData[channelPointer] = 255;
User_4574 0:64cb39e64128 34 }
User_4574 0:64cb39e64128 35
User_4574 0:64cb39e64128 36 void handle(char key) {
User_4574 0:64cb39e64128 37 switch(key) {
User_4574 0:64cb39e64128 38 case 0x11:
User_4574 0:64cb39e64128 39 homeChannel();
User_4574 0:64cb39e64128 40 break;
User_4574 0:64cb39e64128 41 case 0x42:
User_4574 0:64cb39e64128 42 nextChannel();
User_4574 0:64cb39e64128 43 break;
User_4574 0:64cb39e64128 44 case 0x12:
User_4574 0:64cb39e64128 45 previousChannel();
User_4574 0:64cb39e64128 46 break;
User_4574 0:64cb39e64128 47 case 0x21:
User_4574 0:64cb39e64128 48 incrementValue();
User_4574 0:64cb39e64128 49 break;
User_4574 0:64cb39e64128 50 case 0x24:
User_4574 0:64cb39e64128 51 decrementValue();
User_4574 0:64cb39e64128 52 break;
User_4574 0:64cb39e64128 53 case 0x48:
User_4574 0:64cb39e64128 54 maxValue();
User_4574 0:64cb39e64128 55 break;
User_4574 0:64cb39e64128 56 case 0x18:
User_4574 0:64cb39e64128 57 zeroValue();
User_4574 0:64cb39e64128 58 break;
User_4574 0:64cb39e64128 59 case 0x14:
User_4574 0:64cb39e64128 60 saveMemory();
User_4574 0:64cb39e64128 61 break;
User_4574 0:64cb39e64128 62 case 0x44:
User_4574 0:64cb39e64128 63 loadMemory();
User_4574 0:64cb39e64128 64 break;
User_4574 0:64cb39e64128 65 }
User_4574 0:64cb39e64128 66 }
User_4574 0:64cb39e64128 67
User_4574 0:64cb39e64128 68 void keyhandle() {
User_4574 0:64cb39e64128 69 if(keydown) {
User_4574 0:64cb39e64128 70 handle(keydown);
User_4574 0:64cb39e64128 71 timer.attach_us(&keyhandle, 20000);
User_4574 0:64cb39e64128 72 }
User_4574 0:64cb39e64128 73 }
User_4574 0:64cb39e64128 74
User_4574 0:64cb39e64128 75 void keypress() {
User_4574 0:64cb39e64128 76 char byte0f, bytef0;
User_4574 0:64cb39e64128 77 io.read(raddr, &byte0f, 1);
User_4574 0:64cb39e64128 78 bytef0 = 0xF0;
User_4574 0:64cb39e64128 79 io.write(waddr, &bytef0, 1);
User_4574 0:64cb39e64128 80 io.read(raddr, &bytef0, 1);
User_4574 0:64cb39e64128 81 keydown = ~(byte0f | bytef0);
User_4574 0:64cb39e64128 82 if(keydown) {
User_4574 0:64cb39e64128 83 handle(keydown);
User_4574 0:64cb39e64128 84 if((keydown != 0x14) && (keydown != 0x44)) timer.attach_us(&keyhandle, 500000);
User_4574 0:64cb39e64128 85 }
User_4574 0:64cb39e64128 86 byte0f = 0x0F;
User_4574 0:64cb39e64128 87 io.write(waddr, &byte0f, 1);
User_4574 0:64cb39e64128 88 }