#ifndef _ROCCAT_KONE_ORIG_MACRO_H_
#define _ROCCAT_KONE_ORIG_MACRO_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 <glib.h>

G_BEGIN_DECLS

#define KONE_ORIGINAL_MACRO_MAIN_GROUP_NAME "Main"
#define KONE_ORIGINAL_MACRO_COUNT_NAME "Count"

typedef struct _KoneOriginalMacroKeystroke KoneOriginalMacroKeystroke;
typedef struct _KoneOriginalMacro KoneOriginalMacro;

struct _KoneOriginalMacroKeystroke {
	guint8 key;
	guint8 action;
	guint16 period;
} __attribute__ ((packed));

typedef enum {
	KONE_ORIGINAL_MACRO_KEYSTROKE_ACTION_PRESS = 0,
	KONE_ORIGINAL_MACRO_KEYSTROKE_ACTION_RELEASE = 1,
} KoneOriginalMacroKeystrokeAction;

enum {
	KONE_ORIGINAL_MACRO_KEYSTROKES_NUM = 512,
	KONE_ORIGINAL_MACRO_NAME_LENGTH = 52,
};

/*!
 * \brief Kone macro as stored in macro.ini
 */
struct _KoneOriginalMacro {
	guint8 macro_name[KONE_ORIGINAL_MACRO_NAME_LENGTH];
	guint32 count;
	KoneOriginalMacroKeystroke keystrokes[KONE_ORIGINAL_MACRO_KEYSTROKES_NUM];
	guint8 checksum;
} __attribute__ ((packed));

static inline guint16 kone_original_macro_keystroke_get_period(KoneOriginalMacroKeystroke const *keystroke) {
	return GUINT16_FROM_LE(keystroke->period);
}

static inline void kone_original_macro_keystroke_set_period(KoneOriginalMacroKeystroke *keystroke, guint16 new_value) {
	keystroke->period = GUINT16_TO_LE(new_value);
}

static inline guint32 kone_original_macro_get_count(KoneOriginalMacro const *macro) {
	return GUINT32_FROM_LE(macro->count);
}

static inline void kone_original_macro_set_count(KoneOriginalMacro *macro, guint32 new_value) {
	macro->count = GUINT32_TO_LE(new_value);
}

G_END_DECLS

#endif
