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