Mercurial > code > home > repos > homeauto
diff service/garageArduino/garage/garage.pde @ 839:9cf01cee74f6
garage: videoselect and shiftbrite move from parallel to arduino
Ignore-this: 45c791caa87d4c054826020eeae8298b
darcs-hash:20120625075033-312f9-fe2b5088e638e008dd194bd450aa1bac3d48c233.gz
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Mon, 25 Jun 2012 00:50:33 -0700 |
parents | 44e1ca03ddf1 |
children | 62b3bb861e35 |
line wrap: on
line diff
--- a/service/garageArduino/garage/garage.pde Mon May 07 00:17:40 2012 -0700 +++ b/service/garageArduino/garage/garage.pde Mon Jun 25 00:50:33 2012 -0700 @@ -1,4 +1,51 @@ - void setup() { +/* +board is Arduino UNO with '328 + */ + +int datapin = 7; // DI +int latchpin = 9; // LI +int clockpin = 8; // CI + +unsigned long SB_CommandPacket; +int SB_CommandMode; +int SB_BlueCommand; +int SB_RedCommand; +int SB_GreenCommand; + +#define SHIFT(val) shiftOut(datapin, clockpin, MSBFIRST, val) + +void SB_SendPacket() { + /* high bits are 00 for color, 01 for current */ + SB_CommandPacket = SB_CommandMode & B11; + SB_CommandPacket = (SB_CommandPacket << 10) | (SB_BlueCommand & 1023); + SB_CommandPacket = (SB_CommandPacket << 10) | (SB_RedCommand & 1023); + SB_CommandPacket = (SB_CommandPacket << 10) | (SB_GreenCommand & 1023); + + SHIFT(SB_CommandPacket >> 24); + SHIFT(SB_CommandPacket >> 16); + SHIFT(SB_CommandPacket >> 8); + SHIFT(SB_CommandPacket); +} + +void latch() { + delayMicroseconds(100); + digitalWrite(latchpin,HIGH); // latch data into registers + delayMicroseconds(100); + digitalWrite(latchpin,LOW); +} + +void setCurrent(byte r, byte g, byte b) { + /* 127 = max */ + SB_CommandMode = B01; // Write to current control registers + SB_RedCommand = r; + SB_GreenCommand = g; + SB_BlueCommand = b; + SB_SendPacket(); + latch(); +} + + +void setup() { pinMode(2, INPUT); digitalWrite(2, LOW); @@ -16,6 +63,21 @@ // circuitry to prevent such glitches, so a pull-down // resistor may be enough. I haven't checked carefully. + pinMode(4, OUTPUT); + pinMode(5, OUTPUT); + // video input selector. picks which video input will be multiplexed + // into the bt848 capture card + + pinMode(6, OUTPUT); // front yard light + + pinMode(7, OUTPUT); // bathroom shiftbrite data + pinMode(8, OUTPUT); // bathroom shiftbrite clk + pinMode(9, OUTPUT); // bathroom shiftbrite latch + + for (int i=0; i < 1; i++) { + setCurrent(127, 127, 127); + } + Serial.begin(115200); } @@ -74,7 +136,30 @@ Serial.print("{\"garage\":"); Serial.print(arg ? "true" : "false"); Serial.print("}\n"); - } + } else if (cmd == 0x05) { // set video + digitalWrite(4, arg & 1); + digitalWrite(5, arg & 2); + Serial.print("{\"videoSelect\":"); + Serial.print(arg); + Serial.print("}\n"); + } else if (cmd == 0x06) { // talk to shiftbrite + /* + one byte for the string length, then a buffer to be shifted + out to all the shiftbrites + */ + /* + for (int i=0; i < arg / 4; i++) { + setCurrent(127, 127, 127); + } + */ + for (int i=0; i<arg; i++) { + while (Serial.available() == 0) NULL; + SHIFT(Serial.read()); + } + latch(); + Serial.print("{\"ok\":1}\n"); + + } } }