|
Swimming out of my depth againAs ever I have taken on something on that to be honest I don't fully understand. I am looking to control the absolute pan tilt postion of a Sony camera. To do this i need to send Hex values in the range FC90 to 0370 with 0000 as the center. After a bit of research I have discovered this is for the range -800 to +880 which is the number of steps in the range. So far I have got a javascript patch which can convert 0 to +880 but cannot do the negative part of the conversion to reach fc90. I have worked out that the FC90 comes from subtracting this from FFFF to give a result of -879. I have had a look around at javascript examples but don't really understand them fully, so if anyone could help in the conversion of -880 to +880 to hex that would be amazing. The Javascript I have so far is var result = new Object(); function (__string stuff) main (__index number) { result.stuff = number.toString(16); if(result.stuff.length < 4 ) result.stuff = "0"+result.stuff; result.stuff = result.stuff.toUpperCase() return result; } As ever thanks for you help. Steve
|
This will give you 0xfffffc90 for -880, but I'm going to assume it's trivial to clean that up (just lop off the top).
Note that you're using unsigned values. That means you have 2 ranges, not one. The non-negative range is 0x0000 - 0x0370, while -1 to -880 is 0xffff to 0xfc90. "two's compliment" is weird like that.
Thanks so much for this Chris, as far as I can tell this will work great, I will report back when I have this working with the PTZ camera. Thanks again to this forum and especially Chris for all your help and patience. Cheers Steve