HeptaBattery library
HeptaBattery.cpp@6:869e6fe3ba64, 2017-11-15 (annotated)
- Committer:
- HEPTA
- Date:
- Wed Nov 15 02:38:28 2017 +0000
- Revision:
- 6:869e6fe3ba64
- Parent:
- 5:15a6a4425889
- Child:
- 8:92dcd75454b5
- Child:
- 9:7d0aaedfe1c0
HeptaBattery
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; |
hepta2ume | 0:1682fa22a51e | 7 | PHY_PowerDown();//Ethernet PHYchip停止 |
hepta2ume | 0:1682fa22a51e | 8 | } |
hepta2ume | 0:1682fa22a51e | 9 | |
hepta2ume | 0:1682fa22a51e | 10 | void HeptaBattery::vol(float* bt) |
hepta2ume | 0:1682fa22a51e | 11 | { |
hepta2ume | 0:1682fa22a51e | 12 | *bt = (_bat.read()*1.431*3.3);//バッテリー電圧読み出し |
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 | 6:869e6fe3ba64 | 20 | void HeptaBattery::turn_on_regulator() |
HEPTA | 6:869e6fe3ba64 | 21 | { |
HEPTA | 6:869e6fe3ba64 | 22 | _bat_ct = 1; |
HEPTA | 6:869e6fe3ba64 | 23 | } |
HEPTA | 6:869e6fe3ba64 | 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 | |
hepta2ume | 0:1682fa22a51e | 39 | void HeptaBattery::power_saving_mode() |
hepta2ume | 0:1682fa22a51e | 40 | { |
hepta2ume | 0:1682fa22a51e | 41 | float Bat; |
hepta2ume | 0:1682fa22a51e | 42 | Bat = _bat.read()*1.431*3.3; |
hepta2ume | 0:1682fa22a51e | 43 | //4.2以上 |
hepta2ume | 0:1682fa22a51e | 44 | if(Bat>=4.2) { |
umeume | 3:16fd450bcf16 | 45 | _bat_ct = 1; |
hepta2ume | 0:1682fa22a51e | 46 | LPC_SC->CCLKCFG = 2; |
hepta2ume | 0:1682fa22a51e | 47 | SystemCoreClockUpdate(); |
HEPTA | 4:65dc53760aa0 | 48 | } |
hepta2ume | 0:1682fa22a51e | 49 | //3.7 < Voltage < 4.1 |
hepta2ume | 0:1682fa22a51e | 50 | else if(Bat<=4.1 && Bat>=3.7) { |
hepta2ume | 0:1682fa22a51e | 51 | _bat_ct = 1; |
HEPTA | 4:65dc53760aa0 | 52 | LPC_SC->CCLKCFG = 2; |
HEPTA | 4:65dc53760aa0 | 53 | SystemCoreClockUpdate(); |
hepta2ume | 0:1682fa22a51e | 54 | } |
hepta2ume | 0:1682fa22a51e | 55 | //3.5V以下 |
hepta2ume | 0:1682fa22a51e | 56 | else if(Bat<=3.5) { |
HEPTA | 4:65dc53760aa0 | 57 | _bat_ct = 0; |
hepta2ume | 0:1682fa22a51e | 58 | LPC_SC->CCLKCFG = 5; |
hepta2ume | 0:1682fa22a51e | 59 | SystemCoreClockUpdate(); |
hepta2ume | 0:1682fa22a51e | 60 | } |
hepta2ume | 0:1682fa22a51e | 61 | |
hepta2ume | 0:1682fa22a51e | 62 | } |