
/**
 *
 * @file gp2x_wiz_canoo.cpp
 *
 * Part of the OpenJazz project
 *
 * @par Licence:
 * Copyright (c) 2015-2026 Carsten Teibes
 *
 * OpenJazz is distributed under the terms of
 * the GNU General Public License, version 2.0
 *
 */


#include "gp2x_wiz_canoo.h"

#if defined(WIZ) || defined(GP2X)

#include <cstdio>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#include <fcntl.h>
#include <unistd.h>

#include "io/sound.h"

void WizPlatform::AdjustVolume(int direction) {
	if(direction != VOLUME_NOCHG) {
		if(volume <= 10) {
			if(direction == VOLUME_UP)   volume += VOLUME_CHANGE_RATE/2;
			if(direction == VOLUME_DOWN) volume -= VOLUME_CHANGE_RATE/2;
		} else {
			if(direction == VOLUME_UP)   volume += VOLUME_CHANGE_RATE;
			if(direction == VOLUME_DOWN) volume -= VOLUME_CHANGE_RATE;
		}

		if(volume < VOLUME_MIN) volume = VOLUME_MIN;
		if(volume > VOLUME_MAX) volume = VOLUME_MAX;

		printf( "Volume Change: %i\n", volume );
	}

	unsigned long soundDev = open("/dev/mixer", O_RDWR);
	if(soundDev) {
		int vol = ((volume << 8) | volume);
		ioctl(soundDev, SOUND_MIXER_WRITE_PCM, &vol);
		close(soundDev);
	}
}

#endif
