Compare commits
No commits in common. "7eb81404f095b310f6f8895335eb863199f6322e" and "c2e1ac3ae9880ecfee1a5aab80b748e9ddc073a9" have entirely different histories.
7eb81404f0
...
c2e1ac3ae9
5 changed files with 5 additions and 152 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +0,0 @@
|
|||
node_modules
|
||||
*.o
|
||||
/build
|
67
main.js
67
main.js
|
@ -1,67 +0,0 @@
|
|||
const GPIO = require("onoff").Gpio;
|
||||
const WS = require("ws");
|
||||
|
||||
const HEARTBEAT_INT = 400;
|
||||
|
||||
const button = new GPIO(4, "in", "both", {debounceTimeout: 30, activeLow: true});
|
||||
const ledOnAir = new GPIO(24, "low");
|
||||
const ledReady = new GPIO(23, "low");
|
||||
|
||||
const ws = new WS('ws://10.0.0.4:2000');
|
||||
|
||||
let currentID = 0;
|
||||
|
||||
let heartBeat;
|
||||
|
||||
ws.on('open', () => {
|
||||
|
||||
button.watch((e, value) => {
|
||||
if(e) {
|
||||
console.error("Error on button watch:", e);
|
||||
return;
|
||||
}
|
||||
if(value) {
|
||||
ws.send(JSON.stringify({type: 'button-press'}));
|
||||
} else {
|
||||
ws.send(JSON.stringify({type: 'button-release'}));
|
||||
}
|
||||
|
||||
ledOnAir.write(value, (e) => e && console.error("Error writing to led: ", e));
|
||||
});
|
||||
heartBeat = setInterval(() => {
|
||||
button.read((e, buttonState) => {
|
||||
console.log("Button state!", buttonState);
|
||||
if(e) {
|
||||
return console.error("Error reading button state!", e);
|
||||
}
|
||||
ws.send(JSON.stringify({
|
||||
type: 'button-update',
|
||||
body: {buttonState}
|
||||
}));
|
||||
});
|
||||
}, 400);
|
||||
ledReady.write(1, console.error);
|
||||
});
|
||||
|
||||
ws.on('error', (e) => {
|
||||
console.error(e);
|
||||
cleanup();
|
||||
process.exit();
|
||||
});
|
||||
|
||||
function cleanup() {
|
||||
ledOnAir.unexport();
|
||||
ledReady.unexport();
|
||||
button.unexport();
|
||||
ws.close();
|
||||
if(heartBeat) {
|
||||
cancelInterval(heartBeat);
|
||||
heartBeat = null;
|
||||
}
|
||||
}
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
|
15
main.py
15
main.py
|
@ -2,21 +2,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
import socket
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
CONNECT_TO = ("10.0.0.4", 2000)
|
||||
|
||||
|
||||
def buttonEventHandler(value):
|
||||
print "buton event!"
|
||||
if value is 0:
|
||||
GPIO.output(24, True)
|
||||
sock.sendall("button_press")
|
||||
print('Button Pressed...')
|
||||
else:
|
||||
GPIO.output(24, False)
|
||||
sock.sendall("button_release")
|
||||
print('Button Released...')
|
||||
|
||||
def main():
|
||||
|
@ -29,15 +23,12 @@ def main():
|
|||
#GPIO.add_event_detect(23, GPIO.FALLING)
|
||||
#GPIO.add_event_callback(23, buttonEventHandler)
|
||||
try:
|
||||
sock.connect(CONNECT_TO)
|
||||
while True:
|
||||
GPIO.wait_for_edge(23, GPIO.BOTH, bouncetime=100)
|
||||
GPIO.wait_for_edge(23, GPIO.BOTH)
|
||||
buttonEventHandler(GPIO.input(23))
|
||||
except:
|
||||
except KeyboardInterrupt as e:
|
||||
GPIO.cleanup()
|
||||
sock.close()
|
||||
raise
|
||||
|
||||
|
||||
if __name__== "__main__":
|
||||
main()
|
||||
|
|
65
miccontrol.c
65
miccontrol.c
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* miccontrol.c
|
||||
* Copyright (C) 2018 jshaver <jshaver@je-laptop>
|
||||
*
|
||||
* Distributed under terms of the MIT license.
|
||||
*/
|
||||
|
||||
#include "stdio.h"
|
||||
#include "pulse/pulseaudio.h"
|
||||
|
||||
const char *NAME = "miccontrol";
|
||||
|
||||
static pa_context *context = NULL;
|
||||
static pa_mainloop_api *mainloop_api = NULL;
|
||||
static pa_mainloop *mainloop = NULL;
|
||||
|
||||
void querySources(pa_context *c, void *userdata);
|
||||
void handleSourceList(struct pa_context *c, const pa_source_info *i, int eol, void *userdata);
|
||||
|
||||
int main() {
|
||||
int ret = 1;
|
||||
mainloop = pa_mainloop_new();
|
||||
mainloop_api = pa_mainloop_get_api(mainloop);
|
||||
context = pa_context_new(mainloop_api, NULL);
|
||||
pa_context_set_state_callback(context, querySources, NULL);
|
||||
pa_context_connect(context, NULL, 0, NULL);
|
||||
//pa_operation_unref(getSourceOp);
|
||||
|
||||
pa_mainloop_run(mainloop, &ret);
|
||||
|
||||
pa_context_unref(context);
|
||||
pa_mainloop_free(mainloop);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void querySources(pa_context *c, void *userdata) {
|
||||
if(pa_context_get_state(context) != PA_CONTEXT_READY) {
|
||||
return;
|
||||
}
|
||||
pa_operation *getSourceOp = NULL;
|
||||
getSourceOp = pa_context_get_source_info_list(context, handleSourceList, NULL);
|
||||
if(!getSourceOp) {
|
||||
} else {
|
||||
pa_operation_state_t state = pa_operation_get_state(getSourceOp);
|
||||
switch(state) {
|
||||
case PA_OPERATION_RUNNING:
|
||||
break;
|
||||
case PA_OPERATION_DONE:
|
||||
break;
|
||||
case PA_OPERATION_CANCELLED:
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void handleSourceList(pa_context *c, const pa_source_info *i, int eol, void *userdata) {
|
||||
printf("Callback called...\n");
|
||||
printf("eol is %d\n", eol);
|
||||
printf(i->description);
|
||||
printf("\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -14,16 +14,13 @@ def main():
|
|||
|
||||
sourceNumber = getSourceSelection(sources)
|
||||
|
||||
server = SocketServer.TCPServer(LISTEN_ON, RequestHandler)
|
||||
|
||||
try:
|
||||
server = SocketServer.TCPServer(LISTEN_ON, RequestHandler)
|
||||
server.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
server.shutdown()
|
||||
server.server_close()
|
||||
except:
|
||||
server.shutdown()
|
||||
server.server_close()
|
||||
|
||||
|
||||
def getSourceSelection(sources):
|
||||
|
@ -61,7 +58,7 @@ class RequestHandler(SocketServer.StreamRequestHandler):
|
|||
message = line.strip()
|
||||
if message in messageTypes:
|
||||
messageTypes[message]()
|
||||
print("message: ".message)
|
||||
self.wfile.write(message)
|
||||
print("Closed!")
|
||||
self.request.close()
|
||||
|
Loading…
Reference in a new issue