-
Notifications
You must be signed in to change notification settings - Fork 0
/
ardPullerTempoDB.py
executable file
·90 lines (87 loc) · 3.23 KB
/
ardPullerTempoDB.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python
import serial
import re
import os
import sys
import datetime
import random
import pprint
from tempodb import Client, DataPoint
API_KEY = 'mykey'
API_SECRET = 'mysecret'
# Main Function
if __name__ == '__main__':
#my $isXUp = `pidof /usr/bin/Xorg`;
#if ($isXUp ne "")
# my $nvidiatemp = `nvidia-settings -q gpucoretemp -t`;
# print "GPU: $1,\n";
AMIXER = '/usr/bin/amixer'
DEBUG = 0
#my $ardVendor = "2341";
#my $ardProdID = "0001";
ardPort = "/dev/arduinouno" #should be in a conf file
#ardPort = "/dev/ttyACM0" #should be in a conf file
#my $ardLocation = `udevadm info -a -p \$(udevadm info -q path -n $ardDev)`; or use this to make sure this is an arduino
#Better use lsusb and avoid this nasty idea, got a webcam that is USB ACM and screws it all
#Or use inotify?
print "ardPort: ",ardPort
ser = serial.Serial(ardPort, 9600)
temp=light=slide=volvalue=vollimitup=vollimitdown=volstep=0
audioIface = 'PCM Playback Volume'
amixervals = os.popen(AMIXER+" -c 0 cget name='"+audioIface+"'").read()
#numid=32,iface=MIXER,name='Master Playback Volume'
# type=INTEGER,access=rw---R--,values=1,min=0,max=64,step=0
# values=62
#| dBscale-min=-64.00dB,step=1.00dB,mute=0
volRegEx = re.compile("numid=.*[\r\n]*.*min=([^,]*),max=([^,]*),step.*[\r\n]*.*values=([0-9]*)[\r\n]*",re.MULTILINE)
volData = volRegEx.search(amixervals)
if volData:
vollimitdown = volData.group(1)
vollimitup = volData.group(2)
volvalue = int(volData.group(3))
else:
print "AMIXER -c 0 cget name='",audioIface,"' didnt return the right results"
sys.exit()
volstep = (int(vollimitup) - int(vollimitdown)) / 10
print "[INIT]: ",AMIXER," limits from ",vollimitdown," to ",vollimitup,". Current volume is ",volvalue,". Volume Step is ",volstep
i=0
tempArray = []
lightArray = []
softArray = []
client = Client(API_KEY, API_SECRET)
while 1:
sensors = ser.readline()
#Temp: 26.66. Light: 125. softPot: 99
sensorsRegEx = re.compile("Temp: ([0-9.]*). Light: (\d{0,3}). softPot: (\d{0,3})")
sensorsLine = sensorsRegEx.search(sensors)
if i == 1000:
sys.stderr.write("Sending data to tempodb...\n")
client.write_key("light", lightArray)
client.write_key("soft", softArray)
client.write_key("temp", tempArray)
tempArray = []
lightArray = []
softArray = []
i = 0
i+=1
if sensorsLine:
temp = sensorsLine.group(1)
light = sensorsLine.group(2)
slide = int(sensorsLine.group(3))
curtime = datetime.datetime.now()
tempArray.append(DataPoint(curtime,float(temp)))
lightArray.append(DataPoint(curtime,float(light)))
softArray.append(DataPoint(curtime,float(slide)))
#sys.stdout.write("[PULL] "+temp+".."+light+".."+slide+" from: "+sensors)
#print "[PULL] ",float(temp),"..",float(light),"..",float(slide)
volvalue = int(os.popen(AMIXER+" -c 0 cget name='"+audioIface+"'|grep :|cut -f2 -d=|cut -d, -f1").read())
if slide > 240:
if volvalue < vollimitup:
volvalue+=volstep
print "[INFO]: Setting Volume + 10 = ",volvalue
os.popen(AMIXER+" -q cset name='"+audioIface+"' "+str(volvalue)).read()
elif slide < 20:
if volvalue > vollimitdown:
volvalue-=volstep
print "[INFO]: Setting Volume - 10 = ",volvalue
os.popen(AMIXER+" -q cset name='"+audioIface+"' "+str(volvalue)).read()