All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tinkerforge.BrickletUVLightV2 Maven / Gradle / Ivy

/* ***********************************************************
 * This file was automatically generated on 2019-11-25.      *
 *                                                           *
 * Java Bindings Version 2.1.25                              *
 *                                                           *
 * If you have a bugfix for this file and want to commit it, *
 * please fix the bug in the generator. You can find a link  *
 * to the generators git repository on tinkerforge.com       *
 *************************************************************/

package com.tinkerforge;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Measures UV-A, UV-B and UV index
 */
public class BrickletUVLightV2 extends Device {
	public final static int DEVICE_IDENTIFIER = 2118;
	public final static String DEVICE_DISPLAY_NAME = "UV Light Bricklet 2.0";

	public final static byte FUNCTION_GET_UVA = (byte)1;
	public final static byte FUNCTION_SET_UVA_CALLBACK_CONFIGURATION = (byte)2;
	public final static byte FUNCTION_GET_UVA_CALLBACK_CONFIGURATION = (byte)3;
	public final static byte FUNCTION_GET_UVB = (byte)5;
	public final static byte FUNCTION_SET_UVB_CALLBACK_CONFIGURATION = (byte)6;
	public final static byte FUNCTION_GET_UVB_CALLBACK_CONFIGURATION = (byte)7;
	public final static byte FUNCTION_GET_UVI = (byte)9;
	public final static byte FUNCTION_SET_UVI_CALLBACK_CONFIGURATION = (byte)10;
	public final static byte FUNCTION_GET_UVI_CALLBACK_CONFIGURATION = (byte)11;
	public final static byte FUNCTION_SET_CONFIGURATION = (byte)13;
	public final static byte FUNCTION_GET_CONFIGURATION = (byte)14;
	public final static byte FUNCTION_GET_SPITFP_ERROR_COUNT = (byte)234;
	public final static byte FUNCTION_SET_BOOTLOADER_MODE = (byte)235;
	public final static byte FUNCTION_GET_BOOTLOADER_MODE = (byte)236;
	public final static byte FUNCTION_SET_WRITE_FIRMWARE_POINTER = (byte)237;
	public final static byte FUNCTION_WRITE_FIRMWARE = (byte)238;
	public final static byte FUNCTION_SET_STATUS_LED_CONFIG = (byte)239;
	public final static byte FUNCTION_GET_STATUS_LED_CONFIG = (byte)240;
	public final static byte FUNCTION_GET_CHIP_TEMPERATURE = (byte)242;
	public final static byte FUNCTION_RESET = (byte)243;
	public final static byte FUNCTION_WRITE_UID = (byte)248;
	public final static byte FUNCTION_READ_UID = (byte)249;
	public final static byte FUNCTION_GET_IDENTITY = (byte)255;
	private final static int CALLBACK_UVA = 4;
	private final static int CALLBACK_UVB = 8;
	private final static int CALLBACK_UVI = 12;

	public final static char THRESHOLD_OPTION_OFF = 'x';
	public final static char THRESHOLD_OPTION_OUTSIDE = 'o';
	public final static char THRESHOLD_OPTION_INSIDE = 'i';
	public final static char THRESHOLD_OPTION_SMALLER = '<';
	public final static char THRESHOLD_OPTION_GREATER = '>';
	public final static int INTEGRATION_TIME_50MS = 0;
	public final static int INTEGRATION_TIME_100MS = 1;
	public final static int INTEGRATION_TIME_200MS = 2;
	public final static int INTEGRATION_TIME_400MS = 3;
	public final static int INTEGRATION_TIME_800MS = 4;
	public final static int BOOTLOADER_MODE_BOOTLOADER = 0;
	public final static int BOOTLOADER_MODE_FIRMWARE = 1;
	public final static int BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT = 2;
	public final static int BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT = 3;
	public final static int BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT = 4;
	public final static int BOOTLOADER_STATUS_OK = 0;
	public final static int BOOTLOADER_STATUS_INVALID_MODE = 1;
	public final static int BOOTLOADER_STATUS_NO_CHANGE = 2;
	public final static int BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT = 3;
	public final static int BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT = 4;
	public final static int BOOTLOADER_STATUS_CRC_MISMATCH = 5;
	public final static int STATUS_LED_CONFIG_OFF = 0;
	public final static int STATUS_LED_CONFIG_ON = 1;
	public final static int STATUS_LED_CONFIG_SHOW_HEARTBEAT = 2;
	public final static int STATUS_LED_CONFIG_SHOW_STATUS = 3;

