HeptaBattery Library
Dependents: Lab9-01_All_transmit Lab9-03_Thermal_chamber 3daf572bcae1 Team ... more
Fork of HeptaBattery by
HeptaBattery.cpp@11:65c3076b5c24, 2019-08-22 (annotated)
- Committer:
- HEPTA
- Date:
- Thu Aug 22 05:40:34 2019 +0000
- Revision:
- 11:65c3076b5c24
- Parent:
- 9:7d0aaedfe1c0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hepta2ume | 0:1682fa22a51e | 1 | #include "HeptaBattery.h" |
hepta2ume | 0:1682fa22a51e | 2 | #include "mbed.h" |
hepta2ume | 0:1682fa22a51e | 3 | |
hepta2ume | 0:1682fa22a51e | 4 | HeptaBattery::HeptaBattery(PinName bat, PinName bat_ct) : _bat(bat),_bat_ct(bat_ct) |
hepta2ume | 0:1682fa22a51e | 5 | { |
hepta2ume | 2:821f36c03e26 | 6 | _bat_ct = 1; |
HEPTA | 9:7d0aaedfe1c0 | 7 | PHY_PowerDown();//stop Ethernet PHYchip |
hepta2ume | 0:1682fa22a51e | 8 | } |
hepta2ume | 0:1682fa22a51e | 9 | |
hepta2ume | 0:1682fa22a51e | 10 | void HeptaBattery::vol(float* bt) |
hepta2ume | 0:1682fa22a51e | 11 | { |
HEPTA | 9:7d0aaedfe1c0 | 12 | *bt = (_bat.read()*1.431*3.3);//read the battery voltage |
hepta2ume | 0:1682fa22a51e | 13 | } |
hepta2ume | 0:1682fa22a51e | 14 | |
HEPTA | 4:65dc53760aa0 | 15 | void HeptaBattery::shut_down_regulator() |
hepta2ume | 0:1682fa22a51e | 16 | { |
hepta2ume | 2:821f36c03e26 | 17 | _bat_ct = 0; |
hepta2ume | 0:1682fa22a51e | 18 | } |
hepta2ume | 0:1682fa22a51e | 19 | |
HEPTA | 7:b701e9cd2108 | 20 | void HeptaBattery::turn_on_regulator() |
HEPTA | 7:b701e9cd2108 | 21 | { |
HEPTA | 7:b701e9cd2108 | 22 | _bat_ct = 1; |
HEPTA | 7:b701e9cd2108 | 23 | } |
HEPTA | 7:b701e9cd2108 | 24 | |
HEPTA | 5:15a6a4425889 | 25 | void HeptaBattery::vol_u16(char* bt_u16) |
hepta2ume | 0:1682fa22a51e | 26 | { |
hepta2ume | 0:1682fa22a51e | 27 | unsigned short bt_datas; |
hepta2ume | 0:1682fa22a51e | 28 | char bt1[8]= {0x00},bt2[8]= {0x00}; |
hepta2ume | 0:1682fa22a51e | 29 | bt_datas=_bat.read_u16()>>4; |
hepta2ume | 0:1682fa22a51e | 30 | sprintf( bt1, "%02X", (bt_datas >> 8) & 0x0F); |
hepta2ume | 0:1682fa22a51e | 31 | sprintf( bt2, "%02X", (bt_datas) & 0xFF); |
hepta2ume | 0:1682fa22a51e | 32 | bt_u16[0]=bt1[0]; |
hepta2ume | 0:1682fa22a51e | 33 | bt_u16[1]=bt1[1]; |
hepta2ume | 0:1682fa22a51e | 34 | bt_u16[2]=bt2[0]; |
hepta2ume | 0:1682fa22a51e | 35 | bt_u16[3]=bt2[1]; |
HEPTA | 5:15a6a4425889 | 36 | //*dsize = 4; |
hepta2ume | 0:1682fa22a51e | 37 | } |
hepta2ume | 0:1682fa22a51e | 38 | |
HEPTA | 9:7d0aaedfe1c0 | 39 | void HeptaBattery::power_saving_mode(int *flag,float* Bat) |
hepta2ume | 0:1682fa22a51e | 40 | { |
HEPTA | 9:7d0aaedfe1c0 | 41 | *Bat = _bat.read()*1.431*3.3; |
HEPTA | 9:7d0aaedfe1c0 | 42 | //Above 4.2 or more |
HEPTA | 9:7d0aaedfe1c0 | 43 | if(*Bat>=4.2) { |
umeume | 3:16fd450bcf16 | 44 | _bat_ct = 1; |
HEPTA | 11:65c3076b5c24 | 45 | // LPC_SC->CCLKCFG = 2; |
HEPTA | 11:65c3076b5c24 | 46 | //SystemCoreClockUpdate(); |
HEPTA | 9:7d0aaedfe1c0 | 47 | *flag = 0; |
HEPTA | 4:65dc53760aa0 | 48 | } |
hepta2ume | 0:1682fa22a51e | 49 | //3.7 < Voltage < 4.1 |
HEPTA | 9:7d0aaedfe1c0 | 50 | else if(*Bat<=4.1 && *Bat>=3.7) { |
hepta2ume | 0:1682fa22a51e | 51 | _bat_ct = 1; |
HEPTA | 11:65c3076b5c24 | 52 | //LPC_SC->CCLKCFG = 2; |
HEPTA | 11:65c3076b5c24 | 53 | //SystemCoreClockUpdate(); |
HEPTA | 9:7d0aaedfe1c0 | 54 | *flag = 0; |
hepta2ume | 0:1682fa22a51e | 55 | } |
HEPTA | 9:7d0aaedfe1c0 | 56 | //3.5V or less |
HEPTA | 9:7d0aaedfe1c0 | 57 | else if(*Bat<=3.5) { |
HEPTA | 4:65dc53760aa0 | 58 | _bat_ct = 0; |
HEPTA | 11:65c3076b5c24 | 59 | //LPC_SC->CCLKCFG = 5; |
HEPTA | 11:65c3076b5c24 | 60 | //SystemCoreClockUpdate(); |
HEPTA | 9:7d0aaedfe1c0 | 61 | *flag = 1; |
hepta2ume | 0:1682fa22a51e | 62 | } |
hepta2ume | 0:1682fa22a51e | 63 | |
hepta2ume | 0:1682fa22a51e | 64 | } |