HeptaBattery

Dependencies:   PowerControl

Dependents:   Hepta_Battery HEPTA2_assembly_0720 HEPTA2_ALL HEPTA2_ALL_ver0803_02 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HeptaBattery.cpp Source File

HeptaBattery.cpp

00001 #include "HeptaBattery.h"
00002 #include "mbed.h"
00003 
00004 HeptaBattery::HeptaBattery(PinName bat, PinName bat_ct) : _bat(bat),_bat_ct(bat_ct)
00005 {
00006     _bat_ct = 1;
00007     PHY_PowerDown();//Ethernet PHYchip停止
00008 }
00009 
00010 void HeptaBattery::vol(float* bt)
00011 {
00012     *bt = (_bat.read()*1.431*3.3);//バッテリー電圧読み出し
00013 }
00014 
00015 void HeptaBattery::fast_charge()
00016 {
00017     //Peripheral_PowerDown(0x7DFEDFEE);怪しい
00018     _bat_ct = 0;
00019 }
00020 
00021 void HeptaBattery::vol_u16(char* bt_u16, int *dsize)
00022 {
00023     unsigned short bt_datas;
00024     char bt1[8]= {0x00},bt2[8]= {0x00};
00025     bt_datas=_bat.read_u16()>>4;
00026     sprintf( bt1, "%02X", (bt_datas >> 8) & 0x0F);
00027     sprintf( bt2, "%02X", (bt_datas) & 0xFF);
00028     bt_u16[0]=bt1[0];
00029     bt_u16[1]=bt1[1];
00030     bt_u16[2]=bt2[0];
00031     bt_u16[3]=bt2[1];
00032     *dsize = 4;
00033 }
00034 
00035 void HeptaBattery::power_saving_mode()
00036 {
00037     float Bat;
00038     Bat = _bat.read()*1.431*3.3;
00039     //4.2以上
00040     if(Bat>=4.2) {
00041         _bat_ct = 0;
00042         Peripheral_PowerUp(0xFDFF6FF7);
00043         LPC_SC->CCLKCFG = 2;
00044         SystemCoreClockUpdate();
00045     } 
00046     //3.7 < Voltage < 4.1
00047     else if(Bat<=4.1 && Bat>=3.7) {
00048         Peripheral_PowerUp(0xFDFF6FF7);
00049          LPC_SC->CCLKCFG = 2;
00050          SystemCoreClockUpdate();
00051         _bat_ct = 1;
00052     }
00053     //3.5V以下
00054     else if(Bat<=3.5) {
00055         Peripheral_PowerDown(0x7D7E6DF1);
00056         LPC_SC->CCLKCFG = 5;
00057         SystemCoreClockUpdate();
00058         _bat_ct = 1;
00059     }
00060 
00061 }