A library for the AMS AS5045 magnetic encoder using the SPI interface

Revision:
2:02ea2289edb2
Parent:
1:2b21453e2c03
--- a/AS5045Controller.cpp	Fri Sep 16 04:56:51 2016 +0200
+++ b/AS5045Controller.cpp	Fri Sep 16 03:43:22 2016 +0000
@@ -1,34 +1,29 @@
 #include "AS5045Controller.hpp"
 
-AS5045Controller::AS5045Controller(PinName CS, int f, PinName D0, PinName CLK) :
-  _spi(NC,DO,CLK),
-  _cs(CS);
+AS5045Controller::AS5045Controller(PinName CS) :
+  _spi(NC,D12, D13),
+  _cs(CS)
 {
   _spi.format(9,2);
-  _spi.frequency(f);
+  _spi.frequency(500000);
   _cs = 1;
-  _valid = false;
 }
 
-int AS5045Controller::Read()
+int AS5045Controller::GetInt()
 {
   _cs = 0;
   int upper = _spi.write(0x00);
   int lower = _spi.write(0x00);
   _cs = 1;
 
-  _magDEC = (lower >> 1) & 1;
-  _magINC = (lower >> 2) & 1;
-  _lin = (lower >> 3) & 1;
-  _cof = (lower >> 4) & 1;
-  _ocf = (lower >> 5) & 1;
-  _valid = (_ocf & !_cof & !_lin & (_magINC | _magDEC) );
-  _value = ((upper << 3)+(lower >> 6));
 
-  return _value;
+  return ((upper << 3)+(lower >> 6));
 }
 
-bool AS5045Controller::IsValid()
+float AS5045Controller::GetFloat()
 {
-  return _valid;
+  float value = (float)GetInt();
+
+  return value*0.08789;
+
 }