Battery hex
Dependencies: mbed PowerControl SDFileSystem
Fork of HeptaBattery_hex by
hepta_sat/HeptaBattery.cpp@2:7c5919465fc8, 2016-12-13 (annotated)
- Committer:
- MEXT1
- Date:
- Tue Dec 13 10:50:09 2016 +0000
- Revision:
- 2:7c5919465fc8
- Parent:
- 0:30e193b92735
Battery hex
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tomoya123 | 0:30e193b92735 | 1 | #include "HeptaBattery.h" |
tomoya123 | 0:30e193b92735 | 2 | #include "mbed.h" |
tomoya123 | 0:30e193b92735 | 3 | |
tomoya123 | 0:30e193b92735 | 4 | HeptaBattery::HeptaBattery(PinName bat, PinName bat_ct, PinName reg_st) : _bat(bat),_bat_ct(bat_ct),_reg_st(reg_st) |
tomoya123 | 0:30e193b92735 | 5 | { |
tomoya123 | 0:30e193b92735 | 6 | _bat_ct = 0; // disable battery charge |
tomoya123 | 0:30e193b92735 | 7 | _reg_st = 1; // able 3.3V regulator out |
tomoya123 | 0:30e193b92735 | 8 | PHY_PowerDown();// disable Ethernet connection |
tomoya123 | 0:30e193b92735 | 9 | } |
tomoya123 | 0:30e193b92735 | 10 | void HeptaBattery::vol(float* bt) |
tomoya123 | 0:30e193b92735 | 11 | { |
tomoya123 | 0:30e193b92735 | 12 | *bt = (_bat.read()*1.431*3.3); |
tomoya123 | 0:30e193b92735 | 13 | } |
MEXT1 | 2:7c5919465fc8 | 14 | void HeptaBattery::vol_u16(char* bt_u16) |
tomoya123 | 0:30e193b92735 | 15 | { |
tomoya123 | 0:30e193b92735 | 16 | unsigned short bt_datas; |
tomoya123 | 0:30e193b92735 | 17 | char bt1[8]={0x00},bt2[8]={0x00}; |
tomoya123 | 0:30e193b92735 | 18 | bt_datas=_bat.read_u16()>>4; |
tomoya123 | 0:30e193b92735 | 19 | sprintf( bt1, "%02X", (bt_datas >> 8) & 0x0F); |
tomoya123 | 0:30e193b92735 | 20 | sprintf( bt2, "%02X", (bt_datas) & 0xFF); |
tomoya123 | 0:30e193b92735 | 21 | bt_u16[0]=bt1[0]; bt_u16[1]=bt1[1]; |
tomoya123 | 0:30e193b92735 | 22 | bt_u16[2]=bt2[0]; bt_u16[3]=bt2[1]; |
tomoya123 | 0:30e193b92735 | 23 | } |
tomoya123 | 0:30e193b92735 | 24 | void HeptaBattery::chargecontrol(int state, int *save_flag) |
tomoya123 | 0:30e193b92735 | 25 | { |
tomoya123 | 0:30e193b92735 | 26 | float Bat; |
tomoya123 | 0:30e193b92735 | 27 | switch(state){ |
tomoya123 | 0:30e193b92735 | 28 | case 1: |
tomoya123 | 0:30e193b92735 | 29 | //Battery Voltage High Level |
tomoya123 | 0:30e193b92735 | 30 | Peripheral_PowerUp(0xFDFF6FF7); |
tomoya123 | 0:30e193b92735 | 31 | _bat_ct = 0; |
tomoya123 | 0:30e193b92735 | 32 | _reg_st = 1; |
tomoya123 | 0:30e193b92735 | 33 | *save_flag = 0; |
tomoya123 | 0:30e193b92735 | 34 | break; |
tomoya123 | 0:30e193b92735 | 35 | case 2: |
tomoya123 | 0:30e193b92735 | 36 | //Battery Voltage Normal Level |
tomoya123 | 0:30e193b92735 | 37 | Peripheral_PowerUp(0xFDFF6FF7); |
tomoya123 | 0:30e193b92735 | 38 | _reg_st = 1; |
tomoya123 | 0:30e193b92735 | 39 | _bat_ct = 1; |
tomoya123 | 0:30e193b92735 | 40 | *save_flag = 0; |
tomoya123 | 0:30e193b92735 | 41 | break; |
tomoya123 | 0:30e193b92735 | 42 | case 3: |
tomoya123 | 0:30e193b92735 | 43 | //Battery Voltage Low Level |
tomoya123 | 0:30e193b92735 | 44 | Peripheral_PowerDown(0x7D7E6DF1); |
tomoya123 | 0:30e193b92735 | 45 | _bat_ct = 1; |
tomoya123 | 0:30e193b92735 | 46 | _reg_st = 0; |
tomoya123 | 0:30e193b92735 | 47 | *save_flag = 1; |
tomoya123 | 0:30e193b92735 | 48 | break; |
tomoya123 | 0:30e193b92735 | 49 | case 4: |
tomoya123 | 0:30e193b92735 | 50 | //Battery Voltage Auto Charge |
tomoya123 | 0:30e193b92735 | 51 | Bat = _bat.read()*1.431*3.3; |
tomoya123 | 0:30e193b92735 | 52 | if(Bat>=4.2){ |
tomoya123 | 0:30e193b92735 | 53 | Peripheral_PowerUp(0xFDFF6FF7); |
tomoya123 | 0:30e193b92735 | 54 | printf("voltage high level = %f\r\n",Bat); |
tomoya123 | 0:30e193b92735 | 55 | printf("Complete!!!"); |
tomoya123 | 0:30e193b92735 | 56 | _bat_ct = 0; |
tomoya123 | 0:30e193b92735 | 57 | _reg_st = 1; |
tomoya123 | 0:30e193b92735 | 58 | *save_flag = 0; |
tomoya123 | 0:30e193b92735 | 59 | } |
tomoya123 | 0:30e193b92735 | 60 | Peripheral_PowerDown(0x7D7E6DF1); |
tomoya123 | 0:30e193b92735 | 61 | printf("voltage low level = %f\r\n",Bat); |
tomoya123 | 0:30e193b92735 | 62 | _bat_ct = 1; |
tomoya123 | 0:30e193b92735 | 63 | _reg_st = 0; |
tomoya123 | 0:30e193b92735 | 64 | *save_flag = 1; |
tomoya123 | 0:30e193b92735 | 65 | break; |
tomoya123 | 0:30e193b92735 | 66 | default: |
tomoya123 | 0:30e193b92735 | 67 | printf("error\r\n"); |
tomoya123 | 0:30e193b92735 | 68 | break; |
tomoya123 | 0:30e193b92735 | 69 | } |
tomoya123 | 0:30e193b92735 | 70 | } |
tomoya123 | 0:30e193b92735 | 71 |