Rotary Encoder speed with nasal script
Nicola Quargentan <[email protected]> Thu, 11 Jul 2013 00:30:48 +0200
| Newsgroups | gmane.games.flightgear.general |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I connected an encoder with two outputs (A and B) at a Joystick Board
(bodnar BU0836X). I used button 1 for wire A and button 2 for wire B.
Using xml and nasal script I get the right rotation (I want to move obs
knob). Everything works fine only if I move the knob slowly. If I move
the knob quickly, the result is uncertain.
It's pretty clear that I cannot intercept all the steps of the encoder.
Does anyone have any idea on how to fix it?
Thanks.
Here my files:
<button>
<name>Encoder1A</name>
<number>
<unix>0</unix>
<mac>0</mac>
<windows>0</windows>
</number>
<desc>Encoder1 fase A</desc>
<repeatable>false</repeatable>
<binding>
<command>nasal</command>
<script>
bodnar.encoder1("A", 1)
</script>
</binding>
<mod-up>
<binding>
<command>nasal</command>
<script>
bodnar.encoder1("A", 0)
</script>
</binding>
</mod-up>
</button>
<button>
<name>Encoder1B</name>
<number>
<unix>1</unix>
<mac>1</mac>
<windows>1</windows>
</number>
<desc>Encoder1 fase B</desc>
<repeatable>false</repeatable>
<binding>
<command>nasal</command>
<script>
bodnar.encoder1("B", 1)
</script>
</binding>
<mod-up>
<binding>
<command>nasal</command>
<script>
bodnar.encoder1("B", 0)
</script>
</binding>
</mod-up>
</button>
Then this nasal script:
###############################################
var statusA = nil;
var statusB = nil;
var oldStatusA = nil;
var oldStatusB = nil;
var initBodnar = func() {
print ("Loading bodnar.nas");
}
var encoder1 = func(button, status) {
print (button , status);
if(button == "A") {
statusA = status;
}
else if ( button == "B" ) {
statusB = status;
}
if(statusA == statusB) {
if(oldStatusA != statusA) {
direction("cw");
}
else {
direction("ccw")
}
}
else {
if(oldStatusA != statusA) {
direction("ccw");
}
else {
direction("cw")
}
}
oldStatusA = statusA;
oldStatusB = statusB;
}
var direction = func(dir) {
print (dir);
}
#############################################
--
Nicola Quargentan
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk