/*
 * 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 Macro 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 Macro Public License for more details.
 *
 * You should have received a copy of the GNU Macro Public License
 * along with roccat-tools. If not, see <http://www.gnu.org/licenses/>.
 */

#include "roccat/ryos.h"
#include "roccat_helper.h"

static gchar const * const custom_lights_name = "custom_lights";

static guint16 ryos_custom_lights_calc_checksum(RyosCustomLights const *custom_lights) {
	return ROCCAT_BYTESUM_PARTIALLY(custom_lights, RyosCustomLights, command, checksum);
}

static void ryos_custom_lights_set_checksum(RyosCustomLights *custom_lights, guint16 new_value) {
	custom_lights->checksum = GUINT16_TO_LE(new_value);
}

static void ryos_custom_lights_finalize(RyosCustomLights *custom_lights) {
	custom_lights->command = RYOS_COMMAND_CUSTOM_LIGHTS;
	custom_lights->size = sizeof(RyosCustomLights);
	ryos_custom_lights_set_checksum(custom_lights, ryos_custom_lights_calc_checksum(custom_lights));
}

gboolean ryos_custom_lights_write(RoccatDevice *ryos, RyosCustomLights *custom_lights, GError **error) {
	ryos_custom_lights_finalize(custom_lights);
	return roccat_device_write(ryos, custom_lights_name, (gchar const *)custom_lights, sizeof(RyosCustomLights), error);
}

gboolean ryos_custom_lights_empty(RyosCustomLights const *custom_lights) {
	guint i;
	for (i = 0; i < 15; ++i)
		if (custom_lights->data[i])
			return FALSE;
	return TRUE;
}
