001package com.pi4j.io.i2c;
002
003/*
004 * #%L
005 * **********************************************************************
006 * ORGANIZATION  :  Pi4J
007 * PROJECT       :  Pi4J :: Java Library (Core)
008 * FILENAME      :  I2CDevice.java  
009 * 
010 * This file is part of the Pi4J project. More information about 
011 * this project can be found here:  http://www.pi4j.com/
012 * **********************************************************************
013 * %%
014 * Copyright (C) 2012 - 2013 Pi4J
015 * %%
016 * Licensed under the Apache License, Version 2.0 (the "License");
017 * you may not use this file except in compliance with the License.
018 * You may obtain a copy of the License at
019 * 
020 *      http://www.apache.org/licenses/LICENSE-2.0
021 * 
022 * Unless required by applicable law or agreed to in writing, software
023 * distributed under the License is distributed on an "AS IS" BASIS,
024 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
025 * See the License for the specific language governing permissions and
026 * limitations under the License.
027 * #L%
028 */
029
030import java.io.IOException;
031
032/**
033 * This is abstraction of an i2c device. It allows data to be read or written to the device.
034 * 
035 * @author Daniel Sendula
036 *
037 */
038public interface I2CDevice {
039
040    /**
041     * This method writes one byte directly to i2c device.
042     * 
043     * @param b byte to be written
044     * 
045     * @throws IOException thrown in case byte cannot be written to the i2c device or i2c bus
046     */
047    void write(byte b) throws IOException;
048
049    /**
050     * This method writes several bytes directly to the i2c device from given buffer at given offset.
051     * 
052     * @param buffer buffer of data to be written to the i2c device in one go
053     * @param offset offset in buffer 
054     * @param size number of bytes to be written 
055     * 
056     * @throws IOException thrown in case byte cannot be written to the i2c device or i2c bus
057     */
058    void write(byte[] buffer, int offset, int size) throws IOException;
059    
060    /**
061     * This method writes one byte to i2c device.
062     * 
063     * @param address local address in the i2c device
064     * @param b byte to be written
065     * 
066     * @throws IOException thrown in case byte cannot be written to the i2c device or i2c bus
067     */
068    void write(int address, byte b) throws IOException;
069
070    /**
071     * This method writes several bytes to the i2c device from given buffer at given offset.
072     * 
073     * @param address local address in the i2c device
074     * @param buffer buffer of data to be written to the i2c device in one go
075     * @param offset offset in buffer 
076     * @param size number of bytes to be written 
077     * 
078     * @throws IOException thrown in case byte cannot be written to the i2c device or i2c bus
079     */
080    void write(int address, byte[] buffer, int offset, int size) throws IOException;
081    
082    /**
083     * This method reads one byte from the i2c device. Result is between -128 and 127.
084     * 
085     * @return read byte
086     * 
087     * @throws IOException thrown in case byte cannot be read from the i2c device or i2c bus
088     */
089    int read() throws IOException;
090
091    /**
092     * This method reads bytes directly from the i2c device to given buffer at asked offset. 
093     * 
094     * @param buffer buffer of data to be read from the i2c device in one go
095     * @param offset offset in buffer 
096     * @param size number of bytes to be read 
097     * 
098     * @return number of bytes read
099     * 
100     * @throws IOException thrown in case byte cannot be read from the i2c device or i2c bus
101     */
102    int read(byte[] buffer, int offset, int size) throws IOException;
103    
104    /**
105     * This method reads one byte from the i2c device. Result is between -128 and 127.
106     * 
107     * @param address local address in the i2c device
108     * @return
109     * 
110     * @throws IOException thrown in case byte cannot be read from the i2c device or i2c bus
111     */
112    int read(int address) throws IOException;
113
114    /**
115     * This method reads bytes from the i2c device to given buffer at asked offset. 
116     * 
117     * @param address local address in the i2c device
118     * @param buffer buffer of data to be read from the i2c device in one go
119     * @param offset offset in buffer 
120     * @param size number of bytes to be read 
121     * 
122     * @return number of bytes read
123     * 
124     * @throws IOException thrown in case byte cannot be read from the i2c device or i2c bus
125     */
126    int read(int address, byte[] buffer, int offset, int size) throws IOException;
127}