コード例 #1
0
ファイル: hardware.cs プロジェクト: Arakis/TamaniChess
		public void init() {
			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));

			//---

			namedPins.Add("SER", device.createPin(GPIOPins.V2_GPIO_17, GPIODirection.Out, false));
			namedPins.Add("OE", null);
			namedPins.Add("RCLK", device.createPin(GPIOPins.V2_GPIO_22, GPIODirection.Out, false));
			namedPins.Add("SRCLK", device.createPin(GPIOPins.V2_GPIO_27, GPIODirection.Out, false));
			namedPins.Add("SRCLR", null);

			namedPins.Add("O7", device.createPin(GPIOPins.V2_GPIO_23, GPIODirection.In));
			namedPins.Add("CP", device.createPin(GPIOPins.V2_GPIO_24, GPIODirection.Out, false));
			namedPins.Add("PL", device.createPin(GPIOPins.V2_GPIO_25, GPIODirection.Out, false));

			sipo = new TSIPO(namedPins["SER"], namedPins["OE"], namedPins["RCLK"], namedPins["SRCLK"], namedPins["SRCLR"]);
			//sipo.setBits(new int[200]); //clear all //WARNING: CAN DESTROY SCREEN! USE POWER UP / DOWN SEQUENCE!!
			piso = new TPISO(namedPins["O7"], namedPins["PL"], namedPins["CP"]);

			ledMapping = new TBitMapping(8);
			ledMapping.setMapping(0, 1, 2, 3, 7, 6, 5, 4);
			ledMappingBottom = new TBitMapping(8);
			ledMappingBottom.setMapping(0, 1, 2, 3, 7, 6, 5, 4); //OK?
			ledMappingRight = new TBitMapping(8);
			ledMappingRight.setMapping(0, 1, 2, 3, 7, 6, 5, 4); //OK
			//1000 0000

			ledMappingSpecial = new TBitMapping(8);
			ledMappingSpecial.setMapping(0, 1, 2, 3, 7, 6, 5, 4); //CHECK

			outMapping = new TBitMapping(8);
			//outMapping.setMapping(4, 0, 1, 2, 5, 6, 7, 3);
			//outMapping.setMapping(3, 7, 6, 5, 2, 1, 0, 4);
			outMapping.setMapping(7, 6, 5, 4, 3, 2, 1, 0);
			//0000
			//0001

			//outMappingBugFix = new TBitMapping(8);
			//outMappingBugFix.setMapping(4, 0, 1, 2, 5, 7, 6, 3);

			sideMapping = new TBitMapping(8);
			//sideMapping.setMapping(7, 0, 1, 2, 3, 4, 5, 6);
			sideMapping.setMapping(0, 1, 2, 3, 4, 5, 6, 7);

			sideSwitchesOld = new bool[sideSwitchCount];
			sideSwitchesNew = new bool[sideSwitchCount];
			sideSwitchesOldDelay = new bool[sideSwitchCount];
			sideSwitchesNewDelay = new bool[sideSwitchCount];

			//screen
			var D16_SDI = new GPIOMem(GPIOPins.V2_GPIO_10, GPIODirection.Out, false);
			var D17_CLK = new GPIOMem(GPIOPins.V2_GPIO_11, GPIODirection.Out, false);
			var CS = new GPIOMem(GPIOPins.V2_GPIO_08, GPIODirection.Out, false);

			var RST = device.createPin(GPIOPins.V2_GPIO_18, GPIODirection.Out, false);
			var RS = new GPIOMem(GPIOPins.V2_GPIO_04, GPIODirection.Out, false);

			var spi = new TSPIEmulator(D16_SDI, null, D17_CLK, CS);
			var watch = new System.Diagnostics.Stopwatch();

			var bus = new TOLEDSPIFastDataBus(spi, RST, RS);
			lcd = new TOLEDDisplay(bus, this);
			lcd.orientation(3);
			lcd.background(Color.Black);

			displayPowerOff();
		}
コード例 #2
0
ファイル: Program.cs プロジェクト: Arakis/TamaniChess
		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);
			}

		}