Mike R / Mbed 2 deprecated Pinscape_Controller

Dependencies:   USBDevice mbed FastAnalogIn FastIO FastPWM SimpleDMA

Committer:
mjr
Date:
Sat Dec 19 06:37:19 2015 +0000
Revision:
35:e959ffba78fd
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 35:e959ffba78fd 1 // Plunger Sensor Interface
mjr 35:e959ffba78fd 2 //
mjr 35:e959ffba78fd 3 // This module defines the abstract interface to the plunger sensors.
mjr 35:e959ffba78fd 4 // We support several different physical sensor types, so we need a
mjr 35:e959ffba78fd 5 // common interface for use in the main code.
mjr 35:e959ffba78fd 6 //
mjr 35:e959ffba78fd 7
mjr 35:e959ffba78fd 8 #ifndef PLUNGER_H
mjr 35:e959ffba78fd 9 #define PLUNGER_H
mjr 35:e959ffba78fd 10
mjr 35:e959ffba78fd 11 class PlungerSensor
mjr 35:e959ffba78fd 12 {
mjr 35:e959ffba78fd 13 public:
mjr 35:e959ffba78fd 14
mjr 35:e959ffba78fd 15 PlungerSensor() { }
mjr 35:e959ffba78fd 16 virtual ~PlungerSensor() { }
mjr 35:e959ffba78fd 17
mjr 35:e959ffba78fd 18 // Number of "pixels" in the sensor's range. We use the term "pixels"
mjr 35:e959ffba78fd 19 // here for historical reasons, namely that the first sensor we implemented
mjr 35:e959ffba78fd 20 // was an imaging sensor that physically sensed the plunger position as
mjr 35:e959ffba78fd 21 // a pixel coordinate in the image. But it's no longer the right word,
mjr 35:e959ffba78fd 22 // since we support sensor types that have nothing to do with imaging.
mjr 35:e959ffba78fd 23 // Even so, the function this serves is still applicable. Abstractly,
mjr 35:e959ffba78fd 24 // it represents the physical resolution of the sensor, by giving the
mjr 35:e959ffba78fd 25 // total number of quanta that the sensor can resolve over the entire
mjr 35:e959ffba78fd 26 // range of travel of the plunger. For devices that inherently quantize
mjr 35:e959ffba78fd 27 // the position reading at the physical level, such as imaging sensors
mjr 35:e959ffba78fd 28 // and quadrature sensors, this should be set to the total number of
mjr 35:e959ffba78fd 29 // quanta (resolvable position steps) over the range of travel. For
mjr 35:e959ffba78fd 30 // devices with physically analog outputs, such as potentiometers or
mjr 35:e959ffba78fd 31 // LVDTs, the reading still has to be digitized for us to be able to
mjr 35:e959ffba78fd 32 // work with it, but this happens invisibly in the ADC, so the "pixel"
mjr 35:e959ffba78fd 33 // scale is essentially arbitrary. Analog sensor types should thus
mjr 35:e959ffba78fd 34 // simply use the maximum joystick report range, since that's the
mjr 35:e959ffba78fd 35 // final scale we have to convert to - using a different scale would
mjr 35:e959ffba78fd 36 // have no benefit and would just introduce rounding errors.
mjr 35:e959ffba78fd 37 //
mjr 35:e959ffba78fd 38 // This value MUST be initialized in the constructor.
mjr 35:e959ffba78fd 39 int npix;
mjr 35:e959ffba78fd 40
mjr 35:e959ffba78fd 41 // Initialize the physical sensor device. This is called at startup
mjr 35:e959ffba78fd 42 // to set up the device for first use.
mjr 35:e959ffba78fd 43 virtual void init() = 0;
mjr 35:e959ffba78fd 44
mjr 35:e959ffba78fd 45 // Take a high-resolution reading. Sets pos to the current position,
mjr 35:e959ffba78fd 46 // on a scale from 0 to npix: 0 is the maximum forward plunger position,
mjr 35:e959ffba78fd 47 // and npix is the maximum retracted position, in terms of the sensor's
mjr 35:e959ffba78fd 48 // extremes. This is a raw reading in terms of the sensor range; the
mjr 35:e959ffba78fd 49 // caller is responsible for applying calibration data and scaling the
mjr 35:e959ffba78fd 50 // result to the the joystick report range.
mjr 35:e959ffba78fd 51 //
mjr 35:e959ffba78fd 52 // Returns true on success, false on failure. Return false if it wasn't
mjr 35:e959ffba78fd 53 // possible to take a good reading for any reason.
mjr 35:e959ffba78fd 54 virtual bool highResScan(int &pos) = 0;
mjr 35:e959ffba78fd 55
mjr 35:e959ffba78fd 56 // Take a low-resolution reading. This reports the result on the same
mjr 35:e959ffba78fd 57 // 0..npix scale as highResScan(). Returns true on success, false on
mjr 35:e959ffba78fd 58 // failure.
mjr 35:e959ffba78fd 59 //
mjr 35:e959ffba78fd 60 // The difference between the high-res and low-res scans is the amount
mjr 35:e959ffba78fd 61 // of time it takes to complete the reading. The high-res scan is allowed
mjr 35:e959ffba78fd 62 // to take about 10ms; a low-res scan take less than 1ms. For many
mjr 35:e959ffba78fd 63 // sensors, either of these time scales would yield identical resolution;
mjr 35:e959ffba78fd 64 // if that's the case, simply take a reading the same way in both functions.
mjr 35:e959ffba78fd 65 // The distinction is for the benefit of sensors that need significantly
mjr 35:e959ffba78fd 66 // longer to read at higher resolutions, such as image sensors that have
mjr 35:e959ffba78fd 67 // to sample pixels serially.
mjr 35:e959ffba78fd 68 virtual bool lowResScan(int &pos) = 0;
mjr 35:e959ffba78fd 69
mjr 35:e959ffba78fd 70 // Send an exposure report to the joystick interface. This is specifically
mjr 35:e959ffba78fd 71 // for image sensors, and should be omitted by other sensor types. For
mjr 35:e959ffba78fd 72 // image sensors, this takes one exposure and sends all pixels to the host
mjr 35:e959ffba78fd 73 // through special joystick reports. This is used for PC-side testing tools
mjr 35:e959ffba78fd 74 // to let the user check the sensor installation by directly viewing its
mjr 35:e959ffba78fd 75 // pixel output.
mjr 35:e959ffba78fd 76 virtual void sendExposureReport(class USBJoystick &js) { }
mjr 35:e959ffba78fd 77 };
mjr 35:e959ffba78fd 78
mjr 35:e959ffba78fd 79 #endif /* PLUNGER_H */