AMS, Franklin Lightning Sensor "AS3935" Library

Franklin Lightning Sensor

雷(落雷)センサー AS3935 用のライブラリです。

Sample

I2C接続

for LPC1114

main.cpp

#include "mbed.h"
#include "AS3935.h"

Serial pc(USBTX, USBRX);
DigitalOut led1(LED1);

AS3935 as(dp5, dp27, dp26); // sda, scl, irq
//I2C i2c(dp5, dp27);
//AS3935 as(i2c, dp26); // i2c, irq

void lightning () {
    int energy, distance;
    as.read(energy, distance);
    pc.printf("Lightning energy=%d distance=%d\r\n", energy, distance);
}

int main() {
    pc.baud(115200);
    pc.printf("*** AS3935\r\n");
    as.init();
    as.attach(&lightning);
    for (;;) {
        led1 = ! led1;
        wait(0.2);
    }
}

AS3935.h

Committer:
okini3939
Date:
2015-04-13
Revision:
0:5a6d7a605d26

File content as of revision 0:5a6d7a605d26:

/*
 * AMS, Franklin Lightning Sensor "AS3935" Library
 * Copyright (c) 2015 Hiroshi Suga
 * Released under the MIT License: http://mbed.org/license/mit
 */
// http://ams.com/eng/Products/Lightning-Sensor/Franklin-Lightning-Sensor/AS3935

#ifndef _AS3935_h_
#define _AS3935_h_

#include "mbed.h"

class AS3935 {
public:
    /**
     * @param i2c I2C class
     * @param irq IRQ pin
     */
    AS3935 (I2C &i2c, PinName irq);
    /**
     * @param sda I2C SDA pin
     * @param scl I2C SCL pin
     * @param irq IRQ pin
     */
    AS3935 (PinName sda, PinName scl, PinName irq);

    /** Initialize AS3935
     */
    void init ();

    /** Read lightning signal validation
     * @param energy (return) Energy of the Single Lightning
     * @param distance (return) Distance estimation
     */
    void read (int &energy, int &distance);

    /** Attach a function, lightning interrupt
     * @param fptr pointer to a void function, or 0 to set as none
     */
    void attach(void (*fptr)(void)) { 
        _func.attach(fptr);
    }
    /** Attach a member function, lightning interrupt
     * @param tptr pointer to the object to call the member function on
     * @param mptr pointer to the member function to be called
     */
    template<typename T>
    void attach(T *tptr, void (T::*mptr)(void)) { 
        _func.attach(tptr, mptr); 
    }

private:
    I2C _i2c;
    InterruptIn _irq;
    int _freq;
    int _mode;
    int _type;

    FunctionPointer _func;

    void calib_lco ();
    void isr_freq ();
    void isr_lightning ();
};

#endif