Skip to content

Please i beg #1

@snowy-shadow

Description

@snowy-shadow

remove all #define and use constexpr instead.

// please do not do this

#define HW_SERIAL1 1 
#define HW_SERIAL2 2

#define HW_SERIAL(w) (w == 1 ? Serial1 \
                        : (w == 2 ? Serial2 \
                        : (w == 3 ? Serial3 \
                        : (w == 4 ? Serial4 \
                        : (w == 5 ? Serial5 \
                        : (w == 6 ? Serial6 \
                        : (w == 7 ? Serial7 \
                        : Serial8 \
                        )))))))

// use something like 

constexpr uint32_t HW_SERIAL1 = 1; 
constexpr uint32_t  HW_SERIAL2 = 2;

auto constexpr GetSerial(uint32_t W)
{
	switch(W)
	{
		case 1:
			return Serial1;
		case 2:
			return Serial2;
		case 3:
			...

		default:
			return Serial8;
	}
}

Names beginning with an underscore or a double underscore are RESERVED for the C++ implementers. Names with an underscore are reserved for the library to work.

If you have a read at the C++ Coding Standard, you will see that in the very first page it says:

"Don't overlegislate naming, but do use a consistent naming convention: There are only two must-dos: a) never use "underhanded names," ones that begin with an underscore or that contain a double underscore;" (p2 , C++ Coding Standards, Herb Sutter and Andrei Alexandrescu)

see https://stackoverflow.com/questions/3136594/naming-convention-underscore-in-c-and-c-sharp-variables

// change this into
typedef struct _magnetometerData
{
    float magneticX;
    float magneticY;
    float magneticZ;
} MagnetometerData;

struct MagnetometerData
{
    float magneticX;
    float magneticY;
    float magneticZ;
};

// if you want default values then
struct MagnetometerData
{
    float magneticX = 0.f;
    float magneticY = 0.f;
    float magneticZ = 0.f;
};

// and then you create the object with default value as

MagnetometerData M{}; 

// instead of manually writing it out

return by reference instead of by pointer

class SensorBMP280: Sensor
{
public:
	BMP280Data* read();
}

// change to either, c++ have these type safe features, lets use it
BMP280Data& read();
const BMP280Data& read();
const BMP280Data& read() const;

please fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions