internal void PutFile(HypnoLsdController device, string filename) { // read records until no more // a record is 128 bytes, // 1st byte is length N (0-126) of data bytes // then N data bytes (pad with 0 after N) // 128th byte is sum of bytes (checksum) // length 0 record with all 0 entries and 255 sum is end // after each record read correctly, returns 2 bytes: next record count mod 256 (0 based) and the checksum byte obtained // if record failed, resend with current record count mode 256 (asking for resend) and bit-inverted checksum byte var data = File.ReadAllBytes(filename); var block = new byte[128]; var pos = 0; // position of data to send device.WriteString("putfile \"" + Path.GetFileName(filename) + "\"\r\n"); Thread.Sleep(10); var len = 0; do { len = data.Length - pos; if (len > 126) { len = 126; } block[0] = (byte)len; var checksum = 0; for (var i = 0; i < len; ++i) { block[i + 1] = data[pos++]; checksum += block[i + 1]; } // 0 fill for (var i = len; i < 126; i++) { block[i + 1] = 0; } block[127] = (byte)checksum; // send 4 bytes at a time, with delays var temp = new byte[4]; for (var i = 0; i < block.Length; i += 4) { for (var j = 0; j < 4; ++j) { temp[j] = block[j + i]; } device.WriteBytes(temp); Thread.Sleep(1); } //device.WriteBytes(block); } while (len != 0); }
public void Start(HypnoLsdController device, Remapper remapper, int mbaud, Action <uint[]> imageFilterIn = null) { this.device = device; Remapper = remapper; Width = remapper.Width; Height = remapper.Height; if (imageFilterIn != null) { this.imageFilter = imageFilterIn; } else { this.imageFilter = b => { } }; // identity AddDemos(); // get attention device.WriteString("\r\n"); Thread.Sleep(250); //device.ConnectionSpeed = 1000000; // 1 Mbaud for testing //Thread.Sleep(100); //Thread.Sleep(1000); //device.Drawing = true; //Thread.Sleep(1000); //device.Drawing = false; //Thread.Sleep(1000); device.WriteString("\r\n"); device.ConnectionSpeed = mbaud; // 12000000;// 3000000;// 12000000; // 12 Mbaud for testing Thread.Sleep(500); const int delay = 200; device.Drawing = false; Thread.Sleep(delay); device.Drawing = true; Thread.Sleep(delay); device.Drawing = false; Thread.Sleep(delay); if (remapper.SupportedStrands.Contains(remapper.Strands)) { device.SetSize(remapper.Strands, remapper.Width * remapper.Height / remapper.Strands); } else { throw new NotImplementedException("Remapper does not support " + remapper.Strands + " strands"); } // some context switches to ensure we're at the top in case we disconnected early last time. device.Drawing = true; Thread.Sleep(delay); }