These are chat archives for esp8266/Arduino

31st
Aug 2015
Anwar Hahj Jefferson-George
@anwarhahjjeffersongeorge
Aug 31 2015 13:01 UTC
@Links2004 @igrr if I want to enable one of the i2s interrupts (not the SLC interrupts) detailed in esp8266_peri.h, should I use the ETS_SOFT_INUM in ETS_INTR_ENABLE and ETS_INTR_DISABLE ?
methods from ets_sys.h?
Ivan Grokhotkov
@igrr
Aug 31 2015 13:10 UTC
i have no idea what is the I2S interrupt number... I've only seen that ETS_SLC_INUM is equal to 1, but no mention of ETS_I2S_INUM
Anwar Hahj Jefferson-George
@anwarhahjjeffersongeorge
Aug 31 2015 14:34 UTC
i guess I will just try to figure it out and make a pull request if i get it.
tzapu
@tzapu
Aug 31 2015 20:31 UTC
guys, does anyone have handy a singletone example that compiles and works ok in arduino ide/compiler, i ve been pulling my hair out for two days now, and hitting all kinds of walls :(
Neil Kolban
@nkolban
Aug 31 2015 20:32 UTC
by singletone ... do you mean audio or singleton as in programming with a "singleton" pattern?
tzapu
@tzapu
Aug 31 2015 20:32 UTC
singleton pattern
the very much frowned upon singleton pattern
Neil Kolban
@nkolban
Aug 31 2015 20:33 UTC
Can you elaborate more on what you are trying to achieve and what you have tried so far?
tzapu
@tzapu
Aug 31 2015 20:33 UTC
or a way to call interrupts from my class
so, i have a library class, and i am trying to setup some callbacks to some other functions in my class
web server callbacks
but can t do it in the library because apparently it doesn t know what instance to call
i ve tried a c++ example for singletons, with a private constructor and static instance
but run into errors like undefined reference to `__cxa_guard_acquire'
which i found out is the cpp multi threading guard or something
Neil Kolban
@nkolban
Aug 31 2015 20:36 UTC
Perhaps ... instead of coding in C++ and classes, simply code in C and you will no longer have the issue?
If your calling library is "C" and you want to call into a "C++" class instance, I don't think you can do that.
tzapu
@tzapu
Aug 31 2015 20:38 UTC
well, i was under the impression that to make a library, you would be making a class?
Neil Kolban
@nkolban
Aug 31 2015 20:38 UTC
From "C", a function call is basically a "subroutine call to a specific memory address"
to call into C++, the runtime has to setup the environment to satisfy "this" and other class instance data.
tzapu
@tzapu
Aug 31 2015 20:38 UTC
or at least the arduino tutorial implied that
so it looks like i m stuck to making a class if i want to make a library
i assume i could just make and populate the instance that points to the class myself and not rely on any of the cpp compiler magic that i have no idea what it does anyway
Neil Kolban
@nkolban
Aug 31 2015 20:40 UTC
I am imagining you have a library that is a black box to you ...
I am imagining that it accepts a "callback function pointer" ...
and will call that function pointer at a specific time/place ....
Is that correct?
tzapu
@tzapu
Aug 31 2015 20:40 UTC
yes
sounds correct
my library is using the ESP8266WebServer library
Neil Kolban
@nkolban
Aug 31 2015 20:41 UTC
So ... the library is expecting you to supply an entry point to a "C" language function.
Not a method in a C++ class
tzapu
@tzapu
Aug 31 2015 20:41 UTC
and it s functions like server.on("/", handleRoot);
you are correct again
i figured as much, that i need to have a static stub method that calls the method on my class
if those are the correct terms
Neil Kolban
@nkolban
Aug 31 2015 20:42 UTC
... and that's where it gets beyond me I'm afraid. I simply don't know how to call a static C++ method from a C language routine.
and I think THAT is the crux of the story.
tzapu
@tzapu
Aug 31 2015 20:44 UTC
it just seems so messy...
well, thank you very much anyway for taking the time to run me through it
i was just trying to find the best/correctest way of doing it... it just all messy :)
Neil Kolban
@nkolban
Aug 31 2015 20:46 UTC
I think its messy because we are mixing languages .... if the library were "C++" aware, then one would pass in an instance of the class that had the correct members as opposed to a function pointer.
However ... you can always drop down to "C" in a "C++" environment.
tzapu
@tzapu
Aug 31 2015 20:46 UTC
true...but the lib is made to be used from the main app, not to be called from another class/lib it seems
well, my knowledge unfortunately is quite limited of c and c++
Ivan Grokhotkov
@igrr
Aug 31 2015 20:48 UTC
@tzapu can you show some (possibly non-working) code so I can get an idea what are you trying to achieve
tzapu
@tzapu
Aug 31 2015 20:50 UTC
sure, one sec, thanks
this is my lib: https://github.com/tzapu/WiFiManager and i am trying to move it all to use tha latest advanced dns capture portal sample
in the capture portal i ve got the call backs for the various pages/routes
/*(server.on("/wifi", handleWifi);
server.on("/wifisave", handleWifiSave);
server.on("/generate_204", handleRoot); //Android captive portal. Maybe not needed. Might be handled by notFound handler.
server.on("/fwlink", handleRoot); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
that i can not assign in my library because it s a class, and callbacks apparently cant belong or can t find the instance they belong to
so i m stuck on assigning handleWifi, handleRoot and so on
in my lib

i tried to make it a singleton using some info i found, with private constructor private:
WiFiManager();

WiFiManager(WiFiManager const&);// Don't Implement
WiFiManager operator=(WiFiManager const&); // Don't implement

and public instance
public:

static WiFiManager& instance();
Neil Kolban
@nkolban
Aug 31 2015 20:53 UTC
So what you want to have happen is an instance of your WiFiManager class have methods on it that will be invoked when an "on(...)" event is detected?
tzapu
@tzapu
Aug 31 2015 20:54 UTC
yes @nkolban
but the c++ way seems to run into this
iFiManager.cpp.o: In function WiFiManager::WiFiManager()': WiFiManager.cpp:20: undefined reference tocxa_guard_acquire'
WiFiManager.cpp:20: undefined reference to `
cxa_guard_release'
WiFiManager.cpp:20: undefined reference to __cxa_guard_acquire' WiFiManager.cpp:20: undefined reference to__cxa_guard_release'
Ivan Grokhotkov
@igrr
Aug 31 2015 20:54 UTC
okay, got it. will write you a code snippet once I'm near my laptop in 30mins. what you want to do is pretty easy.
tzapu
@tzapu
Aug 31 2015 20:55 UTC
wow, you guys truly are amazing
:D
these projects are so much fun :D
Neil Kolban
@nkolban
Aug 31 2015 20:55 UTC
Oooh!! I'm excited to see what @igrr has ... this is a GREAT learning experience for both of us.
Ivan Grokhotkov
@igrr
Aug 31 2015 20:55 UTC
and im pretty sure this doesn't need a singlton
Neil Kolban
@nkolban
Aug 31 2015 20:56 UTC
@igrr .... I battled this problem a few weeks ago but was too weak and gave up. I wanted to call into a C++ class from an espconn_xxx() callback.
tzapu
@tzapu
Aug 31 2015 20:57 UTC
that would be very cool. all i was able to find trolling the forums and everywhere else is that i can t call a callback in a class because it won t know what instance to address, and the workaround was just to have a static function that called the instance you previusly saved somewhere
and so on
very much looking forward to see now :D
@nkolban a bit of a problem for noobs like me regarding stuff like this is that i don t know when to search for arduino specific stuff, when for c++ stuff and when for c stuff
Neil Kolban
@nkolban
Aug 31 2015 20:59 UTC
We also need to realize that this isn't actually an Arduino.
tzapu
@tzapu
Aug 31 2015 20:59 UTC
:)), yes, that too
Neil Kolban
@nkolban
Aug 31 2015 20:59 UTC
What @igrr has done is made the Arudino IDE available for writing C and C++ programs that run on the ESP8266.
That is part 1.
tzapu
@tzapu
Aug 31 2015 21:00 UTC
i think the singleton stuff might actually compile fine on a yun
or similar
Neil Kolban
@nkolban
Aug 31 2015 21:00 UTC
Part 2 is that he has implemented a LOT of the Arduino APIs (that a programmer might expect to find on a real Arduino) to be available on the ESP8266.
tzapu
@tzapu
Aug 31 2015 21:00 UTC

