X-Git-Url: http://dolda2000.com/gitweb/?p=kaka%2Fcakelight.git;a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FLedFrame.java;h=9d95b0ca742e77d500395b73c18a97ff8492369f;hp=4d6b68add12d99313bfaaedcf0d407434fea0d57;hb=0bf6c885fdaa8273ab72789f7efcd9477234168a;hpb=fa0f769bf3338643755de3624aa4b6db53cea6e6 diff --git a/src/kaka/cakelight/LedFrame.java b/src/kaka/cakelight/LedFrame.java index 4d6b68a..9d95b0c 100644 --- a/src/kaka/cakelight/LedFrame.java +++ b/src/kaka/cakelight/LedFrame.java @@ -1,11 +1,13 @@ package kaka.cakelight; public class LedFrame { + private Configuration config; private byte[] bytes; private int roff = 0, goff = 2, boff = 1; // Color values are stored as RBG, which is what the LED list takes. public static LedFrame from(Configuration config) { LedFrame frame = new LedFrame(); + frame.config = config; frame.bytes = new byte[config.leds.getCount() * 3]; return frame; } @@ -41,4 +43,21 @@ public class LedFrame { public byte[] getBytes() { return bytes; } + + // TODO this needs to be improved + /** The x position of the led from 0.0-1.0. */ + public double xOf(int led) { + /* left */ if (led >= config.leds.cols * 2 + config.leds.rows) return 0; + /* top */ if (led >= config.leds.cols + config.leds.rows) return 1 - (double)(led - config.leds.cols - config.leds.rows) / config.leds.cols; + /* right */ if (led >= config.leds.cols) return 1; + /* bottom */ return (double)led / config.leds.cols; + } + + /** The y position of the led from 0.0-1.0. */ + public double yOf(int led) { + /* left */ if (led >= config.leds.cols * 2 + config.leds.rows) return (double)(led - config.leds.cols * 2 - config.leds.rows) / config.leds.rows; + /* top */ if (led >= config.leds.cols + config.leds.rows) return 0; + /* right */ if (led >= config.leds.cols) return 1 - (double)(led - config.leds.cols) / config.leds.rows; + /* bottom */ return 1; + } }