Skip to content

Commit

Permalink
Python SDK Refactor and Tutorial Updates
Browse files Browse the repository at this point in the history
* Rearchitect Python SDK to encapsulate all operations in Message objects
* Share Protobuf building architecture between Python SDK and Tutorials
* Add missing functionality from last 2 Hero 12 releases
* Implement PUT support and add custom preset update operation
* Add in new setting options
* Refactor Tutorials to allow for non-TLV packets
* Add Protobuf Tutorials
* Add WiFi Station Mode Tutorial
* Add COHN Tutotrial
  • Loading branch information
github-actions committed Apr 9, 2024
1 parent 56aed48 commit 69924b4
Show file tree
Hide file tree
Showing 201 changed files with 14,593 additions and 8,135 deletions.
4 changes: 4 additions & 0 deletions .admin/proto_build/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**

!entrypoint.sh
!requirements.txt
15 changes: 15 additions & 0 deletions .admin/proto_build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Dockerfile/Open GoPro, Version 2.0 (C) Copyright 2021 GoPro, Inc. (http://gopro.com/OpenGoPro).
# This copyright was auto-generated on Wed Mar 27 22:05:54 UTC 2024

FROM python:3.11-bookworm

RUN apt-get update && apt-get install -y \
protobuf-compiler \
bash

COPY . /workdir
RUN pip install -r /workdir/requirements.txt

RUN chmod +x /workdir/entrypoint.sh

ENTRYPOINT [ "/workdir/entrypoint.sh" ]
22 changes: 22 additions & 0 deletions .admin/proto_build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Protobuf Builder

This is a Docker image to build the [Protobuf](../../protobuf/) files in this repo. It currently only build Python
output but should be used in the future for other languages.

## Usage

It is intended to be used via the [docker compose configuration](../../docker-compose.yml).

First build:

```shell
docker compose build proto-build
```

Then build the protobuf files with:

```shell
docker compose run --rm proto-build
```

The output files will be placed in the [build directory](../../.build/protobuf).
27 changes: 27 additions & 0 deletions .admin/proto_build/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# entrypoint.sh/Open GoPro, Version 2.0 (C) Copyright 2021 GoPro, Inc. (http://gopro.com/OpenGoPro).
# This copyright was auto-generated on Wed Mar 27 22:05:54 UTC 2024


PROTO_SRC_DIR=/proto_in
PROTO_PYTHON_OUT_DIR=/proto_python_out

rm -rf $PROTO_PYTHON_OUT_DIR && mkdir -p $PROTO_PYTHON_OUT_DIR

echo
echo "Building protobuf python files and stubs from .proto source files..."
pushd $PROTO_SRC_DIR
protoc --include_imports --descriptor_set_out=$PROTO_PYTHON_OUT_DIR/descriptors --python_out=$PROTO_PYTHON_OUT_DIR --mypy_out=$PROTO_PYTHON_OUT_DIR *
popd

pushd $PROTO_PYTHON_OUT_DIR
echo
echo "Converting relative imports to absolute..."
protol -o . --in-place raw descriptors
rm descriptors

# Format generated files
echo
echo "Formatting..."
black .
popd
3 changes: 3 additions & 0 deletions .admin/proto_build/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mypy-protobuf==3.5.0
protoletariat==3.2.19
black
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
**/*.crt
/.build

/.env
**.log

Expand Down
26 changes: 19 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,50 @@ help: ## Display this help which is generated from Make goal comments
# Docker images are currently not public. So we build if pull fails for the local use case.
.PHONY: docker-setup
docker-setup:
-@docker-compose pull || docker-compose build
-@docker compose pull jekyll plant-uml || docker compose build jekyll plant-uml

.PHONY: docker-kill
docker-kill:
-@docker kill jekyll plant_uml > /dev/null 2>&1
-@docker kill jekyll plant-uml > /dev/null 2>&1

.PHONY: clean
clean: ## Clean cached jekyll files
@echo "🧼 Cleaning jekyll artifacts..."
-@docker-compose down > /dev/null 2>&1
-@docker compose down > /dev/null 2>&1
@rm -rf docs/_site docs/.jekyll-cache docs/.jekyll-metadata

.PHONY: serve
serve: docker-kill docker-setup
serve: ## Serve site locally
@echo COMMAND="-u http://localhost:4998/ -b \"\" -p 4998 serve" > .env
@docker-compose up
@docker compose up
@rm -rf .env

.PHONY: build
build: docker-setup
build: ## Build site for deployment
@echo COMMAND=\"-u ${BUILD_HOST_URL} -b ${BUILD_BASE_URL} build\" > .env
@docker-compose up --abort-on-container-exit
@docker compose up --abort-on-container-exit
@rm -rf .env

PROTO_BUILD_DIR=.build/protobuf/python/*
PYTHON_TUTORIAL_PROTO_DIR=demos/python/tutorial/tutorial_modules/tutorial_5_ble_protobuf/proto
PYTHON_SDK_PROTO_DIR=demos/python/sdk_wireless_camera_control/open_gopro/proto

.PHONY: protos
protos: ## Build generated code from protobuf files
@docker compose run --build --rm proto-build
@rm -rf ${PYTHON_TUTORIAL_PROTO_DIR}/*pb2.py* && mkdir -p ${PYTHON_TUTORIAL_PROTO_DIR}
@cp ${PROTO_BUILD_DIR} ${PYTHON_TUTORIAL_PROTO_DIR}
@rm -rf ${PYTHON_SDK_PROTO_DIR}/*pb2.py* && mkdir -p ${PYTHON_SDK_PROTO_DIR}
@cp ${PROTO_BUILD_DIR} ${PYTHON_SDK_PROTO_DIR}

.PHONY: tests
tests: docker-setup clean
tests: ## Serve, then run link checker. Times out after 5 minutes.
-@docker-compose pull linkchecker || docker-compose build linkchecker
-@docker compose pull linkchecker || docker compose build linkchecker
@echo COMMAND="-u http://jekyll:4998/ -b \"\" -p 4998 serve" > .env
@docker-compose --profile test up --abort-on-container-exit
@docker compose --profile test up --abort-on-container-exit
@rm -rf .env

.PHONY: copyright
Expand Down
1 change: 1 addition & 0 deletions demos/kotlin/tutorial/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea/
*.iml
.gradle
/local.properties
Expand Down
2 changes: 1 addition & 1 deletion demos/kotlin/tutorial/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions demos/kotlin/tutorial/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions demos/kotlin/tutorial/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Tutorial2SendBleCommands(number: Int, name: String, prerequisites: List<Pr

private fun checkStatus(data: UByteArray) =
if (data[2].toUInt() == 0U) Timber.i("Command sent successfully")
else Timber.i("Command Failed")
else Timber.e("Command Failed")

@OptIn(ExperimentalUnsignedTypes::class)
@RequiresPermission(allOf = ["android.permission.BLUETOOTH_SCAN", "android.permission.BLUETOOTH_CONNECT"])
Expand All @@ -68,6 +68,8 @@ class Tutorial2SendBleCommands(number: Int, name: String, prerequisites: List<Pr
// Wait to receive the notification response, then check its status
checkStatus(receivedData.receive())

delay(3000)

// Load Preset Group
Timber.i("Loading Video Preset Group")
val loadPreset = ubyteArrayOf(0x04U, 0x3EU, 0x02U, 0x03U, 0xE8U)
Expand Down
Loading

0 comments on commit 69924b4

Please sign in to comment.