PluginSettings( #ifdef FAR3 FARAPISETTINGSCONTROL settingsControl, const GUID &guid) { SettingsControl = settingsControl; handle = INVALID_HANDLE_VALUE; FarSettingsCreate settings = {sizeof settings,guid,handle}; if(SettingsControl(INVALID_HANDLE_VALUE,SCTL_CREATE,PSL_ROAMING,&settings)) handle = settings.Handle; #else bool bWrite) { extern TCHAR PluginRootKey[]; DWORD disp; if((bWrite ? RegCreateKeyEx(HKEY_CURRENT_USER, PluginRootKey, 0, 0, 0, KEY_WRITE|KEY_READ, 0, &hKey, &disp) : RegOpenKeyEx(HKEY_CURRENT_USER, PluginRootKey, 0, KEY_READ, &hKey)) !=ERROR_SUCCESS) hKey = 0; #endif } ~PluginSettings() { #ifdef FAR3 SettingsControl(handle,SCTL_FREE,0,0); #else for each(HKEY hk in subKeys) //for(HKEY hk : subKeys) after moving to a newer VC RegCloseKey(hk); subKeys.clear(); if(hKey) RegCloseKey(hKey); hKey = 0; #endif } KEY_TYPE CreateSubKey(PCWSTR Name, KEY_TYPE root = 0) { #ifdef FAR3 FarSettingsValue value = {sizeof value, root, Name}; return (KEY_TYPE)SettingsControl(handle,SCTL_CREATESUBKEY,0,&value); #else if(root == 0) root = hKey; HKEY hk; if(RegCreateKeyW(root, Name, &hk) != ERROR_SUCCESS) return 0; subKeys.push_back(hk); return hk; #endif }
vector<tstring> EnumKeys(KEY_TYPE root = 0) const { vector<tstring> keys; #ifdef FAR3 FarSettingsEnum fse = { sizeof fse, root }; if (SettingsControl(handle, SCTL_ENUM, 0, &fse)) { keys.reserve(fse.Count); for(size_t i = 0; i < fse.Count; i++) if (fse.Items[i].Type == FST_SUBKEY) keys.push_back(fse.Items[i].Name); } #else if(root == 0) root = hKey; DWORD cSubKeys, cMaxSubKeyLen; if(RegQueryInfoKey(root, 0, 0, 0, &cSubKeys,&cMaxSubKeyLen,0,0,0,0,0,0)==ERROR_SUCCESS) { keys.reserve(cSubKeys); vector<TCHAR> keyName(cMaxSubKeyLen + 1); for(DWORD iKey=0; iKey<cSubKeys; iKey++) { cMaxSubKeyLen = (DWORD)keyName.size(); if(RegEnumKeyEx(root, iKey, &keyName[0], &cMaxSubKeyLen, 0,0,0,0)!=ERROR_SUCCESS) break; keys.push_back(&keyName[0]); } } #endif return keys; }
/* SerialControl routine This routine allows changing the settings via the serial port. */ void SerialControl(void) { Uint8 Command; // See if new command available if (!RxAvail) return; // Grab it and kick of the next read Command = CmdRxBuf[0]; UART_Rx(CmdRxBuf, 1); // Process the command switch (Command) { case 't': // Test command ConfigDevices(); break; default: if (!SettingsControl(Command)) { UART_TxStr("?"); UART_TxNum(Command, 1); UART_TxStr("?\r\n"); } break; } }
unsigned __int64 Get(PCTSTR szName, unsigned __int64 Default, KEY_TYPE root = 0) const { #ifdef FAR3 FarSettingsItem item={sizeof item, root,szName,FST_QWORD}; return SettingsControl(handle, SCTL_GET, 0, &item) ? item.Number : Default; #else if(root == 0) root = hKey; unsigned __int64 val = 0; DWORD dwSize = sizeof val; return RegQueryValueEx(root, szName, 0, NULL, (PBYTE)&val, &dwSize) == ERROR_SUCCESS ? val : Default; #endif }
bool DeleteSubKey( #ifdef FAR3 KEY_TYPE root) { FarSettingsValue value = {sizeof value, root, NULL}; return SettingsControl(handle,SCTL_DELETE,0,&value) != 0; #else PCWSTR szName, KEY_TYPE root = 0) { if(root == 0) root = hKey; return RegDeleteKeyW(root, szName) == ERROR_SUCCESS; #endif } bool DeleteValue(PCTSTR szName, KEY_TYPE root = 0) { #ifdef FAR3 FarSettingsValue value = {sizeof value, root, szName}; return SettingsControl(handle,SCTL_DELETE,0,&value) != 0; #else if(root == 0) root = hKey; return RegDeleteValue(root, szName) == ERROR_SUCCESS; #endif }
KEY_TYPE OpenSubKey(PCTSTR szName, KEY_TYPE root = 0 #ifndef FAR3 , bool bWrite = false #endif ) { #ifdef FAR3 FarSettingsValue value = {sizeof value, root, szName}; return (KEY_TYPE)SettingsControl(handle,SCTL_OPENSUBKEY,0,&value); #else if(root == 0) root = hKey; HKEY hk; if(RegOpenKeyEx(root, szName, 0, bWrite ? KEY_WRITE|KEY_READ : KEY_READ, &hk) != ERROR_SUCCESS) return 0; subKeys.push_back(hk); return hk; #endif }
PTSTR Get(PCTSTR szName, PTSTR buf, DWORD cchSize, PCTSTR szDefault, KEY_TYPE root = 0) const { if(!szDefault) szDefault = _T(""); #ifdef FAR3 FarSettingsItem item = {sizeof item, root,szName,FST_STRING}; _tcsncpy(buf, SettingsControl(handle,SCTL_GET,0,&item) ? item.String : szDefault, cchSize); #else if(root == 0) root = hKey; DWORD dwSize = cchSize*sizeof(TCHAR); LONG res = RegQueryValueEx(root, szName, 0, NULL, (BYTE*)buf, &dwSize); if(res != ERROR_SUCCESS) _tcsncpy(buf, szDefault, cchSize); #endif return buf; }
tstring Get(PCTSTR szName, PCTSTR szDefault, KEY_TYPE root = 0) const { #ifdef FAR3 FarSettingsItem item = {sizeof item, root, szName, FST_STRING}; return SettingsControl(handle,SCTL_GET,0,&item) ? item.String : szDefault; #else if(root == 0) root = hKey; DWORD dwType, dwSize = 0; if(RegQueryValueEx(root, szName, 0, &dwType, NULL, &dwSize)!=ERROR_SUCCESS) return szDefault; tstring str; str.reserve(dwSize/sizeof(TCHAR)); str.resize(dwSize/sizeof(TCHAR)); if(RegQueryValueEx(root, szName, 0, &dwType, (BYTE*)str.c_str(), &dwSize)!=ERROR_SUCCESS) return szDefault; // remove trailing \0 str.resize((dwSize-1)/sizeof(TCHAR)); return str; #endif }
size_t Get(PCTSTR szName, void *buf, size_t size, KEY_TYPE root = 0) const { #ifdef FAR3 FarSettingsItem item={sizeof item, root,szName,FST_DATA}; if (SettingsControl(handle,SCTL_GET,0,&item)) { if(item.Data.Size < size) size = item.Data.Size; memcpy(buf, item.Data.Data, size); return size; } #else if(root == 0) root = hKey; DWORD dwSize = (DWORD)size; if(size > MAXDWORD) dwSize = MAXDWORD; if(RegQueryValueEx(root, szName, 0, NULL, (BYTE*)buf, &dwSize) == ERROR_SUCCESS) return dwSize; #endif return 0; }
/* SerialControl routine This routine allows changing the settings via the serial port. */ void SerialControl(void) { Uint8 Command; // See if new command available if (!RxAvail) return; // Grab it and kick of the next read Command = CmdRxBuf[0]; UART_Rx(CmdRxBuf, 1); // Process the command switch (Command) { case 't': // Test command MP3_Volume(250); UART_TxStr("MP3Ready "); UART_TxNum(MP3Ready, 1); UART_TxStr(", MP3Paused "); UART_TxNum(MP3Paused, 1); UART_TxNewLine(); break; default: if (!SettingsControl(Command)) { UART_TxStr("?"); UART_TxNum(Command, 1); UART_TxStr("?\r\n"); } break; } }
/* main routine Program entry point */ int main(void) { Uint8 TxBuf[BCMsgSize]; Uint8 RxBuf[BCMsgSize]; Uint8 Address; // Address of device in bay Uint8 Destination; // Address we will reply to Uint8 Param,Param2; MainInit(); UART_TxStr("\r\nPower up\r\n"); UART_Rx(RxData, 9); // Input register setting command Address = BCAOutput + ReadPosition(); BCMessageInit(Address); // Set up the UART BCMessageReceive(RxBuf); // Kick off receive // Enter the main loop for( ; ; ) { // Run forever DelayMS(LoopRate); SettingsControl(); if (BCRXAvail) { // We have a new message if ((RxBuf[BCPAddr] & 0b1111) == Address) { // Check it is for us Destination = RxBuf[BCPAddr] >> 4; // Pre-setup assuming we will reply Destination &= 0b1111; Destination |= Address << 4; TxBuf[BCPAddr] = Destination; DelayMS(2); // Allow line turn around delay switch (RxBuf[BCPType]) { case BCTInquire: // Master request of slave ID TxBuf[BCPType] = BCTInquireAnswer; TxBuf[BCPParam1] = ReadProductID(); TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf,true); // Send the reply BCMessageReceive(RxBuf); // Kick off receive of next frame break; case BCTVolume: // Volume set TxBuf[BCPType] = BCTAck; TxBuf[BCPParam1] = 0; TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf,true); // Send the reply Param = RxBuf[BCPParam1]; // Save parameter so we can receive next frame while processing this request BCMessageReceive(RxBuf); // Kick off receive of next frame // Timer_Clear(); Volume_Set(Param); // UART_TxStr("Volume_Set took "); // UART_TxNum(Timer_Read()); // UART_TxStr("mS\r\n"); break; case BCTHeadphoneChGain: // Volume set TxBuf[BCPType] = BCTAck; TxBuf[BCPParam1] = 0; TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf,true); // Send the reply Param = RxBuf[BCPParam1]; // Save parameter so we can receive next frame while processing this request Param2 = RxBuf[BCPParam2]; // Save parameter so we can receive next frame while processing this request BCMessageReceive(RxBuf); // Kick off receive of next frame // Timer_Clear(); SetChannelAdjust(Param,Param2); // UART_TxStr("Volume_Set took "); // UART_TxNum(Timer_Read()); // UART_TxStr("mS\r\n"); break; case BCTHeadphoneChMax: // Volume set TxBuf[BCPType] = BCTAck; TxBuf[BCPParam1] = 0; TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf,true); // Send the reply Param = RxBuf[BCPParam1]; // Save parameter so we can receive next frame while processing this request Param2 = RxBuf[BCPParam2]; // Save parameter so we can receive next frame while processing this request BCMessageReceive(RxBuf); // Kick off receive of next frame SetChMaxVolume(Param, Param2); break; case BCTAudioFormat: // Audio format set TxBuf[BCPType] = BCTAck; TxBuf[BCPParam1] = 0; TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf,true); // Send the reply Param = RxBuf[BCPParam1]; // Save parameter so we can receive next frame while processing this request BCMessageReceive(RxBuf); // Kick off receive of next frame // Timer_Clear(); WM8960_SetAudioFormat(Param); // UART_TxStr("WM8960_SetAudioFormat took "); // UART_TxNum(Timer_Read()); // UART_TxStr("mS\r\n"); break; default: // Unknown command TxBuf[BCPType] = BCTNAck; TxBuf[BCPParam1] = BCNUnkownType; TxBuf[BCPParam2] = RxBuf[BCPType]; BCMessageSend(TxBuf,true); // Send the reply BCMessageReceive(RxBuf); // Kick off receive of next frame break; } } } }
/* main routine Program entry point */ int main(void) { Uint8 TxBuf[BCMsgSize]; Uint8 RxBuf[BCMsgSize]; Uint8 Address; // Address of device in bay Uint8 Destination; // Address we will reply to Uint8 Param,Param2; Uint8 Volume = 0; Uint8 TempInt; #ifdef CTRL_LED Uint8 TempInt; Uint8 RceiveAddress; Uint8 i; i = 0; #endif MainInit(); UART_TxStr("\r\nPower up\r\n"); UART_Rx(RxData, 9); // Input register setting command Address = BCAOutput + ReadPosition(); BCMessageInit(Address); // Set up the UART BCMessageReceive(RxBuf); // Kick off receive if(ReadProductID()) // 1:pill 2:beats box 3:rave ChannelNumbers = 1; else ChannelNumbers = 5;//0:5 position headphone // Enter the main loop LED1_ON(); LED2_ON(); LED_GRAPHICAL_ON(); SetLamps(3); for( ; ; ) { // Run forever Timer_Clear(); DelayMS(LoopRate); TempInt++; SettingsControl(); if (BCRXAvail) { // We have a new message //send data #ifdef SecondUART #ifdef DumpComms UART_TxStr("Receive: "); for (TempInt = BCPSOH; TempInt <= BCPChecksum; TempInt++) { UART_TxUint8(RxBuf[TempInt]); UART_TxChar(' '); } UART_TxStr("\r\n"); #endif #endif if ((RxBuf[BCPAddr] & 0b1111) == Address) // Check it is for us { Destination = RxBuf[BCPAddr] >> 4; // Pre-setup assuming we will reply Destination &= 0b1111; Destination |= Address << 4; TxBuf[BCPAddr] = Destination; DelayMS(2); // Allow line turn around delay switch (RxBuf[BCPType]) { case BCTInquire: // Master request of slave ID TxBuf[BCPType] = BCTInquireAnswer; TxBuf[BCPParam1] = ReadProductID(); TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf,true); // Send the reply break; case BCTLamps: // Set lamps TxBuf[BCPType] = BCTAck; TxBuf[BCPParam1] = 0; TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf, true); // Send the reply Param = RxBuf[BCPParam1]; SetLamps(Param); break; case BCTVolume: // Volume set TxBuf[BCPType] = BCTAck; TxBuf[BCPParam1] = 0; TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf,true); // Send the reply Volume = RxBuf[BCPParam1]; // Save parameter so we can receive next frame while processing this request Param2 = RxBuf[BCPParam2]; // Save parameter so we can receive next frame while processing this request Volume_Set(Volume,Param2); break; case BCTHeadphoneChGain: // Volume set TxBuf[BCPType] = BCTAck; TxBuf[BCPParam1] = 0; TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf,true); // Send the reply Param = RxBuf[BCPParam1]; // Save parameter so we can receive next frame while processing this request Param2 = RxBuf[BCPParam2]; // Save parameter so we can receive next frame while processing this request SetChannelAdjust(Param,Param2); break; case BCTHeadphoneChMax: // Volume set TxBuf[BCPType] = BCTAck; TxBuf[BCPParam1] = 0; TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf,true); // Send the reply Param = RxBuf[BCPParam1]; // Save parameter so we can receive next frame while processing this request Param2 = RxBuf[BCPParam2]; // Save parameter so we can receive next frame while processing this request SetChMaxVolume(Param, Param2); break; case BCTAudioFormat: // Audio format set TxBuf[BCPType] = BCTAck; TxBuf[BCPParam1] = 0; TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf,true); // Send the reply Param = RxBuf[BCPParam1]; // Save parameter so we can receive next frame while processing this request WM8960_SetAudioFormat(Param); break; case BCTBrightness: // Set lamp brightness TxBuf[BCPType] = BCTAck; TxBuf[BCPParam1] = 0; TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf, true); // Send the reply Param = RxBuf[BCPParam1]; // Save parameter so we can receive next frame while processing this request Param2 = RxBuf[BCPParam2]; // Save parameter so we can receive next frame while processing this request if (Param == 1) LED1 = Param2; else if(Param == 2) LED2 = Param2; break; case BCTReset: // Volume set TxBuf[BCPType] = BCTAck; TxBuf[BCPParam1] = 0; TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf,true); // Send the reply Param = RxBuf[BCPParam1]; // Save parameter so we can receive next frame while processing this request BCMessageReceive(RxBuf); // Kick off receive of next frame asm("jmp 0x0000");//reset break; default: // Unknown command TxBuf[BCPType] = BCTNAck; TxBuf[BCPParam1] = BCNUnkownType; TxBuf[BCPParam2] = RxBuf[BCPType]; BCMessageSend(TxBuf,true); // Send the reply // BCMessageReceive(RxBuf); // Kick off receive of next frame break; } //this send command tv change to 031-517-209 board #if VideoTrackCtrl Uint8 VideoTrack; Uint8 SendVideoFlag; if(Volume > 47) { if(SendVideoFlag) { SendVideoFlag = false; if(Address == BCARightBay) { VideoTrack = 1; } else if(Address == BCALeftBay) { VideoTrack = 2; } TxBuf[BCPAddr] = Address << 4; TxBuf[BCPAddr] |= BDCLCD; TxBuf[BCPType] = BCTPlayTrack; TxBuf[BCPParam1] = VideoTrack; TxBuf[BCPParam2] = 0; BCMessageSend(TxBuf, true); // Send the reply } } else { SendVideoFlag = 1; } #endif } //this for ctrl LED it itself #ifdef CTRL_LED if(RxBuf[BCPType] == BCTVolume) { RceiveAddress = RxBuf[BCPAddr] & 0b1111; a_Volume[RceiveAddress-BCAOutput] = RxBuf[BCPParam1]; if((a_Volume[RceiveAddress-BCAOutput] > 47) && (LastVolume[RceiveAddress-BCAOutput] > 47))//have volume { if((RceiveAddress) == Address) { LED1_ON(); } else { LED1_OFF(); } } i = 0; for(TempInt = 0; TempInt < 4; ) //all volume off { if((a_Volume[TempInt] <= 47) && (LastVolume[TempInt] <= 47)) i++; TempInt++; } if(i >= TempInt) { LED1_ON(); } LastVolume[RceiveAddress-BCAOutput] = a_Volume[RceiveAddress-BCAOutput]; } #endif BCMessageReceive(RxBuf); // Kick off receive of next frame } }