diff --git a/Software/e-mount.py b/Software/e-mount.py index 47fe8be..3392352 100644 --- a/Software/e-mount.py +++ b/Software/e-mount.py @@ -3,12 +3,14 @@ import utime import time import math import sys +import select lens_cs = machine.Pin(7, machine.Pin.IN) body_cs = machine.Pin(8, machine.Pin.OUT) vd_lens = machine.Pin(9, machine.Pin.OUT) tx_pin = machine.Pin(16, machine.Pin.OUT) +poll_obj = '' focal_length = 0 aperture_raw = 0 @@ -16,18 +18,22 @@ focus = 0 focus_limit = 0 status_sent = False -counter = 0 -ap = 2.8 -ap_odd = False -ap_closing = True +counter = 0 #VD_LENS pulse counter +ap = 4884 #aperture +ap_odd = False #variable for controlling one bit in send messages + +focus_pos = 0 #focus position to be set manually af_in_progress = False focus_mode = "MF" #AF/MF -focus_min = 16116 -focus_max = 19415 +focus_min = 12000 +focus_max = 23000 +ap_min = 4884 +ap_max = 6132 focus_pos = 0 +change_focus = False utime.sleep(1) vd_lens.value(1) @@ -50,16 +56,48 @@ time.sleep_ms(20) 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): 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 rightSpan = rightMax - rightMin valueScaled = float(value - leftMin) / float(leftSpan) 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): rx_ack = True @@ -218,22 +256,26 @@ def shutdown(): time.sleep_ms(6) 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() - time.sleep_ms(10) - send_aperture(ap) - send_focus(focus_mode, af_in_progress) - time.sleep_ms(6) - print_rx() - vd_pulse() - time.sleep_ms(10) - send_aperture(ap) - send_focus(focus_mode, af_in_progress) - time.sleep_ms(6) - print_rx() + if change_focus: + move_focus(focus_pos) + change_focus = False + else: + vd_pulse() + time.sleep_ms(10) + send_aperture(ap) + send_focus(focus_mode, af_in_progress) + time.sleep_ms(6) + print_rx() + vd_pulse() + 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) 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() 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: normal_loop() + Comms_Read()