package no.topi.fiken.display; import android.util.Log; import static no.topi.fiken.display.DefaultDisplayService.toHexString; public class FikenStatusPanel { private final static String TAG = DefaultDisplayService.class.getSimpleName(); public static final byte FSP_CMD_GET_GAUGE_COUNT = (byte) 0x01, FSP_CMD_SET_GAUGE = (byte) 0x02, FSP_CMD_GET_GAUGE = (byte) 0x03, FSP_CMD_FAIL = (byte) 0xff; private Integer[] gauges; public int gaugeCount() { return gauges != null ? gauges.length : 0; } public Integer get(int gauge) { return gauges[gauge]; } public void update(byte[] data) { Log.d(TAG, "data=" + toHexString(data)); byte len = data[0]; byte code = data[1]; switch (code) { case FSP_CMD_GET_GAUGE_COUNT: byte count = data[2]; gauges = new Integer[count]; Log.d(TAG, "Gauge count=" + count); break; case FSP_CMD_GET_GAUGE: byte gauge = data[2]; byte value = data[3]; Log.d(TAG, "Gauge #" + gauge + ", value=" + value); if (gauge < gauges.length) { gauges[gauge] = 0xff & value; } break; case FSP_CMD_FAIL: Log.e(TAG, "FSP_CMD_FAIL"); break; case FSP_CMD_SET_GAUGE: // ignored break; default: Log.w(TAG, "Unknown code: " + code); break; } } public static byte[] getGaugeCountReq() { return new byte[]{FSP_CMD_GET_GAUGE_COUNT}; } public static byte[] getGaugeValueReq(byte gauge) { return new byte[]{FSP_CMD_GET_GAUGE, gauge}; } public static byte[] setGaugeValueReq(byte gauge, byte value) { return new byte[]{FSP_CMD_SET_GAUGE, gauge, value}; } }