Compare commits

...

285 Commits
v0.60 ... v0.95

Author SHA1 Message Date
Serge
bb5aeba9e7 Fix for GA402XI 2023-07-05 17:15:47 +02:00
Serge
2d4e794084 Added option to disable tablet mode switch in config 2023-07-05 14:55:52 +02:00
Serge
5f1c926527 Keyboard listener retry 2023-07-04 23:07:55 +02:00
Serge
dc40b317f8 Default temp limit 2023-07-04 16:47:44 +02:00
Serge
db595d54f6 Init Limit 2023-07-04 10:56:24 +02:00
Serge
2c317d9a18 More logs 2023-07-03 21:11:03 +02:00
Serge
1e26696eb6 Merge branch 'main' of https://github.com/seerge/g-helper 2023-07-03 20:56:16 +02:00
Serge
feff220a9b Adjust power modes only when needed 2023-07-03 20:56:14 +02:00
Serge
a05c47a05c Update README.md 2023-07-03 20:55:23 +02:00
Serge
5b08bfbe92 Merge branch 'main' of https://github.com/seerge/g-helper 2023-07-03 18:18:48 +02:00
Serge
606f43380b Minor fixes 2023-07-03 18:18:46 +02:00
Serge
657e09adb0 Update README.md 2023-07-02 21:48:59 +02:00
Serge
188c566097 Update SECURITY.md 2023-07-01 23:07:04 +02:00
Serge
828a1cd13c Update README.md 2023-07-01 20:16:12 +02:00
Serge
c69d3b7c1c Update README.md 2023-07-01 13:48:58 +02:00
Serge
767865ab19 Merge branch 'main' of https://github.com/seerge/g-helper 2023-07-01 11:46:48 +02:00
Serge
ec7350cf5c Optimized mode switch from Ultimate 2023-07-01 11:46:46 +02:00
Serge
d33813b50d Merge pull request #702 from IceStormNG/german-translation
Updated German translation
2023-06-30 15:10:33 +02:00
Carsten Braun
d803b1eede Correction to not cut off text 2023-06-30 15:06:23 +02:00
Carsten Braun
81b73517df Translated the latest changes to German 2023-06-30 14:59:56 +02:00
IceStormNG
dbbf8b4016 Merge branch 'seerge:main' into german-translation 2023-06-30 14:47:40 +02:00
Serge
c4adb1eb8b Cleanup 2023-06-30 14:30:50 +02:00
Serge
dea2b73d7f Merge branch 'main' of https://github.com/seerge/g-helper 2023-06-29 18:18:44 +02:00
Serge
3fb61d3bf1 X13 tweaks 2023-06-29 18:18:42 +02:00
Serge
b83d8d35a4 Update README.md 2023-06-28 19:25:01 +02:00
Serge
8a3708e850 Cleanup 2023-06-28 10:59:53 +02:00
Serge
0e728ccc64 Reset UV 2023-06-27 16:10:00 +02:00
Serge
1a12162ba1 Re-apply temp-limit 2023-06-27 13:42:06 +02:00
Serge
5b5cd0e97a Check for Optimus only on AMD CPU models 2023-06-26 23:29:28 +02:00
Serge
1167d6c380 GPU and Screen Controls 2023-06-26 19:27:50 +02:00
Serge
d0d44c3ef1 More cleanup 2023-06-26 16:46:15 +02:00
Serge
164d417b06 Cleanup 2023-06-25 13:58:17 +02:00
Serge
e1acea9ad9 Merge pull request #673 from marcelomijas/main
Update Spanish translation
2023-06-24 20:27:31 +02:00
Marcelo Moreno
083b74e739 Update Spanish translation
And also... I just learned how to compile with VS... so I expect less "Spanish translation fix" commits.

Little by little :')
2023-06-24 19:55:29 +02:00
Serge
1413fce8f1 Merge branch 'main' of https://github.com/seerge/g-helper 2023-06-24 16:22:45 +02:00
Serge
666dea9bfd GPU apps stopping fix 2023-06-24 16:22:43 +02:00
Serge
41bccc3a56 Update README.md 2023-06-24 15:12:33 +02:00
Serge
976ca50e50 Update README.md 2023-06-24 14:52:43 +02:00
Serge
81b6a6d61c Update README.md 2023-06-24 14:49:46 +02:00
Serge
7f6bdda39a Stop GPU apps button 2023-06-24 13:08:06 +02:00
Serge
96dc22072a UI tweaks 2023-06-24 11:32:59 +02:00
Serge
3c02d5cd95 Optimus check 2023-06-23 19:37:51 +02:00
Serge
e58a396cbd CPU power limits for old devices 2023-06-22 15:53:35 +02:00
IceStormNG
ba9a290ad0 Merge branch 'seerge:main' into german-translation 2023-06-21 20:43:58 +02:00
Serge
40ecdf0d35 Max GPU core/memory config settings 2023-06-20 16:20:14 +02:00
Serge
f31b05dcd1 Aura cleanup 2023-06-20 13:48:32 +02:00
Serge
d778838ad4 Release script 2023-06-19 16:15:33 +02:00
Serge
b177dacf8b Merge branch 'main' of https://github.com/seerge/g-helper 2023-06-19 13:53:09 +02:00
Serge
6e9cc51a5f G15 Advantage Edition TDP 2023-06-19 13:53:07 +02:00
IceStormNG
58fd6650db Merge branch 'seerge:main' into german-translation 2023-06-19 07:18:15 +02:00
Serge
e2a6b770a0 Update README.md 2023-06-18 17:32:16 +02:00
Serge
055e83e976 Default temp fix 2023-06-18 15:28:52 +02:00
Serge
40be93b60d UV/Temp reset fix 2023-06-18 15:23:29 +02:00
Serge
2c2eed4fe2 Temp limit and update checker 2023-06-18 14:59:37 +02:00
Serge
8d6b277fda Merge branch 'main' of https://github.com/seerge/g-helper 2023-06-17 13:24:16 +02:00
Serge
d3de136dd3 Exception handling 2023-06-17 12:32:58 +02:00
Serge
8e6f54e833 Update README.md 2023-06-17 10:39:06 +02:00
Serge
0b030da41b Undervolting 2023-06-17 10:32:30 +02:00
IceStormNG
4d0bc74179 Merge branch 'seerge:main' into german-translation 2023-06-16 23:15:30 +02:00
Serge
05aae069b4 Update README.md 2023-06-15 12:29:44 +02:00
Serge
28e949bee4 Power modes fix 2023-06-15 12:21:48 +02:00
Serge
9a82a54b04 Verion bump 2023-06-15 00:14:08 +02:00
Serge
8aff60546a UI Fixes 2023-06-15 00:09:00 +02:00
Serge Samusya
d5039207ec Rog Ally Aura support 2023-06-15 00:04:33 +02:00
Carsten Braun
66316d3016 Translated additional strings 2023-06-14 17:36:40 +02:00
Serge
f940d343c3 Translations update 2023-06-14 09:19:17 +02:00
Serge
1848612434 UI Tweaks 2023-06-14 09:17:45 +02:00
Serge
fe253de0e1 Merge pull request #618 from weslleykawan/patch-2
(PT-BR) Translation Update 2 (Strings.pt-br.resx)
2023-06-14 09:16:52 +02:00
Weslley K
7211fd5f22 (PT-BR) Translation Update 2 (Strings.pt-br.resx)
- Resolved previous translation issues

- Updated:
 
 <data name="AutoRefreshTooltip" xml:space="preserve">
    <value>Menor taxa de atualização quando estiver na bateria</value>
  </data>

  <data name="MinRefreshTooltip" xml:space="preserve">
    <value>Taxa de atualização à 60Hz para economizar bateria</value>
  </data>

  <data name="MaxRefreshTooltip" xml:space="preserve">
    <value>Taxa de atualização máxima e menor latência</value>
  </data>

Please offer a version so I can test if everything is working as it should.

I want to be part of the PT-BR translation of this project from now on.
2023-06-13 20:33:58 -03:00
Serge
c1a8eb12f9 Merge pull request #616 from weslleykawan/patch-1
(PT-BR) Translation update (Strings.pt-br.resx)
2023-06-13 16:51:24 +02:00
Weslley K
0477d03ecc (PT-BR) Translation update (Strings.pt-br.resx)
Added/updated strings:

    <data name="VolumeDown" xml:space="preserve">
    <value>Abaixar o volume</value>
  </data>

  <data name="VolumeUp" xml:space="preserve">
    <value>Aumentar o volume</value>
  </data>

    <data name="VolumeMute" xml:space="preserve">
    <value>Silenciar microfone</value>
  </data>

  <data name="WindowTop" xml:space="preserve">
    <value>Manter a janela do aplicativo sempre no topo</value>
  </data>

   <data name="Updates" xml:space="preserve">
    <value>Atualizações</value>
  </data>

    <data name="FnLock" xml:space="preserve">
    <value>Processar teclas de atalho Fn+F sem pressionar Fn</value>
  </data>

   <data name="KillGpuApps" xml:space="preserve">
    <value>Parar todos os aplicativos que usam a GPU ao alternar para o modo Eco</value>
  </data>

  <data name="Boot" xml:space="preserve">
    <value>Ao ligar</value>
  </data>

  <data name="Brightness" xml:space="preserve">
    <value>Nível do brilho</value>
  </data>

  <data name="BacklightTimeout" xml:space="preserve">
    <value>Tempo limite da iluminação na bateria (em segundos)</value>
  </data>

    <data name="BacklightTimeoutPlugged" xml:space="preserve">
    <value>Tempo limite da iluminação carregando (0 - sempre ligado)</value>
  </data>

  <data name="LaptopBacklight" xml:space="preserve">
    <value>Configurações de iluminação</value>
  </data>

  <data name="ApplyWindowsPowerPlan" xml:space="preserve">
    <value>Ajuste automático dos modos de energia do Windows</value>
  </data>

    <data name="AsusServicesRunning" xml:space="preserve">
    <value>Serviços da Asus em execução</value>
  </data>

<data name="Start" xml:space="preserve">
    <value>Iniciar</value>
  </data>
  <data name="StartingServices" xml:space="preserve">
    <value>Iniciando os serviços</value>
  </data>
  <data name="StartupError" xml:space="preserve">
    <value>Erro de inicialização</value>
  </data>
  <data name="Stop" xml:space="preserve">
    <value>Parar</value>
  </data>
  <data name="StoppingServices" xml:space="preserve">
    <value>Parando os serviços</value>
  </data>
2023-06-13 10:30:31 -03:00
Serge
e923d82732 Update README.md 2023-06-13 12:34:11 +02:00
Serge
6558d66e8d Update README.md 2023-06-13 12:21:21 +02:00
Serge
ec8605dfe6 UI Fixes 2023-06-13 00:54:11 +02:00
Serge
ac462b628f Driver updater fix, new turbo boost modes 2023-06-12 19:07:57 +02:00
Serge
1cd9c30c4a UI Tweaks 2023-06-12 14:41:47 +02:00
Serge
c575b17aba UI Tweaks 2023-06-11 23:32:13 +02:00
Serge
d2e0e6f51e Colors for custom modes 2023-06-11 17:09:17 +02:00
Serge
0dae1c9115 Custom mode renaming 2023-06-11 14:50:01 +02:00
Serge
16e085d9f1 Custom modes 2023-06-11 00:27:58 +02:00
Serge
6b04ffa172 Version bump 2023-06-09 21:55:47 +02:00
Serge
15e4310016 Clock fix 2023-06-09 21:53:31 +02:00
Serge
3abe924525 Merge branch 'main' of https://github.com/seerge/g-helper 2023-06-09 21:29:02 +02:00
Serge
691f187b7d Improved backlight sync with optimization service 2023-06-09 21:28:59 +02:00
Serge
8e4c0dada7 Update README.md 2023-06-09 15:44:13 +02:00
Serge
f535818fb0 Update README.md 2023-06-09 14:14:21 +02:00
Serge
ce75d2c778 Update README.md 2023-06-09 12:45:08 +02:00
Serge
c755213472 Merge pull request #573 from hellotale/patch-2
Update and fix Korean translation
2023-06-08 14:57:01 +02:00
hellotale
60e8712131 Update and rename Strings.kr.resx to Strings.ko.resx 2023-06-08 21:30:24 +09:00
Serge
2c817b46ef Merge branch 'main' of https://github.com/seerge/g-helper 2023-06-08 13:20:28 +02:00
Serge
e16f612311 Driver updater fix 2023-06-08 13:20:26 +02:00
Serge
4ce4b4bbf7 Update README.md 2023-06-08 12:03:13 +02:00
Serge
f9303ced8a Merge pull request #570 from marcelomijas/main
Spanish translation fix for "Updates" + more
2023-06-08 11:55:28 +02:00
Serge
f000a03395 Update README.md 2023-06-08 11:51:30 +02:00
Marcelo Moreno
90205e9231 Start/stop Spanish translation 2023-06-08 11:51:26 +02:00
Marcelo Moreno
e65270c961 Spanish translation fix for "Updates" 2023-06-08 11:34:13 +02:00
Serge
306dfe2bd7 XGM button fix 2023-06-08 11:17:06 +02:00
Serge
ca7dfff357 Merge branch 'main' of https://github.com/seerge/g-helper 2023-06-07 22:52:05 +02:00
Serge
59288b9422 Integrated debloater 2023-06-07 22:52:04 +02:00
Serge
46ff8deb44 Merge pull request #558 from marcelomijas/main
Update Spanish translation
2023-06-07 22:21:51 +02:00
Marcelo Moreno
e6e8877531 Update Spanish translation 2023-06-07 21:48:57 +02:00
Serge
b13306b989 Added brightness control to M-hotkeys 2023-06-07 16:34:40 +02:00
Serge
838dc039ac Merge branch 'main' of https://github.com/seerge/g-helper 2023-06-07 15:16:34 +02:00
Serge
0702f95e0c Driver Updater improvements 2023-06-07 15:16:32 +02:00
Serge
f42fcf2f73 Merge pull request #554 from hellotale/patch-1
Add Korean translation
2023-06-07 12:07:15 +02:00
hellotale
6a7e1ddaa3 Add Korean translation 2023-06-07 16:25:57 +09:00
Serge
57ffcb8c7f Added manual mode config flag 2023-06-06 22:54:08 +02:00
Serge
5425bd0128 Color Profiles 2023-06-06 22:06:45 +02:00
Serge
328cd8f9f1 Minor refactoring 2023-06-06 13:17:13 +02:00
Serge
38739ca8f6 CPU power limits 2023-06-06 11:38:11 +02:00
Serge
a3e235e886 Added PPT fix for M16, G17 (2023) and F15 (2022) 2023-06-06 10:59:49 +02:00
Serge
678f4b0eb7 UI tweaks 2023-06-05 22:32:50 +02:00
Serge
4bbfbd0382 Driver Updates 2023-06-05 17:31:59 +02:00
Serge
4c8291c74b S15 fix 2023-06-05 11:49:56 +02:00
Serge
e9060ad8c0 Update README.md 2023-06-04 23:29:42 +02:00
Serge
f26585e73c Version bump 2023-06-04 23:21:29 +02:00
Serge
9f7da4c20a GPU Section UI fixes 2023-06-04 23:20:37 +02:00
Serge
eff45c1485 Curve editor fix 2023-06-04 23:09:56 +02:00
Serge
be6e5e8f23 Varibright control 2023-06-04 17:21:31 +02:00
Serge
17083eef21 Check for optimization service before setting backlight 2023-06-04 12:18:51 +02:00
Serge
d5b098335b Kill GPU apps for AMD, Optimus fix 2023-06-04 01:25:39 +02:00
Serge
acb2efdd00 Merge branch 'main' of https://github.com/seerge/g-helper 2023-06-03 22:17:48 +02:00
Serge
92fa210898 UI tweaks 2023-06-03 22:17:46 +02:00
Serge
6dd4e07efe Merge pull request #527 from marcelomijas/main
Update Spanish translation
2023-06-03 18:07:41 +02:00
Marcelo Moreno
ae6972db76 Update Spanish translation
- Translation for the new Fn+F without Fn feature.
- Translation for the Fn-Lock toggle.
- Update backlight timeout translation.
2023-06-03 18:03:42 +02:00
Serge
b3f7b1027f Merge pull request #524 from lswlc33/patch-3
upadte translate
2023-06-03 14:31:22 +02:00
雪中明月
8929daa604 upadte translate 2023-06-03 20:24:13 +08:00
Serge
eb522214f0 UI Tweaks 2023-06-02 21:25:18 +02:00
Serge
1222377c33 Update README.zh-CN.md 2023-06-02 21:14:32 +02:00
Serge
933f07d666 Update README.md 2023-06-02 21:14:02 +02:00
Serge
8f95f6a1bb Update README.md 2023-06-02 21:13:12 +02:00
Serge
f2c32b2e9a Add files via upload 2023-06-02 21:11:05 +02:00
Serge
ddb591b79a Backlight fixes 2023-06-02 14:06:12 +02:00
Serge
65b4192393 Backlight fixes 2023-06-02 13:37:43 +02:00
Serge
846cc6e867 Autoupdate fix 2023-06-02 13:16:09 +02:00
Serge
ddac5a23be Merge branch 'main' of https://github.com/seerge/g-helper 2023-06-02 12:57:11 +02:00
Serge
4f6db4ae0a Save backlight levels per battery / power 2023-06-02 12:57:09 +02:00
Serge
14dd96dee3 Merge pull request #507 from Hoangdus/main
Improve Vietnamese Translation.
2023-06-02 11:54:27 +02:00
Hoangdus
79ff24bbb7 Fix a small translation error 2023-06-02 03:50:19 +07:00
Hoangdus
b715bd0391 Improve Vietnamese Translation 2023-06-02 03:10:36 +07:00
Serge
b97a06eb56 Merge branch 'main' of https://github.com/seerge/g-helper 2023-06-01 20:07:53 +02:00
Serge
e69845e858 Added FN+C binding for Fn-Lock 2023-06-01 20:07:51 +02:00
Serge
b832ba6e8b Update README.md 2023-06-01 17:34:39 +02:00
Serge
314d25c751 Backlight fix 2023-06-01 15:24:51 +02:00
Serge
b52163949c Auto brightness tweak 2023-06-01 15:18:41 +02:00
Serge
f0ee2b8aac Fn-lock support for optimization service 2023-06-01 14:32:29 +02:00
Serge
1603f625ed FN-Lock support for case when optimization service is running 2023-06-01 14:19:43 +02:00
Serge
8f66006791 Fn-lock tweaks 2023-06-01 12:52:35 +02:00
Serge
39387041fe UI fixes 2023-05-31 17:41:24 +02:00
Serge
400b2cd6cb FN-lock 2023-05-31 17:33:53 +02:00
Serge
b20442e61f Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-31 17:23:54 +02:00
Serge
6d219511fc FN-Lock preparations 2023-05-31 17:23:52 +02:00
Serge
2282820453 Merge pull request #491 from marcelomijas/main
Spanish translation small fix
2023-05-31 11:51:11 +02:00
Marcelo Moreno
d4fcfe8895 Spanish translation small fix
Added translations for keyboard backlight timeout but they were too large... This is a shorter translation.
2023-05-31 11:36:13 +02:00
Serge
8eb923a703 PPT labels 2023-05-30 22:43:42 +02:00
Serge
59548be543 PPT UI tweaks 2023-05-30 21:35:21 +02:00
Serge
1596ce84e8 PPT labels fixes 2023-05-30 18:58:44 +02:00
Serge
f670b9e0dc Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-30 14:55:52 +02:00
Serge
52c2987c88 UI tweaks 2023-05-30 14:55:50 +02:00
Serge
c9aa910035 Merge pull request #485 from marcelomijas/main
Update Spanish translation
2023-05-30 12:19:58 +02:00
Marcelo Moreno
22f648a23f Update Spanish translation 2023-05-30 12:18:31 +02:00
Serge
9255a8554d Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-30 00:33:27 +02:00
Serge
859f4f55c3 GPU sliders fix 2023-05-30 00:33:24 +02:00
Serge
7e3872939b Update README.md 2023-05-29 23:54:59 +02:00
Serge
2556583451 Update README.md 2023-05-29 23:53:19 +02:00
Serge
20e7d220e5 Added APU slider 2023-05-29 22:07:08 +02:00
Serge
2f5543ce84 Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-29 19:39:00 +02:00
Serge
4c55e16f2e UI tweaks 2023-05-29 19:38:57 +02:00
Serge
30544e74d7 Update README.md 2023-05-29 19:18:25 +02:00
Serge
f5925accb3 Merge pull request #475 from MDowski/patch-2
Update to Polish translation
2023-05-29 15:31:29 +02:00
MD
842ea2a92d Update to Polish translation
Tweaks in declination and words shortening.
2023-05-29 14:58:37 +02:00
Serge
1ca97bd3f4 Updated translations 2023-05-29 14:36:55 +02:00
Serge
8a1dd9f137 Bumped version number 2023-05-29 13:15:54 +02:00
Serge
325f16cf55 Added optimization service to debloat.bat 2023-05-29 13:15:23 +02:00
Serge
42cc1bdb98 Added option to stop all GPU apps before setting Eco 2023-05-29 12:16:19 +02:00
Serge
83a2d1dc9f Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-28 21:43:26 +02:00
Serge
3aae223b15 Added Ctr+Shif+F12 binding to toggle app window 2023-05-28 21:43:24 +02:00
Serge
b22d2f8ceb Update README.md 2023-05-28 21:26:05 +02:00
Serge
2041861a14 Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-28 16:09:46 +02:00
Serge
dfc3c0e515 UI tweaks 2023-05-28 16:09:44 +02:00
Serge
796ec34284 Update README.md 2023-05-28 14:06:12 +02:00
Serge
50894a59d3 USB adjustment 2023-05-28 12:15:43 +02:00
Serge
1472004d4b Backlight timeouts 2023-05-28 12:02:29 +02:00
Serge
36c42ed05f Merge pull request #468 from etylix/main
Add Vietnamese translations
2023-05-28 11:45:04 +02:00
Hoang Pham Anh Duy
66220351f1 Add Vietnamese translations 2023-05-28 16:40:49 +07:00
Serge
8f2c8842e0 Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-27 22:44:55 +02:00
Serge
1cda822820 Backlight control fix 2023-05-27 22:44:54 +02:00
Serge
2afba74dd5 Update README.md 2023-05-26 11:52:29 +02:00
Serge
e69f9d1014 Update README.md 2023-05-26 11:48:13 +02:00
Serge
47d96aca61 Keybinding fix 2023-05-25 13:30:33 +02:00
Serge
f36fb6ca55 Hide GPU fans from UI if they don't exist in system 2023-05-24 23:47:08 +02:00
Serge
e765b4f037 Tweaks and fixes 2023-05-24 14:34:43 +02:00
Serge
f395c706f6 UI tweaks 2023-05-23 20:49:56 +02:00
Serge
444fdcdd97 Backlight fix 2023-05-23 15:27:00 +02:00
Serge
b874900393 French language fixes 2023-05-23 11:14:03 +02:00
Serge
05aad0f1ad Matrix tweaks 2023-05-23 10:58:27 +02:00
Serge
a34cc1cb03 Animatrix clock fix 2023-05-22 21:57:21 +02:00
Serge
8c557344db Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-22 17:57:08 +02:00
Serge
5b2a4cb065 UI tweaks 2023-05-22 17:57:06 +02:00
Serge
51bcad8bbe Merge pull request #434 from marcelomijas/main
Spanish translation of new key functions
2023-05-22 16:26:13 +02:00
Marcelo Moreno
125aa44e6c Spanish translation of new key functions 2023-05-22 16:21:58 +02:00
Serge
9e6ca7c2e2 Bumped version to 0.67 2023-05-22 16:15:24 +02:00
Serge
252cc9d868 Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-22 13:31:03 +02:00
Serge
0b03b62a2d Extended support for Z13 external keyboard 2023-05-22 13:31:01 +02:00
Serge
ff7a5463d6 Update README.md 2023-05-22 11:44:10 +02:00
Serge
5134aaca9d Native brightness OSD 2023-05-22 11:18:57 +02:00
Serge
2a5c2e02ac Anime matrix fix 2023-05-21 21:23:55 +02:00
Serge
80e3971dad m1,m2 bindings 2023-05-21 20:44:04 +02:00
Serge
ac60986646 Sleep Fix 2023-05-21 19:19:26 +02:00
Serge
1e0169a71d Added M1/M2 keys and keyboard init 2023-05-21 19:01:43 +02:00
Serge
e0346a8af8 UI Tweaks 2023-05-21 18:06:41 +02:00
Serge
4ee97fdbc4 XGM Fixes 2023-05-21 17:42:15 +02:00
Serge
34075b67d4 Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-21 12:27:54 +02:00
Serge
4ed9675d99 Refactoring 2023-05-21 12:27:52 +02:00
Serge
af3538e105 Update README.md 2023-05-21 00:24:57 +02:00
Serge
d818405e04 Bumped version to 0.65 2023-05-20 23:14:15 +02:00
Serge
9794229f3f Extra icons for OSD 2023-05-20 22:59:17 +02:00
Serge
9f56959c67 Some OSD notifications 2023-05-20 21:51:02 +02:00
Serge
09e6676b7c Merge pull request #418 from marcelomijas/main
Update Spanish translation
2023-05-20 20:51:57 +02:00
Serge
6adb2e2fcf Keyboard Reading 2023-05-20 20:50:58 +02:00
Marcelo Moreno
08cc4409a9 Update Spanish translation 2023-05-20 20:37:54 +02:00
Serge
1ac0f2be08 Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-20 14:28:08 +02:00
Serge
05e66d3b95 Tweaks 2023-05-20 14:28:05 +02:00
Serge
0f8f1e9ce5 Merge pull request #300 from tbateson/main
Add GitHub workflows
2023-05-20 11:51:42 +02:00
Thomas Bateson
d37b46c588 Add GitHub workflows 2023-05-19 13:32:31 -05:00
Serge
020a7d074f Some renamings 2023-05-19 19:14:07 +02:00
Serge
7eb7cc9f78 UI tweaks 2023-05-19 16:09:27 +02:00
Serge
38d60e88ea Fixed anime matrix crash 2023-05-19 13:46:49 +02:00
Serge
0cc16765b6 Update README.md 2023-05-19 11:27:24 +02:00
Serge
96f705806b Update README.md 2023-05-19 11:17:27 +02:00
Serge
d1cceda2ab UI Tweaks 2023-05-19 10:40:16 +02:00
Serge
381b4dd3e8 Merge pull request #409 from TomBonnot/main
Adding French and Português Version
2023-05-19 00:16:11 +02:00
Tom Bonnot
a99dcbf445 Last changes on portuguese-brazilian version + deleting .idea files 2023-05-18 18:12:44 -04:00
Tom Bonnot
4751383a3a Saving progress on pt-br translation 2023-05-18 15:50:32 -04:00
Serge
06320afcb3 Audio visualizer 2023-05-18 18:21:09 +02:00
Serge
0eb6209eda Matrix audio visualizer 2023-05-18 17:42:19 +02:00
Tom Bonnot
a342cab9a6 Final version for French translation 2023-05-18 11:40:02 -04:00
Tom Bonnot
12c6482f61 Adding pt-br and completion of fr version (might need some corrections) 2023-05-18 10:30:05 -04:00
Tom Bonnot
20933bfd8d First commit - French version 2023-05-18 09:51:30 -04:00
Serge
c66c8e9030 Custom keybinding for mode toggle 2023-05-17 20:33:41 +02:00
Serge
14b677514b Update README.md 2023-05-17 17:17:13 +02:00
Serge
ce266ffe07 Merge pull request #402 from IceStormNG/german-translation
German translation
2023-05-17 16:51:04 +02:00
Serge
f29410fa2a Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-17 14:52:09 +02:00
Serge
7117b58746 ACPI events listener 2023-05-17 14:52:06 +02:00
Carsten Braun
0456fa013c Improbed a few translations and fixed typos. 2023-05-17 13:11:11 +02:00
Carsten Braun
6a4aa4e138 Localize fan speed labels in the main window 2023-05-17 10:47:41 +02:00
IceStormNG
d75067b40c Merge branch 'seerge:main' into german-translation 2023-05-17 10:39:02 +02:00
Carsten Braun
de45038911 Translated the App to German. Added a few additional resources for localization 2023-05-16 16:20:00 +02:00
Serge
e23c727e79 Update README.md 2023-05-16 15:44:30 +02:00
Serge
2f2c534278 Merge pull request #394 from lswlc33/main
Update Strings.zh-CN.resx
2023-05-16 15:21:34 +02:00
Serge
bdbec79aba UI tweaks 2023-05-16 15:19:53 +02:00
雪中明月
e3d0a04fa4 Update Strings.zh-CN.resx 2023-05-16 21:12:58 +08:00
Serge
4dd7d41cf4 Merge pull request #392 from IceStormNG/windows-power-plan-changes-optional
Windows power plan changes optional
2023-05-16 14:53:58 +02:00
Carsten Braun
8370217cef This is not a perf config but a regular config value. 2023-05-16 13:34:40 +02:00
Carsten Braun
63c1829edd We can reference the checkbox directly 2023-05-16 13:34:26 +02:00
Carsten Braun
69e5a0448e Accomodate for non-exitent settings value 2023-05-16 13:30:08 +02:00
Carsten Braun
b74b9ae257 Fix nullability 2023-05-16 13:29:48 +02:00
Carsten Braun
71e007d8ad Fixed UI that VS Forms Designer broke 2023-05-16 13:29:31 +02:00
Carsten Braun
6896166c3c Fixed French translation value 2023-05-16 12:36:26 +02:00
Carsten Braun
fd89d9c13a Changed string to "Power Mode" instead of "power plan" 2023-05-16 12:33:15 +02:00
Carsten Braun
8bec153da8 Fixed localization key for french 2023-05-16 12:30:57 +02:00
Carsten Braun
7d968f5f08 Do not set default value. 2023-05-16 12:24:06 +02:00
Carsten Braun
ac5fc3f96e Revert "Revert "Adjustment of Windows Power Overlay is now optional""
This reverts commit 8804d19567.
2023-05-16 12:21:28 +02:00
Serge
8590d0301a Merge pull request #391 from seerge/revert-385-windows-power-plan-changes-optional
Revert "Adjustment of Windows Power Overlay is now optional"
2023-05-16 11:39:41 +02:00
Serge
8804d19567 Revert "Adjustment of Windows Power Overlay is now optional" 2023-05-16 11:38:17 +02:00
Serge
57ce0631a3 Merge pull request #385 from IceStormNG/windows-power-plan-changes-optional
Adjustment of Windows Power Overlay is now optional
2023-05-16 11:30:41 +02:00
Carsten Braun
b796f9f9d4 Moved checkbox to 2023-05-16 10:41:02 +02:00
Serge
f39563fcdf Added touchpad toggle for tablet mode on x13/x16 2023-05-15 23:59:21 +02:00
Serge
853d0c231d Auto update 2023-05-15 22:23:16 +02:00
Serge
df3324d641 Auto update 2023-05-15 22:21:41 +02:00
Serge
75c90ee155 Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-15 22:11:29 +02:00
Serge
4015e0a7f7 Added auto-update checker 2023-05-15 22:11:27 +02:00
Carsten Braun
2a82e41894 Adjustment of Windows Power Overlay is now optional 2023-05-15 13:23:20 +02:00
Serge
a5541dfe10 Update README.md 2023-05-14 19:52:02 +02:00
Serge
fd3a139c47 Aura tweaks 2023-05-14 10:28:48 +02:00
Serge
608b8571d4 Fix for turkish keyboard, tweak for default fan curves 2023-05-13 22:13:00 +02:00
Serge
82a39bcfa1 Merge pull request #375 from IceStormNG/animematrix-for-GU604
Supports AniMeMatrix for Zephyrus M16 2023 (GU604)
2023-05-13 18:24:37 +02:00
Carsten Braun
f9ccd92dc6 Supports AniMeMatrix for Zephyrus M16 2023 (GU604) 2023-05-13 18:10:18 +02:00
Serge
1fadc6c31e Hotfix for possible crash 2023-05-13 09:43:26 +02:00
Serge
0b7dd42a5d UI tweak 2023-05-12 17:21:04 +02:00
Serge
51cd700e25 Improved GPU restart 2023-05-12 15:51:57 +02:00
Serge
7484253007 Merge branch 'main' of https://github.com/seerge/g-helper 2023-05-12 14:06:19 +02:00
Serge
f5cf768017 Display workaround 2023-05-12 14:06:15 +02:00
Serge
ca57669596 NV Clocks tweaks 2023-05-11 19:38:53 +02:00
Serge
35f1a3a25b Clock tweak 2023-05-11 11:18:42 +02:00
497 changed files with 14864 additions and 45039 deletions

4
.github/SECURITY.md vendored
View File

@@ -4,8 +4,8 @@
| Version | Supported |
| ------- | ------------------ |
| 0.25+ | :white_check_mark: |
| < 0.24 | :x: |
| 0.89+ | :white_check_mark: |
| < 0.89 | :x: |
## Reporting a Vulnerability

25
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,25 @@
name: Build
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: windows-2022
steps:
- uses: actions/checkout@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
7.0.x
- name: Build
run: |
dotnet build app/GHelper.sln

28
.github/workflows/codeql.yml vendored Normal file
View File

@@ -0,0 +1,28 @@
name: CodeQL
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
- cron: '34 18 * * 3'
permissions:
actions: read
contents: read
security-events: write
jobs:
codeql:
runs-on: windows-2022
steps:
- uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: c#
- name: Autobuild
uses: github/codeql-action/autobuild@v2
- name: Analyze
uses: github/codeql-action/analyze@v2

28
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,28 @@
name: Release
on:
release:
types: [ published ]
permissions:
contents: write
jobs:
release:
runs-on: windows-2022
steps:
- uses: actions/checkout@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
7.0.x
- name: Publish
run: |
dotnet publish app/GHelper.sln --configuration Release --runtime win-x64 -p:PublishSingleFile=true --no-self-contained
powershell Compress-Archive app/bin/x64/Release/net7.0-windows8.0/win-x64/publish/* GHelper.zip
- name: Upload
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release upload ${{ github.ref_name }} GHelper.zip

View File

@@ -0,0 +1,348 @@
using NAudio.CoreAudioApi;
using NAudio.Wave;
using Starlight.AnimeMatrix;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.Timers;
namespace GHelper.AnimeMatrix
{
public class AniMatrixControl
{
SettingsForm settings;
System.Timers.Timer matrixTimer = default!;
AnimeMatrixDevice? mat;
double[]? AudioValues;
WasapiCapture? AudioDevice;
public bool IsValid => mat != null;
private long lastPresent;
private List<double> maxes = new List<double>();
public AniMatrixControl(SettingsForm settingsForm)
{
settings = settingsForm;
try
{
mat = new AnimeMatrixDevice();
Task.Run(mat.WakeUp);
matrixTimer = new System.Timers.Timer(100);
matrixTimer.Elapsed += MatrixTimer_Elapsed;
}
catch
{
mat = null;
}
}
public void SetMatrix()
{
if (!IsValid) return;
int brightness = AppConfig.Get("matrix_brightness");
int running = AppConfig.Get("matrix_running");
bool auto = AppConfig.Is("matrix_auto");
if (brightness < 0) brightness = 0;
if (running < 0) running = 0;
BuiltInAnimation animation = new BuiltInAnimation(
(BuiltInAnimation.Running)running,
BuiltInAnimation.Sleeping.Starfield,
BuiltInAnimation.Shutdown.SeeYa,
BuiltInAnimation.Startup.StaticEmergence
);
StopMatrixTimer();
StopMatrixAudio();
mat.SetProvider();
if (brightness == 0 || (auto && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online))
{
mat.SetDisplayState(false);
Logger.WriteLine("Matrix Off");
}
else
{
mat.SetDisplayState(true);
mat.SetBrightness((BrightnessMode)brightness);
switch (running)
{
case 2:
SetMatrixPicture(AppConfig.GetString("matrix_picture"));
break;
case 3:
SetMatrixClock();
break;
case 4:
SetMatrixAudio();
break;
default:
mat.SetBuiltInAnimation(true, animation);
Logger.WriteLine("Matrix builtin " + animation.AsByte);
break;
}
//mat.SetBrightness((BrightnessMode)brightness);
}
}
private void StartMatrixTimer(int interval = 100)
{
matrixTimer.Interval = interval;
matrixTimer.Start();
}
private void StopMatrixTimer()
{
matrixTimer.Stop();
}
private void MatrixTimer_Elapsed(object? sender, ElapsedEventArgs e)
{
//if (!IsValid) return;
switch (AppConfig.Get("matrix_running"))
{
case 2:
mat.PresentNextFrame();
break;
case 3:
mat.PresentClock();
break;
}
}
public void SetMatrixClock()
{
mat.SetBuiltInAnimation(false);
StartMatrixTimer(1000);
Logger.WriteLine("Matrix Clock");
}
public void Dispose()
{
StopMatrixAudio();
}
void StopMatrixAudio()
{
if (AudioDevice is not null)
{
try
{
AudioDevice.StopRecording();
AudioDevice.Dispose();
}
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
}
}
}
void SetMatrixAudio()
{
if (!IsValid) return;
mat.SetBuiltInAnimation(false);
StopMatrixTimer();
StopMatrixAudio();
try
{
using (var enumerator = new MMDeviceEnumerator())
using (MMDevice device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console))
{
AudioDevice = new WasapiLoopbackCapture(device);
WaveFormat fmt = AudioDevice.WaveFormat;
AudioValues = new double[fmt.SampleRate / 1000];
AudioDevice.DataAvailable += WaveIn_DataAvailable;
AudioDevice.StartRecording();
Logger.WriteLine("Matrix Audio");
}
}
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
}
}
private void WaveIn_DataAvailable(object? sender, WaveInEventArgs e)
{
int bytesPerSamplePerChannel = AudioDevice.WaveFormat.BitsPerSample / 8;
int bytesPerSample = bytesPerSamplePerChannel * AudioDevice.WaveFormat.Channels;
int bufferSampleCount = e.Buffer.Length / bytesPerSample;
if (bufferSampleCount >= AudioValues.Length)
{
bufferSampleCount = AudioValues.Length;
}
if (bytesPerSamplePerChannel == 2 && AudioDevice.WaveFormat.Encoding == WaveFormatEncoding.Pcm)
{
for (int i = 0; i < bufferSampleCount; i++)
AudioValues[i] = BitConverter.ToInt16(e.Buffer, i * bytesPerSample);
}
else if (bytesPerSamplePerChannel == 4 && AudioDevice.WaveFormat.Encoding == WaveFormatEncoding.Pcm)
{
for (int i = 0; i < bufferSampleCount; i++)
AudioValues[i] = BitConverter.ToInt32(e.Buffer, i * bytesPerSample);
}
else if (bytesPerSamplePerChannel == 4 && AudioDevice.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat)
{
for (int i = 0; i < bufferSampleCount; i++)
AudioValues[i] = BitConverter.ToSingle(e.Buffer, i * bytesPerSample);
}
double[] paddedAudio = FftSharp.Pad.ZeroPad(AudioValues);
double[] fftMag = FftSharp.Transform.FFTmagnitude(paddedAudio);
PresentAudio(fftMag);
}
private void DrawBar(int pos, double h)
{
int dx = pos * 2;
int dy = 20;
byte color;
for (int y = 0; y < h - (h % 2); y++)
for (int x = 0; x < 2 - (y % 2); x++)
{
//color = (byte)(Math.Min(1,(h - y - 2)*2) * 255);
mat.SetLedPlanar(x + dx, dy + y, (byte)(h * 255 / 30));
mat.SetLedPlanar(x + dx, dy - y, 255);
}
}
void PresentAudio(double[] audio)
{
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastPresent) < 70) return;
lastPresent = DateTimeOffset.Now.ToUnixTimeMilliseconds();
mat.Clear();
int size = 20;
double[] bars = new double[size];
double max = 2, maxAverage;
for (int i = 0; i < size; i++)
{
bars[i] = Math.Sqrt(audio[i] * 10000);
if (bars[i] > max) max = bars[i];
}
maxes.Add(max);
if (maxes.Count > 20) maxes.RemoveAt(0);
maxAverage = maxes.Average();
for (int i = 0; i < size; i++) DrawBar(20 - i, bars[i] * 20 / maxAverage);
mat.Present();
}
public void OpenMatrixPicture()
{
string fileName = null;
Thread t = new Thread(() =>
{
OpenFileDialog of = new OpenFileDialog();
of.Filter = "Image Files (*.bmp;*.jpg;*.jpeg,*.png,*.gif)|*.BMP;*.JPG;*.JPEG;*.PNG;*.GIF";
if (of.ShowDialog() == DialogResult.OK)
{
fileName = of.FileName;
}
return;
});
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
if (fileName is not null)
{
AppConfig.Set("matrix_picture", fileName);
AppConfig.Set("matrix_running", 2);
SetMatrixPicture(fileName);
settings.SetMatrixRunning(2);
}
}
public void SetMatrixPicture(string fileName)
{
if (!IsValid) return;
StopMatrixTimer();
Image image;
try
{
using (var fs = new FileStream(fileName, FileMode.Open))
{
var ms = new MemoryStream();
fs.CopyTo(ms);
ms.Position = 0;
image = Image.FromStream(ms);
}
}
catch
{
Debug.WriteLine("Error loading picture");
return;
}
mat.SetBuiltInAnimation(false);
mat.ClearFrames();
FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]);
int frameCount = image.GetFrameCount(dimension);
if (frameCount > 1)
{
for (int i = 0; i < frameCount; i++)
{
image.SelectActiveFrame(dimension, i);
mat.GenerateFrame(image);
mat.AddFrame();
}
StartMatrixTimer();
Logger.WriteLine("Matrix GIF " + fileName);
}
else
{
mat.GenerateFrame(image);
mat.Present();
Logger.WriteLine("Matrix " + fileName);
}
}
}
}

View File

@@ -1,7 +1,8 @@
// Source thanks to https://github.com/vddCore/Starlight with some adjustments from me
using Starlight.Communication;
using GHelper.AnimeMatrix.Communication;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Globalization;
using System.Management;
using System.Text;
@@ -61,7 +62,8 @@ namespace Starlight.AnimeMatrix
public enum AnimeType
{
GA401,
GA402
GA402,
GU604
}
@@ -88,12 +90,15 @@ namespace Starlight.AnimeMatrix
//public int FullEvenRows = -1;
public int dx = 0;
//Shifts the whole frame to the left or right to align with the diagonal cut
public int frameShiftX = 0;
public int MaxColumns = 34;
private int frameIndex = 0;
private static AnimeType _model = AnimeType.GA402;
public AnimeMatrixDevice()
: base(0x0B05, 0x193B, 640)
{
@@ -112,6 +117,16 @@ namespace Starlight.AnimeMatrix
UpdatePageLength = 410;
}
if (model.Contains("GU604"))
{
_model = AnimeType.GU604;
MaxColumns = 39;
MaxRows = 92;
LedCount = 1711;
frameShiftX = -5;
UpdatePageLength = 630;
}
_displayBuffer = new byte[LedCount];
@@ -173,6 +188,9 @@ namespace Starlight.AnimeMatrix
{
return (y + 1) / 2 - 3;
}
case AnimeType.GU604:
return (int)Math.Ceiling(Math.Max(0, y - 9) / 2F);
default:
return (int)Math.Ceiling(Math.Max(0, y - 11) / 2F);
}
@@ -184,6 +202,8 @@ namespace Starlight.AnimeMatrix
{
case AnimeType.GA401:
return 33;
case AnimeType.GU604:
return 39;
default:
return 34;
}
@@ -226,7 +246,7 @@ namespace Starlight.AnimeMatrix
if (!IsRowInRange(y)) return;
if (x >= FirstX(y) && x < Width(y))
SetLedLinear(RowToLinearAddress(y) - FirstX(y) + x + dx, value);
SetLedLinear(RowToLinearAddress(y) - FirstX(y) + x + dx + frameShiftX, value);
}
public void WakeUp()
@@ -325,13 +345,21 @@ namespace Starlight.AnimeMatrix
public void PresentClock()
{
int second = DateTime.Now.Second;
string time;
if (CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern.Contains("H"))
PresentTextDiagonal(DateTime.Now.ToString("H" + ((second % 2 == 0) ? ":" : " ") + "mm"));
time = DateTime.Now.ToString("H" + ((second % 2 == 0) ? ":" : " ") + "mm");
else
PresentTextDiagonal(DateTime.Now.ToString("h" + ((second % 2 == 0) ? ":" : " ") + "mmtt"));
time = DateTime.Now.ToString("h" + ((second % 2 == 0) ? ":" : " ") + "mmtt");
if (_model == AnimeType.GA401)
PresentText(time);
else
PresentTextDiagonal(time);
}
public void PresentText(string text1, string text2 = "")
{
using (Bitmap bmp = new Bitmap(MaxColumns * 3, MaxRows))
@@ -341,14 +369,14 @@ namespace Starlight.AnimeMatrix
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.AntiAlias;
using (Font font = new Font("Arial", 24F, GraphicsUnit.Pixel))
using (Font font = new Font("Consolas", 21F, FontStyle.Regular, GraphicsUnit.Pixel))
{
SizeF textSize = g.MeasureString(text1, font);
g.DrawString(text1, font, Brushes.White, (MaxColumns * 3 - textSize.Width) + 3, -3);
g.DrawString(text1, font, Brushes.White, (MaxColumns * 3 - textSize.Width) + 3, -4);
}
if (text2.Length > 0)
using (Font font = new Font("Arial", 18F, GraphicsUnit.Pixel))
using (Font font = new Font("Consolas", 18F, GraphicsUnit.Pixel))
{
SizeF textSize = g.MeasureString(text2, font);
g.DrawString(text2, font, Brushes.White, (MaxColumns * 3 - textSize.Width) + 1, 25);
@@ -419,6 +447,24 @@ namespace Starlight.AnimeMatrix
Clear();
InstalledFontCollection installedFontCollection = new InstalledFontCollection();
string familyName;
string familyList = "";
FontFamily[] fontFamilies;
// Get the array of FontFamily objects.
fontFamilies = installedFontCollection.Families;
int count = fontFamilies.Length;
for (int j = 0; j < count; ++j)
{
familyName = fontFamilies[j].Name;
familyList = familyList + familyName;
familyList = familyList + ", ";
}
int maxX = (int)Math.Sqrt(MaxRows * MaxRows + MaxColumns * MaxColumns);
using (Bitmap bmp = new Bitmap(maxX, MaxRows))
@@ -428,10 +474,10 @@ namespace Starlight.AnimeMatrix
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.AntiAlias;
using (Font font = new Font("Calibri", 13F, GraphicsUnit.Pixel))
using (Font font = new Font("Consolas", 13F, FontStyle.Regular, GraphicsUnit.Pixel))
{
SizeF textSize = g.MeasureString(text, font);
g.DrawString(text, font, Brushes.White, 4, 0);
g.DrawString(text, font, Brushes.White, 4, 1);
}
}

View File

@@ -1,9 +1,8 @@
// Source thanks to https://github.com/vddCore/Starlight :)
using Starlight.Communication.Platform;
using System.Configuration;
using GHelper.AnimeMatrix.Communication.Platform;
namespace Starlight.Communication
namespace GHelper.AnimeMatrix.Communication
{
public abstract class Device : IDisposable
{

View File

@@ -1,6 +1,6 @@
// Source thanks to https://github.com/vddCore/Starlight :)
namespace Starlight.Communication
namespace GHelper.AnimeMatrix.Communication
{
public abstract class Packet
{

View File

@@ -1,4 +1,4 @@
namespace Starlight.Communication.Platform
namespace GHelper.AnimeMatrix.Communication.Platform
{
internal abstract class UsbProvider : IDisposable
{
@@ -13,7 +13,7 @@ namespace Starlight.Communication.Platform
public abstract void Set(byte[] data);
public abstract byte[] Get(byte[] data);
public abstract void Dispose();
}
}

View File

@@ -1,14 +1,14 @@
using System.ComponentModel;
using HidSharp;
namespace Starlight.Communication.Platform
namespace GHelper.AnimeMatrix.Communication.Platform
{
internal class WindowsUsbProvider : UsbProvider
{
protected HidDevice HidDevice { get; }
protected HidStream HidStream { get; }
public WindowsUsbProvider(ushort vendorId, ushort productId, int maxFeatureReportLength)
public WindowsUsbProvider(ushort vendorId, ushort productId, int maxFeatureReportLength)
: base(vendorId, productId)
{
try
@@ -43,7 +43,7 @@ namespace Starlight.Communication.Platform
{
var outData = new byte[data.Length];
Array.Copy(data, outData, data.Length);
WrapException(() =>
{
HidStream.GetFeature(outData);
@@ -57,7 +57,7 @@ namespace Starlight.Communication.Platform
{
HidStream.Dispose();
}
private void WrapException(Action action)
{
try

View File

@@ -1,22 +1,31 @@
using System.Diagnostics;
using GHelper.Mode;
using System.Diagnostics;
using System.Management;
using System.Text.Json;
public class AppConfig
public static class AppConfig
{
public string appPath;
string configFile;
private static string configFile;
private static string? _model;
string _model;
private static Dictionary<string, object> config = new Dictionary<string, object>();
public Dictionary<string, object> config = new Dictionary<string, object>();
public AppConfig()
static AppConfig()
{
appPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\GHelper";
configFile = appPath + "\\config.json";
string startupPath = Application.StartupPath.Trim('\\');
string appPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\GHelper";
string configName = "\\config.json";
if (File.Exists(startupPath + configName))
{
configFile = startupPath + configName;
} else
{
configFile = appPath + configName;
}
if (!System.IO.Directory.Exists(appPath))
System.IO.Directory.CreateDirectory(appPath);
@@ -30,18 +39,19 @@ public class AppConfig
}
catch
{
initConfig();
Logger.WriteLine("Broken config: " + text);
Init();
}
}
else
{
initConfig();
Init();
}
}
public string GetModel()
public static string GetModel()
{
if (_model is null)
{
@@ -58,14 +68,24 @@ public class AppConfig
return _model;
}
public bool ContainsModel(string contains)
public static string GetModelShort()
{
string model = GetModel();
int trim = model.LastIndexOf("_");
if (trim > 0) model = model.Substring(0, trim);
return model;
}
public static bool ContainsModel(string contains)
{
GetModel();
return (_model is not null && _model.Contains(contains));
return (_model is not null && _model.ToLower().Contains(contains.ToLower()));
}
private void initConfig()
private static void Init()
{
config = new Dictionary<string, object>();
config["performance_mode"] = 0;
@@ -73,37 +93,27 @@ public class AppConfig
File.WriteAllText(configFile, jsonString);
}
public int getConfig(string name, bool performance = false)
public static int Get(string name, int empty = -1)
{
if (config.ContainsKey(name))
return int.Parse(config[name].ToString());
else return -1;
else return empty;
}
public string getConfigString(string name)
public static bool Is(string name)
{
return Get(name) == 1;
}
public static string GetString(string name, string empty = null)
{
if (config.ContainsKey(name))
return config[name].ToString();
else return null;
else return empty;
}
public void setConfig(string name, int value)
private static void Write()
{
config[name] = value;
string jsonString = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
try
{
File.WriteAllText(configFile, jsonString);
} catch (Exception e)
{
Debug.Write(e.ToString());
}
}
public void setConfig(string name, string value)
{
config[name] = value;
string jsonString = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
try
{
@@ -115,24 +125,51 @@ public class AppConfig
}
}
public string getParamName(int device, string paramName = "fan_profile")
public static void Set(string name, int value)
{
int mode = getConfig("performance_mode");
config[name] = value;
Write();
}
public static void Set(string name, string value)
{
config[name] = value;
Write();
}
public static void Remove(string name)
{
config.Remove(name);
Write();
}
public static string GgetParamName(AsusFan device, string paramName = "fan_profile")
{
int mode = Modes.GetCurrent();
string name;
if (device == 1)
name = "gpu";
else if (device == 2)
name = "mid";
else
name = "cpu";
switch (device)
{
case AsusFan.GPU:
name = "gpu";
break;
case AsusFan.Mid:
name = "mid";
break;
case AsusFan.XGM:
name = "xgm";
break;
default:
name = "cpu";
break;
}
return paramName + "_" + name + "_" + mode;
}
public byte[] getFanConfig(int device)
public static byte[] GetFanConfig(AsusFan device)
{
string curveString = getConfigString(getParamName(device));
string curveString = GetString(GgetParamName(device));
byte[] curve = { };
if (curveString is not null)
@@ -141,10 +178,10 @@ public class AppConfig
return curve;
}
public void setFanConfig(int device, byte[] curve)
public static void SetFanConfig(AsusFan device, byte[] curve)
{
string bitCurve = BitConverter.ToString(curve);
setConfig(getParamName(device), bitCurve);
Set(GgetParamName(device), bitCurve);
}
@@ -156,27 +193,27 @@ public class AppConfig
return array;
}
public byte[] getDefaultCurve(int device)
public static byte[] GetDefaultCurve(AsusFan device)
{
int mode = getConfig("performance_mode");
int mode = Modes.GetCurrentBase();
byte[] curve;
switch (mode)
{
case 1:
if (device == 1)
if (device == AsusFan.GPU)
curve = StringToBytes("14-3F-44-48-4C-50-54-62-16-1F-26-2D-39-47-55-5F");
else
curve = StringToBytes("14-3F-44-48-4C-50-54-62-11-1A-22-29-34-43-51-5A");
break;
case 2:
if (device == 1)
if (device == AsusFan.GPU)
curve = StringToBytes("3C-41-42-46-47-4B-4C-62-08-11-11-1D-1D-26-26-2D");
else
curve = StringToBytes("3C-41-42-46-47-4B-4C-62-03-0C-0C-16-16-22-22-29");
break;
default:
if (device == 1)
if (device == AsusFan.GPU)
curve = StringToBytes("3A-3D-40-44-48-4D-51-62-0C-16-1D-1F-26-2D-34-4A");
else
curve = StringToBytes("3A-3D-40-44-48-4D-51-62-08-11-16-1A-22-29-30-45");
@@ -186,23 +223,29 @@ public class AppConfig
return curve;
}
public string getConfigPerfString(string name)
public static string GetModeString(string name)
{
int mode = getConfig("performance_mode");
return getConfigString(name + "_" + mode);
return GetString(name + "_" + Modes.GetCurrent());
}
public int getConfigPerf(string name)
public static int GetMode(string name, int empty = -1)
{
int mode = getConfig("performance_mode");
return getConfig(name + "_" + mode);
return Get(name + "_" + Modes.GetCurrent(), empty);
}
public void setConfigPerf(string name, int value)
public static bool IsMode(string name)
{
int mode = getConfig("performance_mode");
setConfig(name + "_" + mode, value);
return Get(name + "_" + Modes.GetCurrent()) == 1;
}
public static void SetMode(string name, int value)
{
Set(name + "_" + Modes.GetCurrent(), value);
}
public static void SetMode(string name, string value)
{
Set(name + "_" + Modes.GetCurrent(), value);
}
}

View File

@@ -1,8 +1,29 @@
using GHelper;
using System.Management;
using System.Management;
using System.Runtime.InteropServices;
public class ASUSWmi
public enum AsusFan
{
CPU = 0,
GPU = 1,
Mid = 2,
XGM = 3
}
public enum AsusMode
{
Balanced = 0,
Turbo = 1,
Silent = 2
}
public enum AsusGPU
{
Eco = 0,
Standard = 1,
Ultimate = 2
}
public class AsusACPI
{
const string FILE_NAME = @"\\.\\ATKACPI";
@@ -10,10 +31,20 @@ public class ASUSWmi
const uint DSTS = 0x53545344;
const uint DEVS = 0x53564544;
const uint INIT = 0x54494E49;
public const uint UniversalControl = 0x00100021;
public const int KB_Light_Up = 0xc4;
public const int KB_Light_Down = 0xc5;
public const int Brightness_Down = 0x10;
public const int Brightness_Up = 0x20;
public const int KB_Sleep = 0x6c;
public const int KB_DUO_PgUpDn = 0x4B;
public const int KB_DUO_SecondDisplay = 0x6A;
public const int Touchpad_Toggle = 0x6B;
public const int ChargerMode = 0x0012006C;
@@ -42,36 +73,44 @@ public class ASUSWmi
public const int Temp_CPU = 0x00120094;
public const int Temp_GPU = 0x00120097;
public const int PPT_TotalA0 = 0x001200A0; // Total PPT on 2022 (PPT_LIMIT_SLOW ) and CPU PPT on 2021
public const int PPT_TotalA0 = 0x001200A0; // SPL (Total limit for all-AMD models) / PL1
public const int PPT_EDCA1 = 0x001200A1; // CPU EDC
public const int PPT_TDCA2 = 0x001200A2; // CPU TDC
public const int PPT_APUA3 = 0x001200A3; // APU PPT ON 2021, doesn't work on 2022
public const int PPT_APUA3 = 0x001200A3; // sPPT (long boost limit) / PL2
public const int PPT_CPUB0 = 0x001200B0; // CPU PPT on 2022 (PPT_LIMIT_APU)
public const int PPT_CPUB1 = 0x001200B1; // Total PPT on 2022 (PPT_LIMIT_SLOW)
public const int PPT_GPUC0 = 0x001200C0; // NVIDIA GPU Boost
public const int PPT_APUC1 = 0x001200C1; // Actual Power Limit (PPT_LIMIT_FAST) AND Sustained Power Limit (STAPM_LIMIT)
public const int PPT_APUC1 = 0x001200C1; // fPPT (fast boost limit)
public const int PPT_GPUC2 = 0x001200C2; // NVIDIA GPU Temp Target (75.. 87 C)
public const int TUF_KB_BRIGHTNESS = 0x00050021;
public const int TUF_KB = 0x00100056;
public const int TUF_KB_STATE = 0x00100057;
public const int TabletState = 0x00060077;
public const int FnLock = 0x00100023;
public const int Tablet_Notebook = 0;
public const int Tablet_Tablet = 1;
public const int Tablet_Tent = 2;
public const int Tablet_Rotated = 3;
public const int PerformanceBalanced = 0;
public const int PerformanceTurbo = 1;
public const int PerformanceSilent = 2;
public const int PerformanceManual = 4;
public const int GPUModeEco = 0;
public const int GPUModeStandard = 1;
public const int GPUModeUltimate = 2;
public const int MaxTotal = 250;
public static int MaxTotal => AppConfig.ContainsModel("13QY") ? 250 : 150;
public const int MinTotal = 5;
public const int DefaultTotal = 125;
public const int MaxCPU = 130;
public const int MaxCPU = 100;
public const int MinCPU = 5;
public const int DefaultCPU = 80;
@@ -117,7 +156,43 @@ public class ASUSWmi
private IntPtr handle;
public ASUSWmi()
// Event handling attempt
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, string lpName);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool WaitForSingleObject(IntPtr hHandle, int dwMilliseconds);
private IntPtr eventHandle;
// still works only with asus optimization service on , if someone knows how to get ACPI events from asus without that - let me know
public void RunListener()
{
eventHandle = CreateEvent(IntPtr.Zero, false, false, "ATK4001");
byte[] outBuffer = new byte[16];
byte[] data = new byte[8];
bool result;
data[0] = BitConverter.GetBytes(eventHandle.ToInt32())[0];
data[1] = BitConverter.GetBytes(eventHandle.ToInt32())[1];
Control(0x222400, data, outBuffer);
Logger.WriteLine("ACPI :" + BitConverter.ToString(data) + "|" + BitConverter.ToString(outBuffer));
while (true)
{
WaitForSingleObject(eventHandle, Timeout.Infinite);
Control(0x222408, new byte[0], outBuffer);
int code = BitConverter.ToInt32(outBuffer);
Logger.WriteLine("ACPI Code: " + code);
}
}
public AsusACPI()
{
handle = CreateFile(
FILE_NAME,
@@ -128,16 +203,19 @@ public class ASUSWmi
FILE_ATTRIBUTE_NORMAL,
IntPtr.Zero
);
if (handle == new IntPtr(-1))
{
throw new Exception("Can't connect to ACPI");
}
}
public void Control(uint dwIoControlCode, byte[] lpInBuffer, byte[] lpOutBuffer)
{
uint lpBytesReturned = 0;
bool result = DeviceIoControl(
DeviceIoControl(
handle,
dwIoControlCode,
lpInBuffer,
@@ -172,6 +250,13 @@ public class ASUSWmi
}
public byte[] DeviceInit()
{
byte[] args = new byte[8];
return CallMethod(INIT, args);
}
public int DeviceSet(uint DeviceID, int Status, string logName)
{
byte[] args = new byte[8];
@@ -205,7 +290,7 @@ public class ASUSWmi
byte[] args = new byte[8];
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
byte[] status = CallMethod(DSTS, args);
return BitConverter.ToInt32(status, 0) - 65536;
}
@@ -215,7 +300,7 @@ public class ASUSWmi
byte[] args = new byte[8];
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
BitConverter.GetBytes((uint)Status).CopyTo(args, 4);
return CallMethod(DSTS, args);
}
@@ -234,7 +319,7 @@ public class ASUSWmi
}
public int SetFanCurve(int device, byte[] curve)
public int SetFanCurve(AsusFan device, byte[] curve)
{
if (curve.Length != 16) return -1;
@@ -243,16 +328,14 @@ public class ASUSWmi
int result;
for (int i = 8; i < curve.Length; i++)
{
curve[i] = Math.Max((byte)0, Math.Min((byte)99, curve[i])); // it seems to be a bug, when some old model's bios can go nuts if fan is set to 100%
}
switch (device)
{
case 1:
case AsusFan.GPU:
result = DeviceSet(DevsGPUFanCurve, curve, "FanGPU");
break;
case 2:
case AsusFan.Mid:
result = DeviceSet(DevsMidFanCurve, curve, "FanMid");
break;
default:
@@ -263,7 +346,7 @@ public class ASUSWmi
return result;
}
public byte[] GetFanCurve(int device, int mode = 0)
public byte[] GetFanCurve(AsusFan device, int mode = 0)
{
uint fan_mode;
@@ -277,9 +360,9 @@ public class ASUSWmi
switch (device)
{
case 1:
case AsusFan.GPU:
return DeviceGetBuffer(DevsGPUFanCurve, fan_mode);
case 2:
case AsusFan.Mid:
return DeviceGetBuffer(DevsMidFanCurve, fan_mode);
default:
return DeviceGetBuffer(DevsCPUFanCurve, fan_mode);
@@ -287,6 +370,82 @@ public class ASUSWmi
}
public static bool IsInvalidCurve(byte[] curve)
{
return curve.Length != 16 || IsEmptyCurve(curve);
}
public static bool IsEmptyCurve(byte[] curve)
{
return curve.All(singleByte => singleByte == 0);
}
public static byte[] FixFanCurve(byte[] curve)
{
if (curve.Length != 16) throw new Exception("Incorrect curve");
var points = new Dictionary<byte, byte>();
for (int i = 0; i < 8; i++) points[curve[i]] = curve[i + 8];
var pointsFixed = new Dictionary<byte, byte>();
bool fix = false;
int count = 0;
foreach (var pair in points.OrderBy(x => x.Key))
{
if (count == 0 && pair.Key >= 40)
{
fix = true;
pointsFixed.Add(30, 0);
}
if (count != 3 || !fix)
pointsFixed.Add(pair.Key, pair.Value);
count++;
}
count = 0;
foreach (var pair in pointsFixed.OrderBy(x => x.Key))
{
curve[count] = pair.Key;
curve[count + 8] = pair.Value;
count++;
}
return curve;
}
public bool IsXGConnected()
{
//return true;
return DeviceGet(GPUXGConnected) == 1;
}
public bool IsAllAmdPPT()
{
return DeviceGet(PPT_CPUB0) >= 0 && DeviceGet(PPT_GPUC0) < 0;
}
public void ScanRange()
{
int value;
string appPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\GHelper";
string logFile = appPath + "\\scan.txt";
for (uint i = 0x00000000; i <= 0x00160000; i++)
{
value = DeviceGet(i);
if (value >= 0)
using (StreamWriter w = File.AppendText(logFile))
{
w.WriteLine(i.ToString("X8") + ": " + value.ToString("X4") + " (" + value + ")");
w.Close();
}
}
}
public void TUFKeyboardBrightness(int brightness)
{
int param = 0x80 | (brightness & 0x7F);
@@ -336,7 +495,8 @@ public class ASUSWmi
watcher.Scope = new ManagementScope("root\\wmi");
watcher.Query = new WqlEventQuery("SELECT * FROM AsusAtkWmiEvent");
watcher.Start();
} catch
}
catch
{
Logger.WriteLine("Can't connect to ASUS WMI events");
}

427
app/AsusUSB.cs Normal file
View File

@@ -0,0 +1,427 @@
using HidLibrary;
using System.Text;
namespace GHelper
{
[Flags]
public enum AuraDev19b6 : uint
{
BootLogo = 1,
BootKeyb = 1 << 1,
AwakeLogo = 1 << 2,
AwakeKeyb = 1 << 3,
SleepLogo = 1 << 4,
SleepKeyb = 1 << 5,
ShutdownLogo = 1 << 6,
ShutdownKeyb = 1 << 7,
BootBar = 1u << (7 + 2),
AwakeBar = 1u << (7 + 3),
SleepBar = 1u << (7 + 4),
ShutdownBar = 1u << (7 + 5),
BootLid = 1u << (15 + 1),
AwakeLid = 1u << (15 + 2),
SleepLid = 1u << (15 + 3),
ShutdownLid = 1u << (15 + 4)
}
public static class AuraDev19b6Extensions
{
public static byte[] ToBytes(this AuraDev19b6[] controls)
{
uint a = 0;
foreach (var n in controls)
{
a |= (uint)n;
}
return new byte[] { 0x5d, 0xbd, 0x01, (byte)(a & 0xff), (byte)((a & 0xff00) >> 8), (byte)((a & 0xff0000) >> 16) };
}
public static ushort BitOr(this AuraDev19b6 self, AuraDev19b6 rhs)
{
return (ushort)(self | rhs);
}
public static ushort BitAnd(this AuraDev19b6 self, AuraDev19b6 rhs)
{
return (ushort)(self & rhs);
}
}
public static class AsusUSB
{
public const int ASUS_ID = 0x0b05;
public const byte INPUT_HID_ID = 0x5a;
public const byte AURA_HID_ID = 0x5d;
public static readonly byte[] LED_INIT1 = new byte[] { AURA_HID_ID, 0xb9 };
public static readonly byte[] LED_INIT2 = Encoding.ASCII.GetBytes("]ASUS Tech.Inc.");
public static readonly byte[] LED_INIT3 = new byte[] { AURA_HID_ID, 0x05, 0x20, 0x31, 0, 0x08 };
public static readonly byte[] LED_INIT4 = Encoding.ASCII.GetBytes("^ASUS Tech.Inc.");
public static readonly byte[] LED_INIT5 = new byte[] { 0x5e, 0x05, 0x20, 0x31, 0, 0x08 };
static byte[] MESSAGE_SET = { AURA_HID_ID, 0xb5, 0, 0, 0 };
static byte[] MESSAGE_APPLY = { AURA_HID_ID, 0xb4 };
static int[] deviceIds = { 0x1a30, 0x1854, 0x1869, 0x1866, 0x19b6, 0x1822, 0x1837, 0x1854, 0x184a, 0x183d, 0x8502, 0x1807, 0x17e0, 0x18c6, 0x1abe };
private static int mode = 0;
private static int speed = 1;
public static Color Color1 = Color.White;
public static Color Color2 = Color.Black;
public static Dictionary<int, string> GetSpeeds()
{
return new Dictionary<int, string>
{
{ 0, Properties.Strings.AuraSlow },
{ 1, Properties.Strings.AuraNormal },
{ 2, Properties.Strings.AuraFast }
};
}
static Dictionary<int, string> _modes = new Dictionary<int, string>
{
{ 0, Properties.Strings.AuraStatic },
{ 1, Properties.Strings.AuraBreathe },
{ 2, Properties.Strings.AuraColorCycle },
{ 3, Properties.Strings.AuraRainbow },
{ 10, Properties.Strings.AuraStrobe },
};
static Dictionary<int, string> _modesStrix = new Dictionary<int, string>
{
{ 0, Properties.Strings.AuraStatic },
{ 1, Properties.Strings.AuraBreathe },
{ 2, Properties.Strings.AuraColorCycle },
{ 3, Properties.Strings.AuraRainbow },
{ 4, "Star" },
{ 5, "Rain" },
{ 6, "Highlight" },
{ 7, "Laser" },
{ 8, "Ripple" },
{ 10, Properties.Strings.AuraStrobe},
{ 11, "Comet" },
{ 12, "Flash" },
};
public static Dictionary<int, string> GetModes()
{
if (AppConfig.ContainsModel("TUF"))
{
_modes.Remove(3);
}
if (AppConfig.ContainsModel("401") || AppConfig.ContainsModel("X13"))
{
_modes.Remove(2);
_modes.Remove(3);
}
if (AppConfig.ContainsModel("G513QY"))
{
return _modes;
}
if (AppConfig.ContainsModel("Strix") || AppConfig.ContainsModel("Scar"))
{
return _modesStrix;
}
return _modes;
}
public static int Mode
{
get { return mode; }
set
{
if (GetModes().ContainsKey(value))
mode = value;
else
mode = 0;
}
}
public static bool HasColor()
{
return AppConfig.ContainsModel("GA401") || AppConfig.ContainsModel("X13");
}
public static bool HasSecondColor()
{
return (mode == 1 && !AppConfig.ContainsModel("TUF"));
}
public static int Speed
{
get { return speed; }
set
{
if (GetSpeeds().ContainsKey(value))
speed = value;
else
speed = 1;
}
}
public static void SetColor(int colorCode)
{
Color1 = Color.FromArgb(colorCode);
}
public static void SetColor2(int colorCode)
{
Color2 = Color.FromArgb(colorCode);
}
private static IEnumerable<HidDevice> GetHidDevices(int[] deviceIds, int minFeatures = 1)
{
HidDevice[] HidDeviceList = HidDevices.Enumerate(ASUS_ID, deviceIds).ToArray();
foreach (HidDevice device in HidDeviceList)
if (device.IsConnected && device.Capabilities.FeatureReportByteLength >= minFeatures)
yield return device;
}
public static HidDevice? GetDevice(byte reportID = INPUT_HID_ID)
{
HidDevice[] HidDeviceList = HidDevices.Enumerate(ASUS_ID, deviceIds).ToArray();
HidDevice input = null;
foreach (HidDevice device in HidDeviceList)
if (device.ReadFeatureData(out byte[] data, reportID))
{
input = device;
//Logger.WriteLine("HID Device("+ reportID + ")" + + device.Capabilities.FeatureReportByteLength + "|" + device.Capabilities.InputReportByteLength + device.DevicePath);
}
return input;
}
public static bool TouchpadToggle()
{
HidDevice? input = GetDevice();
if (input != null) return input.WriteFeatureData(new byte[] { INPUT_HID_ID, 0xf4, 0x6b });
return false;
}
public static byte[] AuraMessage(int mode, Color color, Color color2, int speed)
{
byte[] msg = new byte[17];
msg[0] = AURA_HID_ID;
msg[1] = 0xb3;
msg[2] = 0x00; // Zone
msg[3] = (byte)mode; // Aura Mode
msg[4] = (byte)(color.R); // R
msg[5] = (byte)(color.G); // G
msg[6] = (byte)(color.B); // B
msg[7] = (byte)speed; // aura.speed as u8;
msg[8] = 0; // aura.direction as u8;
msg[10] = (byte)(color2.R); // R
msg[11] = (byte)(color2.G); // G
msg[12] = (byte)(color2.B); // B
return msg;
}
public static void Init()
{
Task.Run(async () =>
{
var devices = GetHidDevices(deviceIds);
foreach (HidDevice device in devices)
{
device.OpenDevice();
device.WriteFeatureData(LED_INIT1);
device.WriteFeatureData(LED_INIT2);
device.WriteFeatureData(LED_INIT3);
device.WriteFeatureData(LED_INIT4);
device.WriteFeatureData(LED_INIT5);
device.CloseDevice();
}
});
}
public static void ApplyBrightness(int brightness, string log = "Backlight")
{
if (AppConfig.ContainsModel("TUF"))
Program.acpi.TUFKeyboardBrightness(brightness);
Task.Run(async () =>
{
byte[] msg = { AURA_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
byte[] msgBackup = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
var devices = GetHidDevices(deviceIds);
foreach (HidDevice device in devices)
{
device.OpenDevice();
if (device.ReadFeatureData(out byte[] data, AURA_HID_ID))
{
device.WriteFeatureData(msg);
Logger.WriteLine(log + ":" + BitConverter.ToString(msg));
}
if (AppConfig.ContainsModel("GA503") && device.ReadFeatureData(out byte[] dataBackkup, INPUT_HID_ID))
{
device.WriteFeatureData(msgBackup);
Logger.WriteLine(log + ":" + BitConverter.ToString(msgBackup));
}
device.CloseDevice();
}
// Backup payload for old models
/*
if (AppConfig.ContainsModel("GA503RW"))
{
byte[] msgBackup = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
var devicesBackup = GetHidDevices(deviceIds);
foreach (HidDevice device in devicesBackup)
{
device.OpenDevice();
device.WriteFeatureData(msgBackup);
device.CloseDevice();
}
}
*/
});
}
public static void ApplyAuraPower(List<AuraDev19b6> flags)
{
byte[] msg = AuraDev19b6Extensions.ToBytes(flags.ToArray());
var devices = GetHidDevices(deviceIds);
foreach (HidDevice device in devices)
{
device.OpenDevice();
if (device.ReadFeatureData(out byte[] data, AURA_HID_ID))
{
device.WriteFeatureData(msg);
Logger.WriteLine("USB-KB " + device.Attributes.ProductHexId + ":" + BitConverter.ToString(msg));
}
device.CloseDevice();
}
if (AppConfig.ContainsModel("TUF"))
Program.acpi.TUFKeyboardPower(
flags.Contains(AuraDev19b6.AwakeKeyb),
flags.Contains(AuraDev19b6.BootKeyb),
flags.Contains(AuraDev19b6.SleepKeyb),
flags.Contains(AuraDev19b6.ShutdownKeyb));
}
public static void ApplyAura()
{
int _speed;
switch (Speed)
{
case 1:
_speed = 0xeb;
break;
case 2:
_speed = 0xf5;
break;
default:
_speed = 0xe1;
break;
}
byte[] msg = AuraMessage(Mode, Color1, Color2, _speed);
var devices = GetHidDevices(deviceIds);
foreach (HidDevice device in devices)
{
device.OpenDevice();
if (device.ReadFeatureData(out byte[] data, AURA_HID_ID))
{
device.WriteFeatureData(msg);
device.WriteFeatureData(MESSAGE_SET);
device.WriteFeatureData(MESSAGE_APPLY);
Logger.WriteLine("USB-KB " + device.Capabilities.FeatureReportByteLength + "|" + device.Capabilities.InputReportByteLength + device.Description + device.DevicePath + ":" + BitConverter.ToString(msg));
}
device.CloseDevice();
}
if (AppConfig.ContainsModel("TUF"))
Program.acpi.TUFKeyboardRGB(Mode, Color1, _speed);
}
// Reference : thanks to https://github.com/RomanYazvinsky/ for initial discovery of XGM payloads
public static int SetXGM(byte[] msg)
{
//Logger.WriteLine("XGM Payload :" + BitConverter.ToString(msg));
var payload = new byte[300];
Array.Copy(msg, payload, msg.Length);
foreach (HidDevice device in GetHidDevices(new int[] { 0x1970 }, 300))
{
device.OpenDevice();
Logger.WriteLine("XGM " + device.Attributes.ProductHexId + "|" + device.Capabilities.FeatureReportByteLength + ":" + BitConverter.ToString(msg));
device.WriteFeatureData(payload);
device.CloseDevice();
//return 1;
}
return 0;
}
public static void ApplyXGMLight(bool status)
{
SetXGM(new byte[] { 0x5e, 0xc5, status ? (byte)0x50 : (byte)0 });
}
public static int ResetXGM()
{
return SetXGM(new byte[] { 0x5e, 0xd1, 0x02 });
}
public static int SetXGMFan(byte[] curve)
{
if (AsusACPI.IsInvalidCurve(curve)) return -1;
byte[] msg = new byte[19];
Array.Copy(new byte[] { 0x5e, 0xd1, 0x01 }, msg, 3);
Array.Copy(curve, 0, msg, 3, curve.Length);
return SetXGM(msg);
}
}
}

View File

@@ -1,311 +0,0 @@
using HidLibrary;
using Microsoft.Win32;
using OSD;
using System.Diagnostics;
using System.Windows.Forms;
namespace GHelper
{
[Flags]
public enum AuraDev19b6 : uint
{
BootLogo = 1,
BootKeyb = 1 << 1,
AwakeLogo = 1 << 2,
AwakeKeyb = 1 << 3,
SleepLogo = 1 << 4,
SleepKeyb = 1 << 5,
ShutdownLogo = 1 << 6,
ShutdownKeyb = 1 << 7,
BootBar = 1u << (7 + 2),
AwakeBar = 1u << (7 + 3),
SleepBar = 1u << (7 + 4),
ShutdownBar = 1u << (7 + 5),
BootLid = 1u << (15 + 1),
AwakeLid = 1u << (15 + 2),
SleepLid = 1u << (15 + 3),
ShutdownLid = 1u << (15 + 4)
}
public static class AuraDev19b6Extensions
{
public static byte[] ToBytes(this AuraDev19b6[] controls)
{
uint a = 0;
foreach (var n in controls)
{
a |= (uint)n;
}
return new byte[] { 0x5d, 0xbd, 0x01, (byte)(a & 0xff), (byte)((a & 0xff00) >> 8), (byte)((a & 0xff0000) >> 16) };
}
public static ushort BitOr(this AuraDev19b6 self, AuraDev19b6 rhs)
{
return (ushort)(self | rhs);
}
public static ushort BitAnd(this AuraDev19b6 self, AuraDev19b6 rhs)
{
return (ushort)(self & rhs);
}
}
public static class Aura
{
static byte[] MESSAGE_SET = { 0x5d, 0xb5, 0, 0, 0 };
static byte[] MESSAGE_APPLY = { 0x5d, 0xb4 };
static int[] deviceIds = { 0x1a30, 0x1854, 0x1869, 0x1866, 0x19b6, 0x1822, 0x1837, 0x1854, 0x184a, 0x183d, 0x8502, 0x1807, 0x17e0, 0x18c6 };
private static int mode = 0;
private static int speed = 1;
public static Color Color1 = Color.White;
public static Color Color2 = Color.Black;
public static Dictionary<int, string> GetSpeeds()
{
return new Dictionary<int, string>
{
{ 0, Properties.Strings.AuraSlow },
{ 1, Properties.Strings.AuraNormal },
{ 2, Properties.Strings.AuraFast }
};
}
static Dictionary<int, string> _modes = new Dictionary<int, string>
{
{ 0, Properties.Strings.AuraStatic },
{ 1, Properties.Strings.AuraBreathe },
{ 2, Properties.Strings.AuraColorCycle },
{ 3, Properties.Strings.AuraRainbow },
{ 10, Properties.Strings.AuraStrobe },
};
static Dictionary<int, string> _modesStrix = new Dictionary<int, string>
{
{ 0, Properties.Strings.AuraStatic },
{ 1, Properties.Strings.AuraBreathe },
{ 2, Properties.Strings.AuraColorCycle },
{ 3, Properties.Strings.AuraRainbow },
{ 4, "Star" },
{ 5, "Rain" },
{ 6, "Highlight" },
{ 7, "Laser" },
{ 8, "Ripple" },
{ 10, Properties.Strings.AuraStrobe},
{ 11, "Comet" },
{ 12, "Flash" },
};
public static Dictionary<int, string> GetModes()
{
if (Program.config.ContainsModel("TUF"))
{
_modes.Remove(3);
}
if (Program.config.ContainsModel("401"))
{
_modes.Remove(2);
_modes.Remove(3);
}
if (Program.config.ContainsModel("Strix") || Program.config.ContainsModel("Scar"))
{
return _modesStrix;
}
return _modes;
}
public static int Mode
{
get { return mode; }
set
{
if (GetModes().ContainsKey(value))
mode = value;
else
mode = 0;
}
}
public static bool HasSecondColor()
{
return (mode == 1 && !Program.config.ContainsModel("TUF"));
}
public static int Speed
{
get { return speed; }
set
{
if (GetSpeeds().ContainsKey(value))
speed = value;
else
speed = 1;
}
}
public static void SetColor(int colorCode)
{
Color1 = Color.FromArgb(colorCode);
}
public static void SetColor2(int colorCode)
{
Color2 = Color.FromArgb(colorCode);
}
private static IEnumerable<HidDevice> GetHidDevices(int[] deviceIds)
{
HidDevice[] HidDeviceList = HidDevices.Enumerate(0x0b05, deviceIds).ToArray();
foreach (HidDevice device in HidDeviceList)
if (device.IsConnected && device.Description.ToLower().Contains("hid") && device.Capabilities.FeatureReportByteLength >= 64)
yield return device;
}
public static byte[] AuraMessage(int mode, Color color, Color color2, int speed)
{
byte[] msg = new byte[17];
msg[0] = 0x5d;
msg[1] = 0xb3;
msg[2] = 0x00; // Zone
msg[3] = (byte)mode; // Aura Mode
msg[4] = (byte)(color.R); // R
msg[5] = (byte)(color.G); // G
msg[6] = (byte)(color.B); // B
msg[7] = (byte)speed; // aura.speed as u8;
msg[8] = 0; // aura.direction as u8;
msg[10] = (byte)(color2.R); // R
msg[11] = (byte)(color2.G); // G
msg[12] = (byte)(color2.B); // B
return msg;
}
public static void ApplyBrightness(int brightness)
{
byte[] msg = { 0x5d, 0xba, 0xc5, 0xc4, (byte)brightness };
var devices = GetHidDevices(deviceIds);
if (devices.Count() > 0) Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg));
foreach (HidDevice device in devices)
{
device.OpenDevice();
device.Write(msg);
device.CloseDevice();
}
if (Program.config.ContainsModel("TUF"))
Program.wmi.TUFKeyboardBrightness(brightness);
}
public static void ApplyAuraPower(List<AuraDev19b6> flags)
{
byte[] msg = AuraDev19b6Extensions.ToBytes(flags.ToArray());
var devices = GetHidDevices(deviceIds);
if (devices.Count() > 0) Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg));
foreach (HidDevice device in devices)
{
device.OpenDevice();
device.Write(msg);
device.CloseDevice();
}
if (Program.config.ContainsModel("TUF"))
Program.wmi.TUFKeyboardPower(
flags.Contains(AuraDev19b6.AwakeKeyb),
flags.Contains(AuraDev19b6.BootKeyb),
flags.Contains(AuraDev19b6.SleepKeyb),
flags.Contains(AuraDev19b6.ShutdownKeyb));
}
public static void ApplyXGMLight(bool status)
{
byte value = status? (byte)0x50:(byte)0;
var msg = new byte[] { 0x5e, 0xc5, value };
foreach (HidDevice device in GetHidDevices(new int[] { 0x1970 }))
{
device.OpenDevice();
var message = new byte[300];
Array.Copy(msg, message, msg.Length);
Debug.WriteLine(BitConverter.ToString(message));
device.WriteFeatureData(message);
device.CloseDevice();
}
}
public static void ApplyAura()
{
int _speed;
switch (Speed)
{
case 1:
_speed = 0xeb;
break;
case 2:
_speed = 0xf5;
break;
default:
_speed = 0xe1;
break;
}
byte[] msg = AuraMessage(Mode, Color1, Color2, _speed);
var devices = GetHidDevices(deviceIds);
if (devices.Count() > 0) Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg));
foreach (HidDevice device in devices)
{
device.OpenDevice();
device.Write(msg);
device.Write(MESSAGE_SET);
device.Write(MESSAGE_APPLY);
device.CloseDevice();
}
if (Program.config.ContainsModel("TUF"))
Program.wmi.TUFKeyboardRGB(Mode, Color1, _speed);
}
public static void SetBacklightOffDelay(int value = 60)
{
try
{
RegistryKey myKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ASUS\ASUS System Control Interface\AsusOptimization\ASUS Keyboard Hotkeys", true);
if (myKey != null)
{
myKey.SetValue("TurnOffKeybdLight", value, RegistryValueKind.DWord);
myKey.Close();
}
} catch (Exception ex)
{
Logger.WriteLine(ex.Message);
}
}
}
}

View File

@@ -0,0 +1,130 @@
using System.Diagnostics;
using System.Net;
using System.Reflection;
using System.Text.Json;
namespace GHelper.AutoUpdate
{
public class AutoUpdateControl
{
SettingsForm settings;
public string versionUrl = "http://github.com/seerge/g-helper/releases";
static long lastUpdate;
public AutoUpdateControl(SettingsForm settingsForm)
{
settings = settingsForm;
settings.SetVersionLabel(Properties.Strings.VersionLabel + ": " + Assembly.GetExecutingAssembly().GetName().Version);
}
public void CheckForUpdates()
{
// Run update once per 12 hours
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeSeconds() - lastUpdate) < 43200) return;
lastUpdate = DateTimeOffset.Now.ToUnixTimeSeconds();
Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromSeconds(1));
CheckForUpdatesAsync();
});
}
public void LoadReleases()
{
Process.Start(new ProcessStartInfo(versionUrl) { UseShellExecute = true });
}
async void CheckForUpdatesAsync()
{
try
{
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Add("User-Agent", "C# App");
var json = await httpClient.GetStringAsync("https://api.github.com/repos/seerge/g-helper/releases/latest");
var config = JsonSerializer.Deserialize<JsonElement>(json);
var tag = config.GetProperty("tag_name").ToString().Replace("v", "");
var assets = config.GetProperty("assets");
string url = null;
for (int i = 0; i < assets.GetArrayLength(); i++)
{
if (assets[i].GetProperty("browser_download_url").ToString().Contains(".zip"))
url = assets[i].GetProperty("browser_download_url").ToString();
}
if (url is null)
url = assets[0].GetProperty("browser_download_url").ToString();
var gitVersion = new Version(tag);
var appVersion = new Version(Assembly.GetExecutingAssembly().GetName().Version.ToString());
//appVersion = new Version("0.50.0.0");
if (gitVersion.CompareTo(appVersion) > 0)
{
versionUrl = url;
settings.SetVersionLabel(Properties.Strings.DownloadUpdate + ": " + tag, true);
if (AppConfig.GetString("skip_version") != tag)
{
DialogResult dialogResult = MessageBox.Show(Properties.Strings.DownloadUpdate + ": G-Helper " + tag + "?", "Update", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
AutoUpdate(url);
else
AppConfig.Set("skip_version", tag);
}
}
else
{
Logger.WriteLine($"Latest version {appVersion}");
}
}
}
catch (Exception ex)
{
Logger.WriteLine("Failed to check for updates:" + ex.Message);
}
}
async void AutoUpdate(string requestUri)
{
Uri uri = new Uri(requestUri);
string zipName = Path.GetFileName(uri.LocalPath);
string exeLocation = Application.ExecutablePath;
string exeDir = Path.GetDirectoryName(exeLocation);
string zipLocation = exeDir + "\\" + zipName;
using (WebClient client = new WebClient())
{
client.DownloadFile(uri, zipLocation);
Logger.WriteLine(requestUri);
Logger.WriteLine(zipLocation);
Logger.WriteLine(exeLocation);
var cmd = new Process();
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.FileName = "powershell";
cmd.StartInfo.Arguments = $"Start-Sleep -Seconds 1; Expand-Archive {zipLocation} -DestinationPath {exeDir} -Force; Remove-Item {zipLocation} -Force; {exeLocation}";
cmd.Start();
Application.Exit();
}
}
}
}

View File

@@ -0,0 +1,33 @@
using GHelper.Helpers;
using System.Diagnostics;
namespace GHelper.Battery
{
internal class BatteryControl
{
public static void SetBatteryChargeLimit(int limit = -1)
{
if (limit < 0) limit = AppConfig.Get("charge_limit");
if (limit < 40 || limit > 100) return;
Program.settingsForm.VisualiseBattery(limit);
Program.acpi.DeviceSet(AsusACPI.BatteryLimit, limit, "BatteryLimit");
try
{
OptimizationService.SetChargeLimit(limit);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
AppConfig.Set("charge_limit", limit);
}
}
}

View File

@@ -0,0 +1,99 @@
using System.Diagnostics;
namespace GHelper.Display
{
public class ScreenControl
{
public void AutoScreen(bool force = false)
{
if (force || AppConfig.Is("screen_auto"))
{
if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online)
SetScreen(1000, 1);
else
SetScreen(60, 0);
}
else
{
SetScreen(overdrive: AppConfig.Get("overdrive"));
}
}
public void SetScreen(int frequency = -1, int overdrive = -1, int miniled = -1)
{
if (ScreenNative.GetRefreshRate() < 0) // Laptop screen not detected or has unknown refresh rate
{
InitScreen();
return;
}
if (frequency >= 1000)
{
frequency = ScreenNative.GetRefreshRate(true);
}
if (frequency > 0)
{
ScreenNative.SetRefreshRate(frequency);
}
if (overdrive >= 0)
{
if (AppConfig.Get("no_overdrive") == 1) overdrive = 0;
Program.acpi.DeviceSet(AsusACPI.ScreenOverdrive, overdrive, "ScreenOverdrive");
}
if (miniled >= 0)
{
Program.acpi.DeviceSet(AsusACPI.ScreenMiniled, miniled, "Miniled");
Debug.WriteLine("Miniled " + miniled);
}
InitScreen();
}
public void ToogleMiniled()
{
int miniled = (AppConfig.Get("miniled") == 1) ? 0 : 1;
AppConfig.Set("miniled", miniled);
SetScreen(-1, -1, miniled);
}
public void InitScreen()
{
int frequency = ScreenNative.GetRefreshRate();
int maxFrequency = ScreenNative.GetRefreshRate(true);
bool screenAuto = AppConfig.Is("screen_auto");
bool overdriveSetting = !AppConfig.Is("no_overdrive");
int overdrive = Program.acpi.DeviceGet(AsusACPI.ScreenOverdrive);
int miniled = Program.acpi.DeviceGet(AsusACPI.ScreenMiniled);
if (miniled >= 0)
AppConfig.Set("miniled", miniled);
bool screenEnabled = (frequency >= 0);
AppConfig.Set("frequency", frequency);
AppConfig.Set("overdrive", overdrive);
Program.settingsForm.Invoke(delegate
{
Program.settingsForm.VisualiseScreen(
screenEnabled: screenEnabled,
screenAuto: screenAuto,
frequency: frequency,
maxFrequency: maxFrequency,
overdrive: overdrive,
overdriveSetting: overdriveSetting,
miniled: miniled
);
});
}
}
}

View File

@@ -0,0 +1,303 @@
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace GHelper.Display
{
public static class ScreenInterrogatory
{
public const int ERROR_SUCCESS = 0;
#region enums
public enum QUERY_DEVICE_CONFIG_FLAGS : uint
{
QDC_ALL_PATHS = 0x00000001,
QDC_ONLY_ACTIVE_PATHS = 0x00000002,
QDC_DATABASE_CURRENT = 0x00000004
}
public enum DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY : uint
{
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER = 0xFFFFFFFF,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HD15 = 0,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SVIDEO = 1,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPOSITE_VIDEO = 2,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPONENT_VIDEO = 3,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DVI = 4,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HDMI = 5,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_LVDS = 6,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_D_JPN = 8,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDI = 9,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EXTERNAL = 10,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED = 11,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EXTERNAL = 12,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EMBEDDED = 13,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDTVDONGLE = 14,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_MIRACAST = 15,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL = 0x80000000,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_FORCE_UINT32 = 0xFFFFFFFF
}
public enum DISPLAYCONFIG_SCANLINE_ORDERING : uint
{
DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED = 0,
DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE = 1,
DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED = 2,
DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_UPPERFIELDFIRST = DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED,
DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_LOWERFIELDFIRST = 3,
DISPLAYCONFIG_SCANLINE_ORDERING_FORCE_UINT32 = 0xFFFFFFFF
}
public enum DISPLAYCONFIG_ROTATION : uint
{
DISPLAYCONFIG_ROTATION_IDENTITY = 1,
DISPLAYCONFIG_ROTATION_ROTATE90 = 2,
DISPLAYCONFIG_ROTATION_ROTATE180 = 3,
DISPLAYCONFIG_ROTATION_ROTATE270 = 4,
DISPLAYCONFIG_ROTATION_FORCE_UINT32 = 0xFFFFFFFF
}
public enum DISPLAYCONFIG_SCALING : uint
{
DISPLAYCONFIG_SCALING_IDENTITY = 1,
DISPLAYCONFIG_SCALING_CENTERED = 2,
DISPLAYCONFIG_SCALING_STRETCHED = 3,
DISPLAYCONFIG_SCALING_ASPECTRATIOCENTEREDMAX = 4,
DISPLAYCONFIG_SCALING_CUSTOM = 5,
DISPLAYCONFIG_SCALING_PREFERRED = 128,
DISPLAYCONFIG_SCALING_FORCE_UINT32 = 0xFFFFFFFF
}
public enum DISPLAYCONFIG_PIXELFORMAT : uint
{
DISPLAYCONFIG_PIXELFORMAT_8BPP = 1,
DISPLAYCONFIG_PIXELFORMAT_16BPP = 2,
DISPLAYCONFIG_PIXELFORMAT_24BPP = 3,
DISPLAYCONFIG_PIXELFORMAT_32BPP = 4,
DISPLAYCONFIG_PIXELFORMAT_NONGDI = 5,
DISPLAYCONFIG_PIXELFORMAT_FORCE_UINT32 = 0xffffffff
}
public enum DISPLAYCONFIG_MODE_INFO_TYPE : uint
{
DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE = 1,
DISPLAYCONFIG_MODE_INFO_TYPE_TARGET = 2,
DISPLAYCONFIG_MODE_INFO_TYPE_FORCE_UINT32 = 0xFFFFFFFF
}
public enum DISPLAYCONFIG_DEVICE_INFO_TYPE : uint
{
DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME = 1,
DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME = 2,
DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_PREFERRED_MODE = 3,
DISPLAYCONFIG_DEVICE_INFO_GET_ADAPTER_NAME = 4,
DISPLAYCONFIG_DEVICE_INFO_SET_TARGET_PERSISTENCE = 5,
DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_BASE_TYPE = 6,
DISPLAYCONFIG_DEVICE_INFO_FORCE_UINT32 = 0xFFFFFFFF
}
#endregion
#region structs
[StructLayout(LayoutKind.Sequential)]
public struct LUID
{
public uint LowPart;
public int HighPart;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_PATH_SOURCE_INFO
{
public LUID adapterId;
public uint id;
public uint modeInfoIdx;
public uint statusFlags;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_PATH_TARGET_INFO
{
public LUID adapterId;
public uint id;
public uint modeInfoIdx;
private DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY outputTechnology;
private DISPLAYCONFIG_ROTATION rotation;
private DISPLAYCONFIG_SCALING scaling;
private DISPLAYCONFIG_RATIONAL refreshRate;
private DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering;
public bool targetAvailable;
public uint statusFlags;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_RATIONAL
{
public uint Numerator;
public uint Denominator;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_PATH_INFO
{
public DISPLAYCONFIG_PATH_SOURCE_INFO sourceInfo;
public DISPLAYCONFIG_PATH_TARGET_INFO targetInfo;
public uint flags;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_2DREGION
{
public uint cx;
public uint cy;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO
{
public ulong pixelRate;
public DISPLAYCONFIG_RATIONAL hSyncFreq;
public DISPLAYCONFIG_RATIONAL vSyncFreq;
public DISPLAYCONFIG_2DREGION activeSize;
public DISPLAYCONFIG_2DREGION totalSize;
public uint videoStandard;
public DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_TARGET_MODE
{
public DISPLAYCONFIG_VIDEO_SIGNAL_INFO targetVideoSignalInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct POINTL
{
private int x;
private int y;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_SOURCE_MODE
{
public uint width;
public uint height;
public DISPLAYCONFIG_PIXELFORMAT pixelFormat;
public POINTL position;
}
[StructLayout(LayoutKind.Explicit)]
public struct DISPLAYCONFIG_MODE_INFO_UNION
{
[FieldOffset(0)]
public DISPLAYCONFIG_TARGET_MODE targetMode;
[FieldOffset(0)]
public DISPLAYCONFIG_SOURCE_MODE sourceMode;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_MODE_INFO
{
public DISPLAYCONFIG_MODE_INFO_TYPE infoType;
public uint id;
public LUID adapterId;
public DISPLAYCONFIG_MODE_INFO_UNION modeInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS
{
public uint value;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_DEVICE_INFO_HEADER
{
public DISPLAYCONFIG_DEVICE_INFO_TYPE type;
public uint size;
public LUID adapterId;
public uint id;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DISPLAYCONFIG_TARGET_DEVICE_NAME
{
public DISPLAYCONFIG_DEVICE_INFO_HEADER header;
public DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS flags;
public DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY outputTechnology;
public ushort edidManufactureId;
public ushort edidProductCodeId;
public uint connectorInstance;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string monitorFriendlyDeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string monitorDevicePath;
}
#endregion
#region DLL-Imports
[DllImport("user32.dll")]
public static extern int GetDisplayConfigBufferSizes(
QUERY_DEVICE_CONFIG_FLAGS flags, out uint numPathArrayElements, out uint numModeInfoArrayElements);
[DllImport("user32.dll")]
public static extern int QueryDisplayConfig(
QUERY_DEVICE_CONFIG_FLAGS flags,
ref uint numPathArrayElements, [Out] DISPLAYCONFIG_PATH_INFO[] PathInfoArray,
ref uint numModeInfoArrayElements, [Out] DISPLAYCONFIG_MODE_INFO[] ModeInfoArray,
nint currentTopologyId
);
[DllImport("user32.dll")]
public static extern int DisplayConfigGetDeviceInfo(ref DISPLAYCONFIG_TARGET_DEVICE_NAME deviceName);
#endregion
private static DISPLAYCONFIG_TARGET_DEVICE_NAME DeviceName(LUID adapterId, uint targetId)
{
var deviceName = new DISPLAYCONFIG_TARGET_DEVICE_NAME
{
header =
{
size = (uint)Marshal.SizeOf(typeof (DISPLAYCONFIG_TARGET_DEVICE_NAME)),
adapterId = adapterId,
id = targetId,
type = DISPLAYCONFIG_DEVICE_INFO_TYPE.DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME
}
};
var error = DisplayConfigGetDeviceInfo(ref deviceName);
if (error != ERROR_SUCCESS)
throw new Win32Exception(error);
return deviceName;
}
public static IEnumerable<DISPLAYCONFIG_TARGET_DEVICE_NAME> GetAllDevices()
{
uint pathCount, modeCount;
var error = GetDisplayConfigBufferSizes(QUERY_DEVICE_CONFIG_FLAGS.QDC_ONLY_ACTIVE_PATHS, out pathCount, out modeCount);
if (error != ERROR_SUCCESS)
throw new Win32Exception(error);
var displayPaths = new DISPLAYCONFIG_PATH_INFO[pathCount];
var displayModes = new DISPLAYCONFIG_MODE_INFO[modeCount];
error = QueryDisplayConfig(QUERY_DEVICE_CONFIG_FLAGS.QDC_ONLY_ACTIVE_PATHS,
ref pathCount, displayPaths, ref modeCount, displayModes, nint.Zero);
if (error != ERROR_SUCCESS)
throw new Win32Exception(error);
for (var i = 0; i < modeCount; i++)
if (displayModes[i].infoType == DISPLAYCONFIG_MODE_INFO_TYPE.DISPLAYCONFIG_MODE_INFO_TYPE_TARGET)
yield return DeviceName(displayModes[i].adapterId, displayModes[i].id);
}
}
}

233
app/Display/ScreenNative.cs Normal file
View File

@@ -0,0 +1,233 @@
using System.Runtime.InteropServices;
using static GHelper.Display.ScreenInterrogatory;
namespace GHelper.Display
{
internal class ScreenNative
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct DEVMODE
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string dmDeviceName;
public short dmSpecVersion;
public short dmDriverVersion;
public short dmSize;
public short dmDriverExtra;
public int dmFields;
public int dmPositionX;
public int dmPositionY;
public int dmDisplayOrientation;
public int dmDisplayFixedOutput;
public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string dmFormName;
public short dmLogPixels;
public short dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
public int dmICMMethod;
public int dmICMIntent;
public int dmMediaType;
public int dmDitherType;
public int dmReserved1;
public int dmReserved2;
public int dmPanningWidth;
public int dmPanningHeight;
};
[Flags()]
public enum DisplaySettingsFlags : int
{
CDS_UPDATEREGISTRY = 1,
CDS_TEST = 2,
CDS_FULLSCREEN = 4,
CDS_GLOBAL = 8,
CDS_SET_PRIMARY = 0x10,
CDS_RESET = 0x40000000,
CDS_NORESET = 0x10000000
}
// PInvoke declaration for EnumDisplaySettings Win32 API
[DllImport("user32.dll")]
public static extern int EnumDisplaySettingsEx(
string lpszDeviceName,
int iModeNum,
ref DEVMODE lpDevMode);
// PInvoke declaration for ChangeDisplaySettings Win32 API
[DllImport("user32.dll")]
public static extern int ChangeDisplaySettingsEx(
string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd,
DisplaySettingsFlags dwflags, IntPtr lParam);
public static DEVMODE CreateDevmode()
{
DEVMODE dm = new DEVMODE();
dm.dmDeviceName = new String(new char[32]);
dm.dmFormName = new String(new char[32]);
dm.dmSize = (short)Marshal.SizeOf(dm);
return dm;
}
public enum COLORPROFILETYPE
{
CPT_ICC,
CPT_DMP,
CPT_CAMP,
CPT_GMMP
}
public enum COLORPROFILESUBTYPE
{
CPST_PERCEPTUAL,
CPST_RELATIVE_COLORIMETRIC,
CPST_SATURATION,
CPST_ABSOLUTE_COLORIMETRIC,
CPST_NONE,
CPST_RGB_WORKING_SPACE,
CPST_CUSTOM_WORKING_SPACE,
CPST_STANDARD_DISPLAY_COLOR_MODE,
CPST_EXTENDED_DISPLAY_COLOR_MODE
}
public enum WCS_PROFILE_MANAGEMENT_SCOPE
{
WCS_PROFILE_MANAGEMENT_SCOPE_SYSTEM_WIDE,
WCS_PROFILE_MANAGEMENT_SCOPE_CURRENT_USER
}
[DllImport("mscms.dll", CharSet = CharSet.Unicode)]
public static extern bool WcsSetDefaultColorProfile(
WCS_PROFILE_MANAGEMENT_SCOPE scope,
string pDeviceName,
COLORPROFILETYPE cptColorProfileType,
COLORPROFILESUBTYPE cpstColorProfileSubType,
uint dwProfileID,
string pProfileName
);
public const int ENUM_CURRENT_SETTINGS = -1;
public const string defaultDevice = "\\\\.\\DISPLAY1";
public static string? FindLaptopScreen()
{
string? laptopScreen = null;
try
{
var devices = GetAllDevices().ToArray();
int count = 0, displayNum = -1;
string internalName = AppConfig.GetString("internal_display");
foreach (var device in devices)
{
if (device.outputTechnology == DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY.DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL ||
device.outputTechnology == DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY.DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED ||
device.monitorFriendlyDeviceName == internalName)
{
displayNum = count;
AppConfig.Set("internal_display", device.monitorFriendlyDeviceName);
}
count++;
//Logger.WriteLine(device.monitorFriendlyDeviceName + ":" + device.outputTechnology.ToString());
}
var screens = Screen.AllScreens;
if (screens.Length != count) return null;
count = 0;
foreach (var screen in screens)
{
if (count == displayNum)
{
laptopScreen = screen.DeviceName;
}
//Logger.WriteLine(screen.DeviceName);
count++;
}
if (displayNum > 0 && count == 0) laptopScreen = defaultDevice;
}
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
Logger.WriteLine("Can't detect internal screen");
laptopScreen = Screen.PrimaryScreen.DeviceName;
}
return laptopScreen;
}
public static int GetRefreshRate(bool max = false)
{
DEVMODE dm = CreateDevmode();
string? laptopScreen = FindLaptopScreen();
int frequency = -1;
if (laptopScreen is null)
return -1;
if (max)
{
int i = 0;
while (0 != EnumDisplaySettingsEx(laptopScreen, i, ref dm))
{
if (dm.dmDisplayFrequency > frequency) frequency = dm.dmDisplayFrequency;
i++;
}
}
else
{
if (0 != EnumDisplaySettingsEx(laptopScreen, ENUM_CURRENT_SETTINGS, ref dm))
{
frequency = dm.dmDisplayFrequency;
}
}
return frequency;
}
public static int SetRefreshRate(int frequency = 120)
{
DEVMODE dm = CreateDevmode();
string? laptopScreen = FindLaptopScreen();
if (laptopScreen is null)
return -1;
if (0 != EnumDisplaySettingsEx(laptopScreen, ENUM_CURRENT_SETTINGS, ref dm))
{
dm.dmDisplayFrequency = frequency;
int iRet = ChangeDisplaySettingsEx(laptopScreen, ref dm, IntPtr.Zero, DisplaySettingsFlags.CDS_UPDATEREGISTRY, IntPtr.Zero);
Logger.WriteLine("Screen = " + frequency.ToString() + "Hz : " + (iRet == 0 ? "OK" : iRet));
//Fallback scenario
if (iRet != 0)
{
Thread.Sleep(300);
iRet = ChangeDisplaySettingsEx(laptopScreen, ref dm, IntPtr.Zero, DisplaySettingsFlags.CDS_UPDATEREGISTRY, IntPtr.Zero);
Logger.WriteLine("Screen = " + frequency.ToString() + "Hz : " + (iRet == 0 ? "OK" : iRet));
}
return iRet;
}
return 0;
}
}
}

798
app/Extra.Designer.cs generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,8 @@
using CustomControls;
using GHelper.Display;
using GHelper.Gpu.AMD;
using GHelper.Helpers;
using GHelper.Input;
using GHelper.UI;
using System.Diagnostics;
namespace GHelper
@@ -6,6 +10,8 @@ namespace GHelper
public partial class Extra : RForm
{
ScreenControl screenControl = new ScreenControl();
Dictionary<string, string> customActions = new Dictionary<string, string>
{
{"","--------------" },
@@ -16,18 +22,37 @@ namespace GHelper
{"performance", Properties.Strings.PerformanceMode},
{"screen", Properties.Strings.ToggleScreen},
{"miniled", Properties.Strings.ToggleMiniled},
{"fnlock", Properties.Strings.ToggleFnLock},
{"brightness_down", Properties.Strings.BrightnessDown},
{"brightness_up", Properties.Strings.BrightnessUp},
{"custom", Properties.Strings.Custom}
};
private void SetKeyCombo(ComboBox combo, TextBox txbox, string name)
{
if (name == "m4")
customActions[""] = Properties.Strings.OpenGHelper;
if (name == "fnf4")
switch (name)
{
customActions[""] = Properties.Strings.ToggleAura;
customActions.Remove("aura");
case "m1":
customActions[""] = Properties.Strings.VolumeDown;
break;
case "m2":
customActions[""] = Properties.Strings.VolumeUp;
break;
case "m3":
customActions[""] = Properties.Strings.MuteMic;
break;
case "m4":
customActions[""] = Properties.Strings.OpenGHelper;
break;
case "fnf4":
customActions[""] = Properties.Strings.ToggleAura;
customActions.Remove("aura");
break;
case "fnc":
customActions[""] = Properties.Strings.ToggleFnLock;
customActions.Remove("fnlock");
break;
}
combo.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -35,7 +60,7 @@ namespace GHelper
combo.DisplayMember = "Value";
combo.ValueMember = "Key";
string action = Program.config.getConfigString(name);
string action = AppConfig.GetString(name);
combo.SelectedValue = (action is not null) ? action : "";
if (combo.SelectedValue is null) combo.SelectedValue = "";
@@ -43,13 +68,17 @@ namespace GHelper
combo.SelectedValueChanged += delegate
{
if (combo.SelectedValue is not null)
Program.config.setConfig(name, combo.SelectedValue.ToString());
AppConfig.Set(name, combo.SelectedValue.ToString());
if (name == "m1" || name == "m2")
Program.inputDispatcher.RegisterKeys();
};
txbox.Text = Program.config.getConfigString(name + "_custom");
txbox.Text = AppConfig.GetString(name + "_custom");
txbox.TextChanged += delegate
{
Program.config.setConfig(name + "_custom", txbox.Text);
AppConfig.Set(name + "_custom", txbox.Text);
};
}
@@ -69,56 +98,65 @@ namespace GHelper
labelSpeed.Text = Properties.Strings.AnimationSpeed;
labelBrightness.Text = Properties.Strings.Brightness;
checkKeyboardAuto.Text = Properties.Strings.KeyboardAuto;
labelBacklightTimeout.Text = Properties.Strings.BacklightTimeout;
labelBacklightTimeoutPlugged.Text = Properties.Strings.BacklightTimeoutPlugged;
checkNoOverdrive.Text = Properties.Strings.DisableOverdrive;
checkTopmost.Text = Properties.Strings.WindowTop;
checkUSBC.Text = Properties.Strings.OptimizedUSBC;
checkAutoApplyWindowsPowerMode.Text = Properties.Strings.ApplyWindowsPowerPlan;
checkFnLock.Text = Properties.Strings.FnLock;
labelBacklight.Text = Properties.Strings.Keyboard;
labelBacklightBar.Text = Properties.Strings.Lightbar;
labelBacklightLid.Text = Properties.Strings.Lid;
labelBacklightLogo.Text = Properties.Strings.Logo;
checkGpuApps.Text = Properties.Strings.KillGpuApps;
Text = Properties.Strings.ExtraSettings;
InitTheme();
SetKeyCombo(comboM1, textM1, "m1");
SetKeyCombo(comboM2, textM2, "m2");
SetKeyCombo(comboM3, textM3, "m3");
SetKeyCombo(comboM4, textM4, "m4");
SetKeyCombo(comboFNF4, textFNF4, "fnf4");
SetKeyCombo(comboFNC, textFNC, "fnc");
Shown += Keyboard_Shown;
comboKeyboardSpeed.DropDownStyle = ComboBoxStyle.DropDownList;
comboKeyboardSpeed.DataSource = new BindingSource(Aura.GetSpeeds(), null);
comboKeyboardSpeed.DataSource = new BindingSource(AsusUSB.GetSpeeds(), null);
comboKeyboardSpeed.DisplayMember = "Value";
comboKeyboardSpeed.ValueMember = "Key";
comboKeyboardSpeed.SelectedValue = Aura.Speed;
comboKeyboardSpeed.SelectedValue = AsusUSB.Speed;
comboKeyboardSpeed.SelectedValueChanged += ComboKeyboardSpeed_SelectedValueChanged;
// Keyboard
checkAwake.Checked = !(Program.config.getConfig("keyboard_awake") == 0);
checkBoot.Checked = !(Program.config.getConfig("keyboard_boot") == 0);
checkSleep.Checked = !(Program.config.getConfig("keyboard_sleep") == 0);
checkShutdown.Checked = !(Program.config.getConfig("keyboard_shutdown") == 0);
checkAwake.Checked = !(AppConfig.Get("keyboard_awake") == 0);
checkBoot.Checked = !(AppConfig.Get("keyboard_boot") == 0);
checkSleep.Checked = !(AppConfig.Get("keyboard_sleep") == 0);
checkShutdown.Checked = !(AppConfig.Get("keyboard_shutdown") == 0);
// Lightbar
checkAwakeBar.Checked = !(Program.config.getConfig("keyboard_awake_bar") == 0);
checkBootBar.Checked = !(Program.config.getConfig("keyboard_boot_bar") == 0);
checkSleepBar.Checked = !(Program.config.getConfig("keyboard_sleep_bar") == 0);
checkShutdownBar.Checked = !(Program.config.getConfig("keyboard_shutdown_bar") == 0);
checkAwakeBar.Checked = !(AppConfig.Get("keyboard_awake_bar") == 0);
checkBootBar.Checked = !(AppConfig.Get("keyboard_boot_bar") == 0);
checkSleepBar.Checked = !(AppConfig.Get("keyboard_sleep_bar") == 0);
checkShutdownBar.Checked = !(AppConfig.Get("keyboard_shutdown_bar") == 0);
// Lid
checkAwakeLid.Checked = !(Program.config.getConfig("keyboard_awake_lid") == 0);
checkBootLid.Checked = !(Program.config.getConfig("keyboard_boot_lid") == 0);
checkSleepLid.Checked = !(Program.config.getConfig("keyboard_sleep_lid") == 0);
checkShutdownLid.Checked = !(Program.config.getConfig("keyboard_shutdown_lid") == 0);
checkAwakeLid.Checked = !(AppConfig.Get("keyboard_awake_lid") == 0);
checkBootLid.Checked = !(AppConfig.Get("keyboard_boot_lid") == 0);
checkSleepLid.Checked = !(AppConfig.Get("keyboard_sleep_lid") == 0);
checkShutdownLid.Checked = !(AppConfig.Get("keyboard_shutdown_lid") == 0);
// Logo
checkAwakeLogo.Checked = !(Program.config.getConfig("keyboard_awake_logo") == 0);
checkBootLogo.Checked = !(Program.config.getConfig("keyboard_boot_logo") == 0);
checkSleepLogo.Checked = !(Program.config.getConfig("keyboard_sleep_logo") == 0);
checkShutdownLogo.Checked = !(Program.config.getConfig("keyboard_shutdown_logo") == 0);
checkAwakeLogo.Checked = !(AppConfig.Get("keyboard_awake_logo") == 0);
checkBootLogo.Checked = !(AppConfig.Get("keyboard_boot_logo") == 0);
checkSleepLogo.Checked = !(AppConfig.Get("keyboard_sleep_logo") == 0);
checkShutdownLogo.Checked = !(AppConfig.Get("keyboard_shutdown_logo") == 0);
checkAwake.CheckedChanged += CheckPower_CheckedChanged;
checkBoot.CheckedChanged += CheckPower_CheckedChanged;
@@ -140,7 +178,7 @@ namespace GHelper
checkSleepLogo.CheckedChanged += CheckPower_CheckedChanged;
checkShutdownLogo.CheckedChanged += CheckPower_CheckedChanged;
if (!Program.config.ContainsModel("Strix"))
if (!AppConfig.ContainsModel("Strix"))
{
labelBacklightBar.Visible = false;
checkAwakeBar.Visible = false;
@@ -148,7 +186,7 @@ namespace GHelper
checkSleepBar.Visible = false;
checkShutdownBar.Visible = false;
if (!Program.config.ContainsModel("Z13"))
if (!AppConfig.ContainsModel("Z13"))
{
labelBacklightLid.Visible = false;
checkAwakeLid.Visible = false;
@@ -164,57 +202,168 @@ namespace GHelper
}
}
checkTopmost.Checked = (Program.config.getConfig("topmost") == 1);
checkTopmost.Checked = AppConfig.Is("topmost");
checkTopmost.CheckedChanged += CheckTopmost_CheckedChanged; ;
checkKeyboardAuto.Checked = (Program.config.getConfig("keyboard_auto") == 1);
checkKeyboardAuto.CheckedChanged += CheckKeyboardAuto_CheckedChanged;
checkNoOverdrive.Checked = (Program.config.getConfig("no_overdrive") == 1);
checkNoOverdrive.Checked = AppConfig.Is("no_overdrive");
checkNoOverdrive.CheckedChanged += CheckNoOverdrive_CheckedChanged;
checkUSBC.Checked = (Program.config.getConfig("optimized_usbc") == 1);
checkUSBC.Checked = AppConfig.Is("optimized_usbc");
checkUSBC.CheckedChanged += CheckUSBC_CheckedChanged;
int kb_brightness = Program.config.getConfig("keyboard_brightness");
trackBrightness.Value = (kb_brightness >= 0 && kb_brightness <= 3) ? kb_brightness : 3;
checkAutoApplyWindowsPowerMode.Checked = (AppConfig.Get("auto_apply_power_plan") != 0);
checkAutoApplyWindowsPowerMode.CheckedChanged += checkAutoApplyWindowsPowerMode_CheckedChanged;
pictureHelp.Click += PictureHelp_Click;
trackBrightness.Value = InputDispatcher.GetBacklight();
trackBrightness.Scroll += TrackBrightness_Scroll;
panelXMG.Visible = (Program.wmi.DeviceGet(ASUSWmi.GPUXGConnected) == 1);
checkXMG.Checked = !(Program.config.getConfig("xmg_light") == 0);
panelXMG.Visible = (Program.acpi.DeviceGet(AsusACPI.GPUXGConnected) == 1);
checkXMG.Checked = !(AppConfig.Get("xmg_light") == 0);
checkXMG.CheckedChanged += CheckXMG_CheckedChanged;
int kb_timeout = Program.config.getConfig("keyboard_light_tiomeout");
numericBacklightTime.Value = (kb_timeout >= 0) ? kb_timeout : 60;
numericBacklightTime.Value = AppConfig.Get("keyboard_timeout", 60);
numericBacklightPluggedTime.Value = AppConfig.Get("keyboard_ac_timeout", 0);
numericBacklightTime.ValueChanged += NumericBacklightTime_ValueChanged;
numericBacklightPluggedTime.ValueChanged += NumericBacklightTime_ValueChanged;
checkGpuApps.Checked = AppConfig.Is("kill_gpu_apps");
checkGpuApps.CheckedChanged += CheckGpuApps_CheckedChanged;
checkFnLock.Checked = AppConfig.Is("fn_lock");
checkFnLock.CheckedChanged += CheckFnLock_CheckedChanged; ;
pictureHelp.Click += PictureHelp_Click;
buttonServices.Click += ButtonServices_Click;
InitVariBright();
InitServices();
}
private void InitServices()
{
if (OptimizationService.IsRunning()) buttonServices.Text = Properties.Strings.Stop;
else buttonServices.Text = Properties.Strings.Start;
labelServices.Text = Properties.Strings.AsusServicesRunning + ": " + OptimizationService.GetRunningCount();
buttonServices.Enabled = true;
}
public void ServiesToggle()
{
buttonServices.Enabled = false;
if (OptimizationService.IsRunning())
{
labelServices.Text = Properties.Strings.StoppingServices + " ...";
Task.Run(() =>
{
OptimizationService.StopAsusServices();
BeginInvoke(delegate
{
InitServices();
});
Program.inputDispatcher.Init();
});
}
else
{
labelServices.Text = Properties.Strings.StartingServices + " ...";
Task.Run(() =>
{
OptimizationService.StartAsusServices();
BeginInvoke(delegate
{
InitServices();
});
});
}
}
private void ButtonServices_Click(object? sender, EventArgs e)
{
if (ProcessHelper.IsUserAdministrator())
ServiesToggle();
else
ProcessHelper.RunAsAdmin("services");
}
private void InitVariBright()
{
try
{
using (var amdControl = new AmdGpuControl())
{
int variBrightSupported = 0, VariBrightEnabled;
if (amdControl.GetVariBright(out variBrightSupported, out VariBrightEnabled))
{
Logger.WriteLine("Varibright: " + variBrightSupported + "," + VariBrightEnabled);
checkVariBright.Checked = (VariBrightEnabled == 3);
}
checkVariBright.Visible = (variBrightSupported > 0);
checkVariBright.CheckedChanged += CheckVariBright_CheckedChanged;
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
checkVariBright.Visible = false;
}
}
private void CheckVariBright_CheckedChanged(object? sender, EventArgs e)
{
using (var amdControl = new AmdGpuControl())
{
amdControl.SetVariBright(checkVariBright.Checked ? 1 : 0);
ProcessHelper.KillByName("RadeonSoftware");
}
}
private void CheckFnLock_CheckedChanged(object? sender, EventArgs e)
{
int fnLock = checkFnLock.Checked ? 1 : 0;
AppConfig.Set("fn_lock", fnLock);
Program.acpi.DeviceSet(AsusACPI.FnLock, (fnLock == 1) ? 0 : 1, "FnLock");
Program.inputDispatcher.RegisterKeys();
}
private void CheckGpuApps_CheckedChanged(object? sender, EventArgs e)
{
AppConfig.Set("kill_gpu_apps", (checkGpuApps.Checked ? 1 : 0));
}
private void NumericBacklightTime_ValueChanged(object? sender, EventArgs e)
{
Program.RunAsAdmin("extra");
Program.config.setConfig("keyboard_light_tiomeout", (int)numericBacklightTime.Value);
Aura.SetBacklightOffDelay((int)numericBacklightTime.Value);
AppConfig.Set("keyboard_timeout", (int)numericBacklightTime.Value);
AppConfig.Set("keyboard_ac_timeout", (int)numericBacklightPluggedTime.Value);
Program.inputDispatcher.InitBacklightTimer();
}
private void CheckXMG_CheckedChanged(object? sender, EventArgs e)
{
Program.config.setConfig("xmg_light", (checkXMG.Checked ? 1 : 0));
Aura.ApplyXGMLight(checkXMG.Checked);
AppConfig.Set("xmg_light", (checkXMG.Checked ? 1 : 0));
AsusUSB.ApplyXGMLight(checkXMG.Checked);
}
private void CheckUSBC_CheckedChanged(object? sender, EventArgs e)
{
Program.config.setConfig("optimized_usbc", (checkUSBC.Checked ? 1 : 0));
AppConfig.Set("optimized_usbc", (checkUSBC.Checked ? 1 : 0));
}
private void TrackBrightness_Scroll(object? sender, EventArgs e)
{
Program.config.setConfig("keyboard_brightness", trackBrightness.Value);
Aura.ApplyBrightness(trackBrightness.Value);
AppConfig.Set("keyboard_brightness", trackBrightness.Value);
AppConfig.Set("keyboard_brightness_ac", trackBrightness.Value);
AsusUSB.ApplyBrightness(trackBrightness.Value, "Slider");
}
private void PictureHelp_Click(object? sender, EventArgs e)
@@ -224,42 +373,38 @@ namespace GHelper
private void CheckNoOverdrive_CheckedChanged(object? sender, EventArgs e)
{
Program.config.setConfig("no_overdrive", (checkNoOverdrive.Checked ? 1 : 0));
Program.settingsForm.AutoScreen(true);
AppConfig.Set("no_overdrive", (checkNoOverdrive.Checked ? 1 : 0));
screenControl.AutoScreen(true);
}
private void CheckKeyboardAuto_CheckedChanged(object? sender, EventArgs e)
{
Program.config.setConfig("keyboard_auto", (checkKeyboardAuto.Checked ? 1 : 0));
}
private void CheckTopmost_CheckedChanged(object? sender, EventArgs e)
{
Program.config.setConfig("topmost", (checkTopmost.Checked ? 1 : 0));
AppConfig.Set("topmost", (checkTopmost.Checked ? 1 : 0));
Program.settingsForm.TopMost = checkTopmost.Checked;
}
private void CheckPower_CheckedChanged(object? sender, EventArgs e)
{
Program.config.setConfig("keyboard_awake", (checkAwake.Checked ? 1 : 0));
Program.config.setConfig("keyboard_boot", (checkBoot.Checked ? 1 : 0));
Program.config.setConfig("keyboard_sleep", (checkSleep.Checked ? 1 : 0));
Program.config.setConfig("keyboard_shutdown", (checkShutdown.Checked ? 1 : 0));
AppConfig.Set("keyboard_awake", (checkAwake.Checked ? 1 : 0));
AppConfig.Set("keyboard_boot", (checkBoot.Checked ? 1 : 0));
AppConfig.Set("keyboard_sleep", (checkSleep.Checked ? 1 : 0));
AppConfig.Set("keyboard_shutdown", (checkShutdown.Checked ? 1 : 0));
Program.config.setConfig("keyboard_awake_bar", (checkAwakeBar.Checked ? 1 : 0));
Program.config.setConfig("keyboard_boot_bar", (checkBootBar.Checked ? 1 : 0));
Program.config.setConfig("keyboard_sleep_bar", (checkSleepBar.Checked ? 1 : 0));
Program.config.setConfig("keyboard_shutdown_bar", (checkShutdownBar.Checked ? 1 : 0));
AppConfig.Set("keyboard_awake_bar", (checkAwakeBar.Checked ? 1 : 0));
AppConfig.Set("keyboard_boot_bar", (checkBootBar.Checked ? 1 : 0));
AppConfig.Set("keyboard_sleep_bar", (checkSleepBar.Checked ? 1 : 0));
AppConfig.Set("keyboard_shutdown_bar", (checkShutdownBar.Checked ? 1 : 0));
Program.config.setConfig("keyboard_awake_lid", (checkAwakeLid.Checked ? 1 : 0));
Program.config.setConfig("keyboard_boot_lid", (checkBootLid.Checked ? 1 : 0));
Program.config.setConfig("keyboard_sleep_lid", (checkSleepLid.Checked ? 1 : 0));
Program.config.setConfig("keyboard_shutdown_lid", (checkShutdownLid.Checked ? 1 : 0));
AppConfig.Set("keyboard_awake_lid", (checkAwakeLid.Checked ? 1 : 0));
AppConfig.Set("keyboard_boot_lid", (checkBootLid.Checked ? 1 : 0));
AppConfig.Set("keyboard_sleep_lid", (checkSleepLid.Checked ? 1 : 0));
AppConfig.Set("keyboard_shutdown_lid", (checkShutdownLid.Checked ? 1 : 0));
Program.config.setConfig("keyboard_awake_logo", (checkAwakeLogo.Checked ? 1 : 0));
Program.config.setConfig("keyboard_boot_logo", (checkBootLogo.Checked ? 1 : 0));
Program.config.setConfig("keyboard_sleep_logo", (checkSleepLogo.Checked ? 1 : 0));
Program.config.setConfig("keyboard_shutdown_logo", (checkShutdownLogo.Checked ? 1 : 0));
AppConfig.Set("keyboard_awake_logo", (checkAwakeLogo.Checked ? 1 : 0));
AppConfig.Set("keyboard_boot_logo", (checkBootLogo.Checked ? 1 : 0));
AppConfig.Set("keyboard_sleep_logo", (checkSleepLogo.Checked ? 1 : 0));
AppConfig.Set("keyboard_shutdown_logo", (checkShutdownLogo.Checked ? 1 : 0));
List<AuraDev19b6> flags = new List<AuraDev19b6>();
@@ -283,21 +428,34 @@ namespace GHelper
if (checkSleepLogo.Checked) flags.Add(AuraDev19b6.SleepLogo);
if (checkShutdownLogo.Checked) flags.Add(AuraDev19b6.ShutdownLogo);
Aura.ApplyAuraPower(flags);
AsusUSB.ApplyAuraPower(flags);
}
private void ComboKeyboardSpeed_SelectedValueChanged(object? sender, EventArgs e)
{
Program.config.setConfig("aura_speed", (int)comboKeyboardSpeed.SelectedValue);
AppConfig.Set("aura_speed", (int)comboKeyboardSpeed.SelectedValue);
Program.settingsForm.SetAura();
}
private void Keyboard_Shown(object? sender, EventArgs e)
{
Top = Program.settingsForm.Top;
if (Height > Program.settingsForm.Height)
{
Top = Program.settingsForm.Top + Program.settingsForm.Height - Height;
}
else
{
Top = Program.settingsForm.Top;
}
Left = Program.settingsForm.Left - Width - 5;
}
private void checkAutoApplyWindowsPowerMode_CheckedChanged(object? sender, EventArgs e)
{
AppConfig.Set("auto_apply_power_plan", checkAutoApplyWindowsPowerMode.Checked ? 1 : 0);
}
}
}

View File

@@ -1,4 +1,64 @@
<root>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">

1312
app/Fans.Designer.cs generated

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,64 @@
<root>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
@@ -57,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="labelRisky.Text" xml:space="preserve">
<value>Undervolting is experimental and risky feature. If applied values are too low for your hardware, it can become unstable or shut down. Try small negative values first, click Apply and test what works for you.</value>
</data>
</root>

View File

@@ -16,7 +16,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.60</AssemblyVersion>
<AssemblyVersion>0.95</AssemblyVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -59,8 +59,11 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="FftSharp" Version="2.0.0" />
<PackageReference Include="hidlibrary" Version="3.3.40" />
<PackageReference Include="HidSharpCore" Version="1.2.1.1" />
<PackageReference Include="NAudio" Version="2.1.0" />
<PackageReference Include="NvAPIWrapper.Net" Version="0.8.1.101" />
<PackageReference Include="System.Management" Version="7.0.1" />
<PackageReference Include="TaskScheduler" Version="2.10.1" />
<PackageReference Include="WinForms.DataVisualization" Version="1.8.0" />
@@ -131,6 +134,12 @@
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<None Update="WinRing0x64.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="WinRing0x64.sys">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -1,18 +1,47 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using static GHelper.Gpu.AMD.Adl2.NativeMethods;
namespace AmdAdl2;
namespace GHelper.Gpu.AMD;
#region Export Struct
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct ADLSGApplicationInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string strFileName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string strFilePath;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string strVersion;
public long timeStamp;
public uint iProfileExists;
public uint iGPUAffinity;
public ADLBdf GPUBdf;
}
[StructLayout(LayoutKind.Sequential)]
public struct ADLSingleSensorData {
public struct ADLBdf
{
public int iBus;
public int iDevice;
public int iFunction;
}
[StructLayout(LayoutKind.Sequential)]
public struct ADLSingleSensorData
{
public int Supported;
public int Value;
}
[StructLayout(LayoutKind.Sequential)]
public struct ADLPMLogDataOutput {
public struct ADLPMLogDataOutput
{
int Size;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = Adl2.ADL_PMLOG_MAX_SENSORS)]
@@ -30,7 +59,8 @@ public struct ADLGcnInfo
}
[Flags]
public enum ADLAsicFamilyType {
public enum ADLAsicFamilyType
{
Undefined = 0,
Discrete = 1 << 0,
Integrated = 1 << 1,
@@ -42,7 +72,8 @@ public enum ADLAsicFamilyType {
Embedded = 1 << 7,
}
public enum ADLSensorType {
public enum ADLSensorType
{
SENSOR_MAXTYPES = 0,
PMLOG_CLK_GFXCLK = 1, // Current graphic clock value in MHz
PMLOG_CLK_MEMCLK = 2, // Current memory clock value in MHz
@@ -122,13 +153,15 @@ public enum ADLSensorType {
//Throttle Status
[Flags]
public enum ADL_THROTTLE_NOTIFICATION {
public enum ADL_THROTTLE_NOTIFICATION
{
ADL_PMLOG_THROTTLE_POWER = 1 << 0,
ADL_PMLOG_THROTTLE_THERMAL = 1 << 1,
ADL_PMLOG_THROTTLE_CURRENT = 1 << 2,
};
public enum ADL_PMLOG_SENSORS {
public enum ADL_PMLOG_SENSORS
{
ADL_SENSOR_MAXTYPES = 0,
ADL_PMLOG_CLK_GFXCLK = 1,
ADL_PMLOG_CLK_MEMCLK = 2,
@@ -210,7 +243,8 @@ public enum ADL_PMLOG_SENSORS {
/// <summary> ADLAdapterInfo Structure</summary>
[StructLayout(LayoutKind.Sequential)]
public struct ADLAdapterInfo {
public struct ADLAdapterInfo
{
/// <summary>The size of the structure</summary>
int Size;
@@ -265,7 +299,8 @@ public struct ADLAdapterInfo {
/// <summary> ADLAdapterInfo Array</summary>
[StructLayout(LayoutKind.Sequential)]
public struct ADLAdapterInfoArray {
public struct ADLAdapterInfoArray
{
/// <summary> ADLAdapterInfo Array </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = Adl2.ADL_MAX_ADAPTERS)]
public ADLAdapterInfo[] ADLAdapterInfo;
@@ -277,7 +312,8 @@ public struct ADLAdapterInfoArray {
/// <summary> ADLDisplayID Structure</summary>
[StructLayout(LayoutKind.Sequential)]
public struct ADLDisplayID {
public struct ADLDisplayID
{
/// <summary> Display Logical Index </summary>
public int DisplayLogicalIndex;
@@ -293,7 +329,8 @@ public struct ADLDisplayID {
/// <summary> ADLDisplayInfo Structure</summary>
[StructLayout(LayoutKind.Sequential)]
public struct ADLDisplayInfo {
public struct ADLDisplayInfo
{
/// <summary> Display Index </summary>
public ADLDisplayID DisplayID;
@@ -328,7 +365,8 @@ public struct ADLDisplayInfo {
#endregion Export Struct
public class Adl2 {
public class Adl2
{
public const string Atiadlxx_FileName = "atiadlxx.dll";
#region Internal Constant
@@ -371,24 +409,30 @@ public class Adl2 {
// ///// <summary> ADL Create Function to create ADL Data</summary>
/// <param name="enumConnectedAdapters">If it is 1, then ADL will only return the physical exist adapters </param>
///// <returns> retrun ADL Error Code</returns>
public static int ADL2_Main_Control_Create(int enumConnectedAdapters, out IntPtr adlContextHandle) {
public static int ADL2_Main_Control_Create(int enumConnectedAdapters, out nint adlContextHandle)
{
return NativeMethods.ADL2_Main_Control_Create(ADL_Main_Memory_Alloc_Impl_Reference, enumConnectedAdapters, out adlContextHandle);
}
public static void FreeMemory(IntPtr buffer) {
public static void FreeMemory(nint buffer)
{
Memory_Free_Impl(buffer);
}
private static bool? isDllLoaded;
public static bool Load() {
public static bool Load()
{
if (isDllLoaded != null)
return isDllLoaded.Value;
try {
try
{
Marshal.PrelinkAll(typeof(Adl2));
isDllLoaded = true;
} catch (Exception e) when (e is DllNotFoundException or EntryPointNotFoundException) {
}
catch (Exception e) when (e is DllNotFoundException or EntryPointNotFoundException)
{
Debug.WriteLine(e);
isDllLoaded = false;
}
@@ -396,53 +440,57 @@ public class Adl2 {
return isDllLoaded.Value;
}
private static NativeMethods.ADL_Main_Memory_Alloc ADL_Main_Memory_Alloc_Impl_Reference = Memory_Alloc_Impl;
private static ADL_Main_Memory_Alloc ADL_Main_Memory_Alloc_Impl_Reference = Memory_Alloc_Impl;
/// <summary> Build in memory allocation function</summary>
/// <param name="size">input size</param>
/// <returns>return the memory buffer</returns>
private static IntPtr Memory_Alloc_Impl(int size) {
private static nint Memory_Alloc_Impl(int size)
{
return Marshal.AllocCoTaskMem(size);
}
/// <summary> Build in memory free function</summary>
/// <param name="buffer">input buffer</param>
private static void Memory_Free_Impl(IntPtr buffer) {
if (IntPtr.Zero != buffer) {
private static void Memory_Free_Impl(nint buffer)
{
if (nint.Zero != buffer)
{
Marshal.FreeCoTaskMem(buffer);
}
}
public static class NativeMethods {
public static class NativeMethods
{
/// <summary> ADL Memory allocation function allows ADL to callback for memory allocation</summary>
/// <param name="size">input size</param>
/// <returns> retrun ADL Error Code</returns>
public delegate IntPtr ADL_Main_Memory_Alloc(int size);
public delegate nint ADL_Main_Memory_Alloc(int size);
// ///// <summary> ADL Create Function to create ADL Data</summary>
/// <param name="callback">Call back functin pointer which is ised to allocate memeory </param>
/// <param name="enumConnectedAdapters">If it is 1, then ADL will only retuen the physical exist adapters </param>
///// <returns> retrun ADL Error Code</returns>
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_Main_Control_Create(ADL_Main_Memory_Alloc callback, int enumConnectedAdapters, out IntPtr adlContextHandle);
public static extern int ADL2_Main_Control_Create(ADL_Main_Memory_Alloc callback, int enumConnectedAdapters, out nint adlContextHandle);
/// <summary> ADL Destroy Function to free up ADL Data</summary>
/// <returns> retrun ADL Error Code</returns>
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_Main_Control_Destroy(IntPtr adlContextHandle);
public static extern int ADL2_Main_Control_Destroy(nint adlContextHandle);
/// <summary> ADL Function to get the number of adapters</summary>
/// <param name="numAdapters">return number of adapters</param>
/// <returns> retrun ADL Error Code</returns>
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_Adapter_NumberOfAdapters_Get(IntPtr adlContextHandle, out int numAdapters);
public static extern int ADL2_Adapter_NumberOfAdapters_Get(nint adlContextHandle, out int numAdapters);
/// <summary> ADL Function to get the GPU adapter information</summary>
/// <param name="info">return GPU adapter information</param>
/// <param name="inputSize">the size of the GPU adapter struct</param>
/// <returns> retrun ADL Error Code</returns>
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_Adapter_AdapterInfo_Get(IntPtr adlContextHandle, IntPtr info, int inputSize);
public static extern int ADL2_Adapter_AdapterInfo_Get(nint adlContextHandle, nint info, int inputSize);
/// <summary> Function to determine if the adapter is active or not.</summary>
/// <remarks>The function is used to check if the adapter associated with iAdapterIndex is active</remarks>
@@ -450,7 +498,7 @@ public class Adl2 {
/// <param name="status"> Status of the adapter. True: Active; False: Dsiabled</param>
/// <returns>Non zero is successfull</returns>
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_Adapter_Active_Get(IntPtr adlContextHandle, int adapterIndex, out int status);
public static extern int ADL2_Adapter_Active_Get(nint adlContextHandle, int adapterIndex, out int status);
/// <summary>Get display information based on adapter index</summary>
/// <param name="adapterIndex">Adapter Index</param>
@@ -460,16 +508,16 @@ public class Adl2 {
/// <returns>return ADL Error Code</returns>
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_Display_DisplayInfo_Get(
IntPtr adlContextHandle,
nint adlContextHandle,
int adapterIndex,
out int numDisplays,
out IntPtr displayInfoArray,
out nint displayInfoArray,
int forceDetect
);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_Overdrive_Caps(
IntPtr adlContextHandle,
nint adlContextHandle,
int adapterIndex,
out int supported,
out int enabled,
@@ -477,9 +525,75 @@ public class Adl2 {
);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_New_QueryPMLogData_Get(IntPtr adlContextHandle, int adapterIndex, out ADLPMLogDataOutput adlpmLogDataOutput);
public static extern int ADL2_New_QueryPMLogData_Get(nint adlContextHandle, int adapterIndex, out ADLPMLogDataOutput adlpmLogDataOutput);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_Adapter_ASICFamilyType_Get(IntPtr adlContextHandle, int adapterIndex, out ADLAsicFamilyType asicFamilyType, out int asicFamilyTypeValids);
public static extern int ADL2_Adapter_ASICFamilyType_Get(nint adlContextHandle, int adapterIndex, out ADLAsicFamilyType asicFamilyType, out int asicFamilyTypeValids);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_SwitchableGraphics_Applications_Get(
nint context,
int iListType,
out int lpNumApps,
out nint lppAppList);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_Adapter_VariBright_Caps(
nint context,
int iAdapterIndex,
out int iSupported,
out int iEnabled,
out int iVersion);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_Adapter_VariBrightEnable_Set(
nint context,
int iAdapterIndex,
int iEnabled);
// Clocks
[StructLayout(LayoutKind.Sequential)]
public struct ADLODNPerformanceLevel
{
public int iClock;
public int iVddc;
public int iEnabled;
}
[StructLayout(LayoutKind.Sequential)]
public struct ADLODNPerformanceLevels
{
public int iSize;
public int iMode;
public int iNumberOfPerformanceLevels;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public ADLODNPerformanceLevel[] aLevels;
}
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_OverdriveN_SystemClocks_Get(
nint context,
int adapterIndex,
ref ADLODNPerformanceLevels performanceLevels);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_OverdriveN_SystemClocks_Set(
nint context,
int adapterIndex,
ref ADLODNPerformanceLevels performanceLevels);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_OverdriveN_MemoryClocks_Get(
nint context,
int adapterIndex,
ref ADLODNPerformanceLevels performanceLevels);
[DllImport(Atiadlxx_FileName)]
public static extern int ADL2_OverdriveN_MemoryClocks_Set(
nint context,
int adapterIndex,
ref ADLODNPerformanceLevels performanceLevels);
}
}

View File

@@ -0,0 +1,234 @@
using GHelper.Helpers;
using System.Runtime.InteropServices;
using static GHelper.Gpu.AMD.Adl2.NativeMethods;
namespace GHelper.Gpu.AMD;
// Reference: https://github.com/GPUOpen-LibrariesAndSDKs/display-library/blob/master/Sample-Managed/Program.cs
public class AmdGpuControl : IGpuControl
{
private bool _isReady;
private nint _adlContextHandle;
private readonly ADLAdapterInfo _internalDiscreteAdapter;
public bool IsNvidia => false;
public string FullName => _internalDiscreteAdapter!.AdapterName;
private ADLAdapterInfo? FindByType(ADLAsicFamilyType type = ADLAsicFamilyType.Discrete)
{
ADL2_Adapter_NumberOfAdapters_Get(_adlContextHandle, out int numberOfAdapters);
if (numberOfAdapters <= 0)
return null;
ADLAdapterInfoArray osAdapterInfoData = new();
int osAdapterInfoDataSize = Marshal.SizeOf(osAdapterInfoData);
nint AdapterBuffer = Marshal.AllocCoTaskMem(osAdapterInfoDataSize);
Marshal.StructureToPtr(osAdapterInfoData, AdapterBuffer, false);
if (ADL2_Adapter_AdapterInfo_Get(_adlContextHandle, AdapterBuffer, osAdapterInfoDataSize) != Adl2.ADL_SUCCESS)
return null;
osAdapterInfoData = (ADLAdapterInfoArray)Marshal.PtrToStructure(AdapterBuffer, osAdapterInfoData.GetType())!;
const int amdVendorId = 1002;
// Determine which GPU is internal discrete AMD GPU
ADLAdapterInfo internalDiscreteAdapter =
osAdapterInfoData.ADLAdapterInfo
.FirstOrDefault(adapter =>
{
if (adapter.Exist == 0 || adapter.Present == 0)
return false;
if (adapter.VendorID != amdVendorId)
return false;
if (ADL2_Adapter_ASICFamilyType_Get(_adlContextHandle, adapter.AdapterIndex, out ADLAsicFamilyType asicFamilyType, out int asicFamilyTypeValids) != Adl2.ADL_SUCCESS)
return false;
asicFamilyType = (ADLAsicFamilyType)((int)asicFamilyType & asicFamilyTypeValids);
return (asicFamilyType & type) != 0;
});
if (internalDiscreteAdapter.Exist == 0)
return null;
return internalDiscreteAdapter;
}
public AmdGpuControl()
{
if (!Adl2.Load())
return;
if (Adl2.ADL2_Main_Control_Create(1, out _adlContextHandle) != Adl2.ADL_SUCCESS)
return;
ADLAdapterInfo? internalDiscreteAdapter = FindByType(ADLAsicFamilyType.Discrete);
if (internalDiscreteAdapter is not null)
{
_internalDiscreteAdapter = (ADLAdapterInfo)internalDiscreteAdapter;
_isReady = true;
}
}
public bool IsValid => _isReady && _adlContextHandle != nint.Zero;
public int? GetCurrentTemperature()
{
if (!IsValid)
return null;
if (ADL2_New_QueryPMLogData_Get(_adlContextHandle, _internalDiscreteAdapter.AdapterIndex, out ADLPMLogDataOutput adlpmLogDataOutput) != Adl2.ADL_SUCCESS)
return null;
ADLSingleSensorData temperatureSensor = adlpmLogDataOutput.Sensors[(int)ADLSensorType.PMLOG_TEMPERATURE_EDGE];
if (temperatureSensor.Supported == 0)
return null;
return temperatureSensor.Value;
}
public int? GetGpuUse()
{
if (!IsValid) return null;
if (ADL2_New_QueryPMLogData_Get(_adlContextHandle, _internalDiscreteAdapter.AdapterIndex, out ADLPMLogDataOutput adlpmLogDataOutput) != Adl2.ADL_SUCCESS)
return null;
ADLSingleSensorData gpuUsage = adlpmLogDataOutput.Sensors[(int)ADLSensorType.PMLOG_INFO_ACTIVITY_GFX];
if (gpuUsage.Supported == 0)
return null;
return gpuUsage.Value;
}
public bool SetVariBright(int enabled)
{
if (_adlContextHandle == nint.Zero) return false;
ADLAdapterInfo? iGPU = FindByType(ADLAsicFamilyType.Integrated);
if (iGPU is null) return false;
return ADL2_Adapter_VariBrightEnable_Set(_adlContextHandle, ((ADLAdapterInfo)iGPU).AdapterIndex, enabled) == Adl2.ADL_SUCCESS;
}
public bool GetVariBright(out int supported, out int enabled)
{
supported = enabled = -1;
if (_adlContextHandle == nint.Zero) return false;
ADLAdapterInfo? iGPU = FindByType(ADLAsicFamilyType.Integrated);
if (iGPU is null) return false;
if (ADL2_Adapter_VariBright_Caps(_adlContextHandle, ((ADLAdapterInfo)iGPU).AdapterIndex, out int supportedOut, out int enabledOut, out int version) != Adl2.ADL_SUCCESS)
return false;
supported = supportedOut;
enabled = enabledOut;
return true;
}
public ADLODNPerformanceLevels? GetGPUClocks()
{
if (!IsValid) return null;
ADLODNPerformanceLevels performanceLevels = new();
ADL2_OverdriveN_SystemClocks_Get(_adlContextHandle, _internalDiscreteAdapter.AdapterIndex, ref performanceLevels);
return performanceLevels;
}
public void KillGPUApps()
{
if (!IsValid) return;
nint appInfoPtr = nint.Zero;
int appCount = 0;
try
{
// Get switchable graphics applications information
var result = ADL2_SwitchableGraphics_Applications_Get(_adlContextHandle, 2, out appCount, out appInfoPtr);
if (result != 0)
{
throw new Exception("Failed to get switchable graphics applications. Error code: " + result);
}
// Convert the application data pointers to an array of structs
var appInfoArray = new ADLSGApplicationInfo[appCount];
nint currentPtr = appInfoPtr;
for (int i = 0; i < appCount; i++)
{
appInfoArray[i] = Marshal.PtrToStructure<ADLSGApplicationInfo>(currentPtr);
currentPtr = nint.Add(currentPtr, Marshal.SizeOf<ADLSGApplicationInfo>());
}
var appNames = new List<string>();
for (int i = 0; i < appCount; i++)
{
if (appInfoArray[i].iGPUAffinity == 1)
{
Logger.WriteLine(appInfoArray[i].strFileName + ":" + appInfoArray[i].iGPUAffinity + "(" + appInfoArray[i].timeStamp + ")");
appNames.Add(Path.GetFileNameWithoutExtension(appInfoArray[i].strFileName));
}
}
List<string> immune = new() { "svchost", "system", "ntoskrnl", "csrss", "winlogon", "wininit", "smss" };
foreach (string kill in appNames)
if (!immune.Contains(kill.ToLower()))
ProcessHelper.KillByName(kill);
}
catch (Exception ex)
{
Logger.WriteLine(ex.Message);
}
finally
{
// Clean up resources
if (appInfoPtr != nint.Zero)
{
Marshal.FreeCoTaskMem(appInfoPtr);
}
}
}
private void ReleaseUnmanagedResources()
{
if (_adlContextHandle != nint.Zero)
{
ADL2_Main_Control_Destroy(_adlContextHandle);
_adlContextHandle = nint.Zero;
_isReady = false;
}
}
public void Dispose()
{
ReleaseUnmanagedResources();
GC.SuppressFinalize(this);
}
~AmdGpuControl()
{
ReleaseUnmanagedResources();
}
}

View File

@@ -1,113 +0,0 @@
using System.Runtime.InteropServices;
using AmdAdl2;
namespace GHelper.Gpu;
// Reference: https://github.com/GPUOpen-LibrariesAndSDKs/display-library/blob/master/Sample-Managed/Program.cs
public class AmdGpuControl : IGpuControl {
private bool _isReady;
private IntPtr _adlContextHandle;
private readonly ADLAdapterInfo _internalDiscreteAdapter;
public bool IsNvidia => false;
public AmdGpuControl() {
if (!Adl2.Load())
return;
if (Adl2.ADL2_Main_Control_Create(1, out _adlContextHandle) != Adl2.ADL_SUCCESS)
return;
Adl2.NativeMethods.ADL2_Adapter_NumberOfAdapters_Get(_adlContextHandle, out int numberOfAdapters);
if (numberOfAdapters <= 0)
return;
ADLAdapterInfoArray osAdapterInfoData = new();
int osAdapterInfoDataSize = Marshal.SizeOf(osAdapterInfoData);
IntPtr AdapterBuffer = Marshal.AllocCoTaskMem(osAdapterInfoDataSize);
Marshal.StructureToPtr(osAdapterInfoData, AdapterBuffer, false);
if (Adl2.NativeMethods.ADL2_Adapter_AdapterInfo_Get(_adlContextHandle, AdapterBuffer, osAdapterInfoDataSize) != Adl2.ADL_SUCCESS)
return;
osAdapterInfoData = (ADLAdapterInfoArray) Marshal.PtrToStructure(AdapterBuffer, osAdapterInfoData.GetType())!;
const int amdVendorId = 1002;
// Determine which GPU is internal discrete AMD GPU
ADLAdapterInfo internalDiscreteAdapter =
osAdapterInfoData.ADLAdapterInfo
.FirstOrDefault(adapter => {
if (adapter.Exist == 0 || adapter.Present == 0)
return false;
if (adapter.VendorID != amdVendorId)
return false;
if (Adl2.NativeMethods.ADL2_Adapter_ASICFamilyType_Get(_adlContextHandle, adapter.AdapterIndex, out ADLAsicFamilyType asicFamilyType, out int asicFamilyTypeValids) != Adl2.ADL_SUCCESS)
return false;
asicFamilyType = (ADLAsicFamilyType) ((int) asicFamilyType & asicFamilyTypeValids);
// FIXME: is this correct for G14 2022?
return (asicFamilyType & ADLAsicFamilyType.Discrete) != 0;
});
if (internalDiscreteAdapter.Exist == 0)
return;
_internalDiscreteAdapter = internalDiscreteAdapter;
_isReady = true;
}
public bool IsValid => _isReady && _adlContextHandle != IntPtr.Zero;
public int? GetCurrentTemperature() {
if (!IsValid)
return null;
if (Adl2.NativeMethods.ADL2_New_QueryPMLogData_Get(_adlContextHandle, _internalDiscreteAdapter.AdapterIndex, out ADLPMLogDataOutput adlpmLogDataOutput) != Adl2.ADL_SUCCESS)
return null;
ADLSingleSensorData temperatureSensor = adlpmLogDataOutput.Sensors[(int) ADLSensorType.PMLOG_TEMPERATURE_EDGE];
if (temperatureSensor.Supported == 0)
return null;
return temperatureSensor.Value;
}
public int? GetGpuUse()
{
if (!IsValid)
return null;
if (Adl2.NativeMethods.ADL2_New_QueryPMLogData_Get(_adlContextHandle, _internalDiscreteAdapter.AdapterIndex, out ADLPMLogDataOutput adlpmLogDataOutput) != Adl2.ADL_SUCCESS)
return null;
ADLSingleSensorData gpuUsage = adlpmLogDataOutput.Sensors[(int)ADLSensorType.PMLOG_INFO_ACTIVITY_GFX];
if (gpuUsage.Supported == 0)
return null;
return gpuUsage.Value;
}
private void ReleaseUnmanagedResources() {
if (_adlContextHandle != IntPtr.Zero) {
Adl2.NativeMethods.ADL2_Main_Control_Destroy(_adlContextHandle);
_adlContextHandle = IntPtr.Zero;
_isReady = false;
}
}
public void Dispose() {
ReleaseUnmanagedResources();
GC.SuppressFinalize(this);
}
~AmdGpuControl() {
ReleaseUnmanagedResources();
}
}

325
app/Gpu/GPUModeControl.cs Normal file
View File

@@ -0,0 +1,325 @@
using GHelper.Display;
using GHelper.Gpu.NVidia;
using GHelper.Helpers;
using System.Diagnostics;
namespace GHelper.Gpu
{
public class GPUModeControl
{
SettingsForm settings;
ScreenControl screenControl = new ScreenControl();
public GPUModeControl(SettingsForm settingsForm)
{
settings = settingsForm;
}
public void InitGPUMode()
{
int eco = Program.acpi.DeviceGet(AsusACPI.GPUEco);
int mux = Program.acpi.DeviceGet(AsusACPI.GPUMux);
Logger.WriteLine("Eco flag : " + eco);
Logger.WriteLine("Mux flag : " + mux);
int GpuMode;
if (mux == 0)
{
GpuMode = AsusACPI.GPUModeUltimate;
}
else
{
if (eco == 1)
GpuMode = AsusACPI.GPUModeEco;
else
GpuMode = AsusACPI.GPUModeStandard;
// Ultimate mode not suported
if (mux != 1) settings.HideUltimateMode();
// GPU mode not supported
if (eco < 0 && mux < 0) settings.HideGPUModes();
}
AppConfig.Set("gpu_mode", GpuMode);
InitXGM();
settings.VisualiseGPUMode(GpuMode);
}
public void SetGPUMode(int GPUMode)
{
int CurrentGPU = AppConfig.Get("gpu_mode");
AppConfig.Set("gpu_auto", 0);
if (CurrentGPU == GPUMode)
{
settings.VisualiseGPUMode();
return;
}
var restart = false;
var changed = false;
if (CurrentGPU == AsusACPI.GPUModeUltimate)
{
DialogResult dialogResult = MessageBox.Show(Properties.Strings.AlertUltimateOff, Properties.Strings.AlertUltimateTitle, MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
Program.acpi.DeviceSet(AsusACPI.GPUMux, 1, "GPUMux");
restart = true;
changed = true;
}
}
else if (GPUMode == AsusACPI.GPUModeUltimate)
{
DialogResult dialogResult = MessageBox.Show(Properties.Strings.AlertUltimateOn, Properties.Strings.AlertUltimateTitle, MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
Program.acpi.DeviceSet(AsusACPI.GPUMux, 0, "GPUMux");
restart = true;
changed = true;
}
}
else if (GPUMode == AsusACPI.GPUModeEco)
{
settings.VisualiseGPUMode(GPUMode);
SetGPUEco(1, true);
changed = true;
}
else if (GPUMode == AsusACPI.GPUModeStandard)
{
settings.VisualiseGPUMode(GPUMode);
SetGPUEco(0);
changed = true;
}
if (changed)
{
AppConfig.Set("gpu_mode", GPUMode);
}
if (restart)
{
settings.VisualiseGPUMode();
Process.Start("shutdown", "/r /t 1");
}
}
public void SetGPUEco(int eco, bool hardWay = false)
{
settings.LockGPUModes();
Task.Run(async () =>
{
int status = 1;
if (eco == 1)
{
if (NvidiaSmi.GetDisplayActiveStatus())
{
DialogResult dialogResult = MessageBox.Show(Properties.Strings.EnableOptimusText, Properties.Strings.EnableOptimusTitle, MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.No)
{
InitGPUMode();
return;
}
}
HardwareControl.KillGPUApps();
}
Logger.WriteLine($"Running eco command {eco}");
status = Program.acpi.SetGPUEco(eco);
if (status == 0 && eco == 1 && hardWay) RestartGPU();
await Task.Delay(TimeSpan.FromMilliseconds(100));
settings.Invoke(delegate
{
InitGPUMode();
screenControl.AutoScreen();
});
if (eco == 0)
{
await Task.Delay(TimeSpan.FromMilliseconds(3000));
HardwareControl.RecreateGpuControl();
Program.modeControl.SetGPUClocks(false);
}
});
}
public static bool IsPlugged()
{
bool optimizedUSBC = AppConfig.Get("optimized_usbc") != 1;
return SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online &&
(optimizedUSBC || Program.acpi.DeviceGet(AsusACPI.ChargerMode) < AsusACPI.ChargerUSB);
}
public bool AutoGPUMode(bool optimized = false)
{
bool GpuAuto = AppConfig.Is("gpu_auto");
bool ForceGPU = AppConfig.ContainsModel("503");
int GpuMode = AppConfig.Get("gpu_mode");
if (!GpuAuto && !ForceGPU) return false;
int eco = Program.acpi.DeviceGet(AsusACPI.GPUEco);
int mux = Program.acpi.DeviceGet(AsusACPI.GPUMux);
if (mux == 0)
{
if (optimized) SetGPUMode(AsusACPI.GPUModeStandard);
return false;
}
else
{
if (ReEnableGPU()) return true;
if (eco == 1)
if ((GpuAuto && IsPlugged()) || (ForceGPU && GpuMode == AsusACPI.GPUModeStandard))
{
SetGPUEco(0);
return true;
}
if (eco == 0)
if ((GpuAuto && !IsPlugged()) || (ForceGPU && GpuMode == AsusACPI.GPUModeEco))
{
if (HardwareControl.IsUsedGPU())
{
DialogResult dialogResult = MessageBox.Show(Properties.Strings.AlertDGPU, Properties.Strings.AlertDGPUTitle, MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.No) return false;
}
SetGPUEco(1);
return true;
}
}
return false;
}
public void RestartGPU(bool confirm = true)
{
if (HardwareControl.GpuControl is null) return;
if (!HardwareControl.GpuControl!.IsNvidia) return;
if (confirm)
{
DialogResult dialogResult = MessageBox.Show(Properties.Strings.RestartGPU, Properties.Strings.EcoMode, MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.No) return;
}
ProcessHelper.RunAsAdmin("gpurestart");
if (!ProcessHelper.IsUserAdministrator()) return;
Logger.WriteLine("Trying to restart dGPU");
Task.Run(async () =>
{
settings.LockGPUModes("Restarting GPU ...");
var nvControl = (NvidiaGpuControl)HardwareControl.GpuControl;
bool status = nvControl.RestartGPU();
settings.Invoke(delegate
{
//labelTipGPU.Text = status ? "GPU Restarted, you can try Eco mode again" : "Failed to restart GPU"; TODO
InitGPUMode();
});
});
}
public bool ReEnableGPU()
{
if (AppConfig.Get("gpu_reenable") != 1) return false;
if (Screen.AllScreens.Length <= 1) return false;
Logger.WriteLine("Re-enabling gpu for 503 model");
Thread.Sleep(1000);
SetGPUEco(1);
Thread.Sleep(1000);
SetGPUEco(0);
return true;
}
public void InitXGM()
{
bool connected = Program.acpi.IsXGConnected();
int activated = Program.acpi.DeviceGet(AsusACPI.GPUXG);
settings.VisualizeXGM(connected, activated == 1);
}
public void ToggleXGM()
{
Task.Run(async () =>
{
settings.LockGPUModes();
if (Program.acpi.DeviceGet(AsusACPI.GPUXG) == 1)
{
HardwareControl.KillGPUApps();
DialogResult dialogResult = MessageBox.Show("Did you close all applications running on XG Mobile?", "Disabling XG Mobile", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
Program.acpi.DeviceSet(AsusACPI.GPUXG, 0, "GPU XGM");
await Task.Delay(TimeSpan.FromSeconds(15));
}
}
else
{
Program.acpi.DeviceSet(AsusACPI.GPUXG, 1, "GPU XGM");
AsusUSB.ApplyXGMLight(AppConfig.Is("xmg_light"));
await Task.Delay(TimeSpan.FromSeconds(15));
if (AppConfig.IsMode("auto_apply"))
AsusUSB.SetXGMFan(AppConfig.GetFanConfig(AsusFan.XGM));
}
settings.Invoke(delegate
{
InitGPUMode();
});
});
}
public void KillGPUApps()
{
if (HardwareControl.GpuControl is not null)
{
HardwareControl.GpuControl.KillGPUApps();
}
}
}
}

View File

@@ -3,6 +3,9 @@
public interface IGpuControl : IDisposable {
bool IsNvidia { get; }
bool IsValid { get; }
public string FullName { get; }
int? GetCurrentTemperature();
int? GetGpuUse();
void KillGPUApps();
}

View File

@@ -1,21 +1,19 @@
using NvAPIWrapper.GPU;
using GHelper.Helpers;
using NvAPIWrapper.GPU;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.Delegates;
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
using NvAPIWrapper.Native.Interfaces.GPU;
using System;
using System.Diagnostics;
using System.Management;
using static NvAPIWrapper.Native.GPU.Structures.PerformanceStates20InfoV1;
namespace GHelper.Gpu;
namespace GHelper.Gpu.NVidia;
public class NvidiaGpuControl : IGpuControl
{
public const int MaxCoreOffset = 250;
public const int MaxMemoryOffset = 250;
public static int MaxCoreOffset => AppConfig.Get("max_gpu_core", 250);
public static int MaxMemoryOffset => AppConfig.Get("max_gpu_memory", 250);
public const int MinCoreOffset = -250;
public const int MinMemoryOffset = -250;
@@ -31,10 +29,11 @@ public class NvidiaGpuControl : IGpuControl
public bool IsNvidia => IsValid;
public string FullName => _internalGpu!.FullName;
public int? GetCurrentTemperature()
{
if (!IsValid)
return null;
if (!IsValid) return null;
PhysicalGPU internalGpu = _internalGpu!;
IThermalSensor? gpuSensor =
@@ -48,12 +47,38 @@ public class NvidiaGpuControl : IGpuControl
{
}
public int GetClocks(out int core, out int memory, out string gpu)
public void KillGPUApps()
{
if (!IsValid) return;
PhysicalGPU internalGpu = _internalGpu!;
gpu = internalGpu.FullName;
try
{
Process[] processes = internalGpu.GetActiveApplications();
foreach (Process process in processes)
try
{
Logger.WriteLine("Kill:" + process.ProcessName);
ProcessHelper.KillByProcess(process);
}
catch (Exception ex)
{
Logger.WriteLine(ex.Message);
}
}
catch (Exception ex)
{
Logger.WriteLine(ex.Message);
}
//NVIDIA.RestartDisplayDriver();
}
public int GetClocks(out int core, out int memory)
{
PhysicalGPU internalGpu = _internalGpu!;
//Logger.WriteLine(internalGpu.FullName);
//Logger.WriteLine(internalGpu.ArchitectInformation.ToString());
@@ -63,50 +88,37 @@ public class NvidiaGpuControl : IGpuControl
IPerformanceStates20Info states = GPUApi.GetPerformanceStates20(internalGpu.Handle);
core = states.Clocks[PerformanceStateId.P0_3DPerformance][0].FrequencyDeltaInkHz.DeltaValue / 1000;
memory = states.Clocks[PerformanceStateId.P0_3DPerformance][1].FrequencyDeltaInkHz.DeltaValue / 1000;
Logger.WriteLine($"GET GPU Clock offsets : {core}, {memory}");
Logger.WriteLine($"GET GPU CLOCKS: {core}, {memory}");
foreach (var delta in states.Voltages[PerformanceStateId.P0_3DPerformance])
{
Logger.WriteLine("GPU VOLT:" + delta.IsEditable + " - " + delta.ValueDeltaInMicroVolt.DeltaValue);
}
return 0;
} catch (Exception ex)
}
catch (Exception ex)
{
Logger.WriteLine(ex.Message);
core = memory = 0;
Logger.WriteLine("GET GPU CLOCKS:" + ex.Message);
core = memory = 0;
return -1;
}
}
private static void RunCMD(string name, string args)
{
var cmd = new Process();
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmd.StartInfo.FileName = name;
cmd.StartInfo.Arguments = args;
cmd.Start();
Logger.WriteLine(cmd.StandardOutput.ReadToEnd());
cmd.WaitForExit();
}
public bool RestartGPU()
{
if (!IsValid) return false;
try
{
PhysicalGPU internalGpu = _internalGpu!;
var pnpDeviceId = internalGpu.BusInformation.PCIIdentifiers.ToString();
Logger.WriteLine("Device ID:"+ pnpDeviceId);
RunCMD("pnputil", $"/disable-device /deviceid \"{pnpDeviceId}\"");
Thread.Sleep(3000);
RunCMD("pnputil", $"/enable-device /deviceid \"{pnpDeviceId}\"");
Thread.Sleep(2000);
string script = @"$device = Get-PnpDevice | Where-Object { $_.FriendlyName -imatch 'NVIDIA' -and $_.Class -eq 'Display' }; Disable-PnpDevice $device.InstanceId -Confirm:$false; Start-Sleep -Seconds 3; Enable-PnpDevice $device.InstanceId -Confirm:$false";
Logger.WriteLine(script);
ProcessHelper.RunCMD("powershell", script);
//Thread.Sleep(2000);
return true;
}
catch (Exception ex )
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
return false;
@@ -115,13 +127,13 @@ public class NvidiaGpuControl : IGpuControl
public int SetClocksFromConfig()
{
int core = Program.config.getConfig("gpu_core");
int memory = Program.config.getConfig("gpu_memory");
int core = AppConfig.Get("gpu_core", 0);
int memory = AppConfig.Get("gpu_memory", 0);
int status = SetClocks(core, memory);
return status;
}
public int SetClocks(int core, int memory)
public int SetClocks(int core, int memory, int voltage = 0)
{
if (core < MinCoreOffset || core > MaxCoreOffset) return 0;
@@ -131,6 +143,7 @@ public class NvidiaGpuControl : IGpuControl
var coreClock = new PerformanceStates20ClockEntryV1(PublicClockDomain.Graphics, new PerformanceStates20ParameterDelta(core * 1000));
var memoryClock = new PerformanceStates20ClockEntryV1(PublicClockDomain.Memory, new PerformanceStates20ParameterDelta(memory * 1000));
var voltageEntry = new PerformanceStates20BaseVoltageEntryV1(PerformanceVoltageDomain.Core, new PerformanceStates20ParameterDelta(voltage));
PerformanceStates20ClockEntryV1[] clocks = { coreClock, memoryClock };
PerformanceStates20BaseVoltageEntryV1[] voltages = { };
@@ -141,12 +154,12 @@ public class NvidiaGpuControl : IGpuControl
try
{
Logger.WriteLine($"SET GPU Clock : {core}, {memory}");
Logger.WriteLine($"SET GPU CLOCKS: {core}, {memory}");
GPUApi.SetPerformanceStates20(internalGpu.Handle, overclock);
}
catch (Exception ex)
{
Logger.WriteLine(ex.Message);
Logger.WriteLine("SET GPU CLOCKS: " + ex.Message);
return -1;
}
@@ -165,7 +178,7 @@ public class NvidiaGpuControl : IGpuControl
}
catch (Exception ex)
{
Logger.WriteLine(ex.Message);
Debug.WriteLine(ex.Message);
return null;
}
}

View File

@@ -0,0 +1,65 @@
using Ryzen;
using System.Diagnostics;
using System.Text.RegularExpressions;
public static class NvidiaSmi
{
public static bool GetDisplayActiveStatus()
{
// Non AMD devices doesn't seem to be affected
if (!RyzenControl.IsAMD()) return false;
string commandOutput = RunNvidiaSmiCommand();
Logger.WriteLine(commandOutput);
if (commandOutput.Length == 0) return false;
if (!commandOutput.Contains("RTX 40")) return false;
// Extract the "Display Active" status using regular expressions
string displayActivePattern = @"Display Active\s+:\s+(\w+)";
Match match = Regex.Match(commandOutput, displayActivePattern, RegexOptions.IgnoreCase);
if (match.Success)
{
string status = match.Groups[1].Value.ToLower().Trim(' ');
return status == "enabled";
}
return false; // Return false if the "Display Active" status is not found
}
private static string RunNvidiaSmiCommand(string arguments = "-i 0 -q")
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "nvidia-smi",
Arguments = arguments,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
Process process = new Process
{
StartInfo = startInfo
};
try
{
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return output;
}
catch (Exception ex)
{
//return File.ReadAllText(@"smi.txt");
Debug.WriteLine(ex.Message);
}
return "";
}
}

View File

@@ -1,5 +1,9 @@
using GHelper;
using GHelper.Gpu;
using GHelper.Gpu.NVidia;
using GHelper.Gpu.AMD;
using GHelper.Helpers;
using System.Diagnostics;
public static class HardwareControl
@@ -19,16 +23,19 @@ public static class HardwareControl
public static int GetFanMax()
{
int max = 58;
if (Program.config.ContainsModel("401")) max = 72;
else if (Program.config.ContainsModel("503")) max = 68;
return Math.Max(max, Program.config.getConfig("fan_max"));
int configMax = AppConfig.Get("fan_max");
if (configMax > 80) configMax = 0; // skipping inadvequate settings
if (AppConfig.ContainsModel("401")) max = 72;
else if (AppConfig.ContainsModel("503")) max = 68;
return Math.Max(max, configMax);
}
public static void SetFanMax(int fan)
{
Program.config.setConfig("fan_max", fan);
AppConfig.Set("fan_max", fan);
}
private static string FormatFan(int fan)
public static string FormatFan(int fan)
{
// fix for old models
if (fan < 0)
@@ -38,12 +45,12 @@ public static class HardwareControl
}
int fanMax = GetFanMax();
if (fan > fanMax && fan < 110) SetFanMax(fan);
if (fan > fanMax && fan < 80) SetFanMax(fan);
if (Program.config.getConfig("fan_rpm") == 1)
return " Fan: " + (fan * 100).ToString() + "RPM";
if (AppConfig.Is("fan_rpm"))
return GHelper.Properties.Strings.FanSpeed + (fan * 100).ToString() + "RPM";
else
return " Fan: " + Math.Min(Math.Round((float)fan / fanMax * 100), 100).ToString() + "%"; // relatively to 6000 rpm
return GHelper.Properties.Strings.FanSpeed + Math.Min(Math.Round((float)fan / fanMax * 100), 100).ToString() + "%"; // relatively to 6000 rpm
}
private static int GetGpuUse()
@@ -51,6 +58,7 @@ public static class HardwareControl
try
{
int? gpuUse = GpuControl?.GetGpuUse();
Logger.WriteLine("GPU usage: " + GpuControl?.FullName + " " + gpuUse + "%");
if (gpuUse is not null) return (int)gpuUse;
}
catch (Exception ex)
@@ -68,11 +76,11 @@ public static class HardwareControl
gpuTemp = -1;
gpuUse = -1;
cpuFan = FormatFan(Program.wmi.DeviceGet(ASUSWmi.CPU_Fan));
gpuFan = FormatFan(Program.wmi.DeviceGet(ASUSWmi.GPU_Fan));
midFan = FormatFan(Program.wmi.DeviceGet(ASUSWmi.Mid_Fan));
cpuFan = FormatFan(Program.acpi.DeviceGet(AsusACPI.CPU_Fan));
gpuFan = FormatFan(Program.acpi.DeviceGet(AsusACPI.GPU_Fan));
midFan = FormatFan(Program.acpi.DeviceGet(AsusACPI.Mid_Fan));
cpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_CPU);
cpuTemp = Program.acpi.DeviceGet(AsusACPI.Temp_CPU);
if (cpuTemp < 0) try
{
@@ -98,7 +106,7 @@ public static class HardwareControl
}
if (gpuTemp is null || gpuTemp < 0)
gpuTemp = Program.wmi.DeviceGet(ASUSWmi.Temp_GPU);
gpuTemp = Program.acpi.DeviceGet(AsusACPI.Temp_GPU);
try
{
@@ -113,7 +121,7 @@ public static class HardwareControl
}
}
public static bool IsUsedGPU(int threshold = 20)
public static bool IsUsedGPU(int threshold = 10)
{
if (GetGpuUse() > threshold)
{
@@ -132,7 +140,7 @@ public static class HardwareControl
return null;
}
public static void RecreateGpuControlWithDelay(int delay = 3)
public static void RecreateGpuControlWithDelay(int delay = 5)
{
// Re-enabling the discrete GPU takes a bit of time,
// so a simple workaround is to refresh again after that happens
@@ -150,9 +158,11 @@ public static class HardwareControl
GpuControl?.Dispose();
IGpuControl _gpuControl = new NvidiaGpuControl();
if (_gpuControl.IsValid)
{
GpuControl = _gpuControl;
Logger.WriteLine(GpuControl.FullName);
return;
}
@@ -162,15 +172,31 @@ public static class HardwareControl
if (_gpuControl.IsValid)
{
GpuControl = _gpuControl;
Logger.WriteLine(GpuControl.FullName);
return;
}
_gpuControl.Dispose();
GpuControl = null;
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
public static void KillGPUApps()
{
List<string> tokill = new() { "EADesktop", "RadeonSoftware", "epicgameslauncher", "ASUSSmartDisplayControl" };
foreach (string kill in tokill) ProcessHelper.KillByName(kill);
if (AppConfig.Is("kill_gpu_apps") && GpuControl is not null)
{
GpuControl.KillGPUApps();
}
}
}

View File

@@ -30,7 +30,7 @@ public static class Logger
try
{
var file = File.ReadAllLines(logFile);
int skip = Math.Max(0, file.Count() - 500);
int skip = Math.Max(0, file.Count() - 1000);
File.WriteAllLines(logFile, file.Skip(skip).ToArray());
}
catch { }

View File

@@ -1,10 +1,10 @@
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
namespace OSD
namespace GHelper.Helpers
{
class OSDNativeForm : NativeWindow, IDisposable
public class OSDNativeForm : NativeWindow, IDisposable
{
private bool _disposed = false;
@@ -19,11 +19,11 @@ namespace OSD
protected internal void Invalidate()
{
this.UpdateLayeredWindow();
UpdateLayeredWindow();
}
private void UpdateLayeredWindow()
{
Bitmap bitmap1 = new Bitmap(this.Size.Width, this.Size.Height, PixelFormat.Format32bppArgb);
Bitmap bitmap1 = new Bitmap(Size.Width, Size.Height, PixelFormat.Format32bppArgb);
using (Graphics graphics1 = Graphics.FromImage(bitmap1))
{
Rectangle rectangle1;
@@ -31,27 +31,27 @@ namespace OSD
POINT point1;
POINT point2;
BLENDFUNCTION blendfunction1;
rectangle1 = new Rectangle(0, 0, this.Size.Width, this.Size.Height);
rectangle1 = new Rectangle(0, 0, Size.Width, Size.Height);
PerformPaint(new PaintEventArgs(graphics1, rectangle1));
IntPtr ptr1 = User32.GetDC(IntPtr.Zero);
IntPtr ptr2 = Gdi32.CreateCompatibleDC(ptr1);
IntPtr ptr3 = bitmap1.GetHbitmap(Color.FromArgb(0));
IntPtr ptr4 = Gdi32.SelectObject(ptr2, ptr3);
size1.cx = this.Size.Width;
size1.cy = this.Size.Height;
point1.x = this.Location.X;
point1.x = this.Location.X;
point1.y = this.Location.Y;
nint ptr1 = User32.GetDC(nint.Zero);
nint ptr2 = Gdi32.CreateCompatibleDC(ptr1);
nint ptr3 = bitmap1.GetHbitmap(Color.FromArgb(0));
nint ptr4 = Gdi32.SelectObject(ptr2, ptr3);
size1.cx = Size.Width;
size1.cy = Size.Height;
point1.x = Location.X;
point1.x = Location.X;
point1.y = Location.Y;
point2.x = 0;
point2.y = 0;
blendfunction1 = new BLENDFUNCTION();
blendfunction1.BlendOp = 0;
blendfunction1.BlendFlags = 0;
blendfunction1.SourceConstantAlpha = this._alpha;
blendfunction1.SourceConstantAlpha = _alpha;
blendfunction1.AlphaFormat = 1;
User32.UpdateLayeredWindow(base.Handle, ptr1, ref point1, ref size1, ptr2, ref point2, 0, ref blendfunction1, 2); //2=ULW_ALPHA
User32.UpdateLayeredWindow(Handle, ptr1, ref point1, ref size1, ptr2, ref point2, 0, ref blendfunction1, 2); //2=ULW_ALPHA
Gdi32.SelectObject(ptr2, ptr4);
User32.ReleaseDC(IntPtr.Zero, ptr1);
User32.ReleaseDC(nint.Zero, ptr1);
Gdi32.DeleteObject(ptr3);
Gdi32.DeleteDC(ptr2);
}
@@ -59,25 +59,25 @@ namespace OSD
public virtual void Show()
{
if (base.Handle == IntPtr.Zero) //if handle don't equal to zero - window was created and just hided
this.CreateWindowOnly();
User32.ShowWindow(base.Handle, User32.SW_SHOWNOACTIVATE);
if (Handle == nint.Zero) //if handle don't equal to zero - window was created and just hided
CreateWindowOnly();
User32.ShowWindow(Handle, User32.SW_SHOWNOACTIVATE);
}
public virtual void Hide()
{
if (base.Handle == IntPtr.Zero)
if (Handle == nint.Zero)
return;
User32.ShowWindow(base.Handle, User32.SW_HIDE);
this.DestroyHandle();
User32.ShowWindow(Handle, User32.SW_HIDE);
DestroyHandle();
}
public virtual void Close()
{
this.Hide();
this.Dispose();
Hide();
Dispose();
}
private void CreateWindowOnly()
@@ -85,55 +85,55 @@ namespace OSD
CreateParams params1 = new CreateParams();
params1.Caption = "FloatingNativeWindow";
int nX = this._location.X;
int nY = this._location.Y;
Screen screen1 = Screen.FromHandle(base.Handle);
if ((nX + this._size.Width) > screen1.Bounds.Width)
int nX = _location.X;
int nY = _location.Y;
Screen screen1 = Screen.FromHandle(Handle);
if (nX + _size.Width > screen1.Bounds.Width)
{
nX = screen1.Bounds.Width - this._size.Width;
nX = screen1.Bounds.Width - _size.Width;
}
if ((nY + this._size.Height) > screen1.Bounds.Height)
if (nY + _size.Height > screen1.Bounds.Height)
{
nY = screen1.Bounds.Height - this._size.Height;
nY = screen1.Bounds.Height - _size.Height;
}
this._location = new Point(nX, nY);
Size size1 = this._size;
Point point1 = this._location;
_location = new Point(nX, nY);
Size size1 = _size;
Point point1 = _location;
params1.X = nX;
params1.Y = nY;
params1.Height = size1.Height;
params1.Width = size1.Width;
params1.Parent = IntPtr.Zero;
params1.Parent = nint.Zero;
uint ui = User32.WS_POPUP;
params1.Style = (int)ui;
params1.ExStyle = User32.WS_EX_TOPMOST | User32.WS_EX_TOOLWINDOW | User32.WS_EX_LAYERED | User32.WS_EX_NOACTIVATE | User32.WS_EX_TRANSPARENT;
this.CreateHandle(params1);
this.UpdateLayeredWindow();
CreateHandle(params1);
UpdateLayeredWindow();
}
protected virtual void SetBoundsCore(int x, int y, int width, int height)
{
if (((this.X != x) || (this.Y != y)) || ((this.Width != width) || (this.Height != height)))
if (X != x || Y != y || Width != width || Height != height)
{
if (base.Handle != IntPtr.Zero)
if (Handle != nint.Zero)
{
int num1 = 20;
if ((this.X == x) && (this.Y == y))
if (X == x && Y == y)
{
num1 |= 2;
}
if ((this.Width == width) && (this.Height == height))
if (Width == width && Height == height)
{
num1 |= 1;
}
User32.SetWindowPos(base.Handle, IntPtr.Zero, x, y, width, height, (uint)num1);
User32.SetWindowPos(Handle, nint.Zero, x, y, width, height, (uint)num1);
}
else
{
this.Location = new Point(x, y);
this.Size = new Size(width, height);
Location = new Point(x, y);
Size = new Size(width, height);
}
}
}
@@ -147,20 +147,20 @@ namespace OSD
/// </summary>
public virtual Point Location
{
get { return this._location; }
get { return _location; }
set
{
if (base.Handle != IntPtr.Zero)
if (Handle != nint.Zero)
{
this.SetBoundsCore(value.X, value.Y, this._size.Width, this._size.Height);
SetBoundsCore(value.X, value.Y, _size.Width, _size.Height);
RECT rect = new RECT();
User32.GetWindowRect(base.Handle, ref rect);
this._location = new Point(rect.left, rect.top);
this.UpdateLayeredWindow();
User32.GetWindowRect(Handle, ref rect);
_location = new Point(rect.left, rect.top);
UpdateLayeredWindow();
}
else
{
this._location = value;
_location = value;
}
}
}
@@ -169,20 +169,20 @@ namespace OSD
/// </summary>
public virtual Size Size
{
get { return this._size; }
get { return _size; }
set
{
if (base.Handle != IntPtr.Zero)
if (Handle != nint.Zero)
{
this.SetBoundsCore(this._location.X, this._location.Y, value.Width, value.Height);
SetBoundsCore(_location.X, _location.Y, value.Width, value.Height);
RECT rect = new RECT();
User32.GetWindowRect(base.Handle, ref rect);
this._size = new Size(rect.right - rect.left, rect.bottom - rect.top);
this.UpdateLayeredWindow();
User32.GetWindowRect(Handle, ref rect);
_size = new Size(rect.right - rect.left, rect.bottom - rect.top);
UpdateLayeredWindow();
}
else
{
this._size = value;
_size = value;
}
}
}
@@ -191,10 +191,10 @@ namespace OSD
/// </summary>
public int Height
{
get { return this._size.Height; }
get { return _size.Height; }
set
{
this._size = new Size(this._size.Width, value);
_size = new Size(_size.Width, value);
}
}
/// <summary>
@@ -202,10 +202,10 @@ namespace OSD
/// </summary>
public int Width
{
get { return this._size.Width; }
get { return _size.Width; }
set
{
this._size = new Size(value, this._size.Height);
_size = new Size(value, _size.Height);
}
}
/// <summary>
@@ -213,10 +213,10 @@ namespace OSD
/// </summary>
public int X
{
get { return this._location.X; }
get { return _location.X; }
set
{
this.Location = new Point(value, this.Location.Y);
Location = new Point(value, Location.Y);
}
}
/// <summary>
@@ -224,10 +224,10 @@ namespace OSD
/// </summary>
public int Y
{
get { return this._location.Y; }
get { return _location.Y; }
set
{
this.Location = new Point(this.Location.X, value);
Location = new Point(Location.X, value);
}
}
/// <summary>
@@ -237,7 +237,7 @@ namespace OSD
{
get
{
return new Rectangle(new Point(0, 0), this._size);
return new Rectangle(new Point(0, 0), _size);
}
}
/// <summary>
@@ -245,12 +245,12 @@ namespace OSD
/// </summary>
public byte Alpha
{
get { return this._alpha; }
get { return _alpha; }
set
{
if (this._alpha == value) return;
this._alpha = value;
this.UpdateLayeredWindow();
if (_alpha == value) return;
_alpha = value;
UpdateLayeredWindow();
}
}
#endregion
@@ -258,15 +258,15 @@ namespace OSD
#region IDisposable Members
public void Dispose()
{
this.Dispose(true);
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!this._disposed)
if (!_disposed)
{
this.DestroyHandle();
this._disposed = true;
DestroyHandle();
_disposed = true;
}
}
#endregion
@@ -299,16 +299,16 @@ namespace OSD
{
public uint cbSize;
public uint dwFlags;
public IntPtr hWnd;
public nint hWnd;
public uint dwHoverTime;
}
[StructLayout(LayoutKind.Sequential)]
internal struct MSG
{
public IntPtr hwnd;
public nint hwnd;
public int message;
public IntPtr wParam;
public IntPtr lParam;
public nint wParam;
public nint lParam;
public int time;
public int pt_x;
public int pt_y;
@@ -345,69 +345,69 @@ namespace OSD
{
}
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool AnimateWindow(IntPtr hWnd, uint dwTime, uint dwFlags);
internal static extern bool AnimateWindow(nint hWnd, uint dwTime, uint dwFlags);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool ClientToScreen(IntPtr hWnd, ref POINT pt);
internal static extern bool ClientToScreen(nint hWnd, ref POINT pt);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool DispatchMessage(ref MSG msg);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool DrawFocusRect(IntPtr hWnd, ref RECT rect);
internal static extern bool DrawFocusRect(nint hWnd, ref RECT rect);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr GetDC(IntPtr hWnd);
internal static extern nint GetDC(nint hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr GetFocus();
internal static extern nint GetFocus();
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern ushort GetKeyState(int virtKey);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool GetMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr GetParent(IntPtr hWnd);
internal static extern nint GetParent(nint hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool GetClientRect(IntPtr hWnd, [In, Out] ref RECT rect);
public static extern bool GetClientRect(nint hWnd, [In, Out] ref RECT rect);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern int GetWindowLong(IntPtr hWnd, int nIndex);
internal static extern int GetWindowLong(nint hWnd, int nIndex);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr GetWindow(IntPtr hWnd, int cmd);
internal static extern nint GetWindow(nint hWnd, int cmd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);
internal static extern bool GetWindowRect(nint hWnd, ref RECT rect);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool HideCaret(IntPtr hWnd);
internal static extern bool HideCaret(nint hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool InvalidateRect(IntPtr hWnd, ref RECT rect, bool erase);
internal static extern bool InvalidateRect(nint hWnd, ref RECT rect, bool erase);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr LoadCursor(IntPtr hInstance, uint cursor);
internal static extern nint LoadCursor(nint hInstance, uint cursor);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, [In, Out] ref RECT rect, int cPoints);
public static extern int MapWindowPoints(nint hWndFrom, nint hWndTo, [In, Out] ref RECT rect, int cPoints);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
internal static extern bool MoveWindow(nint hWnd, int x, int y, int width, int height, bool repaint);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool PeekMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax, uint wFlag);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool PostMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam);
internal static extern bool PostMessage(nint hWnd, int Msg, uint wParam, uint lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool ReleaseCapture();
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
internal static extern int ReleaseDC(nint hWnd, nint hDC);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool ScreenToClient(IntPtr hWnd, ref POINT pt);
internal static extern bool ScreenToClient(nint hWnd, ref POINT pt);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern uint SendMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam);
internal static extern uint SendMessage(nint hWnd, int Msg, uint wParam, uint lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr SetCursor(IntPtr hCursor);
internal static extern nint SetCursor(nint hCursor);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr SetFocus(IntPtr hWnd);
internal static extern nint SetFocus(nint hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int newLong);
internal static extern int SetWindowLong(nint hWnd, int nIndex, int newLong);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndAfter, int X, int Y, int Width, int Height, uint flags);
internal static extern int SetWindowPos(nint hWnd, nint hWndAfter, int X, int Y, int Width, int Height, uint flags);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw);
internal static extern bool SetWindowRgn(nint hWnd, nint hRgn, bool redraw);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool ShowCaret(IntPtr hWnd);
internal static extern bool ShowCaret(nint hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool SetCapture(IntPtr hWnd);
internal static extern bool SetCapture(nint hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern int ShowWindow(IntPtr hWnd, short cmdShow);
internal static extern int ShowWindow(nint hWnd, short cmdShow);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int bRetValue, uint fWinINI);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
@@ -415,9 +415,9 @@ namespace OSD
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool TranslateMessage(ref MSG msg);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref POINT pprSrc, int crKey, ref BLENDFUNCTION pblend, int dwFlags);
internal static extern bool UpdateLayeredWindow(nint hwnd, nint hdcDst, ref POINT pptDst, ref SIZE psize, nint hdcSrc, ref POINT pprSrc, int crKey, ref BLENDFUNCTION pblend, int dwFlags);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool UpdateWindow(IntPtr hwnd);
internal static extern bool UpdateWindow(nint hwnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool WaitMessage();
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
@@ -431,25 +431,25 @@ namespace OSD
{
}
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern int CombineRgn(IntPtr dest, IntPtr src1, IntPtr src2, int flags);
internal static extern int CombineRgn(nint dest, nint src1, nint src2, int flags);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr CreateBrushIndirect(ref LOGBRUSH brush);
internal static extern nint CreateBrushIndirect(ref LOGBRUSH brush);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr CreateCompatibleDC(IntPtr hDC);
internal static extern nint CreateCompatibleDC(nint hDC);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr CreateRectRgnIndirect(ref RECT rect);
internal static extern nint CreateRectRgnIndirect(ref RECT rect);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern bool DeleteDC(IntPtr hDC);
internal static extern bool DeleteDC(nint hDC);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr DeleteObject(IntPtr hObject);
internal static extern nint DeleteObject(nint hObject);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern int GetClipBox(IntPtr hDC, ref RECT rectBox);
internal static extern int GetClipBox(nint hDC, ref RECT rectBox);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern bool PatBlt(IntPtr hDC, int x, int y, int width, int height, uint flags);
internal static extern bool PatBlt(nint hDC, int x, int y, int width, int height, uint flags);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern int SelectClipRgn(IntPtr hDC, IntPtr hRgn);
internal static extern int SelectClipRgn(nint hDC, nint hRgn);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
internal static extern nint SelectObject(nint hDC, nint hObject);
}
[StructLayout(LayoutKind.Sequential)]
public struct LOGBRUSH

View File

@@ -0,0 +1,106 @@
using Microsoft.Win32;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
namespace GHelper.Helpers
{
public static class OptimizationService
{
static List<string> services = new() {
"AsusAppService",
"ASUSLinkNear",
"ASUSLinkRemote",
"ASUSSoftwareManager",
"ASUSSwitch",
"ASUSSystemAnalysis",
"ASUSSystemDiagnosis",
"ArmouryCrateControlInterface",
"AsusCertService",
"ASUSOptimization"
};
public static void SetChargeLimit(int newValue)
{
// Set the path to the .ini file
string path = @"C:\ProgramData\ASUS\ASUS System Control Interface\ASUSOptimization\Customization.ini";
// Make a backup copy of the INI file
string backupPath = path + ".bak";
File.Copy(path, backupPath, true);
string fileContents = File.ReadAllText(path, Encoding.Unicode);
// Find the section [BatteryHealthCharging]
string sectionPattern = @"\[BatteryHealthCharging\]\s*(version=\d+)?\s+value=(\d+)";
Match sectionMatch = Regex.Match(fileContents, sectionPattern);
if (sectionMatch.Success)
{
// Replace the value with the new value
string oldValueString = sectionMatch.Groups[2].Value;
int oldValue = int.Parse(oldValueString);
string newSection = sectionMatch.Value.Replace($"value={oldValue}", $"value={newValue}");
// Replace the section in the file contents
fileContents = fileContents.Replace(sectionMatch.Value, newSection);
File.WriteAllText(path, fileContents, Encoding.Unicode);
}
}
public static bool IsRunning()
{
return Process.GetProcessesByName("AsusOptimization").Count() > 0;
}
public static int GetRunningCount()
{
int count = 0;
foreach (string service in services)
{
if (Process.GetProcessesByName(service).Count() > 0) count++;
}
return count;
}
public static void SetBacklightOffDelay(int value = 60)
{
try
{
RegistryKey myKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ASUS\ASUS System Control Interface\AsusOptimization\ASUS Keyboard Hotkeys", true);
if (myKey != null)
{
myKey.SetValue("TurnOffKeybdLight", value, RegistryValueKind.DWord);
myKey.Close();
}
}
catch (Exception ex)
{
Logger.WriteLine(ex.Message);
}
}
public static void StopAsusServices()
{
foreach (string service in services)
{
ProcessHelper.StopDisableService(service);
}
}
public static void StartAsusServices()
{
foreach (string service in services)
{
ProcessHelper.StartEnableService(service);
}
}
}
}

View File

@@ -0,0 +1,146 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
namespace GHelper.Helpers
{
public static class ProcessHelper
{
private static long lastAdmin;
public static void CheckAlreadyRunning()
{
Process currentProcess = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(currentProcess.ProcessName);
if (processes.Length > 1)
{
foreach (Process process in processes)
if (process.Id != currentProcess.Id)
try
{
process.Kill();
}
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
MessageBox.Show(Properties.Strings.AppAlreadyRunningText, Properties.Strings.AppAlreadyRunning, MessageBoxButtons.OK);
Application.Exit();
return;
}
}
}
public static bool IsUserAdministrator()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
public static void RunAsAdmin(string? param = null)
{
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastAdmin) < 2000) return;
lastAdmin = DateTimeOffset.Now.ToUnixTimeMilliseconds();
// Check if the current user is an administrator
if (!IsUserAdministrator())
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = true;
startInfo.WorkingDirectory = Environment.CurrentDirectory;
startInfo.FileName = Application.ExecutablePath;
startInfo.Arguments = param;
startInfo.Verb = "runas";
try
{
Process.Start(startInfo);
Application.Exit();
}
catch (Exception ex)
{
Logger.WriteLine(ex.Message);
}
}
}
public static void KillByName(string name)
{
foreach (var process in Process.GetProcessesByName(name))
{
try
{
process.Kill();
Logger.WriteLine($"Stopped: {process.ProcessName}");
}
catch (Exception ex)
{
Logger.WriteLine($"Failed to stop: {process.ProcessName} {ex.Message}");
}
}
}
public static void KillByProcess(Process process)
{
try
{
process.Kill();
Logger.WriteLine($"Stopped: {process.ProcessName}");
}
catch (Exception ex)
{
Logger.WriteLine($"Failed to stop: {process.ProcessName} {ex.Message}");
}
}
public static void StopDisableService(string serviceName)
{
try
{
string script = $"Set-Service -Name \"{serviceName}\" -Status stopped -StartupType disabled";
Logger.WriteLine(script);
RunCMD("powershell", script);
}
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
}
}
public static void StartEnableService(string serviceName)
{
try
{
string script = $"Set-Service -Name \"{serviceName}\" -Status running -StartupType Automatic";
Logger.WriteLine(script);
RunCMD("powershell", script);
}
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
}
}
public static void RunCMD(string name, string args)
{
var cmd = new Process();
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmd.StartInfo.FileName = name;
cmd.StartInfo.Arguments = args;
cmd.Start();
Logger.WriteLine(cmd.StandardOutput.ReadToEnd());
cmd.WaitForExit();
}
}
}

View File

@@ -0,0 +1,47 @@
namespace GHelper.Helpers
{
using System;
using System.Diagnostics;
using System.Management;
public static class ScreenBrightness
{
public static int Get()
{
using var mclass = new ManagementClass("WmiMonitorBrightness")
{
Scope = new ManagementScope(@"\\.\root\wmi")
};
using var instances = mclass.GetInstances();
foreach (ManagementObject instance in instances)
{
return (byte)instance.GetPropertyValue("CurrentBrightness");
}
return 0;
}
public static void Set(int brightness)
{
using var mclass = new ManagementClass("WmiMonitorBrightnessMethods")
{
Scope = new ManagementScope(@"\\.\root\wmi")
};
using var instances = mclass.GetInstances();
var args = new object[] { 1, brightness };
foreach (ManagementObject instance in instances)
{
instance.InvokeMethod("WmiSetBrightness", args);
}
}
public static int Adjust(int delta)
{
int brightness = Get();
Debug.WriteLine(brightness);
brightness = Math.Min(100, Math.Max(0, brightness + delta));
Set(brightness);
return brightness;
}
}
}

View File

@@ -1,4 +1,4 @@
using GHelper;
using GHelper.Helpers;
using Microsoft.Win32.TaskScheduler;
using System.Diagnostics;
using System.Security.Principal;
@@ -16,7 +16,7 @@ public class Startup
public static void ReScheduleAdmin()
{
if (Program.IsUserAdministrator() && IsScheduled())
if (ProcessHelper.IsUserAdministrator() && IsScheduled())
{
UnSchedule();
Schedule();
@@ -34,11 +34,12 @@ public class Startup
using (TaskDefinition td = TaskService.Instance.NewTask())
{
td.RegistrationInfo.Description = "G-Helper Auto Start";
td.Triggers.Add(new LogonTrigger { UserId = userId });
td.Triggers.Add(new LogonTrigger { UserId = userId, Delay = TimeSpan.FromSeconds(1) });
td.Actions.Add(strExeFilePath);
if (Program.IsUserAdministrator())
if (ProcessHelper.IsUserAdministrator())
td.Principal.RunLevel = TaskRunLevel.Highest;
td.Settings.StopIfGoingOnBatteries = false;
@@ -54,10 +55,10 @@ public class Startup
}
catch (Exception e)
{
if (Program.IsUserAdministrator())
if (ProcessHelper.IsUserAdministrator())
MessageBox.Show("Can't create a start up task. Try running Task Scheduler by hand and manually deleting GHelper task if it exists there.", "Scheduler Error", MessageBoxButtons.OK);
else
Program.RunAsAdmin();
else
ProcessHelper.RunAsAdmin();
}
}
@@ -73,10 +74,10 @@ public class Startup
}
catch (Exception e)
{
if (Program.IsUserAdministrator())
if (ProcessHelper.IsUserAdministrator())
MessageBox.Show("Can't remove task. Try running Task Scheduler by hand and manually deleting GHelper task if it exists there.", "Scheduler Error", MessageBoxButtons.OK);
else
Program.RunAsAdmin();
ProcessHelper.RunAsAdmin();
}
}
}

163
app/Helpers/ToastForm.cs Normal file
View File

@@ -0,0 +1,163 @@
using System.Drawing.Drawing2D;
namespace GHelper.Helpers
{
static class Drawing
{
public static GraphicsPath RoundedRect(Rectangle bounds, int radius)
{
int diameter = radius * 2;
Size size = new Size(diameter, diameter);
Rectangle arc = new Rectangle(bounds.Location, size);
GraphicsPath path = new GraphicsPath();
if (radius == 0)
{
path.AddRectangle(bounds);
return path;
}
path.AddArc(arc, 180, 90);
arc.X = bounds.Right - diameter;
path.AddArc(arc, 270, 90);
arc.Y = bounds.Bottom - diameter;
path.AddArc(arc, 0, 90);
arc.X = bounds.Left;
path.AddArc(arc, 90, 90);
path.CloseFigure();
return path;
}
public static void FillRoundedRectangle(this Graphics graphics, Brush brush, Rectangle bounds, int cornerRadius)
{
using (GraphicsPath path = RoundedRect(bounds, cornerRadius))
{
graphics.FillPath(brush, path);
}
}
}
public enum ToastIcon
{
BrightnessUp,
BrightnessDown,
BacklightUp,
BacklightDown,
Touchpad,
Microphone,
MicrophoneMute,
FnLock,
Battery,
Charger
}
public class ToastForm : OSDNativeForm
{
protected static string toastText = "Balanced";
protected static ToastIcon? toastIcon = null;
protected static System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
public ToastForm()
{
timer.Tick += timer_Tick;
timer.Enabled = false;
timer.Interval = 2000;
}
protected override void PerformPaint(PaintEventArgs e)
{
Brush brush = new SolidBrush(Color.FromArgb(150, Color.Black));
e.Graphics.FillRoundedRectangle(brush, Bound, 10);
StringFormat format = new StringFormat();
format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Center;
Bitmap? icon = null;
switch (toastIcon)
{
case ToastIcon.BrightnessUp:
icon = Properties.Resources.brightness_up;
break;
case ToastIcon.BrightnessDown:
icon = Properties.Resources.brightness_down;
break;
case ToastIcon.BacklightUp:
icon = Properties.Resources.backlight_up;
break;
case ToastIcon.BacklightDown:
icon = Properties.Resources.backlight_down;
break;
case ToastIcon.Microphone:
icon = Properties.Resources.icons8_microphone_96;
break;
case ToastIcon.MicrophoneMute:
icon = Properties.Resources.icons8_mute_unmute_96;
break;
case ToastIcon.Touchpad:
icon = Properties.Resources.icons8_touchpad_96;
break;
case ToastIcon.FnLock:
icon = Properties.Resources.icons8_function;
break;
case ToastIcon.Battery:
icon = Properties.Resources.icons8_charged_battery_96;
break;
case ToastIcon.Charger:
icon = Properties.Resources.icons8_charging_battery_96;
break;
}
int shiftX = 0;
if (icon is not null)
{
e.Graphics.DrawImage(icon, 18, 18, 64, 64);
shiftX = 40;
}
e.Graphics.DrawString(toastText,
new Font("Segoe UI", 36f, FontStyle.Bold, GraphicsUnit.Pixel),
new SolidBrush(Color.White),
new PointF(Bound.Width / 2 + shiftX, Bound.Height / 2),
format);
}
public void RunToast(string text, ToastIcon? icon = null)
{
Program.settingsForm.Invoke(delegate
{
//Hide();
timer.Stop();
toastText = text;
toastIcon = icon;
Screen screen1 = Screen.FromHandle(Handle);
Width = Math.Max(300, 100 + toastText.Length * 22);
Height = 100;
X = (screen1.Bounds.Width - Width) / 2;
Y = screen1.Bounds.Height - 300 - Height;
Show();
timer.Start();
});
}
private void timer_Tick(object? sender, EventArgs e)
{
//Debug.WriteLine("Toast end");
Hide();
timer.Stop();
}
}
}

View File

@@ -0,0 +1,502 @@
using GHelper.Display;
using GHelper.Helpers;
using GHelper.Mode;
using Microsoft.Win32;
using NAudio.CoreAudioApi;
using System.Diagnostics;
using System.Management;
namespace GHelper.Input
{
public class InputDispatcher
{
System.Timers.Timer timer = new System.Timers.Timer(1000);
public static bool backlightActivity = true;
public static Keys keyProfile = Keys.F5;
public static Keys keyApp = Keys.F12;
static ModeControl modeControl = Program.modeControl;
static ScreenControl screenControl = new ScreenControl();
KeyboardListener listener;
KeyboardHook hook = new KeyboardHook();
public InputDispatcher()
{
byte[] result = Program.acpi.DeviceInit();
Debug.WriteLine($"Init: {BitConverter.ToString(result)}");
Program.acpi.SubscribeToEvents(WatcherEventArrived);
//Task.Run(Program.acpi.RunListener);
hook.KeyPressed += new EventHandler<KeyPressedEventArgs>(KeyPressed);
RegisterKeys();
timer.Elapsed += Timer_Elapsed;
}
private void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{
if (GetBacklight() == 0) return;
TimeSpan iddle = NativeMethods.GetIdleTime();
int kb_timeout;
if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online)
kb_timeout = AppConfig.Get("keyboard_ac_timeout", 0);
else
kb_timeout = AppConfig.Get("keyboard_timeout", 60);
if (kb_timeout == 0) return;
if (backlightActivity && iddle.TotalSeconds > kb_timeout)
{
backlightActivity = false;
AsusUSB.ApplyBrightness(0, "Timeout");
}
if (!backlightActivity && iddle.TotalSeconds < kb_timeout)
{
backlightActivity = true;
SetBacklightAuto();
}
//Debug.WriteLine(iddle.TotalSeconds);
}
public void Init()
{
if (listener is not null) listener.Dispose();
Program.acpi.DeviceInit();
if (!OptimizationService.IsRunning())
listener = new KeyboardListener(HandleEvent);
else
Logger.WriteLine("Optimization service is running");
InitBacklightTimer();
}
public void InitBacklightTimer()
{
timer.Enabled = AppConfig.Get("keyboard_timeout") > 0 && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online ||
AppConfig.Get("keyboard_ac_timeout") > 0 && SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online;
}
public void RegisterKeys()
{
hook.UnregisterAll();
// CTRL + SHIFT + F5 to cycle profiles
if (AppConfig.Get("keybind_profile") != -1) keyProfile = (Keys)AppConfig.Get("keybind_profile");
if (AppConfig.Get("keybind_app") != -1) keyApp = (Keys)AppConfig.Get("keybind_app");
string actionM1 = AppConfig.GetString("m1");
string actionM2 = AppConfig.GetString("m2");
if (keyProfile != Keys.None) hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control, keyProfile);
if (keyApp != Keys.None) hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control, keyApp);
if (!AppConfig.ContainsModel("Z13"))
if (actionM1 is not null && actionM1.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeDown);
if (actionM2 is not null && actionM2.Length > 0) hook.RegisterHotKey(ModifierKeys.None, Keys.VolumeUp);
// FN-Lock group
if (AppConfig.Is("fn_lock") && !AppConfig.ContainsModel("VivoBook"))
for (Keys i = Keys.F1; i <= Keys.F11; i++) hook.RegisterHotKey(ModifierKeys.None, i);
}
static void CustomKey(string configKey = "m3")
{
string command = AppConfig.GetString(configKey + "_custom");
int intKey;
try
{
intKey = Convert.ToInt32(command, 16);
}
catch
{
intKey = -1;
}
if (intKey > 0)
KeyboardHook.KeyPress((Keys)intKey);
else
LaunchProcess(command);
}
public void KeyPressed(object sender, KeyPressedEventArgs e)
{
if (e.Modifier == ModifierKeys.None)
{
Logger.WriteLine(e.Key.ToString());
if (AppConfig.ContainsModel("Z13"))
{
switch (e.Key)
{
case Keys.F2:
KeyboardHook.KeyPress(Keys.VolumeDown);
return;
case Keys.F3:
KeyboardHook.KeyPress(Keys.VolumeUp);
return;
case Keys.F4:
KeyProcess("m3");
return;
case Keys.F11:
HandleEvent(199);
return;
}
}
if (AppConfig.ContainsModel("GA401I") && !AppConfig.ContainsModel("GA401IHR"))
{
switch (e.Key)
{
case Keys.F2:
KeyboardHook.KeyPress(Keys.MediaPreviousTrack);
return;
case Keys.F3:
KeyboardHook.KeyPress(Keys.MediaPlayPause);
return;
case Keys.F4:
KeyboardHook.KeyPress(Keys.MediaNextTrack);
return;
}
}
switch (e.Key)
{
case Keys.F1:
KeyboardHook.KeyPress(Keys.VolumeMute);
break;
case Keys.F2:
HandleEvent(197);
break;
case Keys.F3:
HandleEvent(196);
break;
case Keys.F4:
KeyProcess("fnf4");
break;
case Keys.F5:
KeyProcess("fnf5");
break;
case Keys.F6:
KeyboardHook.KeyPress(Keys.Snapshot);
break;
case Keys.F7:
if (AppConfig.ContainsModel("TUF"))
Program.toast.RunToast(ScreenBrightness.Adjust(-10) + "%", ToastIcon.BrightnessDown);
HandleOptimizationEvent(16);
break;
case Keys.F8:
if (AppConfig.ContainsModel("TUF"))
Program.toast.RunToast(ScreenBrightness.Adjust(+10) + "%", ToastIcon.BrightnessUp);
HandleOptimizationEvent(32);
break;
case Keys.F9:
KeyboardHook.KeyWinPress(Keys.P);
break;
case Keys.F10:
HandleOptimizationEvent(107);
break;
case Keys.F11:
HandleOptimizationEvent(108);
break;
case Keys.F12:
KeyboardHook.KeyWinPress(Keys.A);
break;
case Keys.VolumeDown:
KeyProcess("m1");
break;
case Keys.VolumeUp:
KeyProcess("m2");
break;
default:
break;
}
}
if (e.Modifier == (ModifierKeys.Control | ModifierKeys.Shift))
{
if (e.Key == keyProfile) modeControl.CyclePerformanceMode();
if (e.Key == keyApp) Program.SettingsToggle();
}
}
public static void KeyProcess(string name = "m3")
{
string action = AppConfig.GetString(name);
if (action is null || action.Length <= 1)
{
if (name == "m4")
action = "ghelper";
if (name == "fnf4")
action = "aura";
if (name == "fnf5")
action = "performance";
if (name == "m3" && !OptimizationService.IsRunning())
action = "micmute";
if (name == "fnc")
action = "fnlock";
}
switch (action)
{
case "mute":
KeyboardHook.KeyPress(Keys.VolumeMute);
break;
case "play":
KeyboardHook.KeyPress(Keys.MediaPlayPause);
break;
case "screenshot":
KeyboardHook.KeyPress(Keys.Snapshot);
break;
case "screen":
Logger.WriteLine("Screen off toggle");
NativeMethods.TurnOffScreen(Program.settingsForm.Handle);
break;
case "miniled":
screenControl.ToogleMiniled();
break;
case "aura":
Program.settingsForm.BeginInvoke(Program.settingsForm.CycleAuraMode);
break;
case "performance":
modeControl.CyclePerformanceMode();
break;
case "ghelper":
Program.settingsForm.BeginInvoke(delegate
{
Program.SettingsToggle();
});
break;
case "fnlock":
ToggleFnLock();
break;
case "micmute":
using (var enumerator = new MMDeviceEnumerator())
{
var commDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications);
bool muteStatus = !commDevice.AudioEndpointVolume.Mute;
commDevice.AudioEndpointVolume.Mute = muteStatus;
Program.toast.RunToast(muteStatus ? "Muted" : "Unmuted", muteStatus ? ToastIcon.MicrophoneMute : ToastIcon.Microphone);
}
break;
case "brightness_up":
HandleOptimizationEvent(32);
break;
case "brightness_down":
HandleOptimizationEvent(16);
break;
case "custom":
CustomKey(name);
break;
default:
break;
}
}
static bool GetTouchpadState()
{
using (var key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\PrecisionTouchPad\Status", false))
{
return key?.GetValue("Enabled")?.ToString() == "1";
}
}
static void ToggleFnLock()
{
int fnLock = AppConfig.Is("fn_lock") ? 0 : 1;
AppConfig.Set("fn_lock", fnLock);
if (AppConfig.ContainsModel("VivoBook"))
Program.acpi.DeviceSet(AsusACPI.FnLock, fnLock == 1 ? 0 : 1, "FnLock");
else
Program.settingsForm.BeginInvoke(Program.inputDispatcher.RegisterKeys);
Program.toast.RunToast("Fn-Lock " + (fnLock == 1 ? "On" : "Off"), ToastIcon.FnLock);
}
public static void TabletMode()
{
if (AppConfig.Is("disable_tablet")) return;
bool touchpadState = GetTouchpadState();
bool tabletState = Program.acpi.DeviceGet(AsusACPI.TabletState) > 0;
Logger.WriteLine("Tablet: " + tabletState + " Touchpad: " + touchpadState);
if (tabletState && touchpadState || !tabletState && !touchpadState) AsusUSB.TouchpadToggle();
}
static void HandleEvent(int EventID)
{
switch (EventID)
{
case 124: // M3
KeyProcess("m3");
return;
case 56: // M4 / Rog button
KeyProcess("m4");
return;
case 174: // FN+F5
modeControl.CyclePerformanceMode();
return;
case 179: // FN+F4
case 178: // FN+F4
KeyProcess("fnf4");
return;
case 158: // Fn + C
KeyProcess("fnc");
return;
case 78: // Fn + ESC
ToggleFnLock();
return;
case 189: // Tablet mode
TabletMode();
return;
case 197: // FN+F2
SetBacklight(-1);
return;
case 196: // FN+F3
SetBacklight(1);
return;
case 199: // ON Z13 - FN+F11 - cycles backlight
SetBacklight(4);
return;
case 53: // FN+F6 on GA-502DU model
NativeMethods.TurnOffScreen(Program.settingsForm.Handle);
return;
}
if (!OptimizationService.IsRunning())
HandleOptimizationEvent(EventID);
}
// Asus Optimization service Events
static void HandleOptimizationEvent(int EventID)
{
switch (EventID)
{
case 16: // FN+F7
//ScreenBrightness.Adjust(-10);
Program.acpi.DeviceSet(AsusACPI.UniversalControl, AsusACPI.Brightness_Down, "Brightness");
break;
case 32: // FN+F8
//ScreenBrightness.Adjust(+10);
Program.acpi.DeviceSet(AsusACPI.UniversalControl, AsusACPI.Brightness_Up, "Brightness");
break;
case 107: // FN+F10
bool touchpadState = GetTouchpadState();
AsusUSB.TouchpadToggle();
Program.toast.RunToast(touchpadState ? "Off" : "On", ToastIcon.Touchpad);
break;
case 108: // FN+F11
Program.acpi.DeviceSet(AsusACPI.UniversalControl, AsusACPI.KB_Sleep, "Sleep");
break;
}
}
public static int GetBacklight()
{
int backlight_power = AppConfig.Get("keyboard_brightness", 1);
int backlight_battery = AppConfig.Get("keyboard_brightness_ac", 1);
bool onBattery = SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online;
int backlight;
//backlight = onBattery ? Math.Min(backlight_battery, backlight_power) : Math.Max(backlight_battery, backlight_power);
backlight = onBattery ? backlight_battery : backlight_power;
return Math.Max(Math.Min(3, backlight), 0);
}
public static void SetBacklightAuto(bool init = false)
{
if (init) AsusUSB.Init();
//if (!OptimizationService.IsRunning())
AsusUSB.ApplyBrightness(GetBacklight(), "Auto");
}
public static void SetBacklight(int delta)
{
int backlight_power = AppConfig.Get("keyboard_brightness", 1);
int backlight_battery = AppConfig.Get("keyboard_brightness_ac", 1);
bool onBattery = SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online;
int backlight = onBattery ? backlight_battery : backlight_power;
if (delta >= 4)
backlight = ++backlight % 4;
else
backlight = Math.Max(Math.Min(3, backlight + delta), 0);
if (onBattery)
AppConfig.Set("keyboard_brightness_ac", backlight);
else
AppConfig.Set("keyboard_brightness", backlight);
if (!OptimizationService.IsRunning())
{
AsusUSB.ApplyBrightness(backlight, "HotKey");
string[] backlightNames = new string[] { "Off", "Low", "Mid", "Max" };
Program.toast.RunToast(backlightNames[backlight], delta > 0 ? ToastIcon.BacklightUp : ToastIcon.BacklightDown);
}
}
static void LaunchProcess(string command = "")
{
try
{
string executable = command.Split(' ')[0];
string arguments = command.Substring(executable.Length).Trim();
Process proc = Process.Start(executable, arguments);
}
catch
{
Logger.WriteLine("Failed to run " + command);
}
}
static void WatcherEventArrived(object sender, EventArrivedEventArgs e)
{
if (e.NewEvent is null) return;
int EventID = int.Parse(e.NewEvent["EventID"].ToString());
Logger.WriteLine("WMI event " + EventID);
HandleEvent(EventID);
}
}
}

173
app/Input/KeyboardHook.cs Normal file
View File

@@ -0,0 +1,173 @@
using System.Runtime.InteropServices;
public sealed class KeyboardHook : IDisposable
{
// Registers a hot key with Windows.
[DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
// Unregisters the hot key with Windows.
[DllImport("user32.dll")]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
[DllImport("user32.dll")]
private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern void keybd_event(byte virtualKey, byte scanCode, uint flags, IntPtr extraInfo);
public const int KEYEVENTF_EXTENDEDKEY = 1;
public const int KEYEVENTF_KEYUP = 2;
private const byte VK_LWIN = 0x5B;
public static void KeyPress(Keys key)
{
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
}
public static void KeyWinPress(Keys key)
{
keybd_event(VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero);
keybd_event(VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero);
}
/// <summary>
/// Represents the window that is used internally to get the messages.
/// </summary>
private class Window : NativeWindow, IDisposable
{
private static int WM_HOTKEY = 0x0312;
public static Keys? fakeKey;
public Window()
{
// create the handle for the window.
this.CreateHandle(new CreateParams());
}
/// <summary>
/// Overridden to get the notifications.
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
// check if we got a hot key pressed.
if (m.Msg == WM_HOTKEY)
{
// get the keys.
Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
ModifierKeys modifier = (ModifierKeys)((int)m.LParam & 0xFFFF);
// invoke the event to notify the parent.
if (KeyPressed != null)
KeyPressed(this, new KeyPressedEventArgs(modifier, key));
}
}
public event EventHandler<KeyPressedEventArgs> KeyPressed;
#region IDisposable Members
public void Dispose()
{
this.DestroyHandle();
}
#endregion
}
private Window _window = new Window();
private int _currentId;
public KeyboardHook()
{
// register the event of the inner native window.
_window.KeyPressed += delegate (object sender, KeyPressedEventArgs args)
{
if (KeyPressed != null)
KeyPressed(this, args);
};
}
/// <summary>
/// Registers a hot key in the system.
/// </summary>
/// <param name="modifier">The modifiers that are associated with the hot key.</param>
/// <param name="key">The key itself that is associated with the hot key.</param>
public void RegisterHotKey(ModifierKeys modifier, Keys key)
{
// increment the counter.
_currentId = _currentId + 1;
// register the hot key.
if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key))
Logger.WriteLine("Couldnt register " + key);
}
/// <summary>
/// A hot key has been pressed.
/// </summary>
public event EventHandler<KeyPressedEventArgs> KeyPressed;
#region IDisposable Members
public void UnregisterAll()
{
// unregister all the registered hot keys.
for (int i = _currentId; i > 0; i--)
{
UnregisterHotKey(_window.Handle, i);
}
}
public void Dispose()
{
UnregisterAll();
// dispose the inner native window.
_window.Dispose();
}
#endregion
}
/// <summary>
/// Event Args for the event that is fired after the hot key has been pressed.
/// </summary>
public class KeyPressedEventArgs : EventArgs
{
private ModifierKeys _modifier;
private Keys _key;
internal KeyPressedEventArgs(ModifierKeys modifier, Keys key)
{
_modifier = modifier;
_key = key;
}
public ModifierKeys Modifier
{
get { return _modifier; }
}
public Keys Key
{
get { return _key; }
}
}
/// <summary>
/// The enumeration of possible modifiers.
/// </summary>
[Flags]
public enum ModifierKeys : uint
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
Win = 8
}

View File

@@ -0,0 +1,69 @@
using HidLibrary;
namespace GHelper.Input
{
public class KeyboardListener
{
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
public KeyboardListener(Action<int> KeyHandler)
{
HidDevice? input = AsusUSB.GetDevice();
// Fallback
if (input == null)
{
AsusUSB.Init();
Thread.Sleep(1000);
input = AsusUSB.GetDevice();
}
if (input == null)
{
Logger.WriteLine($"Input device not found");
return;
}
Logger.WriteLine($"Input: {input.DevicePath}");
var task = Task.Run(() =>
{
try
{
while (!cancellationTokenSource.Token.IsCancellationRequested)
{
// Emergency break
if (input == null || !input.IsConnected)
{
Logger.WriteLine("Listener terminated");
break;
}
var data = input.Read().Data;
if (data.Length > 1 && data[0] == AsusUSB.INPUT_HID_ID && data[1] > 0 && data[1] != 236)
{
Logger.WriteLine($"Key: {data[1]}");
KeyHandler(data[1]);
}
}
Logger.WriteLine("Listener stopped");
}
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
}
});
}
public void Dispose()
{
cancellationTokenSource?.Cancel();
}
}
}

423
app/Mode/ModeControl.cs Normal file
View File

@@ -0,0 +1,423 @@
using GHelper.Battery;
using GHelper.Gpu.NVidia;
using GHelper.Helpers;
using Ryzen;
namespace GHelper.Mode
{
public class ModeControl
{
static SettingsForm settings = Program.settingsForm;
private static bool customFans = false;
private static int customPower = 0;
private int _cpuUV = 0;
private int _igpuUV = 0;
static System.Timers.Timer reapplyTimer = default!;
public ModeControl()
{
reapplyTimer = new System.Timers.Timer(AppConfig.GetMode("reapply_time", 30) * 1000);
reapplyTimer.Elapsed += ReapplyTimer_Elapsed;
reapplyTimer.Enabled = false;
}
private void ReapplyTimer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{
SetCPUTemp(AppConfig.GetMode("cpu_temp"), false);
}
public void AutoPerformance(bool powerChanged = false)
{
var Plugged = SystemInformation.PowerStatus.PowerLineStatus;
int mode = AppConfig.Get("performance_" + (int)Plugged);
if (mode != -1)
SetPerformanceMode(mode, powerChanged);
else
SetPerformanceMode(Modes.GetCurrent());
}
public void ResetPerformanceMode()
{
ResetRyzen();
Program.acpi.DeviceSet(AsusACPI.PerformanceMode, Modes.GetCurrentBase(), "Mode");
}
public void SetPerformanceMode(int mode = -1, bool notify = false)
{
int oldMode = Modes.GetCurrent();
if (mode < 0) mode = oldMode;
if (!Modes.Exists(mode)) mode = 0;
customFans = false;
customPower = 0;
settings.ShowMode(mode);
SetModeLabel();
Modes.SetCurrent(mode);
Program.acpi.DeviceSet(AsusACPI.PerformanceMode, IsManualModeRequired() ? AsusACPI.PerformanceManual : Modes.GetBase(mode), "Mode");
if (AppConfig.Is("xgm_fan") && Program.acpi.IsXGConnected()) AsusUSB.ResetXGM();
if (notify)
Program.toast.RunToast(Modes.GetCurrentName(), SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online ? ToastIcon.Charger : ToastIcon.Battery);
SetGPUClocks();
AutoFans();
AutoPower(1000);
if (AppConfig.Get("auto_apply_power_plan") != 0)
{
if (AppConfig.GetModeString("scheme") is not null)
PowerNative.SetPowerScheme(AppConfig.GetModeString("scheme"));
else
PowerNative.SetPowerScheme(Modes.GetBase(mode));
}
if (AppConfig.GetMode("auto_boost") != -1)
{
PowerNative.SetCPUBoost(AppConfig.GetMode("auto_boost"));
}
//BatteryControl.SetBatteryChargeLimit();
/*
if (NativeMethods.PowerGetEffectiveOverlayScheme(out Guid activeScheme) == 0)
{
Debug.WriteLine("Effective :" + activeScheme);
}
*/
settings.FansInit();
}
public void CyclePerformanceMode()
{
SetPerformanceMode(Modes.GetNext(Control.ModifierKeys == Keys.Shift), true);
}
public void AutoFans(bool force = false)
{
customFans = false;
if (AppConfig.IsMode("auto_apply") || force)
{
bool xgmFan = false;
if (AppConfig.Is("xgm_fan") && Program.acpi.IsXGConnected())
{
AsusUSB.SetXGMFan(AppConfig.GetFanConfig(AsusFan.XGM));
xgmFan = true;
}
int cpuResult = Program.acpi.SetFanCurve(AsusFan.CPU, AppConfig.GetFanConfig(AsusFan.CPU));
int gpuResult = Program.acpi.SetFanCurve(AsusFan.GPU, AppConfig.GetFanConfig(AsusFan.GPU));
if (AppConfig.Is("mid_fan"))
Program.acpi.SetFanCurve(AsusFan.Mid, AppConfig.GetFanConfig(AsusFan.Mid));
// something went wrong, resetting to default profile
if (cpuResult != 1 || gpuResult != 1)
{
int mode = Modes.GetCurrentBase();
Logger.WriteLine("ASUS BIOS rejected fan curve, resetting mode to " + mode);
Program.acpi.DeviceSet(AsusACPI.PerformanceMode, mode, "Reset Mode");
settings.LabelFansResult("ASUS BIOS rejected fan curve");
}
else
{
settings.LabelFansResult("");
customFans = true;
}
// force set PPTs for missbehaving bios on FX507/517 series
if ((AppConfig.ContainsModel("FX507") || AppConfig.ContainsModel("FX517") || xgmFan) && !AppConfig.IsMode("auto_apply_power"))
{
Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromSeconds(1));
Program.acpi.DeviceSet(AsusACPI.PPT_TotalA0, 80, "PowerLimit Fix A0");
Program.acpi.DeviceSet(AsusACPI.PPT_APUA3, 80, "PowerLimit Fix A3");
});
}
}
SetModeLabel();
}
private static bool IsManualModeRequired()
{
if (!AppConfig.IsMode("auto_apply_power"))
return false;
return
AppConfig.Is("manual_mode") ||
AppConfig.ContainsModel("GU603") ||
AppConfig.ContainsModel("GU604") ||
AppConfig.ContainsModel("G733");
}
private static bool IsFanRequired()
{
return AppConfig.ContainsModel("GA402XI") || AppConfig.ContainsModel("G513");
}
public void AutoPower(int delay = 0)
{
customPower = 0;
bool applyPower = AppConfig.IsMode("auto_apply_power");
bool applyFans = AppConfig.IsMode("auto_apply");
//bool applyGPU = true;
if (applyPower)
{
// force fan curve for misbehaving bios PPTs on some models
if (!applyFans && IsFanRequired())
{
delay = 500;
AutoFans(true);
}
// Fix for models that don't support PPT settings in all modes, setting a "manual" mode for them
if (IsManualModeRequired() && !applyFans)
{
AutoFans(true);
}
}
if (delay > 0)
{
var timer = new System.Timers.Timer(delay);
timer.Elapsed += delegate
{
timer.Stop();
timer.Dispose();
if (applyPower) SetPower();
SetGPUPower();
AutoRyzen();
};
timer.Start();
}
else
{
if (applyPower) SetPower(true);
SetGPUPower();
AutoRyzen();
}
}
public void SetModeLabel()
{
settings.SetModeLabel(Properties.Strings.PerformanceMode + ": " + Modes.GetCurrentName() + (customFans ? "+" : "") + ((customPower > 0) ? " " + customPower + "W" : ""));
}
public void SetPower(bool launchAsAdmin = false)
{
int limit_total = AppConfig.GetMode("limit_total");
int limit_cpu = AppConfig.GetMode("limit_cpu");
int limit_fast = AppConfig.GetMode("limit_fast");
if (limit_total > AsusACPI.MaxTotal) return;
if (limit_total < AsusACPI.MinTotal) return;
if (limit_cpu > AsusACPI.MaxCPU) return;
if (limit_cpu < AsusACPI.MinCPU) return;
if (limit_fast > AsusACPI.MaxTotal) return;
if (limit_fast < AsusACPI.MinTotal) return;
// SPL + SPPT togeher in one slider
if (Program.acpi.DeviceGet(AsusACPI.PPT_TotalA0) >= 0)
{
Program.acpi.DeviceSet(AsusACPI.PPT_TotalA0, limit_total, "PowerLimit A0");
Program.acpi.DeviceSet(AsusACPI.PPT_APUA3, limit_total, "PowerLimit A3");
customPower = limit_total;
}
else if (RyzenControl.IsAMD())
{
if (ProcessHelper.IsUserAdministrator())
{
var stapmResult = SendCommand.set_stapm_limit((uint)limit_total * 1000);
Logger.WriteLine($"STAPM: {limit_total} {stapmResult}");
var stapmResult2 = SendCommand.set_stapm2_limit((uint)limit_total * 1000);
Logger.WriteLine($"STAPM2: {limit_total} {stapmResult2}");
var slowResult = SendCommand.set_slow_limit((uint)limit_total * 1000);
Logger.WriteLine($"SLOW: {limit_total} {slowResult}");
var fastResult = SendCommand.set_fast_limit((uint)limit_total * 1000);
Logger.WriteLine($"FAST: {limit_total} {fastResult}");
customPower = limit_total;
}
else if (launchAsAdmin)
{
ProcessHelper.RunAsAdmin("cpu");
return;
}
}
if (Program.acpi.IsAllAmdPPT()) // CPU limit all amd models
{
Program.acpi.DeviceSet(AsusACPI.PPT_CPUB0, limit_cpu, "PowerLimit B0");
customPower = limit_cpu;
}
else if (Program.acpi.DeviceGet(AsusACPI.PPT_APUC1) >= 0) // FPPT boost for non all-amd models
{
Program.acpi.DeviceSet(AsusACPI.PPT_APUC1, limit_fast, "PowerLimit C1");
customPower = limit_fast;
}
SetModeLabel();
}
public void SetGPUClocks(bool launchAsAdmin = true)
{
int gpu_core = AppConfig.GetMode("gpu_core");
int gpu_memory = AppConfig.GetMode("gpu_memory");
if (gpu_core == -1 && gpu_memory == -1) return;
//if ((gpu_core > -5 && gpu_core < 5) && (gpu_memory > -5 && gpu_memory < 5)) launchAsAdmin = false;
if (Program.acpi.DeviceGet(AsusACPI.GPUEco) == 1) return;
if (HardwareControl.GpuControl is null) return;
if (!HardwareControl.GpuControl!.IsNvidia) return;
using NvidiaGpuControl nvControl = (NvidiaGpuControl)HardwareControl.GpuControl;
try
{
int getStatus = nvControl.GetClocks(out int current_core, out int current_memory);
if (getStatus != -1)
{
if (Math.Abs(gpu_core - current_core) < 5 && Math.Abs(gpu_memory - current_memory) < 5) return;
}
int setStatus = nvControl.SetClocks(gpu_core, gpu_memory);
if (launchAsAdmin && setStatus == -1) ProcessHelper.RunAsAdmin("gpu");
}
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
}
}
public void SetGPUPower()
{
int gpu_boost = AppConfig.GetMode("gpu_boost");
int gpu_temp = AppConfig.GetMode("gpu_temp");
if (gpu_boost < AsusACPI.MinGPUBoost || gpu_boost > AsusACPI.MaxGPUBoost) return;
if (gpu_temp < AsusACPI.MinGPUTemp || gpu_temp > AsusACPI.MaxGPUTemp) return;
if (Program.acpi.DeviceGet(AsusACPI.PPT_GPUC0) >= 0)
Program.acpi.DeviceSet(AsusACPI.PPT_GPUC0, gpu_boost, "PowerLimit C0");
if (Program.acpi.DeviceGet(AsusACPI.PPT_GPUC2) >= 0)
Program.acpi.DeviceSet(AsusACPI.PPT_GPUC2, gpu_temp, "PowerLimit C2");
}
public void SetCPUTemp(int? cpuTemp, bool log = true)
{
if (cpuTemp >= RyzenControl.MinTemp && cpuTemp < RyzenControl.MaxTemp)
{
var resultCPU = SendCommand.set_tctl_temp((uint)cpuTemp);
if (log) Logger.WriteLine($"CPU Temp: {cpuTemp} {resultCPU}");
var restultAPU = SendCommand.set_apu_skin_temp_limit((uint)cpuTemp);
if (log) Logger.WriteLine($"APU Temp: {cpuTemp} {restultAPU}");
reapplyTimer.Enabled = AppConfig.IsMode("auto_uv");
}
else
{
reapplyTimer.Enabled = false;
}
}
public void SetUV(int cpuUV)
{
if (cpuUV >= RyzenControl.MinCPUUV && cpuUV <= RyzenControl.MaxCPUUV)
{
var uvResult = SendCommand.set_coall(cpuUV);
Logger.WriteLine($"UV: {cpuUV} {uvResult}");
if (uvResult == Smu.Status.OK) _cpuUV = cpuUV;
}
}
public void SetUViGPU(int igpuUV)
{
if (igpuUV >= RyzenControl.MinIGPUUV && igpuUV <= RyzenControl.MaxIGPUUV)
{
var iGPUResult = SendCommand.set_cogfx(igpuUV);
Logger.WriteLine($"iGPU UV: {igpuUV} {iGPUResult}");
if (iGPUResult == Smu.Status.OK) _igpuUV = igpuUV;
}
}
public void SetRyzen(bool launchAsAdmin = false)
{
if (!ProcessHelper.IsUserAdministrator())
{
if (launchAsAdmin) ProcessHelper.RunAsAdmin("uv");
return;
}
try
{
SetUV(AppConfig.GetMode("cpu_uv", 0));
SetUViGPU(AppConfig.GetMode("igpu_uv", 0));
SetCPUTemp(AppConfig.GetMode("cpu_temp"));
}
catch (Exception ex)
{
Logger.WriteLine("UV Error: " + ex.ToString());
}
}
public void ResetRyzen()
{
if (_cpuUV != 0) SetUV(0);
if (_igpuUV != 0) SetUViGPU(0);
}
public void AutoRyzen()
{
if (!RyzenControl.IsAMD()) return;
if (AppConfig.IsMode("auto_uv")) SetRyzen();
else ResetRyzen();
}
}
}

154
app/Mode/Modes.cs Normal file
View File

@@ -0,0 +1,154 @@
namespace GHelper.Mode
{
internal class Modes
{
const int maxModes = 20;
public static Dictionary<int, string> GetDictonary()
{
Dictionary<int, string> modes = new Dictionary<int, string>
{
{2, Properties.Strings.Silent},
{0, Properties.Strings.Balanced},
{1, Properties.Strings.Turbo}
};
for (int i = 3; i < maxModes; i++)
{
if (Exists(i)) modes.Add(i, GetName(i));
}
return modes;
}
public static List<int> GetList()
{
List<int> modes = new() { 2, 0, 1 };
for (int i = 3; i < maxModes; i++)
{
if (Exists(i)) modes.Add(i);
}
return modes;
}
public static void Remove(int mode)
{
List<string> cleanup = new() {
"mode_base",
"mode_name",
"limit_total",
"limit_fast",
"limit_cpu",
"limit_total",
"fan_profile_cpu",
"fan_profile_gpu",
"fan_profile_mid",
"gpu_boost",
"gpu_temp",
"gpu_core",
"gpu_memory",
"auto_boost",
"auto_apply",
"auto_apply_power"
};
foreach (string clean in cleanup)
{
AppConfig.Remove(clean + "_" + mode);
}
}
public static int Add()
{
for (int i = 3; i < maxModes; i++)
{
if (!Exists(i))
{
int modeBase = GetCurrentBase();
string nameName = "Custom " + (i - 2);
AppConfig.Set("mode_base_" + i, modeBase);
AppConfig.Set("mode_name_" + i, nameName);
return i;
}
}
return -1;
}
public static int GetCurrent()
{
return AppConfig.Get("performance_mode");
}
public static bool IsCurrentCustom()
{
return GetCurrent() > 2;
}
public static void SetCurrent(int mode)
{
AppConfig.Set("performance_" + (int)SystemInformation.PowerStatus.PowerLineStatus, mode);
AppConfig.Set("performance_mode", mode);
}
public static int GetCurrentBase()
{
return GetBase(GetCurrent());
}
public static string GetCurrentName()
{
return GetName(GetCurrent());
}
public static bool Exists(int mode)
{
return GetBase(mode) >= 0;
}
public static int GetBase(int mode)
{
if (mode >= 0 && mode <= 2)
return mode;
else
return AppConfig.Get("mode_base_" + mode);
}
public static string GetName(int mode)
{
switch (mode)
{
case 0:
return Properties.Strings.Balanced;
case 1:
return Properties.Strings.Turbo;
case 2:
return Properties.Strings.Silent;
default:
return AppConfig.GetString("mode_name_" + mode);
}
}
public static int GetNext(bool back = false)
{
var modes = GetList();
int index = modes.IndexOf(GetCurrent());
if (back)
{
index--;
if (index < 0) index = modes.Count - 1;
return modes[index];
}
else
{
index++;
if (index > modes.Count - 1) index = 0;
return modes[index];
}
}
}
}

167
app/Mode/PowerNative.cs Normal file
View File

@@ -0,0 +1,167 @@
using System.Runtime.InteropServices;
namespace GHelper.Mode
{
internal class PowerNative
{
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerWriteDCValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
int AcValueIndex);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerWriteACValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
int AcValueIndex);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerReadACValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
out IntPtr AcValueIndex
);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerReadDCValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
out IntPtr AcValueIndex
);
[DllImport("powrprof.dll")]
static extern uint PowerReadACValue(
IntPtr RootPowerKey,
Guid SchemeGuid,
Guid SubGroupOfPowerSettingGuid,
Guid PowerSettingGuid,
ref int Type,
ref IntPtr Buffer,
ref uint BufferSize
);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerSetActiveScheme(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerGetActiveScheme(IntPtr UserPowerKey, out IntPtr ActivePolicyGuid);
static readonly Guid GUID_CPU = new Guid("54533251-82be-4824-96c1-47b60b740d00");
static readonly Guid GUID_BOOST = new Guid("be337238-0d82-4146-a960-4f3749d470c7");
private static Guid GUID_SLEEP_SUBGROUP = new Guid("238c9fa8-0aad-41ed-83f4-97be242c8f20");
private static Guid GUID_HIBERNATEIDLE = new Guid("9d7815a6-7ee4-497e-8888-515a05f02364");
[DllImportAttribute("powrprof.dll", EntryPoint = "PowerGetActualOverlayScheme")]
public static extern uint PowerGetActualOverlayScheme(out Guid ActualOverlayGuid);
[DllImportAttribute("powrprof.dll", EntryPoint = "PowerGetEffectiveOverlayScheme")]
public static extern uint PowerGetEffectiveOverlayScheme(out Guid EffectiveOverlayGuid);
[DllImportAttribute("powrprof.dll", EntryPoint = "PowerSetActiveOverlayScheme")]
public static extern uint PowerSetActiveOverlayScheme(Guid OverlaySchemeGuid);
static Guid GetActiveScheme()
{
IntPtr pActiveSchemeGuid;
var hr = PowerGetActiveScheme(IntPtr.Zero, out pActiveSchemeGuid);
Guid activeSchemeGuid = (Guid)Marshal.PtrToStructure(pActiveSchemeGuid, typeof(Guid));
return activeSchemeGuid;
}
public static int GetCPUBoost()
{
IntPtr AcValueIndex;
Guid activeSchemeGuid = GetActiveScheme();
UInt32 value = PowerReadACValueIndex(IntPtr.Zero,
activeSchemeGuid,
GUID_CPU,
GUID_BOOST, out AcValueIndex);
return AcValueIndex.ToInt32();
}
public static void SetCPUBoost(int boost = 0)
{
Guid activeSchemeGuid = GetActiveScheme();
if (boost == GetCPUBoost()) return;
var hrAC = PowerWriteACValueIndex(
IntPtr.Zero,
activeSchemeGuid,
GUID_CPU,
GUID_BOOST,
boost);
PowerSetActiveScheme(IntPtr.Zero, activeSchemeGuid);
var hrDC = PowerWriteDCValueIndex(
IntPtr.Zero,
activeSchemeGuid,
GUID_CPU,
GUID_BOOST,
boost);
PowerSetActiveScheme(IntPtr.Zero, activeSchemeGuid);
Logger.WriteLine("Boost " + boost);
}
public static void SetPowerScheme(string scheme)
{
List<string> overlays = new() {
"00000000-0000-0000-0000-000000000000",
"ded574b5-45a0-4f42-8737-46345c09c238",
"961cc777-2547-4f9d-8174-7d86181b8a7a",
"3af9B8d9-7c97-431d-ad78-34a8bfea439f"
};
Guid guidScheme = new Guid(scheme);
if (overlays.Contains(scheme))
{
uint status = PowerGetEffectiveOverlayScheme(out Guid activeScheme);
if (status != 0 || activeScheme != guidScheme)
{
PowerSetActiveOverlayScheme(guidScheme);
Logger.WriteLine("Power mode: " + scheme);
}
}
else
{
PowerSetActiveScheme(IntPtr.Zero, guidScheme);
Logger.WriteLine("Power plan: " + scheme);
}
}
public static void SetPowerScheme(int mode)
{
switch (mode)
{
case 0: // balanced
SetPowerScheme("00000000-0000-0000-0000-000000000000");
break;
case 1: // turbo
SetPowerScheme("ded574b5-45a0-4f42-8737-46345c09c238");
break;
case 2: //silent
SetPowerScheme("961cc777-2547-4f9d-8174-7d86181b8a7a");
break;
}
}
}
}

View File

@@ -1,356 +1,27 @@
using GHelper;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using static Tools.ScreenInterrogatory;
using System.Runtime.InteropServices;
namespace Tools
{
public class KeyHandler
{
public const int NOMOD = 0x0000;
public const int ALT = 0x0001;
public const int CTRL = 0x0002;
public const int SHIFT = 0x0004;
public const int WIN = 0x0008;
public const int WM_HOTKEY_MSG_ID = 0x0312;
[DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
[DllImport("user32.dll")]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
private int modifier;
private int key;
private IntPtr hWnd;
private int id;
public KeyHandler(int modifier, Keys key, nint handle)
{
this.modifier = modifier;
this.key = (int)key;
this.hWnd = handle;
id = this.GetHashCode();
}
public override int GetHashCode()
{
return modifier ^ key ^ hWnd.ToInt32();
}
public bool Register()
{
return RegisterHotKey(hWnd, id, modifier, key);
}
public bool Unregiser()
{
return UnregisterHotKey(hWnd, id);
}
}
public static class ScreenInterrogatory
{
public const int ERROR_SUCCESS = 0;
#region enums
public enum QUERY_DEVICE_CONFIG_FLAGS : uint
{
QDC_ALL_PATHS = 0x00000001,
QDC_ONLY_ACTIVE_PATHS = 0x00000002,
QDC_DATABASE_CURRENT = 0x00000004
}
public enum DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY : uint
{
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER = 0xFFFFFFFF,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HD15 = 0,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SVIDEO = 1,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPOSITE_VIDEO = 2,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPONENT_VIDEO = 3,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DVI = 4,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HDMI = 5,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_LVDS = 6,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_D_JPN = 8,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDI = 9,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EXTERNAL = 10,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED = 11,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EXTERNAL = 12,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EMBEDDED = 13,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDTVDONGLE = 14,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_MIRACAST = 15,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL = 0x80000000,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_FORCE_UINT32 = 0xFFFFFFFF
}
public enum DISPLAYCONFIG_SCANLINE_ORDERING : uint
{
DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED = 0,
DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE = 1,
DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED = 2,
DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_UPPERFIELDFIRST = DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED,
DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_LOWERFIELDFIRST = 3,
DISPLAYCONFIG_SCANLINE_ORDERING_FORCE_UINT32 = 0xFFFFFFFF
}
public enum DISPLAYCONFIG_ROTATION : uint
{
DISPLAYCONFIG_ROTATION_IDENTITY = 1,
DISPLAYCONFIG_ROTATION_ROTATE90 = 2,
DISPLAYCONFIG_ROTATION_ROTATE180 = 3,
DISPLAYCONFIG_ROTATION_ROTATE270 = 4,
DISPLAYCONFIG_ROTATION_FORCE_UINT32 = 0xFFFFFFFF
}
public enum DISPLAYCONFIG_SCALING : uint
{
DISPLAYCONFIG_SCALING_IDENTITY = 1,
DISPLAYCONFIG_SCALING_CENTERED = 2,
DISPLAYCONFIG_SCALING_STRETCHED = 3,
DISPLAYCONFIG_SCALING_ASPECTRATIOCENTEREDMAX = 4,
DISPLAYCONFIG_SCALING_CUSTOM = 5,
DISPLAYCONFIG_SCALING_PREFERRED = 128,
DISPLAYCONFIG_SCALING_FORCE_UINT32 = 0xFFFFFFFF
}
public enum DISPLAYCONFIG_PIXELFORMAT : uint
{
DISPLAYCONFIG_PIXELFORMAT_8BPP = 1,
DISPLAYCONFIG_PIXELFORMAT_16BPP = 2,
DISPLAYCONFIG_PIXELFORMAT_24BPP = 3,
DISPLAYCONFIG_PIXELFORMAT_32BPP = 4,
DISPLAYCONFIG_PIXELFORMAT_NONGDI = 5,
DISPLAYCONFIG_PIXELFORMAT_FORCE_UINT32 = 0xffffffff
}
public enum DISPLAYCONFIG_MODE_INFO_TYPE : uint
{
DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE = 1,
DISPLAYCONFIG_MODE_INFO_TYPE_TARGET = 2,
DISPLAYCONFIG_MODE_INFO_TYPE_FORCE_UINT32 = 0xFFFFFFFF
}
public enum DISPLAYCONFIG_DEVICE_INFO_TYPE : uint
{
DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME = 1,
DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME = 2,
DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_PREFERRED_MODE = 3,
DISPLAYCONFIG_DEVICE_INFO_GET_ADAPTER_NAME = 4,
DISPLAYCONFIG_DEVICE_INFO_SET_TARGET_PERSISTENCE = 5,
DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_BASE_TYPE = 6,
DISPLAYCONFIG_DEVICE_INFO_FORCE_UINT32 = 0xFFFFFFFF
}
#endregion
#region structs
[StructLayout(LayoutKind.Sequential)]
public struct LUID
{
public uint LowPart;
public int HighPart;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_PATH_SOURCE_INFO
{
public LUID adapterId;
public uint id;
public uint modeInfoIdx;
public uint statusFlags;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_PATH_TARGET_INFO
{
public LUID adapterId;
public uint id;
public uint modeInfoIdx;
private DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY outputTechnology;
private DISPLAYCONFIG_ROTATION rotation;
private DISPLAYCONFIG_SCALING scaling;
private DISPLAYCONFIG_RATIONAL refreshRate;
private DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering;
public bool targetAvailable;
public uint statusFlags;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_RATIONAL
{
public uint Numerator;
public uint Denominator;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_PATH_INFO
{
public DISPLAYCONFIG_PATH_SOURCE_INFO sourceInfo;
public DISPLAYCONFIG_PATH_TARGET_INFO targetInfo;
public uint flags;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_2DREGION
{
public uint cx;
public uint cy;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO
{
public ulong pixelRate;
public DISPLAYCONFIG_RATIONAL hSyncFreq;
public DISPLAYCONFIG_RATIONAL vSyncFreq;
public DISPLAYCONFIG_2DREGION activeSize;
public DISPLAYCONFIG_2DREGION totalSize;
public uint videoStandard;
public DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_TARGET_MODE
{
public DISPLAYCONFIG_VIDEO_SIGNAL_INFO targetVideoSignalInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct POINTL
{
private int x;
private int y;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_SOURCE_MODE
{
public uint width;
public uint height;
public DISPLAYCONFIG_PIXELFORMAT pixelFormat;
public POINTL position;
}
[StructLayout(LayoutKind.Explicit)]
public struct DISPLAYCONFIG_MODE_INFO_UNION
{
[FieldOffset(0)]
public DISPLAYCONFIG_TARGET_MODE targetMode;
[FieldOffset(0)]
public DISPLAYCONFIG_SOURCE_MODE sourceMode;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_MODE_INFO
{
public DISPLAYCONFIG_MODE_INFO_TYPE infoType;
public uint id;
public LUID adapterId;
public DISPLAYCONFIG_MODE_INFO_UNION modeInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS
{
public uint value;
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAYCONFIG_DEVICE_INFO_HEADER
{
public DISPLAYCONFIG_DEVICE_INFO_TYPE type;
public uint size;
public LUID adapterId;
public uint id;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DISPLAYCONFIG_TARGET_DEVICE_NAME
{
public DISPLAYCONFIG_DEVICE_INFO_HEADER header;
public DISPLAYCONFIG_TARGET_DEVICE_NAME_FLAGS flags;
public DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY outputTechnology;
public ushort edidManufactureId;
public ushort edidProductCodeId;
public uint connectorInstance;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string monitorFriendlyDeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string monitorDevicePath;
}
#endregion
#region DLL-Imports
[DllImport("user32.dll")]
public static extern int GetDisplayConfigBufferSizes(
QUERY_DEVICE_CONFIG_FLAGS flags, out uint numPathArrayElements, out uint numModeInfoArrayElements);
[DllImport("user32.dll")]
public static extern int QueryDisplayConfig(
QUERY_DEVICE_CONFIG_FLAGS flags,
ref uint numPathArrayElements, [Out] DISPLAYCONFIG_PATH_INFO[] PathInfoArray,
ref uint numModeInfoArrayElements, [Out] DISPLAYCONFIG_MODE_INFO[] ModeInfoArray,
IntPtr currentTopologyId
);
[DllImport("user32.dll")]
public static extern int DisplayConfigGetDeviceInfo(ref DISPLAYCONFIG_TARGET_DEVICE_NAME deviceName);
#endregion
private static DISPLAYCONFIG_TARGET_DEVICE_NAME DeviceName(LUID adapterId, uint targetId)
{
var deviceName = new DISPLAYCONFIG_TARGET_DEVICE_NAME
{
header =
{
size = (uint)Marshal.SizeOf(typeof (DISPLAYCONFIG_TARGET_DEVICE_NAME)),
adapterId = adapterId,
id = targetId,
type = DISPLAYCONFIG_DEVICE_INFO_TYPE.DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME
}
};
var error = DisplayConfigGetDeviceInfo(ref deviceName);
if (error != ERROR_SUCCESS)
throw new Win32Exception(error);
return deviceName;
}
public static IEnumerable<DISPLAYCONFIG_TARGET_DEVICE_NAME> GetAllDevices()
{
uint pathCount, modeCount;
var error = GetDisplayConfigBufferSizes(QUERY_DEVICE_CONFIG_FLAGS.QDC_ONLY_ACTIVE_PATHS, out pathCount, out modeCount);
if (error != ERROR_SUCCESS)
throw new Win32Exception(error);
var displayPaths = new DISPLAYCONFIG_PATH_INFO[pathCount];
var displayModes = new DISPLAYCONFIG_MODE_INFO[modeCount];
error = QueryDisplayConfig(QUERY_DEVICE_CONFIG_FLAGS.QDC_ONLY_ACTIVE_PATHS,
ref pathCount, displayPaths, ref modeCount, displayModes, IntPtr.Zero);
if (error != ERROR_SUCCESS)
throw new Win32Exception(error);
for (var i = 0; i < modeCount; i++)
if (displayModes[i].infoType == DISPLAYCONFIG_MODE_INFO_TYPE.DISPLAYCONFIG_MODE_INFO_TYPE_TARGET)
yield return DeviceName(displayModes[i].adapterId, displayModes[i].id);
}
}
}
public class NativeMethods
{
internal struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}
[DllImport("User32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
public static TimeSpan GetIdleTime()
{
LASTINPUTINFO lastInPut = new LASTINPUTINFO();
lastInPut.cbSize = (uint)Marshal.SizeOf(lastInPut);
GetLastInputInfo(ref lastInPut);
return TimeSpan.FromMilliseconds((uint)Environment.TickCount - lastInPut.dwTime);
}
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MONITORPOWER = 0xF170;
private const int MONITOR_OFF = 2;
@@ -435,348 +106,5 @@ public class NativeMethods
}
public const int KEYEVENTF_EXTENDEDKEY = 1;
public const int KEYEVENTF_KEYUP = 2;
public const int VK_MEDIA_NEXT_TRACK = 0xB0;
public const int VK_MEDIA_PLAY_PAUSE = 0xB3;
public const int VK_MEDIA_PREV_TRACK = 0xB1;
public const int VK_VOLUME_MUTE = 0xAD;
public const int VK_SNAPSHOT = 0x2C;
[DllImport("user32.dll", SetLastError = true)]
public static extern void keybd_event(byte virtualKey, byte scanCode, uint flags, IntPtr extraInfo);
public static void KeyPress(int key = VK_MEDIA_PLAY_PAUSE)
{
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
}
[DllImport("user32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
public const int SW_RESTORE = 9;
public static bool SwitchToCurrent()
{
IntPtr hWnd = IntPtr.Zero;
Process process = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(process.ProcessName);
foreach (Process _process in processes)
{
if (_process.Id != process.Id)
{
if (_process.MainWindowHandle != IntPtr.Zero)
{
Debug.WriteLine(_process.Id);
Debug.WriteLine(process.Id);
hWnd = _process.MainWindowHandle;
ShowWindowAsync(hWnd, SW_RESTORE);
}
return true;
break;
}
}
return false;
}
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerWriteDCValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
int AcValueIndex);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerWriteACValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
int AcValueIndex);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerReadACValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
out IntPtr AcValueIndex
);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerReadDCValueIndex(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid SubGroupOfPowerSettingsGuid,
[MarshalAs(UnmanagedType.LPStruct)] Guid PowerSettingGuid,
out IntPtr AcValueIndex
);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerSetActiveScheme(IntPtr RootPowerKey,
[MarshalAs(UnmanagedType.LPStruct)] Guid SchemeGuid);
[DllImport("PowrProf.dll", CharSet = CharSet.Unicode)]
static extern UInt32 PowerGetActiveScheme(IntPtr UserPowerKey, out IntPtr ActivePolicyGuid);
static readonly Guid GUID_CPU = new Guid("54533251-82be-4824-96c1-47b60b740d00");
static readonly Guid GUID_BOOST = new Guid("be337238-0d82-4146-a960-4f3749d470c7");
[DllImportAttribute("powrprof.dll", EntryPoint = "PowerGetActualOverlayScheme")]
public static extern uint PowerGetActualOverlayScheme(out Guid ActualOverlayGuid);
[DllImportAttribute("powrprof.dll", EntryPoint = "PowerGetEffectiveOverlayScheme")]
public static extern uint PowerGetEffectiveOverlayScheme(out Guid EffectiveOverlayGuid);
[DllImportAttribute("powrprof.dll", EntryPoint = "PowerSetActiveOverlayScheme")]
public static extern uint PowerSetActiveOverlayScheme(Guid OverlaySchemeGuid);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct DEVMODE
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string dmDeviceName;
public short dmSpecVersion;
public short dmDriverVersion;
public short dmSize;
public short dmDriverExtra;
public int dmFields;
public int dmPositionX;
public int dmPositionY;
public int dmDisplayOrientation;
public int dmDisplayFixedOutput;
public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string dmFormName;
public short dmLogPixels;
public short dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
public int dmICMMethod;
public int dmICMIntent;
public int dmMediaType;
public int dmDitherType;
public int dmReserved1;
public int dmReserved2;
public int dmPanningWidth;
public int dmPanningHeight;
};
[Flags()]
public enum DisplaySettingsFlags : int
{
CDS_UPDATEREGISTRY = 1,
CDS_TEST = 2,
CDS_FULLSCREEN = 4,
CDS_GLOBAL = 8,
CDS_SET_PRIMARY = 0x10,
CDS_RESET = 0x40000000,
CDS_NORESET = 0x10000000
}
// PInvoke declaration for EnumDisplaySettings Win32 API
[DllImport("user32.dll")]
public static extern int EnumDisplaySettingsEx(
string lpszDeviceName,
int iModeNum,
ref DEVMODE lpDevMode);
// PInvoke declaration for ChangeDisplaySettings Win32 API
[DllImport("user32.dll")]
public static extern int ChangeDisplaySettingsEx(
string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd,
DisplaySettingsFlags dwflags, IntPtr lParam);
public static DEVMODE CreateDevmode()
{
DEVMODE dm = new DEVMODE();
dm.dmDeviceName = new String(new char[32]);
dm.dmFormName = new String(new char[32]);
dm.dmSize = (short)Marshal.SizeOf(dm);
return dm;
}
public const int ENUM_CURRENT_SETTINGS = -1;
public const string defaultDevice = "\\\\.\\DISPLAY1";
public static string FindLaptopScreen()
{
string laptopScreen = null;
try
{
var devices = GetAllDevices().ToArray();
int count = 0, displayNum = -1;
foreach (var device in devices)
{
if (device.outputTechnology == DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY.DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL ||
device.outputTechnology == DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY.DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED)
{
displayNum = count;
}
count++;
//Logger.WriteLine(device.outputTechnology.ToString());
//Logger.WriteLine(device.monitorFriendlyDeviceName);
}
var screens = Screen.AllScreens;
if (screens.Length != count) return null;
count = 0;
foreach (var screen in screens)
{
if (count == displayNum)
{
laptopScreen = screen.DeviceName;
}
//Logger.WriteLine(screen.DeviceName);
count++;
}
}
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
Logger.WriteLine("Can't detect internal screen");
laptopScreen = Screen.PrimaryScreen.DeviceName;
}
return laptopScreen;
}
public static int GetRefreshRate(bool max = false)
{
DEVMODE dm = CreateDevmode();
string laptopScreen = FindLaptopScreen();
int frequency = -1;
if (laptopScreen is null)
return -1;
if (max)
{
int i = 0;
while (0 != NativeMethods.EnumDisplaySettingsEx(laptopScreen, i, ref dm))
{
if (dm.dmDisplayFrequency > frequency) frequency = dm.dmDisplayFrequency;
i++;
}
}
else
{
if (0 != NativeMethods.EnumDisplaySettingsEx(laptopScreen, NativeMethods.ENUM_CURRENT_SETTINGS, ref dm))
{
frequency = dm.dmDisplayFrequency;
}
}
return frequency;
}
public static int SetRefreshRate(int frequency = 120)
{
DEVMODE dm = CreateDevmode();
string laptopScreen = FindLaptopScreen();
if (laptopScreen is null)
return -1;
if (0 != NativeMethods.EnumDisplaySettingsEx(laptopScreen, NativeMethods.ENUM_CURRENT_SETTINGS, ref dm))
{
dm.dmDisplayFrequency = frequency;
int iRet = NativeMethods.ChangeDisplaySettingsEx(laptopScreen, ref dm, IntPtr.Zero, DisplaySettingsFlags.CDS_UPDATEREGISTRY, IntPtr.Zero);
Logger.WriteLine("Screen = " + frequency.ToString() + "Hz : " + (iRet == 0 ? "OK" : iRet));
return iRet;
}
return 0;
}
static Guid GetActiveScheme()
{
IntPtr pActiveSchemeGuid;
var hr = PowerGetActiveScheme(IntPtr.Zero, out pActiveSchemeGuid);
Guid activeSchemeGuid = (Guid)Marshal.PtrToStructure(pActiveSchemeGuid, typeof(Guid));
return activeSchemeGuid;
}
public static int GetCPUBoost()
{
IntPtr AcValueIndex;
Guid activeSchemeGuid = GetActiveScheme();
UInt32 value = PowerReadACValueIndex(IntPtr.Zero,
activeSchemeGuid,
GUID_CPU,
GUID_BOOST, out AcValueIndex);
return AcValueIndex.ToInt32();
}
public static void SetCPUBoost(int boost = 0)
{
Guid activeSchemeGuid = GetActiveScheme();
var hrAC = PowerWriteACValueIndex(
IntPtr.Zero,
activeSchemeGuid,
GUID_CPU,
GUID_BOOST,
boost);
PowerSetActiveScheme(IntPtr.Zero, activeSchemeGuid);
var hrDC = PowerWriteDCValueIndex(
IntPtr.Zero,
activeSchemeGuid,
GUID_CPU,
GUID_BOOST,
boost);
PowerSetActiveScheme(IntPtr.Zero, activeSchemeGuid);
Logger.WriteLine("Boost " + boost);
}
public static void SetPowerScheme(string scheme)
{
PowerSetActiveScheme(IntPtr.Zero, new Guid(scheme));
PowerSetActiveOverlayScheme(new Guid(scheme));
Logger.WriteLine(scheme);
}
public static void SetPowerScheme(int mode)
{
switch (mode)
{
case 0: // balanced
PowerSetActiveOverlayScheme(new Guid("00000000-0000-0000-0000-000000000000"));
break;
case 1: // turbo
PowerSetActiveOverlayScheme(new Guid("ded574b5-45a0-4f42-8737-46345c09c238"));
break;
case 2: //silent
PowerSetActiveOverlayScheme(new Guid("961cc777-2547-4f9d-8174-7d86181b8a7a"));
break;
}
}
}

View File

@@ -1,200 +0,0 @@
using System;
using NvAPIWrapper.Native.Display;
using NvAPIWrapper.Native.Display.Structures;
using NvAPIWrapper.Native.Interfaces.Display;
namespace NvAPIWrapper.Display
{
/// <inheritdoc cref="IColorData" />
public class ColorData : IColorData, IEquatable<ColorData>
{
/// <summary>
/// Creates an instance of <see cref="ColorData" /> to modify the color data
/// </summary>
/// <param name="colorFormat">The color data color format.</param>
/// <param name="colorimetry">The color data color space.</param>
/// <param name="dynamicRange">The color data dynamic range.</param>
/// <param name="colorDepth">The color data color depth.</param>
/// <param name="colorSelectionPolicy">The color data selection policy.</param>
/// <param name="desktopColorDepth">The color data desktop color depth.</param>
public ColorData(
ColorDataFormat colorFormat = ColorDataFormat.Auto,
ColorDataColorimetry colorimetry = ColorDataColorimetry.Auto,
ColorDataDynamicRange? dynamicRange = null,
ColorDataDepth? colorDepth = null,
ColorDataSelectionPolicy? colorSelectionPolicy = null,
ColorDataDesktopDepth? desktopColorDepth = null
)
{
ColorFormat = colorFormat;
Colorimetry = colorimetry;
DynamicRange = dynamicRange;
ColorDepth = colorDepth;
SelectionPolicy = colorSelectionPolicy;
DesktopColorDepth = desktopColorDepth;
}
internal ColorData(IColorData colorData)
{
ColorDepth = colorData.ColorDepth;
DynamicRange = colorData.DynamicRange;
ColorFormat = colorData.ColorFormat;
Colorimetry = colorData.Colorimetry;
SelectionPolicy = colorData.SelectionPolicy;
DesktopColorDepth = colorData.DesktopColorDepth;
}
/// <inheritdoc />
public ColorDataDepth? ColorDepth { get; }
/// <inheritdoc />
public ColorDataFormat ColorFormat { get; }
/// <inheritdoc />
public ColorDataColorimetry Colorimetry { get; }
/// <inheritdoc />
public ColorDataDesktopDepth? DesktopColorDepth { get; }
/// <inheritdoc />
public ColorDataDynamicRange? DynamicRange { get; }
/// <inheritdoc />
public ColorDataSelectionPolicy? SelectionPolicy { get; }
/// <inheritdoc />
public bool Equals(ColorData other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return ColorDepth == other.ColorDepth &&
ColorFormat == other.ColorFormat &&
Colorimetry == other.Colorimetry &&
DesktopColorDepth == other.DesktopColorDepth &&
DynamicRange == other.DynamicRange &&
SelectionPolicy == other.SelectionPolicy;
}
/// <summary>
/// Compares two instances of <see cref="ColorData" /> for equality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>true if two instances are equal; otherwise false.</returns>
public static bool operator ==(ColorData left, ColorData right)
{
return left?.Equals(right) == true;
}
/// <summary>
/// Compares two instances of <see cref="ColorData" /> for inequality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>true if two instances are not equal; otherwise false.</returns>
public static bool operator !=(ColorData left, ColorData right)
{
return !(left == right);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((ColorData) obj);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = ColorDepth.GetHashCode();
hashCode = (hashCode * 397) ^ (int) ColorFormat;
hashCode = (hashCode * 397) ^ (int) Colorimetry;
hashCode = (hashCode * 397) ^ DesktopColorDepth.GetHashCode();
hashCode = (hashCode * 397) ^ DynamicRange.GetHashCode();
hashCode = (hashCode * 397) ^ SelectionPolicy.GetHashCode();
return hashCode;
}
}
internal ColorDataV1 AsColorDataV1(ColorDataCommand command)
{
return new ColorDataV1(
command,
ColorFormat,
Colorimetry
);
}
internal ColorDataV2 AsColorDataV2(ColorDataCommand command)
{
return new ColorDataV2(
command,
ColorFormat,
Colorimetry,
DynamicRange ?? ColorDataDynamicRange.Auto
);
}
internal ColorDataV3 AsColorDataV3(ColorDataCommand command)
{
return new ColorDataV3(
command,
ColorFormat,
Colorimetry,
DynamicRange ?? ColorDataDynamicRange.Auto,
ColorDepth ?? ColorDataDepth.Default
);
}
internal ColorDataV4 AsColorDataV4(ColorDataCommand command)
{
return new ColorDataV4(
command,
ColorFormat,
Colorimetry,
DynamicRange ?? ColorDataDynamicRange.Auto,
ColorDepth ?? ColorDataDepth.Default,
SelectionPolicy ?? ColorDataSelectionPolicy.Default
);
}
internal ColorDataV5 AsColorDataV5(ColorDataCommand command)
{
return new ColorDataV5(
command,
ColorFormat,
Colorimetry,
DynamicRange ?? ColorDataDynamicRange.Auto,
ColorDepth ?? ColorDataDepth.Default,
SelectionPolicy ?? ColorDataSelectionPolicy.Default,
DesktopColorDepth ?? ColorDataDesktopDepth.Default
);
}
}
}

View File

@@ -1,245 +0,0 @@
using System;
using NvAPIWrapper.Native.Display;
using NvAPIWrapper.Native.Display.Structures;
namespace NvAPIWrapper.Display
{
/// <summary>
/// Hold information about a custom display resolution
/// </summary>
public class CustomResolution : IEquatable<CustomResolution>
{
/// <summary>
/// Creates an instance of <see cref="CustomResolution" />.
/// </summary>
/// <param name="width">The screen width.</param>
/// <param name="height">The screen height.</param>
/// <param name="colorFormat">The color format.</param>
/// <param name="timing">The resolution timing.</param>
/// <param name="xRatio">The horizontal scaling ratio.</param>
/// <param name="yRatio">The vertical scaling ratio.</param>
public CustomResolution(
uint width,
uint height,
ColorFormat colorFormat,
Timing timing,
float xRatio = 1,
float yRatio = 1
)
{
if (xRatio <= 0)
{
throw new ArgumentOutOfRangeException(nameof(xRatio));
}
if (yRatio <= 0)
{
throw new ArgumentOutOfRangeException(nameof(yRatio));
}
Width = width;
Height = height;
ColorFormat = colorFormat;
XRatio = xRatio;
YRatio = yRatio;
Timing = timing;
switch (ColorFormat)
{
case ColorFormat.P8:
ColorDepth = 8;
break;
case ColorFormat.R5G6B5:
ColorDepth = 16;
break;
case ColorFormat.A8R8G8B8:
ColorDepth = 24;
break;
case ColorFormat.A16B16G16R16F:
ColorDepth = 32;
break;
default:
throw new ArgumentException("Color format is invalid.", nameof(colorFormat));
}
}
/// <summary>
/// Creates an instance of <see cref="CustomResolution" />.
/// </summary>
/// <param name="width">The screen width.</param>
/// <param name="height">The screen height.</param>
/// <param name="colorDepth">The color depth.</param>
/// <param name="timing">The resolution timing.</param>
/// <param name="xRatio">The horizontal scaling ratio.</param>
/// <param name="yRatio">The vertical scaling ratio.</param>
public CustomResolution(
uint width,
uint height,
uint colorDepth,
Timing timing,
float xRatio = 1,
float yRatio = 1)
{
if (xRatio <= 0)
{
throw new ArgumentOutOfRangeException(nameof(xRatio));
}
if (yRatio <= 0)
{
throw new ArgumentOutOfRangeException(nameof(yRatio));
}
if (colorDepth != 0 && colorDepth != 8 && colorDepth != 16 && colorDepth != 24 && colorDepth != 32)
{
throw new ArgumentOutOfRangeException(nameof(colorDepth));
}
Width = width;
Height = height;
ColorDepth = colorDepth;
ColorFormat = ColorFormat.Unknown;
XRatio = xRatio;
YRatio = yRatio;
Timing = timing;
}
internal CustomResolution(CustomDisplay customDisplay)
{
Width = customDisplay.Width;
Height = customDisplay.Height;
ColorDepth = customDisplay.Depth;
ColorFormat = customDisplay.ColorFormat;
Timing = customDisplay.Timing;
XRatio = customDisplay.XRatio;
YRatio = customDisplay.YRatio;
}
/// <summary>
/// Gets the source surface color depth. "0" means all 8/16/32bpp.
/// </summary>
public uint ColorDepth { get; }
/// <summary>
/// Gets the color format (optional)
/// </summary>
public ColorFormat ColorFormat { get; }
/// <summary>
/// Gets the source surface (source mode) height.
/// </summary>
public uint Height { get; }
/// <summary>
/// Gets the timing used to program TMDS/DAC/LVDS/HDMI/TVEncoder, etc.
/// </summary>
public Timing Timing { get; }
/// <summary>
/// Gets the source surface (source mode) width.
/// </summary>
public uint Width { get; }
/// <summary>
/// Gets the horizontal scaling ratio.
/// </summary>
public float XRatio { get; }
/// <summary>
/// Gets the vertical scaling ratio.
/// </summary>
public float YRatio { get; }
/// <inheritdoc />
public bool Equals(CustomResolution other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Width == other.Width &&
Height == other.Height &&
ColorDepth == other.ColorDepth &&
Timing.Equals(other.Timing) &&
ColorFormat == other.ColorFormat &&
XRatio.Equals(other.XRatio) &&
YRatio.Equals(other.YRatio);
}
/// <summary>
/// Compares two instance of <see cref="CustomResolution" /> for equality.
/// </summary>
/// <param name="left">An first instance of <see cref="CustomResolution" /> to compare.</param>
/// <param name="right">An Second instance of <see cref="CustomResolution" /> to compare.</param>
/// <returns>True if both instances are equal, otherwise false.</returns>
public static bool operator ==(CustomResolution left, CustomResolution right)
{
return Equals(left, right);
}
/// <summary>
/// Compares two instance of <see cref="CustomResolution" /> for inequality.
/// </summary>
/// <param name="left">An first instance of <see cref="CustomResolution" /> to compare.</param>
/// <param name="right">An Second instance of <see cref="CustomResolution" /> to compare.</param>
/// <returns>True if both instances are not equal, otherwise false.</returns>
public static bool operator !=(CustomResolution left, CustomResolution right)
{
return !Equals(left, right);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((CustomResolution) obj);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) Width;
hashCode = (hashCode * 397) ^ (int) Height;
hashCode = (hashCode * 397) ^ (int) ColorDepth;
hashCode = (hashCode * 397) ^ Timing.GetHashCode();
hashCode = (hashCode * 397) ^ (int) ColorFormat;
hashCode = (hashCode * 397) ^ XRatio.GetHashCode();
hashCode = (hashCode * 397) ^ YRatio.GetHashCode();
return hashCode;
}
}
internal CustomDisplay AsCustomDisplay(bool hardwareModeSetOnly)
{
return new CustomDisplay(Width, Height, ColorDepth, ColorFormat, XRatio, YRatio, Timing,
hardwareModeSetOnly);
}
}
}

View File

@@ -1,325 +0,0 @@
using System;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.Display.Structures;
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.Interfaces.Display;
namespace NvAPIWrapper.Display
{
/// <summary>
/// This class contains and provides a way to modify the Digital Vibrance Control information regarding the
/// saturation level of the display or the output
/// </summary>
public class DVCInformation : IDisplayDVCInfo
{
private readonly DisplayHandle _displayHandle = DisplayHandle.DefaultHandle;
private readonly OutputId _outputId = OutputId.Invalid;
private bool? _isLegacy;
/// <summary>
/// Creates a new instance of the class using a DisplayHandle
/// </summary>
/// <param name="displayHandle">The handle of the display.</param>
public DVCInformation(DisplayHandle displayHandle)
{
_displayHandle = displayHandle;
}
/// <summary>
/// Creates a new instance of this class using a OutputId
/// </summary>
/// <param name="outputId">The output identification of a display or an output</param>
public DVCInformation(OutputId outputId)
{
_outputId = outputId;
}
/// <summary>
/// Gets and sets the normalized saturation level in the [-1,1] inclusive range.
/// a -1 value corresponds to the minimum saturation level and maximum under-saturation and the
/// a 1 value corresponds to the maximum saturation level and maximum over-saturation.
/// The value of 0 indicates the default saturation level.
/// </summary>
public double NormalizedLevel
{
get
{
var info = GetInfo();
if (info == null)
{
return double.NaN;
}
var deviance = info.CurrentLevel - info.DefaultLevel;
var range = deviance >= 0
? info.MaximumLevel - info.DefaultLevel
: info.DefaultLevel - info.MinimumLevel;
if (deviance == 0 || range == 0)
{
return 0;
}
return Math.Max(Math.Min((double) deviance / range, 1), -1);
}
set
{
if (double.IsNaN(value) || double.IsInfinity(value))
{
throw new ArgumentOutOfRangeException(nameof(value));
}
var info = GetInfo();
if (info == null)
{
return;
}
var range = value >= 0 ? info.MaximumLevel - info.DefaultLevel : info.DefaultLevel - info.MinimumLevel;
var level = Math.Max(Math.Min((int) (value * range) + info.DefaultLevel, info.MaximumLevel), info.MinimumLevel);
if (level == info.CurrentLevel)
{
return;
}
SetLevel(level);
}
}
/// <summary>
/// Gets and sets the current saturation level
/// </summary>
public int CurrentLevel
{
get => GetInfo()?.CurrentLevel ?? 0;
set
{
var info = GetInfo();
if (info == null)
{
return;
}
value = Math.Max(Math.Min(value, info.MaximumLevel), info.MinimumLevel);
if (info.CurrentLevel == value)
{
return;
}
SetLevel(value);
}
}
/// <inheritdoc />
public int DefaultLevel
{
get => GetInfo()?.DefaultLevel ?? 0;
}
/// <inheritdoc />
public int MaximumLevel
{
get => GetInfo()?.MaximumLevel ?? 0;
}
/// <inheritdoc />
public int MinimumLevel
{
get => GetInfo()?.MinimumLevel ?? 0;
}
/// <inheritdoc />
public override string ToString()
{
return
$"{CurrentLevel:D} @ [{MinimumLevel:D} <= {DefaultLevel:D} <= {MaximumLevel:D}] = {NormalizedLevel:F2}";
}
private IDisplayDVCInfo GetInfo()
{
if (_isLegacy == true)
{
return GetLegacyInfo();
}
if (_isLegacy == false)
{
return GetModernInfo();
}
var info = GetModernInfo() ?? GetLegacyInfo();
if (info == null)
{
// exception occured on both, force a mode
_isLegacy = false;
return GetInfo();
}
return info;
}
private IDisplayDVCInfo GetLegacyInfo()
{
try
{
var info = _outputId == OutputId.Invalid
? DisplayApi.GetDVCInfo(_displayHandle)
: DisplayApi.GetDVCInfo(_outputId);
if (info.MaximumLevel == 0 && info.MinimumLevel == 0 && info.CurrentLevel == 0)
{
return null;
}
if (!_isLegacy.HasValue)
{
_isLegacy = true;
}
return info;
}
catch (Exception)
{
if (_isLegacy == true)
{
throw;
}
// ignore
}
return null;
}
private IDisplayDVCInfo GetModernInfo()
{
try
{
var info = _outputId == OutputId.Invalid
? DisplayApi.GetDVCInfoEx(_displayHandle)
: DisplayApi.GetDVCInfoEx(_outputId);
if (info.MaximumLevel == 0 && info.MinimumLevel == 0 && info.CurrentLevel == 0)
{
return null;
}
if (!_isLegacy.HasValue)
{
_isLegacy = false;
}
return info;
}
catch (Exception)
{
if (_isLegacy == false)
{
throw;
}
// ignore
}
return null;
}
private bool SetLegacyLevel(int level)
{
try
{
if (_outputId == OutputId.Invalid)
{
DisplayApi.SetDVCLevel(_displayHandle, level);
}
else
{
DisplayApi.SetDVCLevel(_outputId, level);
}
if (!_isLegacy.HasValue)
{
_isLegacy = true;
}
return true;
}
catch (Exception)
{
if (_isLegacy == true)
{
throw;
}
// ignore
}
return false;
}
private void SetLevel(int level)
{
if (_isLegacy == true)
{
SetLegacyLevel(level);
}
else if (_isLegacy == false)
{
SetModernLevel(level);
}
else
{
var success = SetModernLevel(level) || SetLegacyLevel(level);
if (!success)
{
// exception occured on both, force a mode
_isLegacy = false;
SetLevel(level);
}
}
}
private bool SetModernLevel(int level)
{
try
{
if (_outputId == OutputId.Invalid)
{
DisplayApi.SetDVCLevelEx(_displayHandle, level);
}
else
{
DisplayApi.SetDVCLevelEx(_outputId, level);
}
if (!_isLegacy.HasValue)
{
_isLegacy = false;
}
return true;
}
catch (Exception)
{
if (_isLegacy == false)
{
throw;
}
// ignore
}
return false;
}
}
}

View File

@@ -1,232 +0,0 @@
using System;
using System.Linq;
using NvAPIWrapper.GPU;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.Display;
using NvAPIWrapper.Native.Display.Structures;
using NvAPIWrapper.Native.Exceptions;
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.Interfaces.Display;
namespace NvAPIWrapper.Display
{
/// <summary>
/// Represents an attached display
/// </summary>
public class Display : IEquatable<Display>
{
/// <summary>
/// Creates a new Display
/// </summary>
/// <param name="handle">Handle of the display device</param>
public Display(DisplayHandle handle)
{
Handle = handle;
}
/// <summary>
/// Creates a new Display
/// </summary>
/// <param name="displayName">Name of the display device</param>
public Display(string displayName)
{
Handle = DisplayApi.GetAssociatedNvidiaDisplayHandle(displayName);
}
/// <summary>
/// Gets the corresponding Digital Vibrance Control information
/// </summary>
public DVCInformation DigitalVibranceControl
{
get => new DVCInformation(Handle);
}
/// <summary>
/// Gets corresponding DisplayDevice based on display name
/// </summary>
public DisplayDevice DisplayDevice
{
get => new DisplayDevice(Name);
}
/// <summary>
/// Gets display driver build title
/// </summary>
public string DriverBuildTitle
{
get => DisplayApi.GetDisplayDriverBuildTitle(Handle);
}
/// <summary>
/// Gets display handle
/// </summary>
public DisplayHandle Handle { get; }
/// <summary>
/// Gets the display HDMI support information
/// </summary>
public IHDMISupportInfo HDMISupportInfo
{
get
{
var outputId = OutputId.Invalid;
try
{
outputId = DisplayApi.GetAssociatedDisplayOutputId(Handle);
}
catch (NVIDIAApiException)
{
// ignore
}
return DisplayApi.GetHDMISupportInfo(Handle, outputId);
}
}
/// <summary>
/// Gets the corresponding HUE information
/// </summary>
public HUEInformation HUEControl
{
get => new HUEInformation(Handle);
}
/// <summary>
/// Gets the driving logical GPU
/// </summary>
public LogicalGPU LogicalGPU
{
get => new LogicalGPU(GPUApi.GetLogicalGPUFromDisplay(Handle));
}
/// <summary>
/// Gets display name
/// </summary>
public string Name
{
get => DisplayApi.GetAssociatedNvidiaDisplayName(Handle);
}
/// <summary>
/// Gets the connected GPU output
/// </summary>
public GPUOutput Output
{
get => new GPUOutput(DisplayApi.GetAssociatedDisplayOutputId(Handle), PhysicalGPUs.FirstOrDefault());
}
/// <summary>
/// Gets the list of all physical GPUs responsible for this display, with the first GPU returned as the one with the
/// attached active output.
/// </summary>
public PhysicalGPU[] PhysicalGPUs
{
get => GPUApi.GetPhysicalGPUsFromDisplay(Handle).Select(handle => new PhysicalGPU(handle)).ToArray();
}
/// <inheritdoc />
public bool Equals(Display other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Handle.Equals(other.Handle);
}
/// <summary>
/// This function returns all NVIDIA displays
/// Note: Display handles can get invalidated on a modeset.
/// </summary>
/// <returns>An array of Display objects</returns>
public static Display[] GetDisplays()
{
return DisplayApi.EnumNvidiaDisplayHandle().Select(handle => new Display(handle)).ToArray();
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(Display left, Display right)
{
return right?.Equals(left) ?? ReferenceEquals(left, null);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(Display left, Display right)
{
return !(right == left);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((Display) obj);
}
/// <inheritdoc />
public override int GetHashCode()
{
return Handle.GetHashCode();
}
/// <inheritdoc />
public override string ToString()
{
return Name;
}
/// <summary>
/// Gets all the supported NVIDIA display views (nView and Dualview modes) for this display.
/// </summary>
/// <returns></returns>
public TargetViewMode[] GetSupportedViews()
{
return DisplayApi.GetSupportedViews(Handle);
}
/// <summary>
/// Overrides the refresh rate on this display.
/// The new refresh rate can be applied right away or deferred to be applied with the next OS
/// mode-set.
/// The override is good for only one mode-set (regardless whether it's deferred or immediate).
/// </summary>
/// <param name="refreshRate">The refresh rate to be applied.</param>
/// <param name="isDeferred">
/// A boolean value indicating if the refresh rate override should be deferred to the next OS
/// mode-set.
/// </param>
public void OverrideRefreshRate(float refreshRate, bool isDeferred = false)
{
DisplayApi.SetRefreshRateOverride(Handle, refreshRate, isDeferred);
}
}
}

View File

@@ -1,893 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NvAPIWrapper.GPU;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.Display;
using NvAPIWrapper.Native.Display.Structures;
using NvAPIWrapper.Native.Exceptions;
using NvAPIWrapper.Native.General;
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
using NvAPIWrapper.Native.Interfaces.Display;
using NvAPIWrapper.Native.Interfaces.GPU;
namespace NvAPIWrapper.Display
{
/// <summary>
/// Represents an NVIDIA display device
/// </summary>
public class DisplayDevice : IEquatable<DisplayDevice>
{
/// <summary>
/// Creates a new DisplayDevice
/// </summary>
/// <param name="displayId">Display identification of the device</param>
public DisplayDevice(uint displayId)
{
DisplayId = displayId;
var extraInformation = PhysicalGPU.GetDisplayDevices().FirstOrDefault(ids => ids.DisplayId == DisplayId);
if (extraInformation != null)
{
IsAvailable = true;
ScanOutInformation = new ScanOutInformation(this);
ConnectionType = extraInformation.ConnectionType;
IsDynamic = extraInformation.IsDynamic;
IsMultiStreamRootNode = extraInformation.IsMultiStreamRootNode;
IsActive = extraInformation.IsActive;
IsCluster = extraInformation.IsCluster;
IsOSVisible = extraInformation.IsOSVisible;
IsWFD = extraInformation.IsWFD;
IsConnected = extraInformation.IsConnected;
IsPhysicallyConnected = extraInformation.IsPhysicallyConnected;
}
}
/// <summary>
/// Creates a new DisplayDevice
/// </summary>
/// <param name="displayIds">Display identification and attributes of the display device</param>
public DisplayDevice(IDisplayIds displayIds)
{
IsAvailable = true;
DisplayId = displayIds.DisplayId;
ScanOutInformation = new ScanOutInformation(this);
ConnectionType = displayIds.ConnectionType;
IsDynamic = displayIds.IsDynamic;
IsMultiStreamRootNode = displayIds.IsMultiStreamRootNode;
IsActive = displayIds.IsActive;
IsCluster = displayIds.IsCluster;
IsOSVisible = displayIds.IsOSVisible;
IsWFD = displayIds.IsWFD;
IsConnected = displayIds.IsConnected;
IsPhysicallyConnected = displayIds.IsPhysicallyConnected;
}
/// <summary>
/// Creates a new DisplayDevice
/// </summary>
/// <param name="displayName">Display name of the display device</param>
public DisplayDevice(string displayName) : this(DisplayApi.GetDisplayIdByDisplayName(displayName))
{
}
/// <summary>
/// Gets the display device connection type
/// </summary>
public MonitorConnectionType ConnectionType { get; }
/// <summary>
/// Gets the current display color data
/// </summary>
public ColorData CurrentColorData
{
get
{
var instances = new IColorData[]
{
new ColorDataV5(ColorDataCommand.Get),
new ColorDataV4(ColorDataCommand.Get),
new ColorDataV3(ColorDataCommand.Get),
new ColorDataV2(ColorDataCommand.Get),
new ColorDataV1(ColorDataCommand.Get)
};
var instance = DisplayApi.ColorControl(DisplayId, instances);
return new ColorData(instance);
}
}
/// <summary>
/// Gets the current display device timing
/// </summary>
public Timing CurrentTiming
{
get => DisplayApi.GetTiming(DisplayId, new TimingInput(TimingOverride.Current));
}
/// <summary>
/// Gets the default display color data
/// </summary>
public ColorData DefaultColorData
{
get
{
var instances = new IColorData[]
{
new ColorDataV5(ColorDataCommand.GetDefault),
new ColorDataV4(ColorDataCommand.GetDefault),
new ColorDataV3(ColorDataCommand.GetDefault),
new ColorDataV2(ColorDataCommand.GetDefault),
new ColorDataV1(ColorDataCommand.GetDefault)
};
var instance = DisplayApi.ColorControl(DisplayId, instances);
return new ColorData(instance);
}
}
/// <summary>
/// Gets the NVIDIA display identification
/// </summary>
public uint DisplayId { get; }
/// <summary>
/// Gets the monitor Display port capabilities
/// </summary>
public MonitorColorData[] DisplayPortColorCapabilities
{
get
{
if (ConnectionType != MonitorConnectionType.DisplayPort)
{
return null;
}
return DisplayApi.GetMonitorColorCapabilities(DisplayId);
}
}
/// <summary>
/// Gets the display driver EDID specified HDR capabilities
/// </summary>
public HDRCapabilitiesV1 DriverHDRCapabilities
{
get => DisplayApi.GetHDRCapabilities(DisplayId, true);
}
/// <summary>
/// Gets the display currently effective HDR capabilities
/// </summary>
public HDRCapabilitiesV1 EffectiveHDRCapabilities
{
get => DisplayApi.GetHDRCapabilities(DisplayId, false);
}
/// <summary>
/// Gets the HDMI audio info-frame current information
/// </summary>
public InfoFrameAudio? HDMIAudioFrameCurrentInformation
{
get
{
try
{
var infoFrame = new InfoFrameData(InfoFrameCommand.Get, InfoFrameDataType.AudioInformation);
DisplayApi.InfoFrameControl(DisplayId, ref infoFrame);
return infoFrame.AudioInformation;
}
catch (NVIDIAApiException e)
{
if (e.Status == Status.NotSupported)
{
return null;
}
throw;
}
}
}
/// <summary>
/// Gets the HDMI audio info-frame default information
/// </summary>
public InfoFrameAudio? HDMIAudioFrameDefaultInformation
{
get
{
try
{
var infoFrame = new InfoFrameData(InfoFrameCommand.GetDefault, InfoFrameDataType.AudioInformation);
DisplayApi.InfoFrameControl(DisplayId, ref infoFrame);
return infoFrame.AudioInformation;
}
catch (NVIDIAApiException e)
{
if (e.Status == Status.NotSupported)
{
return null;
}
throw;
}
}
}
/// <summary>
/// Gets the HDMI audio info-frame override information
/// </summary>
public InfoFrameAudio? HDMIAudioFrameOverrideInformation
{
get
{
try
{
var infoFrame = new InfoFrameData(InfoFrameCommand.GetOverride, InfoFrameDataType.AudioInformation);
DisplayApi.InfoFrameControl(DisplayId, ref infoFrame);
return infoFrame.AudioInformation;
}
catch (NVIDIAApiException e)
{
if (e.Status == Status.NotSupported)
{
return null;
}
throw;
}
}
}
/// <summary>
/// Gets the HDMI audio info-frame property information
/// </summary>
public InfoFrameProperty? HDMIAudioFramePropertyInformation
{
get
{
try
{
var infoFrame = new InfoFrameData(InfoFrameCommand.GetProperty, InfoFrameDataType.AudioInformation);
DisplayApi.InfoFrameControl(DisplayId, ref infoFrame);
return infoFrame.PropertyInformation;
}
catch (NVIDIAApiException e)
{
if (e.Status == Status.NotSupported)
{
return null;
}
throw;
}
}
}
/// <summary>
/// Gets the device HDMI support information
/// </summary>
public IHDMISupportInfo HDMISupportInfo
{
get => DisplayApi.GetHDMISupportInfo(DisplayId);
}
/// <summary>
/// Gets the HDMI auxiliary video info-frame current information
/// </summary>
public InfoFrameVideo? HDMIVideoFrameCurrentInformation
{
get
{
try
{
var infoFrame =
new InfoFrameData(InfoFrameCommand.Get, InfoFrameDataType.AuxiliaryVideoInformation);
DisplayApi.InfoFrameControl(DisplayId, ref infoFrame);
return infoFrame.AuxiliaryVideoInformation;
}
catch (NVIDIAApiException e)
{
if (e.Status == Status.NotSupported)
{
return null;
}
throw;
}
}
}
/// <summary>
/// Gets the HDMI auxiliary video info-frame default information
/// </summary>
public InfoFrameVideo? HDMIVideoFrameDefaultInformation
{
get
{
try
{
var infoFrame = new InfoFrameData(InfoFrameCommand.GetDefault,
InfoFrameDataType.AuxiliaryVideoInformation);
DisplayApi.InfoFrameControl(DisplayId, ref infoFrame);
return infoFrame.AuxiliaryVideoInformation;
}
catch (NVIDIAApiException e)
{
if (e.Status == Status.NotSupported)
{
return null;
}
throw;
}
}
}
/// <summary>
/// Gets the HDMI auxiliary video info-frame override information
/// </summary>
public InfoFrameVideo? HDMIVideoFrameOverrideInformation
{
get
{
try
{
var infoFrame = new InfoFrameData(InfoFrameCommand.GetOverride,
InfoFrameDataType.AuxiliaryVideoInformation);
DisplayApi.InfoFrameControl(DisplayId, ref infoFrame);
return infoFrame.AuxiliaryVideoInformation;
}
catch (NVIDIAApiException e)
{
if (e.Status == Status.NotSupported)
{
return null;
}
throw;
}
}
}
/// <summary>
/// Gets the HDMI auxiliary video info-frame property information
/// </summary>
public InfoFrameProperty? HDMIVideoFramePropertyInformation
{
get
{
try
{
var infoFrame = new InfoFrameData(InfoFrameCommand.GetProperty,
InfoFrameDataType.AuxiliaryVideoInformation);
DisplayApi.InfoFrameControl(DisplayId, ref infoFrame);
return infoFrame.PropertyInformation;
}
catch (NVIDIAApiException e)
{
if (e.Status == Status.NotSupported)
{
return null;
}
throw;
}
}
}
/// <summary>
/// Gets the HDR color data, or null if the HDR is disabled or unavailable
/// </summary>
public HDRColorData HDRColorData
{
get
{
try
{
var instances = new IHDRColorData[]
{
new HDRColorDataV2(ColorDataHDRCommand.Get),
new HDRColorDataV1(ColorDataHDRCommand.Get)
};
var instance = DisplayApi.HDRColorControl(DisplayId, instances);
if (instance.HDRMode == ColorDataHDRMode.Off)
{
return null;
}
return new HDRColorData(instance);
}
catch (NVIDIAApiException e)
{
if (e.Status == Status.NotSupported)
{
return null;
}
throw;
}
}
}
/// <summary>
/// Indicates if the display is being actively driven
/// </summary>
public bool IsActive { get; }
/// <summary>
/// Indicates if the display device is currently available
/// </summary>
public bool IsAvailable { get; }
/// <summary>
/// Indicates if the display is the representative display
/// </summary>
public bool IsCluster { get; }
/// <summary>
/// Indicates if the display is connected
/// </summary>
public bool IsConnected { get; }
/// <summary>
/// Indicates if the display is part of MST topology and it's a dynamic
/// </summary>
public bool IsDynamic { get; }
/// <summary>
/// Indicates if the display identification belongs to a multi stream enabled connector (root node). Note that when
/// multi stream is enabled and a single multi stream capable monitor is connected to it, the monitor will share the
/// display id with the RootNode.
/// When there is more than one monitor connected in a multi stream topology, then the root node will have a separate
/// displayId.
/// </summary>
public bool IsMultiStreamRootNode { get; }
/// <summary>
/// Indicates if the display is reported to the OS
/// </summary>
public bool IsOSVisible { get; }
/// <summary>
/// Indicates if the display is a physically connected display; Valid only when IsConnected is true
/// </summary>
public bool IsPhysicallyConnected { get; }
/// <summary>
/// Indicates if the display is wireless
/// </summary>
public bool IsWFD { get; }
/// <summary>
/// Gets the connected GPU output
/// </summary>
public GPUOutput Output
{
get
{
PhysicalGPUHandle handle;
var outputId = GPUApi.GetGPUAndOutputIdFromDisplayId(DisplayId, out handle);
return new GPUOutput(outputId, new PhysicalGPU(handle));
}
}
/// <summary>
/// Gets the connected physical GPU
/// </summary>
public PhysicalGPU PhysicalGPU
{
get
{
try
{
var gpuHandle = GPUApi.GetPhysicalGPUFromDisplayId(DisplayId);
return new PhysicalGPU(gpuHandle);
}
catch
{
// ignored
}
return Output.PhysicalGPU;
}
}
/// <summary>
/// Gets information regarding the scan-out settings of this display device
/// </summary>
public ScanOutInformation ScanOutInformation { get; }
/// <summary>
/// Gets monitor capabilities from the Video Capability Data Block if available, otherwise null
/// </summary>
public MonitorVCDBCapabilities? VCDBMonitorCapabilities
{
get => DisplayApi.GetMonitorCapabilities(DisplayId, MonitorCapabilitiesType.VCDB)?.VCDBCapabilities;
}
/// <summary>
/// Gets monitor capabilities from the Vendor Specific Data Block if available, otherwise null
/// </summary>
public MonitorVSDBCapabilities? VSDBMonitorCapabilities
{
get => DisplayApi.GetMonitorCapabilities(DisplayId, MonitorCapabilitiesType.VSDB)?.VSDBCapabilities;
}
/// <inheritdoc />
public bool Equals(DisplayDevice other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return DisplayId == other.DisplayId;
}
/// <summary>
/// Deletes a custom resolution.
/// </summary>
/// <param name="customResolution">The custom resolution to delete.</param>
/// <param name="displayIds">A list of display ids to remove the custom resolution from.</param>
public static void DeleteCustomResolution(CustomResolution customResolution, uint[] displayIds)
{
var customDisplay = customResolution.AsCustomDisplay(false);
DisplayApi.DeleteCustomDisplay(displayIds, customDisplay);
}
/// <summary>
/// Returns an instance of <see cref="DisplayDevice" /> representing the primary GDI display device.
/// </summary>
/// <returns>An instance of <see cref="DisplayDevice" />.</returns>
public static DisplayDevice GetGDIPrimaryDisplayDevice()
{
var displayId = DisplayApi.GetGDIPrimaryDisplayId();
if (displayId == 0)
{
return null;
}
return new DisplayDevice(displayId);
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(DisplayDevice left, DisplayDevice right)
{
return right?.Equals(left) ?? ReferenceEquals(left, null);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(DisplayDevice left, DisplayDevice right)
{
return !(right == left);
}
/// <summary>
/// Reverts the custom resolution currently on trial.
/// </summary>
/// <param name="displayIds">A list of display ids to revert the custom resolution from.</param>
public static void RevertCustomResolution(uint[] displayIds)
{
DisplayApi.RevertCustomDisplayTrial(displayIds);
}
/// <summary>
/// Saves the custom resolution currently on trial.
/// </summary>
/// <param name="displayIds">A list of display ids to save the custom resolution for.</param>
/// <param name="isThisOutputIdOnly">
/// If set, the saved custom display will only be applied on the monitor with the same
/// outputId.
/// </param>
/// <param name="isThisMonitorOnly">
/// If set, the saved custom display will only be applied on the monitor with the same EDID
/// ID or the same TV connector in case of analog TV.
/// </param>
public static void SaveCustomResolution(uint[] displayIds, bool isThisOutputIdOnly, bool isThisMonitorOnly)
{
DisplayApi.SaveCustomDisplay(displayIds, isThisOutputIdOnly, isThisMonitorOnly);
}
/// <summary>
/// Applies a custom resolution into trial
/// </summary>
/// <param name="customResolution">The custom resolution to apply.</param>
/// <param name="displayIds">A list of display ids to apply the custom resolution on.</param>
/// <param name="hardwareModeSetOnly">
/// A boolean value indicating that a hardware mode-set without OS update should be
/// performed.
/// </param>
public static void TrialCustomResolution(
CustomResolution customResolution,
uint[] displayIds,
bool hardwareModeSetOnly = true)
{
var customDisplay = customResolution.AsCustomDisplay(hardwareModeSetOnly);
DisplayApi.TryCustomDisplay(displayIds.ToDictionary(u => u, u => customDisplay));
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((DisplayDevice) obj);
}
/// <inheritdoc />
public override int GetHashCode()
{
return (int) DisplayId;
}
/// <inheritdoc />
public override string ToString()
{
return $"Display #{DisplayId}";
}
/// <summary>
/// Calculates a valid timing based on the argument passed
/// </summary>
/// <param name="width">The preferred width.</param>
/// <param name="height">The preferred height.</param>
/// <param name="refreshRate">The preferred refresh rate.</param>
/// <param name="isInterlaced">The boolean value indicating if the preferred resolution is an interlaced resolution.</param>
/// <returns>Returns a valid instance of <see cref="Timing" />.</returns>
public Timing CalculateTiming(uint width, uint height, float refreshRate, bool isInterlaced)
{
return DisplayApi.GetTiming(
DisplayId,
new TimingInput(width, height, refreshRate, TimingOverride.Auto, isInterlaced)
);
}
/// <summary>
/// Deletes a custom resolution.
/// </summary>
/// <param name="customResolution">The custom resolution to delete.</param>
public void DeleteCustomResolution(CustomResolution customResolution)
{
DeleteCustomResolution(customResolution, new[] {DisplayId});
}
/// <summary>
/// Retrieves the list of custom resolutions saved for this display device
/// </summary>
/// <returns>A list of <see cref="CustomResolution" /> instances.</returns>
public IEnumerable<CustomResolution> GetCustomResolutions()
{
return DisplayApi.EnumCustomDisplays(DisplayId).Select(custom => new CustomResolution(custom));
}
/// <summary>
/// Checks if a color data is supported on this display
/// </summary>
/// <param name="colorData">The color data to be checked.</param>
/// <returns>true if the color data passed is supported; otherwise false</returns>
public bool IsColorDataSupported(ColorData colorData)
{
var instances = new IColorData[]
{
colorData.AsColorDataV5(ColorDataCommand.IsSupportedColor),
colorData.AsColorDataV4(ColorDataCommand.IsSupportedColor),
colorData.AsColorDataV3(ColorDataCommand.IsSupportedColor),
colorData.AsColorDataV2(ColorDataCommand.IsSupportedColor),
colorData.AsColorDataV1(ColorDataCommand.IsSupportedColor)
};
try
{
DisplayApi.ColorControl(DisplayId, instances);
return true;
}
catch (NVIDIAApiException e)
{
if (e.Status == Status.NotSupported)
{
return false;
}
throw;
}
}
/// <summary>
/// Resets the HDMI audio info-frame information to default
/// </summary>
public void ResetHDMIAudioFrameInformation()
{
var infoFrame = new InfoFrameData(
InfoFrameCommand.Reset,
InfoFrameDataType.AudioInformation
);
DisplayApi.InfoFrameControl(DisplayId, ref infoFrame);
}
/// <summary>
/// Resets the HDMI auxiliary video info-frame information to default
/// </summary>
public void ResetHDMIVideoFrameInformation()
{
var infoFrame = new InfoFrameData(
InfoFrameCommand.Reset,
InfoFrameDataType.AuxiliaryVideoInformation
);
DisplayApi.InfoFrameControl(DisplayId, ref infoFrame);
}
/// <summary>
/// Reverts the custom resolution currently on trial.
/// </summary>
public void RevertCustomResolution()
{
RevertCustomResolution(new[] {DisplayId});
}
/// <summary>
/// Saves the custom resolution currently on trial.
/// </summary>
/// <param name="isThisOutputIdOnly">
/// If set, the saved custom display will only be applied on the monitor with the same
/// outputId.
/// </param>
/// <param name="isThisMonitorOnly">
/// If set, the saved custom display will only be applied on the monitor with the same EDID
/// ID or the same TV connector in case of analog TV.
/// </param>
public void SaveCustomResolution(bool isThisOutputIdOnly = true, bool isThisMonitorOnly = true)
{
SaveCustomResolution(new[] {DisplayId}, isThisOutputIdOnly, isThisMonitorOnly);
}
/// <summary>
/// Changes the display current color data configuration
/// </summary>
/// <param name="colorData">The color data to be set.</param>
public void SetColorData(ColorData colorData)
{
var instances = new IColorData[]
{
colorData.AsColorDataV5(ColorDataCommand.Set),
colorData.AsColorDataV4(ColorDataCommand.Set),
colorData.AsColorDataV3(ColorDataCommand.Set),
colorData.AsColorDataV2(ColorDataCommand.Set),
colorData.AsColorDataV1(ColorDataCommand.Set)
};
DisplayApi.ColorControl(DisplayId, instances);
}
/// <summary>
/// Sets the HDMI video info-frame current or override information
/// </summary>
/// <param name="audio">The new information.</param>
/// <param name="isOverride">A boolean value indicating if the changes should persist mode-set and OS restart.</param>
public void SetHDMIAudioFrameInformation(InfoFrameAudio audio, bool isOverride = false)
{
var infoFrame = new InfoFrameData(
isOverride ? InfoFrameCommand.SetOverride : InfoFrameCommand.Set,
audio
);
DisplayApi.InfoFrameControl(DisplayId, ref infoFrame);
}
/// <summary>
/// Sets the HDMI audio info-frame property information
/// </summary>
/// <param name="property">The new property information.</param>
public void SetHDMIAudioFramePropertyInformation(InfoFrameProperty property)
{
var infoFrame = new InfoFrameData(
InfoFrameCommand.SetProperty,
InfoFrameDataType.AudioInformation,
property
);
DisplayApi.InfoFrameControl(DisplayId, ref infoFrame);
}
/// <summary>
/// Sets the HDMI auxiliary video info-frame current or override information
/// </summary>
/// <param name="video">The new information.</param>
/// <param name="isOverride">A boolean value indicating if the changes should persist mode-set and OS restart.</param>
public void SetHDMIVideoFrameInformation(InfoFrameVideo video, bool isOverride = false)
{
var infoFrame = new InfoFrameData(
isOverride ? InfoFrameCommand.SetOverride : InfoFrameCommand.Set,
video
);
DisplayApi.InfoFrameControl(DisplayId, ref infoFrame);
}
/// <summary>
/// Sets the HDMI auxiliary video info-frame property information
/// </summary>
/// <param name="property">The new property information.</param>
public void SetHDMIVideoFramePropertyInformation(InfoFrameProperty property)
{
var infoFrame = new InfoFrameData(
InfoFrameCommand.SetProperty,
InfoFrameDataType.AuxiliaryVideoInformation,
property
);
DisplayApi.InfoFrameControl(DisplayId, ref infoFrame);
}
/// <summary>
/// Changes the display HDR color data configuration
/// </summary>
/// <param name="colorData">The color data to be set.</param>
public void SetHDRColorData(HDRColorData colorData)
{
var instances = new IHDRColorData[]
{
colorData.AsHDRColorDataV2(ColorDataHDRCommand.Set),
colorData.AsHDRColorDataV1(ColorDataHDRCommand.Set)
};
DisplayApi.HDRColorControl(DisplayId, instances);
}
/// <summary>
/// Applies a custom resolution into trial.
/// </summary>
/// <param name="customResolution">The custom resolution to apply.</param>
/// <param name="hardwareModeSetOnly">
/// A boolean value indicating that a hardware mode-set without OS update should be
/// performed.
/// </param>
public void TrialCustomResolution(CustomResolution customResolution, bool hardwareModeSetOnly = true)
{
TrialCustomResolution(customResolution, new[] {DisplayId}, hardwareModeSetOnly);
}
}
}

View File

@@ -1,183 +0,0 @@
using System;
using System.Linq;
namespace NvAPIWrapper.Display
{
/// <summary>
/// Represents a texture of float values
/// </summary>
public class FloatTexture : IEquatable<FloatTexture>
{
/// <summary>
/// Underlying float array containing the values of all channels in all pixels
/// </summary>
protected readonly float[] UnderlyingArray;
/// <summary>
/// Creates a new instance of <see cref="FloatTexture" />.
/// </summary>
/// <param name="width">The texture width.</param>
/// <param name="height">The texture height.</param>
/// <param name="channels">The number of texture channels.</param>
public FloatTexture(int width, int height, int channels) : this(width, height, channels, null)
{
}
/// <summary>
/// Creates a new instance of <see cref="FloatTexture" />.
/// </summary>
/// <param name="width">The texture width.</param>
/// <param name="height">The texture height.</param>
/// <param name="channels">The number of texture channels.</param>
/// <param name="array">The underlying array containing all float values.</param>
// ReSharper disable once TooManyDependencies
protected FloatTexture(int width, int height, int channels, float[] array)
{
Width = width;
Height = height;
Channels = channels;
UnderlyingArray = array ?? new float[width * height * channels];
}
/// <summary>
/// Gets the number of texture channels
/// </summary>
public int Channels { get; }
/// <summary>
/// Gets the texture height in pixel
/// </summary>
public int Height { get; }
/// <summary>
/// Gets the texture width in pixels
/// </summary>
public int Width { get; }
/// <inheritdoc />
public bool Equals(FloatTexture other)
{
if (other == null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (other.UnderlyingArray.Length != UnderlyingArray.Length)
{
return false;
}
if (other.Width != Width || other.Height != Height || other.Channels != Channels)
{
return false;
}
return !UnderlyingArray.Where((t, i) => Math.Abs(other.UnderlyingArray[i] - t) > 0.0001).Any();
}
/// <summary>
/// Returns a new instance of FloatTexture from the passed array of float values.
/// </summary>
/// <param name="width">The texture width.</param>
/// <param name="height">The texture height.</param>
/// <param name="channels">The texture channels.</param>
/// <param name="floats">The array of float values.</param>
/// <returns>A new instance of <see cref="FloatTexture" />.</returns>
// ReSharper disable once TooManyArguments
public static FloatTexture FromFloatArray(int width, int height, int channels, float[] floats)
{
if (floats.Length != width * height * channels)
{
throw new ArgumentOutOfRangeException(nameof(floats));
}
return new FloatTexture(width, height, channels, floats.ToArray());
}
/// <summary>
/// Compares two instance of <see cref="FloatTexture" /> for equality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns><see langword="true" /> if both instances are equal, otherwise <see langword="false" /></returns>
public static bool operator ==(FloatTexture left, FloatTexture right)
{
return Equals(left, right) || left?.Equals(right) == true;
}
/// <summary>
/// Compares two instance of <see cref="FloatTexture" /> for in-equality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns><see langword="true" /> if both instances are not equal, otherwise <see langword="false" /></returns>
public static bool operator !=(FloatTexture left, FloatTexture right)
{
return !(left == right);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return Equals(obj as FloatTexture);
}
/// <inheritdoc />
public override int GetHashCode()
{
return UnderlyingArray.GetHashCode();
}
/// <summary>
/// Gets the values of each channel at a specific location
/// </summary>
/// <param name="x">The horizontal location.</param>
/// <param name="y">The vertical location.</param>
/// <returns>An array of float values each representing a channel value.</returns>
public float[] GetValues(int x, int y)
{
return UnderlyingArray.Skip(y * Width + x).Take(Channels).ToArray();
}
/// <summary>
/// Sets the value of each channel at a specific location
/// </summary>
/// <param name="x">The horizontal location.</param>
/// <param name="y">The vertical location.</param>
/// <param name="floats">An array of float values each representing a channel value.</param>
public void SetValues(int x, int y, params float[] floats)
{
var index = y * Width + x;
for (var i = 0; i < Math.Min(Channels, floats.Length); i++)
{
UnderlyingArray[index + i] = floats[i];
}
}
/// <summary>
/// Returns this instance of <see cref="FloatTexture" /> as an array of float values.
/// </summary>
/// <returns>An array of float values representing this instance of <see cref="FloatTexture" />.</returns>
public float[] ToFloatArray()
{
// Returns a copy of the underlying array
return UnderlyingArray.ToArray();
}
}
}

View File

@@ -1,157 +0,0 @@
using System;
using NvAPIWrapper.Native.Display;
using NvAPIWrapper.Native.Display.Structures;
using NvAPIWrapper.Native.Interfaces.Display;
namespace NvAPIWrapper.Display
{
/// <inheritdoc cref="IHDRColorData" />
public class HDRColorData : IHDRColorData, IEquatable<HDRColorData>
{
/// <summary>
/// Creates an instance of <see cref="HDRColorData" />.
/// </summary>
/// <param name="hdrMode">The hdr mode.</param>
/// <param name="masteringDisplayData">The display color space configurations.</param>
/// <param name="colorFormat">The color data color format.</param>
/// <param name="dynamicRange">The color data dynamic range.</param>
/// <param name="colorDepth">The color data color depth.</param>
public HDRColorData(
ColorDataHDRMode hdrMode,
MasteringDisplayColorData masteringDisplayData,
ColorDataFormat? colorFormat = null,
ColorDataDynamicRange? dynamicRange = null,
ColorDataDepth? colorDepth = null
)
{
HDRMode = hdrMode;
MasteringDisplayData = masteringDisplayData;
ColorFormat = colorFormat;
DynamicRange = dynamicRange;
ColorDepth = colorDepth;
}
internal HDRColorData(IHDRColorData colorData)
{
HDRMode = colorData.HDRMode;
MasteringDisplayData = colorData.MasteringDisplayData;
ColorDepth = colorData.ColorDepth;
ColorFormat = colorData.ColorFormat;
DynamicRange = colorData.DynamicRange;
}
/// <inheritdoc />
public bool Equals(HDRColorData other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return ColorDepth == other.ColorDepth &&
ColorFormat == other.ColorFormat &&
DynamicRange == other.DynamicRange &&
HDRMode == other.HDRMode &&
MasteringDisplayData.Equals(other.MasteringDisplayData);
}
/// <inheritdoc />
public ColorDataDepth? ColorDepth { get; }
/// <inheritdoc />
public ColorDataFormat? ColorFormat { get; }
/// <inheritdoc />
public ColorDataDynamicRange? DynamicRange { get; }
/// <inheritdoc />
public ColorDataHDRMode HDRMode { get; }
/// <inheritdoc />
public MasteringDisplayColorData MasteringDisplayData { get; }
/// <summary>
/// Compares two instances of <see cref="HDRColorData" /> for equality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>true if two instances are equal; otherwise false.</returns>
public static bool operator ==(HDRColorData left, HDRColorData right)
{
return left?.Equals(right) == true;
}
/// <summary>
/// Compares two instances of <see cref="HDRColorData" /> for inequality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns>true if two instances are not equal; otherwise false.</returns>
public static bool operator !=(HDRColorData left, HDRColorData right)
{
return !(left == right);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((HDRColorData) obj);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = ColorDepth.GetHashCode();
hashCode = (hashCode * 397) ^ ColorFormat.GetHashCode();
hashCode = (hashCode * 397) ^ DynamicRange.GetHashCode();
hashCode = (hashCode * 397) ^ (int) HDRMode;
hashCode = (hashCode * 397) ^ MasteringDisplayData.GetHashCode();
return hashCode;
}
}
internal HDRColorDataV1 AsHDRColorDataV1(ColorDataHDRCommand command)
{
return new HDRColorDataV1(
command,
HDRMode,
MasteringDisplayData
);
}
internal HDRColorDataV2 AsHDRColorDataV2(ColorDataHDRCommand command)
{
return new HDRColorDataV2(
command,
HDRMode,
MasteringDisplayData,
ColorFormat ?? ColorDataFormat.Auto,
DynamicRange ?? ColorDataDynamicRange.Auto,
ColorDepth ?? ColorDataDepth.Default
);
}
}
}

View File

@@ -1,97 +0,0 @@
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.Display.Structures;
using NvAPIWrapper.Native.GPU;
namespace NvAPIWrapper.Display
{
/// <summary>
/// This class contains and provides a way to modify the HUE angle
/// </summary>
public class HUEInformation
{
private readonly DisplayHandle _displayHandle = DisplayHandle.DefaultHandle;
private readonly OutputId _outputId = OutputId.Invalid;
/// <summary>
/// Creates a new instance of the class using a DisplayHandle
/// </summary>
/// <param name="displayHandle">The handle of the display.</param>
public HUEInformation(DisplayHandle displayHandle)
{
_displayHandle = displayHandle;
}
/// <summary>
/// Creates a new instance of this class using a OutputId
/// </summary>
/// <param name="outputId">The output identification of a display or an output</param>
public HUEInformation(OutputId outputId)
{
_outputId = outputId;
}
/// <summary>
/// Gets or sets the current HUE offset angle [0-359]
/// </summary>
public int CurrentAngle
{
get
{
PrivateDisplayHUEInfo? hueInfo = null;
if (_displayHandle != DisplayHandle.DefaultHandle)
{
hueInfo = DisplayApi.GetHUEInfo(_displayHandle);
}
else if (_outputId != OutputId.Invalid)
{
hueInfo = DisplayApi.GetHUEInfo(_outputId);
}
return hueInfo?.CurrentAngle ?? 0;
}
set
{
value %= 360;
if (_displayHandle != DisplayHandle.DefaultHandle)
{
DisplayApi.SetHUEAngle(_displayHandle, value);
}
else if (_outputId != OutputId.Invalid)
{
DisplayApi.SetHUEAngle(_outputId, value);
}
}
}
/// <summary>
/// Gets the default HUE offset angle [0-359]
/// </summary>
public int DefaultAngle
{
get
{
PrivateDisplayHUEInfo? hueInfo = null;
if (_displayHandle != DisplayHandle.DefaultHandle)
{
hueInfo = DisplayApi.GetHUEInfo(_displayHandle);
}
else if (_outputId != OutputId.Invalid)
{
hueInfo = DisplayApi.GetHUEInfo(_outputId);
}
return hueInfo?.DefaultAngle ?? 0;
}
}
/// <inheritdoc />
public override string ToString()
{
return $"{CurrentAngle:D}º [{DefaultAngle:D}º]";
}
}
}

View File

@@ -1,70 +0,0 @@
using System;
using System.Linq;
namespace NvAPIWrapper.Display
{
/// <summary>
/// Represents a texture of intensity values
/// </summary>
public class IntensityTexture : FloatTexture
{
/// <summary>
/// Creates a new instance of <see cref="IntensityTexture" />.
/// </summary>
/// <param name="width">The texture width.</param>
/// <param name="height">The texture height.</param>
public IntensityTexture(int width, int height) : base(width, height, 3)
{
}
private IntensityTexture(int width, int height, float[] floats) : base(width, height, 3, floats)
{
}
/// <summary>
/// Returns a new instance of FloatTexture from the passed array of float values.
/// </summary>
/// <param name="width">The texture width.</param>
/// <param name="height">The texture height.</param>
/// <param name="floats">The array of float values.</param>
/// <returns>A new instance of <see cref="FloatTexture" />.</returns>
// ReSharper disable once TooManyArguments
public static IntensityTexture FromFloatArray(int width, int height, float[] floats)
{
if (floats.Length != width * height * 3)
{
throw new ArgumentOutOfRangeException(nameof(floats));
}
return new IntensityTexture(width, height, floats.ToArray());
}
/// <summary>
/// Gets the value of intensity pixel at a specific location.
/// </summary>
/// <param name="x">The horizontal location.</param>
/// <param name="y">The vertical location.</param>
/// <returns>An instance of <see cref="IntensityTexturePixel" />.</returns>
public IntensityTexturePixel GetPixel(int x, int y)
{
return IntensityTexturePixel.FromFloatArray(UnderlyingArray, y * Width + x);
}
/// <summary>
/// Sets the value of intensity pixel at a specific location
/// </summary>
/// <param name="x">The horizontal location.</param>
/// <param name="y">The vertical location.</param>
/// <param name="pixel">An instance of <see cref="IntensityTexturePixel" />.</param>
public void SetPixel(int x, int y, IntensityTexturePixel pixel)
{
var index = y * Width + x;
var floats = pixel.ToFloatArray();
for (var i = 0; i < Math.Min(Channels, floats.Length); i++)
{
UnderlyingArray[index + i] = floats[i];
}
}
}
}

View File

@@ -1,117 +0,0 @@
using System;
namespace NvAPIWrapper.Display
{
/// <summary>
/// Represents a RGB intensity texture pixel
/// </summary>
public class IntensityTexturePixel : IEquatable<IntensityTexturePixel>
{
/// <summary>
/// Creates a new instance of <see cref="IntensityTexturePixel" />.
/// </summary>
/// <param name="redIntensity">The intensity of the red light (0-1)</param>
/// <param name="greenIntensity">The intensity of the green light (0-1)</param>
/// <param name="blueIntensity">The intensity of the blue light (0-1)</param>
public IntensityTexturePixel(float redIntensity, float greenIntensity, float blueIntensity)
{
RedIntensity = Math.Max(Math.Min(redIntensity, 1), 0);
GreenIntensity = Math.Max(Math.Min(greenIntensity, 1), 0);
BlueIntensity = Math.Max(Math.Min(blueIntensity, 1), 0);
}
/// <summary>
/// Gets the intensity of the blue light (0-1)
/// </summary>
public float BlueIntensity { get; }
/// <summary>
/// Gets the intensity of the green light (0-1)
/// </summary>
public float GreenIntensity { get; }
/// <summary>
/// Gets the intensity of the red light (0-1)
/// </summary>
public float RedIntensity { get; }
/// <inheritdoc />
public bool Equals(IntensityTexturePixel other)
{
if (other == null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Math.Abs(RedIntensity - other.RedIntensity) < 0.0001 &&
Math.Abs(GreenIntensity - other.GreenIntensity) < 0.0001 &&
Math.Abs(BlueIntensity - other.BlueIntensity) < 0.0001;
}
/// <summary>
/// Compares two instance of <see cref="IntensityTexturePixel" /> for equality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns><see langword="true" /> if both instances are equal, otherwise <see langword="false" /></returns>
public static bool operator ==(IntensityTexturePixel left, IntensityTexturePixel right)
{
return Equals(left, right) || left?.Equals(right) == true;
}
/// <summary>
/// Compares two instance of <see cref="IntensityTexturePixel" /> for in-equality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns><see langword="true" /> if both instances are not equal, otherwise <see langword="false" /></returns>
public static bool operator !=(IntensityTexturePixel left, IntensityTexturePixel right)
{
return !(left == right);
}
internal static IntensityTexturePixel FromFloatArray(float[] floats, int index)
{
return new IntensityTexturePixel(floats[index], floats[index + 1], floats[index + 2]);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return Equals(obj as IntensityTexturePixel);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = RedIntensity.GetHashCode();
hashCode = (hashCode * 397) ^ GreenIntensity.GetHashCode();
hashCode = (hashCode * 397) ^ BlueIntensity.GetHashCode();
return hashCode;
}
}
internal float[] ToFloatArray()
{
return new[] {RedIntensity, GreenIntensity, BlueIntensity};
}
}
}

View File

@@ -1,288 +0,0 @@
using System;
using System.Linq;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.Display;
using NvAPIWrapper.Native.Display.Structures;
using NvAPIWrapper.Native.Exceptions;
using NvAPIWrapper.Native.General;
using NvAPIWrapper.Native.Helpers;
using NvAPIWrapper.Native.Interfaces.Display;
namespace NvAPIWrapper.Display
{
/// <summary>
/// Represents a configuration path
/// </summary>
public class PathInfo : IEquatable<PathInfo>
{
/// <summary>
/// Creates a new PathInfo
/// </summary>
/// <param name="resolution">Display resolution</param>
/// <param name="colorFormat">Display color format</param>
/// <param name="targetInfos">Target configuration informations</param>
public PathInfo(Resolution resolution, ColorFormat colorFormat, PathTargetInfo[] targetInfos)
{
Resolution = resolution;
ColorFormat = colorFormat;
TargetsInfo = targetInfos;
}
/// <summary>
/// Creates a new PathInfo
/// </summary>
/// <param name="info">IPathInfo implamented object</param>
public PathInfo(IPathInfo info)
{
SourceId = info.SourceId;
Resolution = info.SourceModeInfo.Resolution;
ColorFormat = info.SourceModeInfo.ColorFormat;
Position = info.SourceModeInfo.Position;
SpanningOrientation = info.SourceModeInfo.SpanningOrientation;
IsGDIPrimary = info.SourceModeInfo.IsGDIPrimary;
IsSLIFocus = info.SourceModeInfo.IsSLIFocus;
TargetsInfo =
info.TargetsInfo.Select(targetInfo => new PathTargetInfo(targetInfo)).ToArray();
if (info is PathInfoV2)
{
OSAdapterLUID = ((PathInfoV2) info).OSAdapterLUID;
}
}
/// <summary>
/// Gets or sets the display color format
/// </summary>
public ColorFormat ColorFormat { get; set; }
/// <summary>
/// Gets or sets a boolean value indicating if the this is the primary GDI display
/// </summary>
public bool IsGDIPrimary { get; set; }
/// <summary>
/// Gets or sets a boolean value indicating if the this is the SLI focus display
/// </summary>
public bool IsSLIFocus { get; set; }
/// <summary>
/// Gets OS Adapter of LUID for Non-NVIDIA adapters
/// </summary>
public LUID? OSAdapterLUID { get; }
/// <summary>
/// Gets or sets the display position
/// </summary>
public Position Position { get; set; }
/// <summary>
/// Gets or sets the display resolution
/// </summary>
public Resolution Resolution { get; set; }
/// <summary>
/// Gets or sets the Windows CCD display source identification. This can be optionally set.
/// </summary>
public uint SourceId { get; set; }
/// <summary>
/// Gets or sets the display spanning orientation, valid for XP only
/// </summary>
public SpanningOrientation SpanningOrientation { get; set; }
/// <summary>
/// Gets information about path targets
/// </summary>
public PathTargetInfo[] TargetsInfo { get; }
/// <summary>
/// Checks for equality with a PathInfo instance
/// </summary>
/// <param name="other">The PathInfo object to check with</param>
/// <returns>true if both objects are equal, otherwise false</returns>
public bool Equals(PathInfo other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Resolution.Equals(other.Resolution) &&
ColorFormat == other.ColorFormat &&
Position.Equals(other.Position) &&
SpanningOrientation == other.SpanningOrientation &&
IsGDIPrimary == other.IsGDIPrimary &&
IsSLIFocus == other.IsSLIFocus &&
TargetsInfo.SequenceEqual(other.TargetsInfo);
}
/// <summary>
/// Creates and fills a PathInfo object
/// </summary>
/// <returns>The newly created PathInfo object</returns>
public static PathInfo[] GetDisplaysConfig()
{
var configs = DisplayApi.GetDisplayConfig();
var logicalDisplays = configs.Select(info => new PathInfo(info)).ToArray();
configs.DisposeAll();
return logicalDisplays;
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(PathInfo left, PathInfo right)
{
return right?.Equals(left) ?? ReferenceEquals(left, null);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(PathInfo left, PathInfo right)
{
return !(left == right);
}
/// <summary>
/// Applies one or more path information configurations
/// </summary>
/// <param name="pathInfos">An array of path information configuration</param>
/// <param name="flags">DisplayConfigFlags flags</param>
public static void SetDisplaysConfig(PathInfo[] pathInfos, DisplayConfigFlags flags)
{
try
{
var configsV2 = pathInfos.Select(config => config.GetPathInfoV2()).Cast<IPathInfo>().ToArray();
DisplayApi.SetDisplayConfig(configsV2, flags);
configsV2.DisposeAll();
}
catch (NVIDIAApiException ex)
{
if (ex.Status != Status.IncompatibleStructureVersion)
{
throw;
}
}
catch (NVIDIANotSupportedException)
{
// ignore
}
var configsV1 = pathInfos.Select(config => config.GetPathInfoV1()).Cast<IPathInfo>().ToArray();
DisplayApi.SetDisplayConfig(configsV1, flags);
configsV1.DisposeAll();
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((PathInfo) obj);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = Resolution.GetHashCode();
hashCode = (hashCode * 397) ^ (int) ColorFormat;
hashCode = (hashCode * 397) ^ Position.GetHashCode();
hashCode = (hashCode * 397) ^ (int) SpanningOrientation;
hashCode = (hashCode * 397) ^ IsGDIPrimary.GetHashCode();
hashCode = (hashCode * 397) ^ IsSLIFocus.GetHashCode();
hashCode = (hashCode * 397) ^ (TargetsInfo?.GetHashCode() ?? 0);
return hashCode;
}
}
/// <inheritdoc />
public override string ToString()
{
return $"{Resolution} @ {Position} [{TargetsInfo.Length}]";
}
/// <summary>
/// Creates and fills a GetPathInfoV1 object
/// </summary>
/// <returns>The newly created GetPathInfoV1 object</returns>
public PathInfoV1 GetPathInfoV1()
{
var sourceModeInfo = GetSourceModeInfo();
var pathTargetInfoV1 = GetPathTargetInfoV1Array();
return new PathInfoV1(pathTargetInfoV1, sourceModeInfo, SourceId);
}
/// <summary>
/// Creates and fills a GetPathInfoV2 object
/// </summary>
/// <returns>The newly created GetPathInfoV2 object</returns>
public PathInfoV2 GetPathInfoV2()
{
var sourceModeInfo = GetSourceModeInfo();
var pathTargetInfoV2 = GetPathTargetInfoV2Array();
return new PathInfoV2(pathTargetInfoV2, sourceModeInfo, SourceId);
}
/// <summary>
/// Creates and fills an array of GetPathTargetInfoV1 object
/// </summary>
/// <returns>The newly created array of GetPathTargetInfoV1 objects</returns>
public PathTargetInfoV1[] GetPathTargetInfoV1Array()
{
return TargetsInfo.Select(config => config.GetPathTargetInfoV1()).ToArray();
}
/// <summary>
/// Creates and fills an array of GetPathTargetInfoV2 object
/// </summary>
/// <returns>The newly created array of GetPathTargetInfoV2 objects</returns>
public PathTargetInfoV2[] GetPathTargetInfoV2Array()
{
return TargetsInfo.Select(config => config.GetPathTargetInfoV2()).ToArray();
}
/// <summary>
/// Creates and fills a SourceModeInfo object
/// </summary>
/// <returns>The newly created SourceModeInfo object</returns>
public SourceModeInfo GetSourceModeInfo()
{
return new SourceModeInfo(Resolution, ColorFormat, Position, SpanningOrientation, IsGDIPrimary, IsSLIFocus);
}
}
}

View File

@@ -1,304 +0,0 @@
using System;
using System.Collections.Generic;
using NvAPIWrapper.Native.Display;
using NvAPIWrapper.Native.Display.Structures;
using NvAPIWrapper.Native.Exceptions;
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.Interfaces.Display;
namespace NvAPIWrapper.Display
{
/// <summary>
/// Represents a display configuration on a path
/// </summary>
public class PathTargetInfo : IEquatable<PathTargetInfo>
{
private TimingOverride _timingOverride;
/// <summary>
/// Creates a new PathTargetInfo
/// </summary>
/// <param name="info">IPathTargetInfo implamented object</param>
public PathTargetInfo(IPathTargetInfo info)
{
DisplayDevice = new DisplayDevice(info.DisplayId);
if (info.Details.HasValue)
{
Rotation = info.Details.Value.Rotation;
Scaling = info.Details.Value.Scaling;
TVConnectorType = info.Details.Value.ConnectorType;
TVFormat = info.Details.Value.TVFormat;
RefreshRateInMillihertz = info.Details.Value.RefreshRateInMillihertz;
TimingOverride = info.Details.Value.TimingOverride;
IsInterlaced = info.Details.Value.IsInterlaced;
IsClonePrimary = info.Details.Value.IsClonePrimary;
IsClonePanAndScanTarget = info.Details.Value.IsClonePanAndScanTarget;
DisableVirtualModeSupport = info.Details.Value.DisableVirtualModeSupport;
IsPreferredUnscaledTarget = info.Details.Value.IsPreferredUnscaledTarget;
}
if (info is PathTargetInfoV2)
{
WindowsCCDTargetId = ((PathTargetInfoV2) info).WindowsCCDTargetId;
}
}
/// <summary>
/// Creates a new PathTargetInfo
/// </summary>
/// <param name="device">DisplayDevice object</param>
public PathTargetInfo(DisplayDevice device)
{
DisplayDevice = device;
}
/// <summary>
/// Gets or sets the virtual mode support
/// </summary>
public bool DisableVirtualModeSupport { get; set; }
/// <summary>
/// Gets corresponding DisplayDevice
/// </summary>
public DisplayDevice DisplayDevice { get; }
/// <summary>
/// Gets or sets the pan and scan is availability. Valid only when the target is part of clone
/// topology.
/// </summary>
public bool IsClonePanAndScanTarget { get; set; }
/// <summary>
/// Gets or sets the primary display in clone configuration. This is *NOT* GDI Primary.
/// Only one target can be primary per source. If no primary is specified, the first target will automatically be
/// primary.
/// </summary>
public bool IsClonePrimary { get; set; }
/// <summary>
/// Gets or sets the interlaced mode flag, ignored if refreshRate == 0
/// </summary>
public bool IsInterlaced { get; set; }
/// <summary>
/// Gets or sets the preferred unscaled mode of target
/// </summary>
public bool IsPreferredUnscaledTarget { get; set; }
/// <summary>
/// Gets and sets the non-interlaced Refresh Rate of the mode, multiplied by 1000, 0 = ignored
/// This is the value which driver reports to the OS.
/// </summary>
public uint RefreshRateInMillihertz { get; set; }
/// <summary>
/// Gets and sets the rotation setting
/// </summary>
public Rotate Rotation { get; set; }
/// <summary>
/// Gets and sets the scaling setting
/// </summary>
public Scaling Scaling { get; set; }
/// <summary>
/// Gets and sets the custom timing of display
/// Ignored if TimingOverride == TimingOverride.Current
/// </summary>
public TimingOverride TimingOverride
{
get => _timingOverride;
set
{
if (value == TimingOverride.Custom)
{
throw new NVIDIANotSupportedException("Custom timing is not supported yet.");
}
_timingOverride = value;
}
}
/// <summary>
/// Gets and sets the connector type. For TV only, ignored if TVFormat == TVFormat.None.
/// </summary>
public ConnectorType TVConnectorType { get; set; }
/// <summary>
/// Gets and sets the TV format. For TV only, otherwise set to TVFormat.None
/// </summary>
public TVFormat TVFormat { get; set; }
/// <summary>
/// Gets the Windows CCD target ID. Must be present only for non-NVIDIA adapter, for NVIDIA adapter this parameter is
/// ignored.
/// </summary>
public uint WindowsCCDTargetId { get; }
/// <summary>
/// Checks for equality with a PathTargetInfo instance
/// </summary>
/// <param name="other">The PathTargetInfo object to check with</param>
/// <returns>true if both objects are equal, otherwise false</returns>
public bool Equals(PathTargetInfo other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return _timingOverride == other._timingOverride &&
Rotation == other.Rotation &&
Scaling == other.Scaling &&
RefreshRateInMillihertz == other.RefreshRateInMillihertz &&
(TVFormat == TVFormat.None || TVConnectorType == other.TVConnectorType) &&
TVFormat == other.TVFormat &&
DisplayDevice.Equals(other.DisplayDevice) &&
IsInterlaced == other.IsInterlaced &&
IsClonePrimary == other.IsClonePrimary &&
IsClonePanAndScanTarget == other.IsClonePanAndScanTarget &&
DisableVirtualModeSupport == other.DisableVirtualModeSupport &&
IsPreferredUnscaledTarget == other.IsPreferredUnscaledTarget;
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(PathTargetInfo left, PathTargetInfo right)
{
return right?.Equals(left) ?? ReferenceEquals(left, null);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(PathTargetInfo left, PathTargetInfo right)
{
return !(left == right);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((PathTargetInfo) obj);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) _timingOverride;
hashCode = (hashCode * 397) ^ (int) Rotation;
hashCode = (hashCode * 397) ^ (int) Scaling;
hashCode = (hashCode * 397) ^ (int) RefreshRateInMillihertz;
hashCode = (hashCode * 397) ^ (int) TVFormat;
hashCode = (hashCode * 397) ^ (TVFormat != TVFormat.None ? (int) TVConnectorType : 0);
hashCode = (hashCode * 397) ^ (DisplayDevice?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ IsInterlaced.GetHashCode();
hashCode = (hashCode * 397) ^ IsClonePrimary.GetHashCode();
hashCode = (hashCode * 397) ^ IsClonePanAndScanTarget.GetHashCode();
hashCode = (hashCode * 397) ^ DisableVirtualModeSupport.GetHashCode();
hashCode = (hashCode * 397) ^ IsPreferredUnscaledTarget.GetHashCode();
return hashCode;
}
}
/// <inheritdoc />
public override string ToString()
{
var strs = new List<string>
{
DisplayDevice.ToString()
};
if (RefreshRateInMillihertz > 0)
{
strs.Add($"@ {RefreshRateInMillihertz / 1000}hz");
}
if (TVFormat != TVFormat.None)
{
strs.Add($"- TV {TVFormat}");
}
strs.Add(IsInterlaced ? "Interlaced" : "Progressive");
if (Rotation != Rotate.Degree0)
{
strs.Add($"- Rotation: {Rotation}");
}
return string.Join(" ", strs);
}
/// <summary>
/// Creates and fills a PathAdvancedTargetInfo object
/// </summary>
/// <returns>The newly created PathAdvancedTargetInfo object</returns>
public PathAdvancedTargetInfo GetPathAdvancedTargetInfo()
{
if (TVFormat == TVFormat.None)
{
return new PathAdvancedTargetInfo(Rotation, Scaling, RefreshRateInMillihertz, TimingOverride,
IsInterlaced, IsClonePrimary, IsClonePanAndScanTarget, DisableVirtualModeSupport,
IsPreferredUnscaledTarget);
}
return new PathAdvancedTargetInfo(Rotation, Scaling, TVFormat, TVConnectorType, RefreshRateInMillihertz,
TimingOverride, IsInterlaced, IsClonePrimary, IsClonePanAndScanTarget, DisableVirtualModeSupport,
IsPreferredUnscaledTarget);
}
/// <summary>
/// Creates and fills a PathTargetInfoV1 object
/// </summary>
/// <returns>The newly created PathTargetInfoV1 object</returns>
public PathTargetInfoV1 GetPathTargetInfoV1()
{
var pathAdvancedTargetInfo = GetPathAdvancedTargetInfo();
return new PathTargetInfoV1(DisplayDevice.DisplayId, pathAdvancedTargetInfo);
}
/// <summary>
/// Creates and fills a PathTargetInfoV2 object
/// </summary>
/// <returns>The newly created PathTargetInfoV2 object</returns>
public PathTargetInfoV2 GetPathTargetInfoV2()
{
var pathAdvancedTargetInfo = GetPathAdvancedTargetInfo();
return new PathTargetInfoV2(DisplayDevice.DisplayId, WindowsCCDTargetId, pathAdvancedTargetInfo);
}
}
}

View File

@@ -1,218 +0,0 @@
using System.Linq;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.Display;
using NvAPIWrapper.Native.Display.Structures;
using NvAPIWrapper.Native.General.Structures;
using Rectangle = NvAPIWrapper.Native.General.Structures.Rectangle;
namespace NvAPIWrapper.Display
{
/// <summary>
/// Contains information regarding the scan-out buffer settings of a display device
/// </summary>
public class ScanOutInformation
{
internal ScanOutInformation(DisplayDevice displayDevice)
{
DisplayDevice = displayDevice;
}
/// <summary>
/// Gets the clone importance assigned to the target if the target is a cloned view of the SourceDesktopRectangle
/// (0:primary,1 secondary,...).
/// </summary>
public uint CloneImportance
{
get => DisplayApi.GetScanOutConfiguration(DisplayDevice.DisplayId).CloneImportance;
}
/// <summary>
/// Gets the display device that this instance describes
/// </summary>
public DisplayDevice DisplayDevice { get; }
/// <summary>
/// Gets a boolean value indicating if the display device scan out output is warped
/// </summary>
public bool IsDisplayWarped
{
get => DisplayApi.GetScanOutWarpingState(DisplayDevice.DisplayId).IsEnabled;
}
/// <summary>
/// Gets a boolean value indicating if the display device intensity is modified
/// </summary>
public bool IsIntensityModified
{
get => DisplayApi.GetScanOutIntensityState(DisplayDevice.DisplayId).IsEnabled;
}
/// <summary>
/// Gets the operating system display device rectangle in desktop coordinates displayId is scanning out from.
/// </summary>
public Rectangle SourceDesktopRectangle
{
get => DisplayApi.GetScanOutConfiguration(DisplayDevice.DisplayId).SourceDesktopRectangle;
}
/// <summary>
/// Gets the rotation performed between the SourceViewPortRectangle and the TargetViewPortRectangle.
/// </summary>
public Rotate SourceToTargetRotation
{
get => DisplayApi.GetScanOutConfiguration(DisplayDevice.DisplayId).SourceToTargetRotation;
}
/// <summary>
/// Gets the area inside the SourceDesktopRectangle which is scanned out to the display.
/// </summary>
public Rectangle SourceViewPortRectangle
{
get => DisplayApi.GetScanOutConfiguration(DisplayDevice.DisplayId).SourceViewPortRectangle;
}
/// <summary>
/// Gets the vertical size of the active resolution scanned out to the display.
/// </summary>
public uint TargetDisplayHeight
{
get => DisplayApi.GetScanOutConfiguration(DisplayDevice.DisplayId).TargetDisplayHeight;
}
/// <summary>
/// Gets the horizontal size of the active resolution scanned out to the display.
/// </summary>
public uint TargetDisplayWidth
{
get => DisplayApi.GetScanOutConfiguration(DisplayDevice.DisplayId).TargetDisplayWidth;
}
/// <summary>
/// Gets the area inside the rectangle described by targetDisplayWidth/Height SourceViewPortRectangle is scanned out
/// to.
/// </summary>
public Rectangle TargetViewPortRectangle
{
get => DisplayApi.GetScanOutConfiguration(DisplayDevice.DisplayId).TargetViewPortRectangle;
}
/// <summary>
/// Disables the intensity modification on the display device scan-out buffer.
/// </summary>
/// <param name="isSticky">A boolean value that indicates whether the settings will be kept over a reboot.</param>
public void DisableIntensityModifications(out bool isSticky)
{
DisplayApi.SetScanOutIntensity(DisplayDevice.DisplayId, null, out isSticky);
}
/// <summary>
/// Disables the warping of display device scan-out buffer.
/// </summary>
/// <param name="isSticky">A boolean value that indicates whether the settings will be kept over a reboot.</param>
public void DisableWarping(out bool isSticky)
{
var vorticesCount = 0;
DisplayApi.SetScanOutWarping(DisplayDevice.DisplayId, null, ref vorticesCount, out isSticky);
}
/// <summary>
/// Enables the intensity modification on the display device scan-out buffer.
/// </summary>
/// <param name="intensityTexture">The intensity texture to apply to the scan-out buffer.</param>
/// <param name="isSticky">A boolean value that indicates whether the settings will be kept over a reboot.</param>
public void EnableIntensityModifications(IntensityTexture intensityTexture, out bool isSticky)
{
using (
var intensity = new ScanOutIntensityV1(
(uint) intensityTexture.Width,
(uint) intensityTexture.Height,
intensityTexture.ToFloatArray()
)
)
{
DisplayApi.SetScanOutIntensity(DisplayDevice.DisplayId, intensity, out isSticky);
}
}
/// <summary>
/// Enables the intensity modification on the display device scan-out buffer.
/// </summary>
/// <param name="intensityTexture">The intensity texture to apply to the scan-out buffer.</param>
/// <param name="offsetTexture">The offset texture to apply to the scan-out buffer.</param>
/// <param name="isSticky">A boolean value that indicates whether the settings will be kept over a reboot.</param>
public void EnableIntensityModifications(
IntensityTexture intensityTexture,
FloatTexture offsetTexture,
out bool isSticky)
{
using (
var intensity = new ScanOutIntensityV2(
(uint) intensityTexture.Width,
(uint) intensityTexture.Height,
intensityTexture.ToFloatArray(),
(uint) offsetTexture.Channels,
offsetTexture.ToFloatArray()
)
)
{
DisplayApi.SetScanOutIntensity(DisplayDevice.DisplayId, intensity, out isSticky);
}
}
/// <summary>
/// Enables the warping of display device scan-out buffer
/// </summary>
/// <param name="warpingVerticeFormat">The type of warping vortexes.</param>
/// <param name="vortices">An array of warping vortexes.</param>
/// <param name="textureRectangle">The rectangle in desktop coordinates describing the source area for the warping.</param>
/// <param name="isSticky">A boolean value that indicates whether the settings will be kept over a reboot.</param>
// ReSharper disable once TooManyArguments
public void EnableWarping(
WarpingVerticeFormat warpingVerticeFormat,
XYUVRQVortex[] vortices,
Rectangle textureRectangle,
out bool isSticky)
{
using (
var warping = new ScanOutWarpingV1(
warpingVerticeFormat,
vortices.SelectMany(vortex => vortex.AsFloatArray()).ToArray(),
textureRectangle
)
)
{
var vorticesCount = vortices.Length;
DisplayApi.SetScanOutWarping(DisplayDevice.DisplayId, warping, ref vorticesCount, out isSticky);
}
}
/// <summary>
/// Queries the current state of one of the various scan-out composition parameters.
/// </summary>
/// <param name="parameter">The scan-out composition parameter.</param>
/// <param name="additionalValue">The additional value included with the parameter value.</param>
/// <returns>The scan-out composition parameter value.</returns>
public ScanOutCompositionParameterValue GetCompositionParameterValue(
ScanOutCompositionParameter parameter,
out float additionalValue)
{
return DisplayApi.GetScanOutCompositionParameter(DisplayDevice.DisplayId, parameter, out additionalValue);
}
/// <summary>
/// Sets the current state of one of the various scan-out composition parameters.
/// </summary>
/// <param name="parameter">The scan-out composition parameter.</param>
/// <param name="parameterValue">The scan-out composition parameter value.</param>
/// <param name="additionalValue">The additional value included with the parameter value.</param>
public void SetCompositionParameterValue(
ScanOutCompositionParameter parameter,
ScanOutCompositionParameterValue parameterValue,
float additionalValue)
{
DisplayApi.SetScanOutCompositionParameter(DisplayDevice.DisplayId, parameter, parameterValue,
ref additionalValue);
}
}
}

View File

@@ -1,150 +0,0 @@
using System;
using System.Linq;
using NvAPIWrapper.GPU;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.Display.Structures;
namespace NvAPIWrapper.Display
{
/// <summary>
/// Represents an unattached display
/// </summary>
public class UnAttachedDisplay : IEquatable<UnAttachedDisplay>
{
/// <summary>
/// Creates a new UnAttachedDisplay
/// </summary>
/// <param name="handle">Handle of the unattached display device</param>
public UnAttachedDisplay(UnAttachedDisplayHandle handle)
{
Handle = handle;
}
/// <summary>
/// Creates a new UnAttachedDisplay
/// </summary>
/// <param name="displayName">Name of the unattached display device</param>
public UnAttachedDisplay(string displayName)
{
Handle = DisplayApi.GetAssociatedUnAttachedNvidiaDisplayHandle(displayName);
}
/// <summary>
/// Gets display handle
/// </summary>
public UnAttachedDisplayHandle Handle { get; }
/// <summary>
/// Gets display name
/// </summary>
public string Name
{
get => DisplayApi.GetUnAttachedAssociatedDisplayName(Handle);
}
/// <summary>
/// Gets corresponding physical GPU
/// </summary>
public PhysicalGPU PhysicalGPU
{
get => new PhysicalGPU(GPUApi.GetPhysicalGPUFromUnAttachedDisplay(Handle));
}
/// <summary>
/// Checks for equality with a UnAttachedDisplay instance
/// </summary>
/// <param name="other">The Display object to check with</param>
/// <returns>true if both objects are equal, otherwise false</returns>
public bool Equals(UnAttachedDisplay other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Handle.Equals(other.Handle);
}
/// <summary>
/// This function returns all unattached NVIDIA displays
/// Note: Display handles can get invalidated on a modeset.
/// </summary>
/// <returns>An array of Display objects</returns>
public static UnAttachedDisplay[] GetUnAttachedDisplays()
{
return
DisplayApi.EnumNvidiaUnAttachedDisplayHandle().Select(handle => new UnAttachedDisplay(handle))
.ToArray();
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(UnAttachedDisplay left, UnAttachedDisplay right)
{
return right?.Equals(left) ?? ReferenceEquals(left, null);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(UnAttachedDisplay left, UnAttachedDisplay right)
{
return !(left == right);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((UnAttachedDisplay) obj);
}
/// <inheritdoc />
public override int GetHashCode()
{
return Handle.GetHashCode();
}
/// <inheritdoc />
public override string ToString()
{
return Name;
}
/// <summary>
/// Creates a new active attached display from this unattached display
/// At least one GPU must be present in the system and running an NVIDIA display driver.
/// </summary>
/// <returns>An active attached display</returns>
public Display CreateDisplay()
{
return new Display(DisplayApi.CreateDisplayFromUnAttachedDisplay(Handle));
}
}
}

View File

@@ -1,165 +0,0 @@
using System;
using System.Collections.Generic;
namespace NvAPIWrapper.Display
{
/// <summary>
/// Represents a XYUVRQ scan-out warping vortex
/// </summary>
public class XYUVRQVortex : IEquatable<XYUVRQVortex>
{
/// <summary>
/// Creates a new instance of <see cref="XYUVRQVortex" />.
/// </summary>
/// <param name="x">The target view port mesh horizontal coordinate</param>
/// <param name="y">The target view port mesh vertical coordinate</param>
/// <param name="u">The desktop view port texture horizontal coordinate</param>
/// <param name="v">The desktop view port texture vertical coordinate</param>
/// <param name="r">The 3D warp perspective R factor</param>
/// <param name="q">The 3D warp perspective Q factor</param>
// ReSharper disable once TooManyDependencies
public XYUVRQVortex(int x, int y, int u, int v, float r, float q)
{
X = x;
Y = y;
U = u;
V = v;
R = r;
Q = q;
}
/// <summary>
/// 3D warp perspective Q factor
/// </summary>
public float Q { get; }
/// <summary>
/// 3D warp perspective R factor
/// </summary>
public float R { get; }
/// <summary>
/// Desktop view port texture horizontal coordinate
/// </summary>
public int U { get; }
/// <summary>
/// Desktop view port texture vertical coordinate
/// </summary>
public int V { get; }
/// <summary>
/// Target view port mesh horizontal coordinate
/// </summary>
public int X { get; }
/// <summary>
/// Target view port mesh vertical coordinate
/// </summary>
public int Y { get; }
/// <inheritdoc />
public bool Equals(XYUVRQVortex other)
{
if (other == null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Math.Abs(Q - other.Q) < 0.0001 &&
Math.Abs(R - other.R) < 0.0001 &&
U == other.U &&
V == other.V &&
X == other.X &&
Y == other.Y;
}
/// <summary>
/// Parses an array of floats and returns the corresponding <see cref="XYUVRQVortex" />s.
/// </summary>
/// <param name="floats">The array of float representing one or more <see cref="XYUVRQVortex" />s.</param>
/// <returns>Instances of <see cref="XYUVRQVortex" />.</returns>
public static IEnumerable<XYUVRQVortex> FromFloatArray(float[] floats)
{
for (var i = 0; i + 6 <= floats.Length; i += 6)
{
yield return new XYUVRQVortex(
(int) floats[i],
(int) floats[i + 1],
(int) floats[i + 2],
(int) floats[i + 3],
floats[i + 4],
floats[i + 5]
);
}
}
/// <summary>
/// Compares two instance of <see cref="XYUVRQVortex" /> for equality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns><see langword="true" /> if both instances are equal, otherwise <see langword="false" /></returns>
public static bool operator ==(XYUVRQVortex left, XYUVRQVortex right)
{
return Equals(left, right) || left?.Equals(right) == true;
}
/// <summary>
/// Compares two instance of <see cref="XYUVRQVortex" /> for in-equality.
/// </summary>
/// <param name="left">The first instance.</param>
/// <param name="right">The second instance.</param>
/// <returns><see langword="true" /> if both instances are not equal, otherwise <see langword="false" /></returns>
public static bool operator !=(XYUVRQVortex left, XYUVRQVortex right)
{
return !(left == right);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return Equals(obj as XYUVRQVortex);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = Q.GetHashCode();
hashCode = (hashCode * 397) ^ R.GetHashCode();
hashCode = (hashCode * 397) ^ U;
hashCode = (hashCode * 397) ^ V;
hashCode = (hashCode * 397) ^ X;
hashCode = (hashCode * 397) ^ Y;
return hashCode;
}
}
/// <summary>
/// Returns this instance of <see cref="XYUVRQVortex"/> as a float array.
/// </summary>
/// <returns>An array of float values representing this instance of <see cref="XYUVRQVortex"/>.</returns>
public float[] AsFloatArray()
{
return new[] {X, Y, U, V, R, Q};
}
}
}

View File

@@ -1,30 +0,0 @@
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Contains information about the accelerated graphics connection
/// </summary>
public class AGPInformation
{
internal AGPInformation(int aperture, int currentRate)
{
ApertureInMB = aperture;
CurrentRate = currentRate;
}
/// <summary>
/// Gets AGP aperture in megabytes
/// </summary>
public int ApertureInMB { get; }
/// <summary>
/// Gets current AGP Rate (0 = AGP not present, 1 = 1x, 2 = 2x, etc.)
/// </summary>
public int CurrentRate { get; }
/// <inheritdoc />
public override string ToString()
{
return $"AGP Aperture: {ApertureInMB}MB, Current Rate: {CurrentRate}x";
}
}
}

View File

@@ -1,201 +0,0 @@
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.GPU;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Contains information about the ECC memory
/// </summary>
public class ECCMemoryInformation
{
internal ECCMemoryInformation(PhysicalGPU physicalGPU)
{
PhysicalGPU = physicalGPU;
}
/// <summary>
/// Gets the number of aggregated ECC memory double bit errors
/// </summary>
public ulong AggregatedDoubleBitErrors
{
get
{
if (!IsSupported || !IsEnabled)
{
return 0;
}
return GPUApi.GetECCErrorInfo(PhysicalGPU.Handle).AggregatedErrors.DoubleBitErrors;
}
}
/// <summary>
/// Gets the number of aggregated ECC memory single bit errors
/// </summary>
public ulong AggregatedSingleBitErrors
{
get
{
if (!IsSupported || !IsEnabled)
{
return 0;
}
return GPUApi.GetECCErrorInfo(PhysicalGPU.Handle).AggregatedErrors.SingleBitErrors;
}
}
/// <summary>
/// Gets the ECC memory configuration in regard to how changes are applied
/// </summary>
public ECCConfiguration Configuration
{
get
{
try
{
return GPUApi.GetECCStatusInfo(PhysicalGPU.Handle).ConfigurationOptions;
}
catch
{
return ECCConfiguration.NotSupported;
}
}
}
/// <summary>
/// Gets the number of current ECC memory double bit errors
/// </summary>
public ulong CurrentDoubleBitErrors
{
get
{
if (!IsSupported || !IsEnabled)
{
return 0;
}
return GPUApi.GetECCErrorInfo(PhysicalGPU.Handle).CurrentErrors.DoubleBitErrors;
}
}
/// <summary>
/// Gets the number of current ECC memory single bit errors
/// </summary>
public ulong CurrentSingleBitErrors
{
get
{
if (!IsSupported || !IsEnabled)
{
return 0;
}
return GPUApi.GetECCErrorInfo(PhysicalGPU.Handle).CurrentErrors.SingleBitErrors;
}
}
/// <summary>
/// Gets a boolean value indicating if ECC memory error correction is enabled
/// </summary>
public bool IsEnabled
{
get => IsSupported &&
GPUApi.GetECCStatusInfo(PhysicalGPU.Handle).IsEnabled &&
GPUApi.GetECCConfigurationInfo(PhysicalGPU.Handle).IsEnabled;
}
/// <summary>
/// Gets a boolean value indicating if ECC memory is enabled by default
/// </summary>
public bool IsEnabledByDefault
{
get => IsSupported &&
GPUApi.GetECCConfigurationInfo(PhysicalGPU.Handle).IsEnabledByDefault;
}
/// <summary>
/// Gets a boolean value indicating if ECC memory is supported and available
/// </summary>
public bool IsSupported
{
get
{
try
{
return GPUApi.GetECCStatusInfo(PhysicalGPU.Handle).IsSupported;
}
catch
{
return false;
}
}
}
/// <summary>
/// Gets the physical GPU that this instance describes
/// </summary>
public PhysicalGPU PhysicalGPU { get; }
/// <inheritdoc />
public override string ToString()
{
if (!IsSupported)
{
return "[Not Supported]";
}
if (!IsEnabled)
{
return "[Disabled]";
}
return
$"{CurrentSingleBitErrors}, {CurrentDoubleBitErrors} ({AggregatedSingleBitErrors}, {AggregatedDoubleBitErrors})";
}
/// <summary>
/// Clears aggregated error counters.
/// </summary>
public void ClearAggregatedErrors()
{
GPUApi.ResetECCErrorInfo(PhysicalGPU.Handle, false, true);
}
/// <summary>
/// Clears current error counters.
/// </summary>
public void ClearCurrentErrors()
{
GPUApi.ResetECCErrorInfo(PhysicalGPU.Handle, true, false);
}
/// <summary>
/// Clears all error counters.
/// </summary>
public void ClearErrors()
{
GPUApi.ResetECCErrorInfo(PhysicalGPU.Handle, true, true);
}
/// <summary>
/// Disables ECC memory error correction.
/// </summary>
/// <param name="immediate">A boolean value to indicate if this change should get applied immediately</param>
public void Disable(bool immediate)
{
GPUApi.SetECCConfiguration(PhysicalGPU.Handle, false, immediate);
}
/// <summary>
/// Enables ECC memory error correction.
/// </summary>
/// <param name="immediate">A boolean value to indicate if this change should get applied immediately</param>
public void Enable(bool immediate)
{
GPUApi.SetECCConfiguration(PhysicalGPU.Handle, true, immediate);
}
}
}

View File

@@ -1,115 +0,0 @@
using NvAPIWrapper.Native;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Contains physical GPU architect information
/// </summary>
public class GPUArchitectInformation
{
internal GPUArchitectInformation(PhysicalGPU physicalGPU)
{
PhysicalGPU = physicalGPU;
}
/// <summary>
/// Gets total number of cores defined for this GPU, or zero for older architectures
/// </summary>
public int NumberOfCores
{
get => (int) GPUApi.GetGPUCoreCount(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the number of graphics processing clusters (aka GPU Partitions)
/// </summary>
public int NumberOfGPC
{
get => (int) GPUApi.GetPartitionCount(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the number of render output units
/// </summary>
public int NumberOfROPs
{
get => (int) GPUApi.GetROPCount(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the number of shader pipelines
/// </summary>
public int NumberOfShaderPipelines
{
get => (int) GPUApi.GetShaderPipeCount(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the number of shader sub pipelines
/// </summary>
public int NumberOfShaderSubPipelines
{
get => (int) GPUApi.GetShaderSubPipeCount(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the number of video processing engines
/// </summary>
public int NumberOfVPEs
{
get => (int) GPUApi.GetVPECount(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the physical GPU that this instance describes
/// </summary>
public PhysicalGPU PhysicalGPU { get; }
/// <summary>
/// Gets the GPU revision number (should be displayed as a hex string)
/// </summary>
public int Revision
{
get => (int) GPUApi.GetArchitectInfo(PhysicalGPU.Handle).Revision;
}
/// <summary>
/// Gets the GPU short name (aka Codename)
/// </summary>
public string ShortName
{
get => GPUApi.GetShortName(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the total number of streaming multiprocessors
/// </summary>
public int TotalNumberOfSMs
{
get => (int) GPUApi.GetTotalSMCount(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the total number of streaming processors
/// </summary>
public int TotalNumberOfSPs
{
get => (int) GPUApi.GetTotalSPCount(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the total number of texture processing clusters
/// </summary>
public int TotalNumberOfTPCs
{
get => (int) GPUApi.GetTotalTPCCount(PhysicalGPU.Handle);
}
/// <inheritdoc />
public override string ToString()
{
return $"[{ShortName} REV{Revision:X}] Cores: {NumberOfCores}";
}
}
}

View File

@@ -1,118 +0,0 @@
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.GPU;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Contains information about the GPU bus
/// </summary>
public class GPUBusInformation
{
internal GPUBusInformation(PhysicalGPU physicalGPU)
{
PhysicalGPU = physicalGPU;
}
/// <summary>
/// Gets accelerated graphics port information
/// </summary>
public AGPInformation AGPInformation
{
get
{
if (BusType != GPUBusType.AGP)
{
return null;
}
return new AGPInformation(
GPUApi.GetAGPAperture(PhysicalGPU.Handle),
GPUApi.GetCurrentAGPRate(PhysicalGPU.Handle)
);
}
}
/// <summary>
/// Gets the bus identification
/// </summary>
public int BusId
{
get => GPUApi.GetBusId(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the bus slot identification
/// </summary>
public int BusSlot
{
get => GPUApi.GetBusSlotId(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the the bus type
/// </summary>
public GPUBusType BusType
{
get => GPUApi.GetBusType(PhysicalGPU.Handle);
}
/// <summary>
/// Gets number of PCIe lanes being used for the PCIe interface downstream
/// </summary>
public int CurrentPCIeLanes
{
get
{
if (BusType == GPUBusType.PCIExpress)
{
return GPUApi.GetCurrentPCIEDownStreamWidth(PhysicalGPU.Handle);
}
return 0;
}
}
/// <summary>
/// Gets GPU interrupt number
/// </summary>
public int IRQ
{
get => GPUApi.GetIRQ(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the PCI identifiers
/// </summary>
public PCIIdentifiers PCIIdentifiers
{
get
{
if (BusType == GPUBusType.FPCI || BusType == GPUBusType.PCI || BusType == GPUBusType.PCIExpress)
{
GPUApi.GetPCIIdentifiers(
PhysicalGPU.Handle,
out var deviceId,
out var subSystemId,
out var revisionId,
out var extDeviceId
);
return new PCIIdentifiers(deviceId, subSystemId, revisionId, (int) extDeviceId);
}
return null;
}
}
/// <summary>
/// Gets the physical GPU that this instance describes
/// </summary>
public PhysicalGPU PhysicalGPU { get; }
/// <inheritdoc />
public override string ToString()
{
return $"[{BusType}] Bus #{BusId}, Slot #{BusSlot}";
}
}
}

View File

@@ -1,130 +0,0 @@
using System;
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Holds information regarding a GPU cooler entry
/// </summary>
public class GPUCooler
{
internal GPUCooler(int coolerId, PrivateCoolerSettingsV1.CoolerSetting coolerSetting, int currentRPM = -1)
{
CoolerId = coolerId;
CurrentLevel = (int) coolerSetting.CurrentLevel;
DefaultMinimumLevel = (int) coolerSetting.DefaultMinimumLevel;
DefaultMaximumLevel = (int) coolerSetting.DefaultMaximumLevel;
CurrentMinimumLevel = (int) coolerSetting.CurrentMinimumLevel;
CurrentMaximumLevel = (int) coolerSetting.CurrentMaximumLevel;
CoolerType = coolerSetting.CoolerType;
CoolerController = coolerSetting.CoolerController;
DefaultPolicy = coolerSetting.DefaultPolicy;
CurrentPolicy = coolerSetting.CurrentPolicy;
Target = coolerSetting.Target;
ControlMode = coolerSetting.ControlMode;
CurrentFanSpeedInRPM = currentRPM;
}
// ReSharper disable once TooManyDependencies
internal GPUCooler(
PrivateFanCoolersInfoV1.FanCoolersInfoEntry infoEntry,
PrivateFanCoolersStatusV1.FanCoolersStatusEntry statusEntry,
PrivateFanCoolersControlV1.FanCoolersControlEntry controlEntry)
{
if (infoEntry.CoolerId != statusEntry.CoolerId || statusEntry.CoolerId != controlEntry.CoolerId)
{
throw new ArgumentException("Passed arguments are meant to be for different coolers.");
}
CoolerId = (int) statusEntry.CoolerId;
CurrentLevel = (int) statusEntry.CurrentLevel;
DefaultMinimumLevel = (int) statusEntry.CurrentMinimumLevel;
DefaultMaximumLevel = (int) statusEntry.CurrentMaximumLevel;
CurrentMinimumLevel = (int) statusEntry.CurrentMinimumLevel;
CurrentMaximumLevel = (int) statusEntry.CurrentMaximumLevel;
CoolerType = CoolerType.Fan;
CoolerController = CoolerController.Internal;
DefaultPolicy = CoolerPolicy.None;
CurrentPolicy = controlEntry.ControlMode == FanCoolersControlMode.Manual
? CoolerPolicy.Manual
: CoolerPolicy.None;
Target = CoolerTarget.All;
ControlMode = CoolerControlMode.Variable;
CurrentFanSpeedInRPM = (int) statusEntry.CurrentRPM;
}
/// <summary>
/// Gets the cooler control mode
/// </summary>
public CoolerControlMode ControlMode { get; }
/// <summary>
/// Gets the cooler controller
/// </summary>
public CoolerController CoolerController { get; }
/// <summary>
/// Gets the cooler identification number or index
/// </summary>
public int CoolerId { get; }
/// <summary>
/// Gets the cooler type
/// </summary>
public CoolerType CoolerType { get; }
/// <summary>
/// Gets the GPU fan speed in revolutions per minute
/// </summary>
public int CurrentFanSpeedInRPM { get; }
/// <summary>
/// Gets the cooler current level in percentage
/// </summary>
public int CurrentLevel { get; }
/// <summary>
/// Gets the cooler current maximum level in percentage
/// </summary>
public int CurrentMaximumLevel { get; }
/// <summary>
/// Gets the cooler current minimum level in percentage
/// </summary>
public int CurrentMinimumLevel { get; }
/// <summary>
/// Gets the cooler current policy
/// </summary>
public CoolerPolicy CurrentPolicy { get; }
/// <summary>
/// Gets the cooler default maximum level in percentage
/// </summary>
public int DefaultMaximumLevel { get; }
/// <summary>
/// Gets the cooler default minimum level in percentage
/// </summary>
public int DefaultMinimumLevel { get; }
/// <summary>
/// Gets the cooler default policy
/// </summary>
public CoolerPolicy DefaultPolicy { get; }
/// <summary>
/// Gets the cooler target
/// </summary>
public CoolerTarget Target { get; }
/// <inheritdoc />
public override string ToString()
{
return $"[{CoolerId} @ {CoolerController}] {Target}: {CurrentLevel}%";
}
}
}

View File

@@ -1,340 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.Exceptions;
using NvAPIWrapper.Native.General;
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Contains information about the GPU coolers and current fan speed
/// </summary>
public class GPUCoolerInformation
{
internal GPUCoolerInformation(PhysicalGPU physicalGPU)
{
PhysicalGPU = physicalGPU;
// TODO: Add Support For Pascal Only Policy Table Method
// TODO: GPUApi.GetCoolerPolicyTable & GPUApi.SetCoolerPolicyTable & GPUApi.RestoreCoolerPolicyTable
// TODO: Better support of ClientFanCoolers set of APIs
}
/// <summary>
/// Gets a list of all available coolers along with their current settings and status
/// </summary>
public IEnumerable<GPUCooler> Coolers
{
get
{
PrivateCoolerSettingsV1? settings = null;
try
{
settings = GPUApi.GetCoolerSettings(PhysicalGPU.Handle);
}
catch (NVIDIAApiException e)
{
if (e.Status != Status.NotSupported)
{
throw;
}
}
if (settings != null)
{
for (var i = 0; i < settings.Value.CoolerSettings.Length; i++)
{
if (i == 0)
{
var currentRPM = -1;
try
{
currentRPM = (int)GPUApi.GetTachReading(PhysicalGPU.Handle);
}
catch (NVIDIAApiException)
{
// ignored
}
if (currentRPM >= 0)
{
yield return new GPUCooler(
i,
settings.Value.CoolerSettings[i],
currentRPM
);
continue;
}
}
yield return new GPUCooler(
i,
settings.Value.CoolerSettings[i]
);
}
yield break;
}
PrivateFanCoolersStatusV1? status = null;
PrivateFanCoolersInfoV1? info = null;
PrivateFanCoolersControlV1? control = null;
try
{
status = GPUApi.GetClientFanCoolersStatus(PhysicalGPU.Handle);
info = GPUApi.GetClientFanCoolersInfo(PhysicalGPU.Handle);
control = GPUApi.GetClientFanCoolersControl(PhysicalGPU.Handle);
}
catch (NVIDIAApiException e)
{
if (e.Status != Status.NotSupported)
{
throw;
}
}
if (status != null && info != null && control != null)
{
for (var i = 0; i < status.Value.FanCoolersStatusEntries.Length; i++)
{
if (info.Value.FanCoolersInfoEntries.Length > i &&
control.Value.FanCoolersControlEntries.Length > i)
{
yield return new GPUCooler(
info.Value.FanCoolersInfoEntries[i],
status.Value.FanCoolersStatusEntries[i],
control.Value.FanCoolersControlEntries[i]
);
}
}
yield break;
}
throw new NVIDIAApiException(Status.NotSupported);
}
}
/// <summary>
/// Gets the GPU fan speed in revolutions per minute
/// </summary>
public int CurrentFanSpeedInRPM
{
get
{
try
{
return (int) GPUApi.GetTachReading(PhysicalGPU.Handle);
}
catch
{
return Coolers.FirstOrDefault(cooler => cooler.Target == CoolerTarget.All)?.CurrentFanSpeedInRPM ??
0;
}
}
}
/// <summary>
/// Gets the current fan speed in percentage if available
/// </summary>
public int CurrentFanSpeedLevel
{
get
{
try
{
return (int) GPUApi.GetCurrentFanSpeedLevel(PhysicalGPU.Handle);
}
catch
{
return Coolers.FirstOrDefault(cooler => cooler.Target == CoolerTarget.All)?.CurrentLevel ?? 0;
}
}
}
/// <summary>
/// Gets the physical GPU that this instance describes
/// </summary>
public PhysicalGPU PhysicalGPU { get; }
/// <inheritdoc />
public override string ToString()
{
return $"{CurrentFanSpeedInRPM} RPM ({CurrentFanSpeedLevel}%)";
}
/// <summary>
/// Resets all cooler settings to default.
/// </summary>
public void RestoreCoolerSettingsToDefault()
{
RestoreCoolerSettingsToDefault(Coolers.Select(cooler => cooler.CoolerId).ToArray());
}
/// <summary>
/// Resets one or more cooler settings to default.
/// </summary>
/// <param name="coolerIds">The cooler identification numbers (indexes) to reset their settings to default.</param>
public void RestoreCoolerSettingsToDefault(params int[] coolerIds)
{
var availableCoolerIds = Coolers.Select(cooler => cooler.CoolerId).ToArray();
if (coolerIds.Any(i => !availableCoolerIds.Contains(i)))
{
throw new ArgumentException("Invalid cooler identification number provided.", nameof(coolerIds));
}
try
{
GPUApi.RestoreCoolerSettings(PhysicalGPU.Handle, coolerIds.Select(i => (uint) i).ToArray());
return;
}
catch (NVIDIAApiException e)
{
if (e.Status != Status.NotSupported)
{
throw;
}
}
var currentControl = GPUApi.GetClientFanCoolersControl(PhysicalGPU.Handle);
var newControl = new PrivateFanCoolersControlV1(
currentControl.FanCoolersControlEntries.Select(
entry => coolerIds.Contains((int) entry.CoolerId)
? new PrivateFanCoolersControlV1.FanCoolersControlEntry(
entry.CoolerId,
FanCoolersControlMode.Auto
)
: entry
)
.ToArray(),
currentControl.UnknownUInt
);
GPUApi.SetClientFanCoolersControl(PhysicalGPU.Handle, newControl);
}
/// <summary>
/// Changes a cooler settings by modifying the policy and the current level
/// </summary>
/// <param name="coolerId">The cooler identification number (index) to change the settings.</param>
/// <param name="policy">The new cooler policy.</param>
/// <param name="newLevel">The new cooler level. Valid only if policy is set to manual.</param>
// ReSharper disable once TooManyDeclarations
public void SetCoolerSettings(int coolerId, CoolerPolicy policy, int newLevel)
{
if (Coolers.All(cooler => cooler.CoolerId != coolerId))
{
throw new ArgumentException("Invalid cooler identification number provided.", nameof(coolerId));
}
try
{
GPUApi.SetCoolerLevels(
PhysicalGPU.Handle,
(uint) coolerId,
new PrivateCoolerLevelsV1(new[]
{
new PrivateCoolerLevelsV1.CoolerLevel(policy, (uint) newLevel)
}
),
1
);
return;
}
catch (NVIDIAApiException e)
{
if (e.Status != Status.NotSupported)
{
throw;
}
}
var currentControl = GPUApi.GetClientFanCoolersControl(PhysicalGPU.Handle);
var newControl = new PrivateFanCoolersControlV1(
currentControl.FanCoolersControlEntries.Select(
entry => entry.CoolerId == coolerId
? new PrivateFanCoolersControlV1.FanCoolersControlEntry(
entry.CoolerId,
policy == CoolerPolicy.Manual
? FanCoolersControlMode.Manual
: FanCoolersControlMode.Auto,
policy == CoolerPolicy.Manual ? (uint)newLevel : 0u)
: entry
)
.ToArray(),
currentControl.UnknownUInt
);
GPUApi.SetClientFanCoolersControl(PhysicalGPU.Handle, newControl);
}
/// <summary>
/// Changes a cooler setting by modifying the policy
/// </summary>
/// <param name="coolerId">The cooler identification number (index) to change the settings.</param>
/// <param name="policy">The new cooler policy.</param>
// ReSharper disable once TooManyDeclarations
public void SetCoolerSettings(int coolerId, CoolerPolicy policy)
{
if (Coolers.All(cooler => cooler.CoolerId != coolerId))
{
throw new ArgumentException("Invalid cooler identification number provided.", nameof(coolerId));
}
try
{
GPUApi.SetCoolerLevels(
PhysicalGPU.Handle,
(uint) coolerId,
new PrivateCoolerLevelsV1(new[]
{
new PrivateCoolerLevelsV1.CoolerLevel(policy)
}
),
1
);
return;
}
catch (NVIDIAApiException e)
{
if (e.Status != Status.NotSupported)
{
throw;
}
}
var currentControl = GPUApi.GetClientFanCoolersControl(PhysicalGPU.Handle);
var newControl = new PrivateFanCoolersControlV1(
currentControl.FanCoolersControlEntries.Select(
entry => entry.CoolerId == coolerId
? new PrivateFanCoolersControlV1.FanCoolersControlEntry(
entry.CoolerId,
policy == CoolerPolicy.Manual
? FanCoolersControlMode.Manual
: FanCoolersControlMode.Auto)
: entry
)
.ToArray(),
currentControl.UnknownUInt
);
GPUApi.SetClientFanCoolersControl(PhysicalGPU.Handle, newControl);
}
/// <summary>
/// Changes a cooler settings by modifying the policy to manual and sets a new level
/// </summary>
/// <param name="coolerId">The cooler identification number (index) to change the settings.</param>
/// <param name="newLevel">The new cooler level.</param>
public void SetCoolerSettings(int coolerId, int newLevel)
{
SetCoolerSettings(coolerId, CoolerPolicy.Manual, newLevel);
}
}
}

View File

@@ -1,222 +0,0 @@
using System;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.Interfaces.GPU;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Contains information regarding the available and total memory as well as the type of memory and other information
/// regarding the GPU RAM and frame buffer
/// </summary>
public class GPUMemoryInformation : IDisplayDriverMemoryInfo
{
internal GPUMemoryInformation(PhysicalGPU physicalGPU)
{
PhysicalGPU = physicalGPU;
}
/// <summary>
/// Gets the frame buffer bandwidth
/// </summary>
public int FrameBufferBandwidth
{
get
{
GPUApi.GetFrameBufferWidthAndLocation(PhysicalGPU.Handle, out var width, out _);
return (int) width;
}
}
/// <summary>
/// Gets the frame buffer location index
/// </summary>
public int FrameBufferLocation
{
get
{
GPUApi.GetFrameBufferWidthAndLocation(PhysicalGPU.Handle, out _, out var location);
return (int) location;
}
}
/// <summary>
/// Gets the internal clock to bus clock factor based on the type of RAM
/// </summary>
public int InternalClockToBusClockFactor
{
get => GetMemoryBusClockFactor(RAMType);
}
/// <summary>
/// Gets the internal clock to transfer rate factor based on the type of RAM
/// </summary>
public int InternalClockToTransferRateFactor
{
get => GetMemoryTransferRateFactor(RAMType);
}
/// <summary>
/// Gets GPU physical frame buffer size in KB. This does NOT include any system RAM that may be dedicated for use by
/// the GPU.
/// </summary>
public int PhysicalFrameBufferSizeInkB
{
get => GPUApi.GetPhysicalFrameBufferSize(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the physical GPU that this instance describes
/// </summary>
public PhysicalGPU PhysicalGPU { get; }
/// <summary>
/// Gets the number of memory banks
/// </summary>
public uint RAMBanks
{
get => GPUApi.GetRAMBankCount(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the memory bus width
/// </summary>
public uint RAMBusWidth
{
get => GPUApi.GetRAMBusWidth(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the memory maker (brand)
/// </summary>
public GPUMemoryMaker RAMMaker
{
get => GPUApi.GetRAMMaker(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the memory type
/// </summary>
public GPUMemoryType RAMType
{
get => GPUApi.GetRAMType(PhysicalGPU.Handle);
}
/// <summary>
/// Gets virtual size of frame-buffer in KB for this GPU. This includes the physical RAM plus any system RAM that has
/// been dedicated for use by the GPU.
/// </summary>
public int VirtualFrameBufferSizeInkB
{
get => GPUApi.GetVirtualFrameBufferSize(PhysicalGPU.Handle);
}
/// <inheritdoc />
public uint AvailableDedicatedVideoMemoryInkB
{
get => GPUApi.GetMemoryInfo(PhysicalGPU.Handle).AvailableDedicatedVideoMemoryInkB;
}
/// <inheritdoc />
public uint CurrentAvailableDedicatedVideoMemoryInkB
{
get => GPUApi.GetMemoryInfo(PhysicalGPU.Handle).CurrentAvailableDedicatedVideoMemoryInkB;
}
/// <inheritdoc />
public uint DedicatedVideoMemoryInkB
{
get => GPUApi.GetMemoryInfo(PhysicalGPU.Handle).DedicatedVideoMemoryInkB;
}
/// <inheritdoc />
public uint SharedSystemMemoryInkB
{
get => GPUApi.GetMemoryInfo(PhysicalGPU.Handle).SharedSystemMemoryInkB;
}
/// <inheritdoc />
public uint SystemVideoMemoryInkB
{
get => GPUApi.GetMemoryInfo(PhysicalGPU.Handle).SystemVideoMemoryInkB;
}
/// <summary>
/// Gets the memory bus clock to internal memory clock factor
/// </summary>
/// <param name="memoryType"></param>
/// <returns>The value of X in X(InternalMemoryClock)=(BusMemoryClock)</returns>
public static int GetMemoryBusClockFactor(GPUMemoryType memoryType)
{
switch (memoryType)
{
case GPUMemoryType.SDRAM:
// Bus Clocks Per Internal Clock = 1
return 1;
case GPUMemoryType.DDR1:
case GPUMemoryType.DDR2:
case GPUMemoryType.DDR3:
case GPUMemoryType.GDDR2:
case GPUMemoryType.GDDR3:
case GPUMemoryType.GDDR4:
case GPUMemoryType.LPDDR2:
case GPUMemoryType.GDDR5:
case GPUMemoryType.GDDR5X:
// Bus Clocks Per Internal Clock = 2
return 2;
default:
throw new ArgumentOutOfRangeException(nameof(memoryType));
}
}
/// <summary>
/// Gets the number of transfers per internal memory clock factor
/// </summary>
/// <param name="memoryType"></param>
/// <returns>The value of X in X(InternalMemoryClock)=(OperationsPerSecond)</returns>
public static int GetMemoryTransferRateFactor(GPUMemoryType memoryType)
{
switch (memoryType)
{
case GPUMemoryType.SDRAM:
// Transfers Per Internal Clock = 1
return 1;
case GPUMemoryType.DDR1:
case GPUMemoryType.DDR2:
case GPUMemoryType.DDR3:
case GPUMemoryType.GDDR2:
case GPUMemoryType.GDDR3:
case GPUMemoryType.GDDR4:
case GPUMemoryType.LPDDR2:
// Transfers Per Internal Clock = 1
return 2;
case GPUMemoryType.GDDR5:
// Transfers Per Internal Clock = 2
return 4;
case GPUMemoryType.GDDR5X:
// Transfers Per Internal Clock = 4
return 8;
default:
throw new ArgumentOutOfRangeException(nameof(memoryType));
}
}
/// <inheritdoc />
public override string ToString()
{
return
$"[{RAMMaker} {RAMType}] Total: {AvailableDedicatedVideoMemoryInkB:N0} kB - Available: {CurrentAvailableDedicatedVideoMemoryInkB:N0} kB";
}
}
}

View File

@@ -1,264 +0,0 @@
using System;
using NvAPIWrapper.Display;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.Exceptions;
using NvAPIWrapper.Native.General;
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Represents a single GPU output
/// </summary>
public class GPUOutput : IEquatable<GPUOutput>
{
internal GPUOutput(OutputId outputId, PhysicalGPUHandle gpuHandle)
{
OutputId = outputId;
OutputType = !gpuHandle.IsNull ? GPUApi.GetOutputType(gpuHandle, outputId) : OutputType.Unknown;
PhysicalGPU = new PhysicalGPU(gpuHandle);
}
internal GPUOutput(OutputId outputId, PhysicalGPU gpu)
: this(outputId, gpu?.Handle ?? PhysicalGPUHandle.DefaultHandle)
{
PhysicalGPU = gpu;
}
/// <summary>
/// Gets the corresponding Digital Vibrance Control information
/// </summary>
public DVCInformation DigitalVibranceControl
{
get => new DVCInformation(OutputId);
}
/// <summary>
/// Gets the corresponding HUE information
/// </summary>
public HUEInformation HUEControl
{
get => new HUEInformation(OutputId);
}
/// <summary>
/// Gets the output identification as a single bit unsigned integer
/// </summary>
public OutputId OutputId { get; }
/// <summary>
/// Gets the output type
/// </summary>
public OutputType OutputType { get; }
/// <summary>
/// Gets the corresponding physical GPU
/// </summary>
public PhysicalGPU PhysicalGPU { get; }
/// <inheritdoc />
public bool Equals(GPUOutput other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return PhysicalGPU.Equals(other.PhysicalGPU) && OutputId == other.OutputId;
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(GPUOutput left, GPUOutput right)
{
return right?.Equals(left) ?? ReferenceEquals(left, null);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(GPUOutput left, GPUOutput right)
{
return !(left == right);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((GPUOutput) obj);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
return ((PhysicalGPU != null ? PhysicalGPU.GetHashCode() : 0) * 397) ^ (int) OutputId;
}
}
/// <inheritdoc />
public override string ToString()
{
return $"{OutputId} {OutputType} @ {PhysicalGPU}";
}
/// <summary>
/// Overrides the refresh rate on this output.
/// The new refresh rate can be applied right away or deferred to be applied with the next OS
/// mode-set.
/// The override is good for only one mode-set (regardless whether it's deferred or immediate).
/// </summary>
/// <param name="refreshRate">The refresh rate to be applied.</param>
/// <param name="isDeferred">
/// A boolean value indicating if the refresh rate override should be deferred to the next OS
/// mode-set.
/// </param>
public void OverrideRefreshRate(float refreshRate, bool isDeferred = false)
{
DisplayApi.SetRefreshRateOverride(OutputId, refreshRate, isDeferred);
}
/// <summary>
/// Reads data from the I2C bus
/// </summary>
/// <param name="portId">The port id on which device is connected</param>
/// <param name="useDDCPort">A boolean value indicating that the DDC port should be used instead of the communication port</param>
/// <param name="deviceAddress">The device I2C slave address</param>
/// <param name="registerAddress">The target I2C register address</param>
/// <param name="readDataLength">The length of the buffer to allocate for the read operation.</param>
/// <param name="speed">The target speed of the transaction in kHz</param>
public byte[] ReadI2C(
byte? portId,
bool useDDCPort,
byte deviceAddress,
byte[] registerAddress,
uint readDataLength,
I2CSpeed speed = I2CSpeed.Default
)
{
try
{
// ReSharper disable once InconsistentNaming
var i2cInfoV3 = new I2CInfoV3(
OutputId,
portId,
useDDCPort,
deviceAddress,
registerAddress,
readDataLength,
speed
);
return PhysicalGPU.ReadI2C(i2cInfoV3);
}
catch (NVIDIAApiException e)
{
if (e.Status != Status.IncompatibleStructureVersion || portId != null)
{
throw;
}
// ignore
}
// ReSharper disable once InconsistentNaming
var i2cInfoV2 = new I2CInfoV2(
OutputId,
useDDCPort,
deviceAddress,
registerAddress,
readDataLength,
speed
);
return PhysicalGPU.ReadI2C(i2cInfoV2);
}
/// <summary>
/// Writes data to the I2C bus
/// </summary>
/// <param name="portId">The port id on which device is connected</param>
/// <param name="useDDCPort">A boolean value indicating that the DDC port should be used instead of the communication port</param>
/// <param name="deviceAddress">The device I2C slave address</param>
/// <param name="registerAddress">The target I2C register address</param>
/// <param name="data">The payload data</param>
/// <param name="speed">The target speed of the transaction in kHz</param>
public void WriteI2C(
byte? portId,
bool useDDCPort,
byte deviceAddress,
byte[] registerAddress,
byte[] data,
I2CSpeed speed = I2CSpeed.Default
)
{
try
{
// ReSharper disable once InconsistentNaming
var i2cInfoV3 = new I2CInfoV3(
OutputId,
portId,
useDDCPort,
deviceAddress,
registerAddress,
data,
speed
);
PhysicalGPU.WriteI2C(i2cInfoV3);
return;
}
catch (NVIDIAApiException e)
{
if (e.Status != Status.IncompatibleStructureVersion || portId != null)
{
throw;
}
// ignore
}
// ReSharper disable once InconsistentNaming
var i2cInfoV2 = new I2CInfoV2(
OutputId,
useDDCPort,
deviceAddress,
registerAddress,
data,
speed
);
PhysicalGPU.WriteI2C(i2cInfoV2);
}
}
}

View File

@@ -1,124 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.GPU;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Contains information regarding the GPU performance control and limitations
/// </summary>
public class GPUPerformanceControl
{
internal GPUPerformanceControl(PhysicalGPU physicalGPU)
{
PhysicalGPU = physicalGPU;
}
/// <summary>
/// Gets the current active performance limitation
/// </summary>
public PerformanceLimit CurrentActiveLimit
{
get => GPUApi.PerformancePoliciesGetStatus(PhysicalGPU.Handle).PerformanceLimit;
}
/// <summary>
/// Gets the current performance decrease reason
/// </summary>
public PerformanceDecreaseReason CurrentPerformanceDecreaseReason
{
get => GPUApi.GetPerformanceDecreaseInfo(PhysicalGPU.Handle);
}
/// <summary>
/// Gets a boolean value indicating if no load limit is supported with this GPU
/// </summary>
public bool IsNoLoadLimitSupported
{
get => GPUApi.PerformancePoliciesGetInfo(PhysicalGPU.Handle).IsNoLoadLimitSupported;
}
/// <summary>
/// Gets a boolean value indicating if power limit is supported with this GPU
/// </summary>
public bool IsPowerLimitSupported
{
get => GPUApi.PerformancePoliciesGetInfo(PhysicalGPU.Handle).IsPowerLimitSupported;
}
/// <summary>
/// Gets a boolean value indicating if temperature limit is supported with this GPU
/// </summary>
public bool IsTemperatureLimitSupported
{
get => GPUApi.PerformancePoliciesGetInfo(PhysicalGPU.Handle).IsTemperatureLimitSupported;
}
/// <summary>
/// Gets a boolean value indicating if voltage limit is supported with this GPU
/// </summary>
public bool IsVoltageLimitSupported
{
get => GPUApi.PerformancePoliciesGetInfo(PhysicalGPU.Handle).IsVoltageLimitSupported;
}
/// <summary>
/// Gets the physical GPU that this instance describes
/// </summary>
public PhysicalGPU PhysicalGPU { get; }
/// <summary>
/// Gets information regarding possible power limit policies and their acceptable range
/// </summary>
public IEnumerable<GPUPowerLimitInfo> PowerLimitInformation
{
get
{
return GPUApi.ClientPowerPoliciesGetInfo(PhysicalGPU.Handle).PowerPolicyInfoEntries
.Select(entry => new GPUPowerLimitInfo(entry));
}
}
/// <summary>
/// Gets the current active power limit policies
/// </summary>
public IEnumerable<GPUPowerLimitPolicy> PowerLimitPolicies
{
get
{
// TODO: GPUApi.ClientPowerPoliciesSetStatus();
return GPUApi.ClientPowerPoliciesGetStatus(PhysicalGPU.Handle).PowerPolicyStatusEntries
.Select(entry => new GPUPowerLimitPolicy(entry));
}
}
/// <summary>
/// Gets information regarding possible thermal limit policies and their acceptable range
/// </summary>
public IEnumerable<GPUThermalLimitInfo> ThermalLimitInformation
{
get
{
return GPUApi.GetThermalPoliciesInfo(PhysicalGPU.Handle).ThermalPoliciesInfoEntries
.Select(entry => new GPUThermalLimitInfo(entry));
}
}
/// <summary>
/// Gets the current active thermal limit policies
/// </summary>
public IEnumerable<GPUThermalLimitPolicy> ThermalLimitPolicies
{
get
{
// TODO: GPUApi.SetThermalPoliciesStatus();
return GPUApi.GetThermalPoliciesStatus(PhysicalGPU.Handle).ThermalPoliciesStatusEntries
.Select(entry => new GPUThermalLimitPolicy(entry));
}
}
}
}

View File

@@ -1,70 +0,0 @@
using System.Linq;
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.Interfaces.GPU;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Represents a performance state
/// </summary>
public class GPUPerformanceState
{
// ReSharper disable once TooManyDependencies
internal GPUPerformanceState(
int index,
IPerformanceState20 performanceState,
IPerformanceStates20ClockEntry[] statesClockEntries,
IPerformanceStates20VoltageEntry[] baseVoltageEntries,
PCIeInformation pcieInformation)
{
StateIndex = index;
StateId = performanceState.StateId;
IsReadOnly = !performanceState.IsEditable;
Clocks = statesClockEntries.Select(entry => new GPUPerformanceStateClock(entry)).ToArray();
Voltages = baseVoltageEntries.Select(entry => new GPUPerformanceStateVoltage(entry)).ToArray();
PCIeInformation = pcieInformation;
}
/// <summary>
/// Gets a list of clocks associated with this performance state
/// </summary>
public GPUPerformanceStateClock[] Clocks { get; }
/// <summary>
/// Gets a boolean value indicating if this performance state is readonly
/// </summary>
public bool IsReadOnly { get; }
/// <summary>
/// Gets the PCI-e information regarding this performance state.
/// </summary>
public PCIeInformation PCIeInformation { get; }
/// <summary>
/// Gets the performance state identification
/// </summary>
public PerformanceStateId StateId { get; }
/// <summary>
/// Gets the state index
/// </summary>
public int StateIndex { get; }
/// <summary>
/// Gets a list of voltages associated with this performance state
/// </summary>
public GPUPerformanceStateVoltage[] Voltages { get; }
/// <inheritdoc />
public override string ToString()
{
if (IsReadOnly)
{
return $"{StateId} (ReadOnly)";
}
return StateId.ToString();
}
}
}

View File

@@ -1,99 +0,0 @@
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.Interfaces.GPU;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Represents a performance state clock settings
/// </summary>
public class GPUPerformanceStateClock
{
internal GPUPerformanceStateClock(IPerformanceStates20ClockEntry states20ClockEntry)
{
ClockDomain = states20ClockEntry.DomainId;
IsReadOnly = !states20ClockEntry.IsEditable;
ClockDeltaInkHz = states20ClockEntry.FrequencyDeltaInkHz.DeltaValue;
ClockDeltaRangeInkHz = new GPUPerformanceStateValueRange(
states20ClockEntry.FrequencyDeltaInkHz.DeltaRange.Minimum,
states20ClockEntry.FrequencyDeltaInkHz.DeltaRange.Maximum
);
if (states20ClockEntry.ClockType == PerformanceStates20ClockType.Range)
{
CurrentClockInkHz = new GPUPerformanceStateValueRange(
states20ClockEntry.FrequencyRange.MinimumFrequencyInkHz,
states20ClockEntry.FrequencyRange.MaximumFrequencyInkHz
);
BaseClockInkHz = new GPUPerformanceStateValueRange(
CurrentClockInkHz.Minimum - ClockDeltaInkHz,
CurrentClockInkHz.Maximum - ClockDeltaInkHz
);
DependentVoltageDomain = states20ClockEntry.FrequencyRange.VoltageDomainId;
DependentVoltageRangeInMicroVolt = new GPUPerformanceStateValueRange(
states20ClockEntry.FrequencyRange.MinimumVoltageInMicroVolt,
states20ClockEntry.FrequencyRange.MaximumVoltageInMicroVolt
);
}
else
{
CurrentClockInkHz = new GPUPerformanceStateValueRange(
states20ClockEntry.SingleFrequency.FrequencyInkHz
);
BaseClockInkHz = new GPUPerformanceStateValueRange(
CurrentClockInkHz.Minimum - ClockDeltaInkHz
);
DependentVoltageDomain = PerformanceVoltageDomain.Undefined;
DependentVoltageRangeInMicroVolt = null;
}
}
/// <summary>
/// Gets the base clock frequency in kHz
/// </summary>
public GPUPerformanceStateValueRange BaseClockInkHz { get; }
/// <summary>
/// Gets the clock frequency delta in kHz
/// </summary>
public int ClockDeltaInkHz { get; }
/// <summary>
/// Gets the clock frequency delta range in kHz
/// </summary>
public GPUPerformanceStateValueRange ClockDeltaRangeInkHz { get; }
/// <summary>
/// Gets the clock domain
/// </summary>
public PublicClockDomain ClockDomain { get; }
/// <summary>
/// Gets the current clock frequency in kHz
/// </summary>
public GPUPerformanceStateValueRange CurrentClockInkHz { get; }
/// <summary>
/// Gets the dependent voltage domain
/// </summary>
public PerformanceVoltageDomain DependentVoltageDomain { get; }
/// <summary>
/// Gets the dependent voltage range in uV
/// </summary>
public GPUPerformanceStateValueRange DependentVoltageRangeInMicroVolt { get; }
/// <summary>
/// Gets a boolean value indicating if this clock setting is readonly
/// </summary>
public bool IsReadOnly { get; }
/// <inheritdoc />
public override string ToString()
{
var title = IsReadOnly ? $"{ClockDomain} (ReadOnly)" : ClockDomain.ToString();
return
$"{title}: {BaseClockInkHz} + ({ClockDeltaInkHz}) = {CurrentClockInkHz}";
}
}
}

View File

@@ -1,115 +0,0 @@
using System;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Represents an integer value range
/// </summary>
public class GPUPerformanceStateValueRange : IEquatable<GPUPerformanceStateValueRange>
{
/// <summary>
/// Creates a new instance of <see cref="GPUPerformanceStateValueRange" />.
/// </summary>
/// <param name="min">The lower bound of the range.</param>
/// <param name="max">The upper bound of the range.</param>
public GPUPerformanceStateValueRange(long min, long max)
{
Minimum = min;
Maximum = max;
}
/// <summary>
/// Creates a new single value instance of <see cref="GPUPerformanceStateValueRange" />.
/// </summary>
/// <param name="value">The only value in the range</param>
public GPUPerformanceStateValueRange(long value)
{
Minimum = value;
Maximum = value;
}
/// <summary>
/// Gets the upper bound of the inclusive range
/// </summary>
public long Maximum { get; }
/// <summary>
/// Gets the lower bound of the inclusive range
/// </summary>
public long Minimum { get; }
/// <inheritdoc />
public bool Equals(GPUPerformanceStateValueRange other)
{
if (other == null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Maximum == other.Maximum && Minimum == other.Minimum;
}
/// <summary>
/// Checks two instances of <see cref="GPUPerformanceStateValueRange" /> for equality.
/// </summary>
/// <param name="left">The left side of the comparison.</param>
/// <param name="right">The right side of the comparison.</param>
/// <returns>true if instances are equal, otherwise false</returns>
public static bool operator ==(GPUPerformanceStateValueRange left, GPUPerformanceStateValueRange right)
{
return Equals(left, right) || left?.Equals(right) == true;
}
/// <summary>
/// Checks two instances of <see cref="GPUPerformanceStateValueRange" /> for inequality.
/// </summary>
/// <param name="left">The left side of the comparison.</param>
/// <param name="right">The right side of the comparison.</param>
/// <returns>true if instances are in-equal, otherwise false</returns>
public static bool operator !=(GPUPerformanceStateValueRange left, GPUPerformanceStateValueRange right)
{
return !(left == right);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return Equals(obj as GPUPerformanceStateValueRange);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
return ((int) Maximum * 397) ^ (int) Minimum;
}
}
/// <inheritdoc />
public override string ToString()
{
if (Minimum == Maximum)
{
return $"({Minimum})";
}
return $"[({Minimum}) - ({Maximum})]";
}
}
}

View File

@@ -1,65 +0,0 @@
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.Interfaces.GPU;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Represents a performance state voltage settings
/// </summary>
public class GPUPerformanceStateVoltage
{
internal GPUPerformanceStateVoltage(IPerformanceStates20VoltageEntry states20BaseVoltageEntry)
{
VoltageDomain = states20BaseVoltageEntry.DomainId;
IsReadOnly = !states20BaseVoltageEntry.IsEditable;
CurrentVoltageInMicroVolt = states20BaseVoltageEntry.ValueInMicroVolt;
VoltageDeltaInMicroVolt = states20BaseVoltageEntry.ValueDeltaInMicroVolt.DeltaValue;
BaseVoltageInMicroVolt = (int) (CurrentVoltageInMicroVolt - VoltageDeltaInMicroVolt);
VoltageDeltaRangeInMicroVolt = new GPUPerformanceStateValueRange(
states20BaseVoltageEntry.ValueDeltaInMicroVolt.DeltaRange.Minimum,
states20BaseVoltageEntry.ValueDeltaInMicroVolt.DeltaRange.Maximum
);
}
/// <summary>
/// Gets the base voltage in uV
/// </summary>
public int BaseVoltageInMicroVolt { get; }
/// <summary>
/// Gets the current voltage in uV
/// </summary>
public uint CurrentVoltageInMicroVolt { get; }
/// <summary>
/// Gets a boolean value indicating if this voltage is readonly
/// </summary>
public bool IsReadOnly { get; }
/// <summary>
/// Gets the voltage delta in uV
/// </summary>
public int VoltageDeltaInMicroVolt { get; }
/// <summary>
/// Gets the voltage delta range in uV
/// </summary>
public GPUPerformanceStateValueRange VoltageDeltaRangeInMicroVolt { get; }
/// <summary>
/// Gets the voltage domain
/// </summary>
public PerformanceVoltageDomain VoltageDomain { get; }
/// <inheritdoc />
public override string ToString()
{
var title = IsReadOnly ? $"{VoltageDomain} (ReadOnly)" : VoltageDomain.ToString();
return
$"{title}: ({BaseVoltageInMicroVolt}) + ({VoltageDeltaInMicroVolt}) = ({CurrentVoltageInMicroVolt})";
}
}
}

View File

@@ -1,107 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
using NvAPIWrapper.Native.Interfaces.GPU;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Holds the retrieved performance states information
/// </summary>
public class GPUPerformanceStatesInformation
{
internal GPUPerformanceStatesInformation(
IPerformanceStates20Info states20Info,
PerformanceStateId currentPerformanceStateId,
PrivatePCIeInfoV2? pciInformation)
{
IsReadOnly = !states20Info.IsEditable;
GlobalVoltages = states20Info.GeneralVoltages
.Select(entry => new GPUPerformanceStateVoltage(entry))
.ToArray();
var clocks = states20Info.Clocks;
var baseVoltages = states20Info.Voltages;
PerformanceStates = states20Info.PerformanceStates.Select((state20, i) =>
{
PCIeInformation statePCIeInfo = null;
if (pciInformation != null && pciInformation.Value.PCIePerformanceStateInfos.Length > i)
{
statePCIeInfo = new PCIeInformation(pciInformation.Value.PCIePerformanceStateInfos[i]);
}
return new GPUPerformanceState(
i,
state20,
clocks[state20.StateId],
baseVoltages[state20.StateId],
statePCIeInfo
);
}).ToArray();
CurrentPerformanceState =
PerformanceStates.FirstOrDefault(performanceState =>
performanceState.StateId == currentPerformanceStateId);
}
/// <summary>
/// Gets the currently active performance state
/// </summary>
public GPUPerformanceState CurrentPerformanceState { get; }
/// <summary>
/// Gets a list of global voltage settings
/// </summary>
public GPUPerformanceStateVoltage[] GlobalVoltages { get; }
/// <summary>
/// Gets a boolean value indicating if performance states are readonly
/// </summary>
public bool IsReadOnly { get; }
/// <summary>
/// Gets a list of all available performance states
/// </summary>
public GPUPerformanceState[] PerformanceStates { get; }
/// <inheritdoc />
public override string ToString()
{
if (PerformanceStates.Length == 0)
{
return "No Performance State Available";
}
return string.Join(
", ",
PerformanceStates
.Select(
state =>
{
var attributes = new List<string>();
if (state.IsReadOnly)
{
attributes.Add("ReadOnly");
}
if (CurrentPerformanceState.StateId == state.StateId)
{
attributes.Add("Active");
}
if (attributes.Any())
{
return $"{state.StateId} ({string.Join(" - ", attributes)})";
}
return state.StateId.ToString();
})
);
}
}
}

View File

@@ -1,70 +0,0 @@
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Holds information regarding a possible power limit policy and its acceptable range
/// </summary>
public class GPUPowerLimitInfo
{
internal GPUPowerLimitInfo(PrivatePowerPoliciesInfoV1.PowerPolicyInfoEntry powerPolicyInfoEntry)
{
PerformanceStateId = powerPolicyInfoEntry.PerformanceStateId;
MinimumPowerInPCM = powerPolicyInfoEntry.MinimumPowerInPCM;
DefaultPowerInPCM = powerPolicyInfoEntry.DefaultPowerInPCM;
MaximumPowerInPCM = powerPolicyInfoEntry.MaximumPowerInPCM;
}
/// <summary>
/// Gets the default policy target power in per cent mille (PCM)
/// </summary>
public uint DefaultPowerInPCM { get; }
/// <summary>
/// Gets the default policy target power in percentage
/// </summary>
public float DefaultPowerInPercent
{
get => DefaultPowerInPCM / 1000f;
}
/// <summary>
/// Gets the maximum possible policy target power in per cent mille (PCM)
/// </summary>
public uint MaximumPowerInPCM { get; }
/// <summary>
/// Gets the maximum possible policy target power in percentage
/// </summary>
public float MaximumPowerInPercent
{
get => MaximumPowerInPCM / 1000f;
}
/// <summary>
/// Gets the minimum possible policy target power in per cent mille (PCM)
/// </summary>
public uint MinimumPowerInPCM { get; }
/// <summary>
/// Gets the minimum possible policy target power in percentage
/// </summary>
public float MinimumPowerInPercent
{
get => MinimumPowerInPCM / 1000f;
}
/// <summary>
/// Gets the corresponding performance state identification
/// </summary>
public PerformanceStateId PerformanceStateId { get; }
/// <inheritdoc />
public override string ToString()
{
return
$"[{PerformanceStateId}] Default: {DefaultPowerInPercent}% - Range: ({MinimumPowerInPercent}% - {MaximumPowerInPercent}%)";
}
}
}

View File

@@ -1,41 +0,0 @@
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Holds information regarding a currently active power limit policy
/// </summary>
public class GPUPowerLimitPolicy
{
internal GPUPowerLimitPolicy(PrivatePowerPoliciesStatusV1.PowerPolicyStatusEntry powerPolicyStatusEntry)
{
PerformanceStateId = powerPolicyStatusEntry.PerformanceStateId;
PowerTargetInPCM = powerPolicyStatusEntry.PowerTargetInPCM;
}
/// <summary>
/// Gets the corresponding performance state identification
/// </summary>
public PerformanceStateId PerformanceStateId { get; }
/// <summary>
/// Gets the current policy target power in per cent mille (PCM)
/// </summary>
public uint PowerTargetInPCM { get; }
/// <summary>
/// Gets the current policy target power in percentage
/// </summary>
public float PowerTargetInPercent
{
get => PowerTargetInPCM / 1000f;
}
/// <inheritdoc />
public override string ToString()
{
return $"{PerformanceStateId} Target: {PowerTargetInPercent}%";
}
}
}

View File

@@ -1,34 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using NvAPIWrapper.Native;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Holds information regarding current power topology and their current power usage
/// </summary>
public class GPUPowerTopologyInformation
{
internal GPUPowerTopologyInformation(PhysicalGPU physicalGPU)
{
PhysicalGPU = physicalGPU;
}
/// <summary>
/// Gets the physical GPU that this instance describes
/// </summary>
public PhysicalGPU PhysicalGPU { get; }
/// <summary>
/// Gets the current power topology entries
/// </summary>
public IEnumerable<GPUPowerTopologyStatus> PowerTopologyEntries
{
get
{
return GPUApi.ClientPowerTopologyGetStatus(PhysicalGPU.Handle).PowerPolicyStatusEntries
.Select(entry => new GPUPowerTopologyStatus(entry));
}
}
}
}

View File

@@ -1,42 +0,0 @@
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Contains information about a power domain usage
/// </summary>
public class GPUPowerTopologyStatus
{
internal GPUPowerTopologyStatus(
PrivatePowerTopologiesStatusV1.PowerTopologiesStatusEntry powerTopologiesStatusEntry)
{
Domain = powerTopologiesStatusEntry.Domain;
PowerUsageInPCM = powerTopologiesStatusEntry.PowerUsageInPCM;
}
/// <summary>
/// Gets the power usage domain
/// </summary>
public PowerTopologyDomain Domain { get; }
/// <summary>
/// Gets the current power usage in per cent mille (PCM)
/// </summary>
public uint PowerUsageInPCM { get; }
/// <summary>
/// Gets the current power usage in percentage
/// </summary>
public float PowerUsageInPercent
{
get => PowerUsageInPCM / 1000f;
}
/// <inheritdoc />
public override string ToString()
{
return $"[{Domain}] {PowerUsageInPercent}%";
}
}
}

View File

@@ -1,42 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using NvAPIWrapper.Native;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Holds information regarding the available thermal sensors and current thermal level of a GPU
/// </summary>
public class GPUThermalInformation
{
internal GPUThermalInformation(PhysicalGPU physicalGPU)
{
PhysicalGPU = physicalGPU;
}
/// <summary>
/// Gets the current thermal level of the GPU
/// </summary>
public int CurrentThermalLevel
{
get => (int) GPUApi.GetCurrentThermalLevel(PhysicalGPU.Handle);
}
/// <summary>
/// Gets the physical GPU that this instance describes
/// </summary>
public PhysicalGPU PhysicalGPU { get; }
/// <summary>
/// Gets the list of available thermal sensors
/// </summary>
public IEnumerable<GPUThermalSensor> ThermalSensors
{
get
{
return GPUApi.GetThermalSettings(PhysicalGPU.Handle).Sensors
.Select((sensor, i) => new GPUThermalSensor(i, sensor));
}
}
}
}

View File

@@ -1,47 +0,0 @@
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Holds information regarding a possible thermal limit policy and its acceptable range
/// </summary>
public class GPUThermalLimitInfo
{
internal GPUThermalLimitInfo(PrivateThermalPoliciesInfoV2.ThermalPoliciesInfoEntry policiesInfoEntry)
{
Controller = policiesInfoEntry.Controller;
MinimumTemperature = policiesInfoEntry.MinimumTemperature;
DefaultTemperature = policiesInfoEntry.DefaultTemperature;
MaximumTemperature = policiesInfoEntry.MaximumTemperature;
}
/// <summary>
/// Gets the policy's thermal controller
/// </summary>
public ThermalController Controller { get; }
/// <summary>
/// Gets the default policy target temperature in degree Celsius
/// </summary>
public int DefaultTemperature { get; }
/// <summary>
/// Gets the maximum possible policy target temperature in degree Celsius
/// </summary>
public int MaximumTemperature { get; }
/// <summary>
/// Gets the minimum possible policy target temperature in degree Celsius
/// </summary>
public int MinimumTemperature { get; }
/// <inheritdoc />
public override string ToString()
{
return
$"[{Controller}] Default: {DefaultTemperature}°C - Range: ({MinimumTemperature}°C - {MaximumTemperature}°C)";
}
}
}

View File

@@ -1,40 +0,0 @@
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Holds information regarding a currently active temperature limit policy
/// </summary>
public class GPUThermalLimitPolicy
{
internal GPUThermalLimitPolicy(PrivateThermalPoliciesStatusV2.ThermalPoliciesStatusEntry thermalPoliciesEntry)
{
Controller = thermalPoliciesEntry.Controller;
PerformanceStateId = thermalPoliciesEntry.PerformanceStateId;
TargetTemperature = thermalPoliciesEntry.TargetTemperature;
}
/// <summary>
/// Gets the policy's thermal controller
/// </summary>
public ThermalController Controller { get; }
/// <summary>
/// Gets the corresponding performance state identification
/// </summary>
public PerformanceStateId PerformanceStateId { get; }
/// <summary>
/// Gets the current policy target temperature in degree Celsius
/// </summary>
public int TargetTemperature { get; }
/// <inheritdoc />
public override string ToString()
{
return
$"{PerformanceStateId} [{Controller}] Target: {TargetTemperature}°C";
}
}
}

View File

@@ -1,48 +0,0 @@
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.Interfaces.GPU;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Represents a thermal sensor
/// </summary>
public class GPUThermalSensor : IThermalSensor
{
internal GPUThermalSensor(int sensorId, IThermalSensor thermalSensor)
{
SensorId = sensorId;
Controller = thermalSensor.Controller;
DefaultMinimumTemperature = thermalSensor.DefaultMinimumTemperature;
DefaultMaximumTemperature = thermalSensor.DefaultMaximumTemperature;
CurrentTemperature = thermalSensor.CurrentTemperature;
Target = thermalSensor.Target;
}
/// <summary>
/// Gets the sensor identification number or index
/// </summary>
public int SensorId { get; set; }
/// <inheritdoc />
public ThermalController Controller { get; }
/// <inheritdoc />
public int CurrentTemperature { get; }
/// <inheritdoc />
public int DefaultMaximumTemperature { get; }
/// <inheritdoc />
public int DefaultMinimumTemperature { get; }
/// <inheritdoc />
public ThermalSettingsTarget Target { get; }
/// <inheritdoc />
public override string ToString()
{
return
$"[{Target} @ {Controller}] Current: {CurrentTemperature}°C - Default Range: [({DefaultMinimumTemperature}°C) , ({DefaultMaximumTemperature}°C)]";
}
}
}

View File

@@ -1,33 +0,0 @@
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.Interfaces.GPU;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Holds information about a utilization domain
/// </summary>
public class GPUUsageDomainStatus
{
internal GPUUsageDomainStatus(UtilizationDomain domain, IUtilizationDomainInfo utilizationDomainInfo)
{
Domain = domain;
Percentage = (int) utilizationDomainInfo.Percentage;
}
/// <summary>
/// Gets the utilization domain that this instance describes
/// </summary>
public UtilizationDomain Domain { get; }
/// <summary>
/// Gets the percentage of time where the domain is considered busy in the last 1 second interval.
/// </summary>
public int Percentage { get; }
/// <inheritdoc />
public override string ToString()
{
return $"[{Domain}] {Percentage}%";
}
}
}

View File

@@ -1,99 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.GPU;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Holds information about the GPU utilization domains
/// </summary>
public class GPUUsageInformation
{
internal GPUUsageInformation(PhysicalGPU physicalGPU)
{
PhysicalGPU = physicalGPU;
}
/// <summary>
/// Gets the Bus interface (BUS) utilization
/// </summary>
public GPUUsageDomainStatus BusInterface
{
get => UtilizationDomainsStatus.FirstOrDefault(status => status.Domain == UtilizationDomain.BusInterface);
}
/// <summary>
/// Gets the frame buffer (FB) utilization
/// </summary>
public GPUUsageDomainStatus FrameBuffer
{
get => UtilizationDomainsStatus.FirstOrDefault(status => status.Domain == UtilizationDomain.FrameBuffer);
}
/// <summary>
/// Gets the graphic engine (GPU) utilization
/// </summary>
public GPUUsageDomainStatus GPU
{
get => UtilizationDomainsStatus.FirstOrDefault(status => status.Domain == UtilizationDomain.GPU);
}
/// <summary>
/// Gets a boolean value indicating if the dynamic performance states is enabled
/// </summary>
public bool IsDynamicPerformanceStatesEnabled
{
get => GPUApi.GetDynamicPerformanceStatesInfoEx(PhysicalGPU.Handle).IsDynamicPerformanceStatesEnabled;
}
/// <summary>
/// Gets the physical GPU that this instance describes
/// </summary>
public PhysicalGPU PhysicalGPU { get; }
/// <summary>
/// Gets all valid utilization domains and information
/// </summary>
public IEnumerable<GPUUsageDomainStatus> UtilizationDomainsStatus
{
get
{
try
{
var dynamicPerformanceStates = GPUApi.GetDynamicPerformanceStatesInfoEx(PhysicalGPU.Handle);
if (dynamicPerformanceStates.IsDynamicPerformanceStatesEnabled)
{
return dynamicPerformanceStates.Domains
.Select(pair => new GPUUsageDomainStatus(pair.Key, pair.Value));
}
}
catch
{
// ignored
}
return GPUApi.GetUsages(PhysicalGPU.Handle).Domains
.Select(pair => new GPUUsageDomainStatus(pair.Key, pair.Value));
}
}
/// <summary>
/// Gets the Video engine (VID) utilization
/// </summary>
public GPUUsageDomainStatus VideoEngine
{
get => UtilizationDomainsStatus.FirstOrDefault(status => status.Domain == UtilizationDomain.VideoEngine);
}
/// <summary>
/// Enables dynamic performance states
/// </summary>
public void EnableDynamicPerformanceStates()
{
GPUApi.EnableDynamicPStates(PhysicalGPU.Handle);
}
}
}

View File

@@ -1,119 +0,0 @@
using System;
using System.Linq;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.GPU.Structures;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Represents a logical NVIDIA GPU
/// </summary>
public class LogicalGPU : IEquatable<LogicalGPU>
{
/// <summary>
/// Creates a new LogicalGPU
/// </summary>
/// <param name="handle">Logical GPU handle</param>
public LogicalGPU(LogicalGPUHandle handle)
{
Handle = handle;
}
/// <summary>
/// Gets a list of all corresponding physical GPUs
/// </summary>
public PhysicalGPU[] CorrespondingPhysicalGPUs
{
get
{
return GPUApi.GetPhysicalGPUsFromLogicalGPU(Handle).Select(handle => new PhysicalGPU(handle)).ToArray();
}
}
/// <summary>
/// Gets the logical GPU handle
/// </summary>
public LogicalGPUHandle Handle { get; }
/// <inheritdoc />
public bool Equals(LogicalGPU other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Handle.Equals(other.Handle);
}
/// <summary>
/// Gets all logical GPUs
/// </summary>
/// <returns>An array of logical GPUs</returns>
public static LogicalGPU[] GetLogicalGPUs()
{
return GPUApi.EnumLogicalGPUs().Select(handle => new LogicalGPU(handle)).ToArray();
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(LogicalGPU left, LogicalGPU right)
{
return right?.Equals(left) ?? ReferenceEquals(left, null);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(LogicalGPU left, LogicalGPU right)
{
return !(left == right);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((LogicalGPU) obj);
}
/// <inheritdoc />
public override int GetHashCode()
{
return Handle.GetHashCode();
}
/// <inheritdoc />
public override string ToString()
{
return
$"Logical GPU [{CorrespondingPhysicalGPUs.Length}] {{{string.Join(", ", CorrespondingPhysicalGPUs.Select(gpu => gpu.FullName).ToArray())}}}";
}
}
}

View File

@@ -1,114 +0,0 @@
using System;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Contains information about the PCI connection
/// </summary>
public class PCIIdentifiers : IEquatable<PCIIdentifiers>
{
// ReSharper disable once TooManyDependencies
internal PCIIdentifiers(uint deviceId, uint subSystemId, uint revisionId, int externalDeviceId = 0)
{
DeviceId = deviceId;
SubSystemId = subSystemId;
RevisionId = revisionId;
if (externalDeviceId > 0)
{
ExternalDeviceId = (ushort) externalDeviceId;
}
else
{
ExternalDeviceId = (ushort) (deviceId >> 16);
}
VendorId = (ushort) ((DeviceId << 16) >> 16);
}
/// <summary>
/// Gets the internal PCI device identifier
/// </summary>
public uint DeviceId { get; }
/// <summary>
/// Gets the external PCI device identifier
/// </summary>
public ushort ExternalDeviceId { get; }
/// <summary>
/// Gets the internal PCI device-specific revision identifier
/// </summary>
public uint RevisionId { get; }
/// <summary>
/// Gets the internal PCI subsystem identifier
/// </summary>
public uint SubSystemId { get; }
/// <summary>
/// Gets the vendor identification calculated from internal device identification
/// </summary>
public ushort VendorId { get; }
/// <inheritdoc />
public bool Equals(PCIIdentifiers other)
{
return DeviceId == other.DeviceId &&
SubSystemId == other.SubSystemId &&
RevisionId == other.RevisionId;
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(PCIIdentifiers left, PCIIdentifiers right)
{
return left.Equals(right);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(PCIIdentifiers left, PCIIdentifiers right)
{
return !left.Equals(right);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is PCIIdentifiers identifiers && Equals(identifiers);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) DeviceId;
hashCode = (hashCode * 397) ^ (int) SubSystemId;
hashCode = (hashCode * 397) ^ (int) RevisionId;
return hashCode;
}
}
/// <inheritdoc />
public override string ToString()
{
return $"PCI\\VEN_{VendorId:X}&DEV_{ExternalDeviceId:X}&SUBSYS_{SubSystemId:X}&REV_{RevisionId:X}";
}
}
}

View File

@@ -1,67 +0,0 @@
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Contains information about the PCI-e connection
/// </summary>
public class PCIeInformation
{
internal PCIeInformation(PrivatePCIeInfoV2.PCIePerformanceStateInfo stateInfo)
{
TransferRateInMTps = stateInfo.TransferRateInMTps;
Generation = stateInfo.Generation;
Lanes = stateInfo.Lanes;
Version = stateInfo.Version;
}
/// <summary>
/// Gets the PCI-e generation
/// </summary>
public PCIeGeneration Generation { get; }
/// <summary>
/// Gets the PCI-e down stream lanes
/// </summary>
public uint Lanes { get; }
/// <summary>
/// Gets the PCIe transfer rate in Mega Transfers per Second
/// </summary>
public uint TransferRateInMTps { get; }
/// <summary>
/// Gets the PCI-e version
/// </summary>
public PCIeGeneration Version { get; }
/// <inheritdoc />
public override string ToString()
{
var v = "Unknown";
switch (Version)
{
case PCIeGeneration.PCIe1:
v = "PCIe 1.0";
break;
case PCIeGeneration.PCIe1Minor1:
v = "PCIe 1.1";
break;
case PCIeGeneration.PCIe2:
v = "PCIe 2.0";
break;
case PCIeGeneration.PCIe3:
v = "PCIe 3.0";
break;
}
return $"{v} x{Lanes} - {TransferRateInMTps} MTps";
}
}
}

View File

@@ -1,559 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using NvAPIWrapper.Display;
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.Exceptions;
using NvAPIWrapper.Native.General;
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
using NvAPIWrapper.Native.Helpers;
using NvAPIWrapper.Native.Interfaces.GPU;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Represents a physical NVIDIA GPU
/// </summary>
public class PhysicalGPU : IEquatable<PhysicalGPU>
{
/// <summary>
/// Creates a new PhysicalGPU
/// </summary>
/// <param name="handle">Physical GPU handle</param>
public PhysicalGPU(PhysicalGPUHandle handle)
{
Handle = handle;
UsageInformation = new GPUUsageInformation(this);
ThermalInformation = new GPUThermalInformation(this);
BusInformation = new GPUBusInformation(this);
ArchitectInformation = new GPUArchitectInformation(this);
MemoryInformation = new GPUMemoryInformation(this);
CoolerInformation = new GPUCoolerInformation(this);
ECCMemoryInformation = new ECCMemoryInformation(this);
PerformanceControl = new GPUPerformanceControl(this);
PowerTopologyInformation = new GPUPowerTopologyInformation(this);
}
/// <summary>
/// Gets all active outputs of this GPU
/// </summary>
public GPUOutput[] ActiveOutputs
{
get
{
var outputs = new List<GPUOutput>();
var allOutputs = GPUApi.GetActiveOutputs(Handle);
foreach (OutputId outputId in Enum.GetValues(typeof(OutputId)))
{
if (outputId != OutputId.Invalid && allOutputs.HasFlag(outputId))
{
outputs.Add(new GPUOutput(outputId, this));
}
}
return outputs.ToArray();
}
}
/// <summary>
/// Gets GPU architect information
/// </summary>
public GPUArchitectInformation ArchitectInformation { get; }
/// <summary>
/// Gets GPU base clock frequencies
/// </summary>
public IClockFrequencies BaseClockFrequencies
{
get => GPUApi.GetAllClockFrequencies(Handle, new ClockFrequenciesV2(ClockType.BaseClock));
}
/// <summary>
/// Gets GPU video BIOS information
/// </summary>
public VideoBIOS Bios
{
get => new VideoBIOS(
GPUApi.GetVBIOSRevision(Handle),
(int) GPUApi.GetVBIOSOEMRevision(Handle),
GPUApi.GetVBIOSVersionString(Handle)
);
}
/// <summary>
/// Gets the board information
/// </summary>
public BoardInfo Board
{
get
{
try
{
return GPUApi.GetBoardInfo(Handle);
}
catch (NVIDIAApiException ex)
{
if (ex.Status == Status.NotSupported)
{
return default;
}
throw;
}
}
}
/// <summary>
/// Gets GPU boost clock frequencies
/// </summary>
public IClockFrequencies BoostClockFrequencies
{
get => GPUApi.GetAllClockFrequencies(Handle, new ClockFrequenciesV2(ClockType.BoostClock));
}
/// <summary>
/// Gets GPU bus information
/// </summary>
public GPUBusInformation BusInformation { get; }
/// <summary>
/// Gets GPU coolers information
/// </summary>
public GPUCoolerInformation CoolerInformation { get; }
/// <summary>
/// Gets corresponding logical GPU
/// </summary>
public LogicalGPU CorrespondingLogicalGPU
{
get => new LogicalGPU(GPUApi.GetLogicalGPUFromPhysicalGPU(Handle));
}
/// <summary>
/// Gets GPU current clock frequencies
/// </summary>
public IClockFrequencies CurrentClockFrequencies
{
get => GPUApi.GetAllClockFrequencies(Handle, new ClockFrequenciesV2(ClockType.CurrentClock));
}
/// <summary>
/// Gets the driver model number for this GPU
/// </summary>
public uint DriverModel
{
get => GPUApi.GetDriverModel(Handle);
}
/// <summary>
/// Gets GPU ECC memory information
/// </summary>
public ECCMemoryInformation ECCMemoryInformation { get; }
/// <summary>
/// Gets the chipset foundry
/// </summary>
public GPUFoundry Foundry
{
get => GPUApi.GetFoundry(Handle);
}
/// <summary>
/// Gets GPU full name
/// </summary>
public string FullName
{
get => GPUApi.GetFullName(Handle);
}
/// <summary>
/// Gets the GPU identification number
/// </summary>
public uint GPUId
{
get => GPUApi.GetGPUIDFromPhysicalGPU(Handle);
}
/// <summary>
/// Gets GPU type
/// </summary>
public GPUType GPUType
{
get => GPUApi.GetGPUType(Handle);
}
/// <summary>
/// Gets the physical GPU handle
/// </summary>
public PhysicalGPUHandle Handle { get; }
/// <summary>
/// Gets a boolean value indicating the Quadro line of products
/// </summary>
public bool IsQuadro
{
get => GPUApi.GetQuadroStatus(Handle);
}
/// <summary>
/// Gets GPU memory and RAM information as well as frame-buffer information
/// </summary>
public GPUMemoryInformation MemoryInformation { get; }
/// <summary>
/// Gets GPU performance control status and configurations
/// </summary>
public GPUPerformanceControl PerformanceControl { get; }
/// <summary>
/// Gets the GPU performance states information and configurations
/// </summary>
public GPUPerformanceStatesInformation PerformanceStatesInfo
{
get
{
var performanceStates20Info = GPUApi.GetPerformanceStates20(Handle);
var currentPerformanceState = GPUApi.GetCurrentPerformanceState(Handle);
PrivatePCIeInfoV2? pcieInformation = null;
if (BusInformation.BusType == GPUBusType.PCIExpress)
{
try
{
pcieInformation = GPUApi.GetPCIEInfo(Handle);
}
catch
{
// ignore
}
}
return new GPUPerformanceStatesInformation(performanceStates20Info, currentPerformanceState,
pcieInformation);
}
}
/// <summary>
/// Gets GPU coolers information
/// </summary>
public GPUPowerTopologyInformation PowerTopologyInformation { get; }
/// <summary>
/// Gets GPU system type
/// </summary>
public SystemType SystemType
{
get => GPUApi.GetSystemType(Handle);
}
/// <summary>
/// Gets GPU thermal sensors information
/// </summary>
public GPUThermalInformation ThermalInformation { get; }
/// <summary>
/// Gets the GPU utilization domains and usages
/// </summary>
public GPUUsageInformation UsageInformation { get; }
/// <inheritdoc />
public bool Equals(PhysicalGPU other)
{
if (other == null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Handle.Equals(other.Handle);
}
/// <summary>
/// Gets the corresponding <see cref="PhysicalGPU" /> instance from a GPU identification number.
/// </summary>
/// <param name="gpuId">The GPU identification number.</param>
/// <returns>An instance of <see cref="PhysicalGPU" /> or <see langword="null" /> if operation failed.</returns>
public static PhysicalGPU FromGPUId(uint gpuId)
{
var handle = GPUApi.GetPhysicalGPUFromGPUID(gpuId);
if (handle.IsNull)
{
return null;
}
return new PhysicalGPU(handle);
}
/// <summary>
/// Gets all physical GPUs
/// </summary>
/// <returns>An array of physical GPUs</returns>
public static PhysicalGPU[] GetPhysicalGPUs()
{
return GPUApi.EnumPhysicalGPUs().Select(handle => new PhysicalGPU(handle)).ToArray();
}
/// <summary>
/// Gets all physical GPUs in TCC state
/// </summary>
/// <returns>An array of physical GPUs</returns>
public static PhysicalGPU[] GetTCCPhysicalGPUs()
{
return GPUApi.EnumTCCPhysicalGPUs().Select(handle => new PhysicalGPU(handle)).ToArray();
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(PhysicalGPU left, PhysicalGPU right)
{
return Equals(left, right) || left?.Equals(right) == true;
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(PhysicalGPU left, PhysicalGPU right)
{
return !(left == right);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
return Equals(obj as PhysicalGPU);
}
/// <inheritdoc />
public override int GetHashCode()
{
return Handle.GetHashCode();
}
/// <inheritdoc />
public override string ToString()
{
return FullName;
}
/// <summary>
/// Get a list of all active applications for this GPU
/// </summary>
/// <returns>An array of processes</returns>
public Process[] GetActiveApplications()
{
return GPUApi.QueryActiveApps(Handle).Select(app => Process.GetProcessById(app.ProcessId)).ToArray();
}
/// <summary>
/// Get a list of all connected display devices on this GPU
/// </summary>
/// <param name="flags">ConnectedIdsFlag flag</param>
/// <returns>An array of display devices</returns>
public DisplayDevice[] GetConnectedDisplayDevices(ConnectedIdsFlag flags)
{
return GPUApi.GetConnectedDisplayIds(Handle, flags).Select(display => new DisplayDevice(display)).ToArray();
}
/// <summary>
/// Get the display device connected to a specific GPU output
/// </summary>
/// <param name="output">The GPU output to get connected display device for</param>
/// <returns>DisplayDevice connected to the specified GPU output</returns>
public DisplayDevice GetDisplayDeviceByOutput(GPUOutput output)
{
return new DisplayDevice(GPUApi.GetDisplayIdFromGPUAndOutputId(Handle, output.OutputId));
}
/// <summary>
/// Get a list of all display devices on any possible output
/// </summary>
/// <returns>An array of display devices</returns>
public DisplayDevice[] GetDisplayDevices()
{
return GPUApi.GetAllDisplayIds(Handle).Select(display => new DisplayDevice(display)).ToArray();
}
/// <summary>
/// Reads EDID data of an output
/// </summary>
/// <param name="output">The GPU output to read EDID information for</param>
/// <returns>A byte array containing EDID data</returns>
public byte[] ReadEDIDData(GPUOutput output)
{
try
{
var data = new byte[0];
var identification = 0;
var totalSize = EDIDV3.MaxDataSize;
for (var offset = 0; offset < totalSize; offset += EDIDV3.MaxDataSize)
{
var edid = GPUApi.GetEDID(Handle, output.OutputId, offset, identification);
identification = edid.Identification;
totalSize = edid.TotalSize;
var edidData = edid.Data;
Array.Resize(ref data, data.Length + edidData.Length);
Array.Copy(edidData, 0, data, data.Length - edidData.Length, edidData.Length);
}
return data;
}
catch (NVIDIAApiException ex)
{
if (ex.Status == Status.IncompatibleStructureVersion)
{
return GPUApi.GetEDID(Handle, output.OutputId).Data;
}
throw;
}
}
/// <summary>
/// Reads data from the I2C bus
/// </summary>
/// <param name="i2cInfo">Information required to read from the I2C bus.</param>
/// <returns>The returned payload.</returns>
// ReSharper disable once InconsistentNaming
public byte[] ReadI2C(II2CInfo i2cInfo)
{
GPUApi.I2CRead(Handle, ref i2cInfo);
return i2cInfo.Data;
}
/// <summary>
/// Validates a set of GPU outputs to check if they can be active simultaneously
/// </summary>
/// <param name="outputs">GPU outputs to check</param>
/// <returns>true if all specified outputs can be active simultaneously, otherwise false</returns>
public bool ValidateOutputCombination(GPUOutput[] outputs)
{
var gpuOutpudIds =
outputs.Aggregate(OutputId.Invalid, (current, gpuOutput) => current | gpuOutput.OutputId);
return GPUApi.ValidateOutputCombination(Handle, gpuOutpudIds);
}
/// <summary>
/// Writes EDID data of an output
/// </summary>
/// <param name="output">The GPU output to write EDID information for</param>
/// <param name="edidData">A byte array containing EDID data</param>
public void WriteEDIDData(GPUOutput output, byte[] edidData)
{
WriteEDIDData((uint) output.OutputId, edidData);
}
/// <summary>
/// Writes EDID data of an display
/// </summary>
/// <param name="display">The display device to write EDID information for</param>
/// <param name="edidData">A byte array containing EDID data</param>
public void WriteEDIDData(DisplayDevice display, byte[] edidData)
{
WriteEDIDData(display.DisplayId, edidData);
}
/// <summary>
/// Writes data to the I2C bus
/// </summary>
/// <param name="i2cInfo">Information required to write to the I2C bus including data payload.</param>
// ReSharper disable once InconsistentNaming
public void WriteI2C(II2CInfo i2cInfo)
{
GPUApi.I2CWrite(Handle, i2cInfo);
}
private void WriteEDIDData(uint displayOutputId, byte[] edidData)
{
try
{
if (edidData.Length == 0)
{
var instance = typeof(EDIDV3).Instantiate<EDIDV3>();
GPUApi.SetEDID(Handle, displayOutputId, instance);
}
for (var offset = 0; offset < edidData.Length; offset += EDIDV3.MaxDataSize)
{
var array = new byte[Math.Min(EDIDV3.MaxDataSize, edidData.Length - offset)];
Array.Copy(edidData, offset, array, 0, array.Length);
var instance = EDIDV3.CreateWithData(0, (uint) offset, array, edidData.Length);
GPUApi.SetEDID(Handle, displayOutputId, instance);
}
return;
}
catch (NVIDIAApiException ex)
{
if (ex.Status != Status.IncompatibleStructureVersion)
{
throw;
}
}
catch (NVIDIANotSupportedException)
{
// ignore
}
try
{
if (edidData.Length == 0)
{
var instance = typeof(EDIDV2).Instantiate<EDIDV2>();
GPUApi.SetEDID(Handle, displayOutputId, instance);
}
for (var offset = 0; offset < edidData.Length; offset += EDIDV2.MaxDataSize)
{
var array = new byte[Math.Min(EDIDV2.MaxDataSize, edidData.Length - offset)];
Array.Copy(edidData, offset, array, 0, array.Length);
GPUApi.SetEDID(Handle, displayOutputId, EDIDV2.CreateWithData(array, edidData.Length));
}
return;
}
catch (NVIDIAApiException ex)
{
if (ex.Status != Status.IncompatibleStructureVersion)
{
throw;
}
}
catch (NVIDIANotSupportedException)
{
// ignore
}
GPUApi.SetEDID(Handle, displayOutputId, EDIDV1.CreateWithData(edidData));
}
}
}

View File

@@ -1,52 +0,0 @@
using System;
namespace NvAPIWrapper.GPU
{
/// <summary>
/// Contains information about the GPU Video BIOS
/// </summary>
public class VideoBIOS
{
internal VideoBIOS(uint revision, int oemRevision, string versionString)
{
Revision = revision;
OEMRevision = oemRevision;
VersionString = versionString.ToUpper();
}
/// <summary>
/// Gets the the OEM revision of the video BIOS
/// </summary>
public int OEMRevision { get; }
/// <summary>
/// Gets the revision of the video BIOS
/// </summary>
public uint Revision { get; }
/// <summary>
/// Gets the full video BIOS version string
/// </summary>
public string VersionString { get; }
/// <inheritdoc />
public override string ToString()
{
return AsVersion().ToString();
}
/// <summary>
/// Returns the video BIOS version as a .Net Version object
/// </summary>
/// <returns>A Version object representing the video BIOS version</returns>
public Version AsVersion()
{
return new Version(
(int) ((Revision >> 28) + ((Revision << 4) >> 28) * 16), // 8 bit little endian
(int) (((Revision << 8) >> 28) + ((Revision << 12) >> 28) * 16), // 8 bit little endian
(int) ((Revision << 16) >> 16), // 16 bit big endian
OEMRevision // 8 bit integer
);
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

View File

@@ -1,81 +0,0 @@
using NvAPIWrapper.Native;
using NvAPIWrapper.Native.General.Structures;
using NvAPIWrapper.Native.Interfaces.General;
namespace NvAPIWrapper
{
/// <summary>
/// .Net friendly version of system and general functions of NVAPI library
/// </summary>
public static class NVIDIA
{
/// <summary>
/// Gets information about the system's chipset.
/// </summary>
public static IChipsetInfo ChipsetInfo
{
get => GeneralApi.GetChipsetInfo();
}
/// <summary>
/// Gets NVIDIA driver branch version as string
/// </summary>
public static string DriverBranchVersion
{
get
{
GeneralApi.GetDriverAndBranchVersion(out var branchVersion);
return branchVersion;
}
}
/// <summary>
/// Gets NVIDIA driver version
/// </summary>
public static uint DriverVersion
{
get => GeneralApi.GetDriverAndBranchVersion(out _);
}
/// <summary>
/// Gets NVAPI interface version as string
/// </summary>
public static string InterfaceVersionString
{
get => GeneralApi.GetInterfaceVersionString();
}
/// <summary>
/// Gets the current lid and dock information.
/// </summary>
public static LidDockParameters LidAndDockParameters
{
get => GeneralApi.GetLidAndDockInfo();
}
/// <summary>
/// Initializes the NvAPI library (if not already initialized) but always increments the ref-counter.
/// </summary>
public static void Initialize()
{
GeneralApi.Initialize();
}
/// <summary>
/// PRIVATE - Requests to restart the display driver
/// </summary>
public static void RestartDisplayDriver()
{
GeneralApi.RestartDisplayDriver();
}
/// <summary>
/// Decrements the ref-counter and when it reaches ZERO, unloads NVAPI library.
/// </summary>
public static void Unload()
{
GeneralApi.Unload();
}
}
}

View File

@@ -1,15 +0,0 @@
using System;
namespace NvAPIWrapper.Native.Attributes
{
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Delegate)]
internal class AcceptsAttribute : Attribute
{
public AcceptsAttribute(params Type[] types)
{
Types = types;
}
public Type[] Types { get; set; }
}
}

View File

@@ -1,16 +0,0 @@
using System;
using NvAPIWrapper.Native.Helpers;
namespace NvAPIWrapper.Native.Attributes
{
[AttributeUsage(AttributeTargets.Delegate)]
internal class FunctionIdAttribute : Attribute
{
public FunctionIdAttribute(FunctionId functionId)
{
FunctionId = functionId;
}
public FunctionId FunctionId { get; set; }
}
}

View File

@@ -1,19 +0,0 @@
using System;
namespace NvAPIWrapper.Native.Attributes
{
[AttributeUsage(AttributeTargets.Struct)]
internal class StructureVersionAttribute : Attribute
{
public StructureVersionAttribute()
{
}
public StructureVersionAttribute(int versionNumber)
{
VersionNumber = versionNumber;
}
public int VersionNumber { get; set; }
}
}

View File

@@ -1,8 +0,0 @@
namespace NvAPIWrapper.Native.Constants
{
internal static class Display
{
public const int AdvancedDisplayHeads = 4;
public const int MaxDisplayHeads = 2;
}
}

View File

@@ -1,8 +0,0 @@
namespace NvAPIWrapper.Native.Constants
{
internal static class General
{
public const int BinaryDataMax = 4096;
public const int UnicodeStringLength = 2048;
}
}

View File

@@ -1,28 +0,0 @@
namespace NvAPIWrapper.Native.DRS
{
/// <summary>
/// Holds possible values for the setting location
/// </summary>
public enum DRSSettingLocation : uint
{
/// <summary>
/// Setting is part of the current profile
/// </summary>
CurrentProfile = 0,
/// <summary>
/// Setting is part of the global profile
/// </summary>
GlobalProfile,
/// <summary>
/// Setting is part of the base profile
/// </summary>
BaseProfile,
/// <summary>
/// Setting is part of the default profile
/// </summary>
DefaultProfile
}
}

Some files were not shown because too many files have changed in this diff Show More