Skip to content

Commit

Permalink
chore: better way to organize arduino library
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierChanth committed Dec 7, 2024
1 parent 6b1a513 commit 9250ed7
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 11 deletions.
2 changes: 2 additions & 0 deletions generators/arduino/atsdk/.clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CompileFlags:
Add: [-xc++, -std=c++11]
4 changes: 0 additions & 4 deletions generators/arduino/atsdk/atsdk_atsdk.cpptemplate

This file was deleted.

10 changes: 5 additions & 5 deletions generators/arduino/atsdk/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,20 @@ fix_rel_headers() {
}

public_headers() {
cat "$script_dir/atsdk.htemplate" >>$src_base/atsdk.h
cp $script_dir/lib/* $src_base/
# cat "$script_dir/atsdk.htemplate" >>$src_base/atsdk.h
for d in ${packages[@]}; do
local includes=$(
cd "$src_base/$d" &&
ls *.h
)
for f in $includes; do

echo "#include \"$d/$f\" // IWYU pragma: export" >>$src_base/atsdk.h
done
done
cp "$script_dir/atsdk_cjson.htemplate" $src_base/atsdk_cjson.h
cp "$script_dir/atsdk_cjson.ctemplate" $src_base/atsdk_cjson.c
cp "$script_dir/atsdk_atsdk.cpptemplate" $src_base/atsdk_atsdk.cpp
# cp "$script_dir/atsdk_cjson.htemplate" $src_base/atsdk_cjson.h
# cp "$script_dir/atsdk_cjson.ctemplate" $src_base/atsdk_cjson.c
# cp "$script_dir/atsdk_atsdk.cpptemplate" $src_base/atsdk_atsdk.cpp
}

echo "Cleaning generated files and folders"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

#ifndef ATSDK_ARDUINO_H
#define ATSDK_ARDUINO_H

#ifdef __cplusplus
extern "C" {
#endif

#include <ctype.h>
#define ATLOGGER_DISABLE_TIMESTAMPS
#include <ctype.h> // IWYU pragma: export

#ifdef __cplusplus
}
Expand Down
43 changes: 43 additions & 0 deletions generators/arduino/atsdk/lib/atsdk_atsdk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// For both development and compile time
#include "atsdk.h"
#include <cstdarg>
#include <cstdio>
#include <cstdlib>

#ifdef __clang__ // For development to supress irrelevant errors
#include "../../../../packages/atlogger/include/atlogger/atlogger.h"
class DummySerial {
public:
void print(const char *);
void println(const char *);
};
extern DummySerial Serial;

#else // Actual compile time includes
#include <Arduino.h>
#endif

void atsdk_arduino_setup() {}

extern "C" {
void atlogger_log(const char *tag, const enum atlogger_logging_level level, const char *format, ...) {
atlogger_logging_level allowed_level = atlogger_get_logging_level();
if (level > allowed_level) {
return;
}

va_list args;
va_start(args, format);
if (tag != nullptr) {
Serial.print(tag);
Serial.print(" | ");
}
int len = vsnprintf(NULL, 0, format, args);
char *buf = new char[len + 1];
vsnprintf(buf, len, format, args);
Serial.println(buf);
delete[] buf;

va_end(args);
}
}
File renamed without changes.
File renamed without changes.

0 comments on commit 9250ed7

Please sign in to comment.