Local library

Dependencies:   WakeUp PinDetect

Dependents:   Inductive_Sensor Inductive_Sensor_Jasper Inductive_Sensor_3

Committer:
bobgiesberts
Date:
Tue Apr 12 14:39:08 2016 +0000
Revision:
5:c2468a69aacb
Parent:
4:9c3c8eb56a2b
Child:
6:0e7c0ad0508b
Good working version;  - cleaned up some code;  - only support for 1 LED now, the other one is for DS1825

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bobgiesberts 0:17943815800f 1 /**
bobgiesberts 0:17943815800f 2 * @file Bob.cpp
bobgiesberts 0:17943815800f 3 * @brief just so functions to communicate with the
bobgiesberts 0:17943815800f 4 * processor board for the LDC1101
bobgiesberts 0:17943815800f 5 *
bobgiesberts 0:17943815800f 6 * @author Bob Giesberts
bobgiesberts 0:17943815800f 7 *
bobgiesberts 0:17943815800f 8 * @date 2015-12-18
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 5:c2468a69aacb 17 Bob::Bob(PinName led, PinName sd_enable, PinName sd_present, PinName battery, PinName V_Det) : _led(led), _sd_enable(sd_enable)
bobgiesberts 0:17943815800f 18 {
bobgiesberts 5:c2468a69aacb 19 _led = 0;
bobgiesberts 5:c2468a69aacb 20
bobgiesberts 2:681ecede6dcb 21 _sd_enable = 1;
bobgiesberts 2:681ecede6dcb 22
bobgiesberts 2:681ecede6dcb 23 _sd_card_detect = new DigitalIn( sd_present );
bobgiesberts 2:681ecede6dcb 24 _sd_card_detect->mode( PullUp );
bobgiesberts 0:17943815800f 25
bobgiesberts 2:681ecede6dcb 26 _batt = new AnalogIn( battery );
bobgiesberts 2:681ecede6dcb 27
bobgiesberts 2:681ecede6dcb 28 _V_Det = new DigitalIn( V_Det );
bobgiesberts 2:681ecede6dcb 29 _V_Det->mode( PullUp );
bobgiesberts 2:681ecede6dcb 30
bobgiesberts 3:68c005d410e1 31 // WakeUp::calibrate();
bobgiesberts 0:17943815800f 32 }
bobgiesberts 0:17943815800f 33
bobgiesberts 0:17943815800f 34 bool Bob::checkSD(void)
bobgiesberts 0:17943815800f 35 {
bobgiesberts 3:68c005d410e1 36 _sd_enable.write(1);
bobgiesberts 2:681ecede6dcb 37 return !_sd_card_detect->read();
bobgiesberts 2:681ecede6dcb 38 }
bobgiesberts 2:681ecede6dcb 39
bobgiesberts 4:9c3c8eb56a2b 40 void Bob::wakeup(void)
bobgiesberts 2:681ecede6dcb 41 {
bobgiesberts 4:9c3c8eb56a2b 42 _sd_enable.write(1); // power SD-card + power sensor
bobgiesberts 4:9c3c8eb56a2b 43 // wait(0.3); // this shouldn't be necessary because loading the LDC library already takes 0.81 s
bobgiesberts 0:17943815800f 44 }
bobgiesberts 0:17943815800f 45
bobgiesberts 4:9c3c8eb56a2b 46 void Bob::beforesleep(void)
bobgiesberts 3:68c005d410e1 47 {
bobgiesberts 3:68c005d410e1 48 _sd_enable.write(0);
bobgiesberts 3:68c005d410e1 49 }
bobgiesberts 3:68c005d410e1 50
bobgiesberts 4:9c3c8eb56a2b 51 void Bob::sleep(uint32_t ms)
bobgiesberts 3:68c005d410e1 52 {
bobgiesberts 4:9c3c8eb56a2b 53 _sd_enable.write(0); // unpower SD-card + unpower sensor
bobgiesberts 4:9c3c8eb56a2b 54 WakeUp::calibrate(); // calibration takes 100 ms
bobgiesberts 4:9c3c8eb56a2b 55 WakeUp::set_ms( ms - 100 ); // substract this from the total sleep time
bobgiesberts 4:9c3c8eb56a2b 56 deepsleep();
bobgiesberts 3:68c005d410e1 57 }
bobgiesberts 1:2234e0b31d94 58
bobgiesberts 2:681ecede6dcb 59 // battery voltage should be 3.1V (min) < 3.7V (typ) < 4.22V (max)
bobgiesberts 2:681ecede6dcb 60 float Bob::battery(void)
bobgiesberts 2:681ecede6dcb 61 {
bobgiesberts 2:681ecede6dcb 62 return (float)_batt->read() * 3.0 * 2.0;
bobgiesberts 2:681ecede6dcb 63 }
bobgiesberts 2:681ecede6dcb 64
bobgiesberts 0:17943815800f 65 void Bob::flash( int n )
bobgiesberts 0:17943815800f 66 {
bobgiesberts 5:c2468a69aacb 67 _led = 0;
bobgiesberts 0:17943815800f 68 for(int i=0; i<n*2; i++){
bobgiesberts 5:c2468a69aacb 69 _led = 1-_led;
bobgiesberts 5:c2468a69aacb 70 wait(0.2);
bobgiesberts 0:17943815800f 71 }
bobgiesberts 0:17943815800f 72 }
bobgiesberts 0:17943815800f 73
bobgiesberts 5:c2468a69aacb 74 void Bob::ledon(void) { _led = 1; }
bobgiesberts 5:c2468a69aacb 75 void Bob::ledoff(void) { _led = 0; }
bobgiesberts 2:681ecede6dcb 76
bobgiesberts 4:9c3c8eb56a2b 77
bobgiesberts 4:9c3c8eb56a2b 78
bobgiesberts 4:9c3c8eb56a2b 79
bobgiesberts 4:9c3c8eb56a2b 80
bobgiesberts 4:9c3c8eb56a2b 81
bobgiesberts 4:9c3c8eb56a2b 82
bobgiesberts 5:c2468a69aacb 83