From 0318ffd7cc5995b0e8dfef0284d3d4964b8bdd18 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Mon, 15 Aug 2022 14:46:53 +0000 Subject: [PATCH] Fix hardware key type to u8 in input system --- src/input.cc | 17 ++++++++--------- src/input.h | 21 +++++++-------------- src/inputcec.cc | 10 +++++----- src/inputcec.h | 4 ++-- src/inputlinux.cc | 10 +++++----- src/inputlinux.h | 4 ++-- src/inputlirc.cc | 2 +- src/inputlirc.h | 4 ++-- src/inputudp.cc | 2 +- src/inputudp.h | 4 ++-- src/threadp.h | 2 +- 11 files changed, 36 insertions(+), 44 deletions(-) diff --git a/src/input.cc b/src/input.cc index cc42c9c..4f09e4f 100644 --- a/src/input.cc +++ b/src/input.cc @@ -35,7 +35,7 @@ void Input::ResetToDefault() InitHWCListwithDefaults(); } -u1 Input::TranslateHWC(HWC_TYPE code) +u1 Input::TranslateHWC(u8 code) { u1 ret = TranslateHWCFixed(code); @@ -48,7 +48,7 @@ u1 Input::TranslateHWC(HWC_TYPE code) return TranslateHWCList(code); } -u1 Input::TranslateHWCList(HWC_TYPE code) +u1 Input::TranslateHWCList(u8 code) { if (learnMode != NOLEARNMODE) { @@ -67,12 +67,12 @@ u1 Input::TranslateHWCList(HWC_TYPE code) } } -void Input::setHWCtoCommand(HWC_TYPE hcw, u1 command) +void Input::setHWCtoCommand(u8 hcw, u1 command) { translist[hcw] = command; } -void Input::unsetHWC(HWC_TYPE hcw) // FIXME never used +void Input::unsetHWC(u8 hcw) // FIXME never used { translist.erase(hcw); } @@ -80,16 +80,16 @@ void Input::unsetHWC(HWC_TYPE hcw) // FIXME never used void Input::LoadKeysConfig(VDR *vdr,const char *cfg) { u4 number=0; - if (sscanf(cfg,"%ld",&number) != 1) return; + if (sscanf(cfg,"%d",&number) != 1) return; LogNT::getInstance()->info(TAG, "Config Input/Remote keys num keys {}", number); char keybuf[1024]; for (u4 i = 0; i < number; i++) { - sprintf(keybuf, "RemoteKey%lu", i); + sprintf(keybuf, "RemoteKey%u", i); const char *keytrans = vdr->configLoad(modName(), keybuf); if (keytrans) { u4 ul1, ul2; u4 uc; - if (sscanf(keytrans, "%lXI%lXK%lX", &ul1, &ul2, &uc) == 3) { + if (sscanf(keytrans, "%XI%XK%X", &ul1, &ul2, &uc) == 3) { translist[((u8) ul1) | ((u8) ul2) << 32] = (u1) uc; } delete[] keytrans; @@ -109,8 +109,7 @@ void Input::SaveKeysConfig() RemoteTranslationList::const_iterator it; for (it = translist.begin(); it != translist.end(); it++) { - sprintf(buffer,"%08lXI%08lXK%02X", - (u4)it->first ,(u4) (it->first >> 32), it->second); + sprintf(buffer,"%08XI%08XK%02X", (u4)it->first, (u4)(it->first >> 32), it->second); sprintf(keybuf,"RemoteKey%d",number); VDR::getInstance()->configSave(modName(), keybuf, buffer); number++; diff --git a/src/input.h b/src/input.h index a6e38ef..fcb0b68 100644 --- a/src/input.h +++ b/src/input.h @@ -26,16 +26,9 @@ #include "defines.h" #include "abstractoption.h" -#ifdef WIN32 -#define HWC_TYPE u8 -#else -#define HWC_TYPE int -#endif - - class VDR; -typedef std::map RemoteTranslationList; +typedef std::map RemoteTranslationList; class Input: public AbstractOption { @@ -51,8 +44,8 @@ class Input: public AbstractOption static void sendInputKey(int key); - void setHWCtoCommand(HWC_TYPE hcw, u1 command); - void unsetHWC(HWC_TYPE hcw); + void setHWCtoCommand(u8 hcw, u1 command); + void unsetHWC(u8 hcw); void LoadKeysConfig(VDR* vdr, const char* keynum); void SaveKeysConfig(); @@ -71,7 +64,7 @@ class Input: public AbstractOption void EnterLearnMode(u1 /* command */ ) {}; // Override and set lernMode to command void cancelLearnMode() { learnMode = NOLEARNMODE; } void ResetToDefault(); - virtual std::string getHardwareKeyName(HWC_TYPE hardwareKey) = 0; + virtual std::string getHardwareKeyName(u8 hardwareKey) = 0; const static u4 NOLEARNMODE = 256; @@ -145,9 +138,9 @@ class Input: public AbstractOption RemoteTranslationList translist; int learnMode{NOLEARNMODE}; - virtual u1 TranslateHWCFixed(HWC_TYPE code) = 0; - u1 TranslateHWCList(HWC_TYPE code); - u1 TranslateHWC(HWC_TYPE code); + virtual u1 TranslateHWCFixed(u8 code) = 0; + u1 TranslateHWCList(u8 code); + u1 TranslateHWC(u8 code); }; #endif diff --git a/src/inputcec.cc b/src/inputcec.cc index c2bfcaf..00cf2dd 100644 --- a/src/inputcec.cc +++ b/src/inputcec.cc @@ -332,7 +332,7 @@ void InputCEC::InitHWCListwithDefaults() translist[CEC_USER_CONTROL_CODE_CHANNEL_DOWN] = CHANNELDOWN; } -u1 InputCEC::TranslateHWCFixed(int code) +u1 InputCEC::TranslateHWCFixed(u8 code) { switch (code) { @@ -453,12 +453,12 @@ const char* InputCEC::getHardCodedHardwareKeyNamesForVompKey(u1 /* vompKey */) return ""; // FIXME } -std::string InputCEC::getHardwareKeyName(int hardwareKey) +std::string InputCEC::getHardwareKeyName(u8 hardwareKey) { - const char* desc = cec_keymap[hardwareKey]; - std::string retval; + if (hardwareKey > CEC_USER_CONTROL_CODE_MAX) return retval; + const char* desc = cec_keymap[hardwareKey]; if (desc) { retval = desc; @@ -466,7 +466,7 @@ std::string InputCEC::getHardwareKeyName(int hardwareKey) else { char* rt = new char[10]; - sprintf(rt, "0x%x", hardwareKey); + sprintf(rt, "0x%llx", hardwareKey); retval = rt; } diff --git a/src/inputcec.h b/src/inputcec.h index fbf750d..434049c 100644 --- a/src/inputcec.h +++ b/src/inputcec.h @@ -41,7 +41,7 @@ class InputCEC : public Input bool addOptionsToPanes(int panenumber,Options *options,WOptionPane* pane); bool handleOptionChanges(Option* option); - std::string getHardwareKeyName(int hardwareKey); + std::string getHardwareKeyName(u8 hardwareKey); const char* getHardCodedHardwareKeyNamesForVompKey(u1 vompKey); private: @@ -49,7 +49,7 @@ class InputCEC : public Input const char* modName() { return myModName; } void InitKeymap(); void InitHWCListwithDefaults(); - u1 TranslateHWCFixed(int code); + u1 TranslateHWCFixed(u8 code); bool cechandlesvolume{}; diff --git a/src/inputlinux.cc b/src/inputlinux.cc index af13055..48af605 100644 --- a/src/inputlinux.cc +++ b/src/inputlinux.cc @@ -106,7 +106,7 @@ void InputLinux::shutdown() initted = 0; } -u1 InputLinux::TranslateHWCFixed(int code) +u1 InputLinux::TranslateHWCFixed(u8 code) { // Translate /dev/input codes to VOMP codes for the hard coded buttons switch (code) @@ -490,12 +490,12 @@ const char* InputLinux::getHardCodedHardwareKeyNamesForVompKey(u1 vompKey) } } -std::string InputLinux::getHardwareKeyName(int hardwareKey) +std::string InputLinux::getHardwareKeyName(u8 hardwareKey) { - const char* desc = linux_keymap[hardwareKey]; - std::string retval; + if (hardwareKey > KEY_MAX) return retval; + const char* desc = linux_keymap[hardwareKey]; if (desc) { retval = desc; @@ -503,7 +503,7 @@ std::string InputLinux::getHardwareKeyName(int hardwareKey) else { char* rt = new char[10]; - sprintf(rt, "0x%x", hardwareKey); + sprintf(rt, "0x%llx", hardwareKey); retval = rt; } diff --git a/src/inputlinux.h b/src/inputlinux.h index e4a30b0..1b98a5c 100644 --- a/src/inputlinux.h +++ b/src/inputlinux.h @@ -34,7 +34,7 @@ class InputLinux : public Input bool init(); void shutdown(); - std::string getHardwareKeyName(int hardwareKey); + std::string getHardwareKeyName(u8 hardwareKey); const char* getHardCodedHardwareKeyNamesForVompKey(u1 vompKey); void EnterLearningMode(u1 vompKey); @@ -49,7 +49,7 @@ class InputLinux : public Input void InitKeymap(); void InitHWCListwithDefaults(); - u1 TranslateHWCFixed(int code); + u1 TranslateHWCFixed(u8 code); std::vector devices; diff --git a/src/inputlirc.cc b/src/inputlirc.cc index 4acad37..70bd526 100644 --- a/src/inputlirc.cc +++ b/src/inputlirc.cc @@ -239,7 +239,7 @@ bool InputLIRC::parse(const std::string& input, std::string& remoteName, std::st // return ""; // } -std::string InputLIRC::getHardwareKeyName(HWC_TYPE /* hardwareKey */) +std::string InputLIRC::getHardwareKeyName(u8 /* hardwareKey */) { std::string retval; return retval; diff --git a/src/inputlirc.h b/src/inputlirc.h index 679eccd..44a9793 100644 --- a/src/inputlirc.h +++ b/src/inputlirc.h @@ -42,7 +42,7 @@ class InputLIRC : public Input void stop(); void InitHWCListwithDefaults() {}; - std::string getHardwareKeyName(HWC_TYPE hardwareKey); + std::string getHardwareKeyName(u8 hardwareKey); private: LogNT* log{}; @@ -56,7 +56,7 @@ class InputLIRC : public Input bool threadReqStop{}; bool parse(const std::string& input, std::string& remoteName, std::string& remoteButton, int& repeatCount); - u1 TranslateHWCFixed(HWC_TYPE code) { return static_cast(code); }; + u1 TranslateHWCFixed(u8 code) { return static_cast(code); }; bool initted{}; TCP tcp; diff --git a/src/inputudp.cc b/src/inputudp.cc index dcde094..289c7a0 100644 --- a/src/inputudp.cc +++ b/src/inputudp.cc @@ -164,7 +164,7 @@ const char* InputUDP::getHardCodedHardwareKeyNamesForVompKey(u1 /* vompKey */) return ""; } -std::string InputUDP::getHardwareKeyName(HWC_TYPE /* hardwareKey */) +std::string InputUDP::getHardwareKeyName(u8 /* hardwareKey */) { std::string retval; return retval; diff --git a/src/inputudp.h b/src/inputudp.h index 911f3c7..2d5682e 100644 --- a/src/inputudp.h +++ b/src/inputudp.h @@ -45,9 +45,9 @@ class InputUDP : public Input // InputUDP doesn't do any translation stuff so just keep everything happy here void InitHWCListwithDefaults() {}; - u1 TranslateHWCFixed(HWC_TYPE code) { return static_cast(code); }; + u1 TranslateHWCFixed(u8 code) { return static_cast(code); }; const char* getHardCodedHardwareKeyNamesForVompKey(u1 vompKey); - std::string getHardwareKeyName(HWC_TYPE hardwareKey); + std::string getHardwareKeyName(u8 hardwareKey); private: static const char* myModName; diff --git a/src/threadp.h b/src/threadp.h index db68e5c..5519f4f 100644 --- a/src/threadp.h +++ b/src/threadp.h @@ -61,7 +61,7 @@ class ThreadP : public Thread static pthread_t thisThreadID(); // Self identification - returns ID of calling thread - static void threadSuicide(); // Self termination + [[ noreturn ]] static void threadSuicide(); // Self termination }; #endif -- 2.39.5