#include "IrFoxAnalyzerSettings.h"
#include <AnalyzerHelpers.h>

IrFoxAnalyzerSettings::IrFoxAnalyzerSettings()
	: mInputChannel(UNDEFINED_CHANNEL),
	  mInputChannelInterface()
{
	mInputChannelInterface.SetTitleAndTooltip(
		"IR",
		"Demodulated IR receiver output (e.g. TSOP: idle HIGH, active LOW)");
	mInputChannelInterface.SetChannel(mInputChannel);

	AddInterface(&mInputChannelInterface);

	AddExportOption(0, "Export as text/csv file");
	AddExportExtension(0, "text", "txt");
	AddExportExtension(0, "csv", "csv");

	ClearChannels();
	AddChannel(mInputChannel, "IR", false);
}

IrFoxAnalyzerSettings::~IrFoxAnalyzerSettings()
{
}

bool IrFoxAnalyzerSettings::SetSettingsFromInterfaces()
{
	mInputChannel = mInputChannelInterface.GetChannel();

	ClearChannels();
	AddChannel(mInputChannel, "IR Fox", true);

	return true;
}

void IrFoxAnalyzerSettings::UpdateInterfacesFromSettings()
{
	mInputChannelInterface.SetChannel(mInputChannel);
}

void IrFoxAnalyzerSettings::LoadSettings(const char* settings)
{
	SimpleArchive text_archive;
	text_archive.SetString(settings);

	text_archive >> mInputChannel;

	ClearChannels();
	AddChannel(mInputChannel, "IR Fox", true);

	UpdateInterfacesFromSettings();
}

const char* IrFoxAnalyzerSettings::SaveSettings()
{
	SimpleArchive text_archive;

	text_archive << mInputChannel;

	return SetReturnString(text_archive.GetString());
}
