Problems: when setting digitalpin, it sets inverted value


Hi to all,
I'm using Rhyduino with Arduino One, but it happend this:
Sequence actions:
1 - call DigitalPins[_pin].SetPinValue(DigitalPinValue.High); > Not happend nothing
2 - call DigitalPins[_pin].SetPinValue(DigitalPinValue.Low); > It's turn on a led to pin setted
3 - call DigitalPins[_pin].SetPinValue(DigitalPinValue.High); > It's turn off a led to pin setted
I downloaded Firmata-2.2 and I uploaded StandardFirmata on using Arduino0022 console.
Can you help me?


syntaxerror1002 wrote Jul 19, 2012 at 5:41 PM

after digging thru the code w/ some breakpoints, it looked as though the bitmask being generated was completely zero when it should have had at least a 1 in it on the first SetPinValue(high).
I saw that the code to generate the bitmask hits a function called GetPinValue() and asks if the current pin is set high, then includes its respective pin index in the bitmask.
However, the GetPinValue method asks the current pin class what it's value is, which hasn't been set yet by SetPinValue.
My fix (which still needs to be looked at more) is in SetPinValue of DigitalPin.cs,

_value = digitalPinValue;
somewhere before:
_arduino.Post(FirmataEncoder.BuildDigitalWriteRequest(PinToPort(PinNumber), _arduino.GetPortValue(PinNumber)));

Otherwise the value is always a command behind.

The library is great so far, I feel like this was just a simple optimization/refactoring bug that was overlooked at some point.
Please let me know if you have any input on this topic.

wrote Feb 14, 2013 at 5:58 PM