add clang-format and format all source files

This commit is contained in:
Peter Buchegger 2021-03-12 23:21:45 +01:00
parent fd4e34bb6c
commit ff25ad4696
41 changed files with 1664 additions and 1808 deletions

View file

@ -1,167 +1,135 @@
#include "BoardFinder.h"
#include <logger.h>
#include <power_management.h>
#include "BoardFinder.h"
BoardConfig::BoardConfig(
String name, BoardType type,
uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset,
uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq,
bool needcheckpowerchip, bool powercheckstatus)
:
Name(name), Type(type),
OledSda(oledsda), OledScl(oledscl), OledAddr(oledaddr), OledReset(oledreset),
LoraSck(lorasck), LoraMiso(loramiso), LoraMosi(loramosi), LoraCS(loracs), LoraReset(lorareset), LoraIRQ(lorairq),
needCheckPowerChip(needcheckpowerchip), powerCheckStatus(powercheckstatus)
{
BoardConfig::BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, bool needcheckpowerchip, bool powercheckstatus)
: Name(name), Type(type), OledSda(oledsda), OledScl(oledscl), OledAddr(oledaddr), OledReset(oledreset), LoraSck(lorasck), LoraMiso(loramiso), LoraMosi(loramosi), LoraCS(loracs), LoraReset(lorareset), LoraIRQ(lorairq), needCheckPowerChip(needcheckpowerchip), powerCheckStatus(powercheckstatus) {
}
BoardFinder::BoardFinder(std::list<std::shared_ptr<BoardConfig>> & boardConfigs)
: _boardConfigs(boardConfigs)
{
BoardFinder::BoardFinder(std::list<std::shared_ptr<BoardConfig>> &boardConfigs) : _boardConfigs(boardConfigs) {
}
std::shared_ptr<BoardConfig> BoardFinder::searchBoardConfig()
{
logPrintlnI("looking for a board config.");
logPrintlnI("searching for OLED...");
std::shared_ptr<BoardConfig> BoardFinder::searchBoardConfig() {
logPrintlnI("looking for a board config.");
logPrintlnI("searching for OLED...");
for(std::shared_ptr<BoardConfig> boardconf : _boardConfigs)
{
if(boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus)
{
PowerManagement powerManagement;
TwoWire wire(0);
wire.begin(boardconf->OledSda, boardconf->OledScl);
powerManagement.begin(wire);
powerManagement.activateOLED();
}
else if(boardconf->needCheckPowerChip)
{
continue;
}
if(checkOledConfig(boardconf))
{
logPrintI("found a board config: ");
logPrintlnI(boardconf->Name);
return boardconf;
}
}
for (std::shared_ptr<BoardConfig> boardconf : _boardConfigs) {
if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus) {
PowerManagement powerManagement;
TwoWire wire(0);
wire.begin(boardconf->OledSda, boardconf->OledScl);
powerManagement.begin(wire);
powerManagement.activateOLED();
} else if (boardconf->needCheckPowerChip) {
continue;
}
if (checkOledConfig(boardconf)) {
logPrintI("found a board config: ");
logPrintlnI(boardconf->Name);
return boardconf;
}
}
logPrintlnW("could not find OLED, will search for the modem now...");
logPrintlnW("could not find OLED, will search for the modem now...");
for(std::shared_ptr<BoardConfig> boardconf : _boardConfigs)
{
if(boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus)
{
PowerManagement powerManagement;
TwoWire wire(0);
wire.begin(boardconf->OledSda, boardconf->OledScl);
powerManagement.begin(wire);
powerManagement.activateLoRa();
}
if(checkModemConfig(boardconf))
{
logPrintI("found a board config: ");
logPrintlnI(boardconf->Name);
return boardconf;
}
}
for (std::shared_ptr<BoardConfig> boardconf : _boardConfigs) {
if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus) {
PowerManagement powerManagement;
TwoWire wire(0);
wire.begin(boardconf->OledSda, boardconf->OledScl);
powerManagement.begin(wire);
powerManagement.activateLoRa();
}
if (checkModemConfig(boardconf)) {
logPrintI("found a board config: ");
logPrintlnI(boardconf->Name);
return boardconf;
}
}
logPrintlnW("could not find a board config!");
logPrintlnW("could not find a board config!");
return 0;
return 0;
}
std::shared_ptr<BoardConfig> BoardFinder::getBoardConfig(String name)
{
std::_List_iterator<std::shared_ptr<BoardConfig>> elem = std::find_if(_boardConfigs.begin(), _boardConfigs.end(), [&](std::shared_ptr<BoardConfig> conf)
{
return conf->Name == name;
});
if(elem == _boardConfigs.end())
{
return 0;
}
return *elem;
std::shared_ptr<BoardConfig> BoardFinder::getBoardConfig(String name) {
std::_List_iterator<std::shared_ptr<BoardConfig>> elem = std::find_if(_boardConfigs.begin(), _boardConfigs.end(), [&](std::shared_ptr<BoardConfig> conf) {
return conf->Name == name;
});
if (elem == _boardConfigs.end()) {
return 0;
}
return *elem;
}
bool BoardFinder::checkOledConfig(std::shared_ptr<BoardConfig> boardConfig)
{
if(boardConfig->OledReset > 0)
{
pinMode(boardConfig->OledReset, OUTPUT);
digitalWrite(boardConfig->OledReset, HIGH);
delay(1);
digitalWrite(boardConfig->OledReset, LOW);
delay(10);
digitalWrite(boardConfig->OledReset, HIGH);
}
TwoWire wire(0);
if(!wire.begin(boardConfig->OledSda, boardConfig->OledScl))
{
logPrintlnW("issue with wire");
return false;
}
wire.beginTransmission(boardConfig->OledAddr);
if(!wire.endTransmission())
{
return true;
}
return false;
bool BoardFinder::checkOledConfig(std::shared_ptr<BoardConfig> boardConfig) {
if (boardConfig->OledReset > 0) {
pinMode(boardConfig->OledReset, OUTPUT);
digitalWrite(boardConfig->OledReset, HIGH);
delay(1);
digitalWrite(boardConfig->OledReset, LOW);
delay(10);
digitalWrite(boardConfig->OledReset, HIGH);
}
TwoWire wire(0);
if (!wire.begin(boardConfig->OledSda, boardConfig->OledScl)) {
logPrintlnW("issue with wire");
return false;
}
wire.beginTransmission(boardConfig->OledAddr);
if (!wire.endTransmission()) {
return true;
}
return false;
}
bool BoardFinder::checkModemConfig(std::shared_ptr<BoardConfig> boardConfig)
{
pinMode(boardConfig->LoraReset, OUTPUT);
digitalWrite(boardConfig->LoraReset, LOW);
delay(10);
digitalWrite(boardConfig->LoraReset, HIGH);
delay(10);
bool BoardFinder::checkModemConfig(std::shared_ptr<BoardConfig> boardConfig) {
pinMode(boardConfig->LoraReset, OUTPUT);
digitalWrite(boardConfig->LoraReset, LOW);
delay(10);
digitalWrite(boardConfig->LoraReset, HIGH);
delay(10);
pinMode(boardConfig->LoraCS, OUTPUT);
digitalWrite(boardConfig->LoraCS, HIGH);
pinMode(boardConfig->LoraCS, OUTPUT);
digitalWrite(boardConfig->LoraCS, HIGH);
SPIClass spi;
spi.begin(boardConfig->LoraSck, boardConfig->LoraMiso, boardConfig->LoraMosi, boardConfig->LoraCS);
SPIClass spi;
spi.begin(boardConfig->LoraSck, boardConfig->LoraMiso, boardConfig->LoraMosi, boardConfig->LoraCS);
digitalWrite(boardConfig->LoraCS, LOW);
digitalWrite(boardConfig->LoraCS, LOW);
spi.beginTransaction(SPISettings(8E6, MSBFIRST, SPI_MODE0));
spi.transfer(0x42);
uint8_t response = spi.transfer(0x00);
spi.endTransaction();
spi.beginTransaction(SPISettings(8E6, MSBFIRST, SPI_MODE0));
spi.transfer(0x42);
uint8_t response = spi.transfer(0x00);
spi.endTransaction();
digitalWrite(boardConfig->LoraCS, HIGH);
digitalWrite(boardConfig->LoraCS, HIGH);
if(response == 0x12)
{
return true;
}
return false;
if (response == 0x12) {
return true;
}
return false;
}
bool BoardFinder::checkPowerConfig(std::shared_ptr<BoardConfig> boardConfig)
{
TwoWire wire(0);
if(!wire.begin(boardConfig->OledSda, boardConfig->OledScl))
{
logPrintlnW("issue with wire");
return false;
}
wire.beginTransmission(0x34);
wire.write(0x03);
wire.endTransmission();
wire.requestFrom(0x34, 1);
int response = wire.read();
wire.endTransmission();
bool BoardFinder::checkPowerConfig(std::shared_ptr<BoardConfig> boardConfig) {
TwoWire wire(0);
if (!wire.begin(boardConfig->OledSda, boardConfig->OledScl)) {
logPrintlnW("issue with wire");
return false;
}
wire.beginTransmission(0x34);
wire.write(0x03);
wire.endTransmission();
logPrintlnD(String(response));
if(response == 0x03)
{
logPrintlnD("power chip found!");
return true;
}
logPrintlnD("power chip NOT found");
return false;
wire.requestFrom(0x34, 1);
int response = wire.read();
wire.endTransmission();
logPrintlnD(String(response));
if (response == 0x03) {
logPrintlnD("power chip found!");
return true;
}
logPrintlnD("power chip NOT found");
return false;
}

View file

@ -5,64 +5,58 @@
#include <memory>
#include <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#include <Wire.h>
enum BoardType
{
eHELTEC_WIFI_LORA_32_V1,
eHELTEC_WIFI_LORA_32_V2,
eTTGO_LORA32_V1,
eTTGO_LORA32_V2,
eTTGO_T_Beam_V0_7,
eTTGO_T_Beam_V1_0,
eETH_BOARD,
eTRACKERD
eHELTEC_WIFI_LORA_32_V1,
eHELTEC_WIFI_LORA_32_V2,
eTTGO_LORA32_V1,
eTTGO_LORA32_V2,
eTTGO_T_Beam_V0_7,
eTTGO_T_Beam_V1_0,
eETH_BOARD,
eTRACKERD
};
class BoardConfig
{
class BoardConfig {
public:
explicit BoardConfig(
String name, BoardType type,
uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset,
uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq,
bool needcheckpowerchip = false, bool powercheckstatus = false);
explicit BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, bool needcheckpowerchip = false, bool powercheckstatus = false);
String Name;
BoardType Type;
String Name;
BoardType Type;
uint8_t OledSda;
uint8_t OledScl;
uint8_t OledAddr;
uint8_t OledReset;
uint8_t OledSda;
uint8_t OledScl;
uint8_t OledAddr;
uint8_t OledReset;
uint8_t LoraSck;
uint8_t LoraMiso;
uint8_t LoraMosi;
uint8_t LoraCS;
uint8_t LoraReset;
uint8_t LoraIRQ;
uint8_t LoraSck;
uint8_t LoraMiso;
uint8_t LoraMosi;
uint8_t LoraCS;
uint8_t LoraReset;
uint8_t LoraIRQ;
bool needCheckPowerChip;
bool powerCheckStatus;
bool needCheckPowerChip;
bool powerCheckStatus;
};
class BoardFinder
{
class BoardFinder {
public:
explicit BoardFinder(std::list<std::shared_ptr<BoardConfig>> & boardConfigs);
explicit BoardFinder(std::list<std::shared_ptr<BoardConfig>> &boardConfigs);
std::shared_ptr<BoardConfig> searchBoardConfig();
std::shared_ptr<BoardConfig> searchBoardConfig();
std::shared_ptr<BoardConfig> getBoardConfig(String name);
std::shared_ptr<BoardConfig> getBoardConfig(String name);
private:
std::list<std::shared_ptr<BoardConfig>> _boardConfigs;
std::list<std::shared_ptr<BoardConfig>> _boardConfigs;
bool checkOledConfig(std::shared_ptr<BoardConfig> boardConfig);
bool checkModemConfig(std::shared_ptr<BoardConfig> boardConfig);
bool checkPowerConfig(std::shared_ptr<BoardConfig> boardConfig);
bool checkOledConfig(std::shared_ptr<BoardConfig> boardConfig);
bool checkModemConfig(std::shared_ptr<BoardConfig> boardConfig);
bool checkPowerConfig(std::shared_ptr<BoardConfig> boardConfig);
};
#endif