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.
Dependencies: ADXL345_I2C MMA8652FC Sht31 TinyGPS mbed Chainable_RGB_LED
Fork of ina-hack-test by
Diff: EEAB-P1/Eeabp1.cpp
- Revision:
- 1:195da8230785
- Parent:
- 0:97a57be77fbb
- Child:
- 6:ae7b9f0a13f7
diff -r 97a57be77fbb -r 195da8230785 EEAB-P1/Eeabp1.cpp
--- a/EEAB-P1/Eeabp1.cpp Sat Jun 24 03:45:00 2017 +0000
+++ b/EEAB-P1/Eeabp1.cpp Sat Jun 24 23:42:01 2017 +0000
@@ -4,7 +4,11 @@
//Thread thread;
static const int lora_msg_max_len = 11;
-Eeabp1::Eeabp1() : pwr_en(P0_0), led(P0_23), lora_reset(P0_22), lora_power(P0_5), grove_power(P0_6)
+Eeabp1::Eeabp1() : pwr_en(P0_0), led(P0_23),
+ lora_power(P0_5), lora_reset(P0_22), grove_power(P0_6),
+ grv_sel2a(P0_19), grv_sel2g(P0_18), grv_sel1a(P0_17), grv_sel1g(P0_16),
+ grv_p1s1a(P0_2), grv_p1s2a(P0_1),
+ grv_p2s1a(P0_4), grv_p2s2a(P0_3)
{
this->led_state = LED_OFF;
this->led = 0;
@@ -16,6 +20,14 @@
this->grove_power = 0;
this->lora_enabled = false;
this->grove_enabled = false;
+ // Grove端子をHiZに
+ this->grv_sel1g = 1;
+ this->grv_sel1a = 1;
+ this->grv_sel2g = 1;
+ this->grv_sel2a = 1;
+ grv_p1s1do = NULL, grv_p1s2do = NULL, grv_p1s1di = NULL, grv_p1s2di = NULL;
+ grv_p2s1do = NULL, grv_p2s2do = NULL, grv_p2s1di = NULL, grv_p2s2di = NULL;
+ temp_humid_sensor = NULL;
}
int Eeabp1::setLedState(EeabLedState state)
@@ -79,6 +91,12 @@
serial->printf("mod set_echo off\r\n"); // ローカルエコー:無効
wait(1);
flushSerial();
+ serial->printf("mod factory_reset\r\n"); // ファクトリーリセットを行い鍵をリフレッシュ
+ ret = chkSerialCharOk();
+ if (ret != 0)
+ return ret;
+ serial->printf("mod set_echo off\r\n"); // ローカルエコー:無効
+ wait(1);
serial->printf("lorawan join otaa\r\n"); // Gatewayに接続(OTAA)
ret = chkSerialCharRes('a'); // 成功 ">> accepted" 失敗 ">> unsuccess"
if (ret != 0)
@@ -119,7 +137,6 @@
flushSerial();
serial->puts(msg);
- //serial->printf("lorawan tx ucnf 16 74657374\r\n");
return 0;
}
@@ -135,10 +152,239 @@
if (!grove_enabled)
return; /* power is already off, do nothing */
+ // Grove端子をHiZに
+ grv_sel1g = 1;
+ grv_sel1a = 1;
+ grv_sel2g = 1;
+ grv_sel2a = 1;
grove_power = 0;
}
}
+int Eeabp1::setGrovePortType(EeabGrovePort port, EeabGrovePortType type)
+{
+ switch (port) {
+ case GROVE_CH1:
+ if (type == GROVE_ANALOG) {
+ grv_sel1g = 1;
+ grv_sel1a = 0;
+ } else {
+ grv_sel1g = 0;
+ grv_sel1a = 1;
+ }
+ break;
+ case GROVE_CH2:
+ if (type == GROVE_ANALOG) {
+ grv_sel2g = 1;
+ grv_sel2a = 0;
+ } else {
+ grv_sel2g = 0;
+ grv_sel2a = 1;
+ }
+ break;
+ default:
+ /* do nothing */
+ break;
+ }
+
+ return 0;
+}
+
+int Eeabp1::setGroveDioDirection(EeabGrovePort port, EeabGroveDioDirection dir, Callback<void()> f)
+{
+ switch (port) {
+ case GROVE_CH1:
+ if(dir == GROVE_DIO_OUT) {
+ if (grv_p1s1di) {
+ delete grv_p1s1di;
+ grv_p1s1di = NULL;
+ }
+ grv_p1s1do = new DigitalOut(P0_13);
+
+ if (grv_p1s2di) {
+ delete grv_p1s2di;
+ grv_p1s2di = NULL;
+ }
+ grv_p1s2do = new DigitalOut(P0_12);
+ } else { /* GROVE_DIO_IN */
+ if (grv_p1s1do) {
+ delete grv_p1s1do;
+ grv_p1s1do = NULL;
+ }
+ grv_p1s1di = new InterruptIn(P0_13);
+ if (f)
+ grv_p1s1di->rise(f);
+
+ if (grv_p1s2do) {
+ delete grv_p1s2do;
+ grv_p1s2do = NULL;
+ }
+ grv_p1s2di = new InterruptIn(P0_12);
+ grv_p1s2di->rise(f);
+ }
+ break;
+ case GROVE_CH2:
+ if(dir == GROVE_DIO_OUT) {
+ if (grv_p2s1di) {
+ delete grv_p2s1di;
+ grv_p2s1di = NULL;
+ }
+ grv_p2s1do = new DigitalOut(P0_15);
+
+ if (grv_p2s2di) {
+ delete grv_p2s2di;
+ grv_p2s2di = NULL;
+ }
+ grv_p2s2do = new DigitalOut(P0_14);
+ } else { /* GROVE_DIO_IN */
+ if (grv_p2s1do) {
+ delete grv_p2s1do;
+ grv_p2s1do = NULL;
+ }
+ grv_p2s1di = new InterruptIn(P0_15);
+ if (f)
+ grv_p2s1di->rise(f);
+
+ if (grv_p2s2do) {
+ delete grv_p2s2do;
+ grv_p2s2do = NULL;
+ }
+ grv_p2s2di = new InterruptIn(P0_14);
+ grv_p2s2di->rise(f);
+ }
+ break;
+ default:
+ /* do nothing */
+ break;
+ }
+
+ return 0;
+}
+
+int Eeabp1::setGroveDio(EeabGrovePort port, EeabGroveDio val)
+{
+ switch (port) {
+ case GROVE_CH1:
+ *grv_p1s1do = val;
+ *grv_p1s2do = val;
+ break;
+ case GROVE_CH2:
+ *grv_p2s1do = val;
+ *grv_p2s2do = val;
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+int Eeabp1::getGroveDio(EeabGrovePort port, EeabGroveSig sig)
+{
+ switch (port) {
+ case GROVE_CH1:
+ if (grv_p1s1di == NULL)
+ return -1;
+ return (sig == GROVE_SIG1) ?
+ grv_p1s1di->read() : grv_p1s2di->read();
+ case GROVE_CH2:
+ if (grv_p2s1di == NULL)
+ return -1;
+ return (sig == GROVE_SIG1) ?
+ grv_p2s1di->read() : grv_p2s2di->read();
+ default:
+ break;
+ }
+
+ return -1;
+}
+
+float Eeabp1::getGroveAnalog(EeabGrovePort port, EeabGroveSig sig)
+{
+ switch (port) {
+ case GROVE_CH1:
+ return (sig == GROVE_SIG1) ?
+ grv_p1s1a.read() : grv_p1s2a.read();
+ case GROVE_CH2:
+ return (sig == GROVE_SIG1) ?
+ grv_p2s1a.read() : grv_p2s2a.read();
+ default:
+ break;
+ }
+
+ return -1;
+}
+
+int Eeabp1::enableTempHumidSensor(void)
+{
+ temp_humid_sensor = new Sht31(P0_30, P0_7);
+ return 0;
+}
+
+float Eeabp1::getTemp(void)
+{
+ if (!temp_humid_sensor)
+ return -1;
+
+ return temp_humid_sensor->readTemperature();
+}
+
+float Eeabp1::getHumid(void)
+{
+ if (!temp_humid_sensor)
+ return -1;
+
+ return temp_humid_sensor->readHumidity();
+}
+
+int Eeabp1::enableAccelerometer(void)
+{
+ accelerometer = new ADXL345_I2C(P0_30, P0_7);
+
+ this->debug("Device ID is: 0x%02x\n", accelerometer->getDeviceID());
+ wait(.001);
+
+ // These are here to test whether any of the initialization fails. It will print the failure
+ if (accelerometer->setPowerControl(0x00)) {
+ this->debug("didn't intitialize power control\n");
+ return -1;
+ }
+ wait(.001);
+
+ //Full resolution, +/-16g, 4mg/LSB.
+ if(accelerometer->setDataFormatControl(0x0B)) {
+ this->debug("didn't set data format\n");
+ return -1;
+ }
+ wait(.001);
+
+ //3.2kHz data rate.
+ if(accelerometer->setDataRate(ADXL345_3200HZ)) {
+ this->debug("didn't set data rate\n");
+ return -1;
+ }
+ wait(.001);
+
+ //Measurement mode.
+ if(accelerometer->setPowerControl(MeasurementMode)) {
+ this->debug("didn't set the power control to measurement\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+int Eeabp1::getAcc(int *x, int *y, int *z)
+{
+ int readings[3] = {0, 0, 0};
+ accelerometer->getOutput(readings);
+ *x = readings[0];
+ *y = readings[1];
+ *z = readings[2];
+
+ return 0;
+}
+
/* private functions */
void Eeabp1::flushSerial()
{
@@ -245,9 +491,9 @@
if (ret != 0)
return __LINE__;
- ret = chkSerialChar(chkchr,2000);
+ ret = waitSerialChar(chkchr,4000);
if (ret != 0)
- return ret * __LINE__;
+ return __LINE__;
ret = waitSerialChar('>',4000);
if (ret != 0)
