Skip to content

Commit

Permalink
Merge branch 'develop' into Fix-audiohat-gpio
Browse files Browse the repository at this point in the history
  • Loading branch information
s-martin committed Feb 21, 2021
2 parents e46f90c + 604bffb commit 591336a
Show file tree
Hide file tree
Showing 33 changed files with 658 additions and 50 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ develop ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ develop ]
schedule:
- cron: '16 18 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: [ 'javascript', 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ The year 2020 also has a clear *:star: community hero :star:*: @s-martin has bee

## Important updates / news

* **Discussions forums** we use Github's Discussions feature for a more forum style. Please ask general questions in [Discussions](https://github.com/MiczFlor/RPi-Jukebox-RFID/discussions), bugs and enhancements should still be in [Issues](https://github.com/MiczFlor/RPi-Jukebox-RFID/issues).

* **Gitter Community** we got ourselves a gitter community; chat us up at https://gitter.im/phoniebox

* **Phoniebox [2.2](https://github.com/MiczFlor/RPi-Jukebox-RFID/milestone/4?closed=1) released (2020-11-23)**
Expand Down
2 changes: 1 addition & 1 deletion components/controls/buttons_usb_encoder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ Tested Devices:

1. Plug in your USB Encoder. You don't need to install any drivers. After plugging in, the USB encoder acts like an
input device.
2. Run the script `setup-buttons-usb-encoder.sh` to set up your USB Encoder (choose the device and map the buttons).
2. Navigate to your RPi-Jukebox home directory and run the script `setup-buttons-usb-encoder.sh` to set up your USB Encoder (choose the device and map the buttons).

![USB Encoder schematics](buttons-usb-encoder.jpg)
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
if event.type == ecodes.EV_KEY:
keyevent = categorize(event)
if keyevent.keystate == KeyEvent.key_down:
button_string = keyevent.keycode
if type(button_string) is list:
button_string = '-'.join(sorted(button_string))
try:
function_name = button_map[keyevent.keycode]
function_name = button_map[button_string]
try:
getattr(components.gpio_control.function_calls, function_name)()
except:
logger.warning(
"Function " + function_name + " not found in function_calls.py (mapped from button: " + keyevent.keycode + ")")
"Function " + function_name + " not found in function_calls.py (mapped from button: " + button_string + ")")
except KeyError:
logger.warning("Button " + keyevent.keycode + " not mapped to any function.")
logger.warning("Button " + button_string + " not mapped to any function.")
except:
logger.error("An error with Buttons USB Encoder occurred.")
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
if event.type == ecodes.EV_KEY:
keyevent = categorize(event)
if keyevent.keystate == KeyEvent.key_down:
button_map[keyevent.keycode] = function_name
print("Button " + keyevent.keycode + " is now mapped to " + function_name_short)
button_string = keyevent.keycode
if type(button_string) is list:
button_string = '-'.join(sorted(button_string))
button_map[button_string] = function_name
print("Button " + button_string + " is now mapped to " + function_name_short)
break
except KeyboardInterrupt:
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ question() {
esac
}

if [ "$PWD" != "$JUKEBOX_HOME_DIR" ]
then
printf "Please execute script from %s directory\n" $JUKEBOX_HOME_DIR
exit 0
fi

printf "Please make sure that the Buttons USB Encoder and the buttons are connected before continuing...\n"
question "Continue"

Expand Down
16 changes: 11 additions & 5 deletions components/gpio_control/GPIODevices/shutdown_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
import logging
from .simple_button import SimpleButton


logger = logging.getLogger(__name__)


class ShutdownButton(SimpleButton):

def __init__(self, pin, action=lambda *args: None, name=None, bouncetime=500, edge=GPIO.FALLING,
hold_time=.1, led_pin=None, time_pressed=2):
hold_time=.1, led_pin=None, time_pressed=2, hold_repeat=False, pull_up_down=GPIO.PUD_UP,iteration_time=.2):
self.led_pin = led_pin
self.time_pressed = 2
self.iteration_time = .2
self.time_pressed = time_pressed
self.iteration_time = iteration_time
super(ShutdownButton, self).__init__(pin=pin, action=action, name=name, bouncetime=bouncetime, edge=edge,
hold_time=hold_time, hold_repeat=False)
hold_time=hold_time, hold_repeat=hold_repeat, pull_up_down=pull_up_down,
)
pass

# function to provide user feedback (= flashing led) while the shutdown button is pressed
# do not directly call shutdown, in case it was hit accedently
Expand Down Expand Up @@ -47,3 +48,8 @@ def callbackFunctionHandler(self, *args):
self.set_led(GPIO.HIGH)
# leave it on for the moment, it will be off when the system is down
self.when_pressed(*args)

def __repr__(self):
return '<ShutdownButton-{}(pin {},hold_repeat={},hold_time={})>'.format(
self.name, self.pin, self.hold_repeat, self.hold_time
)
18 changes: 17 additions & 1 deletion components/gpio_control/example_configs/gpio_settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,26 @@ pull_up: True
hold_time: 0.3
functionCall: functionCallPlayerPrev

[FastForward]
enabled: false
Type: Button
Pin: 7
pull_up: True
hold_time: 0.3
functionCall: functionCallPlayerSeekFwd

[Rewind]
enabled: false
Type: Button
Pin: 8
pull_up: True
hold_time: 0.3
functionCall: functionCallPlayerSeekBack

[Halt]
enabled: False
Type: Button
Pin: 21
Pin: 25
pull_up: True
hold_time: 0.3
functionCall: functionCallPlayerPauseForce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ hold_repeat: False

[Shutdown]
enabled: True
Type: Button
Type: ShutdownButton
Pin: 3
hold_time: 2
functionCall: functionCallShutdown
Expand Down
9 changes: 9 additions & 0 deletions components/gpio_control/gpio_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ def generate_device(config, deviceName):
getFunctionCall(config.get('functionCallDown')),
config.getfloat('timeBase', fallback=0.1),
name=deviceName)
elif device_type == 'ShutdownButton':
return ShutdownButton(pin=config.getint('Pin'),
action=getFunctionCall(config.get('functionCall',fallback='functionCallShutdown')),
name=deviceName,
bouncetime=config.getint('bouncetime', fallback=500),
edge=config.get('edge', fallback='FALLING'),
hold_repeat=config.getboolean('hold_repeat', False),
hold_time=config.getfloat('hold_time', fallback=0.3),
pull_up_down=config.get('pull_up_down', fallback=GPIO.PUD_UP))
logger.warning('cannot find {}'.format(deviceName))
return None

Expand Down
2 changes: 1 addition & 1 deletion components/gpio_control/test/gpio_settings_test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ hold_repeat: False

[Shutdown]
enabled: True
Type: Button
Type: ShutdownButton
Pin: 3
hold_time: 2
functionCall: functionCallShutdown
Expand Down
8 changes: 4 additions & 4 deletions components/gpio_control/test/test_shutdown_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def shutdown_button():
return ShutdownButton(pin=1, action=mocked_function)


class TestShutdownButton():
class TestShutDownButton():
def test_init(self):
ShutdownButton(pin=1)

@patch('time.sleep', mock_time)
def test_action(self, shutdown_button):
def test_action_too_short_press(self, shutdown_button):
for i in range(9):
GPIO.input.reset_mock()
GPIO.input.side_effect = i * [0] + [1]
Expand All @@ -30,13 +30,13 @@ def test_action(self, shutdown_button):
mocked_function.assert_not_called()

@patch('time.sleep', mock_time)
def test_action2(self, shutdown_button):
def test_action_invalid_press(self, shutdown_button):
GPIO.input.side_effect = lambda *args: 1
shutdown_button.callbackFunctionHandler()
mocked_function.assert_not_called()

@patch('time.sleep', mock_time)
def test_action3(self, shutdown_button):
def test_action_valid_press(self, shutdown_button):
GPIO.input.side_effect = lambda *args: 0
shutdown_button.callbackFunctionHandler()
mocked_function.assert_called_once()
Loading

0 comments on commit 591336a

Please sign in to comment.