Xbee CountUp

Dependencies:   mbed

Fork of HeptaXbee_CountUp by 智也 大野

Committer:
tomoya123
Date:
Fri Dec 09 04:58:00 2016 +0000
Revision:
0:0a7fa0911e6c
Xbee CountUP

Who changed what in which revision?

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