You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importasynciofromframe_sdkimportFramefromframe_sdk.displayimportAlignment, PaletteColorsfromframe_sdk.cameraimportQuality, AutofocusTypeimportdatetimeasyncdefmain():
# the with statement handles the connection and disconnection to FrameasyncwithFrame() asf:
# you can access the lower-level bluetooth connection via f.bluetooth, although you shouldn't need to do this oftenprint(f"Connected: {f.bluetooth.is_connected()}")
# let's get the current battery levelprint(f"Frame battery: {awaitf.get_battery_level()}%")
# let's write (or overwrite) the file greeting.txt with "Hello world".# You can provide a bytes object or convert a string with .encode()awaitf.files.write_file("greeting.txt", b"Hello world")
# And now we read that file back.# Note that we should convert the bytearray to a string via the .decode() method.print((awaitf.files.read_file("greeting.txt")).decode())
# run_lua will automatically handle scripts that are too long for the MTU, so you don't need to worry about it.# It will also automatically handle responses that are too long for the MTU automatically.awaitf.run_lua("frame.display.text('Hello world', 50, 100);frame.display.show()")
# evaluate is equivalent to f.run_lua("print(\"1+2\"), await_print=True)# It will also automatically handle responses that are too long for the MTU automatically.print(awaitf.evaluate("1+2"))
print("Tap the Frame to continue...")
awaitf.display.show_text("Tap the Frame to take a photo", align=Alignment.MIDDLE_CENTER)
awaitf.motion.wait_for_tap()
# take a photo and save to diskawaitf.display.show_text("Taking photo...", align=Alignment.MIDDLE_CENTER)
awaitf.camera.save_photo("frame-test-photo.jpg")
awaitf.display.show_text("Photo saved!", align=Alignment.MIDDLE_CENTER, color=PaletteColors.GREEN)
# or with more controlawaitf.camera.save_photo("frame-test-photo-2.jpg", autofocus_seconds=3, quality=Quality.HIGH, autofocus_type=AutofocusType.CENTER_WEIGHTED, resolution=720, pan=-100)
# or get the raw bytesphoto_bytes=awaitf.camera.take_photo(autofocus_seconds=1)
print("About to record until you stop talking")
awaitf.display.show_text("Say something...", align=Alignment.MIDDLE_CENTER)
# record audio to a filelength=awaitf.microphone.save_audio_file("test-audio.wav")
print(f"Recorded {length:01.1f} seconds: \"./test-audio.wav\"")
awaitf.display.show_text(f"Recorded {length:01.1f} seconds", align=Alignment.MIDDLE_CENTER)
awaitasyncio.sleep(3)
# or get the audio directly in memoryawaitf.display.show_text("Say something else...", align=Alignment.MIDDLE_CENTER)
audio_data=awaitf.microphone.record_audio(max_length_in_seconds=10)
awaitf.display.show_text(f"Playing back {len(audio_data) /f.microphone.sample_rate:01.1f} seconds of audio", align=Alignment.MIDDLE_CENTER)
# you can play back the audio on your computerf.microphone.play_audio_background(audio_data)
# or process it using other audio handling libraries, upload to a speech-to-text service, etc.print("Move around to track intensity of your motion")
awaitf.display.show_text("Move around to track intensity of your motion", align=Alignment.MIDDLE_CENTER)
intensity_of_motion=0prev_direction=awaitf.motion.get_direction()
for_inrange(10):
awaitasyncio.sleep(0.1)
direction=awaitf.motion.get_direction()
intensity_of_motion=max(intensity_of_motion, (direction-prev_direction).amplitude())
prev_direction=directionprint(f"Intensity of motion: {intensity_of_motion:01.2f}")
awaitf.display.show_text(f"Intensity of motion: {intensity_of_motion:01.2f}", align=Alignment.MIDDLE_CENTER)
print("Tap the Frame to continue...")
awaitf.motion.wait_for_tap()
# Show the full palettewidth=640//4height=400//4forcolorinrange(0, 16):
tile_x= (color%4)
tile_y= (color//4)
awaitf.display.draw_rect(tile_x*width+1, tile_y*height+1, width, height, PaletteColors(color))
awaitf.display.write_text(f"{color}", tile_x*width+width//2+1, tile_y*height+height//2+1)
awaitf.display.show()
print("Tap the Frame to continue...")
awaitf.motion.wait_for_tap()
# scroll some long textawaitf.display.scroll_text("Never gonna give you up\nNever gonna let you down\nNever gonna run around and desert you\nNever gonna make you cry\nNever gonna say goodbye\nNever gonna tell a lie and hurt you")
# display battery indicator and time as a home screenbatteryPercent=awaitf.get_battery_level()
# select a battery fill color from the default palette based on levelcolor=PaletteColors.REDifbatteryPercent<20elsePaletteColors.YELLOWifbatteryPercent<50elsePaletteColors.GREEN# specify the size of the battery indicator in the top-rightbatteryWidth=150batteryHeight=75# draw the endcap of the batteryawaitf.display.draw_rect(640-32,40+batteryHeight//2-8, 32, 16, PaletteColors.WHITE)
# draw the battery outlineawaitf.display.draw_rect_filled(640-16-batteryWidth, 40-8, batteryWidth+16, batteryHeight+16, 1, PaletteColors.WHITE, PaletteColors.YELLOW)
# fill the battery based on levelawaitf.display.draw_rect(640-8-batteryWidth, 40, int(batteryWidth*0.01*batteryPercent), batteryHeight, color)
# write the battery levelawaitf.display.write_text(f"{batteryPercent}%", 640-8-batteryWidth, 40, batteryWidth, batteryHeight, Alignment.MIDDLE_CENTER)
# write the time and date in the center of the screenawaitf.display.write_text(datetime.datetime.now().strftime("%#I:%M %p\n%a, %B %d, %Y").lstrip("0"), align=Alignment.MIDDLE_CENTER)
# now show what we've been drawing to the bufferawaitf.display.show()
# set a wake screen via script, so when you tap to wake the frame, it shows the battery and timeawaitf.run_on_wake("""frame.display.text('Battery: ' .. frame.battery_level() .. '%', 10, 10); if frame.time.utc() > 10000 then local time_now = frame.time.date(); frame.display.text(time_now['hour'] .. ':' .. time_now['minute'], 300, 160); frame.display.text(time_now['month'] .. '/' .. time_now['day'] .. '/' .. time_now['year'], 300, 220) end; frame.display.show(); frame.sleep(10); frame.display.text(' ',1,1); frame.display.show(); frame.sleep()""")
# tell frame to sleep after 10 seconds then clear the screen and go to sleep, without blocking for thatawaitf.run_lua("frame.sleep(10);frame.display.text(' ',1,1);frame.display.show();frame.sleep()")
# clean disconnection so next connect() succeedsawaitf.bluetooth.disconnect()
print("disconnected")
asyncio.run(main())
But, this script failed to detect Frame.
The text was updated successfully, but these errors were encountered:
I tried to use Frame via Python SDK.
But, example script failed to detect Frame.
Environment
Steps to reproduce
I installed
frame-sdk
using pip.I did pairing of Frame by Ubuntu settings.
I checked that "Connected" is displayed in Bluetooth setting.
And, I tried to run the following example script(https://pypi.org/project/frame-sdk/).
But, this script failed to detect Frame.
The text was updated successfully, but these errors were encountered: