MCU
Loading...
Searching...
No Matches
PrintLogger.h
Go to the documentation of this file.
1#ifndef __PRINTLOGGER_H__
2#define __PRINTLOGGER_H__
3#include <stddef.h>
4#include <stdint.h>
5#ifdef ARDUINO
6#include <Arduino.h>
7#else
8#include <cstdarg>
9#include <stdio.h>
10#include <iostream>
11#endif
12
13#ifdef ARDUINO
14template <typename T>
15void logger_println(T out){
16 Serial.println(out);
17}
18#else
19template <typename T>
20void logger_println(T out){
21 std::cout << out<<std::endl;
22}
23#endif
24
26{
27 private:
28 unsigned long last_out_time_;
29 public:
31 {
33 }
34
35 template <typename T>
36 void log_out(T out, unsigned long current_millis, unsigned long period=100) {
37 if((current_millis - last_out_time_) > period)
38 {
39 logger_println<T>(out);
40 last_out_time_ = current_millis;
41 }
42 }
43};
44#endif // __PRINTLOGGER_H__
void logger_println(T out)
Definition: PrintLogger.h:20
void log_out(T out, unsigned long current_millis, unsigned long period=100)
Definition: PrintLogger.h:36
unsigned long last_out_time_
Definition: PrintLogger.h:28