i got it to compile by adding #ifndef cxafix

define cxafix

extern "C" {
extension typedef int guard attribute((mode (DI)));
int
cxa_guard_acquire(guard g) {return !(char )(g);};
void
cxa_guard_release (__guard g) {(char *)g = 1;};
volatile unsigned long timer0_millis = 0;
};

endif

in main ino, but i can t make it work with it in the lib...

Neil Kolban
@nkolban
Aug 31 2015 21:01 UTC
So in Arduino land, when you call pinWrite() .... that calls Arduino supplied code that drives the ATMEGA
while on the ESP8266, what @igrr has done is implemented the same named function but this time it drives ESP8266 code
So we have illusion upon illusion.
tzapu
@tzapu
Aug 31 2015 21:01 UTC
cross compiling this stuff so it works on all these sdks and hardwares and so on
is just ming boggling for me
Neil Kolban
@nkolban
Aug 31 2015 21:02 UTC
Well ... we have a GREAT community of folks who have time, interest and patience. Just keep plugging at it and keep coming back here and the forums when you run into troubles.
... and before long ... you too will be responding.
tzapu
@tzapu
Aug 31 2015 21:15 UTC
new staging version as well, nice
came up with this
Neil Kolban
@nkolban
Aug 31 2015 21:25 UTC
std::bind?
I'm trying to see where the callback occurs?
tzapu
@tzapu
Aug 31 2015 21:29 UTC
nicee
i assume here
  server->on(uri, std::bind(&Counter::handleRequest, this));
