Accel

Dependencies:   mbed PowerControl SDFileSystem

Fork of HeptaAccel by 智也 大野

Committer:
tomoya123
Date:
Tue Dec 13 07:51:40 2016 +0000
Revision:
1:63c3921c608c
Parent:
0:d721efd58e4e
Accel

Who changed what in which revision?

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