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: LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI mbed-os BSP_DISCO_F429ZI
LaserMon-Main.cpp
00001 00002 // ---------------------------------------------------------------------- 00003 // LaserMon-Main.cpp 00004 // 00005 // Fredric L. Rice, June 2019 00006 // 00007 // ---------------------------------------------------------------------- 00008 00009 #include "mbed.h" // The mbed operating system 00010 #include "LCD_DISCO_F429ZI.h" // For controlling the LCD 00011 #include "TS_DISCO_F429ZI.h" // For controlling the touch screen 00012 #include "LaserMon-TestOutput.h" // For generating test output signal 00013 #include "LaserMon-ScanInput.h" // For monitoring laser power pin 00014 #include "LaserMon-TEC.h" // For monitoring the TEC output 00015 #include "LaserMon-Main.h" // Always include ourself 00016 00017 // ---------------------------------------------------------------------- 00018 // Local data storage 00019 // 00020 // ---------------------------------------------------------------------- 00021 00022 const char * pch_firstMessage = "Test signal on PA_5"; 00023 const char * pch_secondMessage = "Laser Scan on PC_1"; 00024 const char * pch_thirdMessage = "TEC signal on PC_3"; 00025 00026 // Instantiate a digitial input mapped as our push button 00027 static DigitalIn st_pushButton(PA_0); 00028 00029 // We must see the button down for a period of time, we 00030 // do a debounce even though the class may do one already 00031 static uint16_t u16_buttonDownCount; 00032 00033 // This flag informs the laser scan input module whether 00034 // it is permitted to plot the scan input or not 00035 static bool b_allowPlotting; 00036 00037 // We store the scan length in milliseconds offered to this 00038 // module by the laser scanner, and we store the TEC voltage 00039 // offered by the TEC scanner 00040 static uint16_t u16_scanLength; 00041 static uint16_t u16_TECVoltage; 00042 static uint16_t u16_scanCount; 00043 00044 // We talk to Jenkins through an RS232 serial interface 00045 static Serial st_Serial1(USE_SERIAL_TX, USE_SERIAL_RX); 00046 00047 // ---------------------------------------------------------------------- 00048 // Define global data storage which we will export 00049 // 00050 // ---------------------------------------------------------------------- 00051 00052 // We will be using the LCD so instantiate an object locally 00053 LCD_DISCO_F429ZI st_lcd; 00054 00055 // We will be using the touch screen so instantiate an object 00056 TS_DISCO_F429ZI st_touchScreen; 00057 00058 // ---------------------------------------------------------------------- 00059 // MainInit() 00060 // 00061 // ---------------------------------------------------------------------- 00062 static void MainInit(void) 00063 { 00064 // Initialize locally-held data 00065 u16_buttonDownCount = 0; 00066 b_allowPlotting = true; 00067 u16_scanLength = 0; 00068 u16_TECVoltage = 0; 00069 u16_scanCount = 0; 00070 00071 // Bring the LCD up 00072 st_lcd.Clear(LCD_COLOR_WHITE); 00073 00074 // Set the default text color 00075 st_lcd.SetTextColor(LCD_COLOR_BLUE); 00076 00077 // Set the background color 00078 st_lcd.SetBackColor(LCD_COLOR_WHITE); 00079 00080 // Set the default font size 00081 BSP_LCD_SetFont(&Font16); 00082 00083 // Set the push button to not have an internal pull-up or down 00084 st_pushButton.mode(PullNone); 00085 00086 // We configure the serial interface 00087 st_Serial1.baud(115200); 00088 st_Serial1.format(8, SerialBase::None, 1); 00089 } 00090 00091 // ---------------------------------------------------------------------- 00092 // 00093 // 00094 // ---------------------------------------------------------------------- 00095 static void MainCheckInbound(void) 00096 { 00097 // See if there is inbound serial data 00098 if (st_Serial1.readable()) 00099 { 00100 00101 } 00102 } 00103 00104 // ---------------------------------------------------------------------- 00105 // 00106 // 00107 // ---------------------------------------------------------------------- 00108 static void MainTransmitOutput(uint8_t * pu8_thisFrame, uint16_t u16_thisCount) 00109 { 00110 st_Serial1.write(pu8_thisFrame, u16_thisCount, NULL); 00111 } 00112 00113 // ---------------------------------------------------------------------- 00114 // LaserMonMainInformScanInformation() 00115 // 00116 // 00117 // ---------------------------------------------------------------------- 00118 void LaserMonMainInformScanInformation(uint16_t u16_thisScanLength, uint16_t u16_thisScanCount) 00119 { 00120 // If we arte displaying information, the scan gets slowed down 00121 // while we print the information to the screen, making the scan 00122 // information inaccurate. To avoid displaying inaccurate values 00123 // we refrain from storing the scan rate while displaying the 00124 // information 00125 if (true == b_allowPlotting) 00126 { 00127 // Allow the scan information to get updated 00128 u16_scanLength = u16_thisScanLength; 00129 } 00130 00131 // Always store the scan counter value 00132 u16_scanCount = u16_thisScanCount; 00133 } 00134 00135 // ---------------------------------------------------------------------- 00136 // LaserMonMainInformTECVoltage() 00137 // 00138 // ---------------------------------------------------------------------- 00139 void LaserMonMainInformTECVoltage(uint16_t u16_thisVoltage) 00140 { 00141 u16_TECVoltage = u16_thisVoltage; 00142 } 00143 00144 // ---------------------------------------------------------------------- 00145 // MainReportValues() 00146 // 00147 // ---------------------------------------------------------------------- 00148 static void MainReportValues(void) 00149 { 00150 char pch_holdMessage[101] = { 0 }; 00151 00152 (void)sprintf(pch_holdMessage, "Scan duration %u", u16_scanLength); 00153 st_lcd.DisplayStringAt(1, LINE(1), (uint8_t *)pch_holdMessage, LEFT_MODE); 00154 00155 (void)sprintf(pch_holdMessage, "Scan count %u", u16_scanCount); 00156 st_lcd.DisplayStringAt(1, LINE(2), (uint8_t *)pch_holdMessage, LEFT_MODE); 00157 00158 (void)sprintf(pch_holdMessage, "TEC voltage %1.02f", (float)u16_TECVoltage / 100.0f); 00159 st_lcd.DisplayStringAt(1, LINE(3), (uint8_t *)pch_holdMessage, LEFT_MODE); 00160 00161 (void)sprintf(pch_holdMessage, "TEC average %1.02f", (float)TECGetLastTenAverage() / 100.0f); 00162 st_lcd.DisplayStringAt(1, LINE(4), (uint8_t *)pch_holdMessage, LEFT_MODE); 00163 00164 // Build a report for Jenkins or anything else to monitor 00165 (void)sprintf(pch_holdMessage, "%u,%1.02f,%1.02f,%u%c%c", 00166 u16_scanLength, 00167 ((float)u16_TECVoltage / 100.0f), 00168 ((float)TECGetLastTenAverage() / 100.0f), 00169 u16_scanCount, 00170 0x0d, 0x0a); 00171 00172 // Send that report out the serial interface 00173 MainTransmitOutput((uint8_t *)pch_holdMessage, (uint16_t)strlen(pch_holdMessage)); 00174 } 00175 00176 // ---------------------------------------------------------------------- 00177 // MainHandleButtonDown() 00178 // 00179 // ---------------------------------------------------------------------- 00180 static void MainHandleButtonDown(void) 00181 { 00182 // Are we currently allowing the laser scan input to be plotted? 00183 if (true == b_allowPlotting) 00184 { 00185 // Flag the fact that we are not allowing the plot 00186 b_allowPlotting = false; 00187 00188 // Make sure that the display is cleared 00189 st_lcd.Clear(LCD_COLOR_WHITE); 00190 00191 // Report the lasr scan and TEC voltage values 00192 MainReportValues(); 00193 } 00194 else 00195 { 00196 // Clear the display 00197 st_lcd.Clear(LCD_COLOR_WHITE); 00198 00199 // Clear the flag so that the plot of the scan may be displayed 00200 b_allowPlotting = true; 00201 } 00202 } 00203 00204 // ---------------------------------------------------------------------- 00205 // MainThread() 00206 // 00207 // ---------------------------------------------------------------------- 00208 static bool MainThread(void) 00209 { 00210 bool b_restartOneSecondTimer = false; 00211 00212 // Acquire / poll the state of the push button 00213 int i_buttonState = st_pushButton.read(); 00214 00215 // Is the button down? 00216 if (1 == i_buttonState) 00217 { 00218 // The button is not down, was the button down before? 00219 // We need to see if the button is down for 10 milliseconds 00220 // before we agree that the button is down 00221 if (u16_buttonDownCount < 10) 00222 { 00223 if (10 == ++u16_buttonDownCount) 00224 { 00225 // The button has been held down long enough 00226 MainHandleButtonDown(); 00227 00228 // We want to have the one second timer restarted 00229 b_restartOneSecondTimer = true; 00230 } 00231 } 00232 } 00233 else 00234 { 00235 // The button is not down so clear the down counter 00236 u16_buttonDownCount = 0; 00237 } 00238 00239 // See if there is inbouns serial data to be processed 00240 MainCheckInbound(); 00241 00242 // Indicate whether we are displaying the running information or not 00243 return b_restartOneSecondTimer; 00244 } 00245 00246 // ---------------------------------------------------------------------- 00247 // main() 00248 // 00249 // 00250 // ---------------------------------------------------------------------- 00251 int main(void) 00252 { 00253 uint16_t u16_oneSecondCounter = 0; 00254 bool b_restartOneSecondTimer = false; 00255 00256 // Perform local module initialization, if any 00257 MainInit(); 00258 00259 // Initialize the generating of the output test signal module 00260 TestOutputInit(); 00261 00262 // Initialize the scanning of the the laser drive power module 00263 ScanInputInit(); 00264 00265 // Initialize the scanning of the TEC input and launch thread 00266 TECInit(); 00267 00268 // Display information about what signal pigs have what 00269 st_lcd.DisplayStringAt(1, LINE(0), (uint8_t *)pch_firstMessage, LEFT_MODE); 00270 st_lcd.DisplayStringAt(1, LINE(1), (uint8_t *)pch_secondMessage, LEFT_MODE); 00271 st_lcd.DisplayStringAt(1, LINE(2), (uint8_t *)pch_thirdMessage, LEFT_MODE); 00272 00273 // Go in to a forever loop for the main thread which does nothing 00274 while(true) 00275 { 00276 // Wait for 1 millisecond 00277 wait_us(899); 00278 00279 // Instead of launching threads whose timing is a problem, 00280 // we merely call the once-a-millisecond "thread" functions 00281 // to drive the test signal out and the laser scan signal in 00282 TestOutputThread(); 00283 ScanInputThread(b_allowPlotting); 00284 b_restartOneSecondTimer = MainThread(); 00285 TECThread(); 00286 00287 // Have we just started displaying collected information? 00288 if (true == b_restartOneSecondTimer) 00289 { 00290 // Yes, so we will count down the timer 00291 u16_oneSecondCounter = 1000; 00292 } 00293 else 00294 { 00295 // In case the one second timer is running, stop it 00296 b_restartOneSecondTimer = 0; 00297 } 00298 00299 // Is the one second counter running? 00300 if (u16_oneSecondCounter > 0 && false == b_allowPlotting) 00301 { 00302 // Count down the one second timer and see if it's expired 00303 if (0 == --u16_oneSecondCounter) 00304 { 00305 // Report the current values again 00306 MainReportValues(); 00307 00308 // Restart the one second timer 00309 u16_oneSecondCounter = 1000; 00310 } 00311 } 00312 } 00313 } 00314 00315 // End of file 00316
Generated on Thu Jul 14 2022 16:41:21 by
1.7.2