Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: roam_v2 finalV1 finalV1 finalv2 ... more
Revision 0:d3d48514a2aa, committed 2014-12-02
- Comitter:
- labishrestha
- Date:
- Tue Dec 02 07:28:27 2014 +0000
- Commit message:
- Arch GPRS V2 HW library created from Arch GPRS HW Demo
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ARCH_GPRS_V2_HW.cpp Tue Dec 02 07:28:27 2014 +0000
@@ -0,0 +1,146 @@
+/*
+ IOT_hw.cpp
+ 2013 Copyright (c) Seeed Technology Inc. All right reserved.
+
+ Author:Loovee
+ 2013-7-21
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "mbed.h"
+#include "ARCH_GPRS_V2_HW.h"
+#include "ARCH_GPRS_V2_HW_DFS.h"
+
+DigitalOut sim900_pwr(PINPWR);
+DigitalOut sim900_on(PINONOFF);
+
+DigitalOut led1(PINLED1);
+DigitalOut led2(PINLED2);
+DigitalOut led3(PINLED3);
+DigitalOut led4(PINLED4);
+
+DigitalOut grove_pwr(GROVE_PWR);
+DigitalIn charging(PIN_CHRGING);
+DigitalIn chargdone(PIN_CHRGDONE);
+
+Serial sim900uart(PINTX, PINRX, "SIM900");
+
+AnalogIn vol_bat(PIN_READBAT);
+
+void IOT_HW::SIM900_PWRON()
+{
+ sim900_pwr = 0;
+}
+
+void IOT_HW::SIM900_PWROFF()
+{
+ sim900_pwr = 1;
+}
+
+void IOT_HW::SIM900_ON()
+{
+ sim900_on = 0;
+ wait(2);
+ sim900_on = 1;
+}
+
+int IOT_HW::init()
+{
+ init_io();
+ SIM900_PWROFF();
+ wait(2); // wait 2s
+ SIM900_PWRON();
+ SIM900_PWRON();
+ SIM900_ON();
+ return 1;
+}
+
+void IOT_HW::init_io()
+{
+ sim900_pwr = 1;
+ sim900_on = 1;
+}
+
+void IOT_HW::sendCommand(char * command)
+{
+ sim900uart.printf(command);
+}
+
+void IOT_HW::hangup()
+{
+ sim900uart.printf("ATH;");
+}
+
+//int IOT_HW::getSIM900_State()
+//{
+// sim900_state.input();
+// sim900_state.mode(PullDown);
+// if(sim900_state.read())
+// {
+// return 1;
+// }
+// return 0;
+//}
+
+void IOT_HW::SIM900StateLed(unsigned char state)
+{
+ //sim900_state.output();
+ //sim900_state = 1-state;
+}
+
+void IOT_HW::userLed(unsigned char led, unsigned char state)
+{
+ // if(state!=0 || state!=1)return;
+
+ if(1==led)led1 = state;
+ else if(2==led)led2 = state;
+ else if(3==led)led3 = state;
+ else if(4==led)led4 = state;
+
+}
+
+int IOT_HW::readChrgState()
+{
+ if(!charging.read())return CHRGDONE;
+ if(!chargdone.read())return CHRGING;
+ return NOCHRG;
+}
+
+float IOT_HW::readBatVol()
+{
+ unsigned int tmp = vol_bat.read_u16();
+
+ //return tmp;
+ float dr = tmp;
+ dr = dr/65536.0*3.3*2.0;
+ return dr;
+ // return ((float tmp)/65536.0*3.3*2.0);
+}
+
+void IOT_HW::grovePwrOn()
+{
+ grove_pwr = 0;
+}
+
+void IOT_HW::grovePwrOff()
+{
+ grove_pwr = 1;
+}
+
+IOT_HW iot_hw;
+/*********************************************************************************************************
+ END FILE
+*********************************************************************************************************/
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ARCH_GPRS_V2_HW.h Tue Dec 02 07:28:27 2014 +0000
@@ -0,0 +1,57 @@
+/*
+ IOT_hw.h
+ 2013 Copyright (c) Seeed Technology Inc. All right reserved.
+
+ Author:Loovee
+ 2013-7-21
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef __ARCH_GPRS_V2_HW_H__
+#define __ARCH_GPRS_V2_HW_H__
+
+#include "ARCH_GPRS_V2_HW_DFS.h"
+
+class IOT_HW{
+
+private:
+
+public:
+ int init(); // init all
+ void init_io(); // init io
+ void SIM900_PWRON(); // power on sim900
+ void SIM900_PWROFF(); // power off sim900, cut the power
+ void SIM900_ON(); // turn on sim900
+ void SIM900_OFF(); // turn off sim900
+ void SIM900StateLed(unsigned char state); // control led
+
+ void sendCommand(char * number);
+ void hangup();
+
+ int readChrgState();
+ float readBatVol();
+ void userLed(unsigned char led, unsigned char state);
+ void grovePwrOn();
+ void grovePwrOff();
+};
+
+extern IOT_HW iot_hw;
+
+#endif
+
+/*********************************************************************************************************
+ END FILE
+*********************************************************************************************************/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ARCH_GPRS_V2_HW_DFS.h Tue Dec 02 07:28:27 2014 +0000 @@ -0,0 +1,64 @@ +/* + IOT_hw_dfs.h + 2013 Copyright (c) Seeed Technology Inc. All right reserved. + + Author:Loovee + 2013-7-21 + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef __ARCH_GPRS_V2_HW_DFS_H__ +#define __ARCH_GPRS_V2_HW_DFS_H__ + +// pin define +#define PINPWR P1_2 // SIM900 power supply switch, low enable +#define PINONOFF P1_7 // SIM900 power On/Off switch, low enable, low for 2s to turn on SIM900 +#define PINTX P1_27 // SIM900 TX +#define PINRX P1_26 // SIM900 RX + +// grove pin +#define GROVE_I2C_SCL P0_4 // grove i2c pin +#define GROVE_I2C_SDA P0_5 // grove i2c sda + +#define GROVE_UART_RX P0_14 // grove uart rx +#define GROVE_UART_TX P0_13 // grove uart tx + +#define GROVE_ADC_1 P0_12 // grove ADC, the outside one +#define GROVE_ADC_2 P0_11 // grove ADC, the other one + +#define GROVE_PWR P1_3 // control all grove power, low enable + +// charge circuit +#define PIN_CHRGING P1_1 // charging, low enable +#define PIN_CHRGDONE P1_0 // charge done +#define PIN_READBAT P0_23 // battery voltage in, the value should x2 + +// led pin +#define PINLED1 P1_8 +#define PINLED2 P1_9 +#define PINLED3 P1_10 +#define PINLED4 P1_11 + +// charge state +#define CHRGING 1 +#define CHRGDONE 2 +#define NOCHRG 3 + +#endif + +/********************************************************************************************************* + END FILE +*********************************************************************************************************/