Ivan Grokhotkov
@igrr
Aug 31 2015 21:29 UTC
server callback calls Counter::handleRequest
tzapu
@tzapu
Aug 31 2015 21:29 UTC
and would &Counter represent the current instance then?
Neil Kolban
@nkolban
Aug 31 2015 21:29 UTC
It looks like line 14 is the magic.
We are registering a method called "handleRequest" which is on an instance of Counter to be called back ... passing in the context of the counter.
Ivan Grokhotkov
@igrr
Aug 31 2015 21:29 UTC
this refers to current instance
tzapu
@tzapu
Aug 31 2015 21:29 UTC
boy @igrr you sure are a some kind of voodoo doctor
ah, yes
i get it now
class::function, scope
Ivan Grokhotkov
@igrr
Aug 31 2015 21:30 UTC
&Counter::handleRequest is the full name of the function
correct :)
tzapu
@tzapu
Aug 31 2015 21:30 UTC
nice, nice
you were so right, that really is a looooot easier
so cool
thank you very much
Ivan Grokhotkov
@igrr
Aug 31 2015 21:31 UTC
you're welcome!
Ivan Grokhotkov
@igrr
Aug 31 2015 21:37 UTC
std::bind is actually an extremely powerful tool
imagine you want to pass some arguments to handleRequest method... you could do it like this:
void handleRequest(int x) { ... }

server.on(uri, std::bind(&Counter::handleRequest, this, 42));
Ivan Grokhotkov
@igrr
Aug 31 2015 21:43 UTC
you can even bind some arguments and leave others to be defined later:
void fn(String s, int a) {
  Serial.print(s);
  Serial.println(a);
}

std::function<void(String)> f = std::bind(fn, std::placeholders::_1, 42);  
f("value: ");
tzapu
@tzapu
Aug 31 2015 22:10 UTC
yes, i believe i mentioned this before...voodoo
tzapu
@tzapu
Aug 31 2015 22:18 UTC
@igrr one more follow up q if you can spare a sec. if i were to have the loop of the captive portal, the one containing
//DNS
dnsServer.processNextRequest();
//HTTP
server.handleClient();
contained to my library, so it s all handled from the main app in a single function call and only returns when everything is done, what else would i need to call? delay? yield? to keep all stuff working..
Ivan Grokhotkov
@igrr
Aug 31 2015 22:24 UTC
adding yield(); to your loop should work
tzapu
@tzapu
Aug 31 2015 22:26 UTC
cheers