Arch GPRS V2 HW Library Created from the Arch GPRS HW DEMO

Dependents:   roam_v2 finalV1 finalV1 finalv2 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ARCH_GPRS_V2_HW.cpp Source File

ARCH_GPRS_V2_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 "ARCH_GPRS_V2_HW.h"
00025 #include "ARCH_GPRS_V2_HW_DFS.h"
00026 
00027 DigitalOut sim900_pwr(PINPWR);
00028 DigitalOut sim900_on(PINONOFF);
00029 
00030 DigitalOut led1(PINLED1);
00031 DigitalOut led2(PINLED2);
00032 DigitalOut led3(PINLED3);
00033 DigitalOut led4(PINLED4);
00034 
00035 DigitalOut grove_pwr(GROVE_PWR);
00036 DigitalIn  charging(PIN_CHRGING);
00037 DigitalIn  chargdone(PIN_CHRGDONE);
00038 
00039 Serial sim900uart(PINTX, PINRX, "SIM900");
00040 
00041 AnalogIn vol_bat(PIN_READBAT);
00042 
00043 void IOT_HW::SIM900_PWRON()
00044 {
00045     sim900_pwr = 0;
00046 }
00047 
00048 void IOT_HW::SIM900_PWROFF()
00049 {
00050     sim900_pwr = 1;
00051 }
00052 
00053 void IOT_HW::SIM900_ON()
00054 {
00055     sim900_on = 0;
00056     wait(2);
00057     sim900_on = 1;
00058 }
00059 
00060 int IOT_HW::init()
00061 {
00062     init_io();
00063     SIM900_PWROFF();
00064     wait(2);                // wait 2s
00065     SIM900_PWRON();
00066     SIM900_PWRON();
00067     SIM900_ON();
00068     return 1;
00069 }
00070 
00071 void IOT_HW::init_io()
00072 {
00073     sim900_pwr = 1;
00074     sim900_on  = 1;
00075 }
00076 
00077 void IOT_HW::sendCommand(char * command)
00078 {
00079     sim900uart.printf(command);
00080 }
00081 
00082 void IOT_HW::hangup()
00083 {
00084     sim900uart.printf("ATH;");
00085 }
00086 
00087 //int IOT_HW::getSIM900_State()
00088 //{
00089 //   sim900_state.input();
00090 //    sim900_state.mode(PullDown);
00091 //    if(sim900_state.read())
00092 //   {
00093 //        return 1;
00094 //    }
00095 //    return 0;
00096 //}
00097 
00098 void IOT_HW::SIM900StateLed(unsigned char state)
00099 {
00100     //sim900_state.output();
00101     //sim900_state = 1-state;
00102 }
00103 
00104 void IOT_HW::userLed(unsigned char led, unsigned char state)
00105 {
00106     //    if(state!=0 || state!=1)return;
00107 
00108     if(1==led)led1 = state;
00109     else if(2==led)led2 = state;
00110     else if(3==led)led3 = state;
00111     else if(4==led)led4 = state;
00112 
00113 }
00114 
00115 int IOT_HW::readChrgState()
00116 {
00117     if(!charging.read())return CHRGDONE;
00118     if(!chargdone.read())return CHRGING;
00119     return NOCHRG;
00120 }
00121 
00122 float IOT_HW::readBatVol()
00123 {
00124     unsigned int tmp = vol_bat.read_u16();
00125     
00126         //return tmp;
00127     float dr = tmp;
00128     dr = dr/65536.0*3.3*2.0;
00129     return dr;
00130     // return ((float tmp)/65536.0*3.3*2.0);
00131 }
00132 
00133 void IOT_HW::grovePwrOn()
00134 {
00135     grove_pwr = 0;
00136 }
00137 
00138 void IOT_HW::grovePwrOff()
00139 {
00140     grove_pwr = 1;
00141 }
00142 
00143 IOT_HW iot_hw;
00144 /*********************************************************************************************************
00145   END FILE
00146 *********************************************************************************************************/