private void readFieldSwitchBits(int x, int y, bool[,] figureSwitches, TBitMapping mapping = null) { if (mapping == null) mapping = outMapping; var tmpBits = mapping.convert(piso.readBits(8, false)).ToArray(); for (var i = 0; i < 4; i++) { figureSwitches[x + i, y] = tmpBits[i]; figureSwitches[x + i, y + 1] = tmpBits[i + 4]; } }
private void readSideSwitchBits(int index, int count, bool[] sideSwitches, TBitMapping mapping = null) { if (mapping == null) mapping = sideMapping; var tmpBits = mapping.convert(piso.readBits(8, false)).ToArray(); Array.Copy(tmpBits, 0, sideSwitches, index, count); }
static void Main(string[] args) { Console.WriteLine("huhu2"); //var p1 = new GPIOFile(GPIO.GPIOPins.GPIO02, GPIO.DirectionEnum.IN); //while (true) { // Console.Write(p1.Read() ? "1" : "0"); // System.Threading.Thread.Sleep(1000); //} var device = new RPI(); var namedPins = new TNamedPins(); namedPins.Add("LOW", device.createPin(GPIOPins.V2_GPIO_03, GPIODirection.Out, false)); namedPins.Add("HI", device.createPin(GPIOPins.V2_GPIO_27, GPIODirection.Out, true)); namedPins.Add("SER", device.createPin(GPIOPins.V2_GPIO_02, GPIODirection.Out, false)); namedPins.Add("OE", null); namedPins.Add("RCLK", device.createPin(GPIOPins.V2_GPIO_04, GPIODirection.Out, false)); namedPins.Add("SRCLK", device.createPin(GPIOPins.V2_GPIO_17, GPIODirection.Out, false)); namedPins.Add("SRCLR", null); namedPins.Add("O7", device.createPin(GPIOPins.V2_GPIO_10, GPIODirection.In)); namedPins.Add("CP", device.createPin(GPIOPins.V2_GPIO_09, GPIODirection.Out, false)); namedPins.Add("PL", device.createPin(GPIOPins.V2_GPIO_11, GPIODirection.Out, false)); //while (true) // if (namedPins["O7"].Read()) { // Console.Write("1"); // System.Threading.Thread.Sleep(100); // } var sipo = new TSIPO(namedPins["SER"], namedPins["OE"], namedPins["RCLK"], namedPins["SRCLK"], namedPins["SRCLR"]); sipo.setBits(new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); //return; var piso = new TPISO(namedPins["O7"], namedPins["PL"], namedPins["CP"]); var sipoArray = new TSIPOArray(sipo, 16); var ledMapping = new TBitMapping(8); ledMapping.setMapping(0, 1, 7, 6, 2, 3, 4, 5); var outMapping = new TBitMapping(8); //outMapping.setMapping(0, 2, 3, 4, 6, 1, 5, 7); outMapping.setMapping(4, 0, 1, 2, 5, 6, 3, 7); var readBitCount = 64; var lastBits = new bool[readBitCount]; var ledBits = new bool[88]; while (true) { //sipo.setBits(new int[] { 1, 0, 1, 0, 1, 0, 1, 0 }); //System.Threading.Thread.Sleep(200); //sipo.setBits(new int[] { 0, 1, 0, 1, 0, 1, 0, 1 }); //System.Threading.Thread.Sleep(200); //continue; piso.load(); piso.readBits(8*0, false); var tmpBits = outMapping.convert(piso.readBits(8, false)).ToArray(); for (var i = 0; i < 8; i++) { if (tmpBits[i] != lastBits[i]) { foreach (var bit in tmpBits) { Console.Write(bit ? "1" : "0"); } Console.Write(" "); break; } } lastBits = tmpBits; Array.Copy(lastBits, ledBits, 8); //foreach (var bit in tmpBits) { // Console.Write(bit ? "1" : "0"); //} //Console.Write(" "); //if (namedPins["O7"].Read()) ledBits[0] = true; //for (var i = 0; i < readBitCount; i++) { // if (tmpBits[i]) // switch (i) { // case 0: // ledBits[2] = true; // break; // case 1: // ledBits[1] = true; // break; // case 2: // ledBits[0] = true; // break; // case 3: // ledBits[7] = true; // break; // case 4: // ledBits[3] = true; // break; // case 5: // ledBits[4] = true; // break; // case 6: // ledBits[5] = true; // break; // case 7: // ledBits[6] = true; // break; // } //} //ledBits[6] = true; //sipoArray.setBits(ledMapping.convert(ledBits), 0); sipoArray.flush(); //var rowCount = 2; //var columnCount = 4;// 4; //var inputArray = new bool[columnCount, rowCount]; //for (var column = 0; column < columnCount; column++) { // var columnBits = new bool[8]; // columnBits[column] = true; // sipoArray.setBits(columnBits); // sipoArray.flush(); // var row = 0; // foreach (var bit in piso.readBits(rowCount)) { // Console.Write(bit ? "1" : "0"); // inputArray[column, row] = bit; // ledBits[(row * columnCount) + column] = bit; // row++; // } // Console.WriteLine(); //} //Console.WriteLine(); //sipoArray.setBits(ledMapping.convert(ledBits), 8); //sipoArray.flush(); //System.Threading.Thread.Sleep(500); //Console.Write(" "); //namedPins["PL"].Write(true); //System.Threading.Thread.Sleep(100); //namedPins["PL"].Write(false); //System.Threading.Thread.Sleep(100); //namedPins["CP"].Write(false); //System.Threading.Thread.Sleep(100); //printPin(namedPins["O7"]); //System.Threading.Thread.Sleep(100); //namedPins["CP"].Write(true); //System.Threading.Thread.Sleep(100); //namedPins["CP"].Write(false); //System.Threading.Thread.Sleep(100); //printPin(namedPins["O7"]); //System.Threading.Thread.Sleep(100); //namedPins["CP"].Write(true); //System.Threading.Thread.Sleep(100); //namedPins["CP"].Write(false); //System.Threading.Thread.Sleep(100); //printPin(namedPins["O7"]); //System.Threading.Thread.Sleep(100); //namedPins["CP"].Write(true); //System.Threading.Thread.Sleep(100); //namedPins["CP"].Write(false); //System.Threading.Thread.Sleep(100); //printPin(namedPins["O7"]); //System.Threading.Thread.Sleep(100); //namedPins["CP"].Write(true); //System.Threading.Thread.Sleep(100); //System.Threading.Thread.Sleep(1000); } }