X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FLedFrame.java;h=ab4ef5c9fa12bb825fc2a266538232c9b5d0de44;hb=38c759f87fc7de47d9dee60088f2dbc60e0a55fb;hp=a4f6293d6e2d8ecdff9bf70b00364b891a86bfaa;hpb=03b67a7377d6d23d517d33e47f338bb7859596ed;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/LedFrame.java b/src/kaka/cakelight/LedFrame.java index a4f6293..ab4ef5c 100644 --- a/src/kaka/cakelight/LedFrame.java +++ b/src/kaka/cakelight/LedFrame.java @@ -1,21 +1,64 @@ package kaka.cakelight; -import javafx.scene.paint.Color; - public class LedFrame { - private Color[] leds; + 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.leds = new Color[config.leds.cols * 2 + config.leds.rows * 2]; + frame.config = config; + frame.bytes = new byte[config.leds.getCount() * 3]; return frame; } + public void fillColor(int r, int g, int b) { + fillColor(Color.rgb(r, g, b)); + } + + public void fillColor(Color color) { + byte r = (byte)color.r(), g = (byte)color.g(), b = (byte)color.b(); // Gamma corrected values + for (int i = 0; i < bytes.length; i += 3) { + bytes[i + roff] = r; + bytes[i + goff] = g; + bytes[i + boff] = b; + } + } + public void setLedColor(int led, Color color) { - leds[led] = color; + int offset = led * 3; + bytes[offset + roff] = (byte)color.r(); + bytes[offset + goff] = (byte)color.g(); + bytes[offset + boff] = (byte)color.b(); } public Color getLedColor(int led) { - return leds[led]; + int offset = led * 3; + return Color.rgb( + bytes[offset + roff] & 0xff, + bytes[offset + goff] & 0xff, + bytes[offset + boff] & 0xff + ); + } + + 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; } }