moved mopidy-switcher to own repo
This commit is contained in:
parent
bc14d1e138
commit
9f10867e12
8 changed files with 0 additions and 334 deletions
|
@ -1,20 +0,0 @@
|
|||
|
||||
BIN_DIR=/usr/local/bin/mopidy-switcher
|
||||
SYSV_DIR=/etc/init.d
|
||||
SYSD_DIR=/etc/systemd/system
|
||||
|
||||
install-sysv: service/mopidy-switcher
|
||||
install -m 755 -t $(SYSV_DIR) service/mopidy-switcher
|
||||
|
||||
install-sysd: service/mopidy-switcher.service
|
||||
install -m 644 -t $(SYSD_DIR) service/mopidy-switcher.service
|
||||
|
||||
install-switcher: mopidy-switcher.py
|
||||
install -m 755 -t $(BIN_DIR) -D mopidy-switcher.py
|
||||
|
||||
install: install-sysd install-switcher
|
||||
|
||||
uninstall:
|
||||
rm -rf $(BIN_DIR)
|
||||
rm -f $(SYSV_DIR)/mopidy-switcher
|
||||
rm -f $(SYSD_DIR)/mopidy-switcher.service
|
|
@ -1,33 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{34cbb86d-9088-41d8-b0b9-68a131d30188}</ProjectGuid>
|
||||
<ProjectHome />
|
||||
<StartupFile>moped.py</StartupFile>
|
||||
<SearchPath />
|
||||
<WorkingDirectory>.</WorkingDirectory>
|
||||
<OutputPath>.</OutputPath>
|
||||
<ProjectTypeGuids>{888888a0-9f3d-457c-b088-3a5042f75d52}</ProjectTypeGuids>
|
||||
<LaunchProvider>Standard Python launcher</LaunchProvider>
|
||||
<InterpreterId>{2af0f10d-7135-4994-9156-5d01c9c11b7e}</InterpreterId>
|
||||
<InterpreterVersion>2.7</InterpreterVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'" />
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition=" '$(VisualStudioVersion)' == '' ">10.0</VisualStudioVersion>
|
||||
<PtvsTargetsFile>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets</PtvsTargetsFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="moped.py" />
|
||||
<Compile Include="SwitchMopidy.py" />
|
||||
<Compile Include="UserLed.py" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InterpreterReference Include="{2af0f10d-7135-4994-9156-5d01c9c11b7e}\2.7" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(PtvsTargetsFile)" Condition="Exists($(PtvsTargetsFile))" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" Condition="!Exists($(PtvsTargetsFile))" />
|
||||
</Project>
|
|
@ -1,20 +0,0 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.24720.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "Moped", "Moped.pyproj", "{34CBB86D-9088-41D8-B0B9-68A131D30188}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{34CBB86D-9088-41D8-B0B9-68A131D30188}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{34CBB86D-9088-41D8-B0B9-68A131D30188}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -1,40 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import ConfigParser
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
yellowLed = 15
|
||||
redLed = 17
|
||||
greenLed = 18
|
||||
|
||||
mopidyConf = '/etc/mopidy/mopidy.conf'
|
||||
|
||||
def setLeds(yellow, red, green):
|
||||
GPIO.output(yellowLed, yellow)
|
||||
GPIO.output(redLed, red)
|
||||
GPIO.output(greenLed, green)
|
||||
|
||||
def getConfiguredLedColor():
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.read(mopidyConf)
|
||||
|
||||
return config.get('moped-switcher', 'led')
|
||||
|
||||
def setConfiguredLedColor():
|
||||
ledColor = getConfiguredLedColor()
|
||||
|
||||
if ledColor == 'yellow':
|
||||
setLeds(1, 0, 0)
|
||||
elif ledColor == 'red':
|
||||
setLeds(0, 1, 0)
|
||||
elif ledColor == 'green':
|
||||
setLeds(0, 0, 1)
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(yellowLed, GPIO.OUT)
|
||||
GPIO.setup(redLed, GPIO.OUT)
|
||||
GPIO.setup(greenLed, GPIO.OUT)
|
||||
|
||||
setConfiguredLedColor()
|
||||
|
||||
GPIO.cleanup()
|
|
@ -1,45 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from time import sleep
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
yellowLed = 15
|
||||
redLed = 17
|
||||
greenLed = 18
|
||||
|
||||
buttonPin = 27
|
||||
|
||||
sleepTimes = [0.75, 0.5, 0.25, 0.125, 0.0625]
|
||||
sleepTimeIndex = 0
|
||||
|
||||
def buttonHandler(channel):
|
||||
global sleepTimeIndex
|
||||
print 'button pushed'
|
||||
sleepTimeIndex = (sleepTimeIndex + 1) % len(sleepTimes)
|
||||
|
||||
def setLeds(yellow, red, green):
|
||||
GPIO.output(yellowLed, yellow)
|
||||
GPIO.output(redLed, red)
|
||||
GPIO.output(greenLed, green)
|
||||
|
||||
try:
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(yellowLed, GPIO.OUT)
|
||||
GPIO.setup(redLed, GPIO.OUT)
|
||||
GPIO.setup(greenLed, GPIO.OUT)
|
||||
|
||||
GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
|
||||
GPIO.add_event_detect(buttonPin, GPIO.FALLING, callback=buttonHandler, bouncetime=1000)
|
||||
|
||||
while True:
|
||||
setLeds(1, 0, 0)
|
||||
sleep(sleepTimes[sleepTimeIndex])
|
||||
setLeds(0, 1, 0)
|
||||
sleep(sleepTimes[sleepTimeIndex])
|
||||
setLeds(0, 0, 1)
|
||||
sleep(sleepTimes[sleepTimeIndex])
|
||||
finally:
|
||||
setLeds(0, 0, 0)
|
||||
GPIO.cleanup()
|
|
@ -1,105 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import glob
|
||||
import os
|
||||
import subprocess
|
||||
import ConfigParser
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
yellowLed = 15
|
||||
redLed = 17
|
||||
greenLed = 18
|
||||
|
||||
buttonPin = 27
|
||||
dummyPin = 1
|
||||
|
||||
mopidyConf = '/etc/mopidy/mopidy.conf'
|
||||
userDir = '/etc/mopidy/conf.user/'
|
||||
|
||||
def setLeds(yellow, red, green):
|
||||
GPIO.output(yellowLed, yellow)
|
||||
GPIO.output(redLed, red)
|
||||
GPIO.output(greenLed, green)
|
||||
|
||||
def getConfiguredLedColor():
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.read(mopidyConf)
|
||||
|
||||
return config.get('moped-switcher', 'led')
|
||||
|
||||
def setConfiguredLedColor():
|
||||
ledColor = getConfiguredLedColor()
|
||||
|
||||
if ledColor == 'yellow':
|
||||
setLeds(1, 0, 0)
|
||||
elif ledColor == 'red':
|
||||
setLeds(0, 1, 0)
|
||||
elif ledColor == 'green':
|
||||
setLeds(0, 0, 1)
|
||||
|
||||
def stopMopidy():
|
||||
command = ['service', 'mopidy', 'stop']
|
||||
subprocess.call(command, shell=False)
|
||||
|
||||
def startMopidy():
|
||||
command = ['service', 'mopidy', 'start']
|
||||
subprocess.call(command, shell=False)
|
||||
|
||||
def getConfigs():
|
||||
return sorted(glob.glob(os.path.join(userDir, '*.conf')))
|
||||
|
||||
def getCurrentConfig():
|
||||
if os.path.islink(mopidyConf):
|
||||
return os.path.realpath(mopidyConf)
|
||||
else:
|
||||
return None
|
||||
|
||||
def getNextConfig():
|
||||
currentConfig = getCurrentConfig()
|
||||
availableConfigs = getConfigs()
|
||||
currentIndex = availableConfigs.index(currentConfig)
|
||||
nextIndex = (currentIndex + 1) % len(availableConfigs)
|
||||
return availableConfigs[nextIndex]
|
||||
|
||||
def setConfig(newConfig):
|
||||
if os.path.islink(mopidyConf) and os.path.isfile(newConfig):
|
||||
os.unlink(mopidyConf)
|
||||
os.symlink(newConfig, mopidyConf)
|
||||
|
||||
def switchConfig():
|
||||
setConfig(getNextConfig())
|
||||
|
||||
def buttonHandler(channel):
|
||||
print 'Switching to ' + getNextConfig()
|
||||
try:
|
||||
setLeds(0, 0, 0)
|
||||
stopMopidy()
|
||||
switchConfig()
|
||||
startMopidy()
|
||||
setConfiguredLedColor()
|
||||
except OSError as e:
|
||||
print 'Error: ' + e.strerror
|
||||
|
||||
if __name__ == '__main__':
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
|
||||
GPIO.setup(yellowLed, GPIO.OUT)
|
||||
GPIO.setup(redLed, GPIO.OUT)
|
||||
GPIO.setup(greenLed, GPIO.OUT)
|
||||
|
||||
GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
GPIO.setup(dummyPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
|
||||
GPIO.add_event_detect(buttonPin, GPIO.FALLING, callback=buttonHandler, bouncetime=1000)
|
||||
|
||||
setConfiguredLedColor()
|
||||
|
||||
try:
|
||||
while True:
|
||||
GPIO.wait_for_edge(dummyPin, GPIO.RISING)
|
||||
except KeyboardInterrupt:
|
||||
print 'exiting'
|
||||
finally:
|
||||
setLeds(0, 0, 0)
|
||||
GPIO.cleanup()
|
|
@ -1,61 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: mopidy-switcher
|
||||
# Required-Start: $remote_fs $syslog mopidy
|
||||
# Required-Stop: $remote_fs $syslog mopidy
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Mopidy switcher initscript
|
||||
### END INIT INFO
|
||||
|
||||
# Change the next 3 lines to suit where you install your script and what you want to call it
|
||||
DIR=/usr/local/bin/mopidy-switcher
|
||||
DAEMON=$DIR/mopidy-switcher.py
|
||||
DAEMON_NAME=mopidy-switcher
|
||||
|
||||
# Add any command line options for your daemon here
|
||||
DAEMON_OPTS=""
|
||||
|
||||
# This next line determines what user the script runs as.
|
||||
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
|
||||
DAEMON_USER=root
|
||||
|
||||
# The process ID of the script when it runs is stored here:
|
||||
PIDFILE=/var/run/$DAEMON_NAME.pid
|
||||
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
do_start () {
|
||||
log_daemon_msg "Starting system $DAEMON_NAME daemon"
|
||||
start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --startas $DAEMON -- $DAEMON_OPTS
|
||||
log_end_msg $?
|
||||
}
|
||||
do_stop () {
|
||||
log_daemon_msg "Stopping system $DAEMON_NAME daemon"
|
||||
start-stop-daemon --stop --pidfile $PIDFILE --retry 10
|
||||
log_end_msg $?
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
|
||||
start|stop)
|
||||
do_${1}
|
||||
;;
|
||||
|
||||
restart|reload|force-reload)
|
||||
do_stop
|
||||
do_start
|
||||
;;
|
||||
|
||||
status)
|
||||
status_of_proc "$DAEMON_NAME" "$DAEMON" && exit 0 || exit $?
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|restart|status}"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
exit 0
|
|
@ -1,10 +0,0 @@
|
|||
[Unit]
|
||||
Description=Mopidy Switcher
|
||||
After=mopidy.service
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
ExecStart=/usr/local/bin/mopidy-switcher/mopidy-switcher.py
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in a new issue