Local library

Dependencies:   WakeUp PinDetect

Dependents:   Inductive_Sensor Inductive_Sensor_Jasper Inductive_Sensor_3

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Bob.cpp Source File

Bob.cpp

Go to the documentation of this file.
00001 /**
00002 * @file Bob.cpp
00003 * @brief just some functions to communicate with the
00004 * processor board for the LDC1614
00005 *
00006 * @author Bob Giesberts
00007 *
00008 * @date 2016-08-24
00009 */
00010 
00011 #include "Bob.h"
00012 
00013 
00014 
00015 void keyPressed( void )
00016 {
00017     // do something
00018     debug( "button pressed\r\n" );
00019 }
00020 
00021 
00022 
00023 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)
00024 {
00025     // setup leds
00026     _led_process = 0;   // green
00027     _led_error = 0;     // red
00028 
00029     // setup I/O button 
00030     _button.mode( PullUp );
00031     wait_ms(1);
00032     _button.attach_asserted( &keyPressed );
00033     _button.setSampleFrequency();
00034 
00035     // setup SD card system
00036     _sd_card_detect = new DigitalIn( sd_present ); 
00037     _sd_card_detect->mode( PullUp );
00038 
00039     // setup battery
00040     _batt = new AnalogIn( battery );
00041     
00042 }
00043 
00044 Bob::~Bob() {}
00045 
00046 
00047 
00048 bool Bob::checkSD(void)
00049 {
00050     // TODO: this should first check if _enable is on. if not, return false either way!
00051     
00052     _enable.write(1);
00053     wait_ms(3); 
00054     return !_sd_card_detect->read();
00055 }
00056 
00057 void Bob::wakeup_periphery(void)
00058 {
00059     _enable.write(1);      // power SD-card
00060     wait_ms(3);   
00061     // wait(0.3);          // this shouldn't be necessary because loading the LDC library already takes 0.81 s
00062 }
00063 
00064 void Bob::shutdown_periphery(void)
00065 {
00066     _enable.write(0);
00067 }
00068 
00069 void Bob::shutdown_pin(PinName pin, int value, PinMode pull )
00070 {
00071     if( value == 1 )
00072     {
00073         DigitalInOut *_pin = new DigitalInOut( pin );
00074         _pin->output();
00075         _pin->mode( pull );
00076         _pin->write( value );
00077         delete _pin;
00078         _pin = NULL;
00079     }else{
00080         DigitalOut *_pin = new DigitalOut( pin );
00081         _pin->write( value );
00082         delete _pin;
00083         _pin = NULL;
00084     }
00085 }
00086 
00087 void Bob::sleep(uint32_t ms)
00088 {
00089      WakeUp::calibrate();           // calibration takes 100 ms
00090      WakeUp::set_ms( ms - 100 );    // substract this from the total sleep time
00091      deepsleep();
00092 }
00093 
00094 // battery voltage should be 3.1V (min) < 3.7V (typ) < 4.22V (max)
00095 float Bob::battery(void)
00096 {
00097     return (float)_batt->read() * 3.0 * 2.0;
00098 }
00099 
00100 void Bob::flash( int n, int led )
00101 {
00102     if( led == 0 || led == 1 ) _led_process = 0;
00103     if( led == 0 || led == 2 ) _led_error = 0;
00104     for(int i=0; i<n*2; i++){
00105         if( led == 0 || led == 1 ) _led_process = 1-_led_process; 
00106         if( led == 0 || led == 2 ) _led_error = 1-_led_error; 
00107         wait(0.2);
00108     }
00109 }
00110 
00111 void Bob::processing( int n)
00112 {
00113     if( n == 0 ) {
00114         _led_process = 1; 
00115     }else{
00116         _led_process = 0;
00117         flash( n, 1 );
00118         wait(0.8);
00119     }     
00120 }
00121 void Bob::no_processing(void)  { _led_process   = 0; }
00122 
00123 void Bob::error( int n )
00124 {
00125     if( n == 0 ) {
00126         _led_error = 1; 
00127     }else{
00128         _led_error = 0;
00129         flash( n, 2 );
00130         wait(0.8);
00131     }     
00132 }
00133 void Bob::no_error(void)  { _led_error   = 0; }