public static void SetPassword() //Dh { int err; ConsoleKeyInfo passwrdConfig; string soldPassword; string snewPassword; Console.WriteLine("What Type of Access Control Would You " + "like to Set the Device to? \r\n0 : No Password \r\n" + "1 : Enable the Password \r\n2 : Change the Password \r\n" + "3: Permanent Lock"); passwrdConfig = Console.ReadKey(); if (passwrdConfig.Key == ConsoleKey.D0) // disable password { d1.AccessConfig = 0x00; } else if (passwrdConfig.Key == ConsoleKey.D1) // enable password { d1.AccessConfig = 0x40; } else if (passwrdConfig.Key == ConsoleKey.D2) // change password { d1.AccessConfig = 0xA5; } else if (passwrdConfig.Key == ConsoleKey.D2) // change password { Console.WriteLine("Are You Sure You Want to PERMANENTLY LOCK ALL SETTINGS on This Device"); if (Console.ReadKey().Key == ConsoleKey.Y) { d1.AccessConfig = 0xFF; err = MCP2210.M_Mcp2210_SetPermanentLock(d1.Handle); return; // handle the error } } Console.WriteLine("Please Insert the Current Password. " + "8 Characters Max \r\n" + "Please input any 8 Character string if it currently does not have a password"); soldPassword = Console.ReadLine(); Console.WriteLine("Please Insert the New Password. 8 Characters Max"); snewPassword = Console.ReadLine(); err = MCP2210.M_Mcp2210_SetAccessControl(d1.Handle, d1.AccessConfig, soldPassword, snewPassword); if (0 == err) { d1.sPassword = snewPassword; } else { PullbackException oops = new PullbackException(); oops.Mcp2210Error = err; throw oops; } }
public static void GetGpioConfig() //8h { int err; uint tempuinGpioVal = 0; uint tempuinGpioDir = 0; byte tempbRmtWkupEn = 0; byte tempbPinMode = 0; byte tempbSpiBusRelEn = 0; ConsoleKeyInfo memType; Console.WriteLine("Would you like to see GPIO settings for [1] NVRAM or [2] Volitile Memory \r\n"); memType = Console.ReadKey(); if (memType.Key == ConsoleKey.D1) { d1.bFgSelector = (byte)MCP2210.M_MCP2210_NVRAM_CONFIG; } else if (memType.Key == ConsoleKey.D2) { d1.bFgSelector = (byte)MCP2210.M_MCP2210_VM_CONFIG; } err = MCP2210.M_Mcp2210_GetGpioConfig(d1.Handle, d1.bFgSelector, d1.baGpSetting, ref tempuinGpioVal, ref tempuinGpioDir, ref tempbRmtWkupEn, ref tempbPinMode, ref tempbSpiBusRelEn); Converter.CheckByteArray(d1.baGpSetting); d1.uinGpioVal = tempuinGpioVal; d1.uinGpioDir = tempuinGpioDir; d1.bRmtWkupEn = tempbRmtWkupEn; d1.bPinMode = tempbPinMode; d1.bSpiBusRelEn = tempbSpiBusRelEn; Console.WriteLine("The chosen indication is {0} \r\n", d1.uinGpioVal); Console.WriteLine("The chosen direction is {0} \r\n", d1.uinGpioDir); if (d1.bRmtWkupEn == (byte)MCP2210.M_MCP2210_REMOTE_WAKEUP_ENABLED) { Console.WriteLine("Remote Wake Up is Enabled"); } else if (d1.bRmtWkupEn == (byte)MCP2210.M_MCP2210_REMOTE_WAKEUP_DISABLED) { Console.WriteLine("Remote Wake Up is Disabled"); } if (d1.bPinMode == (byte)MCP2210.M_MCP2210_INT_MD_CNT_NONE) { Console.WriteLine("Interupt pin is Disabled"); } else if (d1.bPinMode == (byte)MCP2210.M_MCP2210_INT_MD_CNT_HIGH_PULSES) { Console.WriteLine("Interrupt is High Pulse Triggered"); } else if (d1.bPinMode == (byte)MCP2210.M_MCP2210_INT_MD_CNT_LOW_PULSES) { Console.WriteLine("Interrupt is Low Pulse Triggered"); } else if (d1.bPinMode == (byte)MCP2210.M_MCP2210_INT_MD_CNT_RISING_EDGES) { Console.WriteLine("Interrupt is Rising Edge Triggered"); } else if (d1.bPinMode == (byte)MCP2210.M_MCP2210_INT_MD_CNT_FALLING_EDGES) { Console.WriteLine("Interrupt is Falling Edge Triggered"); } if (d1.bSpiBusRelEn == (byte)MCP2210.M_MCP2210_SPI_BUS_RELEASE_ENABLED) { Console.WriteLine("SPI Bus Release is Enabled"); } if (d1.bSpiBusRelEn == (byte)MCP2210.M_MCP2210_SPI_BUS_RELEASE_DISABLED) { Console.WriteLine("SPI Bus Release is Disabled"); } if (err != 0) { PullbackException oops = new PullbackException(); oops.Mcp2210Error = err; throw oops; } Console.WriteLine("Error is {0}", err); }
public static void SetGpioConfig() //7h { ConsoleKeyInfo memType; ConsoleKeyInfo gpioTemp; string temp_gp; int err; Console.WriteLine("Would you like to set the GPIO settings for [1] NVRAM or [2] Volitile Memory \r\n"); memType = Console.ReadKey(); if (memType.Key == ConsoleKey.D1) { d1.bFgSelector = (byte)MCP2210.M_MCP2210_NVRAM_CONFIG; } else if (memType.Key == ConsoleKey.D2) { d1.bFgSelector = (byte)MCP2210.M_MCP2210_VM_CONFIG; } Console.WriteLine("Please Indicate the GP Pin Designation in Hex Format, GP0 is First & GP8 is Last \r\n 00 : GPIO \r\n 01 : Chip Select \r\n 02 : Dedicated Pin Function \r\n "); temp_gp = Console.ReadLine(); d1.baGpSetting = Converter.ToByteArray(temp_gp); for (int i = 0; i < 9; i++) { Console.WriteLine("Please Indicate the Output Value of Pin GPIO{0} \r\n", i); gpioTemp = Console.ReadKey(); if (gpioTemp.Key == ConsoleKey.D1) { d1.uinGpioVal += (uint)1 << i; } Console.WriteLine("\r\n"); } Console.WriteLine("The chosen indication is {0} \r\n", d1.uinGpioVal); for (int i = 0; i < 9; i++) { Console.WriteLine("Please Indicate the Direction of Pin GPIO{0}\r\n 1 is In, 0 is Out \r\n", i); gpioTemp = Console.ReadKey(); if (gpioTemp.Key == ConsoleKey.D1) { d1.uinGpioDir += (uint)1 << i; } Console.WriteLine("\r\n"); } Console.WriteLine("The chosen direction is {0}", d1.uinGpioDir); Console.WriteLine("\r\n Would You Like the Device to Be Remote Wake Enababled [Y] or [N] /r/n"); gpioTemp = Console.ReadKey(); if (gpioTemp.Key == ConsoleKey.Y) { d1.bRmtWkupEn = (byte)MCP2210.M_MCP2210_REMOTE_WAKEUP_ENABLED; } if (gpioTemp.Key == ConsoleKey.N) { d1.bRmtWkupEn = (byte)MCP2210.M_MCP2210_REMOTE_WAKEUP_DISABLED; } Console.WriteLine("\r\n How would you like the interupt pin to count interupts, GP6 \r\n 0 : NONE \r\n 1 : High Pulses \r\n 2 : Low Pulses \r\n 3 : Rising Edges \r\n 4 : Falling Edges \r\n"); gpioTemp = Console.ReadKey(); if (gpioTemp.Key == ConsoleKey.D0) { d1.bPinMode = (byte)MCP2210.M_MCP2210_INT_MD_CNT_NONE; } else if (gpioTemp.Key == ConsoleKey.D1) { d1.bPinMode = (byte)MCP2210.M_MCP2210_INT_MD_CNT_HIGH_PULSES; } else if (gpioTemp.Key == ConsoleKey.D2) { d1.bPinMode = (byte)MCP2210.M_MCP2210_INT_MD_CNT_LOW_PULSES; } else if (gpioTemp.Key == ConsoleKey.D3) { d1.bPinMode = (byte)MCP2210.M_MCP2210_INT_MD_CNT_RISING_EDGES; } else if (gpioTemp.Key == ConsoleKey.D4) { d1.bPinMode = (byte)MCP2210.M_MCP2210_INT_MD_CNT_FALLING_EDGES; } Console.WriteLine("\r\n Would you like your device to release the SPI Bus to another master when not broadcasting [Y] or [N] \r\n"); gpioTemp = Console.ReadKey(); if (gpioTemp.Key == ConsoleKey.Y) { d1.bSpiBusRelEn = (byte)MCP2210.M_MCP2210_SPI_BUS_RELEASE_ENABLED; } if (gpioTemp.Key == ConsoleKey.N) { d1.bSpiBusRelEn = (byte)MCP2210.M_MCP2210_SPI_BUS_RELEASE_DISABLED; } err = MCP2210.M_Mcp2210_SetGpioConfig(d1.Handle, d1.bFgSelector, d1.baGpSetting, d1.uinGpioVal, d1.uinGpioDir, d1.bRmtWkupEn, d1.bPinMode, d1.bSpiBusRelEn); if (err != 0) { PullbackException oops = new PullbackException(); oops.Mcp2210Error = err; throw oops; } Console.WriteLine("\r\n Error is {0}", err); }