#ifndef __ROCCAT_TYON_PROFILE_SETTINGS_H__
#define __ROCCAT_TYON_PROFILE_SETTINGS_H__

/*
 * This file is part of roccat-tools.
 *
 * roccat-tools is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * roccat-tools is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with roccat-tools. If not, see <http://www.gnu.org/licenses/>.
 */

#include "roccat_device.h"
#include "tyon.h"

G_BEGIN_DECLS

enum {
	TYON_PROFILE_SETTINGS_CPI_LEVELS_NUM = 5,
	TYON_PROFILE_SETTINGS_POLLING_RATE_MASK = 0x0f,
	TYON_PROFILE_SETTINGS_TALKFX_MASK = 0xf0,
	TYON_PROFILE_SETTINGS_POLLING_RATE_SHIFT = 0,
	TYON_PROFILE_SETTINGS_TALKFX_SHIFT = 4,
};

typedef struct _TyonProfileSettings TyonProfileSettings;
typedef struct _TyonLight TyonLight;

struct _TyonLight {
	guint8 index;
	guint8 red;
	guint8 green;
	guint8 blue;
	guint8 unused;
} __attribute__ ((packed));

struct _TyonProfileSettings {
	guint8 command; /* TYON_COMMAND_PROFILE_SETTINGS */
	guint8 size; /* always 30 */
	guint8 profile_index; /* range 0-4 */
	guint8 advanced_sensitivity;
	guint8 sensitivity_x;
	guint8 sensitivity_y;
	guint8 cpi_levels_enabled;
	guint8 cpi_levels[TYON_PROFILE_SETTINGS_CPI_LEVELS_NUM];
	guint8 cpi_active; /* range 0-4 */
	guint8 talkfx_polling_rate;
	guint8 lights_enabled;
	guint8 color_flow;
	guint8 light_effect;
	guint8 effect_speed;
	TyonLight lights[TYON_LIGHTS_NUM];
	guint16 checksum;
} __attribute__ ((packed));

static inline guint8 tyon_profile_settings_get_polling_rate(TyonProfileSettings const *profile_settings) {
	return (profile_settings->talkfx_polling_rate & TYON_PROFILE_SETTINGS_POLLING_RATE_MASK) >> TYON_PROFILE_SETTINGS_POLLING_RATE_SHIFT;
}

static inline guint8 tyon_profile_settings_get_talkfx(TyonProfileSettings const *profile_settings) {
	return (profile_settings->talkfx_polling_rate & TYON_PROFILE_SETTINGS_TALKFX_MASK) >> TYON_PROFILE_SETTINGS_TALKFX_SHIFT;
}

static inline void tyon_profile_settings_set_polling_rate(TyonProfileSettings *profile_settings, guint8 new_value) {
	profile_settings->talkfx_polling_rate = (profile_settings->talkfx_polling_rate & TYON_PROFILE_SETTINGS_TALKFX_MASK) | (new_value << TYON_PROFILE_SETTINGS_POLLING_RATE_SHIFT);
}

static inline void tyon_profile_settings_set_talkfx(TyonProfileSettings *profile_settings, guint8 new_value) {
	profile_settings->talkfx_polling_rate = (profile_settings->talkfx_polling_rate & TYON_PROFILE_SETTINGS_POLLING_RATE_MASK) | (new_value << TYON_PROFILE_SETTINGS_TALKFX_SHIFT);
}

typedef enum {
	TYON_PROFILE_SETTINGS_ADVANCED_SENSITIVITY_OFF = 0,
	TYON_PROFILE_SETTINGS_ADVANCED_SENSITIVITY_ON = 1,
} TyonProfileSettingsAdvancedSensitivity;

typedef enum {
	TYON_PROFILE_SETTINGS_SENSITIVITY_MIN = 0x01,
	TYON_PROFILE_SETTINGS_SENSITIVITY_MAX = 0x0b,
} TyonProfileSettingsSensitivity;

typedef enum {
	TYON_PROFILE_SETTINGS_POLLING_RATE_125 = 0,
	TYON_PROFILE_SETTINGS_POLLING_RATE_250 = 1,
	TYON_PROFILE_SETTINGS_POLLING_RATE_500 = 2,
	TYON_PROFILE_SETTINGS_POLLING_RATE_1000 = 3,
} TyonProfileSettingsPollingRate;

typedef enum {
	TYON_PROFILE_SETTINGS_TALKFX_ON = 0,
	TYON_PROFILE_SETTINGS_TALKFX_OFF = 1,
} TyonProfileSettingsTalkfx;

typedef enum {
	TYON_PROFILE_SETTINGS_LIGHTS_ENABLED_BIT_WHEEL = 0,
	TYON_PROFILE_SETTINGS_LIGHTS_ENABLED_BIT_BOTTOM = 1,
	TYON_PROFILE_SETTINGS_LIGHTS_ENABLED_BIT_CUSTOM_COLOR = 4,
} TyonProfileSettingsLightsEnabled;

typedef enum {
	TYON_PROFILE_SETTINGS_COLOR_FLOW_OFF = 0,
	TYON_PROFILE_SETTINGS_COLOR_FLOW_SIMULTANEOUSLY = 1,
	TYON_PROFILE_SETTINGS_COLOR_FLOW_UP = 2,
	TYON_PROFILE_SETTINGS_COLOR_FLOW_DOWN = 3,
} TyonProfileSettingsColorFlow;

typedef enum {
	TYON_PROFILE_SETTINGS_LIGHT_EFFECT_ALL_OFF = 0,
	TYON_PROFILE_SETTINGS_LIGHT_EFFECT_FULLY_LIGHTED = 1,
	TYON_PROFILE_SETTINGS_LIGHT_EFFECT_BLINKING = 2,
	TYON_PROFILE_SETTINGS_LIGHT_EFFECT_BREATHING = 3,
	TYON_PROFILE_SETTINGS_LIGHT_EFFECT_HEARTBEAT = 4,
} TyonProfileSettingsLightEffect;

typedef enum {
	TYON_PROFILE_SETTINGS_EFFECT_SPEED_MIN = 1,
	TYON_PROFILE_SETTINGS_EFFECT_SPEED_MAX = 3,
} TyonProfileSettingsEffectSpeed;

void tyon_profile_settings_finalize(TyonProfileSettings *profile_settings, guint profile_index);
gboolean tyon_profile_settings_write(RoccatDevice *device, guint profile_index, TyonProfileSettings *profile_settings, GError **error);
TyonProfileSettings *tyon_profile_settings_read(RoccatDevice *device, guint profile_index, GError **error);
gboolean tyon_profile_settings_equal(TyonProfileSettings const *left, TyonProfileSettings const *right);

G_END_DECLS

#endif
