From c368b9d2216660ed7541cad6919338a3538a644b Mon Sep 17 00:00:00 2001 From: John Pietrzak Date: Mon, 3 Sep 2012 18:23:27 -0400 Subject: [PATCH] Update to UI This is a quick release to add an extra button to the Select Keyset window to make accessing favorites easier. Several phrases have been reworked to make them more self-explanatory. Also, iRobot Roomba keyset and panel added. --- dialogs/pireditkeysetdialog.ui | 2 +- dialogs/pirfavoritesdialog.ui | 2 +- dialogs/pirtabschoicedialog.cpp | 3 + forms/pirroombaform.cpp | 122 +++++++++++++++++ forms/pirroombaform.h | 62 +++++++++ forms/pirroombaform.ui | 289 +++++++++++++++++++++++++++++++++++++++ keysets/irobot.cpp | 34 +++++ keysets/irobot.h | 18 +++ keysets/samsung.cpp | 37 +++++ mainwindow.cpp | 2 +- mainwindow.h | 2 +- mainwindow.ui | 12 +- pierogi.pro | 13 +- pierogi.pro.user | 8 +- pirkeynames.h | 8 ++ pirkeysetmanager.cpp | 3 + pirmakenames.cpp | 1 + pirmakenames.h | 1 + pirpanelmanager.cpp | 16 ++- pirpanelmanager.h | 2 + pirpanelnames.h | 4 +- pirselectkeysetform.cpp | 29 +++- pirselectkeysetform.h | 2 + pirselectkeysetform.ui | 66 ++++++--- protocols/irobotprotocol.cpp | 187 +++++++++++++++++++++++++ protocols/irobotprotocol.h | 30 ++++ 26 files changed, 910 insertions(+), 45 deletions(-) create mode 100644 forms/pirroombaform.cpp create mode 100644 forms/pirroombaform.h create mode 100644 forms/pirroombaform.ui create mode 100644 keysets/irobot.cpp create mode 100644 keysets/irobot.h create mode 100644 protocols/irobotprotocol.cpp create mode 100644 protocols/irobotprotocol.h diff --git a/dialogs/pireditkeysetdialog.ui b/dialogs/pireditkeysetdialog.ui index ad58a57..864fa84 100644 --- a/dialogs/pireditkeysetdialog.ui +++ b/dialogs/pireditkeysetdialog.ui @@ -48,7 +48,7 @@ - Add keyset to favorites list + Favorite Keyset diff --git a/dialogs/pirfavoritesdialog.ui b/dialogs/pirfavoritesdialog.ui index e59385f..cd7e4b5 100644 --- a/dialogs/pirfavoritesdialog.ui +++ b/dialogs/pirfavoritesdialog.ui @@ -11,7 +11,7 @@ - Choose Favorite Keyset + Choose Keyset from Favorites diff --git a/dialogs/pirtabschoicedialog.cpp b/dialogs/pirtabschoicedialog.cpp index 7cf9a4f..21d4662 100644 --- a/dialogs/pirtabschoicedialog.cpp +++ b/dialogs/pirtabschoicedialog.cpp @@ -29,6 +29,9 @@ PIRTabsChoiceDialog::PIRTabsChoiceDialog( ui->tabsChoiceListWidget->addItem( new PIRTabsWidgetItem("Air Conditioner Panels", AC_Tabs)); + + ui->tabsChoiceListWidget->addItem( + new PIRTabsWidgetItem("Roomba Panels", Roomba_Tabs)); } diff --git a/forms/pirroombaform.cpp b/forms/pirroombaform.cpp new file mode 100644 index 0000000..051af74 --- /dev/null +++ b/forms/pirroombaform.cpp @@ -0,0 +1,122 @@ +#include "pirroombaform.h" +#include "ui_pirroombaform.h" + +#include "mainwindow.h" +#include "pirkeysetmanager.h" + +/* +PIRRoombaForm::PIRRoombaForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::PIRRoombaForm) +{ + ui->setupUi(this); +} +*/ + +PIRRoombaForm::PIRRoombaForm( + MainWindow *mw) + : QWidget(0), + ui(new Ui::PIRRoombaForm), + mainWindow(mw) +{ + ui->setupUi(this); +} + +PIRRoombaForm::~PIRRoombaForm() +{ + delete ui; +} + +void PIRRoombaForm::enableButtons( + const PIRKeysetManager *km, + unsigned int id) +{ + emit spotEnabled(km->hasKey(id, RobotSpot_Key)); + emit forwardEnabled(km->hasKey(id, RobotForward_Key)); + emit cleanEnabled(km->hasKey(id, RobotClean_Key)); + emit ccwEnabled(km->hasKey(id, RobotCCW_Key)); + emit pauseEnabled(km->hasKey(id, Pause_Key)); + emit cwEnabled(km->hasKey(id, RobotCW_Key)); + emit maxEnabled(km->hasKey(id, RobotMax_Key)); + emit powerEnabled(km->hasKey(id, Power_Key)); +} + +void PIRRoombaForm::on_spotButton_pressed() +{ + mainWindow->startRepeating(RobotSpot_Key); +} + +void PIRRoombaForm::on_spotButton_released() +{ + mainWindow->stopRepeating(); +} + +void PIRRoombaForm::on_forwardButton_pressed() +{ + mainWindow->startRepeating(RobotForward_Key); +} + +void PIRRoombaForm::on_forwardButton_released() +{ + mainWindow->stopRepeating(); +} + +void PIRRoombaForm::on_cleanButton_pressed() +{ + mainWindow->startRepeating(RobotClean_Key); +} + +void PIRRoombaForm::on_cleanButton_released() +{ + mainWindow->stopRepeating(); +} + +void PIRRoombaForm::on_ccwButton_pressed() +{ + mainWindow->startRepeating(RobotCCW_Key); +} + +void PIRRoombaForm::on_ccwButton_released() +{ + mainWindow->stopRepeating(); +} + +void PIRRoombaForm::on_pauseButton_pressed() +{ + mainWindow->startRepeating(Pause_Key); +} + +void PIRRoombaForm::on_pauseButton_released() +{ + mainWindow->stopRepeating(); +} + +void PIRRoombaForm::on_cwButton_pressed() +{ + mainWindow->startRepeating(RobotCW_Key); +} + +void PIRRoombaForm::on_cwButton_released() +{ + mainWindow->stopRepeating(); +} + +void PIRRoombaForm::on_maxButton_pressed() +{ + mainWindow->startRepeating(RobotMax_Key); +} + +void PIRRoombaForm::on_maxButton_released() +{ + mainWindow->stopRepeating(); +} + +void PIRRoombaForm::on_powerButton_pressed() +{ + mainWindow->startRepeating(Power_Key); +} + +void PIRRoombaForm::on_powerButton_released() +{ + mainWindow->stopRepeating(); +} diff --git a/forms/pirroombaform.h b/forms/pirroombaform.h new file mode 100644 index 0000000..f98346a --- /dev/null +++ b/forms/pirroombaform.h @@ -0,0 +1,62 @@ +#ifndef PIRROOMBAFORM_H +#define PIRROOMBAFORM_H + +#include + +class MainWindow; +class PIRKeysetManager; + +namespace Ui { +class PIRRoombaForm; +} + +class PIRRoombaForm : public QWidget +{ + Q_OBJECT + +public: +// explicit PIRRoombaForm(QWidget *parent = 0); + PIRRoombaForm( + MainWindow *mw); + + ~PIRRoombaForm(); + + void enableButtons( + const PIRKeysetManager *keyset, + unsigned int id); + +signals: + void spotEnabled(bool); + void forwardEnabled(bool); + void cleanEnabled(bool); + void ccwEnabled(bool); + void pauseEnabled(bool); + void cwEnabled(bool); + void maxEnabled(bool); + void powerEnabled(bool); + +private slots: + void on_spotButton_pressed(); + void on_spotButton_released(); + void on_forwardButton_pressed(); + void on_forwardButton_released(); + void on_cleanButton_pressed(); + void on_cleanButton_released(); + void on_ccwButton_pressed(); + void on_ccwButton_released(); + void on_pauseButton_pressed(); + void on_pauseButton_released(); + void on_cwButton_pressed(); + void on_cwButton_released(); + void on_maxButton_pressed(); + void on_maxButton_released(); + void on_powerButton_pressed(); + void on_powerButton_released(); + +private: + Ui::PIRRoombaForm *ui; + + MainWindow *mainWindow; +}; + +#endif // PIRROOMBAFORM_H diff --git a/forms/pirroombaform.ui b/forms/pirroombaform.ui new file mode 100644 index 0000000..e5c6e93 --- /dev/null +++ b/forms/pirroombaform.ui @@ -0,0 +1,289 @@ + + + PIRRoombaForm + + + + 0 + 0 + 800 + 480 + + + + Form + + + + 8 + + + + + + 0 + 0 + + + + Spot + + + + + + + + 0 + 0 + + + + Forward + + + + + + + + 0 + 0 + + + + Clean + + + + + + + + 0 + 0 + + + + Counterclockwise + + + + + + + + 0 + 0 + + + + Pause + + + + :/icons/playback_pause_icon&48.png:/icons/playback_pause_icon&48.png + + + + 48 + 48 + + + + + + + + + 0 + 0 + + + + Clockwise + + + + + + + + 0 + 0 + + + + Max + + + + + + + + 0 + 0 + + + + Power + + + + :/icons/on-off_icon&48.png:/icons/on-off_icon&48.png + + + + 48 + 48 + + + + + + + + + + + + PIRRoombaForm + spotEnabled(bool) + spotButton + setEnabled(bool) + + + 399 + 239 + + + 136 + 85 + + + + + PIRRoombaForm + forwardEnabled(bool) + forwardButton + setEnabled(bool) + + + 399 + 239 + + + 399 + 85 + + + + + PIRRoombaForm + cleanEnabled(bool) + cleanButton + setEnabled(bool) + + + 399 + 239 + + + 663 + 85 + + + + + PIRRoombaForm + ccwEnabled(bool) + ccwButton + setEnabled(bool) + + + 399 + 239 + + + 136 + 241 + + + + + PIRRoombaForm + pauseEnabled(bool) + pauseButton + setEnabled(bool) + + + 399 + 239 + + + 399 + 241 + + + + + PIRRoombaForm + cwEnabled(bool) + cwButton + setEnabled(bool) + + + 399 + 239 + + + 663 + 241 + + + + + PIRRoombaForm + maxEnabled(bool) + maxButton + setEnabled(bool) + + + 399 + 239 + + + 136 + 398 + + + + + PIRRoombaForm + powerEnabled(bool) + powerButton + setEnabled(bool) + + + 399 + 239 + + + 399 + 398 + + + + + + spotEnabled(bool) + forwardEnabled(bool) + cleanEnabled(bool) + ccwEnabled(bool) + pauseEnabled(bool) + cwEnabled(bool) + maxEnabled(bool) + powerEnabled(bool) + + diff --git a/keysets/irobot.cpp b/keysets/irobot.cpp new file mode 100644 index 0000000..393428c --- /dev/null +++ b/keysets/irobot.cpp @@ -0,0 +1,34 @@ +#include "irobot.h" +#include "protocols/irobotprotocol.h" + + +IRobotRoomba1::IRobotRoomba1( + unsigned int index) + : PIRKeysetMetaData( + "Roomba Keyset 1", + IRobot_Make, + index) +{ +} + + +void IRobotRoomba1::populateProtocol( + QObject *guiObject) +{ + if (threadableProtocol) + { + // Keyset already populated. + return; + } + + threadableProtocol = new IRobotProtocol(guiObject, index); + + addKey("CounterClockwise", RobotCCW_Key, 0x81, 8); + addKey("Forward", RobotForward_Key, 0x82, 8); + addKey("Clockwise", RobotCW_Key, 0x83, 8); + addKey("spot", RobotSpot_Key, 0x84, 8); + addKey("max", RobotMax_Key, 0x85, 8); + addKey("clean", RobotClean_Key, 0x88, 8); // "clear" + addKey("pause", Pause_Key, 0x89, 8); + addKey("power", Power_Key, 0x8A, 8); +} diff --git a/keysets/irobot.h b/keysets/irobot.h new file mode 100644 index 0000000..c7c3064 --- /dev/null +++ b/keysets/irobot.h @@ -0,0 +1,18 @@ +#ifndef IROBOT_H +#define IROBOT_H + +#include "pirkeysetmetadata.h" + +class QObject; + +class IRobotRoomba1: public PIRKeysetMetaData +{ +public: + IRobotRoomba1( + unsigned int index); + + virtual void populateProtocol( + QObject *guiObject); +}; + +#endif // IROBOT_H diff --git a/keysets/samsung.cpp b/keysets/samsung.cpp index 2001f37..da23518 100644 --- a/keysets/samsung.cpp +++ b/keysets/samsung.cpp @@ -892,6 +892,43 @@ void SamsungAC1::populateProtocol( } +/* +SamsungAC2::SamsungAC2( + unsigned int index) + : PIRKeysetMetaData( + "AC Keyset 2", + Samsung_Make, + index) +{ +} + + +void SamsungAC2::populateProtocol( + QObject *guiObject) +{ + if (threadableProtocol) + { + // Keyset already populated. + return; + } + + threadableProtocol = new ACProtocol(guiObject, index); + + addKey("Power Off", PowerOff_Subkey, 0xC, 4); + addKey("Power On", PowerOn_Subkey, 0x0, 4); + + addKey("Cool Mode - Normal", CoolModeNormal_Subkey, 0x7, 3); + addKey("Cool Mode - Turbo", CoolModeTurbo_Subkey, 0x1, 3); + addKey("Cool Mode - Far", CoolModeFar_Subkey, 0x2, 3); + + addKey("Deflector L/R Off", DeflectorLROff_Subkey, 0x0, 1); + addKey("Deflector L/R On", DeflectorLROn_Subkey, 0x1, 1); + addKey("Deflector U/D Off", DeflectorUDOff_Subkey, 0x0, 1); + addKey("Deflector U/D On", DeflectorUDOn_Subkey, 0x1, 1); +} +*/ + + SamsungDVBT1::SamsungDVBT1( unsigned int index) : PIRKeysetMetaData( diff --git a/mainwindow.cpp b/mainwindow.cpp index bdce733..d55e661 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -302,7 +302,7 @@ void MainWindow::on_actionSelectKeyset_triggered() selectKeysetForm->show(); } -void MainWindow::on_actionSelect_Device_By_Name_triggered() +void MainWindow::on_actionBrowse_Device_List_triggered() { selectDeviceForm->show(); } diff --git a/mainwindow.h b/mainwindow.h index ef6f19a..ba00799 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -103,7 +103,7 @@ public slots: private slots: void on_actionSelectKeyset_triggered(); - void on_actionSelect_Device_By_Name_triggered(); + void on_actionBrowse_Device_List_triggered(); void on_actionPreferences_triggered(); void on_actionAbout_triggered(); void on_actionDocumentation_triggered(); diff --git a/mainwindow.ui b/mainwindow.ui index 19e19c5..4819770 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -49,7 +49,7 @@ Pierogi - + @@ -58,7 +58,7 @@ - Select Keyset by Name + Select Keyset @@ -71,14 +71,14 @@ Documentation - + - Select Keyset by Device + Preferences - + - Preferences + Browse Device List diff --git a/pierogi.pro b/pierogi.pro index 0d16845..4fb68bf 100644 --- a/pierogi.pro +++ b/pierogi.pro @@ -201,7 +201,10 @@ SOURCES += main.cpp mainwindow.cpp \ dialogs/pirfavoritesdialog.cpp \ keysets/medion.cpp \ keysets/blaupunkt.cpp \ - keysets/lifetec.cpp + keysets/lifetec.cpp \ + keysets/irobot.cpp \ + protocols/irobotprotocol.cpp \ + forms/pirroombaform.cpp HEADERS += mainwindow.h \ pirkeynames.h \ pirmakenames.h \ @@ -378,7 +381,10 @@ HEADERS += mainwindow.h \ dialogs/pirfavoritesdialog.h \ keysets/medion.h \ keysets/blaupunkt.h \ - keysets/lifetec.h + keysets/lifetec.h \ + keysets/irobot.h \ + protocols/irobotprotocol.h \ + forms/pirroombaform.h FORMS += mainwindow.ui \ pirdocumentationform.ui \ piraboutform.ui \ @@ -405,7 +411,8 @@ FORMS += mainwindow.ui \ forms/pirvcrform.ui \ forms/pirvideodiscform.ui \ forms/piraudiodeviceform.ui \ - dialogs/pirfavoritesdialog.ui + dialogs/pirfavoritesdialog.ui \ + forms/pirroombaform.ui # Please do not modify the following two lines. Required for deployment. include(deployment.pri) diff --git a/pierogi.pro.user b/pierogi.pro.user index 98159bc..7a9000d 100644 --- a/pierogi.pro.user +++ b/pierogi.pro.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -78,8 +78,8 @@ dpkg-buildpackage -sa -S -uc -us /Users/john/QtSDK/Maemo/4.6.2/bin/mad - false - /Users/john/Develop/n900/pierogi-1.1.5 + true + /Users/john/Develop/n900/pierogi-1.1.6 Custom Process Step ProjectExplorer.ProcessStep @@ -307,7 +307,7 @@ 2012-01-17T13:21:05 2012-01-23T09:47:37 2012-02-03T10:04:34 - 2012-09-02T21:07:05 + 2012-09-03T17:43:57 2012-03-04T19:56:48 2012-01-01T15:35:35 2012-03-12T20:02:57 diff --git a/pirkeynames.h b/pirkeynames.h index 148a334..16abe63 100644 --- a/pirkeynames.h +++ b/pirkeynames.h @@ -219,6 +219,14 @@ enum PIRKeyName{ FanSlower_Key, EnergySave_Key, + // iRobot controls: + RobotForward_Key, + RobotCW_Key, + RobotCCW_Key, + RobotSpot_Key, + RobotMax_Key, + RobotClean_Key, + // Other keys: Captions_Key, Info_Key, diff --git a/pirkeysetmanager.cpp b/pirkeysetmanager.cpp index 0141a4d..817594c 100644 --- a/pirkeysetmanager.cpp +++ b/pirkeysetmanager.cpp @@ -52,6 +52,7 @@ #include "keysets/huawei.h" #include "keysets/humax.h" #include "keysets/hyundai.h" +#include "keysets/irobot.h" #include "keysets/jvc.h" #include "keysets/kaon.h" #include "keysets/kathrein.h" @@ -362,6 +363,8 @@ PIRKeysetManager::PIRKeysetManager() setupKeyset(new HyundaiAudio1(++counter)); setupKeyset(new HyundaiTV1(++counter)); + setupKeyset(new IRobotRoomba1(++counter)); + setupKeyset(new JVCSat1(++counter)); setupKeyset(new JVCSat2(++counter)); setupKeyset(new JVCVCR1(++counter)); diff --git a/pirmakenames.cpp b/pirmakenames.cpp index dd8c547..1fa1dec 100644 --- a/pirmakenames.cpp +++ b/pirmakenames.cpp @@ -50,6 +50,7 @@ PIRMakeMgr::PIRMakeMgr() makes[Huawei_Make] = "Huawei"; makes[Humax_Make] = "Humax"; makes[Hyundai_Make] = "Hyundai"; + makes[IRobot_Make] = "iRobot"; makes[JVC_Make] = "JVC"; makes[Kaon_Make] = "Kaon"; makes[Kathrein_Make] = "Kathrein"; diff --git a/pirmakenames.h b/pirmakenames.h index 3661044..3df98e1 100644 --- a/pirmakenames.h +++ b/pirmakenames.h @@ -51,6 +51,7 @@ enum PIRMakeName{ Huawei_Make, Humax_Make, Hyundai_Make, + IRobot_Make, JVC_Make, Kaon_Make, Kathrein_Make, diff --git a/pirpanelmanager.cpp b/pirpanelmanager.cpp index 36e61b5..0511bfc 100644 --- a/pirpanelmanager.cpp +++ b/pirpanelmanager.cpp @@ -13,6 +13,7 @@ #include "forms/piradjustform.h" #include "forms/pirairconditionerform.h" #include "forms/piraudiodeviceform.h" +#include "forms/pirroombaform.h" #include "mainwindow.h" @@ -39,6 +40,7 @@ PIRPanelManager::PIRPanelManager( adjustForm(0), acForm(0), audioDeviceForm(0), + roombaForm(0), altMainPanelFlag(false), currentTabsName(Universal_Tabs), mainWindow(mw) @@ -86,6 +88,9 @@ PIRPanelManager::PIRPanelManager( shortPanelNames[Audio_Panel] = "Audio"; longPanelNames[Audio_Panel] = "Audio Device Panel - various audio related buttons"; + shortPanelNames[Roomba_Panel] = "Roomba"; + longPanelNames[Roomba_Panel] = + "Roomba Panel - robotic vacuum cleaner controls"; mainForm = new PIRMainForm(mainWindow); panels[Main_Panel] = mainForm; @@ -126,6 +131,9 @@ PIRPanelManager::PIRPanelManager( audioDeviceForm = new PIRAudioDeviceForm(mainWindow); panels[Audio_Panel] = audioDeviceForm; + roombaForm = new PIRRoombaForm(mainWindow); + panels[Roomba_Panel] = roombaForm; + // Set up the panel collections: PIRPanelNameList pset; @@ -135,7 +143,7 @@ PIRPanelManager::PIRPanelManager( pset.push_back(Keypad_Panel); pset.push_back(Menu_Panel); pset.push_back(Media_Panel); - pset.push_back(Input_Panel); +// pset.push_back(Input_Panel); tabLists[Universal_Tabs] = pset; // The TV collection: @@ -175,6 +183,11 @@ PIRPanelManager::PIRPanelManager( pset.push_back(Record_Panel); pset.push_back(Keypad_Panel); tabLists[Record_Tabs] = pset; + + // The Roomba collection: + pset.clear(); + pset.push_back(Roomba_Panel); + tabLists[Roomba_Tabs] = pset; } @@ -252,6 +265,7 @@ void PIRPanelManager::commonEnableButtons( adjustForm->enableButtons(keyset, id); acForm->enableButtons(keyset, id); audioDeviceForm->enableButtons(keyset, id); + roombaForm->enableButtons(keyset, id); } diff --git a/pirpanelmanager.h b/pirpanelmanager.h index 8c065ed..c2cb046 100644 --- a/pirpanelmanager.h +++ b/pirpanelmanager.h @@ -16,6 +16,7 @@ class PIRInputForm; class PIRAdjustForm; class PIRAirConditionerForm; class PIRAudioDeviceForm; +class PIRRoombaForm; class PIRKeysetWidgetItem; class PIRKeysetManager; @@ -83,6 +84,7 @@ private: PIRAdjustForm *adjustForm; PIRAirConditionerForm *acForm; PIRAudioDeviceForm *audioDeviceForm; + PIRRoombaForm *roombaForm; PIRPanelDisplayNameCollection shortPanelNames; PIRPanelDisplayNameCollection longPanelNames; diff --git a/pirpanelnames.h b/pirpanelnames.h index 19f3eee..967913c 100644 --- a/pirpanelnames.h +++ b/pirpanelnames.h @@ -16,6 +16,7 @@ enum PIRPanelName Adjust_Panel, AC_Panel, Audio_Panel, + Roomba_Panel, Last_Panel_Marker // Used when traversing this enumeration. }; @@ -29,7 +30,8 @@ enum PIRTabBarName // VideoTape_Tabs, Audio_Tabs, AC_Tabs, - Record_Tabs + Record_Tabs, + Roomba_Tabs }; #endif // PIRPANELNAMES_H diff --git a/pirselectkeysetform.cpp b/pirselectkeysetform.cpp index f4c2cb7..8d6f403 100644 --- a/pirselectkeysetform.cpp +++ b/pirselectkeysetform.cpp @@ -9,6 +9,9 @@ #include "pirkeysetwidgetitem.h" #include "dialogs/pireditkeysetdialog.h" +// Debugging include: +//#include + extern PIRMakeMgr makeManager; PIRSelectKeysetForm::PIRSelectKeysetForm( @@ -17,6 +20,7 @@ PIRSelectKeysetForm::PIRSelectKeysetForm( ui(new Ui::PIRSelectKeysetForm), mainWindow(mw), editDialog(0), + showOnlyFavorites(false), currentMake(Any_Make) { ui->setupUi(this); @@ -149,12 +153,20 @@ void PIRSelectKeysetForm::refilterList() // Does the keylist have the required make? if ((currentMake == Any_Make) || (item->getMake() == currentMake)) { - // Does this keylist match the search string? - if ( searchString.isEmpty() - || item->text().contains(searchString, Qt::CaseInsensitive)) + // If required, is the keyset a favorite? + if (!showOnlyFavorites || (item->isFavorite())) { - // Yes, we can show this keylist: - item->setHidden(false); + // Does this keylist match the search string? + if ( searchString.isEmpty() + || item->text().contains(searchString, Qt::CaseInsensitive)) + { + // Yes, we can show this keylist: + item->setHidden(false); + } + else + { + item->setHidden(true); + } } else { @@ -180,3 +192,10 @@ void PIRSelectKeysetForm::openKeysetDialog( editDialog->exec(); } + + +void PIRSelectKeysetForm::on_showFavoritesCheckBox_toggled(bool checked) +{ + showOnlyFavorites = checked; + refilterList(); +} diff --git a/pirselectkeysetform.h b/pirselectkeysetform.h index 29e5667..58609f0 100644 --- a/pirselectkeysetform.h +++ b/pirselectkeysetform.h @@ -58,6 +58,7 @@ private slots: void on_searchStringLineEdit_textChanged(const QString &arg1); void on_ssClosePushButton_clicked(); + void on_showFavoritesCheckBox_toggled(bool checked); private: void refilterList(); @@ -67,6 +68,7 @@ private: MainWindow *mainWindow; PIREditKeysetDialog *editDialog; + bool showOnlyFavorites; PIRMakeName currentMake; QString searchString; }; diff --git a/pirselectkeysetform.ui b/pirselectkeysetform.ui index 62fe3bc..7b07973 100644 --- a/pirselectkeysetform.ui +++ b/pirselectkeysetform.ui @@ -17,36 +17,60 @@ Select Keyset - - 8 - - + - - - - 0 - 0 - - + - Make: + Only Show Favorites - - - - 0 - 0 - + + + Qt::Horizontal - - Qt::NoFocus + + QSizePolicy::Minimum - + + + 20 + 20 + + + + + + + + + + + 0 + 0 + + + + Filter by Make: + + + + + + + + 0 + 0 + + + + Qt::NoFocus + + + + diff --git a/protocols/irobotprotocol.cpp b/protocols/irobotprotocol.cpp new file mode 100644 index 0000000..c2ac7ab --- /dev/null +++ b/protocols/irobotprotocol.cpp @@ -0,0 +1,187 @@ +#include "irobotprotocol.h" + +#include "pirrx51hardware.h" + +#include "pirexception.h" + +// Some global communications stuff: +#include +extern bool commandInFlight; +extern QMutex commandIFMutex; + +// The iRobot (Roomba) protocol seems to be extremely simple. +// A "zero" is encoded with a 1000 usec pulse, 3000 usec space. +// A "one" is encoded with a 3000 usec pulse, 1000 usec space. +// So, it looks a little like a shift encoded protocol, even though it +// is space-encoded. +// There is no header and no trailer. +// Each command may run for 100000 usec (sources differ), but it looks like +// commands are not repeated at all... +// The carrier frequency is the usual 38 kHz. + +IRobotProtocol::IRobotProtocol( + QObject *guiObject, + unsigned int index) + : SpaceProtocol( + guiObject, index, + 1000, 3000, + 3000, 1000, + 0, 0, + 0, + 100000, true) +{ +} + + +void IRobotProtocol::startSendingCommand( + unsigned int threadableID, + PIRKeyName command) +{ + // Exceptions here are problematic; I'll try to weed them out by putting the + // whole thing in a try/catch block: + try + { + // First, check if we are meant to be the recipient of this command: + if (threadableID != id) return; + + clearRepeatFlag(); + + KeycodeCollection::const_iterator i = keycodes.find(command); + + // Do we even have this key defined? + if (i == keycodes.end()) + { + std::string s = "Tried to send a non-existent command.\n"; + throw PIRException(s); + } + + // construct the device: + PIRRX51Hardware rx51device(carrierFrequency, dutyCycle); + + int repeatCount = 0; + int commandDuration = 0; + while (repeatCount < MAX_REPEAT_COUNT) + { + // It looks like we only generate the command once, and remain + // silent for the rest of the time the button is held down. So, no + // repeats. + if (!repeatCount) + { + commandDuration = generateCommand((*i).second, rx51device); + + // Tell the device to send the command: + rx51device.sendCommandToDevice(); + } + + // sleep until the next repetition of command: + sleepUntilRepeat(commandDuration); + + // Check whether we've reached the minimum required number of repetitons: + if (repeatCount >= minimumRepetitions) + { + // Check whether we've been asked to stop: + if (checkRepeatFlag()) + { + QMutexLocker cifLocker(&commandIFMutex); + commandInFlight = false; + return; + } + } + + ++repeatCount; + } + } + catch (PIRException e) + { + // inform the gui: + emit commandFailed(e.getError().c_str()); + } + + QMutexLocker cifLocker(&commandIFMutex); + commandInFlight = false; +} + + +int IRobotProtocol::generateCommand( + const PIRKeyBits &pkb, + PIRRX51Hardware &rx51device) +{ + int duration = 0; + + // The protocol seems to involve 8 command bits, a 16000 usec pause, and + // the same 8 bits repeated again. So, we need to tack a 16000 usec + // space on at the end of the first 8 bits, and just drop the last space + // definition at the end of the second 8 bits: + + // The first 7 bits: + int index = 0; + CommandSequence::const_iterator i = pkb.firstCode.begin(); + while ((index < 7) && (i != pkb.firstCode.end())) + { + if (*i) + { + rx51device.addPair(onePulse, oneSpace); + duration += onePulse + oneSpace; + } + else + { + rx51device.addPair(zeroPulse, zeroSpace); + duration += zeroPulse + zeroSpace; + } + + ++index; + ++i; + } + + // Eighth bit with extra space at the end: + if (i != pkb.firstCode.end()) + { + if (*i) + { + rx51device.addPair(onePulse, oneSpace + 16000); + duration += onePulse + oneSpace + 16000; + } + else + { + rx51device.addPair(zeroPulse, zeroSpace + 16000); + duration += zeroPulse + zeroSpace + 16000; + } + } + + // The following seven bits: + index = 0; + i = pkb.firstCode.begin(); + while ((index < 7) && (i != pkb.firstCode.end())) + { + if (*i) + { + rx51device.addPair(onePulse, oneSpace); + duration += onePulse + oneSpace; + } + else + { + rx51device.addPair(zeroPulse, zeroSpace); + duration += zeroPulse + zeroSpace; + } + + ++index; + ++i; + } + + // The last half-bit: + if (i != pkb.firstCode.end()) + { + if (*i) + { + rx51device.addSingle(onePulse); + duration += onePulse; + } + else + { + rx51device.addSingle(zeroPulse); + duration += zeroPulse; + } + } + + return duration; +} diff --git a/protocols/irobotprotocol.h b/protocols/irobotprotocol.h new file mode 100644 index 0000000..b2378c5 --- /dev/null +++ b/protocols/irobotprotocol.h @@ -0,0 +1,30 @@ +#ifndef IROBOTPROTOCOL_H +#define IROBOTPROTOCOL_H + +#include "spaceprotocol.h" + +class PIRRX51Hardware; + +// The iRobot protocol is extremely simple, but my sources differ slightly +// on its exact properties (particularly how repetition is handled). So +// this may need some reworking in the future. + +class IRobotProtocol: public SpaceProtocol +{ +public: + IRobotProtocol( + QObject *guiObject, + unsigned int index); + +public slots: + void startSendingCommand( + unsigned int threadableID, + PIRKeyName command); + +private: + int generateCommand( + const PIRKeyBits &bits, + PIRRX51Hardware &device); +}; + +#endif // IROBOTPROTOCOL_H -- 1.7.9.5