library for enebular edge agent board(version p1)

Dependents:   ina-hack-2nd

Committer:
koyo_take
Date:
Sun Oct 22 03:56:20 2017 +0000
Revision:
3:f80f2838a956
Parent:
2:d48fcae8b5bd
resolve LoRa port number conflit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
koyo_take 0:c6b2a8ace823 1 #if !defined(EEAPP1_H)
koyo_take 0:c6b2a8ace823 2 #define EEAPP1_H
koyo_take 0:c6b2a8ace823 3 #include "mbed.h"
koyo_take 0:c6b2a8ace823 4 #include "types.h"
koyo_take 0:c6b2a8ace823 5 #include "Sht31.h"
koyo_take 0:c6b2a8ace823 6 #include "ADXL345_I2C.h"
koyo_take 0:c6b2a8ace823 7
koyo_take 0:c6b2a8ace823 8 typedef enum {
koyo_take 0:c6b2a8ace823 9 LED_OFF,
koyo_take 0:c6b2a8ace823 10 LED_ON,
koyo_take 0:c6b2a8ace823 11 LED_BLINK_FAST,
koyo_take 0:c6b2a8ace823 12 LED_BLINK_MID,
koyo_take 0:c6b2a8ace823 13 LED_BLINK_SLOW,
koyo_take 0:c6b2a8ace823 14 }EeabLedState;
koyo_take 0:c6b2a8ace823 15
koyo_take 0:c6b2a8ace823 16 typedef enum {
koyo_take 0:c6b2a8ace823 17 GROVE_CH1,
koyo_take 0:c6b2a8ace823 18 GROVE_CH2,
koyo_take 0:c6b2a8ace823 19 }EeabGrovePort;
koyo_take 0:c6b2a8ace823 20
koyo_take 0:c6b2a8ace823 21 typedef enum {
koyo_take 0:c6b2a8ace823 22 GROVE_SIG1,
koyo_take 0:c6b2a8ace823 23 GROVE_SIG2,
koyo_take 0:c6b2a8ace823 24 }EeabGroveSig;
koyo_take 0:c6b2a8ace823 25
koyo_take 0:c6b2a8ace823 26 typedef enum {
koyo_take 0:c6b2a8ace823 27 GROVE_DIO,
koyo_take 0:c6b2a8ace823 28 GROVE_ANALOG,
koyo_take 0:c6b2a8ace823 29 }EeabGrovePortType;
koyo_take 0:c6b2a8ace823 30
koyo_take 0:c6b2a8ace823 31 typedef enum {
koyo_take 0:c6b2a8ace823 32 GROVE_DIO_OUT,
koyo_take 0:c6b2a8ace823 33 GROVE_DIO_IN,
koyo_take 0:c6b2a8ace823 34 }EeabGroveDioDirection;
koyo_take 0:c6b2a8ace823 35
koyo_take 0:c6b2a8ace823 36 typedef enum {
koyo_take 0:c6b2a8ace823 37 GROVE_DIO_LOW = 0,
koyo_take 0:c6b2a8ace823 38 GROVE_DIO_HIGH = 1,
koyo_take 0:c6b2a8ace823 39 }EeabGroveDio;
koyo_take 0:c6b2a8ace823 40
koyo_take 0:c6b2a8ace823 41 class Eeabp1
koyo_take 0:c6b2a8ace823 42 {
koyo_take 0:c6b2a8ace823 43 public:
koyo_take 0:c6b2a8ace823 44 Eeabp1();
koyo_take 0:c6b2a8ace823 45 int setLedState(EeabLedState state);
koyo_take 0:c6b2a8ace823 46 void loop(void);
koyo_take 0:c6b2a8ace823 47 int debug(const char * format, ...);
koyo_take 0:c6b2a8ace823 48 int setLoRaPower(bool on);
koyo_take 0:c6b2a8ace823 49 int sendLoRaString(const char * format, ...);
koyo_take 2:d48fcae8b5bd 50 int sendLoRaStringAndReceiveResponse(char res[], const char * format, ...);
koyo_take 0:c6b2a8ace823 51 int sendLoRaBinary(const char *payload, size_t len);
koyo_take 0:c6b2a8ace823 52 void setGrovePower(bool on);
koyo_take 0:c6b2a8ace823 53 int setGrovePortType(EeabGrovePort port, EeabGrovePortType type);
koyo_take 0:c6b2a8ace823 54 int setGroveDioDirection(EeabGrovePort port, EeabGroveDioDirection dir, Callback<void()> func = NULL);
koyo_take 0:c6b2a8ace823 55 int setGroveDio(EeabGrovePort port, EeabGroveDio val);
koyo_take 0:c6b2a8ace823 56 int setGroveDio(EeabGrovePort port, EeabGroveSig sig , EeabGroveDio val);
koyo_take 0:c6b2a8ace823 57 int getGroveDio(EeabGrovePort port, EeabGroveSig sig);
koyo_take 0:c6b2a8ace823 58 float getGroveAnalog(EeabGrovePort port, EeabGroveSig sig);
koyo_take 0:c6b2a8ace823 59 int enableTempHumidSensor(void);
koyo_take 0:c6b2a8ace823 60 float getTemp(void);
koyo_take 0:c6b2a8ace823 61 float getHumid(void);
koyo_take 0:c6b2a8ace823 62 int enableAccelerometer(void);
koyo_take 0:c6b2a8ace823 63 int getAcc(int *x, int *y, int *z);
koyo_take 0:c6b2a8ace823 64
koyo_take 0:c6b2a8ace823 65 private:
koyo_take 0:c6b2a8ace823 66 DigitalOut pwr_en;
koyo_take 0:c6b2a8ace823 67 /* state LED */
koyo_take 0:c6b2a8ace823 68 DigitalOut led;
koyo_take 0:c6b2a8ace823 69 EeabLedState led_state;
koyo_take 0:c6b2a8ace823 70 /* LoRa */
koyo_take 0:c6b2a8ace823 71 RawSerial *serial;
koyo_take 0:c6b2a8ace823 72 DigitalOut lora_power;
koyo_take 0:c6b2a8ace823 73 DigitalOut lora_reset;
koyo_take 0:c6b2a8ace823 74 bool lora_enabled;
koyo_take 0:c6b2a8ace823 75 /* Grove */
koyo_take 0:c6b2a8ace823 76 DigitalOut grove_power;
koyo_take 0:c6b2a8ace823 77 bool grove_enabled;
koyo_take 0:c6b2a8ace823 78 DigitalOut grv_sel2a;
koyo_take 0:c6b2a8ace823 79 DigitalOut grv_sel2g;
koyo_take 0:c6b2a8ace823 80 DigitalOut grv_sel1a;
koyo_take 0:c6b2a8ace823 81 DigitalOut grv_sel1g;
koyo_take 0:c6b2a8ace823 82
koyo_take 0:c6b2a8ace823 83 DigitalOut *grv_p1s1do; //Port1, Signal1, Digital Out // GP2
koyo_take 0:c6b2a8ace823 84 DigitalOut *grv_p1s2do; //Port1, Signal2, Digital Out // GP1
koyo_take 0:c6b2a8ace823 85 InterruptIn *grv_p1s1di; //Port1, Signal1, Digital In // GP2
koyo_take 0:c6b2a8ace823 86 InterruptIn *grv_p1s2di; //Port1, Signal1, Digital In // GP2
koyo_take 0:c6b2a8ace823 87 AnalogIn grv_p1s1a; //Port1, Signal1, Analog In // AN2
koyo_take 0:c6b2a8ace823 88 AnalogIn grv_p1s2a; //Port1, Signal2, Analog In // AN2
koyo_take 0:c6b2a8ace823 89
koyo_take 0:c6b2a8ace823 90 DigitalOut *grv_p2s1do; //Port2, Signal1, Digital Out // GP4
koyo_take 0:c6b2a8ace823 91 DigitalOut *grv_p2s2do; //Port2, Signal2, Digital Out // GP3
koyo_take 0:c6b2a8ace823 92 InterruptIn *grv_p2s1di; //Port2, Signal1, Digital In // GP4
koyo_take 0:c6b2a8ace823 93 InterruptIn *grv_p2s2di; //Port2, Signal2, Digital In // GP3
koyo_take 0:c6b2a8ace823 94 AnalogIn grv_p2s1a; //Port2, Signal1, Analog In // AN4
koyo_take 0:c6b2a8ace823 95 AnalogIn grv_p2s2a; //Port2, Signal2, Analog In // AN3
koyo_take 0:c6b2a8ace823 96
koyo_take 0:c6b2a8ace823 97 Sht31 *temp_humid_sensor;
koyo_take 0:c6b2a8ace823 98 ADXL345_I2C *accelerometer;
koyo_take 0:c6b2a8ace823 99
koyo_take 0:c6b2a8ace823 100 void flushSerial();
koyo_take 2:d48fcae8b5bd 101 ssize_t getline(char *buf, size_t bufsize, int timeout_ms);
koyo_take 0:c6b2a8ace823 102 int chkSerialChar(const char,uint16_t);
koyo_take 0:c6b2a8ace823 103 int waitSerialChar(const char,uint16_t);
koyo_take 0:c6b2a8ace823 104 int chkSerialCharOk();
koyo_take 0:c6b2a8ace823 105 int chkSerialCharRes(char);
koyo_take 3:f80f2838a956 106
koyo_take 3:f80f2838a956 107 int getLoraPort(void) {
koyo_take 3:f80f2838a956 108 static int port = 1;
koyo_take 3:f80f2838a956 109
koyo_take 3:f80f2838a956 110 port += 1;
koyo_take 3:f80f2838a956 111 if (233 < port)
koyo_take 3:f80f2838a956 112 port = 1;
koyo_take 3:f80f2838a956 113
koyo_take 3:f80f2838a956 114 return port;
koyo_take 3:f80f2838a956 115 }
koyo_take 0:c6b2a8ace823 116 };
koyo_take 0:c6b2a8ace823 117
koyo_take 0:c6b2a8ace823 118 #endif /* !defined(EEAPP1_H) */