From 415b06af7c6605223fe60b5552ce637d5747d654 Mon Sep 17 00:00:00 2001 From: 9c2a94eb294ac460ccbd019f5f01f45fffff7759 <9c2a94eb294ac460ccbd019f5f01f45fffff7759@redacted> Date: Sat, 6 Jun 2020 15:08:46 -0400 Subject: [PATCH] divaio: Add config --- divaio/config.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ divaio/config.h | 16 +++++++++++++++ divaio/meson.build | 2 ++ 3 files changed, 69 insertions(+) create mode 100644 divaio/config.c create mode 100644 divaio/config.h diff --git a/divaio/config.c b/divaio/config.c new file mode 100644 index 0000000..886277e --- /dev/null +++ b/divaio/config.c @@ -0,0 +1,51 @@ +#include + +#include +#include +#include +#include + +#include "divaio/config.h" + +static const int diva_io_default_buttons[] = { + VK_RIGHT, VK_DOWN, VK_LEFT, VK_UP, VK_SPACE +}; + +static const int diva_io_default_slider[] = { + 'Q', 'W', 'E', 'R', 'U', 'I', 'O', 'P' +}; + +void diva_io_config_load( + struct diva_io_config *cfg, + const wchar_t *filename) +{ + wchar_t key[5]; + wchar_t cell[8]; + int i; + int c; + + assert(cfg != NULL); + assert(filename != NULL); + + cfg->vk_test = GetPrivateProfileIntW(L"io3", L"test", '1', filename); + cfg->vk_service = GetPrivateProfileIntW(L"io3", L"service", '2', filename); + cfg->vk_coin = GetPrivateProfileIntW(L"io3", L"coin", '3', filename); + + for (i = 0 ; i < _countof(cfg->vk_buttons) ; i++) { + swprintf_s(key, _countof(key), L"key%i", i + 1); + cfg->vk_buttons[i] = GetPrivateProfileIntW( + L"buttons", + key, + diva_io_default_buttons[i], + filename); + } + + for (c = 0 ; c < _countof(cfg->vk_slider) ; c++) { + swprintf_s(cell, _countof(cell), L"cell%i", c + 1); + cfg->vk_slider[c] = GetPrivateProfileIntW( + L"slider", + cell, + diva_io_default_slider[c], + filename); + } +} diff --git a/divaio/config.h b/divaio/config.h new file mode 100644 index 0000000..86654c8 --- /dev/null +++ b/divaio/config.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +struct diva_io_config { + uint8_t vk_buttons[5]; + uint8_t vk_slider[8]; + uint8_t vk_test; + uint8_t vk_service; + uint8_t vk_coin; +}; + +void diva_io_config_load( + struct diva_io_config *cfg, + const wchar_t *filename); diff --git a/divaio/meson.build b/divaio/meson.build index e8d498f..30eda9b 100644 --- a/divaio/meson.build +++ b/divaio/meson.build @@ -8,5 +8,7 @@ divaio_dll = shared_library( sources : [ 'divaio.c', 'divaio.h', + 'config.c', + 'config.h', ], )