⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lakeysetting.cpp

📁 Lakey这是一个免费的CW练习/收/发软件
💻 CPP
字号:
#include "StdAfx.h"
#include "lakeysetting.h"

#include "stdio.h"

#define SetMorseCode(s, asc, mc, mm, kc)	\
	s.nAscCode = (asc); s.nMorseCode = (mc); s.nMask = (mm); s.nKeyCode = (kc);

#define SetButtonMapping(s, nx, ny, nw, nh, kc, txt)	\
	s.x = (nx); s.y = (ny); s.w = (nw); s.h = (nh); s.nKeyCode = (kc); strncpy(s.vLabel, (txt), sizeof(s.vLabel) - 1);

CLakeySetting::CLakeySetting(void)
{
	m_rBeepFreq = 1000.0;
	m_rBeepVol = 0.25;
	m_nShortHit = 75;
	m_nLongHit = 300;
	m_nHitDelay = 75;
	m_nLetterDelay = 300;
	m_nWordDelay = 300;

	SetRect(&m_oWindowRect, 0, 0, 360, 480);

	m_nSendJournalPeriod = 33;
	SetRect(&m_oSendJournalRect, 5, 160, 348, 192);
	m_nSendIdleLimit = 750;
	SetRect(&m_oSendCharQueueRect, 5, 192, 348, 203);

	m_nRecvJournalPeriod = 33;
	SetRect(&m_oRecvJournalRect, 5, 64, 348, 96);
	m_nRecvIdleLimit = 750;
	SetRect(&m_oRecvMonitorRect, 50, 10, 306, 58);
	m_nRecvAnalyzeSamples = 256;
	m_rRecvThreshold = 0.3l;
	m_nRecvFreqStart = 850;
	m_nRecvFreqEnd = 1250;

	SetButtonMapping(m_oCwKeyButton, 280, 220, 64, 64, VK_RETURN, "CW");
	SetButtonMapping(m_oSendPauseButton, 50, 104, 50, 12, VK_F5, "Pause");
	SetButtonMapping(m_oSendFileButton, 108, 104, 50, 12, VK_F6, "File...");

	SetMorseCode(m_vMorseCode[0], 'A', 0x0002, 0x0003, 'A');
	SetMorseCode(m_vMorseCode[1], 'B', 0x0007, 0x000f, 'B');
	SetMorseCode(m_vMorseCode[2], 'C', 0x0005, 0x000f, 'C');
	SetMorseCode(m_vMorseCode[3], 'D', 0x0003, 0x0007, 'D');
	SetMorseCode(m_vMorseCode[4], 'E', 0x0001, 0x0001, 'E');
	SetMorseCode(m_vMorseCode[5], 'F', 0x000d, 0x000f, 'F');
	SetMorseCode(m_vMorseCode[6], 'G', 0x0001, 0x0007, 'G');
	SetMorseCode(m_vMorseCode[7], 'H', 0x000f, 0x000f, 'H');
	SetMorseCode(m_vMorseCode[8], 'I', 0x0003, 0x0003, 'I');
	SetMorseCode(m_vMorseCode[9], 'J', 0x0008, 0x000f, 'J');
	SetMorseCode(m_vMorseCode[10], 'K', 0x0002, 0x0007, 'K');
	SetMorseCode(m_vMorseCode[11], 'L', 0x000b, 0x000f, 'L');
	SetMorseCode(m_vMorseCode[12], 'M', 0x0000, 0x0003, 'M');
	SetMorseCode(m_vMorseCode[13], 'N', 0x0001, 0x0003, 'N');
	SetMorseCode(m_vMorseCode[14], 'O', 0x0000, 0x0007, 'O');
	SetMorseCode(m_vMorseCode[15], 'P', 0x0009, 0x000f, 'P');
	SetMorseCode(m_vMorseCode[16], 'Q', 0x0002, 0x000f, 'Q');
	SetMorseCode(m_vMorseCode[17], 'R', 0x0005, 0x0007, 'R');
	SetMorseCode(m_vMorseCode[18], 'S', 0x0007, 0x0007, 'S');
	SetMorseCode(m_vMorseCode[19], 'T', 0x0000, 0x0001, 'T');
	SetMorseCode(m_vMorseCode[20], 'U', 0x0006, 0x0007, 'U');
	SetMorseCode(m_vMorseCode[21], 'V', 0x000e, 0x000f, 'V');
	SetMorseCode(m_vMorseCode[22], 'W', 0x0004, 0x0007, 'W');
	SetMorseCode(m_vMorseCode[23], 'X', 0x0006, 0x000f, 'X');
	SetMorseCode(m_vMorseCode[24], 'Y', 0x0004, 0x000f, 'Y');
	SetMorseCode(m_vMorseCode[25], 'Z', 0x0003, 0x000f, 'Z');

	SetMorseCode(m_vMorseCode[26], '1', 0x0010, 0x001f, '1');
	SetMorseCode(m_vMorseCode[27], '2', 0x0018, 0x001f, '2');
	SetMorseCode(m_vMorseCode[28], '3', 0x001c, 0x001f, '3');
	SetMorseCode(m_vMorseCode[29], '4', 0x001e, 0x001f, '4');
	SetMorseCode(m_vMorseCode[30], '5', 0x001f, 0x001f, '5');
	SetMorseCode(m_vMorseCode[31], '6', 0x000f, 0x001f, '6');
	SetMorseCode(m_vMorseCode[32], '7', 0x0007, 0x001f, '7');
	SetMorseCode(m_vMorseCode[33], '8', 0x0003, 0x001f, '8');
	SetMorseCode(m_vMorseCode[34], '9', 0x0001, 0x001f, '9');
	SetMorseCode(m_vMorseCode[35], '0', 0x0000, 0x001f, '0');

	SetMorseCode(m_vMorseCode[36], '?', 0x0033, 0x003f, 0);
	SetMorseCode(m_vMorseCode[37], '/', 0x000d, 0x003f, VK_DIVIDE);
	SetMorseCode(m_vMorseCode[38], '(', 0x0012, 0x003f, 0);
	SetMorseCode(m_vMorseCode[39], ')', 0x0012, 0x003f, 0);
	SetMorseCode(m_vMorseCode[40], '-', 0x000e, 0x003f, VK_SUBTRACT);
	SetMorseCode(m_vMorseCode[41], '.', 0x002a, 0x003f, VK_DECIMAL);
	SetMorseCode(m_vMorseCode[42], '_', 0x0000, 0x0000, ' ');

	m_nKochWordLen = 5;

	Load();
}

