Adjusted display timer in DS5 controller

This commit is contained in:
Nis Wechselberg 2017-09-25 21:44:53 +02:00
parent c337565dc1
commit b32b5dbdee

View file

@ -56,6 +56,8 @@ int curVol = 0;
int targetVol = 0; int targetVol = 0;
unsigned long lastVolChange = 0; unsigned long lastVolChange = 0;
unsigned long volumeInterval = 500; unsigned long volumeInterval = 500;
unsigned long volDisplayDelay = 7000;
uint8_t otherCommandSend = 0;
// Process tracker for calibration. 0 = nothing, 1 = decreasing, 2 = increasing // Process tracker for calibration. 0 = nothing, 1 = decreasing, 2 = increasing
uint8_t recalibrateState = 0; uint8_t recalibrateState = 0;
int calibrateLowerLimit = -55; int calibrateLowerLimit = -55;
@ -266,7 +268,12 @@ void updateState() {
client.publish(mqtt_topic_volumeState, msg); client.publish(mqtt_topic_volumeState, msg);
} }
void updateVolume() { void updateVolume(unsigned long timeSinceChange) {
if (otherCommandSend || timeSinceChange > volDisplayDelay) {
// Switch display to volume mode
replicateNEC(irSendPin, 0x807F7A85, 32);
} else {
// Increase volume a notch if requested // Increase volume a notch if requested
if (targetVol > curVol) { if (targetVol > curVol) {
replicateNEC(irSendPin, 0x807F7A85, 32); replicateNEC(irSendPin, 0x807F7A85, 32);
@ -293,10 +300,18 @@ void updateVolume() {
recalibrateState = 2; recalibrateState = 2;
targetVol = calibrateUpperLimit; targetVol = calibrateUpperLimit;
} }
}
} }
void replicateNEC(int pin, uint32_t data, int dataLength) { void replicateNEC(int pin, uint32_t data, int dataLength) {
// Track if some other command than volume control has been sent in the meantime
if (data == 0x807F7A85 || data == 0x807F6A95) {
otherCommandSend = 0;
} else {
otherCommandSend = 1;
}
if (DEBUGTOSERIAL) { if (DEBUGTOSERIAL) {
Serial.print("Sending code "); Serial.print("Sending code ");
Serial.println(data, HEX); Serial.println(data, HEX);
@ -341,9 +356,9 @@ void loop() {
// Maybe update the volume // Maybe update the volume
unsigned long now = millis(); unsigned long now = millis();
if (now - lastVolChange > volumeInterval) { if (targetVol != curVol && now - lastVolChange > volumeInterval) {
updateVolume(now - lastVolChange);
lastVolChange = now; lastVolChange = now;
updateVolume();
} }
// Maybe push the current status // Maybe push the current status