METRO library for multiple timed events

Has anyone tried to port the METRO library.
https://github.com/thomasfredericks/Metro-Arduino-Wiring
I think it is a great library for simple assignment of multiple timed events without having to keep up with interrupts etc.
Would definitely like to see that in the Spark offering.

1 Like

It’s very easy, in metro.cpp, just replace this

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

with this:

#include "application.h"

Just tested this, and it works.

2 Likes

Thank you for explaining. Now I know how to make an attempt at some other libraries.

1 Like

As far as I know, the sparkCore does follow the wiring interfacing, so if libraries are dependent on them, you can port them pretty easily. Which other libraries are you going to port?

I would like the Adafruit ADS1015 https://github.com/adafruit/Adafruit_ADS1X15

Looks like it may be similar.

I changed the lines as you said. So when I add the Metro.cpp and Metro.h to my sketch and compile, I get these errors. Am I doing something wrong?

> In file included from ../inc/spark_wiring.h:30:0,
> from ../inc/application.h:29,
> from Metro.cpp:10:
> ../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
> #warning "Defaulting to Release Build"
> ^
> Metro.cpp:44:16: warning: extra tokens at end of #ifdef directive [enabled by default]
> #ifdef NOCATCH-UP
> ^
> In file included from ../inc/spark_wiring.h:37:0,
> from ../inc/application.h:29,
> from Metro.cpp:10:
> ../inc/spark_wiring_ipaddress.h: In member function 'IPAddress::operator uint32_t()':
> ../inc/spark_wiring_ipaddress.h:53:52: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
> operator uint32_t() { return *((uint32_t*)_address); };
> ^
> ../inc/spark_wiring_ipaddress.h: In member function 'bool IPAddress::operator==(const IPAddress&)':
> ../inc/spark_wiring_ipaddress.h:54:72: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
> bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
> ^
> ../inc/spark_wiring_ipaddress.h:54:105: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
> bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
> ^
> Metro.cpp: At global scope:
> Metro.cpp:12:1: error: 'Metro' does not name a type
> Metro::Metro()
> ^
> Metro.cpp:20:1: error: 'Metro' does not name a type
> Metro::Metro(unsigned long interval_millis)
> ^
> Metro.cpp:28:6: error: 'Metro' has not been declared
> void Metro::interval(unsigned long interval_millis)
> ^
> Metro.cpp: In function 'void interval(long unsigned int)':
> Metro.cpp:30:3: error: invalid use of 'this' in non-member function
> this->interval_millis = interval_millis;
> ^
> Metro.cpp: At global scope:
> Metro.cpp:33:9: error: 'Metro' has not been declared
> uint8_t Metro::check()
> ^
> Metro.cpp: In function 'uint8_t check()':
> Metro.cpp:38:8: error: 'interval_millis' was not declared in this scope
> if ( interval_millis == 0 ){
> ^
> Metro.cpp:39:5: error: 'previous_millis' was not declared in this scope
> previous_millis = now;
> ^
> Metro.cpp:43:15: error: 'previous_millis' was not declared in this scope
> if ( (now - previous_millis) >= interval_millis) {
> ^
> Metro.cpp:43:35: error: 'interval_millis' was not declared in this scope
> if ( (now - previous_millis) >= interval_millis) {
> ^
> Metro.cpp: At global scope:
> Metro.cpp:56:6: error: 'Metro' has not been declared
> void Metro::reset() 
> ^
> Metro.cpp: In function 'void reset()':
> Metro.cpp:59:3: error: invalid use of 'this' in non-member function
> this->previous_millis = millis();
> ^
> make: *** [Metro.o] Error 1

Sorry, my mistake, I commented out 1 line too many. It compiles now. Thanks

1 Like