Skip to content

Commit

Permalink
Implement CCT state sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphiiko committed Aug 24, 2024
1 parent 93c8b22 commit 920aa12
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 13 deletions.
25 changes: 25 additions & 0 deletions src-overlay-sidecar/src-overlay-sidecar.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "oyasumivr-overlay-sidecar", "oyasumivr-overlay-sidecar.csproj", "{240CFAD1-7680-4BA7-8F6B-A1D23ABBBB91}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{240CFAD1-7680-4BA7-8F6B-A1D23ABBBB91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{240CFAD1-7680-4BA7-8F6B-A1D23ABBBB91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{240CFAD1-7680-4BA7-8F6B-A1D23ABBBB91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{240CFAD1-7680-4BA7-8F6B-A1D23ABBBB91}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C577E4CD-0E1C-477D-9396-41D59EBF9B86}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { CCTControlService } from '../../services/cct-control/cct-control.servic
animations: [fadeUp(), vshrink(), hshrink()],
})
export class CCTControlModalComponent extends BaseModalComponent<void, void> implements OnInit {
cctBounds = [1000, 10000];

protected readonly setCCT = new Subject<number>();

constructor(
Expand Down
35 changes: 35 additions & 0 deletions src-ui/app/services/overlay/overlay-state-sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { HardwareBrightnessControlService } from '../brightness-control/hardware
import { SoftwareBrightnessControlService } from '../brightness-control/software-brightness-control.service';
import { SleepPreparationService } from '../sleep-preparation.service';
import { SystemMicMuteAutomationService } from '../system-mic-mute-automation.service';
import { CCTControlService } from '../cct-control/cct-control.service';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -113,6 +114,14 @@ export class OverlayStateSyncService {
hardwareMinBrightness: 20,
hardwareMaxBrightness: 160,
},
cctState: {
enabled: APP_SETTINGS_DEFAULT.cctControlEnabled,
value: 6600,
min: 1000,
max: 10000,
transitioning: false,
transitionTarget: 6600,
},
sleepPreparationAvailable: false,
sleepPreparationTimedOut: false,
systemMicMuted: false,
Expand All @@ -123,6 +132,7 @@ export class OverlayStateSyncService {
private vrchatService: VRChatService,
private ipcService: IPCService,
private automationConfig: AutomationConfigService,
private cctService: CCTControlService,
private appSettings: AppSettingsService,
private shutdownAutomationsService: ShutdownAutomationsService,
private openvr: OpenVRService,
Expand All @@ -143,6 +153,7 @@ export class OverlayStateSyncService {
this.updateState_WhenOVRDevicesChange();
this.updateState_WhenAppSettingsChange();
this.updateState_WhenBrightnessStateChanges();
this.updateState_WhenCCTStateChanges();
this.updateState_WhenSleepPreparationStateChanges();
this.updateState_WhenSystemMicMuteStateChanges();
}
Expand Down Expand Up @@ -393,6 +404,30 @@ export class OverlayStateSyncService {
});
}

private updateState_WhenCCTStateChanges() {
this.appSettings.settings
.pipe(
map((settings) => settings.cctControlEnabled),
distinctUntilChanged()
)
.subscribe((enabled) => {
const state = structuredClone(this.state.value);
state.cctState!.enabled = enabled;
this.state.next(state);
});
this.cctService.cctStream.pipe(distinctUntilChanged()).subscribe((value) => {
const state = structuredClone(this.state.value);
state.cctState!.value = value;
this.state.next(state);
});
this.cctService.activeTransition.pipe(distinctUntilChanged()).subscribe((transition) => {
const state = structuredClone(this.state.value);
state.cctState!.transitioning = !!transition;
if (transition) state.cctState!.transitionTarget = transition.targetCCT;
this.state.next(state);
});
}

private updateState_WhenSleepPreparationStateChanges() {
this.sleepPreparation.sleepPreparationAvailable.subscribe((available) => {
const state = structuredClone(this.state.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,33 @@ export class BrightnessAutomationDetailsComponent implements OnInit {
}

protected async updateBrightness(type: BrightnessType, value: number | 'CURRENT') {
const copyCurrent = value === 'CURRENT';
const pConfig: Partial<BrightnessEventAutomationConfig> = {};
switch (type) {
case 'SIMPLE': {
if (value === 'CURRENT') value = this.simpleBrightnessControl.brightness;
pConfig.brightness = Math.round(value);
if (copyCurrent) value = this.simpleBrightnessControl.brightness;
pConfig.brightness = Math.round(value as number);
break;
}
case 'SOFTWARE': {
if (value === 'CURRENT') value = this.softwareBrightnessControl.brightness;
pConfig.softwareBrightness = Math.round(value);
if (copyCurrent) value = this.softwareBrightnessControl.brightness;
pConfig.softwareBrightness = Math.round(value as number);
break;
}
case 'HARDWARE': {
if (value === 'CURRENT') value = this.hardwareBrightnessControl.brightness;
pConfig.hardwareBrightness = Math.round(value);
if (copyCurrent) value = this.hardwareBrightnessControl.brightness;
pConfig.hardwareBrightness = Math.round(value as number);
break;
}
}
await this.updateConfig(pConfig);
this.vshakeElements.push('BRIGHTNESS_' + type);
setTimeout(() => {
const index = this.vshakeElements.indexOf('BRIGHTNESS_' + type);
if (index >= 0) this.vshakeElements.splice(index, 1);
}, 300);
if (copyCurrent) {
this.vshakeElements.push('BRIGHTNESS_' + type);
setTimeout(() => {
const index = this.vshakeElements.indexOf('BRIGHTNESS_' + type);
if (index >= 0) this.vshakeElements.splice(index, 1);
}, 300);
}
}

protected async toggleChangeBrightness() {
Expand Down

0 comments on commit 920aa12

Please sign in to comment.