2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "PeripheralHID.h"
22 #include "utils/log.h"
23 #include "guilib/LocalizeStrings.h"
24 #include "input/ButtonTranslator.h"
26 using namespace PERIPHERALS;
29 CPeripheralHID::CPeripheralHID(const PeripheralScanResult& scanResult) :
30 CPeripheral(scanResult)
32 m_strDeviceName = scanResult.m_strDeviceName.empty() ? g_localizeStrings.Get(35001) : scanResult.m_strDeviceName;
33 m_features.push_back(FEATURE_HID);
36 CPeripheralHID::~CPeripheralHID(void)
38 if (!m_strKeymap.empty() && !GetSettingBool("do_not_use_custom_keymap"))
40 CLog::Log(LOGDEBUG, "%s - switching active keymapping to: default", __FUNCTION__);
41 CButtonTranslator::GetInstance().RemoveDevice(m_strKeymap);
45 bool CPeripheralHID::InitialiseFeature(const PeripheralFeature feature)
47 if (feature == FEATURE_HID && !m_bInitialised)
49 m_bInitialised = true;
51 if (HasSetting("keymap"))
52 m_strKeymap = GetSettingString("keymap");
54 if (m_strKeymap.empty())
56 m_strKeymap = StringUtils::Format("v%sp%s", VendorIdAsString(), ProductIdAsString());
57 SetSetting("keymap", m_strKeymap);
60 if (!IsSettingVisible("keymap"))
61 SetSettingVisible("do_not_use_custom_keymap", false);
63 if (!m_strKeymap.empty())
65 bool bKeymapEnabled(!GetSettingBool("do_not_use_custom_keymap"));
68 CLog::Log(LOGDEBUG, "%s - adding keymapping for: %s", __FUNCTION__, m_strKeymap.c_str());
69 CButtonTranslator::GetInstance().AddDevice(m_strKeymap);
71 else if (!bKeymapEnabled)
73 CLog::Log(LOGDEBUG, "%s - removing keymapping for: %s", __FUNCTION__, m_strKeymap.c_str());
74 CButtonTranslator::GetInstance().RemoveDevice(m_strKeymap);
78 CLog::Log(LOGDEBUG, "%s - initialised HID device (%s:%s)", __FUNCTION__, m_strVendorId.c_str(), m_strProductId.c_str());
81 return CPeripheral::InitialiseFeature(feature);
84 void CPeripheralHID::OnSettingChanged(const CStdString &strChangedSetting)
86 if (m_bInitialised && ((strChangedSetting.Equals("keymap") && !GetSettingBool("do_not_use_custom_keymap")) || strChangedSetting.Equals("keymap_enabled")))
88 m_bInitialised = false;
89 InitialiseFeature(FEATURE_HID);