Pinscape Controller version 1 fork. This is a fork to allow for ongoing bug fixes to the original controller version, from before the major changes for the expansion board project.

Dependencies:   FastIO FastPWM SimpleDMA mbed

Fork of Pinscape_Controller by Mike R

Committer:
mjr
Date:
Sat Dec 19 06:37:19 2015 +0000
Revision:
35:e959ffba78fd
Parent:
23:14f8c5004cd0
Child:
43:7a6364d82a41
Keyboard/Media Control interface working, but the extra interface confuses the DOF connector.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mjr 17:ab3cec0c8bf4 1 // Potentiometer plunger sensor
mjr 17:ab3cec0c8bf4 2 //
mjr 17:ab3cec0c8bf4 3 // This file implements our generic plunger sensor interface for a
mjr 17:ab3cec0c8bf4 4 // potentiometer.
mjr 17:ab3cec0c8bf4 5
mjr 17:ab3cec0c8bf4 6 #include "FastAnalogIn.h"
mjr 17:ab3cec0c8bf4 7
mjr 35:e959ffba78fd 8 class PlungerSensorPot: public PlungerSensor
mjr 17:ab3cec0c8bf4 9 {
mjr 17:ab3cec0c8bf4 10 public:
mjr 35:e959ffba78fd 11 PlungerSensorPot(PinName ao) : pot(ao)
mjr 17:ab3cec0c8bf4 12 {
mjr 17:ab3cec0c8bf4 13 }
mjr 17:ab3cec0c8bf4 14
mjr 35:e959ffba78fd 15 virtual void init()
mjr 17:ab3cec0c8bf4 16 {
mjr 35:e959ffba78fd 17 // The potentiometer doesn't have pixels, but we still need an
mjr 35:e959ffba78fd 18 // integer range for normalizing our digitized voltage level values.
mjr 35:e959ffba78fd 19 // The number here is fairly arbitrary; the higher it is, the finer
mjr 35:e959ffba78fd 20 // the digitized steps. A 40" 1080p HDTV has about 55 pixels per inch
mjr 35:e959ffba78fd 21 // on its physical display, so if the on-screen plunger is displayed
mjr 35:e959ffba78fd 22 // at roughly the true physical size, it's about 3" on screen or about
mjr 35:e959ffba78fd 23 // 165 pixels. So the minimum quantization size here should be about
mjr 35:e959ffba78fd 24 // the same. For the pot sensor, this is just a scaling factor,
mjr 35:e959ffba78fd 25 // so higher values don't cost us anything (unlike the CCD, where the
mjr 35:e959ffba78fd 26 // read time is proportional to the number of pixels we sample).
mjr 35:e959ffba78fd 27 npix = 4096;
mjr 17:ab3cec0c8bf4 28 }
mjr 17:ab3cec0c8bf4 29
mjr 35:e959ffba78fd 30 virtual bool highResScan(int &pos)
mjr 17:ab3cec0c8bf4 31 {
mjr 23:14f8c5004cd0 32 // Take a few readings and use the average, to reduce the effect
mjr 23:14f8c5004cd0 33 // of analog voltage fluctuations. The voltage range on the ADC
mjr 23:14f8c5004cd0 34 // is 0-3.3V, and empirically it looks like we can expect random
mjr 23:14f8c5004cd0 35 // voltage fluctuations of up to 50 mV, which is about 1.5% of
mjr 23:14f8c5004cd0 36 // the overall range. We try to quantize at about the mm level
mjr 23:14f8c5004cd0 37 // (in terms of the plunger motion range), which is about 1%.
mjr 23:14f8c5004cd0 38 // So 1.5% noise is big enough to be visible in the joystick
mjr 23:14f8c5004cd0 39 // reports. Averaging several readings should help smooth out
mjr 23:14f8c5004cd0 40 // random noise in the readings.
mjr 23:14f8c5004cd0 41 pos = int((pot.read() + pot.read() + pot.read())/3.0 * npix);
mjr 17:ab3cec0c8bf4 42 return true;
mjr 17:ab3cec0c8bf4 43 }
mjr 17:ab3cec0c8bf4 44
mjr 35:e959ffba78fd 45 virtual bool lowResScan(int &pos)
mjr 23:14f8c5004cd0 46 {
mjr 23:14f8c5004cd0 47 // Use an average of several readings. Note that even though this
mjr 23:14f8c5004cd0 48 // is nominally a "low res" scan, we can still afford to take an
mjr 23:14f8c5004cd0 49 // average. The point of the low res interface is speed, and since
mjr 23:14f8c5004cd0 50 // we only have one analog value to read, we can afford to take
mjr 23:14f8c5004cd0 51 // several samples here even in the low res case.
mjr 35:e959ffba78fd 52 pos = int((pot.read() + pot.read() + pot.read())/3.0 * npix);
mjr 35:e959ffba78fd 53 return true;
mjr 23:14f8c5004cd0 54 }
mjr 23:14f8c5004cd0 55
mjr 17:ab3cec0c8bf4 56 private:
mjr 23:14f8c5004cd0 57 AnalogIn pot;
mjr 17:ab3cec0c8bf4 58 };