remote debugging changes

This commit is contained in:
Peter L 2021-11-10 13:15:26 +01:00
parent d9c9d673fc
commit 761e0f6c8d
2 changed files with 43 additions and 22 deletions

View file

@ -6,12 +6,12 @@ _PWM_MAX = const(65535)
_PWM_FREQ = const(2000) _PWM_FREQ = const(2000)
_PIN_EN_MOTOR_VERT = const(14) _PIN_EN_MOTOR_VERT = const(14)
_PIN_A_MOTOR_VERT = const(13) _PIN_A_MOTOR_VERT = const(12)
_PIN_B_MOTOR_VERT = const(12) _PIN_B_MOTOR_VERT = const(13)
_PIN_EN_MOTOR_HOR = const(15) _PIN_EN_MOTOR_HOR = const(15)
_PIN_A_MOTOR_HOR = const(11) _PIN_A_MOTOR_HOR = const(10)
_PIN_B_MOTOR_HOR = const(10) _PIN_B_MOTOR_HOR = const(11)
_PIN_EN_BACKLIGHT = const(17) _PIN_EN_BACKLIGHT = const(17)
_PIN_A_BACKLIGHT = const(18) _PIN_A_BACKLIGHT = const(18)
@ -26,10 +26,10 @@ _PIN_LED_BLU_BTN = const(4)
_PIN_RED_BTN = const(3) _PIN_RED_BTN = const(3)
_PIN_BLU_BTN = const(5) _PIN_BLU_BTN = const(5)
_PIN_SENS_END_VERT = const(0) _PIN_SENS_END_VERT = const(9)
_PIN_SENS_CNT_VERT = const(0) _PIN_SENS_CNT_VERT = const(7)
_PIN_SENS_END_HOR = const(0) _PIN_SENS_END_HOR = const(6)
_PIN_SENS_CNT_HOR = const(0) _PIN_SENS_CNT_HOR = const(8)
CMD_MOT_V = 'V' # run vertical motor CMD_MOT_V = 'V' # run vertical motor
CMD_MOT_H = 'H' # run horizontal motor CMD_MOT_H = 'H' # run horizontal motor
@ -94,7 +94,12 @@ pwm_mh.freq(_PWM_FREQ)
pin_mv_a = Pin(_PIN_A_MOTOR_VERT, Pin.OUT) pin_mv_a = Pin(_PIN_A_MOTOR_VERT, Pin.OUT)
pin_mv_b = Pin(_PIN_B_MOTOR_VERT, Pin.OUT) pin_mv_b = Pin(_PIN_B_MOTOR_VERT, Pin.OUT)
pin_mh_a = Pin(_PIN_A_MOTOR_HOR, Pin.OUT) pin_mh_a = Pin(_PIN_A_MOTOR_HOR, Pin.OUT)
pin_mh_b = Pin(_PIN_B_MOTOR_HOR) pin_mh_b = Pin(_PIN_B_MOTOR_HOR, Pin.OUT)
pin_bl_a = Pin(_PIN_A_BACKLIGHT, Pin.OUT)
pin_bl_b = Pin(_PIN_B_BACKLIGHT, Pin.OUT)
pin_fl_a = Pin(_PIN_A_FRONTLIGHT, Pin.OUT)
pin_fl_b = Pin(_PIN_B_FRONTLIGHT, Pin.OUT)
led_blu = Pin(_PIN_LED_BLU_BTN, Pin.OUT) led_blu = Pin(_PIN_LED_BLU_BTN, Pin.OUT)
led_red = Pin(_PIN_LED_RED_BTN, Pin.OUT) led_red = Pin(_PIN_LED_RED_BTN, Pin.OUT)
@ -122,15 +127,16 @@ def motor_hor(*opts):
def _motorctrl(scroll: Scroll, steps: int, *opts): def _motorctrl(scroll: Scroll, steps: int, *opts):
end = scroll.c + steps end = scroll.c + steps
while True: print(f'motorctrl, end={end}, scroll.c={scroll.c}')
err = end - scroll.c #while True:
if abs(err) > 4: # err = end - scroll.c
speed = (err / (2 * steps)) + 0.5 # if abs(err) > 4:
scroll.speed = int(100 * speed) # speed = (err / (2 * steps)) + 0.5
else: # scroll.speed = int(100 * speed)
scroll.speed = 0 # else:
break # scroll.speed = 0
time.sleep_ms(5) # break
# time.sleep_ms(5)
def backlight(*opts): def backlight(*opts):
_fade_led(pwm_bl, *opts) _fade_led(pwm_bl, *opts)
@ -171,6 +177,8 @@ def user_interaction(timeout):
b, r = btn_blu.value(), btn_red.value() b, r = btn_blu.value(), btn_red.value()
if (b + r) < 2: if (b + r) < 2:
tmr.deinit() tmr.deinit()
led_blu.value(0)
led_red.value(0)
return 'B' if not b else 'R' return 'B' if not b else 'R'
time.sleep_ms(50) time.sleep_ms(50)
tmr.deinit() tmr.deinit()
@ -223,6 +231,10 @@ def parseCmd(cmd_str: str):
if __name__ == '__main__': if __name__ == '__main__':
pin_bl_a.value(1)
pin_bl_b.value(0)
pin_fl_a.value(1)
pin_fl_b.value(0)
rxData = '' rxData = ''
while True: while True:
rxBuf = uart0.read(1) rxBuf = uart0.read(1)
@ -230,4 +242,4 @@ if __name__ == '__main__':
rxData += rxBuf.decode('utf-8') rxData += rxBuf.decode('utf-8')
if rxData.endswith('\n'): if rxData.endswith('\n'):
parseCmd(rxData.strip()) parseCmd(rxData.strip())
rxData = '' rxData = ''

View file

@ -1,4 +1,4 @@
from machine import Pin, Timer from machine import UART, Pin, Timer
import time import time
led = Pin(25, Pin.OUT) led = Pin(25, Pin.OUT)
@ -41,5 +41,14 @@ def recording(timeout):
return 'OK' return 'OK'
if __name__ == '__main__': if __name__ == '__main__':
print(user_interaction(20)) #print(user_interaction(20))
#print(recording(20)) #Print
uart0 = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1))
rxData = ''
while True:
rxBuf = uart0.read(1)
if rxBuf is not None:
rxData += rxBuf.decode('utf-8')
if rxData.endswith('\n'):
print(rxData.strip())
rxData = ''