Skip to content

Commit 914abb7

Browse files
committed
🎉 Initial Commit
0 parents  commit 914abb7

5 files changed

Lines changed: 220 additions & 0 deletions

File tree

.idea/.gitignore

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lookup_tables.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
INPUT_SELECTOR = {
2+
"SUB_ADDR": 0x0,
3+
1: 0x3,
4+
2: 0x2,
5+
3: 0x1,
6+
4: 0x0
7+
}
8+
9+
INPUT_GAIN = {
10+
"SUB_ADDR": 0x1,
11+
0: 0x0,
12+
2: 0x1,
13+
4: 0x2,
14+
6: 0x3,
15+
8: 0x4,
16+
10: 0x5,
17+
12: 0x6,
18+
14: 0x7,
19+
16: 0x8,
20+
18: 0x9,
21+
20: 0xA,
22+
22: 0xB,
23+
24: 0xC,
24+
26: 0xD,
25+
28: 0xE,
26+
30: 0xF,
27+
}
28+
29+
VOLUME = {
30+
"SUB_ADDR": 0x2,
31+
"MUTE": 0x70
32+
}
33+
34+
BASS_GAIN = {
35+
"SUB_ADDR": 0x3,
36+
-14: 0x0,
37+
-12: 0x1,
38+
-10: 0x2,
39+
-8: 0x3,
40+
-6: 0x4,
41+
-4: 0x5,
42+
-2: 0x6,
43+
0: 0x7,
44+
2: 0xE,
45+
4: 0xD,
46+
6: 0xC,
47+
8: 0xB,
48+
10: 0xA,
49+
12: 0x9,
50+
14: 0x8,
51+
}
52+
53+
MID_GAIN = {
54+
"SUB_ADDR": 0x4,
55+
-14: 0x0,
56+
-12: 0x1,
57+
-10: 0x2,
58+
-8: 0x3,
59+
-6: 0x4,
60+
-4: 0x5,
61+
-2: 0x6,
62+
0: 0x7,
63+
2: 0xE,
64+
4: 0xD,
65+
6: 0xC,
66+
8: 0xB,
67+
10: 0xA,
68+
12: 0x9,
69+
14: 0x8,
70+
}
71+
72+
TREBLE_GAIN = {
73+
"SUB_ADDR": 0x5,
74+
-14: 0x0,
75+
-12: 0x1,
76+
-10: 0x2,
77+
-8: 0x3,
78+
-6: 0x4,
79+
-4: 0x5,
80+
-2: 0x6,
81+
0: 0x7,
82+
2: 0xE,
83+
4: 0xD,
84+
6: 0xC,
85+
8: 0xB,
86+
10: 0xA,
87+
12: 0x9,
88+
14: 0x8,
89+
}
90+
91+
SPEAKER_ATT_R = {
92+
"SUB_ADDR": 0x6,
93+
"MUTE": 0x78,
94+
}
95+
96+
SPEAKER_ATT_L = {
97+
"SUB_ADDR": 0x6,
98+
"MUTE": 0x78,
99+
}

