Package comm
Description:
This class is used as base class for I2C event listeners. Extend this class and implement the following methods:
In order to receive I2C events as slave add the listener to the I2CEventDispatcher of the EventManagement system.
Note
_INSERT_CONSTRUCTOR_ENTRY_HERE_
Public Methods
Methods inherited from comm.OnCommListener
_INSERT_METHOD_ENTRY_HERE_
Methods inherited from java.lang.Object
_INSERT_INHERITED_METHOD_ENTRY_HERE_
_INSERT_FIELDS_ENTRY_HERE_
Example
This Example shows how to implement an OnI2CListener class allowing to receive data with the iLCD controllerJoC in slave mode. The onReceive() method is called automatically when the I2C master has addressed the iLCD controllerJoC as slave receiver sending data to the slave. The onRequest() method is called when the I2C master has addressed the iLCD controllerJoC as slave transmitter requesting data to be send by the slave.
class I2CListener extends OnI2CListener
{
private I2C i2cSlave;
I2CListener(int address)
{
i2cSlave = new I2C(address, true);
}
public void onReceive()
{
if (I2C.getCurrentState() == I2C.DATA_RECEIVED_AS_SLAVE_ACK_TRANSMITTED)
{
byte[] data = new byte[2];
try
{
int nr_of_bytes_received = i2cSlave.read(data, 0, 2);
}
catch(Exception exc)
{
Console.println(exc.getMessage());
}
}
}
public void onRequest()
{
try
{
byte data = 0x41;
i2cSlave.write(data);
while (I2C.getCurrentState() == I2C.BYTE_TRANSMITTED_AS_SLAVE_ACK_RECEIVED)
{
i2cSlave.write(++data);
}
}
catch(Exception exc)
{
Console.println(exc.getMessage());
}
}
}
Copyright © demmel products gmbh. All rights reserved.