Example #1
0
 static void Pulse(RPi.I2C.Net.I2CBus bus)
 {
     Thread.Sleep(1);
     gpio_reg &= (0xff - (1 << PIN_ENABLE));
     bus.WriteByte(PCF_ADDR, (byte)gpio_reg);
     Thread.Sleep(1);
     gpio_reg |= 1 << PIN_ENABLE;
     bus.WriteByte(PCF_ADDR, (byte)gpio_reg);
     Thread.Sleep(1);
     gpio_reg &= (0xff - (1 << PIN_ENABLE));
     bus.WriteByte(PCF_ADDR, (byte)gpio_reg);
     Thread.Sleep(1);
 }
Example #2
0
 static void WriteLCD(RPi.I2C.Net.I2CBus bus, int address, byte reg, int mode)
 {
     gpio_reg |= mode << PIN_RS;
     bus.WriteByte(PCF_ADDR, (byte)gpio_reg);
     Thread.Sleep(1);
     gpio_reg = gpio_reg | (reg >> 4) << 4;
     Pulse(bus);
     gpio_reg = gpio_reg & (0xff - (0xf0));
     gpio_reg = gpio_reg | (reg & 0x0f) << 4;
     Pulse(bus);
     gpio_reg = gpio_reg & (0xff - (1 << PIN_RS) - (0xf0));
 }
Example #3
0
        static void InitialiseLCD(RPi.I2C.Net.I2CBus bus)
        {
            colNumber = 2;
            rowNumber = 16;
            gpio_reg  = 0;

            gpio_reg = gpio_reg | (1 << PIN_BACKLIGHT);
            bus.WriteByte(PCF_ADDR, (byte)gpio_reg);

            WriteLCD(bus, PCF_ADDR, (byte)0x33, (byte)LCD_COMMAND_MODE);
            WriteLCD(bus, PCF_ADDR, (byte)0x30, (byte)LCD_COMMAND_MODE);
            WriteLCD(bus, PCF_ADDR, (byte)0x06, (byte)LCD_COMMAND_MODE);

            displayControl =
                (displayControl | LCD_DISPLAYCONTROL) | LCD_DISPLAYON;

            WriteLCD(bus, PCF_ADDR, (byte)displayControl, (byte)LCD_COMMAND_MODE);
        }
Example #4
0
        public void TestAllCommands(RPi.I2C.Net.I2CBus incomingBus)
        {
            Console.WriteLine("****************************************");
            Console.WriteLine("* Performing all commands test         *");
            Console.WriteLine("****************************************");
            Console.WriteLine();

            Console.WriteLine("Testing COMMAND_ALL_OFF");
            incomingBus.WriteByte(_TBORG_ADDRESS, 0x14);
            Console.WriteLine("Reading response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();

            Console.WriteLine("Testing COMMAND_SET_A_FWD");
            incomingBus.WriteBytes(_TBORG_ADDRESS, new byte[] { 0x08, 0x80 });
            Console.WriteLine("Response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();

            System.Threading.Thread.Sleep(2000);

            Console.WriteLine("Testing COMMAND_ALL_OFF");
            incomingBus.WriteByte(_TBORG_ADDRESS, 0x0E);
            Console.WriteLine("Reading response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();

            System.Threading.Thread.Sleep(2000);

            Console.WriteLine("Testing COMMAND_SET_B_REV");
            incomingBus.WriteBytes(_TBORG_ADDRESS, new byte[] { 12, 0x80 });
            Console.WriteLine("Response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();

            System.Threading.Thread.Sleep(2000);

            Console.WriteLine("Testing COMMAND_SET_LED1");
            incomingBus.WriteBytes(_TBORG_ADDRESS, new byte[] { 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });
            Console.WriteLine("Response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();

            Console.WriteLine("Testing COMMAND_GET_LED1");
            incomingBus.WriteByte(_TBORG_ADDRESS, 0x02);
            Console.WriteLine("Reading response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();

            Console.WriteLine("Testing COMMAND_SET_LED2");
            incomingBus.WriteBytes(_TBORG_ADDRESS, new byte[] { 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });
            Console.WriteLine("Response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();

            Console.WriteLine("Testing COMMAND_GET_LED2");
            incomingBus.WriteByte(_TBORG_ADDRESS, 0x04);
            Console.WriteLine("Reading response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();

            Console.WriteLine("Testing COMMAND_SET_LEDS");
            incomingBus.WriteBytes(_TBORG_ADDRESS, new byte[] { 0x05, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });
            Console.WriteLine("Response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();

            Console.WriteLine("Testing COMMAND_SET_A_FWD");
            incomingBus.WriteBytes(_TBORG_ADDRESS, new byte[] { 0x08, 0x80 });
            Console.WriteLine("Response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();

            Console.WriteLine("Testing COMMAND_SET_B_REV");
            incomingBus.WriteBytes(_TBORG_ADDRESS, new byte[] { 0x0C, 0x80 });
            Console.WriteLine("Response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();

            Console.WriteLine("Testing COMMAND_GET_DRIVE_A_FAULT");
            incomingBus.WriteByte(_TBORG_ADDRESS, 0x0E);
            Console.WriteLine("Reading response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();

            Console.WriteLine("Testing COMMAND_GET_DRIVE_B_FAULT");
            incomingBus.WriteByte(_TBORG_ADDRESS, 0x0F);
            Console.WriteLine("Reading response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();

            Console.WriteLine("Testing COMMAND_SET_FAILSAFE");
            incomingBus.WriteBytes(_TBORG_ADDRESS, new byte[] { 0x13, 0x01 });
            Console.WriteLine("Reading response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();

            Console.WriteLine("Waiting for a few seconds...");
            System.Threading.Thread.Sleep(5000);

            Console.WriteLine("Testing COMMAND_SET_FAILSAFE");
            incomingBus.WriteBytes(_TBORG_ADDRESS, new byte[] { 0x13, 0x00 });
            Console.WriteLine("Reading response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();



            Console.WriteLine("Testing COMMAND_GET_BATT_VOLT");
            incomingBus.WriteByte(_TBORG_ADDRESS, 21);
            Console.WriteLine("Response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));

            Console.WriteLine("Testing COMMAND_ALL_OFF");
            incomingBus.WriteByte(_TBORG_ADDRESS, 0x14);
            Console.WriteLine("Reading response: " + ParseBytes(incomingBus.ReadBytes(_TBORG_ADDRESS, 6)));
            Console.WriteLine();
        }