Local library

Dependencies:   WakeUp PinDetect

Dependents:   Inductive_Sensor Inductive_Sensor_Jasper Inductive_Sensor_3

Committer:
bobgiesberts
Date:
Wed Aug 24 10:30:41 2016 +0000
Revision:
6:0e7c0ad0508b
Parent:
5:c2468a69aacb
Child:
7:0b23995256e7
Incorporated the button. NOT TESTED YET

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bobgiesberts 0:17943815800f 1 /**
bobgiesberts 0:17943815800f 2 * @file Bob.cpp
bobgiesberts 6:0e7c0ad0508b 3 * @brief just some functions to communicate with the
bobgiesberts 6:0e7c0ad0508b 4 * processor board for the LDC1614
bobgiesberts 0:17943815800f 5 *
bobgiesberts 0:17943815800f 6 * @author Bob Giesberts
bobgiesberts 0:17943815800f 7 *
bobgiesberts 6:0e7c0ad0508b 8 * @date 2016-08-24
bobgiesberts 0:17943815800f 9 */
bobgiesberts 0:17943815800f 10
bobgiesberts 0:17943815800f 11 #include "Bob.h"
bobgiesberts 0:17943815800f 12 #include "mbed.h"
bobgiesberts 4:9c3c8eb56a2b 13 #include "mbed_debug.h"
bobgiesberts 2:681ecede6dcb 14 #include "WakeUp.h"
bobgiesberts 0:17943815800f 15
bobgiesberts 2:681ecede6dcb 16
bobgiesberts 6:0e7c0ad0508b 17 void keyPressed( void )
bobgiesberts 6:0e7c0ad0508b 18 {
bobgiesberts 6:0e7c0ad0508b 19 // do something
bobgiesberts 6:0e7c0ad0508b 20 debug( "button pressed\r\n" );
bobgiesberts 6:0e7c0ad0508b 21 }
bobgiesberts 6:0e7c0ad0508b 22
bobgiesberts 6:0e7c0ad0508b 23
bobgiesberts 6:0e7c0ad0508b 24
bobgiesberts 6:0e7c0ad0508b 25 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)
bobgiesberts 0:17943815800f 26 {
bobgiesberts 6:0e7c0ad0508b 27 // setup leds
bobgiesberts 6:0e7c0ad0508b 28 _led_process = 0; // green
bobgiesberts 6:0e7c0ad0508b 29 _led_error = 0; // red
bobgiesberts 5:c2468a69aacb 30
bobgiesberts 6:0e7c0ad0508b 31 // setup I/O button
bobgiesberts 6:0e7c0ad0508b 32 _button.mode( PullUp );
bobgiesberts 6:0e7c0ad0508b 33 wait_ms(1);
bobgiesberts 6:0e7c0ad0508b 34 _button.attach_asserted( &keyPressed );
bobgiesberts 6:0e7c0ad0508b 35 _button.setSampleFrequency();
bobgiesberts 2:681ecede6dcb 36
bobgiesberts 6:0e7c0ad0508b 37 // setup SD card system
bobgiesberts 6:0e7c0ad0508b 38 // _sd_enable = 1;
bobgiesberts 2:681ecede6dcb 39 _sd_card_detect = new DigitalIn( sd_present );
bobgiesberts 2:681ecede6dcb 40 _sd_card_detect->mode( PullUp );
bobgiesberts 0:17943815800f 41
bobgiesberts 6:0e7c0ad0508b 42 // setup battery
bobgiesberts 2:681ecede6dcb 43 _batt = new AnalogIn( battery );
bobgiesberts 2:681ecede6dcb 44
bobgiesberts 3:68c005d410e1 45 // WakeUp::calibrate();
bobgiesberts 0:17943815800f 46 }
bobgiesberts 0:17943815800f 47
bobgiesberts 6:0e7c0ad0508b 48 Bob::~Bob() {}
bobgiesberts 6:0e7c0ad0508b 49
bobgiesberts 6:0e7c0ad0508b 50
bobgiesberts 6:0e7c0ad0508b 51
bobgiesberts 0:17943815800f 52 bool Bob::checkSD(void)
bobgiesberts 0:17943815800f 53 {
bobgiesberts 6:0e7c0ad0508b 54 // _sd_enable.write(1);
bobgiesberts 2:681ecede6dcb 55 return !_sd_card_detect->read();
bobgiesberts 2:681ecede6dcb 56 }
bobgiesberts 2:681ecede6dcb 57
bobgiesberts 4:9c3c8eb56a2b 58 void Bob::wakeup(void)
bobgiesberts 2:681ecede6dcb 59 {
bobgiesberts 6:0e7c0ad0508b 60 // _sd_enable.write(1); // power SD-card
bobgiesberts 4:9c3c8eb56a2b 61 // wait(0.3); // this shouldn't be necessary because loading the LDC library already takes 0.81 s
bobgiesberts 0:17943815800f 62 }
bobgiesberts 0:17943815800f 63
bobgiesberts 4:9c3c8eb56a2b 64 void Bob::beforesleep(void)
bobgiesberts 3:68c005d410e1 65 {
bobgiesberts 6:0e7c0ad0508b 66 // _sd_enable.write(0);
bobgiesberts 3:68c005d410e1 67 }
bobgiesberts 3:68c005d410e1 68
bobgiesberts 4:9c3c8eb56a2b 69 void Bob::sleep(uint32_t ms)
bobgiesberts 3:68c005d410e1 70 {
bobgiesberts 6:0e7c0ad0508b 71 // _sd_enable.write(0); // unpower SD-card
bobgiesberts 4:9c3c8eb56a2b 72 WakeUp::calibrate(); // calibration takes 100 ms
bobgiesberts 4:9c3c8eb56a2b 73 WakeUp::set_ms( ms - 100 ); // substract this from the total sleep time
bobgiesberts 4:9c3c8eb56a2b 74 deepsleep();
bobgiesberts 3:68c005d410e1 75 }
bobgiesberts 1:2234e0b31d94 76
bobgiesberts 2:681ecede6dcb 77 // battery voltage should be 3.1V (min) < 3.7V (typ) < 4.22V (max)
bobgiesberts 2:681ecede6dcb 78 float Bob::battery(void)
bobgiesberts 2:681ecede6dcb 79 {
bobgiesberts 2:681ecede6dcb 80 return (float)_batt->read() * 3.0 * 2.0;
bobgiesberts 2:681ecede6dcb 81 }
bobgiesberts 2:681ecede6dcb 82
bobgiesberts 0:17943815800f 83 void Bob::flash( int n )
bobgiesberts 0:17943815800f 84 {
bobgiesberts 6:0e7c0ad0508b 85 _led_process = 0;
bobgiesberts 0:17943815800f 86 for(int i=0; i<n*2; i++){
bobgiesberts 6:0e7c0ad0508b 87 _led_process = 1-_led_process;
bobgiesberts 5:c2468a69aacb 88 wait(0.2);
bobgiesberts 0:17943815800f 89 }
bobgiesberts 0:17943815800f 90 }
bobgiesberts 0:17943815800f 91
bobgiesberts 6:0e7c0ad0508b 92 void Bob::ledon(void) { _led_process = 1; }
bobgiesberts 6:0e7c0ad0508b 93 void Bob::ledoff(void) { _led_process = 0; }