HeptaBattery library
HeptaBattery.cpp@4:65dc53760aa0, 2017-09-04 (annotated)
- Committer:
- HEPTA
- Date:
- Mon Sep 04 16:27:30 2017 +0000
- Revision:
- 4:65dc53760aa0
- Parent:
- 3:16fd450bcf16
- Child:
- 5:15a6a4425889
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 | |
hepta2ume | 0:1682fa22a51e | 20 | void HeptaBattery::vol_u16(char* bt_u16, int *dsize) |
hepta2ume | 0:1682fa22a51e | 21 | { |
hepta2ume | 0:1682fa22a51e | 22 | unsigned short bt_datas; |
hepta2ume | 0:1682fa22a51e | 23 | char bt1[8]= {0x00},bt2[8]= {0x00}; |
hepta2ume | 0:1682fa22a51e | 24 | bt_datas=_bat.read_u16()>>4; |
hepta2ume | 0:1682fa22a51e | 25 | sprintf( bt1, "%02X", (bt_datas >> 8) & 0x0F); |
hepta2ume | 0:1682fa22a51e | 26 | sprintf( bt2, "%02X", (bt_datas) & 0xFF); |
hepta2ume | 0:1682fa22a51e | 27 | bt_u16[0]=bt1[0]; |
hepta2ume | 0:1682fa22a51e | 28 | bt_u16[1]=bt1[1]; |
hepta2ume | 0:1682fa22a51e | 29 | bt_u16[2]=bt2[0]; |
hepta2ume | 0:1682fa22a51e | 30 | bt_u16[3]=bt2[1]; |
hepta2ume | 0:1682fa22a51e | 31 | *dsize = 4; |
hepta2ume | 0:1682fa22a51e | 32 | } |
hepta2ume | 0:1682fa22a51e | 33 | |
hepta2ume | 0:1682fa22a51e | 34 | void HeptaBattery::power_saving_mode() |
hepta2ume | 0:1682fa22a51e | 35 | { |
hepta2ume | 0:1682fa22a51e | 36 | float Bat; |
hepta2ume | 0:1682fa22a51e | 37 | Bat = _bat.read()*1.431*3.3; |
hepta2ume | 0:1682fa22a51e | 38 | //4.2以上 |
hepta2ume | 0:1682fa22a51e | 39 | if(Bat>=4.2) { |
umeume | 3:16fd450bcf16 | 40 | _bat_ct = 1; |
hepta2ume | 0:1682fa22a51e | 41 | LPC_SC->CCLKCFG = 2; |
hepta2ume | 0:1682fa22a51e | 42 | SystemCoreClockUpdate(); |
HEPTA | 4:65dc53760aa0 | 43 | } |
hepta2ume | 0:1682fa22a51e | 44 | //3.7 < Voltage < 4.1 |
hepta2ume | 0:1682fa22a51e | 45 | else if(Bat<=4.1 && Bat>=3.7) { |
hepta2ume | 0:1682fa22a51e | 46 | _bat_ct = 1; |
HEPTA | 4:65dc53760aa0 | 47 | LPC_SC->CCLKCFG = 2; |
HEPTA | 4:65dc53760aa0 | 48 | SystemCoreClockUpdate(); |
hepta2ume | 0:1682fa22a51e | 49 | } |
hepta2ume | 0:1682fa22a51e | 50 | //3.5V以下 |
hepta2ume | 0:1682fa22a51e | 51 | else if(Bat<=3.5) { |
HEPTA | 4:65dc53760aa0 | 52 | _bat_ct = 0; |
hepta2ume | 0:1682fa22a51e | 53 | LPC_SC->CCLKCFG = 5; |
hepta2ume | 0:1682fa22a51e | 54 | SystemCoreClockUpdate(); |
hepta2ume | 0:1682fa22a51e | 55 | } |
hepta2ume | 0:1682fa22a51e | 56 | |
hepta2ume | 0:1682fa22a51e | 57 | } |