CLakeySetting::~CLakeySetting(void)
{
	Save();
}

void CLakeySetting::StrToMorseCode(int nIdx, const char* pStr)
{
	sscanf(pStr, "%8X,%8X,%4X"
		, &(m_vMorseCode[nIdx].nMorseCode)
		, &(m_vMorseCode[nIdx].nMask)
		, &(m_vMorseCode[nIdx].nKeyCode));
}

char* CLakeySetting::MorseCodeToStr(char* pStr, int nIdx)
{
	sprintf(pStr, "%8.8X,%8.8X,%4.4X"
		, m_vMorseCode[nIdx].nMorseCode
		, m_vMorseCode[nIdx].nMask
		, m_vMorseCode[nIdx].nKeyCode);

	return pStr;
}

void CLakeySetting::StrToButtonMapping(BUTTONMAPPING* pMapping, const char* pStr)
{
	sscanf(pStr, "%d,%d,%d,%d,%4X,%s"
		, &(pMapping->x)
		, &(pMapping->y)
		, &(pMapping->w)
		, &(pMapping->h)
		, &(pMapping->nKeyCode)
		, pMapping->vLabel);
}

char* CLakeySetting::ButtonMappingToStr(char* pStr, const BUTTONMAPPING* pMapping)
{
	sprintf(pStr, "%d,%d,%d,%d,%4.4X,%s"
		, pMapping->x
		, pMapping->y
		, pMapping->w
		, pMapping->h
		, pMapping->nKeyCode
		, pMapping->vLabel);

	return pStr;
}

#define PROFILE_PATHNAME	"./lakey.ini"
#define SECTION_CW			"CW"
#define CW_BEEPFREQ			"beepfreq"
#define CW_BEEPVOL			"beepvol"
#define CW_SHORTHIT			"shorthit"
#define CW_LONGHIT			"longhit"
#define CW_HITDELAY			"hitdelay"
#define CW_LETTERDELAY		"letterdelay"
#define CW_WORDDELAY		"worddelay"