	private List listenerUVA = new CopyOnWriteArrayList();
	private List listenerUVB = new CopyOnWriteArrayList();
	private List listenerUVI = new CopyOnWriteArrayList();

	public class UVACallbackConfiguration {
		public long period;
		public boolean valueHasToChange;
		public char option;
		public int min;
		public int max;

		public String toString() {
			return "[" + "period = " + period + ", " + "valueHasToChange = " + valueHasToChange + ", " + "option = " + option + ", " + "min = " + min + ", " + "max = " + max + "]";
		}
	}

	public class UVBCallbackConfiguration {
		public long period;
		public boolean valueHasToChange;
		public char option;
		public int min;
		public int max;

		public String toString() {
			return "[" + "period = " + period + ", " + "valueHasToChange = " + valueHasToChange + ", " + "option = " + option + ", " + "min = " + min + ", " + "max = " + max + "]";
		}
	}

	public class UVICallbackConfiguration {
		public long period;
		public boolean valueHasToChange;
		public char option;
		public int min;
		public int max;

		public String toString() {
			return "[" + "period = " + period + ", " + "valueHasToChange = " + valueHasToChange + ", " + "option = " + option + ", " + "min = " + min + ", " + "max = " + max + "]";
		}
	}

	public class SPITFPErrorCount {
		public long errorCountAckChecksum;
		public long errorCountMessageChecksum;
		public long errorCountFrame;
		public long errorCountOverflow;

		public String toString() {
			return "[" + "errorCountAckChecksum = " + errorCountAckChecksum + ", " + "errorCountMessageChecksum = " + errorCountMessageChecksum + ", " + "errorCountFrame = " + errorCountFrame + ", " + "errorCountOverflow = " + errorCountOverflow + "]";
		}
	}

	/**
	 * This listener is triggered periodically according to the configuration set by
	 * {@link BrickletUVLightV2#setUVACallbackConfiguration(long, boolean, char, int, int)}.
	 * 
	 * The parameter is the same as {@link BrickletUVLightV2#getUVA()}.
	 */
	public interface UVAListener extends DeviceListener {
		public void uva(int uva);
	}

	/**
	 * This listener is triggered periodically according to the configuration set by
	 * {@link BrickletUVLightV2#setUVBCallbackConfiguration(long, boolean, char, int, int)}.
	 * 
	 * The parameter is the same as {@link BrickletUVLightV2#getUVB()}.
	 */
	public interface UVBListener extends DeviceListener {
		public void uvb(int uvb);
	}

	/**
	 * This listener is triggered periodically according to the configuration set by
	 * {@link BrickletUVLightV2#setUVICallbackConfiguration(long, boolean, char, int, int)}.
	 * 
	 * The parameter is the same as {@link BrickletUVLightV2#getUVI()}.
	 */
	public interface UVIListener extends DeviceListener {
		public void uvi(int uvi);
	}

