예제 #1
0
//-----------------------------------------
int ADC_read()
{
	unsigned char bufv[3];
	int res;
	int x = 0x00;
	int aux = 0x00;

	res = i2c_read(ACD_ADDRESS, ADC_REGISTER, bufv, 2);

	if (res)
	{
		debug_print(DBG_ERROR, "ADC_send() FAILED!!!...");
	}
	else
	{
		int mask = 0b0111111111111;
		aux = bufv[1]&mask;
		x = aux>>4;
		aux = bufv[0] & mask;
		x += aux<<4;
		if (x > 0x07FF)
			x = x-4095;
	}

	char buf[60];
	//For some reason the "if (x > 0x07FF)" part of the code, will not work without the next line:
	int len = mcu_snprintf(buf, 60,"%X %X %X %X:::: ", bufv[0], bufv[1],aux, x);

	return x;
}
예제 #2
0
void mcu_main()
{
	int version = api_version();
	debug_print(DBG_INFO, "API version: %d.%d\n", version/100, version%100);

	gpio_setup(GPIO_DHT, OUTPUT);
	gpio_write(GPIO_DHT, HIGH);

	/* do not send instructions within 1S after power on to pass the unstable state */
	mcu_sleep(100);

	uint8_t data[DHT_DATA_LEN];
	while (1) {
		int rc;
		uint8_t humidity, temperature;
		if ((rc = dht11_read(GPIO_DHT, data, sizeof(data))) == DHT_SUCCESS) {
			humidity = data[0], temperature = data[2];
			debug_print(DBG_INFO, "Humidity: %d%, Temperature: %d C\n", humidity, temperature);
//			debug_print(DBG_INFO, "%d %d %d %d %d\n",
//						data[0], data[1], data[2], data[3], data[4]);
		} else {
			debug_print(DBG_ERROR, "dht11_read() error [%d]\n", rc);
		}

		unsigned char buf[LEN_IPCBUF];
		if ((rc = host_receive(buf, sizeof(buf))) > 0 && buf[0] == '?') {
			rc = mcu_snprintf((char*)buf, LEN_IPCBUF, "RH=%d,T=%d\n", humidity, temperature);
			host_send(buf, rc);
		}

		mcu_sleep(300);
	}
}
예제 #3
0
void mcu_main()
{
	int value;
	while(1)
	{
		value = ADC_read();
		len = mcu_snprintf(buf, 32,"%d\n",value);
		host_send((unsigned char*)buf, len);

		//This will prevent the atom from freezing
		mcu_sleep(1);
	}

}