#define SECTION_GLOBAL			"GLOBAL"
#define GLOBAL_WINDOWRECT		"windowrect"

#define SECTION_JOURNAL			"JOURNAL"
#define JOURNAL_SENDPERIOD		"sendperiod"
#define JOURNAL_SENDIDLELIMIT	"sendidlelimit"
#define JOURNAL_SENDRECT		"sendrect"
#define JOURNAL_SENDQUEUERECT	"sendqueuerect"

#define JOURNAL_RECVPERIOD		"recvperiod"
#define JOURNAL_RECVIDLELIMIT	"recvidlelimit"
#define JOURNAL_RECVRECT		"recvrect"
#define JOURNAL_RECVMRECT		"recvmrect"
#define JOURNAL_RECVANALYZESAMPLE	"recvanalyzesamples"
#define JOURNAL_RECVTHRESHOLD	"recvthreshold"
#define JOURNAL_RECVFREQSTART	"recvfreqstart"
#define JOURNAL_RECVFREQEND		"recvfreqend"

#define SECTION_MORSE		"MORSE"

#define SECTION_MAINPANEL	"MAINPANEL"
#define MAINPANEL_CW		"cw"
#define MAINPANEL_SENDPAUSE	"sendpause"
#define MAINPANEL_SENDFILE	"sendfile"

#define SECTION_KOCH		"KOCH"
#define KOCH_CHARS			"charlist"
#define KOCH_WORDLEN		"koch_wordlen"

BOOL CLakeySetting::Load()
{
	m_rBeepFreq = GetProfileDouble(SECTION_CW, CW_BEEPFREQ, m_rBeepFreq);
	m_rBeepVol = GetProfileDouble(SECTION_CW, CW_BEEPVOL, m_rBeepVol);
	m_nShortHit = GetProfileDec(SECTION_CW, CW_SHORTHIT, m_nShortHit);
	m_nLongHit = GetProfileDec(SECTION_CW, CW_LONGHIT, m_nLongHit);
	m_nHitDelay = GetProfileDec(SECTION_CW, CW_HITDELAY, m_nHitDelay);
	m_nLetterDelay = GetProfileDec(SECTION_CW, CW_LETTERDELAY, m_nLetterDelay);
	m_nWordDelay = GetProfileDec(SECTION_CW, CW_WORDDELAY, m_nWordDelay);

	GetProfileRect(SECTION_GLOBAL, GLOBAL_WINDOWRECT, &m_oWindowRect);

	m_nSendJournalPeriod = GetProfileDec(SECTION_JOURNAL, JOURNAL_SENDPERIOD, m_nSendJournalPeriod);
	m_nSendIdleLimit = GetProfileDec(SECTION_JOURNAL, JOURNAL_SENDIDLELIMIT, m_nSendIdleLimit);
	GetProfileRect(SECTION_JOURNAL, JOURNAL_SENDRECT, &m_oSendJournalRect);
	GetProfileRect(SECTION_JOURNAL, JOURNAL_SENDQUEUERECT, &m_oSendCharQueueRect);

	m_nRecvJournalPeriod = GetProfileDec(SECTION_JOURNAL, JOURNAL_RECVPERIOD, m_nRecvJournalPeriod);
	m_nRecvIdleLimit = GetProfileDec(SECTION_JOURNAL, JOURNAL_RECVIDLELIMIT, m_nRecvIdleLimit);
	GetProfileRect(SECTION_JOURNAL, JOURNAL_RECVRECT, &m_oRecvJournalRect);
	GetProfileRect(SECTION_JOURNAL, JOURNAL_RECVMRECT, &m_oRecvMonitorRect);
	m_nRecvAnalyzeSamples = GetProfileDec(SECTION_JOURNAL, JOURNAL_RECVANALYZESAMPLE, m_nRecvAnalyzeSamples);
	m_rRecvThreshold = GetProfileDouble(SECTION_JOURNAL, JOURNAL_RECVTHRESHOLD, m_rRecvThreshold);
	m_nRecvFreqStart = GetProfileDec(SECTION_JOURNAL, JOURNAL_RECVFREQSTART, m_nRecvFreqStart);
	m_nRecvFreqEnd = GetProfileDec(SECTION_JOURNAL, JOURNAL_RECVFREQEND, m_nRecvFreqEnd);

	GetButtonMapping(SECTION_MAINPANEL, MAINPANEL_CW, &m_oCwKeyButton);
	GetButtonMapping(SECTION_MAINPANEL, MAINPANEL_SENDPAUSE, &m_oSendPauseButton);
	GetButtonMapping(SECTION_MAINPANEL, MAINPANEL_SENDFILE, &m_oSendFileButton);

	GetPrivateProfileString(SECTION_KOCH, KOCH_CHARS, "", m_vKochChar, sizeof(m_vKochChar), PROFILE_PATHNAME);
	m_nKochWordLen = GetProfileDec(SECTION_KOCH, KOCH_WORDLEN, m_nKochWordLen);

	for (int i = 0; i < MORSECODECOUNT; ++i)
	{
		char vMorseKey[2] = {' ', '\0'};
		char vBuff[64];
		vMorseKey[0] = (char)m_vMorseCode[i].nAscCode;
		GetPrivateProfileString(SECTION_MORSE, vMorseKey, "", vBuff, sizeof(vBuff), PROFILE_PATHNAME);
		if (strlen(vBuff))
			StrToMorseCode(i, vBuff);
	}

	return TRUE;
}

