a fork of priustroller

Dependencies:   mbed

Fork of priustroller_current by N K

Revision:
29:cb03760ba9ea
Parent:
28:af9d43bcb371
Child:
30:2b6d426f3bfc
--- a/sensors/sensors.h	Sat Mar 14 19:18:34 2015 +0000
+++ b/sensors/sensors.h	Sat Mar 14 23:42:46 2015 +0000
@@ -8,16 +8,10 @@
     NativeAnalogIn(PinName pin);
     float Read();
     operator float() {return Read();}
-private:
-    unsigned char PinToAdcChannel(PinName pin);
+    static unsigned char PinToAdcChannel(PinName pin);
 private:
     unsigned char _channel;
-};
-
-class CurrentSensor {
-public:
-    virtual float GetCurrent() {return 0.0f;}
-    virtual void Zero() {}
+    float _dummy;
 };
 
 class VoltageSensor {
@@ -36,16 +30,6 @@
     virtual float GetTemp() {return 0.0f;}
 };
 
-class AnalogCurrentSensor: public CurrentSensor {
-public:
-    AnalogCurrentSensor(PinName pin, float volts_per_amp);
-    virtual void Zero();
-    virtual float GetCurrent();
-private:
-    float _zero_level, _volts_per_amp;
-    NativeAnalogIn *_in;
-};
-
 class AnalogVoltageSensor: public VoltageSensor {
 public:
     AnalogVoltageSensor(PinName pin, float scale);
@@ -86,4 +70,15 @@
     VoltageSensor *_in;
 };
 
+inline float NativeAnalogIn::Read() {
+    TIM2->DIER = 0x0000;
+    ADC1->SQR3 = 0x0000;
+    ADC1->SQR3 |= _channel;
+    ADC1->CR2 |= ADC_CR2_SWSTART;
+    while ((ADC1->SR & 2) == 0){}
+    float x = ADC1->DR;
+    TIM2->DIER = 0x0001;
+    return x / 4095.0f;
+}
+
 #endif
\ No newline at end of file