Skip to content

Commit

Permalink
String split
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteHudyma committed Dec 2, 2024
1 parent 5577666 commit 8fe280e
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/system/behavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ typedef enum
// Should never happen, default state
ERROR,
} BehaviorStates;
String BehaviorStatesStr[] = {
const char* BehaviorStatesStr[] = {
"START_LOGIC",
"PRE_CHARGER_OPERATION",
"CHARGER_OPERATIONS",
Expand Down
2 changes: 1 addition & 1 deletion src/system/charger/PDlib/drivers/FUSB302.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern "C" {

/* I2C slave address varies by part number */
/* FUSB302BUCX / FUSB302BMPX */
#define fusb302_I2C_SLAVE_ADDR 0x22 // 7-bit address for Arduino
#define fusb302_I2C_SLAVE_ADDR 0x22 // 7-bit address
/* FUSB302B01MPX */
#define fusb302_I2C_SLAVE_ADDR_B01 0x23
/* FUSB302B10MPX */
Expand Down
22 changes: 11 additions & 11 deletions src/system/charger/charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,39 +353,39 @@ bool Charger_t::is_charging() const
status == ChargerStatus_t::CHARGING;
}

String Charger_t::get_status_str() const
std::string Charger_t::get_status_str() const
{
switch (status)
{
case ChargerStatus_t::UNINITIALIZED:
return String("UNINITIALIZED");
return std::string("UNINITIALIZED");
break;
case ChargerStatus_t::INACTIVE:
return String("INACTIVE");
return std::string("INACTIVE");
break;
case ChargerStatus_t::POWER_DETECTED:
return String("POWER_DETECTED");
return std::string("POWER_DETECTED");
break;
case ChargerStatus_t::SLOW_CHARGING:
return String("SLOW_CHARGING");
return std::string("SLOW_CHARGING");
break;
case ChargerStatus_t::CHARGING:
return String("CHARGING");
return std::string("CHARGING");
break;
case ChargerStatus_t::CHARGE_FINISHED:
return String("CHARGE_FINISHED");
return std::string("CHARGE_FINISHED");
break;
case ChargerStatus_t::ERROR_BATTERY_MISSING:
return String("ERROR_BATTERY_MISSING");
return std::string("ERROR_BATTERY_MISSING");
break;
case ChargerStatus_t::ERROR_SOFTWARE:
return String("ERROR_SOFTWARE");
return std::string("ERROR_SOFTWARE");
break;
case ChargerStatus_t::ERROR_HARDWARE:
return String("ERROR_HARDWARE");
return std::string("ERROR_HARDWARE");
break;
default:
return String("unhandled state");
return std::string("unhandled state");
break;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/system/charger/charger.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#ifndef CHARGER_H
#define CHARGER_H

#include <Arduino.h>

#include <cstdint>
#include <string>

namespace charger {

Expand Down Expand Up @@ -62,7 +61,7 @@ struct Charger_t

// return true when the status is charging or powered
bool is_charging() const;
String get_status_str() const;
std::string get_status_str() const;
};

bool is_vbus_powered();
Expand Down
1 change: 0 additions & 1 deletion src/system/colors/colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#ifdef LMBD_LAMP_TYPE__INDEXABLE

#include <cstdint>
#include <Arduino.h>

#include "src/system/colors/palettes.h"
#include "src/system/utils/constants.h"
Expand Down
3 changes: 1 addition & 2 deletions src/system/physical/battery.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef BATTERY_H
#define BATTERY_H

#include "Arduino.h"

#include <cstdint>
namespace battery {

// return a number between 0 and 10000 (% * 100)
Expand Down
2 changes: 1 addition & 1 deletion src/system/platform/i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "Wire.h"

// set the two interfaces
TwoWire* interfaces[] = {&Wire, &Wire1};
TwoWire* PROGMEM interfaces[] = {&Wire, &Wire1};

void i2c_setup(uint8_t i2cIndex, uint32_t baudrate, uint32_t timeout)
{
Expand Down
25 changes: 3 additions & 22 deletions src/system/utils/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,19 @@

#include <cstdint>

#ifdef ARDUINO
#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#include <pins_arduino.h>
#endif

#ifdef USE_TINYUSB // For Serial when selecting TinyUSB
#include <Adafruit_TinyUSB.h>
#endif

#endif

#ifdef TARGET_LPC1768
#include <Arduino.h>
#endif

#if defined(ARDUINO_ARCH_RP2040)
#include <stdlib.h>

#include "hardware/clocks.h"
#include "hardware/pio.h"
#include "rp2040_pio.h"
#endif

#include <stdint.h>

#include "src/user/constants.h"

const String HARDWARE_VERSION = "1.0";
const String BASE_SOFTWARE_VERSION = "0.01"; // Update when the soft changes version
#define HARDWARE_VERSION "1.0"
// Update when the soft changes version
#define BASE_SOFTWARE_VERSION "0.01"

constexpr uint8_t ADC_RES_EXP = 12; // resolution of the ADC, in bits (can be 8, 10, 12 or 14)
constexpr uint32_t ADC_MAX_VALUE = pow(2, ADC_RES_EXP); // corresponding max value
Expand Down
2 changes: 1 addition & 1 deletion src/system/utils/serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void handleCommand(const String& command)
Serial.print("battery level:");
Serial.print(battery::get_battery_level() / 100.0);
Serial.println("%");
Serial.println(chargerState.get_status_str());
Serial.println(chargerState.get_status_str().c_str());
break;
}

Expand Down
11 changes: 6 additions & 5 deletions src/user/constants.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef USER_CONSTANTS_H
#define USER_CONSTANTS_H

#include <Arduino.h>

//
// common to all lamp type
//
Expand All @@ -16,7 +14,8 @@ static constexpr bool usermodeDefaultsToLockdown = false;

#ifdef LMBD_LAMP_TYPE__SIMPLE

const String SOFTWARE_VERSION = "0.1"; // Update when the soft changes version
// Update when the soft changes version
#define SOFTWARE_VERSION "0.1"

// parameters of the led strip used
constexpr float consWattByMeter = 12; // power consumption (in Watt/meters)
Expand All @@ -31,7 +30,8 @@ constexpr float ledStripLenght_mm = 91.0 * 25.0; // 91 sections of 25 mm

#ifdef LMBD_LAMP_TYPE__CCT

const String SOFTWARE_VERSION = "0.1"; // Update when the soft changes version
// Update when the soft changes version
#define SOFTWARE_VERSION "0.1"

// parameters of the led strip used
constexpr float consWattByMeter = 10; // power consumption (in Watt/meters)
Expand All @@ -46,7 +46,8 @@ constexpr float ledStripLenght_mm = 67.0 * 27.0; // 67 sections of 27 mm

#ifdef LMBD_LAMP_TYPE__INDEXABLE

const String SOFTWARE_VERSION = "0.1"; // Update when the soft changes version
// Update when the soft changes version
#define SOFTWARE_VERSION "0.1"

constexpr float lampBodyRadius_mm = 25; // external radius of the lamp body

Expand Down

0 comments on commit 8fe280e

Please sign in to comment.