HeptaBattery library

Dependencies:   PowerControl

Dependents:   HEPTA_EPS

Committer:
HEPTA
Date:
Wed Aug 08 10:36:56 2018 +0000
Revision:
8:92dcd75454b5
Parent:
7:b701e9cd2108
HeptaBattery

Who changed what in which revision?

UserRevisionLine numberNew 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 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 8:92dcd75454b5 39 void HeptaBattery::power_saving_mode(int *flag,float* Bat)
hepta2ume 0:1682fa22a51e 40 {
HEPTA 8:92dcd75454b5 41 *Bat = _bat.read()*1.431*3.3;
hepta2ume 0:1682fa22a51e 42 //4.2以上
HEPTA 8:92dcd75454b5 43 if(*Bat>=4.2) {
umeume 3:16fd450bcf16 44 _bat_ct = 1;
hepta2ume 0:1682fa22a51e 45 LPC_SC->CCLKCFG = 2;
hepta2ume 0:1682fa22a51e 46 SystemCoreClockUpdate();
HEPTA 8:92dcd75454b5 47 *flag = 0;
HEPTA 4:65dc53760aa0 48 }
hepta2ume 0:1682fa22a51e 49 //3.7 < Voltage < 4.1
HEPTA 8:92dcd75454b5 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();
HEPTA 8:92dcd75454b5 54 *flag = 0;
hepta2ume 0:1682fa22a51e 55 }
hepta2ume 0:1682fa22a51e 56 //3.5V以下
HEPTA 8:92dcd75454b5 57 else if(*Bat<=3.5) {
HEPTA 4:65dc53760aa0 58 _bat_ct = 0;
hepta2ume 0:1682fa22a51e 59 LPC_SC->CCLKCFG = 5;
hepta2ume 0:1682fa22a51e 60 SystemCoreClockUpdate();
HEPTA 8:92dcd75454b5 61 *flag = 1;
hepta2ume 0:1682fa22a51e 62 }
hepta2ume 0:1682fa22a51e 63
hepta2ume 0:1682fa22a51e 64 }