Examples - ejbergdk/loconet-routectrl3 GitHub Wiki
Here you'll find various examples, demonstrating how to use this project.
All examples are available on the Examples branch
Debouncing feedback from contact tracks
Example available in: example_contact_bounce.c
Due to dust and dirt on the tracks and/or wheels, feedback from contact tracks may not be as clean as one would like. The result can be feedback signals that are reporting occupied-free-occupied-free a number of times in rapid succession. Now, some feedback modules have filters built in to fix this problem. The ones I use (Uhlenbrock 63330) certainly has. If you also have feedback modules that takes care of contact bounce, then you don't need to read this example.
If your feedback modules does not filter out contact bounce, you may end up with several feedback reports from one train. This could result in setting a signal to red several times right after each other. To overcome this problem, this example will demonstrate a "trick", where routes are used as a filter for contact bounce.
Routes can be requested more than once, but it will only call its activate callback once, and that is what we'll take advantage of here.
As soon as a feedback reports occupied, we will request a route activation. The route will activate immediately, as it has no constraints. The route activate callback can be used to do whatever you want to do when the feedback is occupied.
The feedback free report however, will be delayed by 2 seconds. If another occupy is received within the 2 seconds (contact bounce), the delay is cancelled and the route remains in its active state. Only after 2 seconds without further feedback reports, will the route be freed.
The example example_contact_bounce.c demonstrates this technique on feedback address 1 to 8, which will trigger route 101 to 108 respectively.