	/**
	 * Creates an object with the unique device ID \c uid. and adds it to
	 * the IP Connection \c ipcon.
	 */
	public BrickletUVLightV2(String uid, IPConnection ipcon) {
		super(uid, ipcon);

		apiVersion[0] = 2;
		apiVersion[1] = 0;
		apiVersion[2] = 0;
		responseExpected[IPConnection.unsignedByte(FUNCTION_GET_UVA)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_SET_UVA_CALLBACK_CONFIGURATION)] = RESPONSE_EXPECTED_FLAG_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_GET_UVA_CALLBACK_CONFIGURATION)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_GET_UVB)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_SET_UVB_CALLBACK_CONFIGURATION)] = RESPONSE_EXPECTED_FLAG_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_GET_UVB_CALLBACK_CONFIGURATION)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_GET_UVI)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_SET_UVI_CALLBACK_CONFIGURATION)] = RESPONSE_EXPECTED_FLAG_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_GET_UVI_CALLBACK_CONFIGURATION)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_SET_CONFIGURATION)] = RESPONSE_EXPECTED_FLAG_FALSE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_GET_CONFIGURATION)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_GET_SPITFP_ERROR_COUNT)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_SET_BOOTLOADER_MODE)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_GET_BOOTLOADER_MODE)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_SET_WRITE_FIRMWARE_POINTER)] = RESPONSE_EXPECTED_FLAG_FALSE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_WRITE_FIRMWARE)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_SET_STATUS_LED_CONFIG)] = RESPONSE_EXPECTED_FLAG_FALSE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_GET_STATUS_LED_CONFIG)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_GET_CHIP_TEMPERATURE)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_RESET)] = RESPONSE_EXPECTED_FLAG_FALSE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_WRITE_UID)] = RESPONSE_EXPECTED_FLAG_FALSE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_READ_UID)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;
		responseExpected[IPConnection.unsignedByte(FUNCTION_GET_IDENTITY)] = RESPONSE_EXPECTED_FLAG_ALWAYS_TRUE;

		callbacks[CALLBACK_UVA] = new IPConnection.DeviceCallbackListener() {
			public void callback(byte[] packet) {
				ByteBuffer bb = ByteBuffer.wrap(packet, 8, packet.length - 8);
				bb.order(ByteOrder.LITTLE_ENDIAN);

				int uva = (bb.getInt());

				for (UVAListener listener: listenerUVA) {
					listener.uva(uva);
				}
			}
		};

		callbacks[CALLBACK_UVB] = new IPConnection.DeviceCallbackListener() {
			public void callback(byte[] packet) {
				ByteBuffer bb = ByteBuffer.wrap(packet, 8, packet.length - 8);
				bb.order(ByteOrder.LITTLE_ENDIAN);

				int uvb = (bb.getInt());

				for (UVBListener listener: listenerUVB) {
					listener.uvb(uvb);
				}
			}
		};

		callbacks[CALLBACK_UVI] = new IPConnection.DeviceCallbackListener() {
			public void callback(byte[] packet) {
				ByteBuffer bb = ByteBuffer.wrap(packet, 8, packet.length - 8);
				bb.order(ByteOrder.LITTLE_ENDIAN);

				int uvi = (bb.getInt());

				for (UVIListener listener: listenerUVI) {
					listener.uvi(uvi);
				}
			}
		};
	}

	/**
	 * Returns the UVA intensity of the sensor, the intensity is given
	 * in 1/10 mW/m². The sensor has not weighted the intensity with the erythemal
	 * action spectrum to get the skin-affecting irradiation. Therefore, you cannot
	 * just divide the value by 250 to get the UVA index. To get the UV index use
	 * {@link BrickletUVLightV2#getUVI()}.
	 * 
	 * If the sensor is saturated, then -1 is returned, see {@link BrickletUVLightV2#setConfiguration(int)}.
	 * 
	 * If you want to get the intensity periodically, it is recommended to use the
	 * {@link BrickletUVLightV2.UVAListener} listener and set the period with
	 * {@link BrickletUVLightV2#setUVACallbackConfiguration(long, boolean, char, int, int)}.
	 * 
	 * 
	 * If you want to get the value periodically, it is recommended to use the
	 * {@link BrickletUVLightV2.UVAListener} listener. You can set the listener configuration
	 * with {@link BrickletUVLightV2#setUVACallbackConfiguration(long, boolean, char, int, int)}.
	 */
	public int getUVA() throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)8, FUNCTION_GET_UVA, this);


		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		int uva = (bb.getInt());

		return uva;
	}

	/**
	 * The period is the period with which the {@link BrickletUVLightV2.UVAListener} listener is triggered
	 * periodically. A value of 0 turns the listener off.
	 * 
	 * If the `value has to change`-parameter is set to true, the listener is only
	 * triggered after the value has changed. If the value didn't change
	 * within the period, the listener is triggered immediately on change.
	 * 
	 * If it is set to false, the listener is continuously triggered with the period,
	 * independent of the value.
	 * 
	 * It is furthermore possible to constrain the listener with thresholds.
	 * 
	 * The `option`-parameter together with min/max sets a threshold for the {@link BrickletUVLightV2.UVAListener} listener.
	 * 
	 * The following options are possible:
	 * 
	 * \verbatim
	 *  "Option", "Description"
	 * 
	 *  "'x'",    "Threshold is turned off"
	 *  "'o'",    "Threshold is triggered when the value is *outside* the min and max values"
	 *  "'i'",    "Threshold is triggered when the value is *inside* or equal to the min and max values"
	 *  "'<'",    "Threshold is triggered when the value is smaller than the min value (max is ignored)"
	 *  "'>'",    "Threshold is triggered when the value is greater than the min value (max is ignored)"
	 * \endverbatim
	 * 
	 * If the option is set to 'x' (threshold turned off) the listener is triggered with the fixed period.
	 */
	public void setUVACallbackConfiguration(long period, boolean valueHasToChange, char option, int min, int max) throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)22, FUNCTION_SET_UVA_CALLBACK_CONFIGURATION, this);

		bb.putInt((int)period);
		bb.put((byte)(valueHasToChange ? 1 : 0));
		bb.put((byte)option);
		bb.putInt(min);
		bb.putInt(max);

		sendRequest(bb.array());
	}

	/**
	 * Returns the listener configuration as set by {@link BrickletUVLightV2#setUVACallbackConfiguration(long, boolean, char, int, int)}.
	 */
	public UVACallbackConfiguration getUVACallbackConfiguration() throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)8, FUNCTION_GET_UVA_CALLBACK_CONFIGURATION, this);


		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		UVACallbackConfiguration obj = new UVACallbackConfiguration();
		obj.period = IPConnection.unsignedInt(bb.getInt());
		obj.valueHasToChange = (bb.get()) != 0;
		obj.option = (char)(bb.get());
		obj.min = (bb.getInt());
		obj.max = (bb.getInt());

		return obj;
	}

	/**
	 * Returns the UVB intensity of the sensor, the intensity is given
	 * in 1/10 mW/m². The sensor has not weighted the intensity with the erythemal
	 * action spectrum to get the skin-affecting irradiation. Therefore, you cannot
	 * just divide the value by 250 to get the UVB index. To get the UV index use
	 * {@link BrickletUVLightV2#getUVI()}.
	 * 
	 * If the sensor is saturated, then -1 is returned, see {@link BrickletUVLightV2#setConfiguration(int)}.
	 * 
	 * If you want to get the intensity periodically, it is recommended to use the
	 * {@link BrickletUVLightV2.UVBListener} listener and set the period with
	 * {@link BrickletUVLightV2#setUVBCallbackConfiguration(long, boolean, char, int, int)}.
	 * 
	 * 
	 * If you want to get the value periodically, it is recommended to use the
	 * {@link BrickletUVLightV2.UVBListener} listener. You can set the listener configuration
	 * with {@link BrickletUVLightV2#setUVBCallbackConfiguration(long, boolean, char, int, int)}.
	 */
	public int getUVB() throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)8, FUNCTION_GET_UVB, this);


		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		int uvb = (bb.getInt());

		return uvb;
	}

	/**
	 * The period is the period with which the {@link BrickletUVLightV2.UVBListener} listener is triggered
	 * periodically. A value of 0 turns the listener off.
	 * 
	 * If the `value has to change`-parameter is set to true, the listener is only
	 * triggered after the value has changed. If the value didn't change
	 * within the period, the listener is triggered immediately on change.
	 * 
	 * If it is set to false, the listener is continuously triggered with the period,
	 * independent of the value.
	 * 
	 * It is furthermore possible to constrain the listener with thresholds.
	 * 
	 * The `option`-parameter together with min/max sets a threshold for the {@link BrickletUVLightV2.UVBListener} listener.
	 * 
	 * The following options are possible:
	 * 
	 * \verbatim
	 *  "Option", "Description"
	 * 
	 *  "'x'",    "Threshold is turned off"
	 *  "'o'",    "Threshold is triggered when the value is *outside* the min and max values"
	 *  "'i'",    "Threshold is triggered when the value is *inside* or equal to the min and max values"
	 *  "'<'",    "Threshold is triggered when the value is smaller than the min value (max is ignored)"
	 *  "'>'",    "Threshold is triggered when the value is greater than the min value (max is ignored)"
	 * \endverbatim
	 * 
	 * If the option is set to 'x' (threshold turned off) the listener is triggered with the fixed period.
	 */
	public void setUVBCallbackConfiguration(long period, boolean valueHasToChange, char option, int min, int max) throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)22, FUNCTION_SET_UVB_CALLBACK_CONFIGURATION, this);

		bb.putInt((int)period);
		bb.put((byte)(valueHasToChange ? 1 : 0));
		bb.put((byte)option);
		bb.putInt(min);
		bb.putInt(max);

		sendRequest(bb.array());
	}

	/**
	 * Returns the listener configuration as set by {@link BrickletUVLightV2#setUVBCallbackConfiguration(long, boolean, char, int, int)}.
	 */
	public UVBCallbackConfiguration getUVBCallbackConfiguration() throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)8, FUNCTION_GET_UVB_CALLBACK_CONFIGURATION, this);


		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		UVBCallbackConfiguration obj = new UVBCallbackConfiguration();
		obj.period = IPConnection.unsignedInt(bb.getInt());
		obj.valueHasToChange = (bb.get()) != 0;
		obj.option = (char)(bb.get());
		obj.min = (bb.getInt());
		obj.max = (bb.getInt());

		return obj;
	}

	/**
	 * Returns the UV index of the sensor, the index is given in 1/10.
	 * 
	 * If the sensor is saturated, then -1 is returned, see {@link BrickletUVLightV2#setConfiguration(int)}.
	 * 
	 * If you want to get the intensity periodically, it is recommended to use the
	 * {@link BrickletUVLightV2.UVIListener} listener and set the period with
	 * {@link BrickletUVLightV2#setUVICallbackConfiguration(long, boolean, char, int, int)}.
	 * 
	 * 
	 * If you want to get the value periodically, it is recommended to use the
	 * {@link BrickletUVLightV2.UVIListener} listener. You can set the listener configuration
	 * with {@link BrickletUVLightV2#setUVICallbackConfiguration(long, boolean, char, int, int)}.
	 */
	public int getUVI() throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)8, FUNCTION_GET_UVI, this);


		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		int uvi = (bb.getInt());

		return uvi;
	}

	/**
	 * The period is the period with which the {@link BrickletUVLightV2.UVIListener} listener is triggered
	 * periodically. A value of 0 turns the listener off.
	 * 
	 * If the `value has to change`-parameter is set to true, the listener is only
	 * triggered after the value has changed. If the value didn't change
	 * within the period, the listener is triggered immediately on change.
	 * 
	 * If it is set to false, the listener is continuously triggered with the period,
	 * independent of the value.
	 * 
	 * It is furthermore possible to constrain the listener with thresholds.
	 * 
	 * The `option`-parameter together with min/max sets a threshold for the {@link BrickletUVLightV2.UVIListener} listener.
	 * 
	 * The following options are possible:
	 * 
	 * \verbatim
	 *  "Option", "Description"
	 * 
	 *  "'x'",    "Threshold is turned off"
	 *  "'o'",    "Threshold is triggered when the value is *outside* the min and max values"
	 *  "'i'",    "Threshold is triggered when the value is *inside* or equal to the min and max values"
	 *  "'<'",    "Threshold is triggered when the value is smaller than the min value (max is ignored)"
	 *  "'>'",    "Threshold is triggered when the value is greater than the min value (max is ignored)"
	 * \endverbatim
	 * 
	 * If the option is set to 'x' (threshold turned off) the listener is triggered with the fixed period.
	 */
	public void setUVICallbackConfiguration(long period, boolean valueHasToChange, char option, int min, int max) throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)22, FUNCTION_SET_UVI_CALLBACK_CONFIGURATION, this);

		bb.putInt((int)period);
		bb.put((byte)(valueHasToChange ? 1 : 0));
		bb.put((byte)option);
		bb.putInt(min);
		bb.putInt(max);

		sendRequest(bb.array());
	}

	/**
	 * Returns the listener configuration as set by {@link BrickletUVLightV2#setUVICallbackConfiguration(long, boolean, char, int, int)}.
	 */
	public UVICallbackConfiguration getUVICallbackConfiguration() throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)8, FUNCTION_GET_UVI_CALLBACK_CONFIGURATION, this);


		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		UVICallbackConfiguration obj = new UVICallbackConfiguration();
		obj.period = IPConnection.unsignedInt(bb.getInt());
		obj.valueHasToChange = (bb.get()) != 0;
		obj.option = (char)(bb.get());
		obj.min = (bb.getInt());
		obj.max = (bb.getInt());

		return obj;
	}

	/**
	 * Sets the configuration of the sensor. The integration time can be configured
	 * between 50 and 800 ms. With a shorter integration time the sensor reading updates
	 * more often but contains more noise. With a longer integration the sensor reading
	 * contains less noise but updates less often.
	 * 
	 * With a longer integration time (especially 800 ms) and a higher UV intensity the
	 * sensor can be saturated. If this happens the UVA/UVB/UVI readings are all -1.
	 * In this case you need to choose a shorter integration time.
	 * 
	 * Default value: 400 ms.
	 */
	public void setConfiguration(int integrationTime) throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)9, FUNCTION_SET_CONFIGURATION, this);

		bb.put((byte)integrationTime);

		sendRequest(bb.array());
	}

	/**
	 * Returns the configuration as set by {@link BrickletUVLightV2#setConfiguration(int)}.
	 */
	public int getConfiguration() throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)8, FUNCTION_GET_CONFIGURATION, this);


		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		int integrationTime = IPConnection.unsignedByte(bb.get());

		return integrationTime;
	}

	/**
	 * Returns the error count for the communication between Brick and Bricklet.
	 * 
	 * The errors are divided into
	 * 
	 * * ACK checksum errors,
	 * * message checksum errors,
	 * * framing errors and
	 * * overflow errors.
	 * 
	 * The errors counts are for errors that occur on the Bricklet side. All
	 * Bricks have a similar function that returns the errors on the Brick side.
	 */
	public SPITFPErrorCount getSPITFPErrorCount() throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)8, FUNCTION_GET_SPITFP_ERROR_COUNT, this);


		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		SPITFPErrorCount obj = new SPITFPErrorCount();
		obj.errorCountAckChecksum = IPConnection.unsignedInt(bb.getInt());
		obj.errorCountMessageChecksum = IPConnection.unsignedInt(bb.getInt());
		obj.errorCountFrame = IPConnection.unsignedInt(bb.getInt());
		obj.errorCountOverflow = IPConnection.unsignedInt(bb.getInt());

		return obj;
	}

	/**
	 * Sets the bootloader mode and returns the status after the requested
	 * mode change was instigated.
	 * 
	 * You can change from bootloader mode to firmware mode and vice versa. A change
	 * from bootloader mode to firmware mode will only take place if the entry function,
	 * device identifier and CRC are present and correct.
	 * 
	 * This function is used by Brick Viewer during flashing. It should not be
	 * necessary to call it in a normal user program.
	 */
	public int setBootloaderMode(int mode) throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)9, FUNCTION_SET_BOOTLOADER_MODE, this);

		bb.put((byte)mode);

		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		int status = IPConnection.unsignedByte(bb.get());

		return status;
	}

	/**
	 * Returns the current bootloader mode, see {@link BrickletUVLightV2#setBootloaderMode(int)}.
	 */
	public int getBootloaderMode() throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)8, FUNCTION_GET_BOOTLOADER_MODE, this);


		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		int mode = IPConnection.unsignedByte(bb.get());

		return mode;
	}

	/**
	 * Sets the firmware pointer for {@link BrickletUVLightV2#writeFirmware(int[])}. The pointer has
	 * to be increased by chunks of size 64. The data is written to flash
	 * every 4 chunks (which equals to one page of size 256).
	 * 
	 * This function is used by Brick Viewer during flashing. It should not be
	 * necessary to call it in a normal user program.
	 */
	public void setWriteFirmwarePointer(long pointer) throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)12, FUNCTION_SET_WRITE_FIRMWARE_POINTER, this);

		bb.putInt((int)pointer);

		sendRequest(bb.array());
	}

	/**
	 * Writes 64 Bytes of firmware at the position as written by
	 * {@link BrickletUVLightV2#setWriteFirmwarePointer(long)} before. The firmware is written
	 * to flash every 4 chunks.
	 * 
	 * You can only write firmware in bootloader mode.
	 * 
	 * This function is used by Brick Viewer during flashing. It should not be
	 * necessary to call it in a normal user program.
	 */
	public int writeFirmware(int[] data) throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)72, FUNCTION_WRITE_FIRMWARE, this);

		for (int i = 0; i < 64; i++) {
			bb.put((byte)data[i]);
		}

		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		int status = IPConnection.unsignedByte(bb.get());

		return status;
	}

	/**
	 * Sets the status LED configuration. By default the LED shows
	 * communication traffic between Brick and Bricklet, it flickers once
	 * for every 10 received data packets.
	 * 
	 * You can also turn the LED permanently on/off or show a heartbeat.
	 * 
	 * If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
	 */
	public void setStatusLEDConfig(int config) throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)9, FUNCTION_SET_STATUS_LED_CONFIG, this);

		bb.put((byte)config);

		sendRequest(bb.array());
	}

	/**
	 * Returns the configuration as set by {@link BrickletUVLightV2#setStatusLEDConfig(int)}
	 */
	public int getStatusLEDConfig() throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)8, FUNCTION_GET_STATUS_LED_CONFIG, this);


		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		int config = IPConnection.unsignedByte(bb.get());

		return config;
	}

	/**
	 * Returns the temperature in °C as measured inside the microcontroller. The
	 * value returned is not the ambient temperature!
	 * 
	 * The temperature is only proportional to the real temperature and it has bad
	 * accuracy. Practically it is only useful as an indicator for
	 * temperature changes.
	 */
	public int getChipTemperature() throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)8, FUNCTION_GET_CHIP_TEMPERATURE, this);


		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		int temperature = (bb.getShort());

		return temperature;
	}

	/**
	 * Calling this function will reset the Bricklet. All configurations
	 * will be lost.
	 * 
	 * After a reset you have to create new device objects,
	 * calling functions on the existing ones will result in
	 * undefined behavior!
	 */
	public void reset() throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)8, FUNCTION_RESET, this);


		sendRequest(bb.array());
	}

	/**
	 * Writes a new UID into flash. If you want to set a new UID
	 * you have to decode the Base58 encoded UID string into an
	 * integer first.
	 * 
	 * We recommend that you use Brick Viewer to change the UID.
	 */
	public void writeUID(long uid) throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)12, FUNCTION_WRITE_UID, this);

		bb.putInt((int)uid);

		sendRequest(bb.array());
	}

	/**
	 * Returns the current UID as an integer. Encode as
	 * Base58 to get the usual string version.
	 */
	public long readUID() throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)8, FUNCTION_READ_UID, this);


		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		long uid = IPConnection.unsignedInt(bb.getInt());

		return uid;
	}

	/**
	 * Returns the UID, the UID where the Bricklet is connected to,
	 * the position, the hardware and firmware version as well as the
	 * device identifier.
	 * 
	 * The position can be 'a', 'b', 'c' or 'd'.
	 * 
	 * The device identifier numbers can be found :ref:`here <device_identifier>`.
	 * |device_identifier_constant|
	 */
	public Identity getIdentity() throws TinkerforgeException {
		ByteBuffer bb = ipcon.createRequestPacket((byte)8, FUNCTION_GET_IDENTITY, this);


		byte[] response = sendRequest(bb.array());

		bb = ByteBuffer.wrap(response, 8, response.length - 8);
		bb.order(ByteOrder.LITTLE_ENDIAN);

		Identity obj = new Identity();
		obj.uid = IPConnection.string(bb, 8);
		obj.connectedUid = IPConnection.string(bb, 8);
		obj.position = (char)(bb.get());
		for (int i = 0; i < 3; i++) {
			obj.hardwareVersion[i] = IPConnection.unsignedByte(bb.get());
		}
		for (int i = 0; i < 3; i++) {
			obj.firmwareVersion[i] = IPConnection.unsignedByte(bb.get());
		}
		obj.deviceIdentifier = IPConnection.unsignedShort(bb.getShort());

		return obj;
	}

	/**
	 * Adds a UVA listener.
	 */
	public void addUVAListener(UVAListener listener) {
		listenerUVA.add(listener);
	}

	/**
	 * Removes a UVA listener.
	 */
	public void removeUVAListener(UVAListener listener) {
		listenerUVA.remove(listener);
	}

	/**
	 * Adds a UVB listener.
	 */
	public void addUVBListener(UVBListener listener) {
		listenerUVB.add(listener);
	}

	/**
	 * Removes a UVB listener.
	 */
	public void removeUVBListener(UVBListener listener) {
		listenerUVB.remove(listener);
	}

	/**
	 * Adds a UVI listener.
	 */
	public void addUVIListener(UVIListener listener) {
		listenerUVI.add(listener);
	}

	/**
	 * Removes a UVI listener.
	 */
	public void removeUVIListener(UVIListener listener) {
		listenerUVI.remove(listener);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy