Skip to content

Commit

Permalink
Small update on fastapi server
Browse files Browse the repository at this point in the history
  • Loading branch information
ranranking committed Dec 14, 2023
1 parent 79c87d8 commit 2b19764
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
14 changes: 9 additions & 5 deletions tools/example_request.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import requests
import time

url = "http://169.254.165.4:8000"
url = "http://localhost:8000"
#url = "http://localhost:8000"

test = "/start_viewer/"
single_run = "/start_viewer_single_loop/10"
single_run = "/start_viewer_single_loop/2"
compeleted = "/wait_for_viewer_completion/"

response = requests.get(url+single_run)
complete = requests.get(url+compeleted)
print(complete.json())
for i in range(4):
response = requests.get(url+single_run)
print(response.json)
complete = requests.get(url+compeleted)
print(complete.json())
time.sleep(5)
28 changes: 9 additions & 19 deletions tools/fastapiSIM.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
print("Not running on Pi")
GPIO = None

# Screen resolution
# Set parameters
mResolution = [1920, 1080]
mResolution = [800, 600]
#mResolution = [800, 600]
unitCellSize = 3
camTriggerPin = 26
currentWavelength = 0 # 488=0, 635=1
Expand Down Expand Up @@ -91,21 +91,9 @@ def __init__(self, update_func, display_size):
global camTriggerPin, nImages, iLoop, iCycle
self.camPin = camTriggerPin
self.iNumber = nImages
self.iLoop = iLoop
self.iCycle = iCycle
self.viewer_completed_event = Event()

def set_title(self, title):
pygame.display.set_caption(title)

def set_twait(self, tWait):
self.tWait = tWait

def set_loop(self, iLoop):
self.iLoop = iLoop

def set_cycle(self, iCycle):
self.iCycle = iCycle

def trigger(self, gpiopin):
GPIO.output(gpiopin, GPIO.HIGH)
Expand Down Expand Up @@ -141,7 +129,6 @@ def start(self):
running = False
pygame.display.quit()
task_lock = True
self.viewer_completed_event.set()

def update(index):
global currentWavelength
Expand Down Expand Up @@ -229,10 +216,13 @@ async def run_cycle(icycle: int):
iter = not iter
return {"wavelength": currentWavelength}

@app.get("/wait_for_viewer_completion")
async def wait_for_viewer_completion():
viewer.viewer_completed_event.wait() # Wait for viewer completion
return {"message": "Viewer completed"}

@app.get("/stop_loop/")
async def stop_loop():
global iLoop, iCycle
iLoop = False
iCycle = 1
return {"message": "Loop stopped"}

# Endpoint to toggle fullscreen mode
@app.get("/toggle_fullscreen")
Expand Down

0 comments on commit 2b19764

Please sign in to comment.