Пример #1
0
extern "C" void user_init(void)
{
    sdk_uart_div_modify(0, UART_CLK_FREQ / 115200);
    
    // give the UART some time to settle
    sdk_os_delay_us(500);
    
    printf("\n\n");
    printf("*****\n");
    printf("START\n");
    printf("*****\n");
    printf("SDK version : %s\n\n", sdk_system_get_sdk_version());
    
    // get our 1 second clock running
    esp_start_system_time();

    if(mqtt_pub.m_Mqtt_payload.init(4) != 0) {
        printf("main(): mqtt_pub.m_Mqtt_payload.init(4) != 0\n");
    }
#if defined(WITH_SMARTLINK)
    if(wifi_global.init(esp_open_rtos::wifi::wifi_t::mode_smartlink) != 0) {
        printf("main(): wifi_global.init() != 0\n");
    }
//#elif defined(WITH_SMARTWEB)
//    if(wifi_global.init() != 0) {
//        printf("main(): wifi_global.init() != 0\n");
//    }
#else
    if(wifi_global.init(WIFI_SSID, WIFI_PASS) != 0) {
        printf("main(): wifi_global.init(WIFI_SSID, WIFI_PASS) != 0\n");
    }
#endif
    else if(wifi_global.task_create("wifi") != 0) {
        printf("main(): wifi_global.task_create(wifi) != 0\n");
    }
    //else if(mdns.init(wifi_global) != 0) {
    //    printf("main(): mdns.init(wifi_global) != 0\n");
    //}
    //else if(mdns.task_create("mdns_task") != 0) {
    //    printf("main(): mdns.task_create(mdns_task) != 0\n");
    //}
    //else if(mqtt_client1.init(mqtt_pub.m_Mqtt_payload.mqtt_queue(), wifi_global, "test.mosquitto.org") != 0) {
    //    printf("main(): mqtt_client1.init(mqtt_pub.m_Mqtt_payload.mqtt_queue(), wifi_global, test.mosquitto.org) != 0\n");
    //}
    //else if(mqtt_client2.init(mqtt_pub.m_Mqtt_payload.mqtt_queue(), wifi_global, "192.168.1.82") != 0) {
        //printf("main(): \n");
    //}
    //else if(mqtt_client1.task_create("MQTT_task_1") != 0) {
    //    printf("main(): mqtt_client1.task_create(MQTT_task_1) != 0\n");
    //}
    ////else if(mqtt_client2.task_create("MQTT_task_2") != 0) {
    ////    printf("main(): mqtt_client2.task_create(MQTT_task_2) != 0\n");
    ////}
    //else if(mqtt_pub.init(mqtt_client1) != 0) {
    //    printf("main(): mqtt_pub.init(mqtt_client1) != 0\n");
    //}
    //else if(mqtt_pub.task_create("mqtt_pub_1") != 0) {
    //    printf("main(): mqtt_pub.task_create(mqtt_pub_1) != 0\n");
    //}
}
Пример #2
0
// Setup HW
void user_setup(void)
{
    // Set UART Parameter
    uart_set_baud(0, 115200);

    // Give the UART some time to settle
    sdk_os_delay_us(500);
}
Пример #3
0
void usleep(uint_t microseconds)
{
	uint_t ticks = microseconds / (1000 * portTICK_RATE_MS);
	if (ticks > 0)
	{
		vTaskDelay(ticks);
	}

	uint_t remainder = microseconds % (1000 * portTICK_RATE_MS);
	while (remainder > 1000)
	{
		sdk_os_delay_us(1000);
		remainder -= 1000;
	}

	if (remainder > 0)
	{
		sdk_os_delay_us(remainder);
	}
}
Пример #4
0
void OS_MSleep(uint_t msec)
{
	uint_t ticks = msec / portTICK_RATE_MS;
	if (ticks > 0)
	{
		vTaskDelay(ticks);
	}

	uint_t remainder = msec % portTICK_RATE_MS;
	while (remainder > 0)
	{
		sdk_os_delay_us(1000);
		remainder--;
	}
}
Пример #5
0
void user_init(void)
{
    uart_set_baud(0, 115200);
    printf("SDK version:%s\n", sdk_system_get_sdk_version());

    i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_100K);

    hd44780_t lcd = {
        .i2c_dev.bus = I2C_BUS,
        .i2c_dev.addr = ADDR,
        .font = HD44780_FONT_5X8,
        .lines = 2,
        .pins = {
            .rs = 0,
            .e  = 2,
            .d4 = 4,
            .d5 = 5,
            .d6 = 6,
            .d7 = 7,
            .bl = 3
        },
        .backlight = true
    };

    hd44780_init(&lcd);
    hd44780_upload_character(&lcd, 0, char_data);
    hd44780_upload_character(&lcd, 1, char_data + 8);

    hd44780_gotoxy(&lcd, 0, 0);
    hd44780_puts(&lcd, "\x08 Hello world!");
    hd44780_gotoxy(&lcd, 0, 1);
    hd44780_puts(&lcd, "\x09 ");

    char time[16];

    while (true)
    {
        hd44780_gotoxy(&lcd, 2, 1);

        snprintf(time, 7, "%u     ", sdk_system_get_time() / 1000000);
        time[sizeof(time) - 1] = 0;

        hd44780_puts(&lcd, time);

        for (uint32_t i = 0; i < 1000; i++)
            sdk_os_delay_us(1000);
    }
}
Пример #6
0
void user_init(void)
{
    // Set UART Parameter
    uart_set_baud(0, 115200);
    // Give the UART some time to settle
    sdk_os_delay_us(500);

    /** -- MANDATORY PART -- */

    // Init all I2C bus interfaces at which BME680 sensors are connected
    i2c_init(I2C_BUS, I2C_SCL_PIN, I2C_SDA_PIN, I2C_FREQ_100K);

    // Init the sensors
    sensor1 = bme680_init_sensor (I2C_BUS, BME680_I2C_ADDRESS_2, 0);
    sensor2 = bme680_init_sensor (SPI_BUS, 0, SPI_CS_GPIO);

    if (sensor1 && sensor2)
    {
        /** -- SENSOR CONFIGURATION PART (optional) --- */

        // Changes the oversampling rates for both sensor to different values
        bme680_set_oversampling_rates(sensor1, osr_4x, osr_2x, osr_1x);
        bme680_set_oversampling_rates(sensor2, osr_8x, osr_8x, osr_8x);

        // Change the IIR filter size for temperature and and pressure to 7.
        bme680_set_filter_size(sensor1, iir_size_7);
        bme680_set_filter_size(sensor2, iir_size_7);

        // Change the heater profile 0 to 200 degree Celcius for 150 ms.
        bme680_set_heater_profile (sensor1, 0, 200, 150);
        bme680_set_heater_profile (sensor2, 0, 200, 150);

        // Activate the heater profile 0
        bme680_use_heater_profile (sensor1, 0);
        bme680_use_heater_profile (sensor2, 0);

        /** -- TASK CREATION PART --- */

        // must be done last to avoid concurrency situations with the sensor 
        // configuration part

        // Create the tasks that use the sensors
        xTaskCreate(user_task_sensor1, "user_task_sensor1", 256, NULL, 2, 0);
        xTaskCreate(user_task_sensor2, "user_task_sensor2", 256, NULL, 2, 0);
    }
}