private void scheduleLedData(final int position, LedData data) { ledDataMap.put(position, data); thereIsNewData = true; if (data.duration > 0) { executorService.schedule( new Runnable() { @Override public void run() { scheduleLedData(position, new LedData()); } }, data.duration, TimeUnit.MILLISECONDS); } }
private void sendLedData() { thereIsNewData = false; if (bricklet == null) { log.warn("No data could be send to the ledstrip..."); return; } for (int i = 0; i < endpoint.getAmountOfLeds(); i += FRAME_LENGTH) { short[] r = new short[FRAME_LENGTH]; short[] g = new short[FRAME_LENGTH]; short[] b = new short[FRAME_LENGTH]; for (int j = 0; (j < FRAME_LENGTH) && ((j + i) < endpoint.getAmountOfLeds()); j++) { LedData data = ledDataMap.get(i + j); if (data != null) { if (endpoint.getRgbPattern().equals("rgb")) { r[j] = data.red; g[j] = data.green; b[j] = data.blue; } else if (endpoint.getRgbPattern().equals("bgr")) { r[j] = data.blue; g[j] = data.green; b[j] = data.red; } else if (endpoint.getRgbPattern().equals("brg")) { r[j] = data.blue; g[j] = data.red; b[j] = data.green; } else { throw new IllegalArgumentException( "Unsupported RGB Pattern: " + endpoint.getRgbPattern()); } } } try { bricklet.setRGBValues(i, FRAME_LENGTH, r, g, b); } catch (TimeoutException | NotConnectedException e) { log.error("Could not send LED data", e); } } }