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:
Mon Feb 15 23:03:55 2016 +0000
Revision:
68:edfecf67a931
Parent:
23:14f8c5004cd0
Child:
35:e959ffba78fd
Finalize USB library updates to fix compatibility problems introduced in USBHAL_KL25Z overhaul.

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