├── README └── readdsc_explore └── readdsc_explore.pde /README: -------------------------------------------------------------------------------- 1 | Arduino code to dump DSC Keybus packets to the serial bus. 2 | 3 | A short presentation is here http://www.house4hack.co.za/?p=410 4 | -------------------------------------------------------------------------------- /readdsc_explore/readdsc_explore.pde: -------------------------------------------------------------------------------- 1 | unsigned long lastread=0; 2 | int datapin = 4; // 4 on the uno; 1 on the tiny 3 | int clockpin = 2; // 2 on the uno ; 2 on the tiny 4 | 5 | #define databytes 14 6 | int data[databytes]; 7 | int datavalue = 0; 8 | 9 | 10 | int bitcounter = 0; 11 | int dataindex = 0; 12 | 13 | int dataread=0; 14 | int lastdataread = 0; 15 | int startbit = 1; 16 | boolean canprint =false; 17 | boolean ignorepadding = true; 18 | unsigned long lastprint = 0; 19 | 20 | #define rxPin 1 21 | #define txPin 3 22 | 23 | void setup() { 24 | // define pin modes for tx, rx, led pins: 25 | Serial.begin(115200); 26 | pinMode(datapin, INPUT); 27 | pinMode(clockpin, INPUT); 28 | 29 | attachInterrupt(0, readbit, CHANGE); 30 | data[0] = 0; 31 | lastread = micros(); 32 | lastprint = millis(); 33 | } 34 | 35 | void loop() { 36 | 37 | unsigned long now = micros(); 38 | if((abs(now - lastread) >1000) && (abs(now - lastread) <10000) && canprint) { 39 | if(data[0]!= 0xA && data[0]!= 0x5 && data[0]!= 0){ 40 | for(int i=0; i<= dataindex; i++){ Serial.print(data[i], HEX); Serial.print(' '); } 41 | Serial.println(); 42 | } 43 | dataindex = 0; 44 | data[dataindex] = 0; 45 | datavalue = 0; 46 | bitcounter = 0; 47 | startbit = 1; 48 | ignorepadding = true; 49 | 50 | canprint = false; 51 | 52 | 53 | } 54 | 55 | } 56 | 57 | 58 | void readbit(){ 59 | lastread = micros(); 60 | int clkstate = digitalRead(clockpin); 61 | if(1==1 ) { // watch for noise 62 | 63 | if(clkstate == LOW) { 64 | if(!startbit){ 65 | if(dataindex != 1 || bitcounter!=0 || !ignorepadding){ 66 | data[dataindex] |= datavalue << (7-bitcounter); 67 | datavalue = 0; 68 | 69 | bitcounter++; 70 | if(bitcounter==8){ 71 | dataindex++; 72 | data[dataindex] = 0; 73 | bitcounter = 0; 74 | } 75 | } else { 76 | ignorepadding = false; 77 | } 78 | } else { 79 | startbit -= 1; //eat startbits 80 | datavalue = 0; 81 | } 82 | 83 | } else { 84 | datavalue = digitalRead(datapin); 85 | } 86 | 87 | 88 | 89 | canprint = true; 90 | } 91 | 92 | 93 | } 94 | 95 | 96 | 97 | 98 | 99 | 100 | --------------------------------------------------------------------------------