added uninterruptable comms loop
This commit is contained in:
@@ -3,12 +3,14 @@ import utime
|
|||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
import sys
|
import sys
|
||||||
|
import select
|
||||||
|
|
||||||
lens_cs = machine.Pin(7, machine.Pin.IN)
|
lens_cs = machine.Pin(7, machine.Pin.IN)
|
||||||
body_cs = machine.Pin(8, machine.Pin.OUT)
|
body_cs = machine.Pin(8, machine.Pin.OUT)
|
||||||
vd_lens = machine.Pin(9, machine.Pin.OUT)
|
vd_lens = machine.Pin(9, machine.Pin.OUT)
|
||||||
tx_pin = machine.Pin(16, machine.Pin.OUT)
|
tx_pin = machine.Pin(16, machine.Pin.OUT)
|
||||||
|
|
||||||
|
poll_obj = ''
|
||||||
|
|
||||||
focal_length = 0
|
focal_length = 0
|
||||||
aperture_raw = 0
|
aperture_raw = 0
|
||||||
@@ -16,18 +18,22 @@ focus = 0
|
|||||||
focus_limit = 0
|
focus_limit = 0
|
||||||
status_sent = False
|
status_sent = False
|
||||||
|
|
||||||
counter = 0
|
counter = 0 #VD_LENS pulse counter
|
||||||
ap = 2.8
|
ap = 4884 #aperture
|
||||||
ap_odd = False
|
ap_odd = False #variable for controlling one bit in send messages
|
||||||
ap_closing = True
|
|
||||||
|
focus_pos = 0 #focus position to be set manually
|
||||||
|
|
||||||
af_in_progress = False
|
af_in_progress = False
|
||||||
focus_mode = "MF" #AF/MF
|
focus_mode = "MF" #AF/MF
|
||||||
|
|
||||||
focus_min = 16116
|
focus_min = 12000
|
||||||
focus_max = 19415
|
focus_max = 23000
|
||||||
|
ap_min = 4884
|
||||||
|
ap_max = 6132
|
||||||
|
|
||||||
focus_pos = 0
|
focus_pos = 0
|
||||||
|
change_focus = False
|
||||||
|
|
||||||
utime.sleep(1)
|
utime.sleep(1)
|
||||||
vd_lens.value(1)
|
vd_lens.value(1)
|
||||||
@@ -50,16 +56,48 @@ time.sleep_ms(20)
|
|||||||
|
|
||||||
rx_ack = False
|
rx_ack = False
|
||||||
|
|
||||||
|
def Comms_Init():
|
||||||
|
global poll_obj
|
||||||
|
|
||||||
|
poll_obj = select.poll()
|
||||||
|
poll_obj.register(sys.stdin, select.POLLIN)
|
||||||
|
|
||||||
|
def Comms_Read():
|
||||||
|
global poll_obj, ap, focus_mode, change_focus, focus_pos
|
||||||
|
|
||||||
|
poll_results = poll_obj.poll(1)
|
||||||
|
if poll_results:
|
||||||
|
rw = sys.stdin.readline().strip()
|
||||||
|
rw = rw.upper()
|
||||||
|
if "APERTURE" in rw:
|
||||||
|
data = rw.split(' ')
|
||||||
|
ap = int(data[1])
|
||||||
|
if "FOCUS" in rw:
|
||||||
|
data = rw.split(' ')
|
||||||
|
focus_pos = int(data[1])
|
||||||
|
change_focus = True
|
||||||
|
if "AF" in rw:
|
||||||
|
focus_mode = "AF"
|
||||||
|
if "MF" in rw:
|
||||||
|
focus_mode = "MF"
|
||||||
|
|
||||||
|
|
||||||
def focal_length_conv(raw):
|
def focal_length_conv(raw):
|
||||||
return (math.exp((raw+92063.3)/8082.9)+406.979)/3256.82
|
return (math.exp((raw+92063.3)/8082.9)+406.979)/3256.82
|
||||||
|
|
||||||
def aperture(value, leftMin=2.8, leftMax=16, rightMin=4884, rightMax=6132):
|
def aperture_count(value, leftMin=2.8, leftMax=16, rightMin=4884, rightMax=6132):
|
||||||
leftSpan = leftMax - leftMin
|
leftSpan = leftMax - leftMin
|
||||||
rightSpan = rightMax - rightMin
|
rightSpan = rightMax - rightMin
|
||||||
|
|
||||||
valueScaled = float(value - leftMin) / float(leftSpan)
|
valueScaled = float(value - leftMin) / float(leftSpan)
|
||||||
return rightMin + (valueScaled * rightSpan)
|
return rightMin + (valueScaled * rightSpan)
|
||||||
|
|
||||||
|
def aperture(value):
|
||||||
|
if value < ap_min:
|
||||||
|
value = ap_min
|
||||||
|
if value > ap_max:
|
||||||
|
value = ap_max
|
||||||
|
return value
|
||||||
|
|
||||||
def rx_end(pin):
|
def rx_end(pin):
|
||||||
rx_ack = True
|
rx_ack = True
|
||||||
@@ -218,22 +256,26 @@ def shutdown():
|
|||||||
time.sleep_ms(6)
|
time.sleep_ms(6)
|
||||||
|
|
||||||
def normal_loop():
|
def normal_loop():
|
||||||
global ap, ap_closing, af_in_progress, focus_mode, focus_pos
|
global ap, ap_closing, af_in_progress, focus_mode, focus_pos, change_focus
|
||||||
|
|
||||||
vd_pulse()
|
if change_focus:
|
||||||
time.sleep_ms(10)
|
move_focus(focus_pos)
|
||||||
send_aperture(ap)
|
change_focus = False
|
||||||
send_focus(focus_mode, af_in_progress)
|
else:
|
||||||
time.sleep_ms(6)
|
vd_pulse()
|
||||||
print_rx()
|
time.sleep_ms(10)
|
||||||
vd_pulse()
|
send_aperture(ap)
|
||||||
time.sleep_ms(10)
|
send_focus(focus_mode, af_in_progress)
|
||||||
send_aperture(ap)
|
time.sleep_ms(6)
|
||||||
send_focus(focus_mode, af_in_progress)
|
print_rx()
|
||||||
time.sleep_ms(6)
|
vd_pulse()
|
||||||
print_rx()
|
time.sleep_ms(10)
|
||||||
|
send_aperture(ap)
|
||||||
|
send_focus(focus_mode, af_in_progress)
|
||||||
|
time.sleep_ms(6)
|
||||||
|
print_rx()
|
||||||
|
|
||||||
|
Comms_Init()
|
||||||
lens_cs.irq(handler=rx_end, trigger=machine.Pin.IRQ_FALLING)
|
lens_cs.irq(handler=rx_end, trigger=machine.Pin.IRQ_FALLING)
|
||||||
|
|
||||||
vd_pulse()
|
vd_pulse()
|
||||||
@@ -266,23 +308,8 @@ tx(b'\xf0\x19\x00\x02\x00\x0a\xff\xff\x03\x00\x00\x00\x00\x00\x3f\x00\x00\x00\x0
|
|||||||
print_rx()
|
print_rx()
|
||||||
time.sleep_ms(10)
|
time.sleep_ms(10)
|
||||||
|
|
||||||
"""
|
|
||||||
for i in range(0,120):
|
|
||||||
normal_loop()
|
|
||||||
move_focus(15000)
|
|
||||||
for i in range(0,120):
|
|
||||||
normal_loop()
|
|
||||||
move_focus(17000)
|
|
||||||
for i in range(0,120):
|
|
||||||
normal_loop()
|
|
||||||
move_focus(20000)
|
|
||||||
for i in range(0,120):
|
|
||||||
normal_loop()
|
|
||||||
"""
|
|
||||||
#send_af()
|
|
||||||
#for i in range(0,6):
|
|
||||||
# normal_loop()
|
|
||||||
#stop_af()
|
|
||||||
while True:
|
while True:
|
||||||
normal_loop()
|
normal_loop()
|
||||||
|
Comms_Read()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user