Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed PowerControl SDFileSystem
Fork of HeptaBattery by
HeptaBattery.cpp
00001 #include "HeptaBattery.h" 00002 #include "mbed.h" 00003 00004 HeptaBattery::HeptaBattery(PinName bat, PinName bat_ct, PinName reg_st) : _bat(bat),_bat_ct(bat_ct),_reg_st(reg_st) 00005 { 00006 _bat_ct = 0; // disable battery charge 00007 _reg_st = 1; // able 3.3V regulator out 00008 PHY_PowerDown();// disable Ethernet connection 00009 } 00010 void HeptaBattery::vol(float* bt) 00011 { 00012 *bt = (_bat.read()*1.431*3.3); 00013 } 00014 void HeptaBattery::vol_u16(char* bt_u16) 00015 { 00016 unsigned short bt_datas; 00017 char bt1[8]={0x00},bt2[8]={0x00}; 00018 bt_datas=_bat.read_u16()>>4; 00019 sprintf( bt1, "%02X", (bt_datas >> 8) & 0x0F); 00020 sprintf( bt2, "%02X", (bt_datas) & 0xFF); 00021 bt_u16[0]=bt1[0]; bt_u16[1]=bt1[1]; 00022 bt_u16[2]=bt2[0]; bt_u16[3]=bt2[1]; 00023 } 00024 void HeptaBattery::chargecontrol(int state, int *save_flag) 00025 { 00026 float Bat; 00027 switch(state){ 00028 case 1: 00029 //Battery Voltage High Level 00030 Peripheral_PowerUp(0xFDFF6FF7); 00031 _bat_ct = 0; 00032 _reg_st = 1; 00033 *save_flag = 0; 00034 break; 00035 case 2: 00036 //Battery Voltage Normal Level 00037 Peripheral_PowerUp(0xFDFF6FF7); 00038 _reg_st = 1; 00039 _bat_ct = 1; 00040 *save_flag = 0; 00041 break; 00042 case 3: 00043 //Battery Voltage Low Level 00044 Peripheral_PowerDown(0x7D7E6DF1); 00045 _bat_ct = 1; 00046 _reg_st = 0; 00047 *save_flag = 1; 00048 break; 00049 case 4: 00050 //Battery Voltage Auto Charge 00051 Bat = _bat.read()*1.431*3.3; 00052 if(Bat>=4.2){ 00053 Peripheral_PowerUp(0xFDFF6FF7); 00054 printf("voltage high level = %f\r\n",Bat); 00055 printf("Complete!!!"); 00056 _bat_ct = 0; 00057 _reg_st = 1; 00058 *save_flag = 0; 00059 } 00060 Peripheral_PowerDown(0x7D7E6DF1); 00061 printf("voltage low level = %f\r\n",Bat); 00062 _bat_ct = 1; 00063 _reg_st = 0; 00064 *save_flag = 1; 00065 break; 00066 default: 00067 printf("error\r\n"); 00068 break; 00069 } 00070 } 00071
Generated on Fri Jul 15 2022 01:55:16 by
1.7.2
