Skip to content

Commit

Permalink
PiLink 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
asb2m10 committed Feb 23, 2016
1 parent 8d0b72b commit 975bc7c
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 93 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ PiLink tries to mimick some of the functionalities of the "defunc" Missing Link

You can configure the device by using : http://`pi_ip_address`:8080

Version 0.2
-----------
* Now comes with [AngularJS Material](https://material.angularjs.org/latest/) UI

Prerequisites
-------------
* Linux/UNIX experience for installing
Expand All @@ -23,3 +27,6 @@ TODO
* More stats and logging
* Make a WIFI access point configuration out of the box for PiLink

SCREENSHOT
----------
![Alt Text](docs/pilink_0.2.jpg)
5 changes: 3 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# this file is automatically generated
sendhost = '192.168.1.27'
# this file was automatically generated

sendhost = '192.168.1.54'
sendport = 9000
receiveport = 8000
mididev = '/dev/midi2'
Expand Down
4 changes: 2 additions & 2 deletions docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ the latest version of PiLink to the home directory and unzip-it. This will creat
automatically.

```
/home/pi $ unzip PiLink-master.zip
/home/pi $ unzip pilink-master.zip
```

Then add the 'execute' right to the main startup script :
Expand All @@ -43,7 +43,7 @@ test if everything is working. Used CTRL-C to stop the process once you are done

You can test the web interface if you point your browser directly to your Pi device

http://`raspberry pi hostname`:8080
http://raspberry pi hostname:8080

Once it is working, you can added it to the OS startup script. Use your favorite editor to modify
/etc/rc.local and add this line at the end :
Expand Down
Binary file added docs/pilink_0.2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions pilink.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import config

def startup() :
#deamonize(router.midiOutput)
#deamonize(router.midiInput)
deamonize(router.midiOutput)
deamonize(router.midiInput)
deamonize(router.oscInput)
web.start()

Expand Down
16 changes: 7 additions & 9 deletions router.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
outq = Queue.Queue()

def parseHexValue(v) :
if v.startswith("0x") or v.startswith("0X") :
if v.startswith("0x") or v.startswith("0X") :
return int(v,16)
else :
return int(v,10)
Expand Down Expand Up @@ -151,7 +151,7 @@ def osc2Midi(msg) :
if action == 'note' :
midiMsg = [ ( '0x90' + chl ), int(msgToken[0]), int(msgToken[1]) ]
else :
print("Unknown OSC action %s" % action)
stats.error("Unknown OSC action %s" % action)

return midiMsg

Expand All @@ -173,15 +173,15 @@ def oscInput() :
parsedMsg = []
oscParser(msg, parsedMsg)

print("==> received %s" % repr(parsedMsg))
stats.oscin(str(parsedMsg))

for i in parsedMsg :
midiMsg.extend(osc2Midi(i))
stats.addoscin()

except Exception as e :
stats.error(e)
exc_type, exc_value, exc_traceback = sys.exc_info()
print(repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))
print(str(traceback.format_exception(exc_type, exc_value, exc_traceback)))
if len(midiMsg) != 0 :
outq.put_nowait(midiMsg)
except Exception as e :
Expand Down Expand Up @@ -217,7 +217,6 @@ def midiInput() :
sysexBuffer.append(i)
if i == 0xF7 :
toSend.extend(sysexBuffer)
stats.addsysex()
sysexBuffer = []
elif i == 0xF0 :
sysexBuffer.append(i)
Expand All @@ -227,6 +226,7 @@ def midiInput() :
if len(toSend) == 0 :
continue

stats.midiin(toSend);
outq.put_nowait(toSend)

if config.sendport != 0 :
Expand All @@ -243,8 +243,6 @@ def midiInput() :

networkConn = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
networkConn.sendto(oscMsg, (config.sendhost, config.sendport))

