Skip to content

Commit

Permalink
Merge pull request #135 from gyroflow/fix-device-settings
Browse files Browse the repository at this point in the history
Fix device settings
  • Loading branch information
DusKing1 authored Jun 10, 2022
2 parents 7f174ec + ec826e7 commit 185fe84
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 38 deletions.
33 changes: 14 additions & 19 deletions src/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def rec(self):
def timeout(self):
self.transation_time = 0


def no_cam(self):
if vram.shutter_state == "starting":
vram.shutter_state = "recording"
Expand Down Expand Up @@ -155,7 +154,7 @@ def rec_release(self):
print("shutter send: ", self.REC_RELEASE)

async def uart_handler(self):
print("Sony MTP UART handler running")
print(str(time.ticks_us()) + " [ OK ] Sony MTP UART handler running")
swriter = asyncio.StreamWriter(self.uart, {})
sreader = asyncio.StreamReader(self.uart)
while True:
Expand Down Expand Up @@ -192,7 +191,7 @@ def __init__(self):
print(str(time.ticks_us()) + " [Create] Zcam UART object")
self.task_mode = "ASYNC"
self.ASYNC_MSG_ENABLE = (0xEA02022A01).to_bytes(5, 'big')
self.ASYNC_MSG_DISABLE = (0xEA02022A00).to_bytes(5, 'big')
self.ASYNC_MSG_DISABLE= (0xEA02022A00).to_bytes(5, 'big')

self.START_REC = (0xEA020105).to_bytes(4, 'big')
self.START_REC_ACK = (0xEA02028500).to_bytes(5, 'big')
Expand All @@ -207,7 +206,7 @@ def __init__(self):

async def uart_handler(self):
import ubinascii
print("ZCAM UART handler running")
print(str(time.ticks_us()) + " [ OK ] ZCAM UART handler running")
swriter = asyncio.StreamWriter(self.uart, {})
sreader = asyncio.StreamReader(self.uart)
while True:
Expand Down Expand Up @@ -245,22 +244,17 @@ async def uart_handler(self):
ext2 = data[16:20]
print("ext2:", ubinascii.hexlify(ext2))



def set_mode(self):
self.uart.write(self.ASYNC_MSG_ENABLE)
# self.uart.write(self.ASYNC_MSG_DISABLE)
# print("FS send: ", self.ASYNC_MSG_ENABLE.from_bytes())

def rec(self):
self.transation_time += 5
if self.transation_time == 500:
if vram.shutter_state == "starting":
self.uart.write(self.START_REC)
print("shutter send: ", self.START_REC)
elif vram.shutter_state == "stopping":
self.uart.write(self.STOP_REC)
print("shutter send: ", self.STOP_REC)
elif self.transation_time > 500:
pass

Expand Down Expand Up @@ -289,37 +283,38 @@ def __init__(self):
print(str(time.ticks_us()) + " [ OK ] LANC object")

def lanc_falling(self, pin):
self.tx.value(0)
# self.tx.value(0)
self.falling_flag = True

def uart_handler(self):
print("LANC UART handler running")
while True:
if self.falling_flag == True:
# self.tx.value(1)
if self.rec_trigger == True:
# handle LANC falling events
duaration = time.ticks_us() - self.falling_time # calc duaration between two falling events
self.falling_time = time.ticks_us() # update falling timestamp
if self.byte_flag == "BYTE1":
self.byte_flag = "BYTE0"# next falling event: send byte 0
time.sleep_us(240)
self.tx.value(0)
time.sleep_us(208)
self.tx.value(1)
time.sleep_us(207)
time.sleep_us(208)
self.tx.value(0)
time.sleep_us(208)
self.tx.value(1)
self.byte_flag = "BYTE0"# next falling event: send byte 0
self.rec_repeat -= 1
if self.rec_repeat <=0:
self.rec_trigger = False
self.rec_repeat = 0
self.rec_trigger_state = True
elif self.byte_flag == "BYTE0" and duaration > 7000:
self.byte_flag = "BYTE1"# next falling event: send byte 1
self.tx.value(1)
time.sleep_us(314)
time.sleep_us(302)
self.tx.value(0)
time.sleep_us(208)
self.tx.value(1)
self.byte_flag = "BYTE1"# next falling event: send bytes 1
else: # elif duaration <= 7000:# LANC is sending other bytes, ignore them
self.tx.value(1)
self.falling_flag = False # clear falling flag
Expand All @@ -329,14 +324,14 @@ def uart_handler(self):

def rec(self):
self.transation_time += 5
if self.transation_time == 800:
if self.transation_time == 50:
self.rec_trigger = True # trigger rec
self.byte_flag = "BYTE0"
self.test.value(0)
self.rec_repeat = 7 # repeat 7 times
self.rec_repeat = 6 # repeat 12 times
# note that sometimes the first three frames might corrupted,
# so we repeat for 7 times to make sure the camera recieves at least 4 valid frames
elif self.transation_time > 800:
elif self.transation_time > 50:
if self.rec_trigger_state == True:
self.test.value(1)
self.transation_time = 0
Expand Down
9 changes: 9 additions & 0 deletions src/crsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# along with flowshutter. If not, see <https://www.gnu.org/licenses/>.
import target, vram
import time
import uasyncio as asyncio

class CRSF:
def __init__(self):
Expand All @@ -40,6 +41,14 @@ def __init__(self):
992,992,992,992,992,992,992,992)
print(str(time.ticks_us()) + " [ OK ] CRSF object")

