Skip to content

Commit

Permalink
Added LightToggleCineAdjustedProcedure
Browse files Browse the repository at this point in the history
  • Loading branch information
iamniklas committed Sep 16, 2022
1 parent 63592a7 commit 436dc96
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 4 deletions.
6 changes: 4 additions & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class LEDDataBundle {
public Float value3;
public Integer modulo;
public InterpolationType interpolation;
public InterpolationType interpolationOverDistance;
public Direction direction;
public Integer bpm;
public Float repetitions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static Procedure getProcedure(LEDUpdateModel _updateModel) {
case Lightning: return new LightningProcedure(_updateModel);
case Javascript: return new JavascriptProcedure(_updateModel);
case LightToggle: return new LightToggleProcedure(_updateModel);
case LightToggleCineAdjusted: return new LightToggleCineAdjustedProcedure(_updateModel);
case NoLongerReady: return new NoLongerReadyProcedure(_updateModel);
default: return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public enum ProcedureType {
Progress,
Lightning,
MusicSync,
LightToggle,
RandomColorBlocks,
Javascript,
NoLongerReady
NoLongerReady,
LightToggle,
LightToggleCineAdjusted,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.github.iamniklas.liocore.procedures.variants;

import com.github.iamniklas.colorspaces.ColorRGB;
import com.github.iamniklas.interpolation.Interpolation;
import com.github.iamniklas.interpolation.InterpolationType;
import com.github.iamniklas.liocore.led.LEDDataBundle;
import com.github.iamniklas.liocore.led.LEDStripManager;
import com.github.iamniklas.liocore.led.colorspace.LIOColor;
import com.github.iamniklas.liocore.network.LEDUpdateModel;
import com.github.iamniklas.liocore.procedures.LEDStrip;
import com.github.iamniklas.liocore.procedures.Procedure;
import com.github.iamniklas.liocore.procedures.ProcedureAction;

public class LightToggleCineAdjustedProcedure extends Procedure {

private boolean lightIsOn = true;

private int lowerBound = 0;
private int upperBound = LEDStripManager.ledCount - 1;
private int counter = 0;

public LightToggleCineAdjustedProcedure(LEDUpdateModel _updateModel) {
super(_updateModel);
}

@Override
public void update() {
if(lightIsOn) {
for (int i = 0; i < Math.min(
Math.round(Interpolation.getInterpolationValue(counter/300f, ledUpdateModel.bundle.interpolation) * LEDStripManager.ledCount),
upperBound + 1); i++) {
strip.setPixel(i, LIOColor.fromRGB(ledUpdateModel.bundle.colorPrimary.dim((LEDStripManager.ledCount - i) / (float)LEDStripManager.ledCount)));
}
/*strip.setArea(
lowerBound,
Math.min(
Math.round(Interpolation.getInterpolationValue(counter/300f, ledUpdateModel.bundle.interpolation) * LEDStripManager.ledCount),
upperBound + 1),
LIOColor.fromRGB(ledUpdateModel.bundle.colorPrimary.dim())
);*/
} else {
for (int i = 0; i < Math.min(
Math.round(Interpolation.getInterpolationValue(counter/300f, ledUpdateModel.bundle.interpolation) * LEDStripManager.ledCount),
upperBound + 1); i++) {
strip.setPixel(i, LIOColor.fromRGB(ColorRGB.BLACK));
}
/*strip.setArea(
lowerBound,
Math.min(
Math.round(Interpolation.getInterpolationValue(counter/300f, ledUpdateModel.bundle.interpolation) * LEDStripManager.ledCount),
upperBound + 1),
LIOColor.fromRGB(ColorRGB.BLACK)
);*/
}

if(counter < upperBound) {
float duration = (ledUpdateModel.bundle.duration == null) ? 1.0f : (float)ledUpdateModel.bundle.duration;
counter += 5 * ( 1 / duration);
}
if(counter > upperBound) {
counter = LEDStripManager.ledCount;
}
}

@Override
public void updateLEDDataBundle(LEDDataBundle ledDataBundle) {
super.updateLEDDataBundle(ledDataBundle);
}

@Override
public void onActionReceived(ProcedureAction procedureAction) {
super.onActionReceived(procedureAction);

switch (procedureAction) {
case Toggle:
counter = 0;
lightIsOn = !lightIsOn;
break;
case Enable:
lightIsOn = true;
break;
case Disable:
lightIsOn = false;
break;
}
}
}

0 comments on commit 436dc96

Please sign in to comment.