/* * BigClown - Humidity, Temperature, Lux Meter and Pressure Module * * https://chiptron.cz * https://time4ee.com * * The example code is based on https://www.bigclown.com/ * * 2018 */ #include "application.h" #define BLACK true // sht20 instance bc_sht20_t sht20; // lux meter instance bc_opt3001_t lux; // presure instance bc_mpl3115a2_t pressure; void sht20_module_event_handler(bc_sht20_t *self, bc_sht20_event_t event, void *event_param) { (void) event_param; char bufferTemp[13]; char bufferHum[13]; float temperature = 0.0; float humidity = 0.0; if (event == BC_SHT20_EVENT_UPDATE) { bc_sht20_get_temperature_celsius(self, &temperature); bc_sht20_get_humidity_percentage(self, &humidity); sprintf(bufferTemp, "%05.2f", temperature); bufferTemp[12] = '\0'; sprintf(bufferHum, "%05.2f", humidity); bufferHum[12] = '\0'; // Use big font bc_module_lcd_set_font(&bc_font_ubuntu_24); bc_module_lcd_draw_string(5, 30, &bufferTemp[0], BLACK); bc_module_lcd_draw_string(100, 30, "°C", BLACK); bc_module_lcd_draw_string(5, 55, &bufferHum[0], BLACK); bc_module_lcd_draw_string(100, 55, "%", BLACK); // Don't forget to update bc_module_lcd_update(); } else { temperature = 0.0; humidity = 0.0; // Use big font bc_module_lcd_set_font(&bc_font_ubuntu_24); bc_module_lcd_draw_string(5, 30, &bufferTemp[0], BLACK); bc_module_lcd_draw_string(100, 30, "°C", BLACK); bc_module_lcd_draw_string(5, 55, &bufferHum[0], BLACK); bc_module_lcd_draw_string(100, 55, "%", BLACK); // Don't forget to update bc_module_lcd_update(); } } void lux_module_event_handler(bc_opt3001_t *self, bc_opt3001_event_t event, void *event_param) { (void) event_param; char bufferLx[13]; float illumination = 0.0; if (event == BC_OPT3001_EVENT_UPDATE) { bc_opt3001_get_illuminance_lux(self, &illumination); sprintf(bufferLx, "%06.2f", illumination); bufferLx[12] = '\0'; // Use big font bc_module_lcd_set_font(&bc_font_ubuntu_24); bc_module_lcd_draw_string(5, 80, &bufferLx[0], BLACK); bc_module_lcd_draw_string(100, 80, "lx", BLACK); // Don't forget to update bc_module_lcd_update(); } else { illumination = 0.0; // Use big font bc_module_lcd_set_font(&bc_font_ubuntu_24); bc_module_lcd_draw_string(5, 80, "0.0", BLACK); // Don't forget to update bc_module_lcd_update(); } } void pressure_module_event_handler(bc_mpl3115a2_t *self, bc_mpl3115a2_event_t event, void *event_param) { (void) event_param; char bufferPressure[13]; float press = 0.0; if (event == BC_MPL3115A2_EVENT_UPDATE) { bc_mpl3115a2_get_pressure_pascal(self, &press); sprintf(bufferPressure, "%06.0f", press); bufferPressure[12] = '\0'; // Use big font bc_module_lcd_set_font(&bc_font_ubuntu_24); bc_module_lcd_draw_string(5, 105, &bufferPressure[0], BLACK); bc_module_lcd_draw_string(100, 105, "Pa", BLACK); // Don't forget to update bc_module_lcd_update(); } else { press = 0.0; // Use big font bc_module_lcd_set_font(&bc_font_ubuntu_24); bc_module_lcd_draw_string(5, 105, "0.0", BLACK); // Don't forget to update bc_module_lcd_update(); } } void application_init(void) { /* LCD init */ // The parameter is internal buffer in SDK, no need to define it bc_module_lcd_init(&_bc_module_lcd_framebuffer); bc_module_lcd_clear(); bc_module_lcd_update(); /* SH20 init (temperature/humidity) */ bc_sht20_init(&sht20, BC_I2C_I2C0, 0x40); // set update interval bc_sht20_set_update_interval(&sht20, 1000); // set evend handler (what to do when tag update is triggered) bc_sht20_set_event_handler(&sht20, sht20_module_event_handler, NULL); /* OPT3001 init */ bc_opt3001_init(&lux, BC_I2C_I2C0, 0x44); // set update interval bc_opt3001_set_update_interval(&lux, 1000); // set evend handler (what to do when tag update is triggered) bc_opt3001_set_event_handler(&lux, lux_module_event_handler, NULL); /* MPL3115A2 init */ bc_mpl3115a2_init(&pressure, BC_I2C_I2C0, 0x60); // set update interval bc_mpl3115a2_set_update_interval(&pressure, 1000); // set evend handler (what to do when tag update is triggered) bc_mpl3115a2_set_event_handler(&pressure, pressure_module_event_handler, NULL); // Init default font, this is necessary // See other fonts in sdk/bcl/inc/bc_font_common.h bc_module_lcd_set_font(&bc_font_ubuntu_15); // Draw string at X, Y location bc_module_lcd_draw_string(10, 5, "chiptron.cz", BLACK); bc_module_lcd_draw_line(5, 20, 115, 20, BLACK); // Don't forget to update bc_module_lcd_update(); }