Adjusted display timer in DS5 controller
This commit is contained in:
parent
c337565dc1
commit
b32b5dbdee
1 changed files with 44 additions and 29 deletions
|
@ -56,6 +56,8 @@ int curVol = 0;
|
|||
int targetVol = 0;
|
||||
unsigned long lastVolChange = 0;
|
||||
unsigned long volumeInterval = 500;
|
||||
unsigned long volDisplayDelay = 7000;
|
||||
uint8_t otherCommandSend = 0;
|
||||
// Process tracker for calibration. 0 = nothing, 1 = decreasing, 2 = increasing
|
||||
uint8_t recalibrateState = 0;
|
||||
int calibrateLowerLimit = -55;
|
||||
|
@ -266,37 +268,50 @@ void updateState() {
|
|||
client.publish(mqtt_topic_volumeState, msg);
|
||||
}
|
||||
|
||||
void updateVolume() {
|
||||
// Increase volume a notch if requested
|
||||
if (targetVol > curVol) {
|
||||
void updateVolume(unsigned long timeSinceChange) {
|
||||
|
||||
if (otherCommandSend || timeSinceChange > volDisplayDelay) {
|
||||
// Switch display to volume mode
|
||||
replicateNEC(irSendPin, 0x807F7A85, 32);
|
||||
curVol += 1;
|
||||
} else {
|
||||
// Increase volume a notch if requested
|
||||
if (targetVol > curVol) {
|
||||
replicateNEC(irSendPin, 0x807F7A85, 32);
|
||||
curVol += 1;
|
||||
|
||||
snprintf(msg, 49, "%d", curVol);
|
||||
client.publish(mqtt_topic_volumeState, msg);
|
||||
snprintf(msg, 49, "%d", curVol);
|
||||
client.publish(mqtt_topic_volumeState, msg);
|
||||
}
|
||||
|
||||
// Decrease volume a notch if requested
|
||||
if (targetVol < curVol) {
|
||||
replicateNEC(irSendPin, 0x807F6A95, 32);
|
||||
curVol -= 1;
|
||||
|
||||
snprintf(msg, 49, "%d", curVol);
|
||||
client.publish(mqtt_topic_volumeState, msg);
|
||||
}
|
||||
|
||||
// Check recalibration state
|
||||
if (recalibrateState == 2 && curVol == calibrateUpperLimit) {
|
||||
recalibrateState = 0;
|
||||
}
|
||||
if (recalibrateState == 1 && curVol == calibrateLowerLimit) {
|
||||
recalibrateState = 2;
|
||||
targetVol = calibrateUpperLimit;
|
||||
}
|
||||
}
|
||||
|
||||
// Decrease volume a notch if requested
|
||||
if (targetVol < curVol) {
|
||||
replicateNEC(irSendPin, 0x807F6A95, 32);
|
||||
curVol -= 1;
|
||||
|
||||
snprintf(msg, 49, "%d", curVol);
|
||||
client.publish(mqtt_topic_volumeState, msg);
|
||||
}
|
||||
|
||||
// Check recalibration state
|
||||
if (recalibrateState == 2 && curVol == calibrateUpperLimit) {
|
||||
recalibrateState = 0;
|
||||
}
|
||||
if (recalibrateState == 1 && curVol == calibrateLowerLimit) {
|
||||
recalibrateState = 2;
|
||||
targetVol = calibrateUpperLimit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
Serial.print("Sending code ");
|
||||
Serial.println(data, HEX);
|
||||
|
@ -341,9 +356,9 @@ void loop() {
|
|||
|
||||
// Maybe update the volume
|
||||
unsigned long now = millis();
|
||||
if (now - lastVolChange > volumeInterval) {
|
||||
if (targetVol != curVol && now - lastVolChange > volumeInterval) {
|
||||
updateVolume(now - lastVolChange);
|
||||
lastVolChange = now;
|
||||
updateVolume();
|
||||
}
|
||||
|
||||
// Maybe push the current status
|
||||
|
|
Loading…
Reference in a new issue