@@ -21,6 +21,9 @@ public class BrightnessDecode {
2121 private static final String INTENSITY_MATH_CLOSE_HEX = ").hex}" ;
2222 private static final String INTENSITY_PERCENT_HEX = "${intensity.percent.hex}" ;
2323 private static final String INTENSITY_BYTE_HEX = "${intensity.byte.hex}" ;
24+ private static final String INTENSITY_PREVIOUS_PERCENT = "${intensity.previous_percent}" ;
25+ private static final String INTENSITY_PREVIOUS_DECIMAL_PERCENT = "${intensity.previous_decimal_percent}" ;
26+ private static final String INTENSITY_PREVIOUS_BYTE = "${intensity.previous_byte}" ;
2427
2528 public static int calculateIntensity (int setIntensity , Integer targetBri , Integer targetBriInc ) {
2629 if (targetBri != null ) {
@@ -45,7 +48,7 @@ else if ((setIntensity + targetBriInc) > 254)
4548 * intensity.math(X*1) : where X is the value from the interface call and
4649 * can use net.java.dev.eval math
4750 */
48- public static String replaceIntensityValue (String request , int intensity , boolean isHex ) {
51+ private static String replaceIntensityValue (String request , int previous_intensity , int intensity , boolean isHex ) {
4952 if (request == null ) {
5053 return null ;
5154 }
@@ -54,6 +57,8 @@ public static String replaceIntensityValue(String request, int intensity, boolea
5457 String replaceTarget = null ;
5558 int percentBrightness = 0 ;
5659 float decimalBrightness = (float ) 1.0 ;
60+ int previousPercentBrightness = 0 ;
61+ float previousDecimalBrightness = (float ) 1.0 ;
5762 Map <String , BigDecimal > variables = new HashMap <String , BigDecimal >();
5863 String mathDescriptor = null ;
5964
@@ -68,6 +73,17 @@ public static String replaceIntensityValue(String request, int intensity, boolea
6873 percentBrightness = 1 ;
6974 }
7075
76+ if (previous_intensity > 0 ) {
77+ previousDecimalBrightness = (float ) (previous_intensity / 255.0 );
78+ if (previous_intensity > 0 && previous_intensity < 5 )
79+ previousPercentBrightness = 1 ;
80+ else
81+ previousPercentBrightness = (int ) Math .round (previous_intensity / 255.0 * 100 );
82+ } else {
83+ previousDecimalBrightness = (float ) 1.0 ;
84+ previousPercentBrightness = 1 ;
85+ }
86+
7187 while (notDone ) {
7288 notDone = false ;
7389 if (request .contains (INTENSITY_BYTE )) {
@@ -78,6 +94,14 @@ public static String replaceIntensityValue(String request, int intensity, boolea
7894 }
7995 replaceTarget = INTENSITY_BYTE ;
8096 notDone = true ;
97+ } else if (request .contains (INTENSITY_PREVIOUS_BYTE )) {
98+ if (isHex ) {
99+ replaceValue = convertToHex (previous_intensity );
100+ } else {
101+ replaceValue = String .valueOf (previous_intensity );
102+ }
103+ replaceTarget = INTENSITY_PREVIOUS_BYTE ;
104+ notDone = true ;
81105 } else if (request .contains (INTENSITY_BYTE_HEX )) {
82106 replaceValue = convertToHex (intensity );
83107 replaceTarget = INTENSITY_BYTE_HEX ;
@@ -90,6 +114,14 @@ public static String replaceIntensityValue(String request, int intensity, boolea
90114 }
91115 replaceTarget = INTENSITY_PERCENT ;
92116 notDone = true ;
117+ } else if (request .contains (INTENSITY_PREVIOUS_PERCENT )) {
118+ if (isHex ) {
119+ replaceValue = convertToHex (previousPercentBrightness );
120+ } else {
121+ replaceValue = String .valueOf (previousPercentBrightness );
122+ }
123+ replaceTarget = INTENSITY_PREVIOUS_PERCENT ;
124+ notDone = true ;
93125 } else if (request .contains (INTENSITY_PERCENT_HEX )) {
94126 replaceValue = convertToHex (percentBrightness );
95127 replaceTarget = INTENSITY_PERCENT_HEX ;
@@ -98,6 +130,10 @@ public static String replaceIntensityValue(String request, int intensity, boolea
98130 replaceValue = String .format (Locale .ROOT , "%1.2f" , decimalBrightness );
99131 replaceTarget = INTENSITY_DECIMAL_PERCENT ;
100132 notDone = true ;
133+ } else if (request .contains (INTENSITY_PREVIOUS_DECIMAL_PERCENT )) {
134+ replaceValue = String .format (Locale .ROOT , "%1.2f" , previousDecimalBrightness );
135+ replaceTarget = INTENSITY_PREVIOUS_DECIMAL_PERCENT ;
136+ notDone = true ;
101137 } else if (request .contains (INTENSITY_MATH_CLOSE )) {
102138 mathDescriptor = request .substring (request .indexOf (INTENSITY_MATH ) + INTENSITY_MATH .length (),
103139 request .indexOf (INTENSITY_MATH_CLOSE ));
@@ -135,7 +171,7 @@ public static String replaceIntensityValue(String request, int intensity, boolea
135171
136172 // Helper Method
137173 public static String calculateReplaceIntensityValue (String request , int theIntensity , Integer targetBri , Integer targetBriInc , boolean isHex ) {
138- return replaceIntensityValue (request , calculateIntensity (theIntensity , targetBri , targetBriInc ), isHex );
174+ return replaceIntensityValue (request , theIntensity , calculateIntensity (theIntensity , targetBri , targetBriInc ), isHex );
139175 }
140176
141177 // Apache Commons Conversion utils likes little endian too much
0 commit comments