View Single Post
Old 11-20-2013, 09:48 AM   #16 (permalink)
P-hack
Master EcoModder
 
P-hack's Avatar
 
Join Date: Oct 2012
Location: USA
Posts: 1,408

awesomer - '04 Toyota prius
Thanks: 102
Thanked 252 Times in 204 Posts
Just a note since other people are doing the same sort of thing as the position switch, to minimize the possibility of fudgy readings, using the midpoint between readings is useful:
readings sorted by value and midpoints:
Code:
n 643
  635
2 627
  605
p 584
  550
r 515
  441
3 368
  346
d 323
  207
4 91
so a function like this should be fairly reliable and allow for a bit of switch/connection degradation:

Code:
//map the position switch resistor reading to an actual position
int position(val){
  if(val > 700)
    return ERROR;
  if(val > 635)
    return NEUTRAL;
  if(val > 605)
    return SECOND;
  if(val > 550)
    return PARK;
  if(val > 441)
    return REVERSE;
  if(val > 346)
    return THIRD;
  if(val > 207)
    return DRIVE;
  return FOURTH;
}
  Reply With Quote