Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 41 additions & 42 deletions examples/get_file.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Example script to download a file from FreeWili device to local filesystem."""

import sys
import pathlib
import sys
import time

# Ensure we use the local freewili module (with our fixes) instead of any installed version
current_dir = pathlib.Path(__file__).parent.parent
sys.path.insert(0, str(current_dir))

from freewili import FreeWili
from freewili.fw import FreeWiliProcessorType as FwProcessor
from freewili import FreeWili # noqa: E402
from freewili.fw import FreeWiliProcessorType as FwProcessor # noqa: E402


def progress_callback(message: str) -> None:
Expand All @@ -20,7 +20,7 @@ def progress_callback(message: str) -> None:

def get_file_from_device(fw: FreeWili, source_file: str, destination_path: str, processor: FwProcessor) -> None:
"""Download a file from the FreeWili device.

Arguments:
----------
fw: FreeWili
Expand All @@ -33,19 +33,16 @@ def get_file_from_device(fw: FreeWili, source_file: str, destination_path: str,
Which processor to get the file from (Main or Display).
"""
print(f"Downloading {source_file} from {processor.name} processor...")

# Ensure destination directory exists
dest_path = pathlib.Path(destination_path)
dest_path.parent.mkdir(parents=True, exist_ok=True)

# Get the file from the device
result = fw.get_file(
source_file=source_file,
destination_path=dest_path,
processor=processor,
event_cb=progress_callback
source_file=source_file, destination_path=dest_path, processor=processor, event_cb=progress_callback
)

if result.is_ok():
print(f"✅ Success: {result.unwrap()}")
print(f" File saved to: {dest_path.absolute()}")
Expand All @@ -56,7 +53,7 @@ def get_file_from_device(fw: FreeWili, source_file: str, destination_path: str,

def list_available_files(fw: FreeWili, processor: FwProcessor, directory: str = "/") -> None:
"""List files available on the device for download.

Arguments:
----------
fw: FreeWili
Expand All @@ -67,29 +64,29 @@ def list_available_files(fw: FreeWili, processor: FwProcessor, directory: str =
Directory to list (default: root directory).
"""
print(f"\nListing files in {directory} on {processor.name} processor:")

# Change to the specified directory
change_result = fw.change_directory(directory, processor)
if change_result.is_err():
print(f"Failed to change to directory {directory}: {change_result.unwrap_err()}")
return

# List current directory contents
result = fw.list_current_directory(processor)
if result.is_err():
print(f"Failed to list directory contents: {result.unwrap_err()}")
return

fs_contents = result.unwrap()
print(f"📁 Current directory: {fs_contents.cwd}")

# Display files that can be downloaded
files_found = False
for item in fs_contents.contents:
if item.name not in ["..", "."] and item.file_type.name == "File":
files_found = True
print(f" 📄 {item.name} ({item.size} bytes)")

if not files_found:
print(" No files found in this directory.")

Expand All @@ -99,63 +96,65 @@ def main() -> None:
print("FreeWili File Download Example")
print("=" * 40)
print("📁 All files will be saved to: ./upload/ directory")

# Find and connect to FreeWili device
fw_result = FreeWili.find_first()
if fw_result.is_err():
print(f"Failed to find FreeWili device: {fw_result.unwrap_err()}")
return

try:
with fw_result.unwrap() as fw:
print(f"🔌 Connected to: {fw}")

# Example 1: List available files on Display processor
list_available_files(fw, FwProcessor.Display, "/") # Root directory
list_available_files(fw, FwProcessor.Display, "/") # Root directory
list_available_files(fw, FwProcessor.Display, "/sounds")
list_available_files(fw, FwProcessor.Display, "/images")

# Example 2: List available files on Main processor
list_available_files(fw, FwProcessor.Main, "/") # Root directory
list_available_files(fw, FwProcessor.Main, "/") # Root directory
list_available_files(fw, FwProcessor.Main, "/scripts")
list_available_files(fw, FwProcessor.Main, "/radio")
list_available_files(fw, FwProcessor.Main, "/fpga")
print(f"\n{'='*50}")

print(f"\n{'=' * 50}")
print("File Download Examples:")
print(f"{'='*50}")
print(f"{'=' * 50}")

# Example 3: Download working files from your device
working_downloads = [
("/settings.txt", "./upload/main_settings.txt", FwProcessor.Main, "Main processor configuration"),
("/settings.txt", "./upload/display_settings.txt", FwProcessor.Display, "Display processor configuration"),
(
"/settings.txt",
"./upload/display_settings.txt",
FwProcessor.Display,
"Display processor configuration",
),
("/testfw.bin", "./upload/testfw.bin", FwProcessor.Main, "Small test firmware binary"),
("/wili.jpeg", "./upload/wili.jpeg", FwProcessor.Main, "JPEG image")
("/wili.jpeg", "./upload/wili.jpeg", FwProcessor.Main, "JPEG image"),
]

for source_file, dest_path, processor, description in working_downloads:
print(f"\n🔄 Downloading {description}...")
try:
get_file_from_device(
fw=fw,
source_file=source_file,
destination_path=dest_path,
processor=processor
fw=fw, source_file=source_file, destination_path=dest_path, processor=processor
)
except Exception as e:
print(f" Download failed: {e}")
print(f"\n{'='*50}")

print(f"\n{'=' * 50}")
print("Additional Examples (modify with actual file names):")
print(f"{'='*50}")
print(f"{'=' * 50}")

except Exception as e:
print(f"Failed to open FreeWili device: {e}")
return
print(f"\nSummary:")
print(f" All downloaded files are saved in the ./upload/ directory")

print("\nSummary:")
print(" All downloaded files are saved in the ./upload/ directory")


if __name__ == "__main__":
main()
main()
11 changes: 7 additions & 4 deletions examples/read_nfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ def event_callback(event_type: EventType, response_frame: ResponseFrame, event_d
elif event_data.disconnected is None:
return
else:
print(f"NFC Card detected: UID={event_data.uid.hex().upper()}, " \
f"ATQA={event_data.atqa.hex().upper()}, " \
f"SAK={event_data.sak.hex().upper()}, " \
f"Type={event_data.card_type}")
if event_data.uid is not None and event_data.atqa is not None and event_data.sak is not None:
print(
f"NFC Card detected: UID={event_data.uid.hex().upper()}, "
f"ATQA={event_data.atqa.hex().upper()}, "
f"SAK={event_data.sak.hex().upper()}, "
f"Type={event_data.card_type}"
)


with FreeWili.find_first().expect("Failed to find FreeWili") as fw:
Expand Down
53 changes: 27 additions & 26 deletions examples/wileye_simple.py
Original file line number Diff line number Diff line change
@@ -1,115 +1,116 @@
"""
Simple WilEye Camera Example
"""Simple WilEye Camera Example.

A basic example showing how to use the WilEye camera commands
with the FreeWili Python library using automatic device discovery.
"""

import sys
import pathlib
import sys
import time
import result

from result import UnwrapError

# Ensure we use the local freewili module
current_dir = pathlib.Path(__file__).parent.parent
sys.path.insert(0, str(current_dir))

from freewili import FreeWili
from freewili import FreeWili # noqa: E402


def main():
def main() -> None:
"""Run WilEye camera examples."""
print("FreeWili WilEye Camera - Simple Example")
print("="*40)
print("=" * 40)

print("Searching for FreeWili devices...")

# Find FreeWili device automatically
try:
fw_device = FreeWili.find_first().expect("No FreeWili devices found")
print(f"Found FreeWili device: {fw_device}")
except result.UnwrapError as ex:
except UnwrapError as ex:
print(f"Error: {ex}")
print("\nMake sure your FreeWili device is:")
print("1. Connected via USB")
print("2. Powered on")
print("3. Recognized by your system")
return

# Use the found device's serial interface
fw = fw_device.main_serial # Use main processor serial interface

try:
# Open connection
result = fw.open()
if result.is_err():
print(f"Failed to connect: {result.unwrap_err()}")
return

print("Connected successfully!")

# Example 1: Take a picture
print("\n1. Taking a picture...")
result = fw.wileye_take_picture(0, "example_photo.jpg")
if result.is_ok():
print("Picture taken successfully!")
else:
print(f"Failed to take picture: {result.unwrap_err()}")

# Example 2: Set camera brightness
print("\n2. Setting camera brightness to 75...")
result = fw.wileye_set_brightness(75)
if result.is_ok():
print("Brightness set successfully!")
else:
print(f"Failed to set brightness: {result.unwrap_err()}")

# Example 3: Set camera contrast
print("\n3. Setting camera contrast to 60...")
result = fw.wileye_set_contrast(60)
if result.is_ok():
print("Contrast set successfully!")
else:
print(f"Failed to set contrast: {result.unwrap_err()}")

# Example 4: Enable flash
print("\n4. Enabling camera flash...")
result = fw.wileye_set_flash_enabled(True)
if result.is_ok():
print("Flash enabled successfully!")
else:
print(f"Failed to enable flash: {result.unwrap_err()}")

# Example 5: Set resolution
print("\n5. Setting camera resolution to high (index 2)...")
result = fw.wileye_set_resolution(2)
if result.is_ok():
print("Resolution set successfully!")
else:
print(f"Failed to set resolution: {result.unwrap_err()}")

# Example 6: Set zoom level
print("\n6. Setting zoom level to 2x...")
result = fw.wileye_set_zoom_level(2)
if result.is_ok():
print("Zoom level set successfully!")
else:
print(f"Failed to set zoom level: {result.unwrap_err()}")

# Example 7: Take another picture with new settings
print("\n7. Taking another picture with new settings...")
result = fw.wileye_take_picture(0, "example_photo_2.jpg")
if result.is_ok():
print("Second picture taken successfully!")
else:
print(f"Failed to take second picture: {result.unwrap_err()}")

# Example 8: Start video recording
print("\n8. Starting video recording...")
result = fw.wileye_start_recording_video(0, "example_video.mp4")
if result.is_ok():
print("Video recording started! Recording for 3 seconds...")
time.sleep(3) # Record for 3 seconds

# Example 9: Stop video recording
print("\n9. Stopping video recording...")
result = fw.wileye_stop_recording_video()
Expand All @@ -119,18 +120,18 @@ def main():
print(f"Failed to stop video recording: {result.unwrap_err()}")
else:
print(f"Failed to start video recording: {result.unwrap_err()}")

# Example 10: Disable flash
print("\n10. Disabling camera flash...")
result = fw.wileye_set_flash_enabled(False)
if result.is_ok():
print("Flash disabled successfully!")
else:
print(f"Failed to disable flash: {result.unwrap_err()}")

print("\nAll WilEye camera examples completed!")
print("Check your FreeWili device storage for the captured files.")

except Exception as e:
print(f"Error: {e}")
finally:
Expand All @@ -140,4 +141,4 @@ def main():


if __name__ == "__main__":
main()
main()
3 changes: 3 additions & 0 deletions freewili/cli_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ def print_verbose(usb_device: fwf.USBDevice, serial: FreeWiliSerial | None = Non
if free_wili.display:
print_usb(2, "Display", free_wili.display)
print_verbose(free_wili.display, free_wili.display_serial)
if free_wili.mass_storage:
print_usb(2, "Mass Storage", free_wili.mass_storage)
print_verbose(free_wili.mass_storage)
if free_wili.fpga:
print_usb(3, "FPGA", free_wili.fpga)
print_verbose(free_wili.fpga, None)
Expand Down
Loading
Loading