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),
33 m_strDeviceName = scanResult.m_strDeviceName.IsEmpty() ? g_localizeStrings.Get(35001) : scanResult.m_strDeviceName;
34 m_features.push_back(FEATURE_HID);
37 CPeripheralHID::~CPeripheralHID(void)
39 if (!m_strKeymap.IsEmpty() && !GetSettingBool("do_not_use_custom_keymap"))
41 CLog::Log(LOGDEBUG, "%s - switching active keymapping to: default", __FUNCTION__);
42 CButtonTranslator::GetInstance().RemoveDevice(m_strKeymap);
46 bool CPeripheralHID::InitialiseFeature(const PeripheralFeature feature)
48 if (feature == FEATURE_HID && !m_bInitialised)
50 m_bInitialised = true;
52 if (HasSetting("keymap"))
53 m_strKeymap = GetSettingString("keymap");
55 if (m_strKeymap.IsEmpty())
57 m_strKeymap.Format("v%sp%s", VendorIdAsString(), ProductIdAsString());
58 SetSetting("keymap", m_strKeymap);
61 if (!IsSettingVisible("keymap"))
62 SetSettingVisible("do_not_use_custom_keymap", false);
64 if (!m_strKeymap.IsEmpty())
66 bool bKeymapEnabled(!GetSettingBool("do_not_use_custom_keymap"));
69 CLog::Log(LOGDEBUG, "%s - adding keymapping for: %s", __FUNCTION__, m_strKeymap.c_str());
70 CButtonTranslator::GetInstance().AddDevice(m_strKeymap);
72 else if (!bKeymapEnabled)
74 CLog::Log(LOGDEBUG, "%s - removing keymapping for: %s", __FUNCTION__, m_strKeymap.c_str());
75 CButtonTranslator::GetInstance().RemoveDevice(m_strKeymap);
79 CLog::Log(LOGDEBUG, "%s - initialised HID device (%s:%s)", __FUNCTION__, m_strVendorId.c_str(), m_strProductId.c_str());
82 return CPeripheral::InitialiseFeature(feature);
85 void CPeripheralHID::OnSettingChanged(const CStdString &strChangedSetting)
87 if (m_bInitialised && ((strChangedSetting.Equals("keymap") && !GetSettingBool("do_not_use_custom_keymap")) || strChangedSetting.Equals("keymap_enabled")))
89 m_bInitialised = false;
90 InitialiseFeature(FEATURE_HID);