forked from drath/libratbag
asus: make pointer variables const wherever possible
Also fixes `ASUS_BUTTON_MAPPING` being duplicated between different source files if I understand C right.
This commit is contained in:
10
src/asus.c
10
src/asus.c
@@ -47,7 +47,7 @@
|
||||
#define ASUS_FIELD_SNAPPING 2
|
||||
|
||||
/* key mapping, the index is actual ASUS code */
|
||||
static unsigned char ASUS_KEY_MAPPING[] = {
|
||||
static const unsigned char ASUS_KEY_MAPPING[] = {
|
||||
/* 00 */ 0, 0, 0, 0,
|
||||
/* 04 */ KEY_A, KEY_B, KEY_C, KEY_D,
|
||||
/* 08 */ KEY_E, KEY_F, KEY_G, KEY_H,
|
||||
@@ -75,7 +75,7 @@ static unsigned char ASUS_KEY_MAPPING[] = {
|
||||
/* 5E */ KEY_KP8, KEY_KP9, 0,
|
||||
};
|
||||
|
||||
static unsigned int ASUS_LED_TYPE[] = {
|
||||
static const unsigned int ASUS_LED_TYPE[] = {
|
||||
RATBAG_LED_TYPE_LOGO, /* Mouse logo */
|
||||
RATBAG_LED_TYPE_WHEEL, /* Mouse wheel */
|
||||
RATBAG_LED_TYPE_SIDE, /* Bottom of the mouse */
|
||||
@@ -84,10 +84,10 @@ static unsigned int ASUS_LED_TYPE[] = {
|
||||
static unsigned int ASUS_POLLING_RATES[] = { 125, 250, 500, 1000 };
|
||||
|
||||
/* search for ASUS button by ratbag types */
|
||||
struct asus_button *
|
||||
const struct asus_button *
|
||||
asus_find_button_by_action(struct ratbag_button_action action)
|
||||
{
|
||||
struct asus_button *asus_button;
|
||||
const struct asus_button *asus_button;
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH(ASUS_BUTTON_MAPPING); i++) {
|
||||
asus_button = &ASUS_BUTTON_MAPPING[i];
|
||||
if ((action.type == RATBAG_BUTTON_ACTION_TYPE_BUTTON && asus_button->button == action.action.button) ||
|
||||
@@ -98,7 +98,7 @@ asus_find_button_by_action(struct ratbag_button_action action)
|
||||
}
|
||||
|
||||
/* search for ASUS button by ASUS button code */
|
||||
struct asus_button *
|
||||
const struct asus_button *
|
||||
asus_find_button_by_code(uint8_t asus_code)
|
||||
{
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH(ASUS_BUTTON_MAPPING); i++) {
|
||||
|
||||
@@ -135,7 +135,7 @@ struct asus_button {
|
||||
};
|
||||
|
||||
/* ASUS code, button type, button number, special button action */
|
||||
static struct asus_button ASUS_BUTTON_MAPPING[] = {
|
||||
static const struct asus_button ASUS_BUTTON_MAPPING[] = {
|
||||
{ 0xf0, RATBAG_BUTTON_ACTION_TYPE_BUTTON, 1, 0 }, /* left */
|
||||
{ 0xf1, RATBAG_BUTTON_ACTION_TYPE_BUTTON, 2, 0 }, /* right (button 3 in xev) */
|
||||
{ 0xf2, RATBAG_BUTTON_ACTION_TYPE_BUTTON, 3, 0 }, /* middle (button 2 in xev) */
|
||||
@@ -155,10 +155,10 @@ static struct asus_button ASUS_BUTTON_MAPPING[] = {
|
||||
{ 0xef, RATBAG_BUTTON_ACTION_TYPE_NONE, 0, 0 }, /* side button F */
|
||||
};
|
||||
|
||||
struct asus_button *
|
||||
const struct asus_button *
|
||||
asus_find_button_by_action(struct ratbag_button_action action);
|
||||
|
||||
struct asus_button *
|
||||
const struct asus_button *
|
||||
asus_find_button_by_code(uint8_t asus_code);
|
||||
|
||||
int
|
||||
|
||||
@@ -78,9 +78,9 @@ static int
|
||||
asus_driver_load_profile(struct ratbag_device *device, struct ratbag_profile *profile)
|
||||
{
|
||||
int rc;
|
||||
struct _asus_binding *asus_binding;
|
||||
struct _asus_led *asus_led;
|
||||
struct asus_button *asus_button;
|
||||
const struct _asus_binding *asus_binding;
|
||||
const struct _asus_led *asus_led;
|
||||
const struct asus_button *asus_button;
|
||||
struct ratbag_button *button;
|
||||
struct ratbag_led *led;
|
||||
struct ratbag_resolution *resolution;
|
||||
@@ -208,9 +208,9 @@ asus_driver_save_profile(struct ratbag_device *device, struct ratbag_profile *pr
|
||||
continue;
|
||||
}
|
||||
|
||||
const struct asus_button *asus_button;
|
||||
uint8_t asus_code_src;
|
||||
uint8_t asus_code_dst;
|
||||
struct asus_button *asus_button;
|
||||
|
||||
rc = drv_data->button_mapping[asus_index];
|
||||
if (rc == -1) {
|
||||
@@ -447,7 +447,7 @@ asus_driver_probe(struct ratbag_device *device)
|
||||
/* setup a lookup table for all defined buttons */
|
||||
unsigned int button_index = 0;
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH(ASUS_BUTTON_MAPPING); i++) {
|
||||
struct asus_button *asus_button = &ASUS_BUTTON_MAPPING[i];
|
||||
const struct asus_button *asus_button = &ASUS_BUTTON_MAPPING[i];
|
||||
|
||||
/* search for this button in the ButtonMapping by it's ASUS code */
|
||||
for (unsigned int j = 0; j < ASUS_MAX_NUM_BUTTON; j++) {
|
||||
|
||||
Reference in New Issue
Block a user