lib for realtimeMM funcs
Fork of realtimeMMLib by
Revision 1:13301255d95a, committed 2018-02-15
- Comitter:
- GTNicholson
- Date:
- Thu Feb 15 16:35:50 2018 +0000
- Parent:
- 0:9f82ee1feae7
- Commit message:
- v4 lib
Changed in this revision
diff -r 9f82ee1feae7 -r 13301255d95a MBedStation.cpp --- a/MBedStation.cpp Mon Oct 02 11:18:47 2017 +0000 +++ b/MBedStation.cpp Thu Feb 15 16:35:50 2018 +0000 @@ -39,5 +39,20 @@ sensor3.enabled = true; MBedStation::sensors[3] = sensor3; sensor_3 = sensor3; - */ + + + sensor_max6675 sensor4(p11,p12,p13,p18); + sensor4.sensor_id = 5; + sensor4.enabled = true; + MBedStation::sensors[4] = sensor4; + sensor_4 = sensor4; + + + sensor_max6675 sensor5(p11,p12,p13,p17); + sensor5.sensor_id = 6; + sensor5.enabled = true; + MBedStation::sensors[5] = sensor5; + sensor_5 = sensor5; + */ + }
diff -r 9f82ee1feae7 -r 13301255d95a MBedStation.h --- a/MBedStation.h Mon Oct 02 11:18:47 2017 +0000 +++ b/MBedStation.h Thu Feb 15 16:35:50 2018 +0000 @@ -17,5 +17,7 @@ sensor_onoff sensor_0; sensor_vin sensor_1; sensor_vin sensor_2; - sensor_pulse sensor_3; + //sensor_pulse sensor_3; + //sensor_max6675 sensor_4; + //sensor_max6675 sensor_5; }; \ No newline at end of file
diff -r 9f82ee1feae7 -r 13301255d95a callbacknotes.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/callbacknotes.cpp Thu Feb 15 16:35:50 2018 +0000 @@ -0,0 +1,30 @@ +/* + +Because a member function is meaningless without an object to invoke it on, you can’t do this directly (if The X Window System was rewritten in C++, it would probably pass references to objects around, not just pointers to functions; naturally the objects would embody the required function and probably a whole lot more). + +As a patch for existing software, use a top-level (non-member) function as a wrapper which takes an object obtained through some other technique. Depending on the routine you’re calling, this “other technique” might be trivial or might require a little work on your part. The system call that starts a thread, for example, might require you to pass a function pointer along with a void*, so you can pass the object pointer in the void*. Many real-time operating systems do something similar for the function that starts a new task. Worst case you could store the object pointer in a global variable; this might be required for Unix signal handlers (but globals are, in general, undesired). In any case, the top-level function would call the desired member function on the object. + +Here’s an example of the worst case (using a global). Suppose you want to call Fred::memberFn() on interrupt: + +class Fred { +public: + void memberFn(); + static void staticMemberFn(); // A static member function can usually handle it + // ... +}; +// Wrapper function uses a global to remember the object: +Fred* object_which_will_handle_signal; +void Fred_memberFn_wrapper() +{ + object_which_will_handle_signal->memberFn(); +} +int main() +{ + signal(SIGINT, Fred::memberFn); // Can NOT do this + signal(SIGINT, Fred_memberFn_wrapper); // Okay + signal(SIGINT, Fred::staticMemberFn); // Okay usually; see below + } +Note: static member functions do not require an actual object to be invoked, so pointers-to-static-member-functions are usually type-compatible with regular pointers-to-functions. However, although it probably works on most compilers, it actually would have to be an extern "C" non-member function to be correct, since “C linkage” doesn’t only cover things like name mangling, but also calling conventions, which might be different between C and C++. + +Test +*/ \ No newline at end of file
diff -r 9f82ee1feae7 -r 13301255d95a sensor_base.cpp --- 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 {
diff -r 9f82ee1feae7 -r 13301255d95a sensor_base.h --- a/sensor_base.h Mon Oct 02 11:18:47 2017 +0000 +++ b/sensor_base.h Thu Feb 15 16:35:50 2018 +0000 @@ -107,6 +107,36 @@ char data_sample[50]; }; +class sensor_max6675 //: public sensor_base +{ + SPI spi; + DigitalOut ncs; + +public: + + int sensor_id; + int sensor_type; + bool enabled; + + //sensor_max6675(); + //sensor_max6675(PinName _cs, PinName _so, PinName _sck, PinName _ncs); + sensor_max6675(SPI _spi, PinName _ncs); + ~sensor_max6675(); + void select(); + void deselect(); + float read_temp(); + + virtual char * read_data(); + char data_sample[50]; + + private: + //PinName _CS_pin; + //PinName _SO_pin; + //PinName _SCK_pin; + int _units; + float _error; + +}; /* class Counter {