package waterlevelsensor;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.keywords.DateTime;

@BA.ShortName("HPT604Data")
public class HPT604Data {
	
	/**
	 * Check if this is a valid data
	 */
	public final boolean valid;
	
	/**
	 * when the measurement taken, in datetime.tick
	 */
	public final long timetick = DateTime.getNow();
	
	/**
	 * Sensor full scale spec, in meters
	 */
	public final double fullscale;
	
	/**
	 * Binary value read from sensor
	 */
	public final int binaryvalue;
	
	/**
	 * Calculated water level, in meters
	 */
	public final double meters;
	
	public HPT604Data() {
		valid = false;
		fullscale = 0;
		binaryvalue = 0;
		meters = 0;
	}
	
	public HPT604Data(int binary, double fullscalevalue) {
		if (binary>0) {
			if (fullscalevalue>0) {
				binaryvalue = binary;
				fullscale = fullscalevalue;
				if (fullscale<10) {
					meters = binaryvalue / 10000.0;
				} else {
					meters = binaryvalue / 1000.0;
				}
				valid = true;
				return;
			}
		}
		valid = false;
		binaryvalue = 0;
		fullscale = 0;
		meters = 0;
	}
	
}
