Skip to content

Commit

Permalink
code reuse good!
Browse files Browse the repository at this point in the history
  • Loading branch information
rusefillc committed Nov 15, 2023
1 parent e686b25 commit b1d7694
Showing 1 changed file with 2 additions and 39 deletions.
41 changes: 2 additions & 39 deletions GDI-4ch/firmware/can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,10 @@
#include "chprintf.h"

#define GDI4_CAN_SET_TAG 0x78

// https://stackoverflow.com/questions/19760221/c-get-the-month-as-number-at-compile-time

#define __MONTH__ (\
__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? 1 : 6) \
: __DATE__ [2] == 'b' ? 2 \
: __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 3 : 4) \
: __DATE__ [2] == 'y' ? 5 \
: __DATE__ [2] == 'l' ? 7 \
: __DATE__ [2] == 'g' ? 8 \
: __DATE__ [2] == 'p' ? 9 \
: __DATE__ [2] == 't' ? 10 \
: __DATE__ [2] == 'v' ? 11 \
: 12)

// https://stackoverflow.com/questions/46899202/how-to-split-date-and-time-macros-into-individual-components-for-variabl
constexpr int compilationDatePortion(const int startIndex, const int totalChars) {

int result = 0;
for (int i = startIndex + totalChars - 1, multiplier = 1;
i >= startIndex;
i--, multiplier *= 10) {
const char c = __DATE__[i];
if (c != ' ') {
result += (c - '0') * multiplier;
}
}

return result;
}

constexpr int compilationYear() {
return compilationDatePortion(7, 4);
}

constexpr int compilationDay() {
return compilationDatePortion(4, 2);
}
#include <rusefi/manifest.h>

// Decimal hex date presented as hex
static char VERSION[] = {compilationYear() / 100, compilationYear() % 100, __MONTH__, compilationDay()};
static char VERSION[] = {compilationYear() / 100, compilationYear() % 100, compilationMonth(), compilationDay()};

extern GDIConfiguration configuration;
extern Pt2001 chip;
Expand Down

0 comments on commit b1d7694

Please sign in to comment.