mirror of
https://github.com/cyberboy666/r_e_c_u_r.git
synced 2025-12-05 16:00:06 +01:00
adding intergration with mcp3008 for analog inputs
This commit is contained in:
29
actions.py
29
actions.py
@@ -198,30 +198,21 @@ class Actions(object):
|
||||
elif self.data.player_mode == 'next':
|
||||
self.data.player_mode = 'now'
|
||||
|
||||
def set_the_camera_colour_u_with_cc(self, amount):
|
||||
u_value = self._convert_midi_cc_value(amount, 0, 255)
|
||||
self.capture.set_colour(u_value, None)
|
||||
def set_the_camera_colour_u_continuous(self, amount):
|
||||
self.capture.set_colour(amount*255, None)
|
||||
|
||||
def set_the_camera_colour_v_with_cc(self, amount):
|
||||
v_value = self._convert_midi_cc_value(amount, 0, 255)
|
||||
self.capture.set_colour(None, v_value)
|
||||
def set_the_camera_colour_v_continuous(self, amount):
|
||||
self.capture.set_colour(None, amount*255)
|
||||
|
||||
def set_the_camera_alpha_cc(self, amount):
|
||||
alpha_amount = self._convert_midi_cc_value(amount, 0, 255)
|
||||
self.capture.set_alpha(alpha_amount)
|
||||
def set_the_camera_alpha_continuous(self, amount):
|
||||
self.capture.set_alpha(amount*255)
|
||||
|
||||
def set_the_current_video_alpha_cc(self, amount):
|
||||
alpha_amount = self._convert_midi_cc_value(amount, 0, 255)
|
||||
self.video_driver.current_player.set_alpha_value(alpha_amount)
|
||||
def set_the_current_video_alpha_continuous(self, amount):
|
||||
self.video_driver.current_player.set_alpha_value(amount*255)
|
||||
|
||||
def set_the_next_video_alpha_cc(self, amount):
|
||||
alpha_amount = self._convert_midi_cc_value(amount, 0, 255)
|
||||
self.video_driver.next_player.set_alpha_value(alpha_amount)
|
||||
def set_the_next_video_alpha_continuous(self, amount):
|
||||
self.video_driver.next_player.set_alpha_value(amount*255)
|
||||
|
||||
@staticmethod
|
||||
def _convert_midi_cc_value(cc_value, min_param, max_param):
|
||||
output_range = max_param - min_param
|
||||
return int(( cc_value / 127 ) * output_range + min_param)
|
||||
|
||||
def get_midi_status(self):
|
||||
self.message_handler.set_message('INFO', 'midi status is {}'.format(self.data.midi_status))
|
||||
|
||||
@@ -16,6 +16,7 @@ class Data(object):
|
||||
DEFAULT_SETTINGS_JSON = 'settings_default.json'
|
||||
KEYPAD_MAPPING_JSON = 'keypad_action_mapping.json'
|
||||
MIDI_MAPPING_JSON = 'midi_action_mapping.json'
|
||||
ANALOG_MAPPING_JSON = 'analog_action_mapping.json'
|
||||
EMPTY_SLOT = dict(name='', location='', length=-1, start=-1, end=-1, rate=1)
|
||||
PATH_TO_DATA_OBJECTS = '/home/pi/r_e_c_u_r/json_objects/'
|
||||
PATH_TO_EXTERNAL_DEVICES = '/media/pi'
|
||||
@@ -51,6 +52,7 @@ class Data(object):
|
||||
|
||||
self.key_mappings = self._read_json(self.KEYPAD_MAPPING_JSON)
|
||||
self.midi_mappings = self._read_json(self.MIDI_MAPPING_JSON)
|
||||
self.analog_mappings = self._read_json(self.ANALOG_MAPPING_JSON)
|
||||
|
||||
@staticmethod
|
||||
def create_empty_bank():
|
||||
|
||||
5
json_objects/analog_action_mapping.json
Normal file
5
json_objects/analog_action_mapping.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"7": {
|
||||
"DEFAULT": ["set_the_current_video_alpha_continuous"]
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
{
|
||||
"control_change 0": {
|
||||
"DEFAULT": ["set_the_current_video_alpha_cc"]
|
||||
"DEFAULT": ["set_the_current_video_alpha_continuous"]
|
||||
},
|
||||
"control_change 1": {
|
||||
"DEFAULT": ["set_the_next_video_alpha_cc"]
|
||||
"DEFAULT": ["set_the_next_video_alpha_continuous"]
|
||||
},
|
||||
"control_change 2": {
|
||||
"DEFAULT": ["set_the_camera_alpha_cc"]
|
||||
"DEFAULT": ["set_the_camera_alpha_continuous"]
|
||||
},
|
||||
"control_change 3": {
|
||||
"DEFAULT": ["set_the_camera_colour_u_with_cc"]
|
||||
"DEFAULT": ["set_the_camera_colour_u_continuous"]
|
||||
},
|
||||
"control_change 4": {
|
||||
"DEFAULT": ["set_the_camera_colour_v_with_cc"]
|
||||
"DEFAULT": ["set_the_camera_colour_v_continuous"]
|
||||
},
|
||||
"note_on 72": {
|
||||
"NAV_BROWSER": ["move_browser_selection_up"],
|
||||
|
||||
@@ -1,5 +1,25 @@
|
||||
{
|
||||
"capture": {
|
||||
"TYPE": {
|
||||
"action": "update_capture_settings",
|
||||
"options": [
|
||||
"piCamera",
|
||||
"piCaptureSd1"
|
||||
],
|
||||
"value": "piCaptureSd1"
|
||||
},
|
||||
"PICAPTURE_INPUT": {
|
||||
"action": "change_piCapture_input",
|
||||
"options": [
|
||||
"auto",
|
||||
"video1",
|
||||
"video2",
|
||||
"video3",
|
||||
"svideo",
|
||||
"component"
|
||||
],
|
||||
"value": "video1"
|
||||
},
|
||||
"DEVICE": {
|
||||
"action": "update_capture_settings",
|
||||
"options": [
|
||||
@@ -87,6 +107,14 @@
|
||||
}
|
||||
},
|
||||
"other": {
|
||||
"ANALOG_INPUT": {
|
||||
"action": null,
|
||||
"options": [
|
||||
"enabled",
|
||||
"disabled"
|
||||
],
|
||||
"value": "disabled"
|
||||
},
|
||||
"DEV_MODE_RESET": {
|
||||
"action": "switch_dev_mode",
|
||||
"options": [
|
||||
|
||||
@@ -11,6 +11,7 @@ from display_centre.display import Display
|
||||
from display_centre.messages import MessageHandler
|
||||
from user_input.numpad_input import NumpadInput
|
||||
from user_input.midi_input import MidiInput
|
||||
from user_input.analog_input import AnalogInput
|
||||
from video_centre.video_driver import VideoDriver
|
||||
from video_centre.capture import Capture
|
||||
import data_centre
|
||||
@@ -39,6 +40,7 @@ actions = Actions(tk, message_handler, data, video_driver, capture, display)
|
||||
|
||||
numpad_input = NumpadInput(tk, message_handler, display, actions, data)
|
||||
midi_input = MidiInput(tk, message_handler, display, actions, data)
|
||||
analog_input = AnalogInput(tk, message_handler, display, actions, data)
|
||||
|
||||
actions.check_and_set_output_mode_on_boot()
|
||||
actions.check_dev_mode()
|
||||
|
||||
68
user_input/analog_input.py
Normal file
68
user_input/analog_input.py
Normal file
@@ -0,0 +1,68 @@
|
||||
import Adafruit_GPIO.SPI as SPI
|
||||
import Adafruit_MCP3008
|
||||
|
||||
class AnalogInput(object):
|
||||
def __init__(self, root, message_handler, display, actions, data):
|
||||
self.root = root
|
||||
self.message_handler = message_handler
|
||||
self.display = display
|
||||
self.actions = actions
|
||||
self.data = data
|
||||
self.analog_mappings = data.analog_mappings
|
||||
self.midi_device = None
|
||||
self.analog_delay = 50
|
||||
|
||||
SPI_PORT = 1
|
||||
SPI_DEVICE = 2
|
||||
self.analog_input = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
|
||||
self.check_if_listening_enabled()
|
||||
|
||||
|
||||
def check_if_listening_enabled(self):
|
||||
if self.data.settings['other']['ANALOG_INPUT']['value'] == 'enabled':
|
||||
self.poll_analog_inputs()
|
||||
else:
|
||||
self.root.after(1000, self.check_if_listening_enabled)
|
||||
|
||||
def poll_analog_inputs(self):
|
||||
if self.data.settings['other']['ANALOG_INPUT']['value'] == 'enabled':
|
||||
for i in range(0,8):
|
||||
if str(i) in self.analog_mappings:
|
||||
print('{} is in the mapping'.format(i))
|
||||
reading = self.analog_input.read_adc(i)
|
||||
self.run_action_for_mapped_channel(i, reading)
|
||||
self.root.after(self.analog_delay, self.poll_analog_inputs)
|
||||
else:
|
||||
self.check_if_listening_enabled()
|
||||
|
||||
def run_action_for_mapped_channel(self, channel, channel_value):
|
||||
this_mapping = self.analog_mappings[str(channel)]
|
||||
if self.data.control_mode in this_mapping:
|
||||
mode = self.data.control_mode
|
||||
elif 'DEFAULT' in this_mapping:
|
||||
mode = 'DEFAULT'
|
||||
|
||||
if self.data.function_on and len(this_mapping[mode]) > 1:
|
||||
method_name = this_mapping[mode][1]
|
||||
self.data.function_on = False
|
||||
else:
|
||||
method_name = this_mapping[mode][0]
|
||||
|
||||
if channel_value is not None:
|
||||
norm_channel_value = channel_value/1023
|
||||
else:
|
||||
norm_channel_value = None
|
||||
|
||||
print('the action being called is {}'.format(method_name))
|
||||
self.call_method_name(method_name, norm_channel_value)
|
||||
## not sure whether we want to update the screen in general; here - probably not most of the time ...
|
||||
#if 'cc' not in message_name:
|
||||
# self.display.refresh_display()
|
||||
|
||||
def call_method_name(self, method_name, argument=None):
|
||||
if argument is not None:
|
||||
getattr(self.actions, method_name)(argument)
|
||||
else:
|
||||
getattr(self.actions, method_name)()
|
||||
|
||||
|
||||
@@ -91,9 +91,13 @@ class MidiInput(object):
|
||||
method_name = this_mapping[mode][0]
|
||||
|
||||
print('the action being called is {}'.format(method_name))
|
||||
self.call_method_name(method_name, mapped_message_value)
|
||||
## only update screen if not cc - seeing if cc can respond faster if not refreshing screen on every action
|
||||
if 'cc' not in message_name:
|
||||
if mapped_message_value is not None:
|
||||
norm_message_value = mapped_message_value/127
|
||||
else:
|
||||
norm_message_value = None
|
||||
self.call_method_name(method_name, norm_message_value)
|
||||
## only update screen if not continuous - seeing if cc can respond faster if not refreshing screen on every action
|
||||
if 'continuous' not in message_name:
|
||||
self.display.refresh_display()
|
||||
|
||||
def call_method_name(self, method_name, argument=None):
|
||||
|
||||
@@ -141,8 +141,9 @@ class VideoPlayer:
|
||||
self.set_alpha_value(255)
|
||||
|
||||
def set_alpha_value(self, amount):
|
||||
self.omx_player.set_alpha(amount)
|
||||
self.alpha = amount
|
||||
if self.omx_player:
|
||||
self.omx_player.set_alpha(amount)
|
||||
self.alpha = amount
|
||||
|
||||
def seek(self, amount):
|
||||
position = self.get_position()
|
||||
|
||||
Reference in New Issue
Block a user