hs loovee
/
ARCH_GPRS_Demo
seeedstudio ARCH GPRS Demo. post data to yeelink.
Embed:
(wiki syntax)
Show/hide line numbers
ARCH_GPRS_HW.cpp
00001 /* 00002 IOT_hw.cpp 00003 2013 Copyright (c) Seeed Technology Inc. All right reserved. 00004 00005 Author:Loovee 00006 2013-7-21 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #include "mbed.h" 00024 #include "tcp_yeelink.h" 00025 #include "tcp_yeelink_dfs.h" 00026 #include "ARCH_GPRS_HW.h" 00027 #include "ARCH_GPRS_HW_DFS.h" 00028 00029 DigitalOut eg10_pwr(PINPWR); 00030 DigitalOut eg10_on(PINONOFF); 00031 DigitalInOut eg10_state(PINEGSTATE); 00032 DigitalOut eg10_rst(PINSYSRST); 00033 00034 DigitalOut led1(PINLED1); 00035 DigitalOut led2(PINLED2); 00036 DigitalOut led3(PINLED3); 00037 DigitalOut led4(PINLED4); 00038 00039 DigitalOut grove_pwr(GROVE_PWR); 00040 DigitalIn charging(PIN_CHRGING); 00041 DigitalIn chargdone(PIN_CHRGDONE); 00042 00043 AnalogIn vol_bat(PIN_READBAT); 00044 00045 void IOT_HW::EG10_PWRON() 00046 { 00047 eg10_pwr = 0; 00048 } 00049 00050 void IOT_HW::EG10_PWROFF() 00051 { 00052 eg10_pwr = 1; 00053 } 00054 00055 void IOT_HW::EG10_ON() 00056 { 00057 eg10_on = 0; 00058 wait(2); 00059 eg10_on = 1; 00060 } 00061 00062 int IOT_HW::init() 00063 { 00064 init_io(); 00065 EG10_PWROFF(); 00066 wait(2); // wait 2s 00067 EG10_PWRON(); 00068 EG10_PWRON(); 00069 EG10_ON(); 00070 return (IOT.waitString("M2MRSSI", 30)); 00071 } 00072 00073 void IOT_HW::init_io() 00074 { 00075 eg10_pwr = 1; 00076 eg10_on = 1; 00077 } 00078 00079 int IOT_HW::getEG10_State() 00080 { 00081 eg10_state.input(); 00082 eg10_state.mode(PullDown); 00083 if(eg10_state.read()) 00084 { 00085 return 1; 00086 } 00087 return 0; 00088 } 00089 00090 void IOT_HW::EG10StateLed(unsigned char state) 00091 { 00092 eg10_state.output(); 00093 eg10_state = 1-state; 00094 } 00095 00096 void IOT_HW::userLed(unsigned char led, unsigned char state) 00097 { 00098 // if(state!=0 || state!=1)return; 00099 00100 if(1==led)led1 = state; 00101 else if(2==led)led2 = state; 00102 else if(3==led)led3 = state; 00103 else if(4==led)led4 = state; 00104 00105 } 00106 00107 int IOT_HW::readChrgState() 00108 { 00109 if(!charging.read())return CHRGDONE; 00110 if(!chargdone.read())return CHRGING; 00111 return NOCHRG; 00112 } 00113 00114 float IOT_HW::readBatVol() 00115 { 00116 unsigned int tmp = vol_bat.read_u16(); 00117 00118 return tmp; 00119 float dr = tmp; 00120 dr = dr/65536.0*3.3*2.0; 00121 return dr; 00122 // return ((float tmp)/65536.0*3.3*2.0); 00123 } 00124 00125 void IOT_HW::grovePwrOn() 00126 { 00127 grove_pwr = 0; 00128 } 00129 00130 void IOT_HW::grovePwrOff() 00131 { 00132 grove_pwr = 1; 00133 } 00134 00135 00136 IOT_HW iot_hw; 00137 /********************************************************************************************************* 00138 END FILE 00139 *********************************************************************************************************/
Generated on Wed Jul 13 2022 08:54:57 by 1.7.2