forked from EdgeTX/edgetx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cpn): Support JSON radio hardware definitions (EdgeTX#4406)
- Loading branch information
Neil Horne
authored
Feb 4, 2024
1 parent
c6ae44f
commit 8329461
Showing
63 changed files
with
4,161 additions
and
2,290 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
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,95 @@ | ||
/* | ||
* Copyright (C) EdgeTX | ||
* | ||
* Based on code named | ||
* opentx - https://github.com/opentx/opentx | ||
* th9x - http://code.google.com/p/th9x | ||
* er9x - http://code.google.com/p/er9x | ||
* gruvin9x - http://code.google.com/p/gruvin9x | ||
* | ||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
#include "boardfactories.h" | ||
|
||
BoardFactories* gBoardFactories = nullptr; | ||
|
||
BoardFactories::BoardFactories() : | ||
m_default(nullptr) | ||
{ | ||
if (registerBoard(Board::BOARD_UNKNOWN, "")) | ||
m_default = instance(Board::BOARD_UNKNOWN); | ||
} | ||
|
||
BoardFactories::~BoardFactories() | ||
{ | ||
unregisterBoardFactories(); | ||
} | ||
|
||
BoardJson* BoardFactories::instance(Board::Type board) const | ||
{ | ||
for (auto *registeredFactory : registeredBoardFactories) { | ||
if (registeredFactory->instance()->board() == board) | ||
return registeredFactory->instance(); | ||
} | ||
|
||
return m_default; | ||
} | ||
|
||
// Registering firmware triggers registering the associated board | ||
bool BoardFactories::registerBoard(Board::Type board, QString hwdefn) | ||
{ | ||
if (board < Board::BOARD_UNKNOWN || board >= Board::BOARD_TYPE_COUNT) | ||
return false; | ||
|
||
if (m_default || board != Board::BOARD_UNKNOWN) { | ||
BoardJson* regboard = instance(board); | ||
|
||
if (regboard->board() == board) { | ||
if (regboard->hwdefn() == hwdefn) { | ||
//qDebug() << "Warning - Board" << Boards::getBoardName(regboard->board()) << "already registered"; | ||
return true; | ||
} | ||
else { | ||
qDebug() << "Error - Board" << Boards::getBoardName(regboard->board()) << "already registered with" | ||
<< regboard->hwdefn() << "hwdefn!"; | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
BoardFactory *bf = new BoardFactory(board, hwdefn); | ||
if (bf->instance()->loadDefinition()) { | ||
if (registerBoardFactory(bf)) { | ||
qDebug() << "Registered board:" << (board != Board::BOARD_UNKNOWN ? Boards::getBoardName(board) : "UNKNOWN (default)"); | ||
return true; | ||
} | ||
else | ||
delete bf; | ||
} | ||
else | ||
delete bf; | ||
|
||
return false; | ||
} | ||
|
||
bool BoardFactories::registerBoardFactory(BoardFactory * factory) | ||
{ | ||
registeredBoardFactories.append(factory); | ||
return true; | ||
} | ||
|
||
void BoardFactories::unregisterBoardFactories() | ||
{ | ||
for (auto *registeredFactory : registeredBoardFactories) | ||
delete registeredFactory; | ||
} |
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,59 @@ | ||
/* | ||
* Copyright (C) EdgeTX | ||
* | ||
* Based on code named | ||
* opentx - https://github.com/opentx/opentx | ||
* th9x - http://code.google.com/p/th9x | ||
* er9x - http://code.google.com/p/er9x | ||
* gruvin9x - http://code.google.com/p/gruvin9x | ||
* | ||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2 as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "boardjson.h" | ||
|
||
class BoardFactory | ||
{ | ||
public: | ||
explicit BoardFactory(Board::Type board, QString hwdefn) : | ||
m_instance(new BoardJson(board, hwdefn)) | ||
{} | ||
|
||
virtual ~BoardFactory() {} | ||
|
||
BoardJson* instance() const { return m_instance; } | ||
|
||
private: | ||
BoardJson *m_instance; | ||
}; | ||
|
||
class BoardFactories | ||
{ | ||
public: | ||
explicit BoardFactories(); | ||
virtual ~BoardFactories(); | ||
|
||
BoardJson* instance(Board::Type board) const; | ||
|
||
bool registerBoard(Board::Type board, QString hwdefn); | ||
bool registerBoardFactory(BoardFactory * factory); | ||
void unregisterBoardFactories(); | ||
|
||
private: | ||
QList<BoardFactory *> registeredBoardFactories; | ||
|
||
BoardJson *m_default; | ||
}; | ||
|
||
extern BoardFactories* gBoardFactories; |
Oops, something went wrong.