lib for realteimMM funcs

Revision:
3:13301255d95a
Parent:
0:9f82ee1feae7
--- a/sensor_base.cpp	Mon Oct 02 11:18:47 2017 +0000
+++ b/sensor_base.cpp	Thu Feb 15 16:35:50 2018 +0000
@@ -223,6 +223,63 @@
 {
 }
 
+///////////////////////////////////////// Start of sensor_max6675 ///////////////
+
+//sensor_max6675::sensor_max6675()  : spi(p11,p12,p13), ncs(p18) {
+//}
+
+sensor_max6675::sensor_max6675(SPI _spi, PinName _ncs) : spi(_spi), ncs(_ncs) {
+//sensor_max6675::sensor_max6675(PinName _cs, PinName _so, PinName _sck, PinName _ncs) : spi(_cs, _so, _sck), ncs(_ncs) {
+
+}
+
+sensor_max6675::~sensor_max6675()
+{
+}
+
+char * sensor_max6675::read_data()
+{
+    //char  mretval[50];
+    sprintf(data_sample, "[%d;%f]", sensor_id, read_temp());
+    return data_sample;
+    //mretval[0] = 68;
+}
+
+float sensor_max6675::read_temp() {
+    short value = 0;
+    float temp = 0;
+    
+    uint8_t highByte=0;
+    uint8_t lowByte=0;
+    
+    select();
+    wait(.25); //This delay is needed else it does'nt seem to update the temp
+
+    highByte = spi.write(0);
+    lowByte = spi.write(0);
+    deselect();
+
+
+    if (lowByte & (1<<2)) {
+        error("No Probe");
+    } else {
+        value = (highByte << 5 | lowByte>>3);
+    }
+
+    temp = (value*0.25); // Multiply the value by 0.25 to get temp in ˚C or
+                         //  * (9.0/5.0)) + 32.0;   // Convert value to ˚F (ensure proper floats!)
+
+return temp;
+}
+
+void sensor_max6675::select() {
+    ncs = 0;
+}
+
+void sensor_max6675::deselect() {
+    ncs = 1;
+}
+
 
 /*
 class Counter {