1 /* 2 * Copyright © 2016 Greg Chabala 3 * 4 * This file is part of brick-control-lab. 5 * 6 * brick-control-lab is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as 8 * published by the Free Software Foundation, either version 3 of the 9 * License, or (at your option) any later version. 10 * 11 * brick-control-lab is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with brick-control-lab. If not, see http://www.gnu.org/licenses/. 18 */ 19 package org.chabala.brick.controllab.sensor; 20 21 import org.chabala.brick.controllab.InputId; 22 23 /** 24 * The values obtained from reading an {@link InputId}. 25 */ 26 public interface SensorValue { 27 28 static SensorValue newSensorValue(byte high, byte low) { 29 return new SensorValueImpl(high, low); 30 } 31 32 /** 33 * Analog value returned by sensor, in the range of 0 to 1023. 34 * @return value from 0 to 1023, inclusive. 35 */ 36 int getAnalogValue(); 37 38 /** 39 * Six bit status code from the sensor, as a value from 0 to 63. 40 * @return value from 0 to 63, inclusive. 41 */ 42 int getStatusCode(); 43 44 /** 45 * bit 3 looks like 0 for passive, 1 for active sensors. 46 * @return true for passive sensors, false for active sensors 47 */ 48 default boolean isPassive() { 49 return (getStatusCode() & 0b000100) == 0; 50 } 51 52 /** 53 * bit 4 looks like 0 for engaged, 1 for released. 54 * (when four is low, sensor is lit on box) 55 * @return true for engaged sensors, false for released sensors 56 */ 57 default boolean isEngaged() { 58 return (getStatusCode() & 0b001000) == 0; 59 } 60 }