This repository has been archived by the owner on Feb 8, 2023. It is now read-only.
forked from FeralAI/GP2040
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from arntsonl/addonrework
Addon Rework - Per-Core Addons with Manager
- Loading branch information
Showing
19 changed files
with
107 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef _ADDONMANAGER_H_ | ||
#define _ADDONMANAGER_H_ | ||
|
||
#include "gpaddon.h" | ||
|
||
#include <vector> | ||
#include <pico/mutex.h> | ||
|
||
typedef enum ADDON_PROCESS { | ||
CORE0_INPUT, | ||
CORE1_LOOP | ||
} _ADDON_PROCESS; | ||
|
||
typedef struct AddonBlock { | ||
GPAddon * ptr; | ||
ADDON_PROCESS process; | ||
bool enabled; | ||
}; | ||
|
||
class AddonManager { | ||
public: | ||
AddonManager() {} | ||
~AddonManager() {} | ||
void LoadAddon(GPAddon*, ADDON_PROCESS, bool enabled=true); | ||
void ProcessAddons(ADDON_PROCESS); | ||
GPAddon * GetAddon(std::string); // hack for NeoPicoLED | ||
private: | ||
std::vector<AddonBlock*> addons; // addons currently loaded | ||
}; | ||
|
||
#endif |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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,30 @@ | ||
#include "addonmanager.h" | ||
|
||
void AddonManager::LoadAddon(GPAddon* addon, ADDON_PROCESS processAt, bool enabled) { | ||
if (addon->available()) { | ||
AddonBlock * block = new AddonBlock; | ||
addon->setup(); | ||
block->ptr = addon; | ||
block->process = processAt; | ||
block->enabled = enabled; | ||
addons.push_back(block); | ||
} else { | ||
delete addon; // Don't use the memory if we don't have to | ||
} | ||
} | ||
|
||
void AddonManager::ProcessAddons(ADDON_PROCESS processType) { | ||
// Loop through all addons and process any that match our type | ||
for (std::vector<AddonBlock*>::iterator it = addons.begin(); it != addons.end(); it++) { | ||
if ( (*it)->process == processType && (*it)->enabled == true) | ||
(*it)->ptr->process(); | ||
} | ||
} | ||
|
||
// HACK : change this for NeoPicoLED | ||
GPAddon * AddonManager::GetAddon(std::string name) { // hack for NeoPicoLED | ||
for (std::vector<AddonBlock*>::iterator it = addons.begin(); it != addons.end(); it++) { | ||
if ( (*it)->ptr->name() == name ) | ||
return (*it)->ptr; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "inputs/analog.h" | ||
#include "addons/analog.h" | ||
#include "storagemanager.h" | ||
|
||
#include "hardware/adc.h" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "inputs/jslider.h" | ||
#include "addons/jslider.h" | ||
|
||
#include "storagemanager.h" | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "inputs/reverse.h" | ||
#include "addons/reverse.h" | ||
#include "storagemanager.h" | ||
#include "GamepadEnums.h" | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "inputs/turbo.h" | ||
#include "addons/turbo.h" | ||
|
||
#include "storagemanager.h" | ||
|
||
|
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 |
---|---|---|
@@ -1,36 +1,35 @@ | ||
// GP2040 includes | ||
#include "gp2040aux.h" | ||
#include "gamepad.h" | ||
#include "storagemanager.h" // Managers | ||
|
||
#include "storagemanager.h" // Global Managers | ||
#include "addonmanager.h" | ||
|
||
#include "addons/i2cdisplay.h" // Add-Ons | ||
#include "addons/neopicoleds.h" | ||
#include "addons/playerleds.h" | ||
|
||
#include <iterator> | ||
|
||
GP2040Aux::GP2040Aux() { | ||
GP2040Aux::GP2040Aux() : nextRuntime(0) { | ||
} | ||
|
||
GP2040Aux::~GP2040Aux() { | ||
} | ||
|
||
void GP2040Aux::setup() { | ||
setupAddon(new I2CDisplayAddon()); | ||
setupAddon(new NeoPicoLEDAddon()); | ||
setupAddon(new PlayerLEDAddon()); | ||
addons.LoadAddon(new I2CDisplayAddon(), CORE1_LOOP); | ||
addons.LoadAddon(new NeoPicoLEDAddon(), CORE1_LOOP); | ||
addons.LoadAddon(new PlayerLEDAddon(), CORE1_LOOP); | ||
} | ||
|
||
void GP2040Aux::run() { | ||
while (1) { | ||
for (std::vector<GPAddon*>::iterator it = Storage::getInstance().Addons.begin(); it != Storage::getInstance().Addons.end(); it++) { | ||
(*it)->process(); | ||
if (nextRuntime > getMicro()) { // fix for unsigned | ||
sleep_us(50); // Give some time back to our CPU (lower power consumption) | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
void GP2040Aux::setupAddon(GPAddon* addon) { | ||
if (addon->available()) { | ||
addon->setup(); | ||
Storage::getInstance().Addons.push_back(addon); | ||
addons.ProcessAddons(CORE1_LOOP); | ||
nextRuntime = getMicro() + GAMEPAD_POLL_MICRO; | ||
} | ||
} |
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