main.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import uvicorn
2+
from fastapi import FastAPI
3+
from starlette.middleware.cors import CORSMiddleware
4+
5+
from sepve import SEPVE
6+
7+
addr = 0x88
8+
9+
app = FastAPI(title='SEPVE-WebControl', version='0.0.1 RC1')
10+
11+
app.add_middleware(
12+
CORSMiddleware,
13+
allow_origins=['*'],
14+
allow_credentials=True,
15+
allow_methods=['*'],
16+
allow_headers=['*']
17+
)
18+
19+
sepve = SEPVE(addr)
20+
21+
22+
@app.post('/select_input/{input_id}')
23+
def selectInput(input_id: int):
24+
sepve.setInputChannelFunction(channel=input_id)
25+
26+
27+
@app.post('/intput_gain/{gain}')
28+
def setInputGain(gain: int):
29+
sepve.setInputGainFunction(gain=gain)
30+
31+
32+
@app.post('/volume/{volume}')
33+
def setVolume(volume: int):
34+
sepve.setVolumeFunction(volume=volume)
35+
36+
37+
@app.post('/bass_gain/{gain}')
38+
def setBassGain(gain: int):
39+
sepve.setBassGainFunction(gain=gain)
40+
41+
42+
@app.post('/mid_gain/{gain}')
43+
def setMidGain(gain: int):
44+
sepve.setMidGainFunction(gain=gain)
45+
46+
47+
@app.post('/treble_gain/{gain}')
48+
def setTrebleGain(gain: int):
49+
sepve.setTrebleGainFunction(gain=gain)
50+
51+
52+
@app.post('/speaker_att_r/{att}')
53+
def setSpeakerAttR(att):
54+
sepve.setSpeakerAttRFunction(att=att)
55+
56+
57+
@app.post('/speaker_att_l/{att}')
58+
def setSpeakerAttL(att):
59+
sepve.setSpeakerAttLFunction(att=att)
60+
61+
62+
if __name__ == "__main__":
63+
uvicorn.run(app, host="10.0.0.40", port=9000)

requierments.txt

Whitespace-only changes.

sepve.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from smbus2 import SMBus
2+
from lookup_tables import *
3+
4+
5+
class SEPVE:
6+
CURRENT_INPUT: int = 2
7+
INPUT_GAIN_dB: int = 28
8+
VOLUME: str = "MUTE"
9+
BASS_dB: int = 0
10+
MID_dB: int = 2
11+
TREBLE_dB: int = 2
12+
SPEAKER: str = "MUTE"
13+
i2c_addr = 0x88
14+
bus = None
15+
16+
def __init__(self, addr):
17+
self.i2c_addr = addr
18+
self.bus = SMBus(1)
19+
20+
async def setInputChannelFunction(self, channel: int):
21+
self.bus.write_byte_data(self.i2c_addr, INPUT_SELECTOR.get("SUB_ADDR"), INPUT_SELECTOR.get(channel))
22+
23+
async def setInputGainFunction(self, gain: int):
24+
self.bus.write_byte_data(self.i2c_addr, INPUT_GAIN.get("SUB_ADDR"), INPUT_GAIN.get(gain))
25+
26+
async def setVolumeFunction(self, volume):
27+
if volume == "MUTE":
28+
volume = VOLUME.get("MUTE")
29+
self.bus.write_byte_data(self.i2c_addr, VOLUME.get("SUB_ADDR"), volume)
30+
31+
async def setBassGainFunction(self, gain: int):
32+
self.bus.write_byte_data(self.i2c_addr, BASS_GAIN.get("SUB_ADDR"), BASS_GAIN.get(gain))
33+
34+
async def setMidGainFunction(self, gain: int):
35+
self.bus.write_byte_data(self.i2c_addr, TREBLE_GAIN.get("SUB_ADDR"), TREBLE_GAIN.get(gain))
36+
37+
async def setTrebleGainFunction(self, gain: int):
38+
self.bus.write_byte_data(self.i2c_addr, TREBLE_GAIN.get("SUB_ADDR"), TREBLE_GAIN.get(gain))
39+
40+
async def setSpeakerAttRFunction(self, att):
41+
if att == "MUTE":
42+
att = SPEAKER_ATT_R.get("MUTE")
43+
self.bus.write_byte_data(self.i2c_addr, SPEAKER_ATT_R.get("SUB_ADDR"), att)
44+
45+
async def setSpeakerAttLFunction(self, att):
46+
if att == "MUTE":
47+
att = SPEAKER_ATT_L.get("MUTE")
48+
self.bus.write_byte_data(self.i2c_addr, SPEAKER_ATT_L.get("SUB_ADDR"), att)

0 commit comments

Comments
 (0)