| | |
| | | #include <time.h> |
| | | #include <unistd.h> |
| | | |
| | | #include "led.h" |
| | | #include "ds18b20.h" |
| | | #include "sht20.h" |
| | | |
| | | int hal_init(void); |
| | | #include "logger.h" |
| | | #include "hal.h" |
| | | |
| | | /******************************************************************************** |
| | | * Description: |
| | |
| | | float temp; |
| | | float rh; |
| | | |
| | | if( hal_init() < 0 ) |
| | | //if( logger_init("mqttd.log", LOG_LEVEL_DEBUG, 1024) < 0 ) |
| | | if( logger_init(DBG_LOG_FILE, LOG_LEVEL_DEBUG, 1024) < 0 ) |
| | | { |
| | | printf("Initialise hardware failure\n"); |
| | | fprintf(stderr, "Logger system initialise failure\n"); |
| | | return -1; |
| | | } |
| | | |
| | | while(1) |
| | | |
| | | |
| | | log_dbg("Logger system initialise ok\n"); |
| | | |
| | | #if 0 |
| | | if( hal_init() < 0 ) |
| | | { |
| | | turn_led(LED_R, ON); |
| | | sleep(1); |
| | | turn_led(LED_R, OFF); |
| | | sleep(1); |
| | | |
| | | turn_led(LED_G, ON); |
| | | sleep(1); |
| | | turn_led(LED_G, OFF); |
| | | sleep(1); |
| | | |
| | | turn_led(LED_B, ON); |
| | | sleep(1); |
| | | turn_led(LED_B, OFF); |
| | | sleep(1); |
| | | |
| | | if(sht2x_get_temp_humidity(&temp, &rh) < 0) |
| | | { |
| | | printf("SHT2X get temperature and relative humidity failure\n"); |
| | | } |
| | | else |
| | | { |
| | | printf("SHT2X Temperature=%lfC, Relative humidity=%lf%% \n", temp, rh); |
| | | } |
| | | |
| | | |
| | | if( ds18b20_get_temperature(&temp) < 0) |
| | | { |
| | | printf("DS18B20 get temperature failure\n"); |
| | | } |
| | | else |
| | | { |
| | | printf("DS18B20 get temperature=%lf ℃ \n", temp); |
| | | } |
| | | log_err("Initialise hardware failure\n"); |
| | | return -1; |
| | | } |
| | | #endif |
| | | |
| | | log_nrml("HAL initialise ok\n"); |
| | | |
| | | |
| | | logger_term(); |
| | | |
| | | return 0; |
| | | } /* ----- End of main() ----- */ |
| | | |
| | | |
| | | int hal_init(void) |
| | | { |
| | | init_led(); |
| | | |
| | | if( sht2x_init() < 0 ) |
| | | { |
| | | printf("Initialise SHT20 failure\n"); |
| | | return -2; |
| | | } |
| | | |
| | | return 0; |
| | | } |