#ifndef _ROCCAT_ORIG_MACRO_H_
#define _ROCCAT_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 "roccat/roccat.h"

/*
 * This header contains information about the macro format contained in Roccats
 * .dat files
 */

G_BEGIN_DECLS

#define ROCCAT_ORIGINAL_MACRO_MAIN_GROUP_NAME "SetMacro"
#define ROCCAT_ORIGINAL_MACRO_COUNT_NAME "number"

typedef struct _RoccatOriginalMacroKeystroke RoccatOriginalMacroKeystroke;
typedef struct _RoccatOriginalMacro RoccatOriginalMacro;

enum {
	ROCCAT_ORIGINAL_MACRO_SEQUENCE_KEYSTROKES_NUM = 500,
	ROCCAT_ORIGINAL_MACRO_SEQUENCE_NAME_LENGTH = 52,
};

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

typedef enum {
	ROCCAT_ORIGINAL_MACRO_KEYSTROKE_ACTION_PRESS = 1,
	ROCCAT_ORIGINAL_MACRO_KEYSTROKE_ACTION_RELEASE = 2,
} RoccatOriginalMacroKeystrokeAction;

struct _RoccatOriginalMacro {
	guint8 macro_name[ROCCAT_ORIGINAL_MACRO_SEQUENCE_NAME_LENGTH];
	guint32 loop;
	guint32 count;
	RoccatOriginalMacroKeystroke keystrokes[ROCCAT_ORIGINAL_MACRO_SEQUENCE_KEYSTROKES_NUM];
	guint8 checksum;
} __attribute__ ((packed));

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

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

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

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

static inline guint32 roccat_original_macro_get_loop(RoccatOriginalMacro const *macro) {
	return GUINT32_FROM_LE(macro->loop);
}

static inline void roccat_original_macro_set_loop(RoccatOriginalMacro *macro, guint32 new_value) {
	macro->loop = GUINT32_TO_LE(new_value);
}

G_END_DECLS

#endif