async def uart_handler(self):
print(str(time.ticks_us()) + " [ OK ] CRSF listener running")
swriter = asyncio.StreamWriter(self.uart, {})
sreader = asyncio.StreamReader(self.uart)
while True:
data = await sreader.read(n=-1)
print("FC sent:", data)

def _toggle_marker_(self): #toggle the marker
if self.marker == 'L':
self.marker = 'H'
Expand Down
17 changes: 11 additions & 6 deletions src/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@
timer0 = Timer(0) # 200Hz task scheduler
timer0.init(period=5, mode=Timer.PERIODIC, callback=task.scheduler)

if task.ui.camera.task_mode == "ASYNC":
import uasyncio as asyncio
loop = asyncio.get_event_loop()
loop.create_task(task.ui.camera.uart_handler())
loop.run_forever()
elif task.ui.camera.task_mode == "THREAD":
if task.ui.camera.task_mode == "THREAD":
import _thread
import machine
machine.freq(240000000)
_thread.start_new_thread(task.ui.camera.uart_handler, ())

import uasyncio as asyncio
loop = asyncio.get_event_loop()
loop.create_task(task.fc_link.uart_handler())
if task.ui.camera.task_mode == "ASYNC":
loop.create_task(task.ui.camera.uart_handler())
loop.run_forever()

10 changes: 5 additions & 5 deletions src/sha.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
},
{
"name": "camera.py",
"sha1": "80fe5150287ed769406f4afa387222e89dc87030"
"sha1": "4bf6bf2dd246f0a8af04b5762d1d94a8eaa59015"
},
{
"name": "canvas.py",
"sha1": "0f8f941827b42740548f6884dc68696369256ae8"
},
{
"name": "crsf.py",
"sha1": "f9645d23fb977c027ec6e861e23040034ea5bba7"
"sha1": "212866f53581ee858d28595b425a2549b3d523d6"
},
{
"name": "entry.py",
"sha1": "57e0d58313a51e62ebc9fc4383e0d2404b31b096"
"sha1": "bef31a2e101d91ca1dea5d285183feae23851c0e"
},
{
"name": "main.py",
Expand Down Expand Up @@ -58,7 +58,7 @@
},
{
"name": "task.py",
"sha1": "d5b5589e679c82177646c3d4456cb82865d7c311"
"sha1": "72aa3d79322250b1096e4309bf9449031d053a5c"
},
{
"name": "ui.py",
Expand All @@ -70,7 +70,7 @@
},
{
"name": "vram.py",
"sha1": "f91f025f93c90bf29aa5bf4ff7a5cb235ed67539"
"sha1": "041eca7b468f11cd11d160a0743c688b1267f16e"
},
{
"name": "wlan.py",
Expand Down
6 changes: 3 additions & 3 deletions src/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class Task:
def __init__(self):
print(str(time.ticks_us()) + " [Create] Task scheduler")
self.crsf = crsf.CRSF()
self.fc_link = crsf.CRSF()
self.mem_opt_interval = 100 # gc per 100ms
self.battery = peripherals.Battery()
self.buttons = peripherals.Buttons()
Expand All @@ -34,8 +34,8 @@ def mem_opt(self):
def scheduler(self, t):
self.mem_opt_interval -= 5

# task1 - CRSF sender
self.crsf.send_packet(t)
# task1 - FC RC packeet sender
self.fc_link.send_packet(t)

# task2 - OLED display or GC
if vram.oled_tasklist != []:
Expand Down
12 changes: 7 additions & 5 deletions src/vram.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
ota_source = "GitHub"
ota_channel = "stable"

camera_protocol_range = ["NO", "MMTRY GND", "3V3 Schmitt", "Sony MTP", "ZCAM UART", "LANC"]
camera_protocol_range = ["NO", "MMTRY GND", "3V3 Schmitt", "Sony MTP", "ZCAM UART"]
# camera_protocol_range = ["NO", "MMTRY GND", "3V3 Schmitt", "Sony MTP", "ZCAM UART", "LANC"]
device_mode_range = ["MASTER"]
inject_mode_range = ["OFF", "ON"]
ota_source_range = ["GitHub", "Gitee"]
Expand All @@ -73,10 +74,11 @@ def update_camera_preset():# per camera protocol
if camera_protocol == "Sony MTP":
device_mode = "SLAVE"
device_mode_range = ["SLAVE", "MASTER/SLAVE"]
if camera_protocol == "ZCAM UART":
device_mode = "TEST"
device_mode_range = ["MASTER", "TEST"]
elif camera_protocol == "NO" or camera_protocol == "MMTRY GND" or camera_protocol == "3V3 Schmitt" or camera_protocol == "LANC":
# if camera_protocol == "ZCAM UART":
# device_mode = "MASTER"
# device_mode_range = ["MASTER", "TEST"]
# elif camera_protocol == "NO" or camera_protocol == "MMTRY GND" or camera_protocol == "3V3 Schmitt" or camera_protocol == "LANC":
elif camera_protocol == "NO" or camera_protocol == "MMTRY GND" or camera_protocol == "3V3 Schmitt" or camera_protocol == "ZCAM UART":
device_mode = "MASTER"
device_mode_range = ["MASTER"]

Expand Down

0 comments on commit 185fe84

Please sign in to comment.