We have launched a new Community! Please post any new forum topics there. This forum will remain available as an archive, but we hope you enjoy the new experience and feature set the latest NCD Community will offer!

loop() code on NCD4Relay?

Hi, 

I am wondering about the code that is in the loop() function of this library: https://github.com/ControlEverythingCom/NCD4Relay in exactly this file: https://github.com/ControlEverythingCom/NCD4Relay/blob/master/firmware/examples/NCD4RelaySample.cpp

 

what does it all do?

thanks!

int status = relayController.readAllInputs();
 int a = 0;
 for(int i = 1; i < 9; i*=2){
 if(status & i){
 debugTrips[a]++;
 if(debugTrips[a] >= minTrips){
 if(!tripped[a]){
 tripped[a] = true;
 //set input trip event to true
 String eventName = "Input_";
 eventName+=(a+1);
 Particle.publish(eventName, "ON");
 Serial.print("eventName: ");
 Serial.println(eventName);
 Serial.print("eventContents: ");
 Serial.println("ON");
 }
 }
 }else{
 debugTrips[a] = 0;
 if(tripped[a]){
 tripped[a] = false;
 //set input trip event to false
 String eventName = "Input_";
 eventName+=(a+1);
 Particle.publish(eventName, "OFF");
 Serial.print("eventName: ");
 Serial.println(eventName);
 Serial.print("eventContents: ");
 Serial.println("OFF");
 }
 }
 a++;
 

}

 

 

 

T

Hi Gustavo, 

I see you found our new site.  Good to hear from you again.

Basically all the code in that loop is for debouncing the inputs on the board.  It makes sure that the input has changed state and has stayed in that state for x number of loop() cycles.  If you just read the inputs in that loop and publish events to particle the small amount of bounce on the input will cause the board to publish to many events to particle and it will then be blocked by the Particle server for a certain period.  There are several alternative ways this could be accomplished, this is just the way I did it.

Let me know if that makes sense and if you have any other questions.

Thank you,

Travis Elliott

gusgonnet's picture

Hey! nice talking to you again.

Yes, the code makes sense. I haven't used the inputs on the board yet and that's why I never looked at the code deeply enough to understand what it is doing.

Thank you for the clarification!

Gustavo.

gusgonnet's picture

hey, BTW the new site is pretty nice!

what is this software running your forums? is not Discourse, is it? https://www.discourse.org/

 

T

Hey Gustavo,

Thank you for the complement on the site.  Our web development team did a fantastic job.  Please keep us updated if you run into any questions on the site navigation or any pitfalls you run into.  It is still new and we are constantly trying to improve it.  Outside insight is a big help with that so let us know what you think as you use it more.

(Discourse) No, we thought about discourse but it required a Ruby server which we really didn't want to get into.  It's our own home brewed discourse knock off pretty much.  Our web developers built it.  I really don't know the specificas though.  @Trey might be able to comment more on that.

Thanks Gustavo and let me know if you need anything at all.

Travis Elliott

gusgonnet's picture

Sad to hear the requirement on Discourse left it out of the table. I think a docker container could help you guys, since Discourse is so freaking awesome and replicating all its features must mean time and money on devs: https://github.com/discourse/discourse_docker

Discourse is all over the place now and not having it may (or may not) complicate a bit the life of your customers ;)

I'll report back if I see something not correct on the site. Cheers

Gustavo.

 

Trey's picture

Hi Gustavo,

Thanks for the feedback first off! We all love Discourse here, it's a great piece of software and has all the features we'd like to have. As Travis said, the primary reason for not using it was the framework, docker makes deployment a breeze, but we don't have anyone here with any real experience with Ruby, and custom development is something we've always found important (our store is actually Wordpress, but with a great deal of customization).

One things our web department is very familiar with is Drupal, which is what this forum uses as a backend, it is also what all of our last generations of sites were built on, which made migrating the threads much simpler, and allowed us to focus on the store. We hope to have more time for fleshing out some of those great discourse-style features in the future, but with only 2 web devs, who also work on product libraries, and help with some support,  our time is pretty short most days as you can imagine. Another forum option we really liked was Flarum (http://flarum.org/), but it's still in beta, and we weren't quite prepared to pull the trigger on that kind of commitment.

gusgonnet's picture

thanks Trey for the details, keep it up!

Gustavo.

Trey's picture

Hi Gustavo!

Since you mentioned it I thought I'd let you know, now that we have ncd.io a bit more complete, we were able to revisit the Forum software discussion. There is a new community available, running on Discourse, at https://community.ncd.io. This forum will remain open, but we're only going to accept new topics on Discourse.