Files
LedD-Android/app/src/main/java/com/idlegandalf/ledd/components/LedStripe.java
Giovanni Harting 58980c494e updated libs
added library management
changed some edittext to the right class
2016-04-30 20:17:07 +02:00

121 lines
3.5 KiB
Java

/*
* LEDD Project
* Copyright (C) 2015 LEDD Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.idlegandalf.ledd.components;
import android.graphics.Color;
import android.support.annotation.Nullable;
import com.idlegandalf.ledd.ColorApplication;
import com.idlegandalf.ledd.callbacks.ReceiveColorCallback;
import com.idlegandalf.ledd.helper.LedDHelper;
import hugo.weaving.DebugLog;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class LedStripe {
int id;
int channelRed;
int channelGreen;
int channelBlue;
String name;
HSV color;
double gammaCorrection;
boolean RGB;
Controller controller;
LedDDaemon ledDDaemon;
LedDHelper helper;
public LedStripe() {
this(-1, -1, -1, -1, "");
}
public LedStripe(int channelRed, int channelGreen, int channelBlue, String name) {
this(-1, channelRed, channelGreen, channelBlue, name, true);
}
public LedStripe(int id, int channelRed, int channelGreen, int channelBlue, String name) {
this(id, channelRed, channelGreen, channelBlue, name, true);
}
public LedStripe(int id, int channelRed, int channelGreen, int channelBlue, String name, boolean RGB) {
this.id = id;
this.channelRed = channelRed;
this.channelGreen = channelGreen;
this.channelBlue = channelBlue;
this.name = name;
this.RGB = RGB;
}
@Override
public String toString() {
return String.format("%s->%s->%s (%d|%d|%d)", ledDDaemon, controller.getAddress(), name, channelRed, channelGreen, channelBlue);
}
@DebugLog
public void setColor(int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
setColor(new HSV(hsv[0], hsv[1], hsv[2]));
}
public void setColor(HSV color) {
checkHelper();
this.color = color;
helper.setColor(this);
}
private void checkHelper() {
if (helper == null) {
helper = ColorApplication.getInstance().getHelperForDaemon(ledDDaemon);
}
}
@DebugLog
public void getColor(@Nullable final ReceiveColorCallback callback) {
checkHelper();
helper.getColor(this, new ReceiveColorCallback() {
@Override
public void onColorReceived(LedStripe stripe) {
color = stripe.getColor();
if (callback != null)
callback.onColorReceived(LedStripe.this);
}
@Override
public void onReceiveFailed(int code, String msg) {
if (callback != null) callback.onReceiveFailed(code, msg);
}
@Override
public void onConnectionFailed(String message) {
if (callback != null) callback.onConnectionFailed(message);
}
});
}
@DebugLog
public boolean isOn() {
return color != null && color.getValue() != 0.0;
}
}