-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
PendantState
python class, proto, & example (#182)
- Loading branch information
1 parent
bb69591
commit 5b87ca6
Showing
9 changed files
with
338 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Amiga Pendant State example | ||
|
||
URL: https://amiga.farm-ng.com/docs/examples/pendant_state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright (c) farm-ng, inc. | ||
# | ||
# Licensed under the Amiga Development Kit License (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://github.com/farm-ng/amiga-dev-kit/blob/main/LICENSE | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from __future__ import annotations | ||
|
||
import argparse | ||
import asyncio | ||
from pathlib import Path | ||
|
||
from farm_ng.canbus import amiga_v6_pb2 | ||
from farm_ng.canbus.packet import PendantButtons | ||
from farm_ng.canbus.packet import PendantState | ||
from farm_ng.core.event_client import EventClient | ||
from farm_ng.core.event_service_pb2 import EventServiceConfig | ||
from farm_ng.core.events_file_reader import proto_from_json_file | ||
|
||
|
||
async def main(service_config_path: Path) -> None: | ||
"""Run the canbus service client. | ||
Args: | ||
service_config_path (Path): The path to the canbus service config. | ||
""" | ||
|
||
config: EventServiceConfig = proto_from_json_file(service_config_path, EventServiceConfig()) | ||
async for event, msg in EventClient(config).subscribe(config.subscriptions[0], decode=True): | ||
if not isinstance(msg, amiga_v6_pb2.PendantState): | ||
print(f"Unexpected message type: {type(msg)}") | ||
continue | ||
pendant_state: PendantState = PendantState.from_proto(msg) | ||
print(f"Received pendant state: {pendant_state}") | ||
for button in PendantButtons: | ||
if pendant_state.is_button_pressed(button): | ||
print(f"Button {button.name} is pressed") | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(prog="Stream PendantState messages the canbus service.") | ||
parser.add_argument("--service-config", type=Path, required=True, help="The canbus service config.") | ||
args = parser.parse_args() | ||
|
||
asyncio.run(main(args.service_config)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
farm-ng-amiga |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "canbus", | ||
"port": 6001, | ||
"host": "localhost", | ||
"log_level": "INFO", | ||
"subscriptions": [ | ||
{ | ||
"uri": { | ||
"path": "/pendant", | ||
"query": "service_name=canbus" | ||
}, | ||
"every_n": 1 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.