Repository navigation
Improved simulator #721
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
Improved simulator #721
Changes from all commits
Commits
Show all changes
2 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
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
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
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
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,8 @@ | ||
| description: Mock power supply with a fixed battery state and toggleable charging | ||
|
|
||
| compatible: "mock,power-supply" | ||
|
|
||
| properties: | ||
| _unused: | ||
| type: int | ||
| default: 0 |
7 changes: 7 additions & 0 deletions
7
Drivers/mock-drivers-module/include/bindings/mock_power_supply.h
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,7 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #pragma once | ||
|
|
||
| #include <tactility/bindings/bindings.h> | ||
| #include <mock/mock_power_supply.h> | ||
|
|
||
| DEFINE_DEVICETREE(power_supply, struct MockPowerSupplyConfig) |
14 changes: 14 additions & 0 deletions
14
Drivers/mock-drivers-module/include/mock/mock_power_supply.h
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,14 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #pragma once | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| struct MockPowerSupplyConfig { | ||
| int _unused; | ||
| }; | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
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,85 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| #include <tactility/device.h> | ||
| #include <tactility/driver.h> | ||
| #include <tactility/drivers/power_supply.h> | ||
|
|
||
| #include <atomic> | ||
|
|
||
| // region PowerSupplyApi | ||
|
|
||
| static std::atomic<bool> allowed_to_charge { true }; | ||
|
|
||
| static bool supports_property(Device*, PowerSupplyProperty property) { | ||
| switch (property) { | ||
| case POWER_SUPPLY_PROP_IS_CHARGING: | ||
| case POWER_SUPPLY_PROP_CURRENT: | ||
| case POWER_SUPPLY_PROP_VOLTAGE: | ||
| case POWER_SUPPLY_PROP_CAPACITY: | ||
| return true; | ||
| default: | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| static error_t get_property(Device*, PowerSupplyProperty property, PowerSupplyPropertyValue* out_value) { | ||
| const bool charging = allowed_to_charge.load(); | ||
| switch (property) { | ||
| case POWER_SUPPLY_PROP_IS_CHARGING: | ||
| out_value->int_value = charging ? 1 : 0; | ||
| return ERROR_NONE; | ||
| case POWER_SUPPLY_PROP_CURRENT: | ||
| out_value->int_value = charging ? 500 : -150; | ||
| return ERROR_NONE; | ||
| case POWER_SUPPLY_PROP_VOLTAGE: | ||
| out_value->int_value = 3950; | ||
| return ERROR_NONE; | ||
| case POWER_SUPPLY_PROP_CAPACITY: | ||
| out_value->int_value = 80; | ||
| return ERROR_NONE; | ||
| default: | ||
| return ERROR_NOT_SUPPORTED; | ||
| } | ||
| } | ||
|
|
||
| static bool supports_charge_control(Device*) { return true; } | ||
| static bool is_allowed_to_charge(Device*) { return allowed_to_charge.load(); } | ||
|
|
||
| static error_t set_allowed_to_charge(Device*, bool allowed) { | ||
| allowed_to_charge.store(allowed); | ||
| return ERROR_NONE; | ||
| } | ||
|
|
||
| static bool supports_quick_charge(Device*) { return false; } | ||
| static bool is_quick_charge_enabled(Device*) { return false; } | ||
| static error_t set_quick_charge_enabled(Device*, bool) { return ERROR_NOT_SUPPORTED; } | ||
| static bool supports_power_off(Device*) { return false; } | ||
| static error_t power_off(Device*) { return ERROR_NOT_SUPPORTED; } | ||
|
|
||
| // endregion | ||
|
|
||
| static const PowerSupplyApi mock_power_supply_api = { | ||
| .supports_property = supports_property, | ||
| .get_property = get_property, | ||
| .supports_charge_control = supports_charge_control, | ||
| .is_allowed_to_charge = is_allowed_to_charge, | ||
| .set_allowed_to_charge = set_allowed_to_charge, | ||
| .supports_quick_charge = supports_quick_charge, | ||
| .is_quick_charge_enabled = is_quick_charge_enabled, | ||
| .set_quick_charge_enabled = set_quick_charge_enabled, | ||
| .supports_power_off = supports_power_off, | ||
| .power_off = power_off, | ||
| }; | ||
|
|
||
| extern "C" { | ||
|
|
||
| Driver mock_power_supply_driver = { | ||
| .name = "mock_power_supply", | ||
| .compatible = (const char*[]) { "mock,power-supply", nullptr }, | ||
| .start_device = nullptr, | ||
| .stop_device = nullptr, | ||
| .api = (const void*)&mock_power_supply_api, | ||
| .device_type = &POWER_SUPPLY_TYPE, | ||
| .internal = nullptr | ||
| }; | ||
|
|
||
| } // extern "C" |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.