Merge pull request #489 from nodemcu/revert-488-dev
Revert "Merge dev to dev096"
This commit is contained in:
commit
5c84ea1b74
|
@ -39,7 +39,6 @@ SUBDIRS= \
|
|||
spiffs \
|
||||
cjson \
|
||||
crypto \
|
||||
dhtlib
|
||||
|
||||
endif # } PDIR
|
||||
|
||||
|
@ -89,7 +88,6 @@ COMPONENTS_eagle.app.v6 = \
|
|||
spiffs/spiffs.a \
|
||||
cjson/libcjson.a \
|
||||
crypto/libcrypto.a \
|
||||
dhtlib/libdhtlib.a \
|
||||
modules/libmodules.a
|
||||
|
||||
LINKFLAGS_eagle.app.v6 = \
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
|
||||
#############################################################
|
||||
# Required variables for each makefile
|
||||
# Discard this section from all parent makefiles
|
||||
# Expected variables (with automatic defaults):
|
||||
# CSRCS (all "C" files in the dir)
|
||||
# SUBDIRS (all subdirs with a Makefile)
|
||||
# GEN_LIBS - list of libs to be generated ()
|
||||
# GEN_IMAGES - list of images to be generated ()
|
||||
# COMPONENTS_xxx - a list of libs/objs in the form
|
||||
# subdir/lib to be extracted and rolled up into
|
||||
# a generated lib/image xxx.a ()
|
||||
#
|
||||
ifndef PDIR
|
||||
GEN_LIBS = libdhtlib.a
|
||||
endif
|
||||
|
||||
|
||||
#############################################################
|
||||
# Configuration i.e. compile options etc.
|
||||
# Target specific stuff (defines etc.) goes in here!
|
||||
# Generally values applying to a tree are captured in the
|
||||
# makefile at its root level - these are then overridden
|
||||
# for a subtree within the makefile rooted therein
|
||||
#
|
||||
#DEFINES +=
|
||||
|
||||
#############################################################
|
||||
# Recursion Magic - Don't touch this!!
|
||||
#
|
||||
# Each subtree potentially has an include directory
|
||||
# corresponding to the common APIs applicable to modules
|
||||
# rooted at that subtree. Accordingly, the INCLUDE PATH
|
||||
# of a module can only contain the include directories up
|
||||
# its parent path, and not its siblings
|
||||
#
|
||||
# Required for each makefile to inherit from the parent
|
||||
#
|
||||
|
||||
INCLUDES := $(INCLUDES) -I $(PDIR)include
|
||||
INCLUDES += -I ./
|
||||
INCLUDES += -I ./include
|
||||
INCLUDES += -I ../include
|
||||
INCLUDES += -I ../../include
|
||||
INCLUDES += -I ../libc
|
||||
INCLUDES += -I ../platform
|
||||
PDIR := ../$(PDIR)
|
||||
sinclude $(PDIR)Makefile
|
||||
|
315
app/dhtlib/dht.c
315
app/dhtlib/dht.c
|
@ -1,315 +0,0 @@
|
|||
//
|
||||
// FILE: dht.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.14
|
||||
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
|
||||
// URL: http://arduino.cc/playground/Main/DHTLib
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.14 replace digital read with faster (~3x) code => more robust low MHz machines.
|
||||
// 0.1.13 fix negative dht_temperature
|
||||
// 0.1.12 support DHT33 and DHT44 initial version
|
||||
// 0.1.11 renamed DHTLIB_TIMEOUT
|
||||
// 0.1.10 optimized faster WAKEUP + TIMEOUT
|
||||
// 0.1.09 optimize size: timeout check + use of mask
|
||||
// 0.1.08 added formula for timeout based upon clockspeed
|
||||
// 0.1.07 added support for DHT21
|
||||
// 0.1.06 minimize footprint (2012-12-27)
|
||||
// 0.1.05 fixed negative dht_temperature bug (thanks to Roseman)
|
||||
// 0.1.04 improved readability of code using DHTLIB_OK in code
|
||||
// 0.1.03 added error values for temp and dht_humidity when read failed
|
||||
// 0.1.02 added error codes
|
||||
// 0.1.01 added support for Arduino 1.0, fixed typos (31/12/2011)
|
||||
// 0.1.00 by Rob Tillaart (01/04/2011)
|
||||
//
|
||||
// inspired by DHT11 library
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include "user_interface.h"
|
||||
#include "platform.h"
|
||||
#include "c_stdio.h"
|
||||
#include "dht.h"
|
||||
|
||||
#ifndef LOW
|
||||
#define LOW 0
|
||||
#endif /* ifndef LOW */
|
||||
|
||||
#ifndef HIGH
|
||||
#define HIGH 1
|
||||
#endif /* ifndef HIGH */
|
||||
|
||||
#define COMBINE_HIGH_AND_LOW_BYTE(byte_high, byte_low) (((byte_high) << 8) | (byte_low))
|
||||
|
||||
static double dht_humidity;
|
||||
static double dht_temperature;
|
||||
|
||||
static uint8_t dht_bytes[5]; // buffer to receive data
|
||||
static int dht_readSensor(uint8_t pin, uint8_t wakeupDelay);
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
// PUBLIC
|
||||
//
|
||||
|
||||
// return values:
|
||||
// Humidity
|
||||
double dht_getHumidity(void)
|
||||
{
|
||||
return dht_humidity;
|
||||
}
|
||||
|
||||
// return values:
|
||||
// Temperature
|
||||
double dht_getTemperature(void)
|
||||
{
|
||||
return dht_temperature;
|
||||
}
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int dht_read_universal(uint8_t pin)
|
||||
{
|
||||
// READ VALUES
|
||||
int rv = dht_readSensor(pin, DHTLIB_DHT_UNI_WAKEUP);
|
||||
if (rv != DHTLIB_OK)
|
||||
{
|
||||
dht_humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered?
|
||||
dht_temperature = DHTLIB_INVALID_VALUE; // invalid value
|
||||
return rv; // propagate error value
|
||||
}
|
||||
|
||||
#if defined(DHT_DEBUG_BYTES)
|
||||
int i;
|
||||
for (i = 0; i < 5; i++)
|
||||
{
|
||||
DHT_DEBUG("%02X\n", dht_bytes[i]);
|
||||
}
|
||||
#endif // defined(DHT_DEBUG_BYTES)
|
||||
|
||||
// Assume it is DHT11
|
||||
// If it is DHT11, both bit[1] and bit[3] is 0
|
||||
if ((dht_bytes[1] == 0) && (dht_bytes[3] == 0))
|
||||
{
|
||||
// It may DHT11
|
||||
// CONVERT AND STORE
|
||||
DHT_DEBUG("DHT11 method\n");
|
||||
dht_humidity = dht_bytes[0]; // dht_bytes[1] == 0;
|
||||
dht_temperature = dht_bytes[2]; // dht_bytes[3] == 0;
|
||||
|
||||
// TEST CHECKSUM
|
||||
// dht_bytes[1] && dht_bytes[3] both 0
|
||||
uint8_t sum = dht_bytes[0] + dht_bytes[2];
|
||||
if (dht_bytes[4] != sum)
|
||||
{
|
||||
// It may not DHT11
|
||||
dht_humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered?
|
||||
dht_temperature = DHTLIB_INVALID_VALUE; // invalid value
|
||||
// Do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
return DHTLIB_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// Assume it is not DHT11
|
||||
// CONVERT AND STORE
|
||||
DHT_DEBUG("DHTxx method\n");
|
||||
dht_humidity = (double)COMBINE_HIGH_AND_LOW_BYTE(dht_bytes[0], dht_bytes[1]) * 0.1;
|
||||
dht_temperature = (double)COMBINE_HIGH_AND_LOW_BYTE(dht_bytes[2] & 0x7F, dht_bytes[3]) * 0.1;
|
||||
if (dht_bytes[2] & 0x80) // negative dht_temperature
|
||||
{
|
||||
dht_temperature = -dht_temperature;
|
||||
}
|
||||
|
||||
// TEST CHECKSUM
|
||||
uint8_t sum = dht_bytes[0] + dht_bytes[1] + dht_bytes[2] + dht_bytes[3];
|
||||
if (dht_bytes[4] != sum)
|
||||
{
|
||||
return DHTLIB_ERROR_CHECKSUM;
|
||||
}
|
||||
return DHTLIB_OK;
|
||||
}
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int dht_read11(uint8_t pin)
|
||||
{
|
||||
// READ VALUES
|
||||
int rv = dht_readSensor(pin, DHTLIB_DHT11_WAKEUP);
|
||||
if (rv != DHTLIB_OK)
|
||||
{
|
||||
dht_humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered?
|
||||
dht_temperature = DHTLIB_INVALID_VALUE; // invalid value
|
||||
return rv;
|
||||
}
|
||||
|
||||
// CONVERT AND STORE
|
||||
dht_humidity = dht_bytes[0]; // dht_bytes[1] == 0;
|
||||
dht_temperature = dht_bytes[2]; // dht_bytes[3] == 0;
|
||||
|
||||
// TEST CHECKSUM
|
||||
// dht_bytes[1] && dht_bytes[3] both 0
|
||||
uint8_t sum = dht_bytes[0] + dht_bytes[2];
|
||||
if (dht_bytes[4] != sum) return DHTLIB_ERROR_CHECKSUM;
|
||||
|
||||
return DHTLIB_OK;
|
||||
}
|
||||
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int dht_read(uint8_t pin)
|
||||
{
|
||||
// READ VALUES
|
||||
int rv = dht_readSensor(pin, DHTLIB_DHT_WAKEUP);
|
||||
if (rv != DHTLIB_OK)
|
||||
{
|
||||
dht_humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered?
|
||||
dht_temperature = DHTLIB_INVALID_VALUE; // invalid value
|
||||
return rv; // propagate error value
|
||||
}
|
||||
|
||||
// CONVERT AND STORE
|
||||
dht_humidity = (double)COMBINE_HIGH_AND_LOW_BYTE(dht_bytes[0], dht_bytes[1]) * 0.1;
|
||||
dht_temperature = (double)COMBINE_HIGH_AND_LOW_BYTE(dht_bytes[2] & 0x7F, dht_bytes[3]) * 0.1;
|
||||
if (dht_bytes[2] & 0x80) // negative dht_temperature
|
||||
{
|
||||
dht_temperature = -dht_temperature;
|
||||
}
|
||||
|
||||
// TEST CHECKSUM
|
||||
uint8_t sum = dht_bytes[0] + dht_bytes[1] + dht_bytes[2] + dht_bytes[3];
|
||||
if (dht_bytes[4] != sum)
|
||||
{
|
||||
return DHTLIB_ERROR_CHECKSUM;
|
||||
}
|
||||
return DHTLIB_OK;
|
||||
}
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int dht_read21(uint8_t pin) __attribute__((alias("dht_read")));
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int dht_read22(uint8_t pin) __attribute__((alias("dht_read")));
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int dht_read33(uint8_t pin) __attribute__((alias("dht_read")));
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int dht_read44(uint8_t pin) __attribute__((alias("dht_read")));
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
// PRIVATE
|
||||
//
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int dht_readSensor(uint8_t pin, uint8_t wakeupDelay)
|
||||
{
|
||||
// INIT BUFFERVAR TO RECEIVE DATA
|
||||
uint8_t mask = 128;
|
||||
uint8_t idx = 0;
|
||||
uint8_t i = 0;
|
||||
|
||||
// replace digitalRead() with Direct Port Reads.
|
||||
// reduces footprint ~100 bytes => portability issue?
|
||||
// direct port read is about 3x faster
|
||||
// uint8_t bit = digitalPinToBitMask(pin);
|
||||
// uint8_t port = digitalPinToPort(pin);
|
||||
// volatile uint8_t *PIR = portInputRegister(port);
|
||||
|
||||
// EMPTY BUFFER
|
||||
for (i = 0; i < 5; i++) dht_bytes[i] = 0;
|
||||
|
||||
// REQUEST SAMPLE
|
||||
// pinMode(pin, OUTPUT);
|
||||
platform_gpio_mode(pin, PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_PULLUP);
|
||||
DIRECT_MODE_OUTPUT(pin);
|
||||
// digitalWrite(pin, LOW); // T-be
|
||||
DIRECT_WRITE_LOW(pin);
|
||||
// delay(wakeupDelay);
|
||||
for (i = 0; i < wakeupDelay; i++) os_delay_us(1000);
|
||||
// digitalWrite(pin, HIGH); // T-go
|
||||
DIRECT_WRITE_HIGH(pin);
|
||||
os_delay_us(40);
|
||||
// pinMode(pin, INPUT);
|
||||
DIRECT_MODE_INPUT(pin);
|
||||
|
||||
// GET ACKNOWLEDGE or TIMEOUT
|
||||
uint16_t loopCntLOW = DHTLIB_TIMEOUT;
|
||||
while (DIRECT_READ(pin) == LOW ) // T-rel
|
||||
{
|
||||
os_delay_us(1);
|
||||
if (--loopCntLOW == 0) return DHTLIB_ERROR_TIMEOUT;
|
||||
}
|
||||
|
||||
uint16_t loopCntHIGH = DHTLIB_TIMEOUT;
|
||||
while (DIRECT_READ(pin) != LOW ) // T-reh
|
||||
{
|
||||
os_delay_us(1);
|
||||
if (--loopCntHIGH == 0) return DHTLIB_ERROR_TIMEOUT;
|
||||
}
|
||||
|
||||
// READ THE OUTPUT - 40 BITS => 5 BYTES
|
||||
for (i = 40; i != 0; i--)
|
||||
{
|
||||
loopCntLOW = DHTLIB_TIMEOUT;
|
||||
while (DIRECT_READ(pin) == LOW )
|
||||
{
|
||||
os_delay_us(1);
|
||||
if (--loopCntLOW == 0) return DHTLIB_ERROR_TIMEOUT;
|
||||
}
|
||||
|
||||
uint32_t t = system_get_time();
|
||||
|
||||
loopCntHIGH = DHTLIB_TIMEOUT;
|
||||
while (DIRECT_READ(pin) != LOW )
|
||||
{
|
||||
os_delay_us(1);
|
||||
if (--loopCntHIGH == 0) return DHTLIB_ERROR_TIMEOUT;
|
||||
}
|
||||
|
||||
if ((system_get_time() - t) > 40)
|
||||
{
|
||||
dht_bytes[idx] |= mask;
|
||||
}
|
||||
mask >>= 1;
|
||||
if (mask == 0) // next byte?
|
||||
{
|
||||
mask = 128;
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
// pinMode(pin, OUTPUT);
|
||||
DIRECT_MODE_OUTPUT(pin);
|
||||
// digitalWrite(pin, HIGH);
|
||||
DIRECT_WRITE_HIGH(pin);
|
||||
|
||||
return DHTLIB_OK;
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
|
@ -1,70 +0,0 @@
|
|||
//
|
||||
// FILE: dht.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.14
|
||||
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
|
||||
// URL: http://arduino.cc/playground/Main/DHTLib
|
||||
//
|
||||
// HISTORY:
|
||||
// see dht.cpp file
|
||||
//
|
||||
|
||||
#ifndef dht_h
|
||||
#define dht_h
|
||||
|
||||
// #if ARDUINO < 100
|
||||
// #include <WProgram.h>
|
||||
// #else
|
||||
// #include <Arduino.h>
|
||||
// #endif
|
||||
#include "c_types.h"
|
||||
|
||||
#define DHT_LIB_VERSION "0.1.14"
|
||||
|
||||
#define DHTLIB_OK 0
|
||||
#define DHTLIB_ERROR_CHECKSUM -1
|
||||
#define DHTLIB_ERROR_TIMEOUT -2
|
||||
#define DHTLIB_INVALID_VALUE -999
|
||||
|
||||
#define DHTLIB_DHT11_WAKEUP 18
|
||||
#define DHTLIB_DHT_WAKEUP 1
|
||||
#define DHTLIB_DHT_UNI_WAKEUP 18
|
||||
|
||||
#define DHT_DEBUG
|
||||
|
||||
// max timeout is 100 usec.
|
||||
// For a 16 Mhz proc 100 usec is 1600 clock cycles
|
||||
// loops using DHTLIB_TIMEOUT use at least 4 clock cycli
|
||||
// so 100 us takes max 400 loops
|
||||
// so by dividing F_CPU by 40000 we "fail" as fast as possible
|
||||
// ESP8266 uses delay_us get 1us time
|
||||
#define DHTLIB_TIMEOUT (100)
|
||||
|
||||
// Platform specific I/O definitions
|
||||
|
||||
#define DIRECT_READ(pin) (0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(pin_num[pin])))
|
||||
#define DIRECT_MODE_INPUT(pin) GPIO_DIS_OUTPUT(pin_num[pin])
|
||||
#define DIRECT_MODE_OUTPUT(pin)
|
||||
#define DIRECT_WRITE_LOW(pin) (GPIO_OUTPUT_SET(GPIO_ID_PIN(pin_num[pin]), 0))
|
||||
#define DIRECT_WRITE_HIGH(pin) (GPIO_OUTPUT_SET(GPIO_ID_PIN(pin_num[pin]), 1))
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int dht_read_universal(uint8_t pin);
|
||||
int dht_read11(uint8_t pin);
|
||||
int dht_read(uint8_t pin);
|
||||
|
||||
int dht_read21(uint8_t pin);
|
||||
int dht_read22(uint8_t pin);
|
||||
int dht_read33(uint8_t pin);
|
||||
int dht_read44(uint8_t pin);
|
||||
|
||||
double dht_getHumidity(void);
|
||||
double dht_getTemperature(void);
|
||||
|
||||
#endif
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
|
@ -33,7 +33,6 @@
|
|||
#define LUA_USE_MODULES_CJSON
|
||||
#define LUA_USE_MODULES_CRYPTO
|
||||
#define LUA_USE_MODULES_RC
|
||||
#define LUA_USE_MODULES_DHT
|
||||
|
||||
#endif /* LUA_USE_MODULES */
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
#define NODE_VERSION_INTERNAL 0U
|
||||
|
||||
#define NODE_VERSION "NodeMCU 0.9.6"
|
||||
#define BUILD_DATE "build 20150618"
|
||||
#define BUILD_DATE "build 20150617"
|
||||
|
||||
#endif /* __USER_VERSION_H__ */
|
||||
|
|
|
@ -48,7 +48,6 @@ INCLUDES += -I ../wofs
|
|||
INCLUDES += -I ../spiffs
|
||||
INCLUDES += -I ../smart
|
||||
INCLUDES += -I ../cjson
|
||||
INCLUDES += -I ../dhtlib
|
||||
PDIR := ../$(PDIR)
|
||||
sinclude $(PDIR)Makefile
|
||||
|
||||
|
|
|
@ -82,15 +82,6 @@ LUALIB_API int ( luaopen_ow )( lua_State *L );
|
|||
#define AUXLIB_CJSON "cjson"
|
||||
LUALIB_API int ( luaopen_cjson )( lua_State *L );
|
||||
|
||||
#define AUXLIB_CRYPTO "crypto"
|
||||
LUALIB_API int ( luaopen_crypto )( lua_State *L );
|
||||
|
||||
#define AUXLIB_RC "rc"
|
||||
LUALIB_API int ( luaopen_rc )( lua_State *L );
|
||||
|
||||
#define AUXLIB_DHT "dht"
|
||||
LUALIB_API int ( luaopen_dht )( lua_State *L );
|
||||
|
||||
// Helper macros
|
||||
#define MOD_CHECK_ID( mod, id )\
|
||||
if( !platform_ ## mod ## _exists( id ) )\
|
||||
|
|
|
@ -1,129 +0,0 @@
|
|||
// Module for interfacing with the DHTxx sensors (xx = 11-21-22-33-44).
|
||||
|
||||
#include "lualib.h"
|
||||
#include "lauxlib.h"
|
||||
#include "auxmods.h"
|
||||
#include "lrotable.h"
|
||||
#include "cpu_esp8266.h"
|
||||
#include "dht.h"
|
||||
|
||||
#define NUM_DHT GPIO_PIN_NUM
|
||||
|
||||
// ****************************************************************************
|
||||
// DHT functions
|
||||
int platform_dht_exists( unsigned id )
|
||||
{
|
||||
return ((id < NUM_DHT) && (id > 0));
|
||||
}
|
||||
|
||||
// Lua: status, temp, humi, tempdec, humidec = dht.read( id )
|
||||
static int dht_lapi_read( lua_State *L )
|
||||
{
|
||||
unsigned id = luaL_checkinteger( L, 1 );
|
||||
MOD_CHECK_ID( dht, id );
|
||||
lua_pushinteger( L, dht_read_universal(id) );
|
||||
double temp = dht_getTemperature();
|
||||
double humi = dht_getHumidity();
|
||||
int tempdec = (int)((temp - (int)temp) * 1000);
|
||||
int humidec = (int)((humi - (int)humi) * 1000);
|
||||
lua_pushnumber( L, temp );
|
||||
lua_pushnumber( L, humi );
|
||||
lua_pushnumber( L, tempdec );
|
||||
lua_pushnumber( L, humidec );
|
||||
return 5;
|
||||
}
|
||||
|
||||
// Lua: status, temp, humi, tempdec, humidec = dht.read11( id ))
|
||||
static int dht_lapi_read11( lua_State *L )
|
||||
{
|
||||
unsigned id = luaL_checkinteger( L, 1 );
|
||||
MOD_CHECK_ID( dht, id );
|
||||
lua_pushinteger( L, dht_read11(id) );
|
||||
double temp = dht_getTemperature();
|
||||
double humi = dht_getHumidity();
|
||||
int tempdec = (int)((temp - (int)temp) * 1000);
|
||||
int humidec = (int)((humi - (int)humi) * 1000);
|
||||
lua_pushnumber( L, temp );
|
||||
lua_pushnumber( L, humi );
|
||||
lua_pushnumber( L, tempdec );
|
||||
lua_pushnumber( L, humidec );
|
||||
return 5;
|
||||
}
|
||||
|
||||
// Lua: status, temp, humi, tempdec, humidec = dht.readxx( id ))
|
||||
static int dht_lapi_readxx( lua_State *L )
|
||||
{
|
||||
unsigned id = luaL_checkinteger( L, 1 );
|
||||
MOD_CHECK_ID( dht, id );
|
||||
lua_pushinteger( L, dht_read(id) );
|
||||
double temp = dht_getTemperature();
|
||||
double humi = dht_getHumidity();
|
||||
int tempdec = (int)((temp - (int)temp) * 1000);
|
||||
int humidec = (int)((humi - (int)humi) * 1000);
|
||||
lua_pushnumber( L, temp );
|
||||
lua_pushnumber( L, humi );
|
||||
lua_pushnumber( L, tempdec );
|
||||
lua_pushnumber( L, humidec );
|
||||
return 5;
|
||||
}
|
||||
|
||||
// // Lua: result = dht.humidity()
|
||||
// static int dht_lapi_humidity( lua_State *L )
|
||||
// {
|
||||
// lua_pushnumber( L, dht_getHumidity() );
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
// // Lua: result = dht.humiditydecimal()
|
||||
// static int dht_lapi_humiditydecimal( lua_State *L )
|
||||
// {
|
||||
// double value = dht_getHumidity();
|
||||
// int result = (int)((value - (int)value) * 1000);
|
||||
// lua_pushnumber( L, result );
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
// // Lua: result = dht.temperature()
|
||||
// static int dht_lapi_temperature( lua_State *L )
|
||||
// {
|
||||
// lua_pushnumber( L, dht_getTemperature() );
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
// // Lua: result = dht.temperaturedecimal()
|
||||
// static int dht_lapi_temperaturedecimal( lua_State *L )
|
||||
// {
|
||||
// double value = dht_getTemperature();
|
||||
// int result = (int)((value - (int)value) * 1000);
|
||||
// lua_pushnumber( L, result );
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
// Module function map
|
||||
#define MIN_OPT_LEVEL 2
|
||||
#include "lrodefs.h"
|
||||
const LUA_REG_TYPE dht_map[] =
|
||||
{
|
||||
{ LSTRKEY( "read" ), LFUNCVAL( dht_lapi_read ) },
|
||||
{ LSTRKEY( "read11" ), LFUNCVAL( dht_lapi_read11 ) },
|
||||
{ LSTRKEY( "readxx" ), LFUNCVAL( dht_lapi_readxx ) },
|
||||
#if LUA_OPTIMIZE_MEMORY > 0
|
||||
{ LSTRKEY( "OK" ), LNUMVAL( DHTLIB_OK ) },
|
||||
{ LSTRKEY( "ERROR_CHECKSUM" ), LNUMVAL( DHTLIB_ERROR_CHECKSUM ) },
|
||||
{ LSTRKEY( "ERROR_TIMEOUT" ), LNUMVAL( DHTLIB_ERROR_TIMEOUT ) },
|
||||
#endif
|
||||
{ LNILKEY, LNILVAL }
|
||||
};
|
||||
|
||||
LUALIB_API int luaopen_dht( lua_State *L )
|
||||
{
|
||||
#if LUA_OPTIMIZE_MEMORY > 0
|
||||
return 0;
|
||||
#else // #if LUA_OPTIMIZE_MEMORY > 0
|
||||
luaL_register( L, AUXLIB_DHT, dht_map );
|
||||
|
||||
// Add the constants
|
||||
|
||||
return 1;
|
||||
#endif // #if LUA_OPTIMIZE_MEMORY > 0
|
||||
}
|
|
@ -165,14 +165,6 @@
|
|||
#define ROM_MODULES_RC
|
||||
#endif
|
||||
|
||||
#if defined(LUA_USE_MODULES_DHT)
|
||||
#define MODULES_DHT "dht"
|
||||
#define ROM_MODULES_DHT \
|
||||
_ROM(MODULES_DHT, luaopen_dht, dht_map)
|
||||
#else
|
||||
#define ROM_MODULES_DHT
|
||||
#endif
|
||||
|
||||
#define LUA_MODULES_ROM \
|
||||
ROM_MODULES_GPIO \
|
||||
ROM_MODULES_PWM \
|
||||
|
@ -193,7 +185,6 @@
|
|||
ROM_MODULES_WS2812 \
|
||||
ROM_MODULES_CJSON \
|
||||
ROM_MODULES_CRYPTO \
|
||||
ROM_MODULES_RC \
|
||||
ROM_MODULES_DHT
|
||||
ROM_MODULES_RC
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
// -- This WS2812 code must be compiled with -O2 to get the timing right. Read this:
|
||||
// -- http://wp.josh.com/2014/05/13/ws2812-neopixels-are-not-so-finicky-once-you-get-to-know-them/
|
||||
// -- The ICACHE_FLASH_ATTR is there to trick the compiler and get the very first pulse width correct.
|
||||
static void ICACHE_FLASH_ATTR __attribute__((optimize("O2"))) send_ws_0(uint8_t gpio){
|
||||
static void ICACHE_FLASH_ATTR send_ws_0(uint8_t gpio) {
|
||||
uint8_t i;
|
||||
i = 4; while (i--) GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, 1 << gpio);
|
||||
i = 9; while (i--) GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, 1 << gpio);
|
||||
}
|
||||
|
||||
static void ICACHE_FLASH_ATTR __attribute__((optimize("O2"))) send_ws_1(uint8_t gpio){
|
||||
static void ICACHE_FLASH_ATTR send_ws_1(uint8_t gpio) {
|
||||
uint8_t i;
|
||||
i = 8; while (i--) GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, 1 << gpio);
|
||||
i = 6; while (i--) GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, 1 << gpio);
|
||||
|
|
|
@ -75,7 +75,6 @@ int platform_tmr_exists( unsigned id )
|
|||
return id < NUM_TMR;
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
// I2C support
|
||||
int platform_i2c_exists( unsigned id )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue