Ejemplo n.º 1
0
bool write_remap_read_5() {

	int i = 65;
	void *j;

	bool ok;
	dht_init();
	ok = dht_init_table(0, 20, false);
	
	if (!ok) {
		printf("> malloc fail causes fail not logic fail.\n");
		return false;
	}

	/* expect null */
	j = &i;
	dht_write(0, j);

	ok = dht_init_table(0, 4, false);
	
	if (!ok) {
		printf("> malloc fail causes fail not logic fail.\n");
		return false;
	}

	j = dht_read(0);

	return (j == NULL);

}
Ejemplo n.º 2
0
bool write_remap_read_4() {

	int i = 65, b;
	void *j;

	bool ok;
	dht_init();
	ok = dht_init_table(0, 20, false);
	
	if (!ok) {
		printf("> malloc fail causes fail not logic fail.\n");
		return false;
	}

	/* expect null */
	j = &i;
	dht_write(0, j);

	ok = dht_init_table(0, 4, true);
	
	if (!ok) {
		printf("> malloc fail causes fail not logic fail.\n");
		return false;
	}

	j = dht_read(0);

	b = *((int*)j);
	return (b == i);

}
Ejemplo n.º 3
0
bool write_remap_read_3() {

	int i = 1, b;
	void *j;

	bool ok;
	dht_init();
	ok = dht_init_table(101, 1600, false);
	
	if (!ok) {
		printf("> malloc fail causes fail not logic fail.\n");
		return false;
	}

	/* expect null */
	j = &i;
	dht_write(171, j);

	ok = dht_init_table(100, 172, true);
	
	if (!ok) {
		printf("> malloc fail causes fail not logic fail.\n");
		return false;
	}

	j = dht_read(171);

	b = *((int*)j);
	return (b == i);

}
Ejemplo n.º 4
0
bool read_write_11() {
	

	int i = 72, b;
	void *j;
	

	bool ok;
	dht_init();
	ok = dht_init_table(0, 20, false);
	
	if (!ok) {
		printf("> malloc fail causes fail not logic fail.\n");
		return false;
	}

	/* expect null */
	j = &i;
	dht_write(19, j);
	j = dht_read(19);

	b = *((int*)j);
	return (b == i);

}
Ejemplo n.º 5
0
void
dht_periodic(void)
{
  if (dht_global.polling_delay == 0)
  {
    /* read sensor data */
    dht_read();
    dht_global.polling_delay = DHT_POLLING_INTERVAL * HZ;
  }
  else if (--dht_global.polling_delay == 0)
  {
    dht_start();
  }
}
Ejemplo n.º 6
0
// 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;
}
Ejemplo n.º 7
0
static int check_and_read(const void *dev, phydat_t *res, int16_t *val, uint8_t unit)
{
    uint32_t now = xtimer_now_usec();

    if ((now - last) > DHT_SAUL_HOLD_TIME) {
        dht_read((const dht_t *)dev, &temp, &hum);
        last = now;
    }

    res->val[0] = *val;
    memset(&res->val[1], 0, 2 * sizeof(int16_t));
    res->unit = unit;
    res->scale = -1;
    return 1;
}
Ejemplo n.º 8
0
bool read_write_5() {
	
	void *j;

	bool ok;
	dht_init();
	ok = dht_init_table(1, 20, false);
	
	if (!ok) {
		printf("> malloc fail causes fail not logic fail.\n");
		return false;
	}

	/* expect null */
	j = dht_read(3);

	return (j == NULL);

}
Ejemplo n.º 9
0
static void _mqttclient_send_data(void) {
    enum dht_read_status status = dht_read();
    // TODO: remove hardcoded constant
    char buffer[20];
    uint8_t len = 0;
    int16_t _val_integral;
    uint16_t _val_decimal;
    switch (status) {
        case DHT_OK:
            /* If status is OK, publish measured data and return from function. */
            _val_integral = dht_data.humidity / 10;
            _val_decimal = dht_data.humidity % 10;
            len = snprintf(buffer, sizeof(buffer), "%d.%u", _val_integral, _val_decimal);
            umqtt_publish(&_mqtt, MQTT_TOPIC_HUMIDITY, (uint8_t *)buffer, len, 0);
            if (dht_data.temperature < 0) {
                _val_integral = dht_data.temperature / 10;
                _val_decimal = -dht_data.temperature % 10;
            } else {
                _val_integral = dht_data.temperature / 10;
                _val_decimal = dht_data.temperature % 10;
            }
            len = snprintf(buffer, sizeof(buffer), "%d.%u", _val_integral, _val_decimal);
            umqtt_publish(&_mqtt, MQTT_TOPIC_TEMPERATURE, (uint8_t *)buffer, len, 0);
            return;
        case DHT_ERROR_CHECKSUM:
            len = snprintf(buffer, sizeof(buffer), "E_CHECKSUM");
            break;
        case DHT_ERROR_TIMEOUT:
            len = snprintf(buffer, sizeof(buffer), "E_TIMEOUT");
            break;
        case DHT_ERROR_CONNECT:
            len = snprintf(buffer, sizeof(buffer), "E_CONNECT");
            break;
        case DHT_ERROR_ACK:
            len = snprintf(buffer, sizeof(buffer), "E_ACK");
            break;
    }

    /* Publish error codes. */
    umqtt_publish(&_mqtt, MQTT_TOPIC_HUMIDITY, (uint8_t *)buffer, len, 0);
    umqtt_publish(&_mqtt, MQTT_TOPIC_TEMPERATURE, (uint8_t *)buffer, len, 0);
}