Arch GPRS V2 HW Library Created from the Arch GPRS HW DEMO
Dependents: roam_v2 finalV1 finalV1 finalv2 ... more
ARCH_GPRS_V2_HW.cpp@0:d3d48514a2aa, 2014-12-02 (annotated)
- Committer:
- labishrestha
- Date:
- Tue Dec 02 07:28:27 2014 +0000
- Revision:
- 0:d3d48514a2aa
Arch GPRS V2 HW library created from Arch GPRS HW Demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
labishrestha | 0:d3d48514a2aa | 1 | /* |
labishrestha | 0:d3d48514a2aa | 2 | IOT_hw.cpp |
labishrestha | 0:d3d48514a2aa | 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. |
labishrestha | 0:d3d48514a2aa | 4 | |
labishrestha | 0:d3d48514a2aa | 5 | Author:Loovee |
labishrestha | 0:d3d48514a2aa | 6 | 2013-7-21 |
labishrestha | 0:d3d48514a2aa | 7 | |
labishrestha | 0:d3d48514a2aa | 8 | This library is free software; you can redistribute it and/or |
labishrestha | 0:d3d48514a2aa | 9 | modify it under the terms of the GNU Lesser General Public |
labishrestha | 0:d3d48514a2aa | 10 | License as published by the Free Software Foundation; either |
labishrestha | 0:d3d48514a2aa | 11 | version 2.1 of the License, or (at your option) any later version. |
labishrestha | 0:d3d48514a2aa | 12 | |
labishrestha | 0:d3d48514a2aa | 13 | This library is distributed in the hope that it will be useful, |
labishrestha | 0:d3d48514a2aa | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
labishrestha | 0:d3d48514a2aa | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
labishrestha | 0:d3d48514a2aa | 16 | Lesser General Public License for more details. |
labishrestha | 0:d3d48514a2aa | 17 | |
labishrestha | 0:d3d48514a2aa | 18 | You should have received a copy of the GNU Lesser General Public |
labishrestha | 0:d3d48514a2aa | 19 | License along with this library; if not, write to the Free Software |
labishrestha | 0:d3d48514a2aa | 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
labishrestha | 0:d3d48514a2aa | 21 | */ |
labishrestha | 0:d3d48514a2aa | 22 | |
labishrestha | 0:d3d48514a2aa | 23 | #include "mbed.h" |
labishrestha | 0:d3d48514a2aa | 24 | #include "ARCH_GPRS_V2_HW.h" |
labishrestha | 0:d3d48514a2aa | 25 | #include "ARCH_GPRS_V2_HW_DFS.h" |
labishrestha | 0:d3d48514a2aa | 26 | |
labishrestha | 0:d3d48514a2aa | 27 | DigitalOut sim900_pwr(PINPWR); |
labishrestha | 0:d3d48514a2aa | 28 | DigitalOut sim900_on(PINONOFF); |
labishrestha | 0:d3d48514a2aa | 29 | |
labishrestha | 0:d3d48514a2aa | 30 | DigitalOut led1(PINLED1); |
labishrestha | 0:d3d48514a2aa | 31 | DigitalOut led2(PINLED2); |
labishrestha | 0:d3d48514a2aa | 32 | DigitalOut led3(PINLED3); |
labishrestha | 0:d3d48514a2aa | 33 | DigitalOut led4(PINLED4); |
labishrestha | 0:d3d48514a2aa | 34 | |
labishrestha | 0:d3d48514a2aa | 35 | DigitalOut grove_pwr(GROVE_PWR); |
labishrestha | 0:d3d48514a2aa | 36 | DigitalIn charging(PIN_CHRGING); |
labishrestha | 0:d3d48514a2aa | 37 | DigitalIn chargdone(PIN_CHRGDONE); |
labishrestha | 0:d3d48514a2aa | 38 | |
labishrestha | 0:d3d48514a2aa | 39 | Serial sim900uart(PINTX, PINRX, "SIM900"); |
labishrestha | 0:d3d48514a2aa | 40 | |
labishrestha | 0:d3d48514a2aa | 41 | AnalogIn vol_bat(PIN_READBAT); |
labishrestha | 0:d3d48514a2aa | 42 | |
labishrestha | 0:d3d48514a2aa | 43 | void IOT_HW::SIM900_PWRON() |
labishrestha | 0:d3d48514a2aa | 44 | { |
labishrestha | 0:d3d48514a2aa | 45 | sim900_pwr = 0; |
labishrestha | 0:d3d48514a2aa | 46 | } |
labishrestha | 0:d3d48514a2aa | 47 | |
labishrestha | 0:d3d48514a2aa | 48 | void IOT_HW::SIM900_PWROFF() |
labishrestha | 0:d3d48514a2aa | 49 | { |
labishrestha | 0:d3d48514a2aa | 50 | sim900_pwr = 1; |
labishrestha | 0:d3d48514a2aa | 51 | } |
labishrestha | 0:d3d48514a2aa | 52 | |
labishrestha | 0:d3d48514a2aa | 53 | void IOT_HW::SIM900_ON() |
labishrestha | 0:d3d48514a2aa | 54 | { |
labishrestha | 0:d3d48514a2aa | 55 | sim900_on = 0; |
labishrestha | 0:d3d48514a2aa | 56 | wait(2); |
labishrestha | 0:d3d48514a2aa | 57 | sim900_on = 1; |
labishrestha | 0:d3d48514a2aa | 58 | } |
labishrestha | 0:d3d48514a2aa | 59 | |
labishrestha | 0:d3d48514a2aa | 60 | int IOT_HW::init() |
labishrestha | 0:d3d48514a2aa | 61 | { |
labishrestha | 0:d3d48514a2aa | 62 | init_io(); |
labishrestha | 0:d3d48514a2aa | 63 | SIM900_PWROFF(); |
labishrestha | 0:d3d48514a2aa | 64 | wait(2); // wait 2s |
labishrestha | 0:d3d48514a2aa | 65 | SIM900_PWRON(); |
labishrestha | 0:d3d48514a2aa | 66 | SIM900_PWRON(); |
labishrestha | 0:d3d48514a2aa | 67 | SIM900_ON(); |
labishrestha | 0:d3d48514a2aa | 68 | return 1; |
labishrestha | 0:d3d48514a2aa | 69 | } |
labishrestha | 0:d3d48514a2aa | 70 | |
labishrestha | 0:d3d48514a2aa | 71 | void IOT_HW::init_io() |
labishrestha | 0:d3d48514a2aa | 72 | { |
labishrestha | 0:d3d48514a2aa | 73 | sim900_pwr = 1; |
labishrestha | 0:d3d48514a2aa | 74 | sim900_on = 1; |
labishrestha | 0:d3d48514a2aa | 75 | } |
labishrestha | 0:d3d48514a2aa | 76 | |
labishrestha | 0:d3d48514a2aa | 77 | void IOT_HW::sendCommand(char * command) |
labishrestha | 0:d3d48514a2aa | 78 | { |
labishrestha | 0:d3d48514a2aa | 79 | sim900uart.printf(command); |
labishrestha | 0:d3d48514a2aa | 80 | } |
labishrestha | 0:d3d48514a2aa | 81 | |
labishrestha | 0:d3d48514a2aa | 82 | void IOT_HW::hangup() |
labishrestha | 0:d3d48514a2aa | 83 | { |
labishrestha | 0:d3d48514a2aa | 84 | sim900uart.printf("ATH;"); |
labishrestha | 0:d3d48514a2aa | 85 | } |
labishrestha | 0:d3d48514a2aa | 86 | |
labishrestha | 0:d3d48514a2aa | 87 | //int IOT_HW::getSIM900_State() |
labishrestha | 0:d3d48514a2aa | 88 | //{ |
labishrestha | 0:d3d48514a2aa | 89 | // sim900_state.input(); |
labishrestha | 0:d3d48514a2aa | 90 | // sim900_state.mode(PullDown); |
labishrestha | 0:d3d48514a2aa | 91 | // if(sim900_state.read()) |
labishrestha | 0:d3d48514a2aa | 92 | // { |
labishrestha | 0:d3d48514a2aa | 93 | // return 1; |
labishrestha | 0:d3d48514a2aa | 94 | // } |
labishrestha | 0:d3d48514a2aa | 95 | // return 0; |
labishrestha | 0:d3d48514a2aa | 96 | //} |
labishrestha | 0:d3d48514a2aa | 97 | |
labishrestha | 0:d3d48514a2aa | 98 | void IOT_HW::SIM900StateLed(unsigned char state) |
labishrestha | 0:d3d48514a2aa | 99 | { |
labishrestha | 0:d3d48514a2aa | 100 | //sim900_state.output(); |
labishrestha | 0:d3d48514a2aa | 101 | //sim900_state = 1-state; |
labishrestha | 0:d3d48514a2aa | 102 | } |
labishrestha | 0:d3d48514a2aa | 103 | |
labishrestha | 0:d3d48514a2aa | 104 | void IOT_HW::userLed(unsigned char led, unsigned char state) |
labishrestha | 0:d3d48514a2aa | 105 | { |
labishrestha | 0:d3d48514a2aa | 106 | // if(state!=0 || state!=1)return; |
labishrestha | 0:d3d48514a2aa | 107 | |
labishrestha | 0:d3d48514a2aa | 108 | if(1==led)led1 = state; |
labishrestha | 0:d3d48514a2aa | 109 | else if(2==led)led2 = state; |
labishrestha | 0:d3d48514a2aa | 110 | else if(3==led)led3 = state; |
labishrestha | 0:d3d48514a2aa | 111 | else if(4==led)led4 = state; |
labishrestha | 0:d3d48514a2aa | 112 | |
labishrestha | 0:d3d48514a2aa | 113 | } |
labishrestha | 0:d3d48514a2aa | 114 | |
labishrestha | 0:d3d48514a2aa | 115 | int IOT_HW::readChrgState() |
labishrestha | 0:d3d48514a2aa | 116 | { |
labishrestha | 0:d3d48514a2aa | 117 | if(!charging.read())return CHRGDONE; |
labishrestha | 0:d3d48514a2aa | 118 | if(!chargdone.read())return CHRGING; |
labishrestha | 0:d3d48514a2aa | 119 | return NOCHRG; |
labishrestha | 0:d3d48514a2aa | 120 | } |
labishrestha | 0:d3d48514a2aa | 121 | |
labishrestha | 0:d3d48514a2aa | 122 | float IOT_HW::readBatVol() |
labishrestha | 0:d3d48514a2aa | 123 | { |
labishrestha | 0:d3d48514a2aa | 124 | unsigned int tmp = vol_bat.read_u16(); |
labishrestha | 0:d3d48514a2aa | 125 | |
labishrestha | 0:d3d48514a2aa | 126 | //return tmp; |
labishrestha | 0:d3d48514a2aa | 127 | float dr = tmp; |
labishrestha | 0:d3d48514a2aa | 128 | dr = dr/65536.0*3.3*2.0; |
labishrestha | 0:d3d48514a2aa | 129 | return dr; |
labishrestha | 0:d3d48514a2aa | 130 | // return ((float tmp)/65536.0*3.3*2.0); |
labishrestha | 0:d3d48514a2aa | 131 | } |
labishrestha | 0:d3d48514a2aa | 132 | |
labishrestha | 0:d3d48514a2aa | 133 | void IOT_HW::grovePwrOn() |
labishrestha | 0:d3d48514a2aa | 134 | { |
labishrestha | 0:d3d48514a2aa | 135 | grove_pwr = 0; |
labishrestha | 0:d3d48514a2aa | 136 | } |
labishrestha | 0:d3d48514a2aa | 137 | |
labishrestha | 0:d3d48514a2aa | 138 | void IOT_HW::grovePwrOff() |
labishrestha | 0:d3d48514a2aa | 139 | { |
labishrestha | 0:d3d48514a2aa | 140 | grove_pwr = 1; |
labishrestha | 0:d3d48514a2aa | 141 | } |
labishrestha | 0:d3d48514a2aa | 142 | |
labishrestha | 0:d3d48514a2aa | 143 | IOT_HW iot_hw; |
labishrestha | 0:d3d48514a2aa | 144 | /********************************************************************************************************* |
labishrestha | 0:d3d48514a2aa | 145 | END FILE |
labishrestha | 0:d3d48514a2aa | 146 | *********************************************************************************************************/ |