void capOverallBrightness(RNLights & lights) { uint8_t avgPixelBrightness = lights.getAvgPixelBrightness(); uint8_t avgBrightness = avgPixelBrightness * lights.getBrightness()/256; if (avgBrightness > constants.brightnessChunkSize) { int goal = scaleBrightness(avgBrightness); int newBrightness = goal * 255 / avgPixelBrightness; #ifdef RN_PRINT_BRIGHTNESS_ADJUSTMENTS info->printf("Avg brightness is %d/%d, goal is %d, Reducing brightness from %d -> %d\n", avgPixelBrightness, avgBrightness, goal, lights->getBrightness(), newBrightness); #endif /* RN_PRINT_BRIGHTNESS_ADJUSTMENTS */ lights.setBrightness(newBrightness); } // else info.printf("Avg brightness is %d/%d\n", avgPixelBrightness, avgBrightness); }
void RNInfo::showActivityWithBrightness(RNLights & lights, uint16_t minBrightness) { int maxAdjustment = (256 - minBrightness); float activity = getLocalActivity() * 6; if (activity > 1.0) activity = 1.0; minBrightness += maxAdjustment * activity / 4; if (minBrightness >= 256) return; int b = 256; int age = timeSinceLastTap() - 100; if (age > 0) b = 256 - age/2; if (b < minBrightness) b = minBrightness; int newBrightness = b * lights.getBrightness() / 256; #ifdef RN_PRINT_BRIGHTNESS_ADJUSTMENTS printf("Changing brightness %d -> %d\n", lights.getBrightness(), newBrightness); #endif /* RN_PRINT_BRIGHTNESS_ADJUSTMENTS */ lights.setBrightness(newBrightness); }