-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathshell.py
56 lines (35 loc) · 1.4 KB
/
shell.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
import statistics
import time
import IPython
import wintertools.oscilloscope
from libgemini import fallback_calibration, gemini, oscillators, reference_calibration
gem = gemini.Gemini.get()
def set_oscillators_to_note(note, calibration=reference_calibration):
freq = oscillators.midi_note_to_frequency(note)
period = oscillators.frequency_to_timer_period(freq)
charge_code_castor = oscillators.calibrated_charge_code_for_period(
period, calibration.castor
)
charge_code_pollux = oscillators.calibrated_charge_code_for_period(
period, calibration.pollux
)
print(
f"Note: {note}, Freq: {freq}, Charge codes: {charge_code_castor}, {charge_code_pollux}"
)
gem.set_dac(charge_code_castor, 2048, charge_code_pollux, 2048)
gem.set_frequency(0, freq)
gem.set_frequency(1, freq)
def sweep_notes(calibration=reference_calibration):
for n in range(12, 94):
set_oscillators_to_note(n, calibration=calibration)
time.sleep(0.5)
def sweep_notes_with_ref():
return sweep_notes(calibration=reference_calibration)
def sweep_notes_with_fallback():
return sweep_notes(calibration=fallback_calibration)
def get_oscilloscope():
return wintertools.oscilloscope.Oscilloscope()
def read_adc_average(channel, count=100):
return statistics.mean([gem.read_adc(channel) for _ in range(count)])
gem.enter_calibration_mode()
IPython.embed()