Repository navigation
Use /sys/class/board-info/ to detect platform type #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,41 +1,17 @@ | ||
|
|
||
| """ | ||
| Use platform.machine() to determine the platform type, cache the | ||
| results in /tmp/current_platform so that we do not have to import | ||
| platform and run platform.machine() each time someone imports ev3dev.auto | ||
| """ | ||
| import os | ||
| from ev3dev.core import get_current_platform | ||
|
|
||
| filename = '/tmp/current_platform' | ||
| current_platform = None | ||
| current_platform = get_current_platform() | ||
|
|
||
| if os.path.exists(filename): | ||
| with open(filename, 'r') as fh: | ||
| current_platform = fh.read().strip() | ||
|
|
||
| if not current_platform: | ||
| import platform | ||
|
|
||
| def get_current_platform(): | ||
| """ | ||
| Guess platform we are running on | ||
| """ | ||
| machine = platform.machine() | ||
|
|
||
| if machine == 'armv5tejl': | ||
| return 'ev3' | ||
| elif machine == 'armv6l': | ||
| return 'brickpi' | ||
| else: | ||
| return 'unsupported' | ||
| if current_platform == 'brickpi': | ||
| from .brickpi import * | ||
|
|
||
| current_platform = get_current_platform() | ||
| elif current_platform == 'evb': | ||
| from .evb import * | ||
|
|
||
| with open(filename, 'w') as fh: | ||
| fh.write(current_platform + '\n') | ||
| elif current_platform == 'pistorms': | ||
| from .pistorms import * | ||
|
|
||
| if current_platform == 'brickpi': | ||
| from .brickpi import * | ||
| else: | ||
| # Import ev3 by default, so that it is covered by documentation. | ||
| from .ev3 import * |
This file contains hidden or 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 hidden or 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,128 @@ | ||
|
|
||
| """ | ||
| An assortment of classes modeling specific features of the EVB. | ||
| """ | ||
|
|
||
| from .core import * | ||
|
|
||
|
|
||
| OUTPUT_A = 'outA' | ||
| OUTPUT_B = 'outB' | ||
| OUTPUT_C = 'outC' | ||
| OUTPUT_D = 'outD' | ||
|
|
||
| INPUT_1 = 'in1' | ||
| INPUT_2 = 'in2' | ||
| INPUT_3 = 'in3' | ||
| INPUT_4 = 'in4' | ||
|
|
||
|
|
||
| class Button(ButtonEVIO): | ||
| """ | ||
| EVB Buttons | ||
| """ | ||
|
|
||
| _buttons = { | ||
| 'up': {'name': '/dev/input/by-path/platform-evb-buttons-event', 'value': 103}, | ||
| 'down': {'name': '/dev/input/by-path/platform-evb-buttons-event', 'value': 108}, | ||
| 'left': {'name': '/dev/input/by-path/platform-evb-buttons-event', 'value': 105}, | ||
| 'right': {'name': '/dev/input/by-path/platform-evb-buttons-event', 'value': 106}, | ||
| 'enter': {'name': '/dev/input/by-path/platform-evb-buttons-event', 'value': 28}, | ||
| 'backspace': {'name': '/dev/input/by-path/platform-evb-buttons-event', 'value': 14}, | ||
| } | ||
|
|
||
| @property | ||
| @staticmethod | ||
| def on_up(state): | ||
| """ | ||
| This handler is called by `process()` whenever state of 'up' button | ||
| has changed since last `process()` call. `state` parameter is the new | ||
| state of the button. | ||
| """ | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def on_down(state): | ||
| """ | ||
| This handler is called by `process()` whenever state of 'down' button | ||
| has changed since last `process()` call. `state` parameter is the new | ||
| state of the button. | ||
| """ | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def on_left(state): | ||
| """ | ||
| This handler is called by `process()` whenever state of 'left' button | ||
| has changed since last `process()` call. `state` parameter is the new | ||
| state of the button. | ||
| """ | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def on_right(state): | ||
| """ | ||
| This handler is called by `process()` whenever state of 'right' button | ||
| has changed since last `process()` call. `state` parameter is the new | ||
| state of the button. | ||
| """ | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def on_enter(state): | ||
| """ | ||
| This handler is called by `process()` whenever state of 'enter' button | ||
| has changed since last `process()` call. `state` parameter is the new | ||
| state of the button. | ||
| """ | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def on_backspace(state): | ||
| """ | ||
| This handler is called by `process()` whenever state of 'backspace' button | ||
| has changed since last `process()` call. `state` parameter is the new | ||
| state of the button. | ||
| """ | ||
| pass | ||
|
|
||
| def up(self): | ||
| """ | ||
| Check if 'up' button is pressed. | ||
| """ | ||
| return 'up' in self.buttons_pressed | ||
|
|
||
| @property | ||
| def down(self): | ||
| """ | ||
| Check if 'down' button is pressed. | ||
| """ | ||
| return 'down' in self.buttons_pressed | ||
|
|
||
| @property | ||
| def left(self): | ||
| """ | ||
| Check if 'left' button is pressed. | ||
| """ | ||
| return 'left' in self.buttons_pressed | ||
|
|
||
| @property | ||
| def right(self): | ||
| """ | ||
| Check if 'right' button is pressed. | ||
| """ | ||
| return 'right' in self.buttons_pressed | ||
|
|
||
| @property | ||
| def enter(self): | ||
| """ | ||
| Check if 'enter' button is pressed. | ||
| """ | ||
| return 'enter' in self.buttons_pressed | ||
|
|
||
| @property | ||
| def backspace(self): | ||
| """ | ||
| Check if 'backspace' button is pressed. | ||
| """ | ||
| return 'backspace' in self.buttons_pressed | ||
This file contains hidden or 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,16 @@ | ||
|
|
||
| """ | ||
| An assortment of classes modeling specific features of the PiStorms. | ||
| """ | ||
|
|
||
| from .core import * | ||
|
|
||
| OUTPUT_A = 'pistorms:BBM1' | ||
| OUTPUT_B = 'pistorms:BBM2' | ||
| OUTPUT_C = 'pistorms:BAM2' | ||
| OUTPUT_D = 'pistorms:BAM1' | ||
|
|
||
| INPUT_1 = 'pistorms:BBS1' | ||
| INPUT_2 = 'pistorms:BBS2' | ||
| INPUT_3 = 'pistorms:BAS2' | ||
| INPUT_4 = 'pistorms:BAS1' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so you can do things like
I'm working on making this event driven as part of the buttons API work...today you have to call it in a while loop like that to make it do what you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. Damn, Python is weird 😆 Is that a common idiom? Is there not an event framework of some sort?
Either way, I don't think it's blocking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This project is the only place I've seen this approach used...but I've only been writing python for 4 years so who knows maybe it is wildly popular and I just haven't been exposed to it.