iono pi max demo (drums)
+ fix spacing in ionopimax.py
This commit is contained in:
parent
99a58933ec
commit
bc7922f5c8
27
cfg/drums_cfg.py
Normal file
27
cfg/drums_cfg.py
Normal file
@ -0,0 +1,27 @@
|
||||
Node('relais.psi.ch',
|
||||
'relais test',
|
||||
'tcp://5000',
|
||||
)
|
||||
|
||||
Mod('rl',
|
||||
'frappy_psi.ionopimax.DigitalOutput',
|
||||
'left relais',
|
||||
addr = 'o1',
|
||||
value = 0, # start with relais off
|
||||
)
|
||||
|
||||
Mod('rr',
|
||||
'frappy_psi.ionopimax.DigitalOutput',
|
||||
'right relais',
|
||||
addr = 'o2',
|
||||
value = 0, # start with relais off
|
||||
)
|
||||
|
||||
Mod('drummer',
|
||||
'frappy_psi.drums.Drums',
|
||||
'drummer',
|
||||
target = 150,
|
||||
pattern='l2L2rl1R1L2',
|
||||
left='rl',
|
||||
right='rr',
|
||||
)
|
65
frappy_psi/drums.py
Normal file
65
frappy_psi/drums.py
Normal file
@ -0,0 +1,65 @@
|
||||
# *****************************************************************************
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation; either version 2 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# Module authors:
|
||||
# Markus Zolliker <markus.zolliker@psi.ch>
|
||||
# *****************************************************************************
|
||||
"""iono pi max relais drums
|
||||
|
||||
for demo purposes
|
||||
"""
|
||||
|
||||
from frappy.core import Module, Attached, FloatRange, StringType, Writable, Parameter
|
||||
|
||||
|
||||
class Drums(Writable):
|
||||
target = Parameter('drum speed', FloatRange(unit='beats/min'))
|
||||
left = Attached(Writable)
|
||||
right = Attached(Writable)
|
||||
pollinterval = Parameter('drum interval', FloatRange(0, 10, unit='s'), readonly=False)
|
||||
pattern = Parameter('''pattern
|
||||
|
||||
a string containing:
|
||||
L,R: left / right relais on
|
||||
l,r: left / right relais off
|
||||
blank: wait''', StringType(), readonly=False)
|
||||
_pos = 0
|
||||
_wait = 0
|
||||
|
||||
def initModule(self):
|
||||
super().initModule()
|
||||
self.actions = {'L': self.left, 'R': self.right}
|
||||
|
||||
def write_target(self, target):
|
||||
self.pollinterval = 60 / max(1, target)
|
||||
self.value = target
|
||||
|
||||
def doPoll(self):
|
||||
if not self.target:
|
||||
return
|
||||
if self._wait:
|
||||
self._wait -= 1
|
||||
return
|
||||
if self._pos >= len(self.pattern):
|
||||
self._pos = 0
|
||||
for i, action in enumerate(self.pattern[self._pos:]):
|
||||
upper = action.upper()
|
||||
relais = self.actions.get(action.upper())
|
||||
if relais:
|
||||
relais.write_target(upper == action) # True when capital letter
|
||||
else:
|
||||
self._wait = int(action) - 1
|
||||
self._pos += i + 1
|
||||
return
|
@ -25,6 +25,7 @@ from math import log
|
||||
|
||||
class Base:
|
||||
addr = Property('address', StringType())
|
||||
|
||||
def read(self, addr, scale=None):
|
||||
with open(f'/sys/class/ionopimax/{self.devclass}/{addr}') as f:
|
||||
result = f.read()
|
||||
@ -67,7 +68,6 @@ class AnalogInput(Base, Readable):
|
||||
return y0 + (y1 - y0) * (self.x - x0) / (x1 - x0)
|
||||
|
||||
|
||||
|
||||
class VoltageInput(AnalogInput):
|
||||
scale = 1e5
|
||||
|
||||
@ -75,6 +75,7 @@ class VoltageInput(AnalogInput):
|
||||
super().initModule()
|
||||
self.write(f'{self.addr}_mode','U')
|
||||
|
||||
|
||||
class LogVoltageInput(VoltageInput):
|
||||
|
||||
def read_value(self):
|
||||
@ -122,5 +123,3 @@ class VoltageOutput(AnalogOutput):
|
||||
self.write(f'{self.addr}_mode', 'V')
|
||||
self.write(f'{self.addr}', '0')
|
||||
self.write(f'{self.addr}_enabled', '1')
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user