Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MCP23017 SDFileSystem WattBob_TextLCD mbed
Tasks.h
00001 /* ##################################################################### 00002 Tasks.h 00003 ------- 00004 00005 Embedded Software - Assignment 2 00006 -------------------------------- 00007 00008 Written by: Steven Kay 00009 00010 Date: February 2016 00011 00012 Function: This file contains the function prototypes for the 00013 included classes and methods. It also details some 00014 constants used within the program and includes AUX 00015 files, for instance the LCD system and the SD card. 00016 00017 ##################################################################### */ 00018 00019 #ifndef _TASKS_H_ 00020 #define _TASKS_H_ 00021 00022 // Includes to operate the LCD Display 00023 #include "MCP23017.h" 00024 #include "WattBob_TextLCD.h" 00025 00026 // Includes to operate the SD Card system 00027 #include "SDFileSystem.h" 00028 00029 // Global definitions 00030 #define HIGH 1 00031 #define LOW 0 00032 #define TRUE 1 00033 #define FALSE 0 00034 00035 // Task 1 definitions 00036 #define SAMPLE_FREQ 1 00037 00038 // Task 2 definitions 00039 00040 // Task 3 definitions 00041 #define WATCHDOG_PULSE_WIDTH 15 // ms 00042 00043 // Task 4 definitions 00044 #define NUM_ANALOG_SAMPLES 4.0 00045 #define V_SUPPLY 3.3 00046 00047 // Task 5 definitions 00048 #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT) 00049 #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT) 00050 00051 // Task 6 definitions 00052 #define ERROR_CODE_CDTN_MET 3 00053 #define ERROR_CODE_CDTN_FAIL 0 00054 00055 00056 /* ####################### Class definitions and prototypes ####################### */ 00057 00058 /* ==================================== Task 1 ==================================== */ 00059 // Measure freuqnecy 00060 class Task1 00061 { 00062 public: 00063 // Public constructer method 00064 Task1(PinName squareWaveInPin); 00065 00066 // Public method which initiates and returns a frequency measurement 00067 int ReadFrequency(); 00068 00069 private: 00070 // Private Timer object used to count the high or low time of input signal 00071 Timer _Task1Timer; 00072 00073 // Private method which contains the logic to measure frequency 00074 void MeasureFrequency(); 00075 00076 // Private and volatile field contains most recent frequency 00077 // Volatile to avoid the compiler modifying it for any reason 00078 volatile int measuredFrequency; 00079 00080 protected: 00081 // Pointer to DigitalIn object 00082 DigitalIn *_squareWaveIn; 00083 }; 00084 00085 00086 /* ==================================== Task 2 ==================================== */ 00087 // Digital Input 00088 class Task2 00089 { 00090 public: 00091 // Public constructer method 00092 Task2(PinName digitalInCheckPin); 00093 00094 // Public method to return the state of the DigitalIn pin 00095 bool digitalInState(); 00096 00097 private: 00098 00099 00100 protected: 00101 // Pointer to DigitalIn Object 00102 DigitalIn *_digitalInCheck; 00103 }; 00104 00105 00106 /* ==================================== Task 3 ==================================== */ 00107 // Output watchdog pulse 00108 class Task3 00109 { 00110 public: 00111 // Public constructer method 00112 Task3(PinName WatchdogPin); 00113 00114 // Public method to output watchdog pulse opon calling method 00115 void OutputWatchdogPulse(); 00116 00117 private: 00118 00119 00120 protected: 00121 // Pointer to DigitalOut Object 00122 DigitalOut *_Watchdog; 00123 }; 00124 00125 00126 /* ==================================== Task 4 ==================================== */ 00127 // Read 2 analog inputs 00128 class Task4 00129 { 00130 public: 00131 // Public constructer method 00132 Task4(PinName Analog1Pin,PinName Analog2Pin); 00133 00134 // Public method to return pointer to array containing 00135 // the filtered analog results, increment pointer once for both results 00136 float *returnAnalogReadings(); 00137 00138 private: 00139 00140 00141 protected: 00142 // Pointers to AnalogIn channels 00143 AnalogIn *_AnalogIn1; 00144 AnalogIn *_AnalogIn2; 00145 }; 00146 00147 //* ==================================== Task 5 ==================================== */ 00148 // Display outputs to LCD 00149 class Task5 00150 { 00151 public: 00152 // Public constructer method 00153 Task5(PinName sda, PinName scl, int address); 00154 00155 // Public method to update display using input values from other tasks 00156 void updateDisplay( int task1Param, 00157 int task2Param, 00158 int errorState, 00159 float task4Channel1, 00160 float task4Channel2 ); 00161 00162 private: 00163 00164 00165 protected: 00166 // Pointers to required LCD objects 00167 MCP23017 *_par_port; 00168 WattBob_TextLCD *_lcd; 00169 }; 00170 00171 ///* ==================================== Task 6 ==================================== */ 00172 // Logical checks 00173 class Task6 00174 { 00175 public: 00176 // Public method to calculate condition of error state 00177 int updateErrorCode(int switch_1, float analog1, float analog2); 00178 00179 private: 00180 00181 00182 protected: 00183 00184 00185 }; 00186 00187 /* ==================================== Task 7 ==================================== */ 00188 // Save data to SD Card 00189 class Task7 00190 { 00191 public: 00192 // Public constructer method 00193 Task7( PinName mosi, 00194 PinName miso, 00195 PinName sck, 00196 PinName cs, 00197 const char* SDName, 00198 const char *dir ); 00199 00200 // Public method to output Stream of data to open FILE 00201 void writeData(const char *dataStream); 00202 00203 // Public method to open FILE 00204 int openFile(const char *dirFile, const char *accessType); 00205 00206 // Public method to close FILE 00207 void closeFile(); 00208 00209 private: 00210 // Private method to construct a new directory on SD 00211 void makeDirectory(const char *dir); 00212 00213 protected: 00214 // Pointer to SDFileSystem object 00215 SDFileSystem *_sd; 00216 00217 // Pointer to FILE object 00218 FILE *fp; 00219 }; 00220 00221 #endif
Generated on Fri Jul 15 2022 15:41:37 by
1.7.2