Final tidy of code following installation of new sensor, more comments added prior to submission

Dependencies:   mbed

Committer:
legstar85
Date:
Fri Jan 21 14:26:56 2022 +0000
Revision:
13:5ad65a688f3f
Updated due to issues with using Start Temp variable later in program now resolved. Doxygen completed and folders in place correctly

Who changed what in which revision?

UserRevisionLine numberNew contents of line
legstar85 13:5ad65a688f3f 1 /* *
legstar85 13:5ad65a688f3f 2 * Prints a string of characters to the screen buffer, string is cut off after the 83rd pixel.
legstar85 13:5ad65a688f3f 3 * @param x - the column number (0 to 83)
legstar85 13:5ad65a688f3f 4 * @param y - the row number (0-5) - the display is split into 6 banks - each bank can be considered a row
legstar85 13:5ad65a688f3f 5 * @author - David Leaming - 25574043
legstar85 13:5ad65a688f3f 6 * @ Date - December 2021
legstar85 13:5ad65a688f3f 7 *
legstar85 13:5ad65a688f3f 8 * Acknowledgements
legstar85 13:5ad65a688f3f 9 * Craig A. Evans, University of Leeds, TMP102 Library ,Feb 2016
legstar85 13:5ad65a688f3f 10 * Dr Edmond Nurellari, University of Lincoln, Joystick & N5110 Libraries
legstar85 13:5ad65a688f3f 11 *
legstar85 13:5ad65a688f3f 12 */
legstar85 13:5ad65a688f3f 13
legstar85 13:5ad65a688f3f 14 // it is good practice to put a comment block on the top, with the name and details of the library
legstar85 13:5ad65a688f3f 15 // you can also include version numbers to keep track of changes/additions
legstar85 13:5ad65a688f3f 16
legstar85 13:5ad65a688f3f 17 /* TMP102
legstar85 13:5ad65a688f3f 18
legstar85 13:5ad65a688f3f 19 Simple library to get the temperature data from a TMP102 sensor over I2C.
legstar85 13:5ad65a688f3f 20
legstar85 13:5ad65a688f3f 21 v 1.0 - initial release
legstar85 13:5ad65a688f3f 22
legstar85 13:5ad65a688f3f 23 (c) Craig A. Evans, University of Leeds, Jan 2016
legstar85 13:5ad65a688f3f 24
legstar85 13:5ad65a688f3f 25 */
legstar85 13:5ad65a688f3f 26
legstar85 13:5ad65a688f3f 27 // this is called a header guard and prevents a library from being included more than once
legstar85 13:5ad65a688f3f 28 // if it is not already defined, it is defined. If it it already defined, it won't be defined again
legstar85 13:5ad65a688f3f 29 // the header guard is closed at the end of the file
legstar85 13:5ad65a688f3f 30 #ifndef TMP102_H
legstar85 13:5ad65a688f3f 31 #define TMP102_H
legstar85 13:5ad65a688f3f 32
legstar85 13:5ad65a688f3f 33 // the next thing in a library is usually any required defines
legstar85 13:5ad65a688f3f 34 // addresses for ADD0 connected to GND
legstar85 13:5ad65a688f3f 35 #define TMP102_ADD 0x48
legstar85 13:5ad65a688f3f 36 #define TMP102_R_ADD 0x91
legstar85 13:5ad65a688f3f 37 #define TMP102_W_ADD 0x90
legstar85 13:5ad65a688f3f 38
legstar85 13:5ad65a688f3f 39 // register addresses
legstar85 13:5ad65a688f3f 40 #define TEMP_REG 0x00
legstar85 13:5ad65a688f3f 41 #define CONFIG_REG 0x01
legstar85 13:5ad65a688f3f 42 #define THIGH_REG 0x02
legstar85 13:5ad65a688f3f 43 #define TLOW_REG 0x03
legstar85 13:5ad65a688f3f 44
legstar85 13:5ad65a688f3f 45 // we need to include the mbed header (this will also have a header guard to prevent it being included more than once)
legstar85 13:5ad65a688f3f 46 #include "mbed.h"
legstar85 13:5ad65a688f3f 47
legstar85 13:5ad65a688f3f 48 // a library is actually just a C++ class, we will create an instance of this class (an object) in our main code
legstar85 13:5ad65a688f3f 49 class TMP102
legstar85 13:5ad65a688f3f 50 {
legstar85 13:5ad65a688f3f 51 // we define the methods that are 'public' i.e. able to be used by the user
legstar85 13:5ad65a688f3f 52 public:
legstar85 13:5ad65a688f3f 53
legstar85 13:5ad65a688f3f 54 // this is a 'constructor' and is used to create the object
legstar85 13:5ad65a688f3f 55 TMP102(PinName sda, PinName scl);
legstar85 13:5ad65a688f3f 56
legstar85 13:5ad65a688f3f 57 // we will also create an initialisation method
legstar85 13:5ad65a688f3f 58 void init();
legstar85 13:5ad65a688f3f 59
legstar85 13:5ad65a688f3f 60 // and a method to get the temperature - note the return type
legstar85 13:5ad65a688f3f 61 float get_temperature();
legstar85 13:5ad65a688f3f 62
legstar85 13:5ad65a688f3f 63 // we also have 'private' methods that can be used in the library itself, but not called directly by the user
legstar85 13:5ad65a688f3f 64 private:
legstar85 13:5ad65a688f3f 65
legstar85 13:5ad65a688f3f 66 // called in event of error - flashes LED and hangs
legstar85 13:5ad65a688f3f 67 void error();
legstar85 13:5ad65a688f3f 68 // reads temperature from the sensor
legstar85 13:5ad65a688f3f 69 void read_temperature();
legstar85 13:5ad65a688f3f 70
legstar85 13:5ad65a688f3f 71
legstar85 13:5ad65a688f3f 72 // we also do the same for any variables
legstar85 13:5ad65a688f3f 73 public:
legstar85 13:5ad65a688f3f 74 // don't generally allow direct access to variables, instead use 'accessor' and 'mutator' methods
legstar85 13:5ad65a688f3f 75
legstar85 13:5ad65a688f3f 76 private:
legstar85 13:5ad65a688f3f 77
legstar85 13:5ad65a688f3f 78 // class data member names often have a trailing underscore to make them easily identifiable
legstar85 13:5ad65a688f3f 79 I2C* i2c_;
legstar85 13:5ad65a688f3f 80 DigitalOut* led_;
legstar85 13:5ad65a688f3f 81 float temperature_;
legstar85 13:5ad65a688f3f 82
legstar85 13:5ad65a688f3f 83 };
legstar85 13:5ad65a688f3f 84
legstar85 13:5ad65a688f3f 85 // end of the header guard
legstar85 13:5ad65a688f3f 86 #endif