From 95e58c74c8ede05630600f09d0da2cfb59d21907 Mon Sep 17 00:00:00 2001 From: Julius Date: Tue, 4 Dec 2018 10:59:48 +0100 Subject: [PATCH 1/4] Install script improvement - switched to output checking --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 531fe66..ca33457 100644 --- a/install.sh +++ b/install.sh @@ -9,7 +9,7 @@ sudo pip install adafruit-pca9685 sudo apt install vsftpd sudo apt install vlc sudo modprobe bcm2835-v4l2 -if [hash pip3];then +if [[hash pip3]];then pip install pygame exit 0 fi From 9f658ee30143e9d3f7ab362e2176461d93536ffe Mon Sep 17 00:00:00 2001 From: Julius Date: Tue, 4 Dec 2018 11:15:46 +0100 Subject: [PATCH 2/4] Quality Improvements - less complexity in controllib --- lib/controllib.py | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/controllib.py b/lib/controllib.py index d47614d..e27fda5 100644 --- a/lib/controllib.py +++ b/lib/controllib.py @@ -21,45 +21,43 @@ class Joystick: self.pressed = [] self.splaying = False + def _button_check(self, name, i, c, button): + """ Checks if a button was pressed and wasn't pressed before. """ + if i == c[name]: + if button == 1 and i not in self.pressed: + self.pressed.append(i) + return 1 + elif button == 0 and i in self.pressed: + self.pressed.remove(i) + return 2 + return 0 + def _handle_buttons(self, axis_dict, c): for i in range(self.joystick.get_numbuttons()): button = self.joystick.get_button(i) axis_dict['Button {}'.format(i)] = button - if i == c['LIGHT'] and button == 1 and i not in self.pressed: + if self._button_check('LIGHT', i, c, button) == 1: self.light.switch() - self.pressed.append(i) - elif i == c['LIGHT'] and button == 0 and i in self.pressed: - self.pressed.remove(i) - elif i == c['MUSIC'] and button == 1 and i not in self.pressed: + elif self._button_check('MUSIC', i, c, button) == 1: if self.splaying: self.sound.stop() self.splaying = False else: self.sound.play() self.splaying = True - self.pressed.append(i) - elif i == c['MUSIC'] and button == 0 and i in self.pressed: - self.pressed.remove(i) - elif i == c['VOLIN'] and button == 1 and i not in self.pressed: + elif self._button_check('VOLIN', i, c, button) == 1: self.sound.set_volume(self.sound.get_volume() + 0.1) - self.pressed.append(i) - elif i == c['VOLIN'] and button == 0 and i in self.pressed: + elif self._button_check('VOLIN', i, c, button) == 2: self.sound.set_volume(self.sound.get_volume() - 0.1) - self.pressed.remove(i) - elif i == c['VOLDE'] and button == 1 and i not in self.pressed: - self.pressed.append(i) - elif i == c['VOLDE'] and button == 0 and i in self.pressed: - self.pressed.remove(i) + elif self._button_check('VOLDE', i, c, button): + pass - elif i == c['REC'] and button == 1 and i not in self.pressed: + elif self._button_check('REC', i, c, button) == 1: self._save_camimg() - self.pressed.append(i) - elif i == c['REC'] and button == 0 and i in self.pressed: - self.pressed.remove(i) return axis_dict def handle(self): From 4f155ce038b063cda17d2cd95dd5e4913f0705ad Mon Sep 17 00:00:00 2001 From: Trivernis Date: Tue, 4 Dec 2018 11:19:12 +0100 Subject: [PATCH 3/4] Even more Quality Improvements --- install.sh | 2 +- lib/gyro.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index ca33457..cb23760 100644 --- a/install.sh +++ b/install.sh @@ -9,7 +9,7 @@ sudo pip install adafruit-pca9685 sudo apt install vsftpd sudo apt install vlc sudo modprobe bcm2835-v4l2 -if [[hash pip3]];then +if hash pip3; then pip install pygame exit 0 fi diff --git a/lib/gyro.py b/lib/gyro.py index 33d1d51..9e6eaac 100644 --- a/lib/gyro.py +++ b/lib/gyro.py @@ -26,8 +26,7 @@ def read_word_2c(reg): val = read_word(reg) if val >= 0x8000: return -((65535 - val) + 1) - else: - return val + return val def dist(a, b): From e5a7eb262b8b3f6acb53802b5e9c853f6e105b44 Mon Sep 17 00:00:00 2001 From: Trivernis Date: Tue, 4 Dec 2018 11:20:31 +0100 Subject: [PATCH 4/4] Improved install script --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index cb23760..50515ab 100644 --- a/install.sh +++ b/install.sh @@ -13,7 +13,7 @@ if hash pip3; then pip install pygame exit 0 fi -if [hash pip];then +if hash pip;then pip install pygame exit 0 fi