For Hepta-Sat Lite

Committer:
heptasat2021
Date:
Tue Aug 17 10:50:52 2021 +0000
Revision:
11:2d5ef7475e31
Parent:
10:00fc48db2361
For Hepta-Sat Lite

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;
heptasat2021 11:2d5ef7475e31 7 //PHY_PowerDown();//stop Ethernet PHYchip
hepta2ume 0:1682fa22a51e 8 }
hepta2ume 0:1682fa22a51e 9
hepta2ume 0:1682fa22a51e 10 void HeptaBattery::vol(float* bt)
hepta2ume 0:1682fa22a51e 11 {
HEPTA 9:7d0aaedfe1c0 12 *bt = (_bat.read()*1.431*3.3);//read the battery voltage
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;
heptasat2021 11:2d5ef7475e31 23 wait_ms(1000);
HEPTA 7:b701e9cd2108 24 }
HEPTA 7:b701e9cd2108 25
HEPTA 5:15a6a4425889 26 void HeptaBattery::vol_u16(char* bt_u16)
hepta2ume 0:1682fa22a51e 27 {
hepta2ume 0:1682fa22a51e 28 unsigned short bt_datas;
hepta2ume 0:1682fa22a51e 29 char bt1[8]= {0x00},bt2[8]= {0x00};
hepta2ume 0:1682fa22a51e 30 bt_datas=_bat.read_u16()>>4;
hepta2ume 0:1682fa22a51e 31 sprintf( bt1, "%02X", (bt_datas >> 8) & 0x0F);
hepta2ume 0:1682fa22a51e 32 sprintf( bt2, "%02X", (bt_datas) & 0xFF);
hepta2ume 0:1682fa22a51e 33 bt_u16[0]=bt1[0];
hepta2ume 0:1682fa22a51e 34 bt_u16[1]=bt1[1];
hepta2ume 0:1682fa22a51e 35 bt_u16[2]=bt2[0];
hepta2ume 0:1682fa22a51e 36 bt_u16[3]=bt2[1];
HEPTA 5:15a6a4425889 37 //*dsize = 4;
hepta2ume 0:1682fa22a51e 38 }
hepta2ume 0:1682fa22a51e 39
HEPTA 9:7d0aaedfe1c0 40 void HeptaBattery::power_saving_mode(int *flag,float* Bat)
hepta2ume 0:1682fa22a51e 41 {
HEPTA 9:7d0aaedfe1c0 42 *Bat = _bat.read()*1.431*3.3;
HEPTA 9:7d0aaedfe1c0 43 //Above 4.2 or more
HEPTA 9:7d0aaedfe1c0 44 if(*Bat>=4.2) {
umeume 3:16fd450bcf16 45 _bat_ct = 1;
HeptaSatTraining2019 10:00fc48db2361 46 //LPC_SC->CCLKCFG = 2;
HeptaSatTraining2019 10:00fc48db2361 47 //SystemCoreClockUpdate();
HEPTA 9:7d0aaedfe1c0 48 *flag = 0;
HEPTA 4:65dc53760aa0 49 }
hepta2ume 0:1682fa22a51e 50 //3.7 < Voltage < 4.1
HEPTA 9:7d0aaedfe1c0 51 else if(*Bat<=4.1 && *Bat>=3.7) {
hepta2ume 0:1682fa22a51e 52 _bat_ct = 1;
HeptaSatTraining2019 10:00fc48db2361 53 //LPC_SC->CCLKCFG = 2;
HeptaSatTraining2019 10:00fc48db2361 54 //SystemCoreClockUpdate();
HEPTA 9:7d0aaedfe1c0 55 *flag = 0;
hepta2ume 0:1682fa22a51e 56 }
HEPTA 9:7d0aaedfe1c0 57 //3.5V or less
HEPTA 9:7d0aaedfe1c0 58 else if(*Bat<=3.5) {
HEPTA 4:65dc53760aa0 59 _bat_ct = 0;
HeptaSatTraining2019 10:00fc48db2361 60 //LPC_SC->CCLKCFG = 5;
HeptaSatTraining2019 10:00fc48db2361 61 //SystemCoreClockUpdate();
HEPTA 9:7d0aaedfe1c0 62 *flag = 1;
hepta2ume 0:1682fa22a51e 63 }
hepta2ume 0:1682fa22a51e 64
hepta2ume 0:1682fa22a51e 65 }