BOOL CLakeySetting::Save()
{
	WriteProfileDouble(SECTION_CW, CW_BEEPFREQ, m_rBeepFreq);
	WriteProfileDouble(SECTION_CW, CW_BEEPVOL, m_rBeepVol);
	WriteProfileDec(SECTION_CW, CW_SHORTHIT, m_nShortHit);
	WriteProfileDec(SECTION_CW, CW_LONGHIT, m_nLongHit);
	WriteProfileDec(SECTION_CW, CW_HITDELAY, m_nHitDelay);
	WriteProfileDec(SECTION_CW, CW_LETTERDELAY, m_nLetterDelay);
	WriteProfileDec(SECTION_CW, CW_WORDDELAY, m_nWordDelay);

	WriteProfileRect(SECTION_GLOBAL, GLOBAL_WINDOWRECT, &m_oWindowRect);

	WriteProfileDec(SECTION_JOURNAL, JOURNAL_SENDPERIOD, m_nSendJournalPeriod);
	WriteProfileDec(SECTION_JOURNAL, JOURNAL_SENDIDLELIMIT, m_nSendIdleLimit);
	WriteProfileRect(SECTION_JOURNAL, JOURNAL_SENDRECT, &m_oSendJournalRect);
	WriteProfileRect(SECTION_JOURNAL, JOURNAL_SENDQUEUERECT, &m_oSendCharQueueRect);

	WriteProfileDec(SECTION_JOURNAL, JOURNAL_RECVPERIOD, m_nRecvJournalPeriod);
	WriteProfileDec(SECTION_JOURNAL, JOURNAL_RECVIDLELIMIT, m_nRecvIdleLimit);
	WriteProfileRect(SECTION_JOURNAL, JOURNAL_RECVRECT, &m_oRecvJournalRect);
	WriteProfileRect(SECTION_JOURNAL, JOURNAL_RECVMRECT, &m_oRecvMonitorRect);
	WriteProfileDec(SECTION_JOURNAL, JOURNAL_RECVANALYZESAMPLE, m_nRecvAnalyzeSamples);
	WriteProfileDouble(SECTION_JOURNAL, JOURNAL_RECVTHRESHOLD, m_rRecvThreshold);
	WriteProfileDec(SECTION_JOURNAL, JOURNAL_RECVFREQSTART, m_nRecvFreqStart);
	WriteProfileDec(SECTION_JOURNAL, JOURNAL_RECVFREQEND, m_nRecvFreqEnd);

	WriteButtonMapping(SECTION_MAINPANEL, MAINPANEL_CW, &m_oCwKeyButton);
	WriteButtonMapping(SECTION_MAINPANEL, MAINPANEL_SENDPAUSE, &m_oSendPauseButton);
	WriteButtonMapping(SECTION_MAINPANEL, MAINPANEL_SENDFILE, &m_oSendFileButton);

	WritePrivateProfileString(SECTION_KOCH, KOCH_CHARS, m_vKochChar, PROFILE_PATHNAME);
	WriteProfileDec(SECTION_KOCH, KOCH_WORDLEN, m_nKochWordLen);

	for (int i = 0; i < MORSECODECOUNT; ++i)
	{
		char vMorseKey[2] = {' ', '\0'};
		char vBuff[64];
		vMorseKey[0] = (char)m_vMorseCode[i].nAscCode;
		WritePrivateProfileString(SECTION_MORSE, vMorseKey, MorseCodeToStr(vBuff, i), PROFILE_PATHNAME);
	}

	return TRUE;
}

