int main(int argc, char ** argv)
{
    int ret = -1;
    int dhtTemp=0, dhtHdty=0, board;
    char modStr[BUF_SIZE];
    int pin = GPIO_PIN(7);

    if ((board = boardInit()) < 0) {
        printf("Fail to init board\n");
        return -1;
    }    
    if (board == BOARD_NANOPI_T2)
        pin = GPIO_PIN(15);
    
    sprintf(modStr, "modprobe %s gpio=%d", DRIVER_MODULE, pintoGPIO(pin));
    system(modStr);
    if ((ret = dht11Read(DHT_HUMIDITY, &dhtHdty)) != -1) {
        printf("The humidity is %d\n", dhtHdty);
    } else {
        printf("Faided to get humidity\n");
    }
    if ((ret = dht11Read(DHT_TEMP, &dhtTemp)) != -1) {
        printf("The temperature is %d\n", dhtTemp);
    } else {
        printf("Faided to get temperature\n");
    }
    system("rmmod "DRIVER_MODULE);
    return ret;
}
int main(int argc, char ** argv) {
	int dhtTemp = 0;
	int dhtHdty = 0;
	int INT_BUF = 0;
	char* buf = (char *) malloc(LCD_LENGTH);
	memset(buf, 0, LCD_LENGTH);
	char* line1 = " hum: ";
	char* line2 = " temp: ";
	THmonitoring_init();
	if (LCD1602DispLines(devFD_LCD, line1, line2) == -1) {
        	printf("Fail to Display String\n");
    	}
	signal(SIGINT, Stop);
	printf("you can press ctrl+c to stop\n");
	while(!stop) {
		if ((dht11Read(DHT_HUMIDITY, &dhtHdty)) == -1) {
			dhtHdty = 0;
		}
		if ((dht11Read(DHT_TEMP, &dhtTemp)) == -1) {
			dhtTemp = 0;
		}

		if (dhtHdty == 0) {
			sprintf(buf, "%s", "Er");
		} else {
			INT_BUF = dhtHdty / 1000;
			sprintf(buf, "%d", INT_BUF);
		}
		LCD1602DispStr(devFD_LCD, 6, 0, buf);

		if (dhtTemp == 0) {
			sprintf(buf, "%s", "Er");
		} else {
			INT_BUF = dhtTemp / 1000;
			sprintf(buf, "%d", INT_BUF);
		}
		LCD1602DispStr(devFD_LCD, 7, 1, buf);

		if (dhtTemp >= SET_TEMP) {
			 if (THmonitoring_alart() != 0) {
				printf("fail to alart!\n");
				break;
			 }
		}

		sleep(1);
		THmonitoring_noalart();
		sleep(1);		
	}
	free(buf);
	THmonitoring_deinit();
	return 0;
}
Exemple #3
0
struct dht11Result dht11(uint8_t tryNumber) {
	struct dht11Result result = dht11Read();
	if(!result.ok && ++tryNumber < 10) {
		delay(100);
		return dht11(tryNumber);
	}
	return result;
}
Exemple #4
0
void userHandle(void)
{
    uint8_t ret  = 0;
    int8_t curTem = 0;
    int8_t curHum = 0;
    uint8_t curInfrared = 0;
    static int8_t lastTem = 0;
    static int8_t lastHum = 0;
    static uint32_t irLastTimer = 0;
    static uint32_t thLastTimer = 0;
    
    curInfrared = irHandle();
    if(curInfrared != reportData.devStatus.Infrared)
    {
        if((gizwitsGetTimerCount() - irLastTimer) > REPORT_TIME_MAX/4) //timeout = 2S
        {
            reportData.devStatus.Infrared = curInfrared;

            irLastTimer = gizwitsGetTimerCount();
            #if EN_DEBUG > 0
            printf("Infrared %d \r\n", irLastTimer);
            #endif
        }
    }
    
    if((gizwitsGetTimerCount()-thLastTimer) > REPORT_TIME_MAX) //timeout = 2S
    {
        ret = dht11Read(&curTem, &curHum);
        
        if(0 == ret)
        {
            if((curTem != lastTem)||(curHum != lastHum))
            {            
                reportData.devStatus.Temperature = Y2X(TEMPERATURE_RATIO,TEMPERATURE_ADDITION,curTem);
                reportData.devStatus.Humidity = Y2X(HUMIDITY_RATIO,HUMIDITY_ADDITION,curHum);
                
                lastTem = curTem;
                lastHum = curHum;
                #if EN_DEBUG > 0
                printf("Temperature&Humidity  [%d-%d] %d %d\r\n", gizwitsGetTimerCount(), thLastTimer, curTem, curHum);
                #endif
            }
        }
        else
        {
            #if EN_DEBUG > 0
            printf("Failed to read DHT11\r\n");
            #endif
        }
        
        thLastTimer = gizwitsGetTimerCount();
    }
}