#include "include.h"
#include <Arduino.h>
#include <stdarg.h>
#define ELEMENTS(x) (sizeof(x) / sizeof(x[0]))
//#define ARRAY_WITH_SIZE(x) x,sizeof(x)
/*
#define UNWRAP(...) __VA_ARGS__
#define MYMACRO(T,A) literal<T>(UNWRAP A);
*/
#define MYMACRO(T,...) literal<T>(__VA_ARGS__);
#define FOO(...) "" #__VA_ARGS__
int myArray[] = {2,3,4,5,6}; // Let the computer count how many elements you need
/*
template<typename T, int sz>
void getSize(T(&)[sz]) {
Serial1.printf("getSize: %d\n",sz);
}
*/
/* CHATGPT... */
/*
// Function template to process an array of any type
template<typename T>
void processArray(const T& arr, size_t size) {
for (size_t i = 0; i < size; ++i) {
Serial.print(arr[i]);
Serial.print(" ");
}
Serial.println();
}
#define PROCESS_ARRAY(T, ...) processArray<T>({__VA_ARGS__}, sizeof((T[]){__VA_ARGS__}) / sizeof(T))
// Macro to simplify the process of calling processArray
//#define BRACED_INIT_LIST(...) {__VA_ARGS__}
//#define PROCESS_ARRAY(T, ...) processArray<T>(BRACED_INIT_LIST(__VA_ARGS__), sizeof((T[]){__VA_ARGS__}) / sizeof(T))
*/
//MYMACRO( long[2], ({1, 2}) );
/*
void parseArray() {
arraySize(arr1);
//Serial1.printf("mySize: %d\n",arraySize({1,2,3,4}));
}
*/
/*
template<typename T>
void parseArray(const T& (&arr), size_t size) {
for (size_t i = 0; i < size; ++i) {
Serial.print(arr[i]);
Serial.print(" ");
}
Serial.println();
}
*/
template <class Type, size_t Size>
struct ArrayWrapper {
Type data[Size];
};
ArrayWrapper<int, 3> a = {{ 1, 2, 3 }};
ArrayWrapper<float, 2> b = {{ 0.1, 0.2 }};
template<typename T, int sz>
void getSize(T(&)[sz]) {
Serial1.printf("getSize: %d\n",sz);
}
template<typename T>
void parseArray(const T& myArgs) {
Serial1.print(myArgs);
Serial1.println();
}
#define ARRAY_MACRO(T, ...) parseArray<T>(__VA_ARGS__)
void readArray(const int (&arr)[4]) {
//Serial1.println(__VA_ARGS__);
int i;
Serial1.println("readArray() :");
for (i = 0; i < ELEMENTS(arr); i++) {
Serial1.print(arr[i]); // Array indexing
Serial1.print(" ");
}
Serial1.println();
//getSize(arr);
//int mySize = getSize({1,2,3,4});
//Serial1.printf("mySize: %d\n",getSize({1,2,3,4}));
}
template <typename T, size_t N> void myFunc(T(& myArray)[N]) {
Serial1.println(N);
};
void setup() {
Serial1.begin(115200);
Serial1.println("Hello user!");
Serial1.println();
delay(1000);
ARRAY_MACRO(int, 41);
readArray({1,2,3,4});
//myFunc(int, 4, {1,2,3,4});
// Example usage of the macro with int type
//PROCESS_ARRAY(1, 2, 3, 4);
//PROCESS_ARRAY(int, (1, 2, 3, 4));
// Example usage of the macro with double type
//PROCESS_ARRAY(double, 0.5, 1.5, 2.5);
//arr1[] = {5,6,7,8,9};
//size_t arr_size = sizeof(arr1)/sizeof(arr1[0]);
//Serial1.println(FOO(1,2,3));
//Serial1.printf("arr_size: %d\n",(sizeof arr / sizeof arr[0]));
//Serial1.printf("arr_size: %zu, %zu\n",sizeof arr, sizeof arr[0]);
}
void loop() {
// Your main code here
}