Skip to content

Commit

Permalink
add driver code
Browse files Browse the repository at this point in the history
  • Loading branch information
martha-johnston committed Nov 5, 2024
1 parent ad4d6b0 commit cbe5b71
Show file tree
Hide file tree
Showing 13 changed files with 470 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .canon.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file provides project-level configuration for the canon dev environment utility. https://github.com/viamrobotics/canon
MODULE:
pca:
default: true
image_amd64: ghcr.io/viamrobotics/rdk-devenv:amd64-cache
image_arm64: ghcr.io/viamrobotics/rdk-devenv:arm64-cache
Expand All @@ -9,7 +9,7 @@ MODULE:
group: testbot
persistent: true

MODULE-antique:
pca-antique:
image_amd64: ghcr.io/viamrobotics/antique2:amd64-cache
image_arm64: ghcr.io/viamrobotics/antique2:arm64-cache
minimum_date: 2023-10-26T20:00:00.0Z
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ jobs:
script: |
let prNumber = context.payload.pull_request && context.payload.pull_request.number;
try {
await github.rest.issues.removeLabel({owner: "viam-modules", repo: "MODULE", issue_number: prNumber, name: "safe to test"});
await github.rest.issues.removeLabel({owner: "viam-modules", repo: "pca", issue_number: prNumber, name: "safe to test"});
} catch (err) {
core.info(`Non-fatal error ${err}, while trying to remove 'safe to test' label.`);
}
let orgResp = await github.rest.orgs.checkMembershipForUser({org: "viam-modules", username: context.payload.sender.login});
if (orgResp.status === 204) {
// order of labeling events must be preserved, so two seperate calls
await github.rest.issues.addLabels({owner: "viam-modules", repo: "MODULE", issue_number: prNumber, labels: ["safe to test"]});
await github.rest.issues.addLabels({owner: "viam-modules", repo: "pca", issue_number: prNumber, labels: ["safe to test"]});
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pullrequest-trusted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ on:
jobs:
test:
if: (github.event.label.name == 'safe to test' || github.event.label.name == 'appimage')
uses: viam-modules/MODULE/.github/workflows/test.yml@main
uses: viam-modules/pca/.github/workflows/test.yml@main
secrets:
MONGODB_TEST_OUTPUT_URI: ${{ secrets.MONGODB_TEST_OUTPUT_URI }}
DOCKER_PUBLIC_READONLY_PAT: ${{ secrets.DOCKER_PUBLIC_READONLY_PAT }}

license_finder:
uses: viam-modules/MODULE/.github/workflows/license_finder.yml@main
uses: viam-modules/pca/.github/workflows/license_finder.yml@main
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ jobs:
- name: Build and package
run: |
canon --profile MODULE
canon --profile pca
TARGET_OS=${{ matrix.platform }} TARGET_ARCH=${{ matrix.arch }} make module
- name: Upload MODULE module to registry
- name: Upload pca module to registry
uses: viamrobotics/upload-module@main
with:
meta-path: meta.json
Expand Down
Empty file removed MODEL/MODEL.go
Empty file.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ endif

module: build
rm -f $(BIN_OUTPUT_PATH)/module.tar.gz
tar czf $(BIN_OUTPUT_PATH)/module.tar.gz $(BIN_OUTPUT_PATH)/MODULE meta.json
tar czf $(BIN_OUTPUT_PATH)/module.tar.gz $(BIN_OUTPUT_PATH)/pca meta.json

build: build-go

build-go:
rm -f $(BIN_OUTPUT_PATH)/MODULE
go build -tags no_cgo,osusergo,netgo -ldflags="-extldflags=-static $(COMMON_LDFLAGS)" -o $(BIN_OUTPUT_PATH)/MODULE main.go
rm -f $(BIN_OUTPUT_PATH)/pca
go build -tags no_cgo,osusergo,netgo -ldflags="-extldflags=-static $(COMMON_LDFLAGS)" -o $(BIN_OUTPUT_PATH)/pca main.go

tool-install:
GOBIN=`pwd`/$(TOOL_BIN) go install \
Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# [`MODULE` module](https://github.com/viam-modules/MODULE)
# [`pca` module](https://github.com/viam-modules/pca)

This [MODULE module](https://app.viam.com/module/viam/MODULE) implements a MODULE [MODEL COMPONENT](<LINK TO HARDWARE>), used for <DESCRIPTION> using the [`rdk:component:COMPONENT` API](https://docs.viam.com/appendix/apis/components/COMPONENT/).
This [pca module](https://app.viam.com/module/viam/pca) implements a pca [pca9685 board](<LINK TO HARDWARE>), used for <DESCRIPTION> using the [`rdk:component:board` API](https://docs.viam.com/appendix/apis/components/board/).

> [!NOTE]
> Before configuring your COMPONENT, you must [create a machine](https://docs.viam.com/cloud/machines/#add-a-new-machine).
> Before configuring your board, you must [create a machine](https://docs.viam.com/cloud/machines/#add-a-new-machine).
## Configure your MODEL COMPONENT
## Configure your pca9685 board

Navigate to the [**CONFIGURE** tab](https://docs.viam.com/configure/) of your [machine](https://docs.viam.com/fleet/machines/) in the [Viam app](https://app.viam.com/).
[Add COMPONENT / MODULE:MODEL to your machine](https://docs.viam.com/configure/#components).
[Add board / pca:pca9685 to your machine](https://docs.viam.com/configure/#components).

On the new component panel, copy and paste the following attribute template into your COMPONENT's attributes field:
On the new component panel, copy and paste the following attribute template into your board's attributes field:

```json
{
Expand All @@ -20,22 +20,22 @@ On the new component panel, copy and paste the following attribute template into

### Attributes

The following attributes are available for `viam:MODULE:MODEL` COMPONENTs:
The following attributes are available for `viam:pca:pca9685` boards:

<EXAMPLE !!>
| Attribute | Type | Required? | Description |
| --------- | ---- | --------- | ---------- |
| `i2c_bus` | string | **Required** | The index of the I<sup>2</sup>C bus on the board that the COMPONENT is wired to. |
| `i2c_address` | string | Optional | Default: `0x77`. The [I<sup>2</sup>C device address](https://learn.adafruit.com/i2c-addresses/overview) of the COMPONENT. |
| `i2c_bus` | string | **Required** | The index of the I<sup>2</sup>C bus on the board that the board is wired to. |
| `i2c_address` | string | Optional | Default: `0x77`. The [I<sup>2</sup>C device address](https://learn.adafruit.com/i2c-addresses/overview) of the board. |

## Example configuration

### `viam:MODULE:MODEL`
### `viam:pca:pca9685`
```json
{
"name": "<your-MODULE-MODEL-COMPONENT-name>",
"model": "viam:MODULE:MODEL",
"type": "COMPONENT",
"name": "<your-pca-pca9685-board-name>",
"model": "viam:pca:pca9685",
"type": "board",
"namespace": "rdk",
"attributes": {
},
Expand All @@ -44,6 +44,6 @@ The following attributes are available for `viam:MODULE:MODEL` COMPONENTs:
```

### Next Steps
- To test your COMPONENT, expand the **TEST** section of its configuration pane or go to the [**CONTROL** tab](https://docs.viam.com/fleet/control/).
- To write code against your COMPONENT, use one of the [available SDKs](https://docs.viam.com/sdks/).
- To view examples using a COMPONENT component, explore [these tutorials](https://docs.viam.com/tutorials/).
- To test your board, expand the **TEST** section of its configuration pane or go to the [**CONTROL** tab](https://docs.viam.com/fleet/control/).
- To write code against your board, use one of the [available SDKs](https://docs.viam.com/sdks/).
- To view examples using a board component, explore [these tutorials](https://docs.viam.com/tutorials/).
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module MODULE
module pca

go 1.23.0

Expand All @@ -8,7 +8,9 @@ require (
github.com/edaniels/golinters v0.0.5-0.20220906153528-641155550742
github.com/fullstorydev/grpcurl v1.8.6
github.com/golangci/golangci-lint v1.61.0
github.com/pkg/errors v0.9.1
github.com/rhysd/actionlint v1.6.24
go.viam.com/api v0.1.350
go.viam.com/rdk v0.48.2
go.viam.com/utils v0.1.110
gotest.tools/gotestsum v1.10.0
Expand Down Expand Up @@ -44,6 +46,7 @@ require (
github.com/alingse/asasalint v0.0.11 // indirect
github.com/ashanbrown/forbidigo v1.6.0 // indirect
github.com/ashanbrown/makezero v1.1.1 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bep/debounce v1.2.1 // indirect
github.com/bkielbasa/cyclop v1.2.1 // indirect
Expand Down Expand Up @@ -208,7 +211,6 @@ require (
github.com/pion/stun v0.6.1 // indirect
github.com/pion/transport/v2 v2.2.10 // indirect
github.com/pion/turn/v2 v2.1.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polyfloyd/go-errorlint v1.6.0 // indirect
Expand Down Expand Up @@ -287,7 +289,6 @@ require (
go.uber.org/goleak v1.3.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
go.viam.com/api v0.1.350 // indirect
go.viam.com/test v1.1.1-0.20220913152726-5da9916c08a2 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
Expand Down Expand Up @@ -318,4 +319,6 @@ require (
mvdan.cc/gofumpt v0.7.0 // indirect
mvdan.cc/unparam v0.0.0-20240528143540-8a5130ca722f // indirect
nhooyr.io/websocket v1.8.7 // indirect
periph.io/x/conn/v3 v3.7.0 // indirect
periph.io/x/host/v3 v3.8.1-0.20230331112814-9f0d9f7d76db // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,8 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jonboulle/clockwork v0.2.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg=
github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand Down
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ package main
import (
"context"

"pca/pca9685"

"go.viam.com/rdk/components/board"
"go.viam.com/rdk/logging"
"go.viam.com/rdk/module"
"go.viam.com/utils"
)

func main() {
utils.ContextualMain(mainWithArgs, module.NewLoggerFromArgs("MODULE"))
utils.ContextualMain(mainWithArgs, module.NewLoggerFromArgs("pca"))
}

func mainWithArgs(ctx context.Context, args []string, logger logging.Logger) error {
Expand All @@ -19,7 +22,7 @@ func mainWithArgs(ctx context.Context, args []string, logger logging.Logger) err
return err
}

if err = module.AddModelFromRegistry(ctx, COMPONENT.API, MODEL.Model); err != nil {
if err = module.AddModelFromRegistry(ctx, board.API, pca9685.Model); err != nil {
return err
}

Expand Down
12 changes: 6 additions & 6 deletions meta.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"$schema": "https://dl.viam.dev/module.schema.json",
"module_id": "NAMESPACE:MODULE",
"module_id": "viam:pca",
"visibility": "public",
"url": "https://github.com/viam-modules/MODULE",
"description": "Go module for MODULE MODEL COMPONENT, compatible with Viam",
"url": "https://github.com/viam-modules/pca",
"description": "Go module for pca pca9685 board, compatible with Viam",
"models": [
{
"api": "rdk:component:COMPONENT",
"model": "NAMESPACE:MODULE:MODEL"
"api": "rdk:component:board",
"model": "viam:pca:pca9685"
}
],
"build": {
"build": "make module",
"path": "bin/module.tar.gz",
"arch" : ["linux/arm64", "linux/amd64", "darwin/arm64"]
},
"entrypoint": "bin/MODULE"
"entrypoint": "bin/pca"
}
Loading

0 comments on commit cbe5b71

Please sign in to comment.