int CLakeySetting::GetProfileHex(const char* pSec, const char* pKey, int nDefault)
{
	char vBuff[32];
	GetPrivateProfileString(pSec, pKey, "", vBuff, sizeof(vBuff), PROFILE_PATHNAME);
	if (strlen(vBuff))
		sscanf(vBuff, "%8X", &nDefault);

	return nDefault;
}

void CLakeySetting::WriteProfileHex(const char* pSec, const char* pKey, int n)
{
	char vBuff[32];
	sprintf(vBuff, "%8.8X", n);

	WritePrivateProfileString(pSec, pKey, vBuff, PROFILE_PATHNAME);
}

int CLakeySetting::GetProfileDec(const char* pSec, const char* pKey, int nDefault)
{
	char vBuff[32];
	GetPrivateProfileString(pSec, pKey, "", vBuff, sizeof(vBuff), PROFILE_PATHNAME);
	if (strlen(vBuff))
		sscanf(vBuff, "%d", &nDefault);

	return nDefault;
}

void CLakeySetting::WriteProfileDec(const char* pSec, const char* pKey, int n)
{
	char vBuff[32];
	sprintf(vBuff, "%d", n);

	WritePrivateProfileString(pSec, pKey, vBuff, PROFILE_PATHNAME);
}

double CLakeySetting::GetProfileDouble(const char* pSec, const char* pKey, double rDefault)
{
	char vBuff[32];
	GetPrivateProfileString(pSec, pKey, "", vBuff, sizeof(vBuff), PROFILE_PATHNAME);
	if (strlen(vBuff))
		sscanf(vBuff, "%lf", &rDefault);

	return rDefault;
}

void CLakeySetting::WriteProfileDouble(const char* pSec, const char* pKey, double r)
{
	char vBuff[32];
	sprintf(vBuff, "%lf", r);

	WritePrivateProfileString(pSec, pKey, vBuff, PROFILE_PATHNAME);
}

void CLakeySetting::GetButtonMapping(const char* pSec, const char* pKey, BUTTONMAPPING* pBtMap)
{
	char vBuff[64];
	GetPrivateProfileString(pSec, pKey, "", vBuff, sizeof(vBuff), PROFILE_PATHNAME);
	if (strlen(vBuff))
		StrToButtonMapping(pBtMap, vBuff);
}

void CLakeySetting::WriteButtonMapping(const char* pSec, const char* pKey, const BUTTONMAPPING* pBtMap)
{
	char vBuff[64];
	WritePrivateProfileString(pSec, pKey, ButtonMappingToStr(vBuff, pBtMap), PROFILE_PATHNAME);
}

void CLakeySetting::GetProfileRect(const char* pSec, const char* pKey, RECT* pRect)
{
	char vBuff[64];
	GetPrivateProfileString(pSec, pKey, "", vBuff, sizeof(vBuff), PROFILE_PATHNAME);
	if (strlen(vBuff))
		sscanf(vBuff, "%d,%d,%d,%d", &pRect->left, &pRect->top, &pRect->right, &pRect->bottom);
}

void CLakeySetting::WriteProfileRect(const char* pSec, const char* pKey, const RECT* pRect)
{
	char vBuff[64];
	sprintf(vBuff, "%d,%d,%d,%d", pRect->left, pRect->top, pRect->right, pRect->bottom);
	WritePrivateProfileString(pSec, pKey, vBuff, PROFILE_PATHNAME);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -