Mark Gottscho / UtilityLib

Fork of UtilityLib by Mark Gottscho

Revision:
0:cc61e9d1c295
Child:
1:2a3bbec22035
diff -r 000000000000 -r cc61e9d1c295 Utility.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utility.h	Tue Feb 18 22:19:16 2014 +0000
@@ -0,0 +1,79 @@
+/* Utility.h
+ * Tested with mbed board: FRDM-KL46Z
+ * Author: Mark Gottscho
+ * mgottscho@ucla.edu
+ */
+ 
+#ifndef UTILITY_H
+#define UTILITY_H
+ 
+#include "mbed.h"
+#include <string>
+
+class Utility {
+    public:
+        Utility(PinName green_led_pin, PinName red_led_pin, PinName serial_tx_pin, PinName serial_rx_pin);
+        ~Utility();
+        
+        /**
+         * Infinitely loop in a panic condition, disabling the green user LED, enabling the red user LED and printing an error message to the serial console.
+         * This method never returns.
+         * @param errorMessage the string to print
+         * @param errorCode the accompanying error code to print
+         */
+        void panic(string errorMessage, int errorCode);
+        
+        /**
+         * Print a warning message to the serial console.
+         * @param errorMessage the string to print
+         * @param errorCode the accompanying error code to print
+         */
+        void warn(string errorMessage, int errorCode);
+        
+        /**
+         * Object-oriented assert statement.
+         * @param condition if false, calls panic() with results of the assertion, and never returns.
+         * @param file string representing the source file where the assertion is called
+         * @param line line number of the source file where the assertion is called
+         */
+        void myAssert(bool condition, const char *file, const unsigned long line);
+        
+        /**
+         * Blink the green user LED. This is a non-blocking call. The LED will blink until it is disabled.
+         * @param enable if true, enables the blinking LED
+         * @param half_period half of the blink period. This is the "on-time" and "off-time" of LED (50% duty cycle).
+         * If non-positive, the LED will stay on. 
+         * half_period must be no more than 1800 seconds (30 minutes), or this method will have no effect.
+         */
+        void blinkGreen(bool enable, float half_period);
+        
+        /**
+         * Blink the red user LED. This is a non-blocking call. The LED will blink until it is disabled.
+         * @param enable if true, enables the blinking LED
+         * @param half_period half of the blink period. This is the "on-time" and "off-time" of LED (50% duty cycle).
+         * If non-positive, the LED will stay on. 
+         * half_period must be no more than 1800 seconds (30 minutes), or this method will have no effect.
+         */
+        void blinkRed(bool enable, float half_period);
+        
+        Serial console;
+                
+    private:
+        /**
+         * Interrupt service routine for blinking the green user LED.
+         */
+        void __greenLED_ISR();
+        
+        /**
+         * Interrupt service routine for blinking the red user LED.
+         */
+        void __redLED_ISR();
+    
+        DigitalOut __green_led;
+        Ticker __green_led_interrupt;
+        
+        DigitalOut __red_led;
+        Ticker __red_led_interrupt;
+};
+
+#endif
\ No newline at end of file