Local library

Dependencies:   WakeUp PinDetect

Dependents:   Inductive_Sensor Inductive_Sensor_Jasper Inductive_Sensor_3

Files at this revision

API Documentation at this revision

Comitter:
bobgiesberts
Date:
Wed Sep 07 09:58:19 2016 +0000
Parent:
6:0e7c0ad0508b
Child:
8:42b54bfe81db
Commit message:
No big changes

Changed in this revision

Bob.cpp Show annotated file Show diff for this revision Revisions of this file
Bob.h Show annotated file Show diff for this revision Revisions of this file
--- a/Bob.cpp	Wed Aug 24 10:30:41 2016 +0000
+++ b/Bob.cpp	Wed Sep 07 09:58:19 2016 +0000
@@ -22,7 +22,7 @@
 
 
 
-Bob::Bob(PinName process_led, PinName error_led, PinName button, PinName sd_present, PinName battery) : _led_process(process_led), _led_error(error_led), _button(button)// , _sd_enable(sd_enable)
+Bob::Bob(PinName process_led, PinName error_led, PinName button, PinName enable, PinName sd_present, PinName battery) : _led_process(process_led), _led_error(error_led), _button(button), _enable(enable)
 {
     // setup leds
     _led_process = 0;   // green
@@ -35,14 +35,12 @@
     _button.setSampleFrequency();
 
     // setup SD card system
-    // _sd_enable = 1;    
     _sd_card_detect = new DigitalIn( sd_present ); 
     _sd_card_detect->mode( PullUp );
 
     // setup battery
     _batt = new AnalogIn( battery );
     
-    // WakeUp::calibrate();
 }
 
 Bob::~Bob() {}
@@ -51,24 +49,27 @@
 
 bool Bob::checkSD(void)
 {
-    // _sd_enable.write(1);
+    // TODO: this should first check if _enable is on. if not, return false either way!
+    
+    _enable.write(1);
+    wait_ms(3); 
     return !_sd_card_detect->read();
 }
 
-void Bob::wakeup(void)
+void Bob::wakeup_periphery(void)
 {
-    // _sd_enable.write(1);   // power SD-card
+    _enable.write(1);      // power SD-card
+    wait_ms(3);   
     // wait(0.3);          // this shouldn't be necessary because loading the LDC library already takes 0.81 s
 }
 
-void Bob::beforesleep(void)
+void Bob::shutdown_periphery(void)
 {
-    // _sd_enable.write(0);
+    _enable.write(0);
 }
 
 void Bob::sleep(uint32_t ms)
 {
-     // _sd_enable.write(0);           // unpower SD-card
      WakeUp::calibrate();           // calibration takes 100 ms
      WakeUp::set_ms( ms - 100 );    // substract this from the total sleep time
      deepsleep();
@@ -89,5 +90,8 @@
     }
 }
 
-void Bob::ledon(void)   { _led_process   = 1; }
-void Bob::ledoff(void)  { _led_process   = 0; }
+void Bob::processing(void)   { _led_process   = 1; }
+void Bob::no_processing(void)  { _led_process   = 0; }
+
+void Bob::error(void)   { _led_error   = 1; }
+void Bob::no_error(void)  { _led_error   = 0; }
--- a/Bob.h	Wed Aug 24 10:30:41 2016 +0000
+++ b/Bob.h	Wed Sep 07 09:58:19 2016 +0000
@@ -21,31 +21,39 @@
          * @param process_led   Pin connected to the green led, used for processing
          * @param error_led     Pin connected to the red led, used for errors
          * @param button        Pin connected to the I/O button
+         * @param enable        Pin connected to the SD card system and the crystal
          * @param sd_present    Pin connected to the SDCardDetect port
          * @param battery       Pin connected to the battery
          */
-        Bob(PinName process_led, PinName error_led, PinName button, PinName sd_present, PinName battery);
+        Bob(PinName process_led, PinName error_led, PinName button, PinName enable, PinName sd_present, PinName battery);
         ~Bob();
         
         bool checkSD(void);
         
-        void wakeup(void);
-        void beforesleep(void);
+        void wakeup_periphery(void);
+        
+        /** shutdown_periphery
+         *  Powers down the SD card system, the crystal and the LDC1614
+         */
+        void shutdown_periphery(void);
         void sleep(uint32_t ms);
         
 
         float battery(void);
         
         void flash(int n);
-        void ledon(void);
-        void ledoff(void);
+        void processing(void);
+        void no_processing(void);
+        void error(void);
+        void no_error(void);
             
     private:
-        DigitalOut _led_process;
-        DigitalOut _led_error;
-        // DigitalOut _sd_enable;
+        DigitalOut _led_process;    // green led
+        DigitalOut _led_error;      // red led
+        PinDetect  _button;         // button
+        DigitalOut _enable;         // pin to power all periphery (SD, crystal, LDC1614)
+        
         DigitalIn *_sd_card_detect;
-        PinDetect _button;
         
         AnalogIn  *_batt;