/** * Function returns all of the scribbler sensors (not fluke) in a hashmap. Each associated array * for a key is of variable length, depending on the type of sensor. IR array has size 2; LIGHT * array has size 3; LINE array has size 2; STALL array has size 1; * * @return hashmap with keys: "IR", "LINE", "LIGHT", and "STALL" */ public HashMap<String, int[]> getAll() { HashMap<String, int[]> hm = new HashMap<String, int[]>(); int[] v; if (getCommands != null) { v = getCommands.getAll(); hm.put("IR", new int[] {v[0], v[1]}); hm.put("LIGHT", new int[] {v[2], v[3], v[4]}); hm.put("LINE", new int[] {v[5], v[6]}); hm.put("STALL", new int[] {v[7]}); } return hm; }
public float getBattery() { byte[] ba = null; int unmodified; float value = 0; if (getCommands != null) { ba = getCommands.getBattery(); unmodified = (ba[0] & 0xFF) << 8 | ba[1] & 0xFF; value = unmodified / 20.9813f; if (D) Log.d(TAG, "getBattery -> " + value); } return value; }
/** * Function properly gets and converts the robots name * * @return - String representing the robots trimmed name */ public String getName() { int[] ba; StringBuilder build; String name = null; if (getCommands != null) { // Get the proper bytes and convert them to characters ba = getCommands.getName(); build = new StringBuilder(ba.length); for (int i = 0; i < ba.length; i++) build.append((char) ba[i]); name = build.toString().trim(); } if (D) Log.d(TAG, "Scribbler Name Read: " + name); return name; }
public int[] getIR(String type) { int[] ba, ret = null; type = type.toLowerCase(); if (getCommands != null) { ba = getCommands.getIR(); if (type.equals("left")) { ret = new int[1]; ret[0] = ba[0]; } else if (type.equals("right")) { ret = new int[1]; ret[0] = ba[1]; } else { ret = ba; } } return ret; }
public Bitmap takePicture() { Bitmap bm = null; byte[] ba; if (getCommands != null) { ba = getCommands.getPictureArray(); bm = Bitmap.createBitmap(256, 192, Bitmap.Config.ARGB_8888); int w = 256; int h = 192; int vy, vu, y1v, y1u, uy, uv, y2u, y2v; int V = 0, Y = 0, U = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (j >= 3) { vy = -1; vu = 2; y1v = -1; y1u = -3; uy = -1; uv = -2; y2u = -1; y2v = -3; } else { vy = 1; vu = 2; y1v = 3; y1u = 1; uy = 1; uv = 2; y2u = 3; y2v = 1; } if ((j % 4) == 0) { V = ba[i * w + j] & 0xff; Y = ba[i * w + j + vy] & 0xff; U = ba[i * w + j + vu] & 0xff; } else if ((j % 4) == 1) { Y = ba[i * w + j] & 0xff; V = ba[i * w + j + y1v] & 0xff; U = ba[i * w + j + y1u] & 0xff; } else if ((j % 4) == 2) { U = ba[i * w + j] & 0xff; Y = ba[i * w + j + uy] & 0xff; V = ba[i * w + j + uv] & 0xff; } else if ((j % 4) == 3) { Y = ba[i * w + j] & 0xff; U = ba[i * w + j + y2u] & 0xff; V = ba[i * w + j + y2v] & 0xff; } U = U - 128; V = V - 128; // Y = Y; bm.setPixel( j, i, Color.rgb( (int) Math.max(Math.min(Y + 1.13983 * V, 255), 0), (int) Math.max(Math.min(Y - 0.39466 * U - 0.58060 * V, 255), 0), (int) Math.max(Math.min(Y + 2.03211 * U, 255), 0))); } } } return bm; }