gex: map anime dbus data

This commit is contained in:
Luke D. Jones
2023-06-29 15:16:21 +12:00
parent 6b058c9922
commit 15e6782e10
6 changed files with 199 additions and 116 deletions

View File

@@ -52,14 +52,14 @@
Get the device state as stored by asusd Get the device state as stored by asusd
--> -->
<method name="DeviceState"> <method name="DeviceState">
<arg type="(bsb(ssss))" direction="out"/> <arg type="bsb(ssss)" direction="out"/>
</method> </method>
<!-- <!--
Notify listeners of the status of AniMe LED power and factory Notify listeners of the status of AniMe LED power and factory
system-status animations system-status animations
--> -->
<signal name="NotifyDeviceState"> <signal name="NotifyDeviceState">
<arg name="data" type="(bsb(ssss))"/> <arg name="data" type="bsb(ssss)"/>
</signal> </signal>
</interface> </interface>
</node> </node>

View File

@@ -18,7 +18,8 @@ const ThisModule = imports.misc.extensionUtils.getCurrentExtension();
// const TestProxy = Gio.DBusProxy.makeProxyWrapper(interfaceXml); // const TestProxy = Gio.DBusProxy.makeProxyWrapper(interfaceXml);
import * as Platform from './bindings/platform'; import * as Platform from './bindings/platform';
import { ChargingLimit } from './modules/charge_dbus'; import { AnimeDbus } from './modules/anime_dbus';
import { Power } from './modules/power_dbus';
import { Supported } from './modules/supported_dbus'; import { Supported } from './modules/supported_dbus';
const QuickMiniLed = GObject.registerClass( const QuickMiniLed = GObject.registerClass(
@@ -135,7 +136,8 @@ class Extension {
private _naff: Platform.GpuMode; private _naff: Platform.GpuMode;
private _indicateMiniLed: typeof IndicateMiniLed; private _indicateMiniLed: typeof IndicateMiniLed;
private _indicatePanelOd: typeof IndicatePanelOd; private _indicatePanelOd: typeof IndicatePanelOd;
private _dbus_charge!: ChargingLimit; private _dbus_charge!: Power;
private _dbus_anime!: AnimeDbus;
private _dbus_supported!: Supported; private _dbus_supported!: Supported;
constructor() { constructor() {
@@ -147,16 +149,21 @@ class Extension {
enable() { enable() {
this._indicateMiniLed = new IndicateMiniLed(); this._indicateMiniLed = new IndicateMiniLed();
this._indicatePanelOd = new IndicatePanelOd(); this._indicatePanelOd = new IndicatePanelOd();
this._dbus_charge = new ChargingLimit(); this._dbus_charge = new Power();
this._dbus_charge.start().then(() => { this._dbus_charge.start().then(() => {
//@ts-ignore //@ts-ignore
log(`DOOOOOM!, charge limit =`, this._dbus_charge.lastState); log(`DOOOOOM!, charge limit =`, this._dbus_charge.chargeLimit);
}); });
this._dbus_supported = new Supported(); this._dbus_supported = new Supported();
this._dbus_supported.start().then(() => { this._dbus_supported.start().then(() => {
//@ts-ignore //@ts-ignore
log(`DOOOOOM!, supported =`, this._dbus_supported.supported); log(`DOOOOOM!, supported =`, this._dbus_supported.supported);
}); });
this._dbus_anime = new AnimeDbus();
this._dbus_anime.start().then(() => {
//@ts-ignore
log(`DOOOOOM!, anime =`, this._dbus_anime.deviceState.display_enabled);
});
} }
disable() { disable() {

View File

@@ -1,33 +1,37 @@
declare const global: any, imports: any; declare const global: any, imports: any;
declare var asusctlGexInstance: any; declare var asusctlGexInstance: any;
//@ts-ignore //@ts-ignore
const ThisModule = imports.misc.extensionUtils.getCurrentExtension(); const Me = imports.misc.extensionUtils.getCurrentExtension();
import * as Resources from './resources';
const { Gio } = imports.gi;
import { DbusBase } from '../modules/dbus'; import { DbusBase } from '../modules/dbus';
import { DeviceState, AnimBooting, Brightness, AnimAwake, AnimSleeping, AnimShutdown } from '../bindings/anime';
export class AnimeDbus extends DbusBase { export class AnimeDbus extends DbusBase {
state: boolean = true; deviceState: DeviceState = {
brightness: number = 255; display_enabled: false,
display_brightness: Brightness.Med,
builtin_anims_enabled: false,
builtin_anims: {
boot: AnimBooting.GlitchConstruction,
awake: AnimAwake.BinaryBannerScroll,
sleep: AnimSleeping.BannerSwipe,
shutdown: AnimShutdown.GlitchOut
},
};
constructor() { constructor() {
super('org-asuslinux-anime-4', '/org/asuslinux/Anime'); super('org-asuslinux-anime-4', '/org/asuslinux/Anime');
} }
public setOnOffState(state: boolean | null) { public setEnableDisplay(state: boolean | null) {
if (this.isRunning()) { if (this.isRunning()) {
try { try {
// if null, toggle the current state // if null, toggle the current state
state = (state == null ? !this.state : state); state = (state == null ? !this.deviceState.display_enabled : state);
if (this.state !== state) { if (this.deviceState.display_enabled !== state) {
this.state = state; this.deviceState.display_enabled = state;
} }
//@ts-ignore
log(`Setting AniMe Power to ${state}`);
return this.dbus_proxy.SetOnOffSync(state); return this.dbus_proxy.SetOnOffSync(state);
} catch (e) { } catch (e) {
//@ts-ignore //@ts-ignore
@@ -36,16 +40,13 @@ export class AnimeDbus extends DbusBase {
} }
} }
public setBrightness(brightness: number) { public setBrightness(brightness: Brightness) {
if (this.isRunning()) { if (this.isRunning()) {
try { try {
if (this.brightness !== brightness) { if (this.deviceState.display_brightness !== brightness) {
this.brightness = brightness; this.deviceState.display_brightness = brightness;
} }
//@ts-ignore
log(`Setting AniMe Brightness to ${brightness}`);
return this.dbus_proxy.SetBrightnessSync(brightness); return this.dbus_proxy.SetBrightnessSync(brightness);
// Panel.Actions.spawnCommandLine(`asusctl anime leds -b ${brightness}`);
} catch (e) { } catch (e) {
//@ts-ignore //@ts-ignore
log(`AniMe DBus set brightness failed!`, e); log(`AniMe DBus set brightness failed!`, e);
@@ -53,40 +54,65 @@ export class AnimeDbus extends DbusBase {
} }
} }
async start() { _parseDeviceState(input: String) {
//@ts-ignore let valueString: string = '';
log(`Starting AniMe DBus client...`);
try { for (const [_key, value] of Object.entries(input)) {
// creating the proxy
let xml = Resources.File.DBus('org-asuslinux-anime-4')
this.dbus_proxy = new Gio.DBusProxy.makeProxyWrapper(xml)(
Gio.DBus.system,
'org.asuslinux.Daemon',
'/org/asuslinux/Anime'
);
this.connected = true;
// currently there is no DBUS method because this can't be read from
// hardware (as to @fluke).
// https://gitlab.com/asus-linux/asusctl/-/issues/138
/*
this.asusLinuxProxy.connectSignal(
"NotifyCharge",
(proxy: any = null, name: string, data: string) => {
if (proxy) {
Log.info(`AniMe Power State has changed to ${data}% (${name}).`);
}
}
);
*/
} catch (e) {
//@ts-ignore //@ts-ignore
log(`AniMe DBus initialization failed!`, e); valueString = value.toString();
switch (parseInt(_key)) {
case 0:
this.deviceState.display_enabled = (valueString == 'true' ? true : false);
break;
case 1:
this.deviceState.display_brightness = Brightness[valueString as Brightness];
break;
case 2:
this.deviceState.builtin_anims_enabled = (valueString == 'true' ? true : false);
break;
case 3:
let anims = valueString.split(',');
this.deviceState.builtin_anims.boot = AnimBooting[anims[0] as AnimBooting];
this.deviceState.builtin_anims.awake = AnimAwake[anims[1] as AnimAwake];
this.deviceState.builtin_anims.sleep = AnimSleeping[anims[2] as AnimSleeping];
this.deviceState.builtin_anims.shutdown = AnimShutdown[anims[3] as AnimShutdown];
break;
}
} }
} }
public getDeviceState() {
if (this.isRunning()) {
try {
let _data = this.dbus_proxy.DeviceStateSync();
if (_data.length > 0) {
this._parseDeviceState(_data);
}
} catch (e) {
//@ts-ignore
log(`Failed to fetch DeviceState!`, e);
}
}
return this.deviceState;
}
async start() {
await super.start();
this.getDeviceState();
this.dbus_proxy.connectSignal(
"NotifyDeviceState",
(proxy: any = null, name: string, data: string) => {
if (proxy) {
this._parseDeviceState(data);
//@ts-ignore
log(`NotifyDeviceState has changed to ${data}% (${name}).`);
}
}
);
}
async stop() { async stop() {
await super.stop(); await super.stop();
} }

View File

@@ -6,6 +6,7 @@ const Me = imports.misc.extensionUtils.getCurrentExtension();
import * as bios from '../bindings/platform'; import * as bios from '../bindings/platform';
import { DbusBase } from '../modules/dbus'; import { DbusBase } from '../modules/dbus';
// TODO: add callbacks for notifications
export class Platform extends DbusBase { export class Platform extends DbusBase {
bios: bios.RogBiosSupportedFunctions = asusctlGexInstance.supported.connector.supported; bios: bios.RogBiosSupportedFunctions = asusctlGexInstance.supported.connector.supported;
@@ -17,7 +18,7 @@ export class Platform extends DbusBase {
if (this.isRunning()) { if (this.isRunning()) {
try { try {
let currentState = this.dbus_proxy.PostBootSoundSync(); let currentState = this.dbus_proxy.PostBootSoundSync();
return parseInt(currentState) == 1 ? true : false; this.bios.post_sound = parseInt(currentState) == 1 ? true : false;
} catch (e) { } catch (e) {
//@ts-ignore //@ts-ignore
log(`Failed to get POST Boot Sound state!`, e); log(`Failed to get POST Boot Sound state!`, e);
@@ -40,20 +41,20 @@ export class Platform extends DbusBase {
} }
} }
public getMUX() { public getGpuMuxMode() {
if (this.isRunning()) { if (this.isRunning()) {
try { try {
let currentState = this.dbus_proxy.GpuMuxModeSync(); let currentState = this.dbus_proxy.GpuMuxModeSync();
return parseInt(currentState) == 0 ? true : false; this.bios.gpu_mux = parseInt(currentState) == 0 ? true : false;
} catch (e) { } catch (e) {
//@ts-ignore //@ts-ignore
log(`Failed to get MUX state!`, e); log(`Failed to get MUX state!`, e);
} }
} }
return this.bios.post_sound; return this.bios.gpu_mux;
} }
public setMUX(state: boolean) { public setGpuMuxMode(state: boolean) {
if (this.isRunning()) { if (this.isRunning()) {
try { try {
if (!state !== this.bios.gpu_mux) { if (!state !== this.bios.gpu_mux) {
@@ -67,11 +68,11 @@ export class Platform extends DbusBase {
} }
} }
public getOverdrive() { public getPanelOd() {
if (this.isRunning()) { if (this.isRunning()) {
try { try {
let currentState = this.dbus_proxy.PanelOverdriveSync(); let currentState = this.dbus_proxy.PanelOdSync();
return parseInt(currentState) == 1 ? true : false; this.bios.panel_overdrive = parseInt(currentState) == 1 ? true : false;
} catch (e) { } catch (e) {
//@ts-ignore //@ts-ignore
log(`Failed to get Overdrive state!`, e); log(`Failed to get Overdrive state!`, e);
@@ -80,13 +81,40 @@ export class Platform extends DbusBase {
return this.bios.panel_overdrive; return this.bios.panel_overdrive;
} }
public setOverdrive(state: boolean) { public setPanelOd(state: boolean) {
if (this.isRunning()) { if (this.isRunning()) {
try { try {
if (state !== this.bios.panel_overdrive) { if (state !== this.bios.panel_overdrive) {
this.bios.panel_overdrive = state; this.bios.panel_overdrive = state;
} }
return this.dbus_proxy.SetPanelOverdriveSync(state); return this.dbus_proxy.SetPanelOdSync(state);
} catch (e) {
//@ts-ignore
log(`Overdrive DBus set overdrive state failed!`, e);
}
}
}
public getMiniLedMode() {
if (this.isRunning()) {
try {
let currentState = this.dbus_proxy.MiniLedModeSync();
this.bios.mini_led_mode = parseInt(currentState) == 1 ? true : false;
} catch (e) {
//@ts-ignore
log(`Failed to get Overdrive state!`, e);
}
}
return this.bios.mini_led_mode;
}
public setMiniLedMode(state: boolean) {
if (this.isRunning()) {
try {
if (state !== this.bios.mini_led_mode) {
this.bios.mini_led_mode = state;
}
return this.dbus_proxy.SetMiniLedModeSync(state);
} catch (e) { } catch (e) {
//@ts-ignore //@ts-ignore
log(`Overdrive DBus set overdrive state failed!`, e); log(`Overdrive DBus set overdrive state failed!`, e);
@@ -98,57 +126,53 @@ export class Platform extends DbusBase {
try { try {
await super.start(); await super.start();
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_toggleSound) { this.bios.post_sound = this.getPostBootSound();
this.bios.post_sound = this.getPostBootSound(); this.dbus_proxy.connectSignal(
this.dbus_proxy.connectSignal( "NotifyPostBootSound",
"NotifyPostBootSound", (proxy: any = null, _name: string, data: boolean) => {
(proxy: any = null, _name: string, data: boolean) => { if (proxy) {
if (proxy) { //@ts-ignore
//@ts-ignore log(`PostBootSound changed to ${data}`);
log(`PostBootSound changed to ${data}`);
asusctlGexInstance.Platform.switchPostBootSound.setToggleState(this.bios.post_sound);
}
} }
); }
} );
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_overdrive) { this.bios.panel_overdrive = this.getPanelOd();
this.bios.panel_overdrive = this.getOverdrive(); this.dbus_proxy.connectSignal(
this.dbus_proxy.connectSignal( "NotifyPanelOd",
"NotifyPanelOverdrive", (proxy: any = null, _name: string, data: boolean) => {
(proxy: any = null, _name: string, data: boolean) => { if (proxy) {
if (proxy) { //@ts-ignore
//@ts-ignore log(`NotifyPanelOd has changed to ${data}.`);
log(`Overdrive has changed to ${data}.`);
asusctlGexInstance.Platform.overdriveSwitch.setToggleState(this.bios.panel_overdrive);
}
} }
); }
} );
if (asusctlGexInstance.supported.connector.supportedAttributes.bios_toggleMUX) { this.bios.panel_overdrive = this.getMiniLedMode();
this.bios.gpu_mux = this.getMUX(); this.dbus_proxy.connectSignal(
this.dbus_proxy.connectSignal( "NotifyMiniLedMode",
"NotifyGpuMuxMode", (proxy: any = null, _name: string, data: boolean) => {
(proxy: any = null, _name: string, data: boolean) => { if (proxy) {
if (proxy) { //@ts-ignore
//@ts-ignore log(`MiniLedMode has changed to ${data}.`);
log(`MUX has changed to ${data}.`);
asusctlGexInstance.Platform.switchMUX.setToggleState(this.bios.gpu_mux);
// Panel.Actions.notify(
// 'ASUS Notebook Control',
// `MUX Mode has chnged. Please reboot to apply the changes.`,
// 'scalable/reboot.svg',
// 'reboot'
// );
}
} }
); }
} );
this.bios.gpu_mux = this.getGpuMuxMode();
this.dbus_proxy.connectSignal(
"NotifyGpuMuxMode",
(proxy: any = null, _name: string, data: boolean) => {
if (proxy) {
//@ts-ignore
log(`MUX has changed to ${data}.`);
}
}
);
} catch (e) { } catch (e) {
//@ts-ignore //@ts-ignore
log(`Overdrive DBus init failed!`, e); log(`Platform DBus init failed!`, e);
} }
} }
@@ -156,5 +180,7 @@ export class Platform extends DbusBase {
await super.stop(); await super.stop();
this.bios.post_sound = false; this.bios.post_sound = false;
this.bios.panel_overdrive = false; this.bios.panel_overdrive = false;
this.bios.mini_led_mode = false;
this.bios.gpu_mux = false;
} }
} }

View File

@@ -19,8 +19,9 @@ import { DbusBase } from '../modules/dbus';
// return result; // return result;
// } // }
export class ChargingLimit extends DbusBase { export class Power extends DbusBase {
lastState: number = 100; chargeLimit: number = 100;
mainsOnline = false;
constructor() { constructor() {
super('org-asuslinux-power-4', '/org/asuslinux/Power'); super('org-asuslinux-power-4', '/org/asuslinux/Power');
@@ -29,21 +30,21 @@ export class ChargingLimit extends DbusBase {
public getChargingLimit() { public getChargingLimit() {
if (this.isRunning()) { if (this.isRunning()) {
try { try {
this.lastState = this.dbus_proxy.ChargeControlEndThresholdSync(); this.chargeLimit = this.dbus_proxy.ChargeControlEndThresholdSync();
} catch (e) { } catch (e) {
//@ts-ignore //@ts-ignore
log(`Failed to fetch Charging Limit!`, e); log(`Failed to fetch Charging Limit!`, e);
} }
} }
return this.lastState; return this.chargeLimit;
} }
public setChargingLimit(limit: number) { public setChargingLimit(limit: number) {
if (this.isRunning()) { if (this.isRunning()) {
try { try {
if (limit > 0 && this.lastState !== limit) { if (limit > 0 && this.chargeLimit !== limit) {
// update state // update state
this.lastState = limit; this.chargeLimit = limit;
} }
return this.dbus_proxy.SetChargeControlEndThresholdSync(limit); return this.dbus_proxy.SetChargeControlEndThresholdSync(limit);
} catch (e) { } catch (e) {
@@ -53,6 +54,18 @@ export class ChargingLimit extends DbusBase {
} }
} }
public getMainsOnline() {
if (this.isRunning()) {
try {
this.mainsOnline = this.dbus_proxy.MainsOnlineSync();
} catch (e) {
//@ts-ignore
log(`Failed to fetch MainsLonline!`, e);
}
}
return this.mainsOnline;
}
async start() { async start() {
try { try {
await super.start(); await super.start();
@@ -64,7 +77,18 @@ export class ChargingLimit extends DbusBase {
if (proxy) { if (proxy) {
//@ts-ignore //@ts-ignore
log(`Charging Limit has changed to ${data}% (${name}).`); log(`Charging Limit has changed to ${data}% (${name}).`);
this.lastState = parseInt(data); this.chargeLimit = parseInt(data);
}
}
);
this.dbus_proxy.connectSignal(
"NotifyMainsOnline",
(proxy: any = null, name: string, data: string) => {
if (proxy) {
//@ts-ignore
log(`NotifyMainsOnline has changed to ${data}% (${name}).`);
this.mainsOnline = parseInt(data) == 1 ? true : false;
} }
} }
); );

View File

@@ -3,7 +3,7 @@
"compilerOptions": { "compilerOptions": {
"target": "es2019", "target": "es2019",
// "module": "ES2015", // "module": "ES2015",
// "moduleResolution": "node", "moduleResolution": "node",
// "rootDir": "./", // "rootDir": "./",
"strict": true, "strict": true,
"outDir": "./target", "outDir": "./target",