stats.addmidiin()
except Exception as e :
stats.error(e)
print("**> Midi Input Exception cought: %s" % e)
Expand Down Expand Up @@ -273,7 +271,7 @@ def midiOutput() :
display = ""
for i in midiMsg :
display = display + "0x%x " % i
print("<== sending midi %s" % display)
stats.midiout(display)
os.write(midiConn, bytearray(midiMsg))
except Exception as e :
stats.error(e)
Expand Down
45 changes: 24 additions & 21 deletions stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,34 @@
"""

sysex = 0
midiin = 0
oscin = 0
lasterror = ""
log = ""
activity = { 'midiin': 0, 'oscin' : 0, 'midiout' : 0 }
messages = [ "pilink started." ]

def addsysex() :
global sysex
sysex += 1
def midiin(msg) :
activity['midiin'] = activity['midiin'] + 1
log("==> midiin: " + msg)

def addmidiin() :
global midiin
midiin += 1
def midiout(msg) :
activity['midiout'] = activity['midiout'] + 1
log("<== midiout " + msg)

def addoscin() :
global oscin
oscin += 1
def oscin(msg) :
activity['oscin'] = activity['oscin'] + 1
log("==> osc " + msg)

def error(msg) :
if len(messages) > 1024 :
messages.pop(0)
messages.append("ERROR: " + str(msg))

def log(msg) :
global log
log = msg
print msg
if len(messages) > 1024 :
messages.pop(0)
messages.append(msg)

def error(msg) :
global lasterror
lasterror = msg

def getStats() :
return "midi %d osc %d sysex %d error %s" % (midiin, oscin, sysex, lasterror)
ret = {}
ret['messages'] = messages[::-1]
ret['activity'] = activity
return ret
18 changes: 12 additions & 6 deletions web.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ def config(self, data, handler) :
for i in dir(config) :
if not i.startswith("__") :
ret[i] = eval("config.%s" % i)

#ret['mididev_lst'] = " ".join(glob.glob("/dev/midi*"))
ret['mididev_lst'] = "/dev/midi2 /dev/midi01"
ret['mididev_lst'] = glob.glob("/dev/midi*")
ret['clientip'] = handler.client_address[0]
return ret;
else :
print data
return ret;
config.sendhost = data['sendhost']
config.sendport = data['sendport']
config.receiveport = data['receiveport']
config.mididev = data['mididev']
pilink.saveConfig()
ret['return'] = "OKOK"
return ret;


def shutdown(self, data, handler) :
pilink.deamonize(pilink.shutdown)
Expand All @@ -52,6 +55,9 @@ def reboot(self, data, handler) :
pilink.deamonize(pilink.reboot)
return { "be right" : "back" }

def logs(self, data, handler) :
return stats.getStats();

### =====================================================================
def call(self, name, data, handler) :
calle = getattr(self, name)
Expand Down
38 changes: 8 additions & 30 deletions web/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
<html>
<head>
<link rel="stylesheet" href="css/angular-material.min.css">
<link rel="stylesheet" href="css/modal.css">
</head>
<style>
.contentdemoBasicUsage div.demo-content {
height: 600px; }
.contentdemoBasicUsage div[ng-controller] {
height: 100%;
padding-bottom: 15px; }
.contentdemoBasicUsage md-content {
padding: 24px; }
</style>

<body ng-app="app">
<script src="lib/angular.min.js"></script>
Expand All @@ -32,7 +24,6 @@ <h2>
<span flex></span>
</div>
</md-toolbar>

<md-content layout-padding>
<div>
<form ng-submit="processForm()">
Expand All @@ -55,8 +46,7 @@ <h2>
<md-input-container class="md-block" flex-gt-sm>
<label>Midi Device</label>
<md-select ng-model="formData.mididev">
<md-select-label>{{ formData.mididev }}</md-select-label>
<md-option ng-repeat="dev_lst in formData.mididev_lst" ng-value="dev_lst">
<md-option ng-repeat="dev_lst in mididev_lst" ng-value="dev_lst">
{{dev_lst}}
</md-option>
</md-select>
Expand All @@ -70,33 +60,21 @@ <h2>
</form>

</div>
<!-- </md-content>

<md-content>-->
<div layout="column" ng-cloak>
<div ng-cloak>
<md-toolbar>
<div class="md-toolbar-tools">
<md-button class="md-icon-button" aria-label="Refresh">
<md-button class="md-icon-button" aria-label="Refresh" ng-click="refreshLogs()">
<md-icon md-svg-icon="img/icons/ic_refresh_24px.svg"></md-icon>
</md-button>
<h2 class="md-flex">Logging</h2>
<span flex></span>
midi in : {{midiin}} midi out : {{midiout}} osc : {{osc}}
</div>
</md-toolbar>
<md-content flex="" layout-padding="">
<p>Lorem ipsum dolor sit amet, ne quod novum mei. Sea omnium invenire mediocrem at, in lobortis </p>
<p>Lorem ipsum dolor sit amet, ne quod novum mei. Sea omnium invenire mediocrem at, in lobortis </p>
<p>Lorem ipsum dolor sit amet, ne quod novum mei. Sea omnium invenire mediocrem at, in lobortis </p>
<p>Lorem ipsum dolor sit amet, ne quod novum mei. Sea omnium invenire mediocrem at, in lobortis </p>
<p>Lorem ipsum dolor sit amet, ne quod novum mei. Sea omnium invenire mediocrem at, in lobortis </p>
<p>Lorem ipsum dolor sit amet, ne quod novum mei. Sea omnium invenire mediocrem at, in lobortis </p>
<p>Lorem ipsum dolor sit amet, ne quod novum mei. Sea omnium invenire mediocrem at, in lobortis </p>
<p>Lorem ipsum dolor sit amet, ne quod novum mei. Sea omnium invenire mediocrem at, in lobortis </p>
<p>Lorem ipsum dolor sit amet, ne quod novum mei. Sea omnium invenire mediocrem at, in lobortis </p>
<p>Lorem ipsum dolor sit amet, ne quod novum mei. Sea omnium invenire mediocrem at, in lobortis </p>
<p>Lorem ipsum dolor sit amet, ne quod novum mei. Sea omnium invenire mediocrem at, in lobortis </p>

<md-content flex="" layout-padding="column">
<pre>{{completeMsg}}</pre>
</md-content>

</div>
</md-content>
</md-content>
Expand Down
81 changes: 60 additions & 21 deletions web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,71 @@
"use strict";

var app = angular.module('app', ['ngMaterial']);
app.controller('formController', ['$scope', '$http', function($scope,$http) {

// create a blank object to hold our form information
// $scope will allow this to pass between controller and view

app.controller('formController', ['$scope', '$http', '$mdDialog', function($scope,$http, $mdDialog) {
$scope.formData = {};

$http({ method : 'GET', url : 'config' }).success(function(data) {
$scope.formData = data;
console.log(data)
});
$scope.midiin = 0;
$scope.midiout = 0;
$scope.osc = 0;
$scope.completeMsg = "";

$scope.alert = $mdDialog.alert({ title: 'Please wait',
content: 'Rebooting PiLink....', ok: "WAIT"});


$scope.refreshLogs = function() {
$http.get('logs').then(function(resp) {
$scope.midiin = resp.data.activity.midiin
$scope.midiout = resp.data.activity.midiout
$scope.osc = resp.data.activity.oscin
$scope.completeMsg = resp.data.messages.join("\n")
}, function (resp) {
console.log(resp)
$scope.midiin = -1
$scope.midiout = -1
$scope.osc = -1
$scope.completeMsg = "!!! UNABLE TO GET PILINK LOGS !!!"
})
}

$scope.rebootDevice = function() {
$http.get('reboot')
setTimeout(function() { location.reload() } , 5000);
$mdDialog.show( $scope.alert ).finally(function() { location.reload() } )
}


$scope.processForm = function() {
$http({
method : 'POST',
url : 'config',
data : $scope.formData,
}).success(function(data) {
if (!data.success) {
//$scope.errorName = data.errors.name;
} else {
//$scope.errorName = '';
}
});
$http.post('config', $scope.formData).then(function(resp) {
$scope.rebootDevice()
}, function(resp) {
console.log(resp)
alert("ERROR: Something went wrong with the PiLink config update.")
})
};

}]);

$http.get('config').then(function(resp) {
$scope.formData = resp.data;
$scope.mididev_lst = resp.data['mididev_lst']
}, function(resp) {
console.log(resp)
});

$scope.refreshLogs()
}]);

})();

/*
// this is kept so the log(completeMsg) can contain html
angular.module('app').filter('to_trusted', ['$sce', function($sce) {
return function(text) {
return $sce.trustAsHtml(text);
};
<div ng-bind-html="completeMsg | to_trusted"></div>
}]);
*/

0 comments on commit 975bc7c

Please sign in to comment.