#include "ui_task.h" updata updata_struct_to_ui; // u_int32_t timeOut = 10000; IS3 is3; // uint16_t is3_data[515]; // uint16_t is3_dark_data[515]; typedef struct { uint16_t s_data[515]; uint16_t dark_data[515]; uint16_t wr_data[515]; uint16_t s_average_data[515]; // uint16_t opt_data[515]; // uint16_t plot_data[515]; } is3_data_t; is3_data_t is3_data; EventGroupHandle_t is3_event_group; DynamicJsonDocument califile_doc(1024); DynamicJsonDocument SpectralInfo_doc(1024); DynamicJsonDocument sys_doc(1024); DynamicJsonDocument file_doc(1024); String SpectralInfo_data_str; IRIS_Time_Struct hh3_time_structure; SpectralData_Section_Header SpectralData_header; SpectralInfo_Section_Header SpectralInfo_header; Other__Section_Header Other_header; Image_Section_Header Image_header; picture image_picture; HH3_data_struct hh3_data_s_dn; HH3_data_struct hh3_data_dark_dn; HH3_data_struct hh3_data_wr_dn; califlie_data_struct hh3_data_flat_ref; HH3califlie hh3_califlie_struct; HH3califlie hh3_flatfile_struct; SemaphoreHandle_t xMutexInventory = NULL; //创建信号量Handler EventGroupHandle_t ui_event_group; EventGroupHandle_t ui_event_group2; uint32_t dc_wr_time = 0; uint32_t system_time_count = 0; uint32_t califile_Count = 0; uint8_t *file_data = NULL; const uint32_t file_heap_size = 60 * 1024; uint32_t stop_polt = 0; // 任务句柄声明 TaskHandle_t updata_to_ui_TaskHandle; TaskHandle_t get_is3_TaskHandle; TaskHandle_t main_2_plot_TaskHandle; TaskHandle_t main_2_opt_TaskHandle; TaskHandle_t main_2_dc_TaskHandle; TaskHandle_t main_2_save_TaskHandle; TaskHandle_t main_2_wr_TaskHandle; TaskHandle_t set_it_TaskHandle; TaskHandle_t main_2_rad_TaskHandle; TaskHandle_t red_ray_TaskHandle; TaskHandle_t power_off_TaskHandle; TaskHandle_t play_music_TaskHandle; TaskHandle_t fiber_sel_TaskHandle; TaskHandle_t calculate_average_TaskHandle; TaskHandle_t ui_time_TaskHandle; TaskHandle_t show_data_TaskHandle; TaskHandle_t set_system_time_TaskHandle; TaskHandle_t save_path_TaskHandle; volatile uint32_t pc_sta = 0; void ui_task_init(void) { xTaskCreatePinnedToCore(updata_to_ui, "updata", 1024*(3 ), NULL, 21, &updata_to_ui_TaskHandle, 1); xTaskCreatePinnedToCore(main_2_opt, "opt_task", 1024*(4 ), NULL, 25, &main_2_opt_TaskHandle, 1); xTaskCreatePinnedToCore(main_2_plot, "plot_task", 1024*(2 ), NULL, 25, &main_2_plot_TaskHandle, 1); xTaskCreatePinnedToCore(main_2_dc, "dc_task", 1024*(4 ), NULL, 25, &main_2_dc_TaskHandle, 1); xTaskCreatePinnedToCore(main_2_save, "save_task", 1024*(6 +2), NULL, 25, &main_2_save_TaskHandle, 1); xTaskCreatePinnedToCore(main_2_wr, "wr_task", 1024*(4 ), NULL, 25, &main_2_wr_TaskHandle, 1); xTaskCreatePinnedToCore(get_is3_data, "get_is3_task", 1024*(6 ), NULL, 30, &get_is3_TaskHandle, 1); xTaskCreatePinnedToCore(set_it_task, "set_it_task", 1024*(4 ), NULL, 25, &set_it_TaskHandle, 1); xTaskCreatePinnedToCore(main_2_rad, "set_polt_type", 1024*(2 ), NULL, 21, &main_2_rad_TaskHandle, 1); xTaskCreatePinnedToCore(red_ray_task, "red_ray_task", 1024*(1), NULL, 21, &red_ray_TaskHandle, 1); xTaskCreatePinnedToCore(power_off_task, "power_off_task", 1024*(1 ), NULL, 21, &power_off_TaskHandle, 1); xTaskCreatePinnedToCore(play_music_task, "play_music_task", 1024*(4 ), NULL, 29, &play_music_TaskHandle, 1); xTaskCreatePinnedToCore(fiber_sel_task, "fiber_sel_task", 1024*(8), NULL, 21, &fiber_sel_TaskHandle, 1); xTaskCreatePinnedToCore(calculate_average_task, "average_task", 1024*(4 ), NULL, 28, &calculate_average_TaskHandle, 1); xTaskCreatePinnedToCore(ui_time_task, "ui_time_task", 1024*(1 ), NULL, 21, &ui_time_TaskHandle, 1); xTaskCreatePinnedToCore(show_data_task, "show_data_task", 1024*(8 ), NULL, 21, &show_data_TaskHandle, 1); xTaskCreatePinnedToCore(set_system_time_task, "set_time_task", 1024*(2 ), NULL, 21, &set_system_time_TaskHandle, 1); xTaskCreatePinnedToCore(save_path_task, "save_path_task", 1024*(4 ), NULL, 21, &save_path_TaskHandle, 1); xTaskCreatePinnedToCore(pc_mode_task, "pc_mode_task", 1024*8, NULL, 21, NULL, 1); xTaskCreatePinnedToCore(flat_task, "flat_task", 1024*8, NULL, 21, NULL, 1); } // 挂起所有任务 void suspend_all_tasks(void) { // xEventGroupWaitBits(is3_event_group, IS3_UPDATA_BIT, pdTRUE, pdFALSE, portMAX_DELAY); // xEventGroupWaitBits(is3_event_group, IS3_UPDATA_BIT, pdTRUE, pdFALSE, portMAX_DELAY); // vTaskSuspend(updata_to_ui_TaskHandle); // xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE1_BIT, pdTRUE, pdFALSE, portMAX_DELAY); // xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE1_BIT, pdTRUE, pdFALSE, portMAX_DELAY); // vTaskSuspend(get_is3_TaskHandle); pc_sta = 1; } // 恢复所有任务 void resume_all_tasks(void) { // vTaskResume(updata_to_ui_TaskHandle); // vTaskResume(get_is3_TaskHandle); pc_sta = 0; } void get_is3_data(void *pvParameters) { uint16_t read_buff[515]; uint32_t it = 15; uint32_t a; double a1, a2, a3, a4; a1 = is3.a1; a2 = is3.a2; a3 = is3.a3; a4 = is3.a4; // Serial0.printf("a1:%f,a2:%f,a3:%f,a4:%f\n", a1, a2, a3, a4); while (1) { while (pc_sta == 1) { vTaskDelay(100); } bool suc = is3.get_data((uint8_t *) read_buff); if(suc == false) { // Serial0.println("get_is3_data fail"); // vTaskDelay(10); vTaskDelay(it*2); a++; // if(a > 20) // { // is3.reset(); // // vTaskDelay(2000); // } continue; } // Serial0.println("get_is3_data ok"); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { //反 // int n = 0 ; // for (int i = 512; i >= 0; i--) // { // // double x= a1*i*i*i + a2*i*i + a3*i + a4; // is3_data.s_data[n] = read_buff[i]; // n++; // } // 正 for (int i = 0; i < 515; i++) { is3_data.s_data[i] = read_buff[i]; } // is3_data.s_data[513] = read_buff[513]; // is3_data.s_data[514] = read_buff[514]; it = is3.integration_time; xSemaphoreGive(xMutexInventory); } // a++; // Serial0.println("get_is3_data ook"); // // float is3_temperature; // // is3.get_is3_temperature(&is3_temperature); xEventGroupSetBits(is3_event_group, IS3_GET_DATA_DONE_BIT); xEventGroupSetBits(is3_event_group, IS3_GET_DATA_DONE0_BIT); xEventGroupSetBits(is3_event_group, IS3_GET_DATA_DONE1_BIT); xEventGroupSetBits(is3_event_group, IS3_GET_DATA_DONE2_BIT); xEventGroupSetBits(is3_event_group, IS3_GET_DATA_DONE3_BIT); xEventGroupSetBits(is3_event_group, IS3_GET_DATA_DONE4_BIT); xEventGroupSetBits(is3_event_group, IS3_GET_DATA_DONE5_BIT); // Serial0.println("get_is3_data done"); vTaskDelay(it/2 + 4); } } void calculate_average_task(void *pvParameters) { uint16_t average_buffer[515]; uint32_t S_count= 0; while (1) { uint32_t a=0; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { S_count = updata_struct_to_ui.S_count; xSemaphoreGive(xMutexInventory); } while(S_count--) { xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE_BIT, pdTRUE, pdFALSE, portMAX_DELAY); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { for(uint16_t i = 0; i < 515; i++) { average_buffer[i] = (average_buffer[i] * a + is3_data.s_data[i])/(a+1); } xSemaphoreGive(xMutexInventory); } a++; } if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { for(uint16_t i = 0; i < 512; i++) { is3_data.s_average_data[i] = average_buffer[i]; } xSemaphoreGive(xMutexInventory); } xEventGroupSetBits(is3_event_group, IS3_AVERAGE_DONE1_BIT); xEventGroupSetBits(is3_event_group, IS3_AVERAGE_DONE2_BIT); } } void updata_to_ui(void *pvParameters) { uint32_t aa = 0; while (1) { while (pc_sta == 1) { vTaskDelay(100); } uint32_t Brightness,volume,last_Brightness,last_volume; uint8_t system_save = 0; uint8_t sd_sta = 0; // bool wifi_sw; // bool bluetooth_sw; bool screen_sw; uint16_t screen_keep_time; float temperature, humidity ,voltage; ds1307_date ds1307_date; t_sQMI8658 qmi8658_data; hh3_slave_data slave_data = {0,0,0,0,0}; if(get_sd_card_status() == false) sd_sta = 0; else sd_sta = 1; get_aht10_data(&temperature, &humidity); get_hh3_slave_data(&slave_data); qmi8658_fetch_angleFromAcc(&qmi8658_data); // 获取倾角 ds1307_get_time(&ds1307_date); float sd_used = get_sd_used_percent(); voltage = get_voltage(); if(slave_data.gps_sta != 3) { slave_data.gps_lat = 39.56; slave_data.gps_lon = 116.28; } if(slave_data.height_sta != 3) { slave_data.height = 0; } // Serial0.printf("gps_sta:%d,gps_lat:%f,gps_lon:%f\n", slave_data.gps_sta, slave_data.gps_lat,slave_data.gps_lon); // Serial0.printf("height_sta:%d,height:%f\n", slave_data.height_sta, slave_data.height); // height_sta String system_info; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { updata_struct_to_ui.sd_used_precent = sd_used; // updata_struct_to_ui.W_count = 10; // updata_struct_to_ui.D_count = 10; // updata_struct_to_ui.S_count = 10; if(updata_struct_to_ui.mode == 0) dc_wr_time = 0; updata_struct_to_ui.dc_wr_time = dc_wr_time; updata_struct_to_ui.height_sta = slave_data.height_sta; updata_struct_to_ui.gps_sta = slave_data.gps_sta; updata_struct_to_ui.gps_lat = slave_data.gps_lat; updata_struct_to_ui.gps_lon = slave_data.gps_lon; updata_struct_to_ui.voltage = voltage; updata_struct_to_ui.temperature = temperature; updata_struct_to_ui.humidity = humidity; // strcpy(updata_struct_to_ui.save_path, "test"); // updata_struct_to_ui.save_num = 10; updata_struct_to_ui.height = slave_data.height; updata_struct_to_ui.integration_time = is3.integration_time; updata_struct_to_ui.AngleX = qmi8658_data.AngleX; updata_struct_to_ui.AngleY = qmi8658_data.AngleY; updata_struct_to_ui.AngleZ = qmi8658_data.AngleZ; updata_struct_to_ui.year = ds1307_date.year; updata_struct_to_ui.month = ds1307_date.month; updata_struct_to_ui.day = ds1307_date.day; updata_struct_to_ui.hour = ds1307_date.hour; updata_struct_to_ui.minute = ds1307_date.minute; updata_struct_to_ui.second = ds1307_date.second; hh3_time_structure.timezone = 0; hh3_time_structure.year = ds1307_date.year; hh3_time_structure.month = ds1307_date.month; hh3_time_structure.day = ds1307_date.day; hh3_time_structure.hour = ds1307_date.hour; hh3_time_structure.minute = ds1307_date.minute; hh3_time_structure.second = ds1307_date.second; hh3_time_structure.millisecond = 0; updata_struct_to_ui.sd_alert = sd_sta; String rtcdate_now = String(ds1307_date.year) + "-" + String(ds1307_date.month) + "-" + String(ds1307_date.day) + " " + String(ds1307_date.hour) + ":" + String(ds1307_date.minute) + ":" + String(ds1307_date.second); SpectralInfo_doc["info_type"] = "infolist"; SpectralInfo_doc["info_number"] = 2; JsonArray info_list = SpectralInfo_doc.createNestedArray("info_list"); // 第一个info对象 - devinfo JsonObject info0 = info_list.createNestedObject(); info0["info_type"] = "devinfo"; info0["sensor_id"] = is3.info; info0["bandnum"] = is3.bandnum; info0["IT"] = is3.integration_time; JsonObject wave_coeff = info0.createNestedObject("wave_coeff"); wave_coeff["a1"] = is3.a1; wave_coeff["a2"] = is3.a2; wave_coeff["a3"] = is3.a3; wave_coeff["a4"] = is3.a4; info0["termperature"] = is3.temperature; // 第二个info对象 - environment JsonObject info1 = info_list.createNestedObject(); info1["info_type"] = "environment"; info1["MN"] = "IS3-HH"; info1["SN"] = SN_2; info1["version"] = Version_3; info1["date"] = rtcdate_now; info1["humidity"] = humidity; info1["temperature"] = temperature; info1["height"] = slave_data.height; info1["voltage"] = voltage; info1["ForeOptics"] = updata_struct_to_ui.fiber_sel_type; info1["FiberLength"] = updata_struct_to_ui.fiber_sel_length; info1["FiberWidth"] = updata_struct_to_ui.fiber_sel_width; info1["cailifilePath"] = updata_struct_to_ui.fiber_path; info1["flatfile_name"] = sys_doc["flatfile_name"]; info1["save_count"] = updata_struct_to_ui.save_count; info1["save_interval"] = updata_struct_to_ui.save_time; info1["W_count"] = updata_struct_to_ui.W_count; info1["D_count"] = updata_struct_to_ui.D_count; info1["S_count"] = updata_struct_to_ui.S_count; // info1["mode"] = updata_struct_to_ui.mode; JsonObject gps = info1.createNestedObject("gps"); gps["status"] = slave_data.gps_sta; gps["longitude"] = slave_data.gps_lon; gps["latitude"] = slave_data.gps_lat; SpectralInfo_data_str.clear(); serializeJson(SpectralInfo_doc, SpectralInfo_data_str); SpectralInfo_doc.clear(); //////////////////////////////////////////////// Brightness = updata_struct_to_ui.brightness_value; volume = updata_struct_to_ui.volume_value; /////////////////////////sys_doc///////////////////////////// sys_doc["save_data_path"] = updata_struct_to_ui.save_path; sys_doc["W_count"] = updata_struct_to_ui.W_count; sys_doc["D_count"] = updata_struct_to_ui.D_count; sys_doc["S_count"] = updata_struct_to_ui.S_count; sys_doc["save_count"] = updata_struct_to_ui.save_count; sys_doc["save_time"] = updata_struct_to_ui.save_time ; sys_doc["save_data_num"] = updata_struct_to_ui.save_num; sys_doc["califile_num"] = updata_struct_to_ui.califile_num; sys_doc["brightness_value"] = updata_struct_to_ui.brightness_value; sys_doc["volume_value"] = updata_struct_to_ui.volume_value; sys_doc["ForeOptics_sel1"] = updata_struct_to_ui.ForeOptics_sel1 ; sys_doc["ForeOptics_sel2"] = updata_struct_to_ui.ForeOptics_sel2 ; sys_doc["ForeOptics_sel3"] = updata_struct_to_ui.ForeOptics_sel3 ; sys_doc["wifi_ssid"] = updata_struct_to_ui.wifi_ssid; sys_doc["wifi_pwd"] = updata_struct_to_ui.wifi_pwd; sys_doc["wifi_sw"] = updata_struct_to_ui.wifi_sw; sys_doc["bluetooth_sw"] = updata_struct_to_ui.bluetooth_sw; sys_doc["screen_keep_time"] = updata_struct_to_ui.screen_keep_time ; sys_doc["screen_sw"] = updata_struct_to_ui.screen_sw; sys_doc["set_save_num"] = updata_struct_to_ui.set_save_num; system_save = updata_struct_to_ui.system_save; //////////////////// screen_keep_time = updata_struct_to_ui.screen_keep_time; screen_sw = updata_struct_to_ui.screen_sw; if(screen_sw == false) system_time_count = 0; if(system_time_count < 60*screen_keep_time) Brightness = Brightness; else if(system_time_count > 60*(screen_keep_time + 1)) Brightness = 0; else Brightness = 50; xSemaphoreGive(xMutexInventory); } serializeJson(sys_doc, system_info); if(system_save) save_system_info(system_info); if(last_Brightness != Brightness) { setBrightness(Brightness); last_Brightness = Brightness; } if(last_volume != volume) { last_volume = volume; audio.setVolume(volume); play_music("/OK2.mp3"); } if(aa%200 == 0) { // write_log(system_info, LOG_LEVEL_INFO); // write_log(SpectralInfo_data_str, LOG_LEVEL_INFO); } if(voltage < 4.2) { if(aa%20 == 0) { // play_music("meidian.mp3"); } } aa++; xEventGroupSetBits(is3_event_group, IS3_UPDATA_BIT); vTaskDelay(100 / portTICK_PERIOD_MS); } } void main_2_plot(void *pvParameters) { uint32_t a; while (1) { // xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE1_BIT, pdTRUE, pdFALSE, portMAX_DELAY); xEventGroupWaitBits(is3_event_group, IS3_AVERAGE_DONE1_BIT, pdTRUE, pdFALSE, portMAX_DELAY); if( stop_polt ) continue; uint32_t plot_type,it_time; uint16_t max = 0; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { updata_struct_to_ui.saturation_alert = 0; for (uint16_t i = 0; i < 512; i++) { // updata_struct_to_ui.plot_data[i] = is3_data.s_data[i]; updata_struct_to_ui.plot_data[i] = is3_data.s_average_data[i]; max = max < updata_struct_to_ui.plot_data[i] ? updata_struct_to_ui.plot_data[i] : max; } if(max > 65535 * 0.99) { updata_struct_to_ui.saturation_alert = 1; } plot_type = updata_struct_to_ui.plot_type; it_time = is3.integration_time; xSemaphoreGive(xMutexInventory); } if(max > 65535 * 0.99) play_music("/baojing.mp3"); //0 dn 1 rad 2 ref switch (plot_type) { case 0: { if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { for(uint16_t i = 0; i < 512; i++) { updata_struct_to_ui.plot_data[i] = updata_struct_to_ui.plot_data[i] - hh3_data_dark_dn.data[i]; } xSemaphoreGive(xMutexInventory); } } break; case 1: { if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { for(uint16_t i = 0; i < 512; i++) { updata_struct_to_ui.plot_data[i] = (double)(updata_struct_to_ui.plot_data[i] - hh3_data_dark_dn.data[i])/ (double)it_time *hh3_califlie_struct.gian.integration_time *(hh3_califlie_struct.gian.data[i] * 1000000); } xSemaphoreGive(xMutexInventory); } } break; case 2: { if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { for(uint16_t i = 0; i < 512; i++) { updata_struct_to_ui.plot_data[i] = (float)(updata_struct_to_ui.plot_data[i] - hh3_data_dark_dn.data[i]) / (float)(hh3_data_wr_dn.data[i] - hh3_data_dark_dn.data[i]) *hh3_data_flat_ref.data[i]* 10000; } xSemaphoreGive(xMutexInventory); } } break; default: break; } xEventGroupSetBits(ui_event_group, MAIN_2_PLOT_BIT); } } void main_2_opt(void *pvParameters) { while (1) { xEventGroupWaitBits(ui_event_group, MAIN_2_OPT_BIT, pdTRUE, pdFALSE, portMAX_DELAY); xEventGroupSetBits(ui_event_group, MAIN_2_OPT_ING_BIT); play_music("/baoguang.mp3"); // write_log("start opt", LOG_LEVEL_INFO); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { updata_struct_to_ui.bar_value = 0; updata_struct_to_ui.button2_count = 0; xSemaphoreGive(xMutexInventory); } uint32_t n = 100; bool suc; do { xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE1_BIT, pdTRUE, pdFALSE, portMAX_DELAY); suc = is3.set_shutter_time(12); } while (!suc); xEventGroupClearBits(is3_event_group, IS3_GET_DATA_DONE1_BIT); // xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE1_BIT, pdTRUE, pdFALSE, portMAX_DELAY); // is3.reset(); // xEventGroupClearBits(is3_event_group, IS3_GET_DATA_DONE1_BIT); // do // { // xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE1_BIT, pdTRUE, pdFALSE, portMAX_DELAY); // suc = is3.set_shutter_time(12); // } while (!suc); uint16_t set_shutter_time = is3.integration_time; while(n -- ) { uint16_t max = 0; xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE1_BIT, pdTRUE, pdFALSE, portMAX_DELAY); // vTaskSuspend(get_is3_TaskHandle); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { for (uint16_t i = 0; i < 515; i++) { max = max > is3_data.s_data[i] ? max : is3_data.s_data[i]; } xSemaphoreGive(xMutexInventory); } if ((max > 65535 * 0.7) && (max < 65535 * 0.8)) { // Serial0.println("max > 65535 * 0.7"); break; } if(max < ( 65535 * 0.8)) { float bbb = (65535.f*0.8) / (float)max; if(bbb > 6) set_shutter_time = set_shutter_time * 4; else if(bbb > 3) set_shutter_time = set_shutter_time * 2; else if(bbb > 2) set_shutter_time = set_shutter_time * 1.5; else if(bbb > 1.4) set_shutter_time = set_shutter_time * 1.3; else set_shutter_time = set_shutter_time * 1.2 + 1; } else { // set_shutter_time = set_shutter_time / 2; float bbb = (65535.f*0.8) / (float)max; set_shutter_time = set_shutter_time * bbb - 1; } do { if(set_shutter_time > 1100) { set_shutter_time = 1100; } if(set_shutter_time < 12) { set_shutter_time = 12; } xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE1_BIT, pdTRUE, pdFALSE, portMAX_DELAY); suc = is3.set_shutter_time(set_shutter_time); } while (!suc); if(set_shutter_time == 1100 || set_shutter_time == 12) break; } if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { system_time_count = 0; updata_struct_to_ui.bar_value = 40; updata_struct_to_ui.mode = 1; updata_struct_to_ui.plot_type = 0; xSemaphoreGive(xMutexInventory); } stop_polt = 1; dark_dn_collect(); xEventGroupWaitBits(is3_event_group, IS3_AVERAGE_DONE2_BIT, pdTRUE, pdFALSE, portMAX_DELAY); xEventGroupWaitBits(is3_event_group, IS3_AVERAGE_DONE2_BIT, pdTRUE, pdFALSE, portMAX_DELAY); stop_polt = 0; play_music("/OK2.mp3"); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { updata_struct_to_ui.bar_value = 100; xSemaphoreGive(xMutexInventory); } // write_log("end opt", LOG_LEVEL_INFO); xEventGroupClearBits(ui_event_group, MAIN_2_OPT_ING_BIT); // xEventGroupSetBits(ui_event_group, MAIN_2_DC_BIT); } } void main_2_wr(void *pvParameters) { while (1) { //wr xEventGroupWaitBits(ui_event_group, MAIN_2_WR_BIT, pdTRUE, pdFALSE, portMAX_DELAY); xEventGroupSetBits(ui_event_group, MAIN_2_WR_ING_BIT); play_music("/cankao.mp3"); // write_log("start wr", LOG_LEVEL_INFO); vTaskDelay(1000); // UBaseType_t watermark = uxTaskGetStackHighWaterMark(NULL); // Serial0.printf("updata_to_ui watermark: %u bytes\n", watermark); // Serial0.printf( "Free DMA heap: %d\n", heap_caps_get_free_size(MALLOC_CAP_DMA)); uint16_t n; float a,b; a = 0; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { updata_struct_to_ui.button2_count = 1; updata_struct_to_ui.bar_value = 0; n = updata_struct_to_ui.W_count; xSemaphoreGive(xMutexInventory); } b = n; while (n--) { //1更新polt xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE2_BIT, pdTRUE, pdFALSE, portMAX_DELAY); //2暗电流采集 if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { for (uint16_t i = 0; i < 515; i++) { /* code */ is3_data.wr_data[i] =((float)is3_data.wr_data[i]*(float)a + (float)is3_data.s_data[i])/(float)(a+1); } updata_struct_to_ui.bar_value = a/(b)*45; xSemaphoreGive(xMutexInventory); } a++; } wr_dn_pack(false); stop_polt = 1; dark_dn_collect(); xEventGroupWaitBits(is3_event_group, IS3_AVERAGE_DONE2_BIT, pdTRUE, pdFALSE, portMAX_DELAY); xEventGroupWaitBits(is3_event_group, IS3_AVERAGE_DONE2_BIT, pdTRUE, pdFALSE, portMAX_DELAY); stop_polt = 0; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { system_time_count = 0; if(updata_struct_to_ui.mode == 1) updata_struct_to_ui.mode = 2; updata_struct_to_ui.plot_type = 2; updata_struct_to_ui.bar_value = 100; xSemaphoreGive(xMutexInventory); } play_music("/OK2.mp3"); // write_log("end wr", LOG_LEVEL_INFO); xEventGroupClearBits(ui_event_group, MAIN_2_WR_BIT); xEventGroupClearBits(ui_event_group, MAIN_2_WR_ING_BIT); // xEventGroupSetBits(ui_event_group, MAIN_2_DC_BIT); } } void save_path_task(void *pvParameters) { String data_path = "/data"; while(1) { xEventGroupWaitBits(ui_event_group, MAIN_2_SAVE_PATH_BIT, pdTRUE, pdFALSE, portMAX_DELAY); uint32_t save_time; uint32_t save_num; String save_str,SpectralInfo_str; uint16_t year,month,day; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { save_time = updata_struct_to_ui.save_time; save_str = updata_struct_to_ui.save_path; save_num = updata_struct_to_ui.save_num; year = updata_struct_to_ui.year; month = updata_struct_to_ui.month; day = updata_struct_to_ui.day; xSemaphoreGive(xMutexInventory); } // String date_now = String(year) + "_" + String(month) + "_" + String(day); String date_now = String(year) + "_"; if(month < 10) date_now = date_now + "0" + String(month) + "_"; else date_now = date_now + String(month) + "_"; if(day < 10) date_now = date_now + "0" + String(day); else date_now = date_now + String(day); String save_path = data_path+ "/" + date_now ; // SD_MMC.mkdir(save_path);////// save_path = save_path + "/"; // String file_name = save_str + String(save_num) + ".iris"; char file_name_buf[128]; String file_name; sprintf(file_name_buf, "%s%04d.iris", save_str.c_str(), save_num); file_name = String(file_name_buf); while (SD_MMC.exists(save_path + file_name)) { save_num++; sprintf(file_name_buf, "%s%04d.iris", save_str.c_str(), save_num); file_name = String(file_name_buf); } if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { updata_struct_to_ui.save_num = save_num; xSemaphoreGive(xMutexInventory); } char file_num_str[32]; snprintf(file_num_str, sizeof(file_num_str), "%04u", save_num); lv_textarea_set_text(guider_ui.Setting_filename_ta_2, file_num_str); } } void main_2_save(void *pvParameters) { uint32_t save_num = 0; String data_path = "/data"; while (1) { //save xEventGroupWaitBits(ui_event_group, MAIN_2_SAVE_BIT, pdTRUE, pdFALSE, portMAX_DELAY); USB_CAM_SetResolution(800,480); if(get_sd_card_status() == false) { continue; } xEventGroupSetBits(ui_event_group,MAIN_2_SAVE_ING_BIT); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { updata_struct_to_ui.button2_count = 2; updata_struct_to_ui.bar_value = 0; image_picture.length = 0; xSemaphoreGive(xMutexInventory); } close_ceju(); play_music("/baocun.mp3"); // write_log("start save", LOG_LEVEL_INFO); //打开相机 vTaskDelay(100); // if(image_picture.length != 0) // { // // play_music("/baojing.mp3"); // vTaskDelay(5 * 1000); // } uint16_t save_count; uint32_t save_time; uint32_t save_num; uint8_t mode; String save_str,SpectralInfo_str; uint16_t year,month,day; // hour,minute,second; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { updata_struct_to_ui.button2_count = 2; save_count = updata_struct_to_ui.save_count; save_time = updata_struct_to_ui.save_time; save_str = updata_struct_to_ui.save_path; save_num = updata_struct_to_ui.save_num; mode = updata_struct_to_ui.mode; year = updata_struct_to_ui.year; month = updata_struct_to_ui.month; day = updata_struct_to_ui.day; // hour = updata_struct_to_ui.hour; // minute = updata_struct_to_ui.minute; // second = updata_struct_to_ui.second; SpectralInfo_str = SpectralInfo_data_str; xSemaphoreGive(xMutexInventory); } String date_now = String(year) + "_"; if(month < 10) date_now += "0" + String(month) + "_"; else date_now += String(month) + "_"; if(day < 10) date_now += "0" + String(day); else date_now += String(day); String save_path = data_path + "/" + date_now ; // SD_MMC.mkdir(save_path); if(SD_MMC.exists(save_path) == false) { SD_MMC.mkdir(save_path); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { save_num = updata_struct_to_ui.set_save_num; updata_struct_to_ui.save_num = save_num; xSemaphoreGive(xMutexInventory); } } save_path = save_path + "/"; char file_name_buf[128]; String file_name; sprintf(file_name_buf, "%s%04d.iris", save_str.c_str(), save_num); file_name = String(file_name_buf); while (SD_MMC.exists(save_path + file_name)) { save_num++; sprintf(file_name_buf, "%s%04d.iris", save_str.c_str(), save_num); file_name = String(file_name_buf); } float a=0,b; b=save_count; xEventGroupClearBits(is3_event_group, IS3_AVERAGE_DONE2_BIT); xEventGroupWaitBits(is3_event_group, IS3_AVERAGE_DONE2_BIT, pdTRUE, pdFALSE, portMAX_DELAY); while(save_count --) { xEventGroupWaitBits(is3_event_group, IS3_AVERAGE_DONE2_BIT, pdTRUE, pdFALSE, portMAX_DELAY); // xEventGroupClearBits(is3_event_group, IS3_CAM_DONE_BIT); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { // system_time_count = 0; updata_struct_to_ui.save_num = save_num; SpectralInfo_str = SpectralInfo_data_str; updata_struct_to_ui.system_save = 1; image_picture.length = 0; image_picture.Squantity = 0; xSemaphoreGive(xMutexInventory); } // char file_name_buf[64]; sprintf(file_name_buf, "%s%04d.iris", save_str.c_str(), save_num); file_name = String(file_name_buf); // file_name = save_str + String(save_num) + ".iris"; // Serial0.println(String(save_count)); // Serial0.println("save_path : " + save_path + file_name); header_pack(SpectralInfo_str); // Serial0.println("header_pack"); Ground_DN_pack(); // Serial0.println("Ground_DN_pack"); wr_dn_pack(true); // Serial0.println("wr_dn_pack"); dark_dn_pack(true); // Serial0.println("dark_dn_pack"); flat_ref_pack(); // Serial0.println("flat_ref_pack"); picture_pack(save_str,String(save_num)); // Serial0.println("picture_pack"); save_data(save_path,file_name,SpectralInfo_str); // Serial0.println("save_data"); a++; save_num++; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { updata_struct_to_ui.save_num = save_num; updata_struct_to_ui.bar_value = a/(b) * 90; xSemaphoreGive(xMutexInventory); } uint32_t t = save_time * 1000; if(save_count != 0) vTaskDelay(t); // write_log("end save", LOG_LEVEL_INFO); xEventGroupClearBits(is3_event_group, IS3_AVERAGE_DONE2_BIT); } read_data_from_file(save_path + file_name); USB_CAM_SetResolution(480,320); play_music("/OK2.mp3"); open_ceju(); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { updata_struct_to_ui.system_save = 1; updata_struct_to_ui.bar_value = 100; xSemaphoreGive(xMutexInventory); } xEventGroupClearBits(ui_event_group, MAIN_2_SAVE_BIT); xEventGroupClearBits(ui_event_group, MAIN_2_SAVE_ING_BIT); } } void dark_dn_collect() { bool shutter_flag = false; xEventGroupClearBits(is3_event_group, IS3_GET_DATA_DONE4_BIT); do { xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE4_BIT, pdTRUE, pdFALSE, portMAX_DELAY); // Serial0.println("dark_dn_collect"); shutter_flag = is3.close_shutter(); } while (!shutter_flag); vTaskDelay(500); // xEventGroupClearBits(is3_event_group, IS3_GET_DATA_DONE4_BIT); xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE4_BIT, pdTRUE, pdFALSE, portMAX_DELAY); // xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE4_BIT, pdTRUE, pdFALSE, portMAX_DELAY); // xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE4_BIT, pdTRUE, pdFALSE, portMAX_DELAY); uint16_t n; float a = 0; float bar ; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { n = updata_struct_to_ui.D_count; bar = updata_struct_to_ui.bar_value; xSemaphoreGive(xMutexInventory); } float b = n; while (n--) { //1更新polt xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE4_BIT, pdTRUE, pdFALSE, portMAX_DELAY); //2暗电流采集 if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { for (uint16_t i = 0; i < 515; i++) { /* code */ is3_data.dark_data[i] = (is3_data.dark_data[i]*a + is3_data.s_data[i])/(a+1); } a++; if(bar > 30) updata_struct_to_ui.bar_value = a/b *45 + 45; else { updata_struct_to_ui.bar_value = a/b *90; } xSemaphoreGive(xMutexInventory); } // Serial0.printf("dark n : %d\n",n); } dark_dn_pack(false); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { system_time_count = 0; if(updata_struct_to_ui.mode == 0) updata_struct_to_ui.mode = 1; dc_wr_time = 0; xSemaphoreGive(xMutexInventory); } // vTaskSuspend(get_is3_TaskHandle); xEventGroupClearBits(is3_event_group, IS3_GET_DATA_DONE4_BIT); do { xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE4_BIT, pdTRUE, pdFALSE, portMAX_DELAY); shutter_flag = is3.open_shutter(); } while (!shutter_flag); // vTaskResume(main_2_plot_TaskHandle); } void main_2_dc(void *pvParameters) { while(1) { //dc xEventGroupWaitBits(ui_event_group, MAIN_2_DC_BIT, pdTRUE, pdFALSE, portMAX_DELAY); xEventGroupSetBits(ui_event_group, MAIN_2_DC_ING_BIT); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { updata_struct_to_ui.bar_value = 0; xSemaphoreGive(xMutexInventory); } play_music("/andianliu.mp3"); // write_log("start dc ", LOG_LEVEL_INFO); // vTaskSuspend(get_is3_TaskHandle); dark_dn_collect(); // vTaskDelay(2000 / portTICK_PERIOD_MS); vTaskDelay(1000); play_music("/OK2.mp3"); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { updata_struct_to_ui.button2_count = 4; updata_struct_to_ui.bar_value = 100; xSemaphoreGive(xMutexInventory); } // write_log("end dc ", LOG_LEVEL_INFO); xEventGroupClearBits(ui_event_group, MAIN_2_DC_BIT); xEventGroupClearBits(ui_event_group, MAIN_2_DC_ING_BIT); } } void power_off_task(void *pvParameters) { while(1) { xEventGroupWaitBits(ui_event_group,POWER_OFF_BIT, pdTRUE, pdFALSE, portMAX_DELAY); // write_log("power", LOG_LEVEL_INFO); vTaskDelay(3000); // xEventGroupWaitBits(is3_event_group,IS3_GET_DATA_DONE5_BIT, pdTRUE, pdFALSE, portMAX_DELAY); // xEventGroupWaitBits(ui_event_group,TOP_UPDATA_BIT, pdTRUE, pdFALSE, portMAX_DELAY); vTaskSuspend(updata_to_ui_TaskHandle); // vTaskSuspend(get_is3_TaskHandle); SD_MMC.end(); esp_restart(); } } void set_it_task(void *pvParameters) { while(1) { xEventGroupWaitBits(ui_event_group, SET_INTEGRATION_TIME_BIT, pdTRUE, pdFALSE, portMAX_DELAY); uint32_t shutter_time ; if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS) { shutter_time = updata_struct_to_ui.set_integration_time; xSemaphoreGive(xMutexInventory); } bool suc; // vTaskSuspend(get_is3_TaskHandle); do { // xEventGroupWaitBits(is3_event_group, IS3_GET_DATA_DONE5_BIT, pdTRUE, pdFALSE, portMAX_DELAY); suc = is3.set_shutter_time(shutter_time); vTaskDelay(1); } while (!suc); // vTaskResume(get_is3_TaskHandle); if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS) { updata_struct_to_ui.mode = 0; updata_struct_to_ui.button2_count = 0; updata_struct_to_ui.plot_type = 0; xSemaphoreGive(xMutexInventory); } play_music("/OK2.mp3"); // write_log("set_it : " + String(shutter_time), LOG_LEVEL_INFO); // xEventGroupSetBits(ui_event_group, MAIN_2_DC_BIT); } } void main_2_rad(void *pvParameters) { while(1) { xEventGroupWaitBits(ui_event_group,MAIN_2_RAD_BIT,pdTRUE,pdFALSE,portMAX_DELAY); if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS) { updata_struct_to_ui.button2_count = 3; updata_struct_to_ui.plot_type ++; updata_struct_to_ui.plot_type = updata_struct_to_ui.plot_type > 2 ? 0 : updata_struct_to_ui.plot_type; switch (updata_struct_to_ui.mode) { case 0: updata_struct_to_ui.plot_type = 0; break; case 1: updata_struct_to_ui.plot_type = updata_struct_to_ui.plot_type > 1 ? 0 : updata_struct_to_ui.plot_type; if(updata_struct_to_ui.califile_num == 0 && updata_struct_to_ui.plot_type == 1) updata_struct_to_ui.plot_type = 0; break; case 2: updata_struct_to_ui.plot_type = updata_struct_to_ui.plot_type > 2 ? 0 : updata_struct_to_ui.plot_type; if(updata_struct_to_ui.califile_num == 0 && updata_struct_to_ui.plot_type == 1) updata_struct_to_ui.plot_type = 2; break; default: break; } xSemaphoreGive(xMutexInventory); } } } void red_ray_task(void* arg) { while (1) { xEventGroupWaitBits(is3_event_group,RED_RAY_BIT,pdTRUE, pdFALSE,portMAX_DELAY); EventBits_t uxBits = xEventGroupGetBits(ui_event_group); if ((uxBits & MAIN_2_OPT_ING_BIT) || (uxBits & MAIN_2_DC_ING_BIT) || (uxBits & MAIN_2_WR_ING_BIT) || (uxBits & MAIN_2_SAVE_ING_BIT)) continue; red_ray_on(); vTaskDelay(1000); red_ray_off(); } } void play_music_task(void* arg) { while (1) { xEventGroupWaitBits(ui_event_group,MUSIC_BIT,pdTRUE,pdFALSE,portMAX_DELAY); String music_path; if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS) { music_path = updata_struct_to_ui.music_path; memset(updata_struct_to_ui.music_path,'\0',sizeof(updata_struct_to_ui.music_path)); xSemaphoreGive(xMutexInventory); } const char* path = music_path.c_str(); // Serial0.println(path); if(language == chinese) audio.connecttoFS(SPIFFS, path); else if(language == english) { music_path = "/config/music/english/" + music_path; const char* path_2 = music_path.c_str(); audio.connecttoFS(SD_MMC, path_2); } while (audio.isRunning()) { audio.loop(); vTaskDelay(1); } } } bool is_leap_year(uint32_t year) { return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)); } void set_system_time_task(void *pvParameters) { while(1) { xEventGroupWaitBits(ui_event_group,SET_SYSTEM_TIME_BIT,pdTRUE,pdFALSE,portMAX_DELAY); bool flag = true; uint16_t year,month,day,hour,minute,second; if (xSemaphoreTake(lvgl_mutex, portMAX_DELAY)) { const char * year_str = lv_textarea_get_text(guider_ui.Setting_system_ta_3); year = (uint32_t)atoi(year_str); const char * month_str = lv_textarea_get_text(guider_ui.Setting_system_ta_5); month = (uint32_t)atoi(month_str); const char * day_str = lv_textarea_get_text(guider_ui.Setting_system_ta_4); day = (uint32_t)atoi(day_str); const char * hour_str = lv_textarea_get_text(guider_ui.Setting_system_ta_7); hour = (uint32_t)atoi(hour_str); const char * minute_str = lv_textarea_get_text(guider_ui.Setting_system_ta_6); minute = (uint32_t)atoi(minute_str); const char * second_str = lv_textarea_get_text(guider_ui.Setting_system_ta_8); second = (uint32_t)atoi(second_str); xSemaphoreGive(lvgl_mutex); } if(year < 2000 || year > 2099) flag = false;; if(month < 1 || month > 12) flag = false; if(day < 1 || day > 31) flag = false; if(hour < 0 || hour > 23) flag = false; if(minute < 0 || minute > 59) flag = false; if(second < 0 || second > 59) flag = false; const uint8_t days_in_month[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; uint8_t max_day = days_in_month[month - 1]; if(month == 2 && is_leap_year(year)) { max_day = 29; } if(day < 1 || day > max_day) flag = false; if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS) { updata_struct_to_ui.set_time_flag = flag; xSemaphoreGive(xMutexInventory); } if(!flag) continue; ds1307_set_time(year, month, day, hour, minute, second); } } void fiber_sel_task(void* arg) { while(1) { xEventGroupWaitBits(ui_event_group,FiBER_SEL_BIT , pdTRUE, pdFALSE, portMAX_DELAY); String fiber_type , fiber_length, fiber_width; if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS) { fiber_type = updata_struct_to_ui.fiber_sel_type; fiber_length = updata_struct_to_ui.fiber_sel_length; fiber_width = updata_struct_to_ui.fiber_sel_width; xSemaphoreGive(xMutexInventory); } uint32_t a = find_califile(fiber_type, fiber_length, fiber_width); califile_read(a); } } void ui_time_task(void *pvParameters) { while (1) { if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { dc_wr_time ++; if(updata_struct_to_ui.mode == 0) dc_wr_time = 0; system_time_count ++; xSemaphoreGive(xMutexInventory); } vTaskDelay(1000); } } void save_system_info(String system_info) { // if(!get_sd_card_status()) return; File file; file = SPIFFS.open("/system_tem.json", FILE_WRITE); // file = SD_MMC.open(system_tem_path, FILE_WRITE); file.println(system_info); file.flush(); file.close(); // Serial0.println("system_info="+ system_info); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { updata_struct_to_ui.system_save = 0; xSemaphoreGive(xMutexInventory); } } String read_system_info() { String system_info; // if(SD_MMC.exists(system_tem_path)) if(SPIFFS.exists("/system_tem.json")) { File file; // file = SD_MMC.open(system_tem_path, FILE_READ); file = SPIFFS.open("/system_tem.json", FILE_READ); system_info = file.readString(); file.flush(); file.close(); } else { return "-1"; } // Serial0.println("system_temp : "+system_info); return system_info; } bool califile_init() { File root = SD_MMC.open(califile_path); if (!root || !root.isDirectory()) { // Serial0.println("Failed to open directory"); root.close(); return false; } File file = root.openNextFile(); // Serial0.println("Listing files in directory:"); while (file) { if (!file.isDirectory()) { califile_Count++; califile_doc[String(califile_path)][String(califile_Count)]["name"] = String(file.name()); // Serial0.printf("FILE: %s, SIZE: %d bytes\n", file.name(), file.size()); } else { // Serial0.printf("DIR : %s\n", file.name()); } file.close(); file = root.openNextFile(); } String cali_str; serializeJson(califile_doc, cali_str); // Serial0.println(cali_str); // Serial0.println("califile_Count: " + String(califile_Count)); root.close(); return true; } bool califile_read(uint32_t califile_num) { if(califile_num == 0) { String str = "NULL"; if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS) { updata_struct_to_ui.califile_num = califile_num; memset(&hh3_califlie_struct, 1, sizeof(hh3_califlie_struct)); memset(updata_struct_to_ui.fiber_path, '\0', 100); strcpy(updata_struct_to_ui.fiber_path, str.c_str()); xSemaphoreGive(xMutexInventory); } return false; } String califile_name = califile_doc[String(califile_path)][String(califile_num)]["name"]; String read_file_path = String(califile_path) + "/" + califile_name; if(califile_name.indexOf("_180d") != -1) { if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS) { updata_struct_to_ui.IRAD = 1; xSemaphoreGive(xMutexInventory); } } else { if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS) { updata_struct_to_ui.IRAD = 0; xSemaphoreGive(xMutexInventory); } } // Serial0.println("read_file_path: " + read_file_path); // if(!SD_MMC.exists(read_file_path)) // { // Serial0.println("File not exist : "+ read_file_path); // String str = "NULL"; // if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS) // { // updata_struct_to_ui.califile_num = califile_num; // memset(&hh3_califlie_struct, 1, sizeof(hh3_califlie_struct)); // memset(updata_struct_to_ui.fiber_path, '\0', 100); // strcpy(updata_struct_to_ui.fiber_path, str.c_str()); // xSemaphoreGive(xMutexInventory); // } // return false; // } File file = SD_MMC.open(read_file_path,FILE_READ); uint32_t file_size = file.size(); file.read((uint8_t *)&hh3_califlie_struct, sizeof(hh3_califlie_struct)); file.flush(); file.close(); if(hh3_califlie_struct.gian.GroundType != califile || file_size < sizeof(hh3_califlie_struct)/2) { String str = "NULL"; if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS) { updata_struct_to_ui.califile_num = califile_num; memset(&hh3_califlie_struct, 1, sizeof(hh3_califlie_struct)); memset(updata_struct_to_ui.fiber_path, '\0', 100); strcpy(updata_struct_to_ui.fiber_path, str.c_str()); xSemaphoreGive(xMutexInventory); } // Serial0.println(read_file_path + " is not a califlie file"); return false; } if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS) { updata_struct_to_ui.califile_num = califile_num; memset(updata_struct_to_ui.fiber_path, '\0', 100); strcpy(updata_struct_to_ui.fiber_path, read_file_path.c_str()); updata_struct_to_ui.system_save = 1; xSemaphoreGive(xMutexInventory); } return true; } void fiber_fields() { uint32_t a = califile_Count; // String fiber_type = "无\n光纤\n"; // String fiber_width = "无\n"; // String fiber_length = "无\n"; String fiber_type = "光纤\n"; String fiber_width = ""; String fiber_length = ""; uint32_t fiber_count = 0; while(a) { String name = califile_doc[String(califile_path)][String(a)]["name"]; int f_pos = name.indexOf("_F_"); if (f_pos != -1) { int m_pos = name.indexOf("m_", f_pos); if (m_pos != -1) { String m_Str = name.substring(f_pos + 3, m_pos); if(fiber_length.indexOf(m_Str) == -1) fiber_length = fiber_length + m_Str + '\n'; } int d_pos = name.indexOf("d", f_pos); if (d_pos != -1 && d_pos > name.indexOf("m", f_pos)) { String d_Str = name.substring(m_pos+2, d_pos); if(fiber_width.indexOf(d_Str) == -1) fiber_width = fiber_width + d_Str + '\n'; } fiber_count++; } else { int d_pos = name.indexOf("d"); if (d_pos != -1) { int start = name.lastIndexOf("_", d_pos - 1); if (start != -1) { String d_Str = name.substring(start + 1, d_pos); if(fiber_type.indexOf(d_Str) == -1) fiber_type = fiber_type + d_Str + '\n'; } } } a--; } if(fiber_count == 0) fiber_type = fiber_type.substring(7, fiber_type.length()); strcpy(updata_struct_to_ui.fiber_type, fiber_type.c_str()); strcpy(updata_struct_to_ui.fiber_length, fiber_length.c_str()); strcpy(updata_struct_to_ui.fiber_width, fiber_width.c_str()); updata_struct_to_ui.fiber_type[fiber_type.length()-1] = '\0'; // updata_struct_to_ui.fiber_length[fiber_length.length()-1] = '\0'; // updata_struct_to_ui.fiber_width[fiber_width.length()-1] = '\0'; } uint32_t find_califile(String fiber_type, String fiber_length, String fiber_width) { uint32_t a; if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS) { a = califile_Count; xSemaphoreGive(xMutexInventory); } // Serial0.println("fiber_type: " + fiber_type); // Serial0.println("fiber_length: " + fiber_length); // Serial0.println("fiber_width: " + fiber_width); // 处理 fiber_type if (fiber_type == "g") { fiber_type = "_F_"; } else if ((fiber_type != "w") && (fiber_type != "_F_")) { fiber_type = "_" + fiber_type + "d_"; } else { fiber_type = "-1"; } // 处理 fiber_length if (fiber_length != "w") { fiber_length = "_" + fiber_length + "m_"; } else { fiber_length = "-1"; } // 处理 fiber_width if (fiber_width != "w") { fiber_width = "_" + fiber_width + "d_"; } else { fiber_width = "-1"; } if(fiber_type == "-1") { return 0; } String name2; // String find_str; // if(fiber_type == "_F_") find_str = fiber_type + fiber_length + fiber_width; // else find_str = fiber_type; while(a) { String name = califile_doc[String(califile_path)][String(a)]["name"]; // Serial0.println("name:" + name); if(fiber_type == "_F_") { if((name.indexOf(fiber_type) != -1) && (name.indexOf(fiber_length) != -1 )&& (name.indexOf(fiber_width) != -1)) { name2 = name; break; } // if(name.indexOf(find_str) != -1) // { // name2 = name; // break; // } } else { if((name.indexOf(fiber_type) != -1) && (name.indexOf("_F_") == -1)) { name2 = name; break; } } a--; } return a; } void system_data_init() { ui_event_group = xEventGroupCreate(); if (ui_event_group == NULL) { while (1) { // Serial0.println("ui_event_group create fail!"); vTaskDelay(1000 / portTICK_PERIOD_MS); // 停住系统防止崩溃 } } ui_event_group2 = xEventGroupCreate(); if (ui_event_group == NULL) { while (1) { // Serial0.println("ui_event_group create fail!"); vTaskDelay(1000 / portTICK_PERIOD_MS); // 停住系统防止崩溃 } } is3_event_group = xEventGroupCreate(); if (is3_event_group == NULL) { while (1) { // Serial0.println("is3_event_group create fail!"); vTaskDelay(1000 / portTICK_PERIOD_MS); // 停住系统防止崩溃 } } xMutexInventory = xSemaphoreCreateMutex(); //创建MUTEX // if(xMutexInventory == NULL) Serial0.println("xMutexInventory is NULL"); image_picture.data = (uint8_t *)heap_caps_malloc(55 * 1024, MALLOC_CAP_SPIRAM); assert(image_picture.data != NULL); file_data = (uint8_t *)heap_caps_malloc(file_heap_size, MALLOC_CAP_SPIRAM); memset(file_data, 0, file_heap_size); califile_init(); if(califile_Count != 0) fiber_fields(); uint32_t califile_num = 0; String system_info = read_system_info(); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { if(system_info !="-1") { deserializeJson(sys_doc, system_info); String save_data_path = sys_doc["save_data_path"]; updata_struct_to_ui.W_count = sys_doc["W_count"]; updata_struct_to_ui.W_count = updata_struct_to_ui.W_count > 1 ? updata_struct_to_ui.W_count : 1; updata_struct_to_ui.D_count = sys_doc["D_count"]; updata_struct_to_ui.D_count = updata_struct_to_ui.D_count > 1 ? updata_struct_to_ui.D_count : 1; updata_struct_to_ui.S_count = sys_doc["S_count"]; updata_struct_to_ui.S_count = updata_struct_to_ui.S_count > 1 ? updata_struct_to_ui.S_count : 1; updata_struct_to_ui.save_count = sys_doc["save_count"]; updata_struct_to_ui.save_count = updata_struct_to_ui.save_count > 1 ? updata_struct_to_ui.save_count : 1; updata_struct_to_ui.save_time = sys_doc["save_time"]; updata_struct_to_ui.save_time = updata_struct_to_ui.save_time > 0 ? updata_struct_to_ui.save_time : 0; updata_struct_to_ui.califile_num = sys_doc["califile_num"]; califile_num = updata_struct_to_ui.califile_num; updata_struct_to_ui.brightness_value = sys_doc["brightness_value"]; updata_struct_to_ui.brightness_value = updata_struct_to_ui.brightness_value > 50 ? updata_struct_to_ui.brightness_value : 50; updata_struct_to_ui.volume_value = sys_doc["volume_value"]; updata_struct_to_ui.ForeOptics_sel1 = sys_doc["ForeOptics_sel1"]; updata_struct_to_ui.ForeOptics_sel2 = sys_doc["ForeOptics_sel2"]; updata_struct_to_ui.ForeOptics_sel3 = sys_doc["ForeOptics_sel3"]; updata_struct_to_ui.wifi_sw = sys_doc["wifi_sw"]; updata_struct_to_ui.bluetooth_sw = sys_doc["bluetooth_sw"]; String wifi_ssid = sys_doc["wifi_ssid"]; String wifi_pwd = sys_doc["wifi_pwd"] ; strcpy(updata_struct_to_ui.wifi_ssid,wifi_ssid.c_str()); strcpy(updata_struct_to_ui.wifi_pwd,wifi_pwd.c_str()); updata_struct_to_ui.screen_keep_time = sys_doc["screen_keep_time"]; updata_struct_to_ui.screen_keep_time = updata_struct_to_ui.screen_keep_time > 1 ? updata_struct_to_ui.screen_keep_time : 1; updata_struct_to_ui.screen_sw = sys_doc["screen_sw"]; updata_struct_to_ui.set_save_num = sys_doc["set_save_num"]; strcpy(updata_struct_to_ui.save_path, save_data_path.c_str()); updata_struct_to_ui.save_num = sys_doc["save_data_num"]; } if ( system_info =="-1" || updata_struct_to_ui.W_count == 0) { updata_struct_to_ui.W_count = 10; updata_struct_to_ui.D_count = 25; updata_struct_to_ui.S_count = 10; updata_struct_to_ui.save_count = 1; updata_struct_to_ui.save_time = 0; updata_struct_to_ui.brightness_value = 255; updata_struct_to_ui.volume_value = 21; updata_struct_to_ui.set_save_num = 0; strcpy(updata_struct_to_ui.save_path, "data"); updata_struct_to_ui.save_num = 00; } updata_struct_to_ui.bar_value = 0; updata_struct_to_ui.mode = 0; updata_struct_to_ui.plot_type = 0; updata_struct_to_ui.button1_count = 0; updata_struct_to_ui.button2_count = 0; updata_struct_to_ui.set_time_flag = true; xSemaphoreGive(xMutexInventory); } if(califile_num != 0) califile_read(califile_num); else { // if(califile_Count != 0) califile_read(1); // else califile_read(0); } ds1307_date now; ds1307_get_time(&now); // String date_now = String(now.year) + "_" + String(now.month) + "_" + String(now.day); String date_now = String(now.year) + "_"; if(now.month < 10) date_now = date_now+"0" + String(now.month) + "_"; else date_now = date_now + String(now.month) + "_"; if(now.day < 10) date_now = date_now + "0" + String(now.day); else date_now = date_now + String(now.day); String save_path = "/data/" + date_now ; if(SD_MMC.exists(save_path) == false) { // SD_MMC.mkdir(save_path); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { uint32_t save_num = updata_struct_to_ui.set_save_num; updata_struct_to_ui.save_num = save_num; xSemaphoreGive(xMutexInventory); } } } void header_pack(String SpectralInfo_str) { if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { uint32_t SpectralData_Squantity = 2; uint32_t SpectralData_SectionLength = 2 + sizeof(hh3_data_s_dn) + sizeof(hh3_data_dark_dn); if(updata_struct_to_ui.mode == 2) { SpectralData_Squantity += 2; SpectralData_SectionLength = SpectralData_SectionLength+sizeof(hh3_data_wr_dn) + sizeof(hh3_data_flat_ref); } if(hh3_califlie_struct.gian.GroundType == califile) { SpectralData_Squantity ++; SpectralData_SectionLength += sizeof(hh3_califlie_struct.gian); } SpectralData_header.SectionFlag = SpectralData; SpectralData_header.SectionLength = SpectralData_SectionLength; SpectralData_header.Squantity = SpectralData_Squantity; SpectralInfo_header.SectionFlag = SpectralInfo; SpectralInfo_header.SectionLength = SpectralInfo_str.length() + 2 + 2 + 1; SpectralInfo_header.Squantity = SpectralInfo_Squantity; SpectralInfo_header.info1_length = SpectralInfo_str.length(); SpectralInfo_header.info1_type = 0x00; Other_header.SectionFlag = Other; Other_header.SectionLength = 0; Image_header.SectionFlag = Image; Image_header.SectionLength = 0; xSemaphoreGive(xMutexInventory); } } void Ground_DN_pack() { String save_str; uint32_t save_num; uint16_t max = 0; String name; char file_name_buf[64]; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { save_str = updata_struct_to_ui.save_path; save_num = updata_struct_to_ui.save_num; //name sprintf(file_name_buf, "%s%04d_Ground_DN", save_str.c_str(), save_num); // name = save_str + String(save_num) +"_" + "Ground_DN"; name = String(file_name_buf); memset(hh3_data_s_dn.name,'\0',100); memcpy(hh3_data_s_dn.name,name.c_str(),name.length()); hh3_data_s_dn.name[name.length()] = '\0'; //sensor_id memcpy(hh3_data_s_dn.sensor_id,(uint8_t *)&is3.info,is3.info.length()); hh3_data_s_dn.sensor_id[is3.info.length()] = '\0'; hh3_data_s_dn.FiberID = hh3_FiberID; //date hh3_data_s_dn.date = hh3_time_structure; hh3_data_s_dn.integration_time = is3.integration_time; hh3_data_s_dn.gain = 0.0; hh3_data_s_dn.data_type = DATA_TYPE_UINT16; hh3_data_s_dn.PixelSize = 2; hh3_data_s_dn.GroundType = s_dn; hh3_data_s_dn.band_num = 515; hh3_data_s_dn.ValidFlag = 1 ; for (uint16_t i = 0; i < 515; i++) { hh3_data_s_dn.data[i] = is3_data.s_average_data[i]; max = max < is3_data.s_average_data[i] ? is3_data.s_average_data[i] : max; } if(max > 65535 * 0.99) hh3_data_s_dn.ValidFlag = 0; xSemaphoreGive(xMutexInventory); } } void dark_dn_pack(bool flag) { uint32_t save_num; String save_str; uint16_t max = 0; String name; char name_buf[64]; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { save_str = updata_struct_to_ui.save_path; save_num = updata_struct_to_ui.save_num; // name = save_str+String(save_num) + "_dark_dn"; sprintf(name_buf, "%s%04d_dark_dn", save_str.c_str(), save_num); name = String(name_buf); memset(hh3_data_dark_dn.name,'\0',100); memcpy(hh3_data_dark_dn.name,name.c_str(),name.length()); hh3_data_dark_dn.name[name.length()] = '\0'; if(flag) { xSemaphoreGive(xMutexInventory); return; } // hh3_data_dark_dn.sensor_id memcpy(hh3_data_dark_dn.sensor_id,(uint8_t *)&is3.info,is3.info.length()); hh3_data_dark_dn.sensor_id[is3.info.length()] = '\0'; hh3_data_dark_dn.FiberID = hh3_FiberID; hh3_data_dark_dn.date = hh3_time_structure; hh3_data_dark_dn.integration_time = is3.integration_time; hh3_data_dark_dn.gain = 0.0; hh3_data_dark_dn.data_type = DATA_TYPE_UINT16; hh3_data_dark_dn.PixelSize = 2; hh3_data_dark_dn.GroundType = dark_dn; hh3_data_dark_dn.band_num = 515; hh3_data_dark_dn.ValidFlag = 1 ; for (uint16_t i = 0; i < 515; i++) { hh3_data_dark_dn.data[i] = is3_data.dark_data[i]; max = max < is3_data.dark_data[i] ? is3_data.dark_data[i] : max; } if(max > 65535 * 0.99) hh3_data_dark_dn.ValidFlag = 0; xSemaphoreGive(xMutexInventory); } } void wr_dn_pack(bool flag) { uint32_t save_num; String save_str; uint16_t max = 0; String name; char file_name_buf[64]; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { save_str = updata_struct_to_ui.save_path; save_num = updata_struct_to_ui.save_num; // name = save_str+String(save_num) + "_flat_dn"; sprintf(file_name_buf, "%s%04d_flat_dn", save_str.c_str(), save_num); name = String(file_name_buf); memset(hh3_data_wr_dn.name,'\0',100); memcpy(hh3_data_wr_dn.name,name.c_str(),name.length()); hh3_data_wr_dn.name[name.length()] = '\0'; if(flag) { xSemaphoreGive(xMutexInventory); return; } // hh3_data_wr_dn.sensor_id memcpy(hh3_data_wr_dn.sensor_id,(uint8_t *)&is3.info,is3.info.length()); hh3_data_wr_dn.sensor_id[is3.info.length()] = '\0'; hh3_data_wr_dn.FiberID = hh3_FiberID; hh3_data_wr_dn.date = hh3_time_structure; hh3_data_wr_dn.integration_time = is3.integration_time; hh3_data_wr_dn.gain = 0.0; hh3_data_wr_dn.data_type = DATA_TYPE_UINT16; hh3_data_wr_dn.PixelSize = 2; hh3_data_wr_dn.GroundType = flat_dn; hh3_data_wr_dn.band_num = 515; hh3_data_wr_dn.ValidFlag = 1 ; for (uint16_t i = 0; i < 515; i++) { hh3_data_wr_dn.data[i] = is3_data.wr_data[i]; max = max < is3_data.wr_data[i] ? is3_data.wr_data[i] : max; } if(max > 65535 * 0.99) hh3_data_wr_dn.ValidFlag = 0; xSemaphoreGive(xMutexInventory); } } void flat_ref_pack() { // uint8_t mode; // String save_str; // uint32_t save_num; // uint16_t max = 0; // String name; // char file_name_buf[64]; // if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) // { // save_str = updata_struct_to_ui.save_path; // save_num = updata_struct_to_ui.save_num; // mode = updata_struct_to_ui.mode; // xSemaphoreGive(xMutexInventory); // } // if(mode != 2) return; //name // name = save_str + String(save_num) +"_" + "flat_ref"; // sprintf(file_name_buf, "%s%04d.iris", save_str.c_str(), save_num); // name = String(file_name_buf); // memset(hh3_data_flat_ref.name,'\0',100); // memcpy(hh3_data_flat_ref.name,name.c_str(),name.length()); // hh3_data_flat_ref.name[name.length()] = '\0'; // //sensor_id // memcpy(hh3_data_flat_ref.sensor_id,(uint8_t *)&is3.info,is3.info.length()); // hh3_data_flat_ref.sensor_id[is3.info.length()] = '\0'; // hh3_data_flat_ref.FiberID = hh3_FiberID; // hh3_data_flat_ref.date = hh3_time_structure; // hh3_data_flat_ref.integration_time = is3.integration_time; // hh3_data_flat_ref.gain = 0.0; // hh3_data_flat_ref.data_type = DATA_TYPE_FLOAT64; // hh3_data_flat_ref.PixelSize = 8; // hh3_data_flat_ref.GroundType = flat_ref; // hh3_data_flat_ref.band_num = 512; // hh3_data_flat_ref.ValidFlag = 1 ; // for (uint16_t i = 0; i < 512; i++) // { // hh3_data_flat_ref.data[i] = (double)(is3_data.s_average_data[i] - hh3_data_dark_dn.data[i]) / (double)(hh3_data_wr_dn.data[i] - hh3_data_dark_dn.data[i]); // } // if(max > 65535 * 0.99) hh3_data_flat_ref.ValidFlag = 0; } void picture_pack(String name,String num) { if(get_cam_status() == 0) { // Serial0.println("cam stop"); return; } // image_picture.length = 0; if(image_picture.length == 0) { xEventGroupClearBits(is3_event_group, IS3_CAM_DONE_BIT); xEventGroupWaitBits(is3_event_group, IS3_CAM_DONE_BIT, pdTRUE, pdFALSE, 100 / portTICK_PERIOD_MS); } if(image_picture.length == 0) return; vTaskDelay(1); // String name_str = name + num + ".jpg"; char file_name_buf[64]; sprintf(file_name_buf, "%s%04d.jpg", name.c_str(), num); String name_str = String(file_name_buf); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { Image_header.SectionFlag = Image; image_picture.Squantity = Image_Squantity; Image_header.SectionLength = image_picture.length + sizeof(image_picture) - sizeof(uint8_t *); memcpy(image_picture.name,name_str.c_str(),name_str.length()); image_picture.length = image_picture.length + 100 + 10 + 1; image_picture.date = hh3_time_structure; image_picture.type = 0; xSemaphoreGive(xMutexInventory); } vTaskDelay(10); } void save_data(String path ,String name,String SpectralInfo_str) { uint8_t mode; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { mode = updata_struct_to_ui.mode; xSemaphoreGive(xMutexInventory); } File file; file = SD_MMC.open(path + name,FILE_WRITE); //SpectralData_Section file.write((uint8_t *)&SpectralData_header,sizeof(SpectralData_header)); //地物DN file.write((uint8_t *)&hh3_data_s_dn,sizeof(hh3_data_s_dn)); // file.flush(); //白板DN if(mode == 2) { file.write((uint8_t *)&hh3_data_wr_dn,sizeof(hh3_data_wr_dn)); } //DARK_DN file.write((uint8_t *)&hh3_data_dark_dn,sizeof(hh3_data_dark_dn)); //flat_ref // file.flush(); if(mode == 2) { // file.write((uint8_t *)&hh3_data_wr_dn,sizeof(hh3_data_wr_dn)); file.write((uint8_t *)&hh3_data_flat_ref,sizeof(hh3_data_flat_ref)); } //califlie if(hh3_califlie_struct.gian.GroundType == califile) file.write((uint8_t *)&hh3_califlie_struct.gian,sizeof(hh3_califlie_struct.gian)); // file.flush(); //SpectralInfo_Section file.write((uint8_t *)&SpectralInfo_header,sizeof(SpectralInfo_header)); file.write((uint8_t *)SpectralInfo_str.c_str(),SpectralInfo_str.length()); // file.flush(); //other_Section file.write((uint8_t *)&Other_header,sizeof(Other_header)); //Image_Section file.write((uint8_t *)&Image_header,sizeof(Image_header)); // file.flush(); if(image_picture.Squantity > 0) { file.flush(); file.write((uint8_t *)&image_picture,sizeof(image_picture) - sizeof(uint8_t *)); file.write(image_picture.data,image_picture.length - sizeof(image_picture.name) - sizeof(image_picture.date) - sizeof(image_picture.type)); } file.flush(); file.close(); } void print_heap_detail() { Serial0.printf("Heap : %u bytes\n", heap_caps_get_free_size(MALLOC_CAP_DEFAULT)); Serial0.printf("Heap : %u bytes\n", heap_caps_get_largest_free_block(MALLOC_CAP_DEFAULT)); Serial0.printf(": %u bytes\n", heap_caps_get_total_size(MALLOC_CAP_DEFAULT)); Serial0.printf(": %u bytes\n", heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT)); Serial0.printf("PSRAM : %u bytes\n", heap_caps_get_free_size(MALLOC_CAP_SPIRAM)); Serial0.printf("PSRAM : %u bytes\n", heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM)); Serial0.printf("PSRAM : %u bytes\n", heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM)); } void show_data_task(void *pvParameters) { String path = "/data"; uint32_t path_deep = 0; uint32_t page_log[100]= {0}; uint16_t file_s_dn[512]; uint8_t plot_type = 0; show_data_structure.mode = 0xff; read_file_point file_point = {NULL,NULL,NULL,NULL,NULL,NULL,NULL}; bool first_flag = true; memset(page_log,0,sizeof(page_log)); while(1) { xEventGroupWaitBits(ui_event_group, SHOW_DATA_BIT, pdTRUE, pdFALSE, portMAX_DELAY); if(get_sd_card_status() == false) { if (xSemaphoreTake(lvgl_mutex, portMAX_DELAY)) { lv_obj_set_size(guider_ui.screen_data_spinner_1, 1, 1); lv_label_set_text(guider_ui.screen_data_label_17, ""); lv_obj_clear_state(guider_ui.screen_data_btnm_1, LV_STATE_DISABLED); xSemaphoreGive(lvgl_mutex); } continue; } if (xSemaphoreTake(lvgl_mutex, portMAX_DELAY)) { lv_obj_set_size(guider_ui.screen_data_spinner_1, 41, 52); lv_label_set_text(guider_ui.screen_data_label_17, "加载中"); lv_obj_add_state(guider_ui.screen_data_btnm_1, LV_STATE_DISABLED); // 禁用按钮 xSemaphoreGive(lvgl_mutex); } // lock_screen(); uint32_t mode; String target_path = "/"; uint32_t target_page =0; uint32_t total_page = 0; String read_path; bool flag = false; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { mode = show_data_structure.mode; target_page = show_data_structure.target_page; target_page = target_page - 1; target_path += show_data_structure.target_path; plot_type = show_data_structure.plot_type; if(mode == 7) plot_type++; plot_type = plot_type > 3 ? 0 : plot_type; show_data_structure.plot_type = plot_type; total_page = show_data_structure.total_page; xSemaphoreGive(xMutexInventory); } //更新列表 //0下一页 1上一页 2跳转 3返回 4进入 5加载 6查看数据 7改变曲线 uint32_t page = page_log[path_deep]; switch (mode) { case 0: if(total_page == 0 ) break; if((page_log[path_deep] + 1 )< total_page) { page_log[path_deep]++; page = page_log[path_deep]; show_page(path, page); } break; case 1: if(total_page == 0 ) break; if(page_log[path_deep] > 0) { page_log[path_deep]--; page = page_log[path_deep]; show_page(path, page); } break; case 2: if(page_log[path_deep] != target_page) { if(target_page > total_page) target_page = total_page - 1; // if(target_page < 0) target_page = 0; page_log[path_deep] = target_page; page = page_log[path_deep]; show_page(path, page); } break; case 3: { int slashIndex = path.lastIndexOf('/'); if (slashIndex > 0) { path = path.substring(0, slashIndex); if (path_deep > 0) path_deep--; total_page = get_file_num(path); page = page_log[path_deep]; show_page(path, page); } break; } case 4: { path = path + target_path; path_deep ++; page_log[path_deep] = 0; total_page = get_file_num(path); // page = page_log[path_deep]; page = total_page - 1; page_log[path_deep] = page; show_page(path, page); break; } case 5: { flag = file_data_analysis(&file_point); if(flag) change_plot_type(file_point,plot_type); if(flag) show_picture(&file_point); total_page = get_file_num(path); page = total_page - 1; show_page(path, page); break; } case 6: { read_path = path + target_path; // plot_type = 0; // if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) // { // show_data_structure.plot_type = plot_type; // xSemaphoreGive(xMutexInventory); // } flag = read_data_from_file(read_path); if(flag) flag = file_data_analysis(&file_point); if(flag) change_plot_type(file_point,plot_type); if(flag) show_picture(&file_point); break; } case 7: { change_plot_type(file_point,plot_type); break; } default: break; } if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { show_data_structure.total_page = total_page; show_data_structure.now_page = page + 1; if(total_page == 0) show_data_structure.now_page = 0; show_data_structure.mode = 0xff; xSemaphoreGive(xMutexInventory); } xEventGroupSetBits(ui_event_group,SHOW_DATA_DONE_BIT); if (xSemaphoreTake(lvgl_mutex, portMAX_DELAY)) { lv_obj_set_size(guider_ui.screen_data_spinner_1, 1, 1); lv_label_set_text(guider_ui.screen_data_label_17, ""); lv_obj_clear_state(guider_ui.screen_data_btnm_1, LV_STATE_DISABLED); xSemaphoreGive(lvgl_mutex); } xEventGroupClearBits(ui_event_group,SHOW_DATA_BIT); } } //0 dn 1 rad 2ref 3dark_dn void change_plot_type(read_file_point file_point,uint8_t plot_type) { if((file_point.s_dn_data == NULL )|| (file_point.dark_dn_data == NULL) || (file_point.data_info == NULL)) { return; } uint16_t str_len; memcpy(&str_len,file_point.data_info,2); char temp_str[str_len + 1]; memcpy(temp_str, file_point.data_info + 2 + 1, str_len); temp_str[str_len] = '\0'; String SpectralInfo_str(temp_str); // file_doc deserializeJson(file_doc, SpectralInfo_str); uint32_t dn_it; One_Spectral_Data_Struct *p = file_point.s_dn_data; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { memcpy(show_data_structure.file_name,p->Name,sizeof(show_data_structure.file_name)); show_data_structure.year = p->CollectionTime.year; show_data_structure.month = p->CollectionTime.month; show_data_structure.day = p->CollectionTime.day; show_data_structure.hour = p->CollectionTime.hour; show_data_structure.minute = p->CollectionTime.minute; show_data_structure.second = p->CollectionTime.second; show_data_structure.IT = p->Exposure; dn_it = p->Exposure; JsonObject info1 = file_doc["info_list"][1]; // 如果确定是第二个对象 show_data_structure.W_count = info1["W_count"] | 0; show_data_structure.D_count = info1["D_count"] | 0; show_data_structure.S_count = info1["S_count"] | 0; show_data_structure.height = info1["height"].as(); xSemaphoreGive(xMutexInventory); } if(plot_type == 1) { if(file_point.califile_data == NULL) plot_type++; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { show_data_structure.plot_type = plot_type; xSemaphoreGive(xMutexInventory); } } if(plot_type == 2) { if(file_point.wr_dn_data == NULL) plot_type++; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { show_data_structure.plot_type = plot_type; xSemaphoreGive(xMutexInventory); } } uint16_t *dn = (uint16_t *)(file_point.s_dn_data->SpectralDataAddress); uint16_t *dark = (uint16_t *)(file_point.dark_dn_data->SpectralDataAddress); switch (plot_type) { case 0: { if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { for (uint16_t i = 0; i < 512; i++) { show_data_structure.plot_data[i] = (int)dn[i] - (int)dark[i]; } xSemaphoreGive(xMutexInventory); } } break; case 1://rad { if(file_point.califile_data == NULL) return; double *gian = (double *)(file_point.califile_data->SpectralDataAddress); double gain_it = file_point.califile_data->Exposure; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { for (uint16_t i = 0; i < 512; i++) { show_data_structure.plot_data[i] = (double)(dn[i] - dark[i])/ (double)dn_it * gain_it * (gian[i] * 1000000); } xSemaphoreGive(xMutexInventory); } } break; case 2: //ref { if(file_point.wr_dn_data == NULL) return; uint16_t *wr = (uint16_t *)(file_point.wr_dn_data->SpectralDataAddress); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { for (uint16_t i = 0; i < 512; i++) { show_data_structure.plot_data[i] = (float)(dn[i] - dark[i]) / (float)(wr[i] - dark[i]) * 10000; } xSemaphoreGive(xMutexInventory); } } break; case 3: //dark_dn { if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { for (uint16_t i = 0; i < 512; i++) { show_data_structure.plot_data[i] = dark[i]; } xSemaphoreGive(xMutexInventory); } } break; default: break; } } static void updata_dir(lv_event_t *e) { uint8_t mode; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { mode = show_data_structure.mode; xSemaphoreGive(xMutexInventory); } if(mode == 0xff) { lv_obj_t * obj = lv_event_get_target(e); const char *dir = lv_list_get_btn_text(guider_ui.screen_data_list_1, obj); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { show_data_structure.mode = 4; strcpy(show_data_structure.target_path, dir); xSemaphoreGive(xMutexInventory); } xEventGroupSetBits(ui_event_group, SHOW_DATA_BIT); } } //更新数据 static void updata_data(lv_event_t *e) { uint8_t mode; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { mode = show_data_structure.mode; xSemaphoreGive(xMutexInventory); } if(mode == 0xff) { lv_obj_t * obj = lv_event_get_target(e); const char *dir = lv_list_get_btn_text(guider_ui.screen_data_list_1, obj); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { show_data_structure.mode = 6; strcpy(show_data_structure.target_path, dir); xSemaphoreGive(xMutexInventory); } xEventGroupSetBits(ui_event_group, SHOW_DATA_BIT); } } // 0_0 /data // static uint32_t show_page(String path, uint32_t page) // { // File root = SD_MMC.open(path); // if (!root || !root.isDirectory()) { // return 0; // } // if (xSemaphoreTake(lvgl_mutex, portMAX_DELAY)) // { // lv_obj_clean(guider_ui.screen_data_list_1); // 清空列表 // xSemaphoreGive(lvgl_mutex); // } // // lv_obj_invalidate(guider_ui.screen_data_list_1); // 强制刷新父对象 // // vTaskDelay(50); // uint32_t start_index = page * ITEMS_PER_PAGE; // uint32_t end_index = start_index + ITEMS_PER_PAGE; // uint32_t current_index = 0; // File file = root.openNextFile(); // uint32_t count = 0; // while (file) // { // // Serial0.println("current_index" + String(current_index)); // if (current_index >= start_index) // { // String filename = file.name(); // bool isDir = file.isDirectory(); // const char* icon = isDir ? LV_SYMBOL_DIRECTORY : LV_SYMBOL_FILE; // if (xSemaphoreTake(lvgl_mutex, portMAX_DELAY)) // { // guider_ui.screen_data_list_1_btn = lv_list_add_btn(guider_ui.screen_data_list_1, icon, filename.c_str()); // lv_obj_t* label = lv_obj_get_child(guider_ui.screen_data_list_1_btn, 1); // if (label != NULL) // { // lv_label_set_long_mode(label, LV_LABEL_LONG_CLIP); // } // if(isDir) lv_obj_add_event_cb(guider_ui.screen_data_list_1_btn,updata_dir, LV_EVENT_CLICKED, NULL); // else lv_obj_add_event_cb(guider_ui.screen_data_list_1_btn,updata_data, LV_EVENT_CLICKED, NULL); // xSemaphoreGive(lvgl_mutex); // } // } // file = root.openNextFile(); // current_index++; // if(current_index >= end_index) break; // count++; // if(count%20 == 0) vTaskDelay(1); // } // root.close(); // return end_index; // } // static uint32_t get_file_num(String path) // { // uint32_t file_count = 0; // File root = SD_MMC.open(path); // if (!root) // { // // Serial0.println("Failed to open directory"); // return 0; // } // if (!root.isDirectory()) // { // // Serial0.println("Not a directory"); // root.close(); // return 0; // } // if (xSemaphoreTake(lvgl_mutex, portMAX_DELAY)) // { // lv_obj_clean(guider_ui.screen_data_list_1); // 清空列表 // xSemaphoreGive(lvgl_mutex); // } // // lv_obj_clean(guider_ui.screen_data_list_1); // 清空列表 // // vTaskDelay(50); // uint32_t count = 0; // File file = root.openNextFile(); // while (file) // { // file_count++; // // file.close(); // 关闭当前文件 // file = root.openNextFile(); // 获取下一个文件 // if(count%20 == 0) vTaskDelay(1); // } // root.close(); // uint32_t total_page = ceil((float)file_count / ITEMS_PER_PAGE); // if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) // { // show_data_structure.total_page = total_page; // xSemaphoreGive(xMutexInventory); // } // // Serial0.println("file_count:" + String(file_count)); // // Serial0.println("total_page:" + String(total_page)); // return total_page; // } /////////////////////////////////////////////////////////////////////////////// #include "driver/sdmmc_host.h" #include static uint32_t get_file_num(String path_str) { uint32_t file_count = 0; esp_err_t ret; DIR *dir; struct dirent *ent; lv_obj_t * btn; path_str = "/sdcard" + path_str; const char *path = path_str.c_str(); // Serial0.println("path:" + String(path)); if ((dir = opendir(path))!= NULL) { // 打开目录 while ((ent = readdir(dir))!= NULL) { file_count++; } closedir(dir); } else { // Serial0.println("Failed to open directory"); return 0; } uint32_t total_page = ceil((float)file_count / ITEMS_PER_PAGE); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { show_data_structure.total_page = total_page; xSemaphoreGive(xMutexInventory); } // Serial0.println("file_count:" + String(file_count)); // Serial0.println("total_page:" + String(total_page)); return total_page; } static uint32_t show_page(String path, uint32_t page) { File root = SD_MMC.open(path); if (!root || !root.isDirectory()) { return 0; } root.close(); if (xSemaphoreTake(lvgl_mutex, portMAX_DELAY)) { lv_obj_clean(guider_ui.screen_data_list_1); // 清空列表 xSemaphoreGive(lvgl_mutex); } uint32_t start_index = page * ITEMS_PER_PAGE; uint32_t end_index = start_index + ITEMS_PER_PAGE; uint32_t current_index = 0; uint32_t count = 0; esp_err_t ret; DIR *dir; struct dirent *ent; lv_obj_t * btn; path = "/sdcard" + path; const char *path_str = path.c_str(); if ((dir = opendir(path_str))!= NULL) { // 打开目录 while ((ent = readdir(dir))!= NULL) { if (current_index >= start_index) { if (xSemaphoreTake(lvgl_mutex, portMAX_DELAY)) { if (ent->d_type == DT_REG)// 如果是常规文件 { guider_ui.screen_data_list_1_btn = lv_list_add_btn(guider_ui.screen_data_list_1, LV_SYMBOL_FILE, (const char *)ent->d_name); lv_obj_t* label_1 = lv_obj_get_child(guider_ui.screen_data_list_1_btn, 1); if (label_1 != NULL) { lv_label_set_long_mode(label_1, LV_LABEL_LONG_CLIP); } lv_obj_add_event_cb(guider_ui.screen_data_list_1_btn,updata_data, LV_EVENT_CLICKED, NULL); } else if (ent->d_type == DT_DIR) { guider_ui.screen_data_list_1_btn = lv_list_add_btn(guider_ui.screen_data_list_1, LV_SYMBOL_DIRECTORY, (const char *)ent->d_name); lv_obj_t* label_2 = lv_obj_get_child(guider_ui.screen_data_list_1_btn, 1); if (label_2 != NULL) { lv_label_set_long_mode(label_2, LV_LABEL_LONG_CLIP); } lv_obj_add_event_cb(guider_ui.screen_data_list_1_btn,updata_dir, LV_EVENT_CLICKED, NULL); } xSemaphoreGive(lvgl_mutex); } } current_index++; if(current_index >= end_index) break; // count++; // if(count%20 == 0) vTaskDelay(1); } closedir(dir); } else { return 0; } return end_index; } /////////////////////////////////////////////////// bool read_data_from_file(String path) { if(path.indexOf(".iris") < 0) { // Serial0.println("file_type_error"); return false; } memset(file_data,0,file_heap_size); bool flag = false; uint32_t size; uint32_t type; File file; file = SD_MMC.open(path,FILE_READ); size = file.size(); if(size && (size < file_heap_size)) { file.read(file_data,size); flag = true; } file.close(); // Serial0.println("file size:" + String(size)); // Serial0.println("if read:" + String(flag)); // Serial0.printf("file_data:%x %x %x %x\n",file_data[0],file_data[1],file_data[2],file_data[3]); // Serial0.write(file_data,4); return flag; } bool file_data_analysis(read_file_point *p) { // p = {NULL,NULL,NULL,NULL,NULL,NULL,NULL}; p->califile_data = NULL; p->dark_dn_data = NULL; p->flat_ref_data = NULL; p->s_dn_data = NULL; p->wr_dn_data= NULL; p->data_info = NULL; p->image_info = NULL; uint32_t SpectralData_pos,Spectralinfo_pos,Other_pos,Image_pos; uint32_t pos=0; uint32_t header; uint32_t length = 0; memcpy(&header,file_data,4); if(header != SpectralData) return false; for (uint16_t i = 0; i < 4; i++) { memcpy(&header,file_data+pos,4); memcpy(&length,file_data+pos+4,8); // Serial0.printf("i:%d\n",i); // Serial0.printf("header:%x,length:%d\n",header,length); if((header == SpectralData)) SpectralData_pos = pos; else if((header == SpectralInfo)) Spectralinfo_pos = pos; else if((header == Other) ) Other_pos = pos; else if((header == Image)) Image_pos = pos; pos = pos + 4 + 8 + length; } // Serial0.printf("SpectralData_pos:%d\n",SpectralData_pos); // Serial0.printf("SpectralInfo_pos:%d\n",Spectralinfo_pos); // Serial0.printf("Other_pos:%d\n",Other_pos); // Serial0.printf("Image_pos:%d\n",Image_pos); // SpectralData_len uint64_t SpectralData_len = 0; memcpy(&SpectralData_len,file_data+SpectralData_pos+4,8); // Serial0.printf("SpectralData_len:%d\n",SpectralData_len); uint16_t SpectralData_quantity = 0; memcpy(&SpectralData_quantity,file_data+SpectralData_pos+12,2); // Serial0.printf("SpectralData_quantity:%d\n",SpectralData_quantity); uint32_t offset = 4 + 8 + 2; for(int i = 0;i < SpectralData_quantity;i++) { One_Spectral_Data_Struct *Spectral_Data_Structure; // memcpy(&Spectral_Data_Structure,file_data+offset,sizeof(Spectral_Data_Structure)-sizeof(Spectral_Data_Structure.SpectralDataAddress)); Spectral_Data_Structure = (One_Spectral_Data_Struct *)(file_data+offset); switch (Spectral_Data_Structure->GroundType) { case s_dn: p->s_dn_data = Spectral_Data_Structure; p->s_dn_data->SpectralDataAddress = file_data + offset + sizeof(One_Spectral_Data_Struct) - sizeof(uint8_t *); break; case flat_dn: p->wr_dn_data = Spectral_Data_Structure; p->wr_dn_data->SpectralDataAddress = file_data + offset + sizeof(One_Spectral_Data_Struct) - sizeof(uint8_t *); break; case dark_dn: p->dark_dn_data = Spectral_Data_Structure; p->dark_dn_data->SpectralDataAddress = file_data + offset + sizeof(One_Spectral_Data_Struct) - sizeof(uint8_t *); break; case flat_ref: p->flat_ref_data = Spectral_Data_Structure; p->flat_ref_data->SpectralDataAddress = file_data + offset + sizeof(One_Spectral_Data_Struct) - sizeof(uint8_t *); break; case califile: p->califile_data = Spectral_Data_Structure; p->califile_data->SpectralDataAddress = file_data + offset + sizeof(One_Spectral_Data_Struct) - sizeof(uint8_t *); break; default: break; } offset = offset + sizeof(One_Spectral_Data_Struct)-sizeof(uint8_t *) + Spectral_Data_Structure->Bands*Spectral_Data_Structure->PixelSize; } uint64_t Spectralinfo_len; memcpy(&Spectralinfo_len,file_data+Spectralinfo_pos+4,sizeof(uint64_t)); // Serial0.printf("Spectralinfo_len:%d\n",Spectralinfo_len); offset = 4 + 8 + 2; if(Spectralinfo_len) p->data_info = file_data + Spectralinfo_pos + offset; else p->data_info = NULL; uint64_t image_len; memcpy(&image_len,file_data+Image_pos+4,sizeof(uint64_t)); // Serial0.printf("image_len:%d\n",image_len); if(image_len != 0) { p->image_info = (picture *)(file_data + Image_pos + 4 + 8); // p->image_info->data = (uint8_t *)(file_data + Image_pos + 4 + 8 + 2 + 8 + 100 + 10 + 1); } else p->image_info = NULL; return true; } bool picture_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap) { if (y >= 204) return 0; // 忽略底部多余区域 for (int j = 0; j < h; j++) { int yy = y + j; if (yy >= 204) continue; // 裁剪下边界 for (int i = 0; i < w; i++) { int xx = x + i; if (xx >= 324) continue; // 裁剪右边界 int dst_idx = yy * 324 + xx; buf_screen_data_canvas_1[dst_idx].full = bitmap[j * w + i]; } } return 1; } void clear_screen(uint16_t color = 0xffff) // 白色,RGB565 { for (int y = 0; y < 204; ++y) { for (int x = 0; x < 324; ++x) { int idx = y * 324 + x; buf_screen_data_canvas_1[idx].full = color; } } } void show_picture(read_file_point *p) { clear_screen(0xffff); if(p->image_info == NULL) { // buf_screen_data_canvas_1[dst_idx].full = bitmap[j * w + i]; clear_screen(0xffff); // Serial0.println("p->image_info == NULL"); return; } if( p->image_info->Squantity != 1 ) { clear_screen(0xffff); // Serial0.println("no picture"); return; } uint64_t picture_len = p->image_info->length - 100 - 10 -1; // Serial0.printf("picture_len : %d",picture_len); char p_name[100] ; memcpy(p_name,p->image_info->name,100); xEventGroupSetBits(ui_event_group,CAM_STOP_BIT); TJpgDec.setJpgScale(1); // 缩小 TJpgDec.setSwapBytes(false); // RGB转换 TJpgDec.setCallback(picture_output); TJpgDec.drawJpg(0, 0, (uint8_t *)p->image_info + 2 + 8 + 100 + 10 + 1,picture_len); vTaskDelay(200); initJPEGDecoder(); } void pc_mode_task(void *pvParameters) { while (1) { xEventGroupWaitBits(ui_event_group, PC_MODE_BIT, pdFALSE, pdFALSE, portMAX_DELAY); play_music("diannaomoshi.mp3"); suspend_all_tasks(); is3.reset(); uint32_t i = 0; uint8_t s0rx_buf[1024 * 2]; uint8_t s1rx_buf[1024 * 2]; while (1) { EventBits_t uxBits = xEventGroupGetBits(ui_event_group); if(!(uxBits & PC_MODE_BIT)) break; // 1. Serial0 -> Serial1 // if (Serial0.available()) if(my_usart_available(0)) { // int byte_from_pc = Serial0.readBytes(s0rx_buf,1024); int byte_from_pc = uart_read_bytes(0,s0rx_buf,1024*2,10); Serial1.write(s0rx_buf,byte_from_pc); } // 2. Serial1 -> Serial0 // if (Serial1.available()) if(my_usart_available(1)) { // int byte_from_uart = Serial1.readBytes(s1rx_buf,1024); int byte_from_uart = uart_read_bytes(1,s1rx_buf,1024*2,10); Serial0.write(s1rx_buf,byte_from_uart); } if(i == 1000) { vTaskDelay(1); i = 0; } i++; } // Serial1.flush(); is3.reset(); is3.set_shutter_time(is3.integration_time); resume_all_tasks(); vTaskDelay(200); } } bool read_flat_file(String file_name) { String path = "/config/flatfile/" + file_name; File file = SD_MMC.open(path); if(!file) { return false; } file.read((uint8_t *)(&hh3_flatfile_struct),sizeof(hh3_flatfile_struct)); file.close(); // Serial0.printf("file_name:%s\n",file_name.c_str()); // Serial0.printf("GroundType:%d\n",hh3_flatfile_struct.gian.GroundType); if(hh3_flatfile_struct.gian.GroundType != 5) { return false; } // uint32_t bandnum = hh3_flatfile_struct.gian.band_num; uint32_t bandnum = 512; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { // memcpy(&hh3_data_flat_ref,&hh3_flatfile_struct.gian,sizeof(hh3_data_flat_ref)); for(int i = 0; i < bandnum; i++) { flat_structure.plot_data[i] = hh3_flatfile_struct.gian.data[i] * 10000; } xSemaphoreGive(xMutexInventory); } xEventGroupSetBits(ui_event_group2,flat_plot_BIT); // if (xSemaphoreTake(lvgl_mutex, portMAX_DELAY)) // { // int32_t nn = 511; // for (uint16_t i = 0; i < 512; i++) // { // guider_ui.Setting_ckb_chart_1_0->y_points[i] = flat_structure.plot_data[i]; // nn--; // } // lv_chart_set_range(guider_ui.Setting_ckb_chart_1, LV_CHART_AXIS_PRIMARY_Y, 0, 1.25 * 10000); //设置坐标y轴范围 // lv_chart_refresh(guider_ui.Setting_ckb_chart_1); // xSemaphoreGive(lvgl_mutex); // } // if(hh3_flatfile_struct.gian.GroundType == 5) // { // memcpy(&hh3_data_flat_ref,&hh3_flatfile_struct.gian,sizeof(hh3_data_flat_ref)); // return true; // } return true; } //更新数据 static lv_obj_t * plat_last_btn; // 记录上一次点击的按钮 static void flatfile_read(lv_event_t *e) { // static lv_obj_t *last_btn; // 记录上一次点击的按钮 lv_obj_t * obj = lv_event_get_target(e); const char *dir = lv_list_get_btn_text(guider_ui.screen_data_list_1,obj); if(plat_last_btn && plat_last_btn != obj) { lv_obj_set_style_bg_color(plat_last_btn, lv_color_hex(0xFFFFFF), // 默认背景色 LV_PART_MAIN | LV_STATE_DEFAULT); } lv_obj_set_style_bg_color(obj, lv_color_hex(0x0E49F8), LV_PART_MAIN|LV_STATE_DEFAULT); plat_last_btn = obj; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { flat_structure.flat_type = 1; strcpy(flat_structure.flat_file_name,dir); xSemaphoreGive(xMutexInventory); } xEventGroupSetBits(ui_event_group2, flat_BIT); } void add_flatfile_item() { String path = "/config/flatfile"; File root = SD_MMC.open(path); if (!root || !root.isDirectory()) { return; } root.close(); String flat_name; if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { String str = sys_doc["flatfile_name"]; flat_name = str; xSemaphoreGive(xMutexInventory); } esp_err_t ret; DIR *dir; struct dirent *ent; lv_obj_t * btn; path = "/sdcard" + path; const char *path_str = path.c_str(); if ((dir = opendir(path_str))!= NULL) { // 打开目录 uint8_t num = 0; while ((ent = readdir(dir))!= NULL) { if (xSemaphoreTake(lvgl_mutex, portMAX_DELAY)) { if (ent->d_type == DT_REG)// 如果是常规文件 { guider_ui.Setting_ckb_list_1_btn = lv_list_add_btn(guider_ui.Setting_ckb_list_1, LV_SYMBOL_FILE, (const char *)ent->d_name); lv_obj_t* label_1 = lv_obj_get_child(guider_ui.Setting_ckb_list_1_btn, 1); if(String(ent->d_name) == flat_name) { lv_obj_set_style_bg_color(guider_ui.Setting_ckb_list_1_btn, lv_color_hex(0x0E49F8), LV_PART_MAIN|LV_STATE_DEFAULT); plat_last_btn = guider_ui.Setting_ckb_list_1_btn; } if (label_1 != NULL) { lv_label_set_long_mode(label_1, LV_LABEL_LONG_CLIP); } lv_obj_add_event_cb(guider_ui.Setting_ckb_list_1_btn,flatfile_read, LV_EVENT_CLICKED, NULL); } else if(ent->d_type == DT_DIR) { } xSemaphoreGive(lvgl_mutex); } num++; if (num > 20) break; } closedir(dir); read_flat_file(flat_name); } } void reset_flat_sturct() { hh3_data_flat_ref.name[0] = '\0'; hh3_data_flat_ref.sensor_id[0] = '\0'; hh3_data_flat_ref.FiberID = 0; hh3_data_flat_ref.date = {0,0,0,0,0,0,0,0}; hh3_data_flat_ref.integration_time = 0; hh3_data_flat_ref.gain = 0; hh3_data_flat_ref.data_type = 0x21; hh3_data_flat_ref.PixelSize = 8; hh3_data_flat_ref.GroundType = 5; hh3_data_flat_ref.band_num = 515; hh3_data_flat_ref.ValidFlag = 0; // memset(hh3_data_flat_ref.data,1,sizeof(hh3_data_flat_ref.data)); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { for(int i = 0; i < hh3_data_flat_ref.band_num; i++) { hh3_data_flat_ref.data[i] = 1; } xSemaphoreGive(xMutexInventory); } } void flat_task(void *pvParameters) { reset_flat_sturct(); uint8_t flag = 0; bool reset = false; while(1) { uint8_t flat_type; String flat_file_name; if(flag == 0) { if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { String str = sys_doc["flatfile_name"]; strcpy(flat_structure.flat_file_name,str.c_str()); flat_file_name = str; xSemaphoreGive(xMutexInventory); } read_flat_file(flat_file_name); flag = 1; } xEventGroupWaitBits(ui_event_group2,flat_BIT,pdTRUE,pdFALSE,portMAX_DELAY); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { flat_type = flat_structure.flat_type; flat_file_name = flat_structure.flat_file_name; xSemaphoreGive(xMutexInventory); } // Serial0.println("flat_task"); switch (flat_type) { case 0: //加载 add_flatfile_item(); break; case 1: //读取 read_flat_file(flat_file_name); reset = false; break; case 2: //保存 { if(reset) { reset_flat_sturct(); if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { for(int i = 0; i < 512; i++) { flat_structure.plot_data[i] = hh3_data_flat_ref.data[i] * 10000; // flat_structure.plot_data[i] = 1 * 10000; } sys_doc["flatfile_name"] = "flat_default.iris"; updata_struct_to_ui.system_save = 1; xSemaphoreGive(xMutexInventory); } } else { if(hh3_flatfile_struct.gian.GroundType == 5) { if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS) { sys_doc["flatfile_name"] = flat_file_name; updata_struct_to_ui.system_save = 1; xSemaphoreGive(xMutexInventory); } memcpy(&hh3_data_flat_ref,&hh3_flatfile_struct.gian,sizeof(hh3_data_flat_ref)); } } play_music("/OK2.mp3"); break; } case 3: //还原默认 { reset = true; if(xSemaphoreTake(lvgl_mutex, portMAX_DELAY)) { for (uint16_t i = 0; i < 512; i++) { guider_ui.Setting_ckb_chart_1_0->y_points[i] = 1 * 10000; } lv_chart_set_range(guider_ui.Setting_ckb_chart_1, LV_CHART_AXIS_PRIMARY_Y, 0, 1.25 * 10000); //设置坐标y轴范围 lv_chart_refresh(guider_ui.Setting_ckb_chart_1); xSemaphoreGive(lvgl_mutex); } // xEventGroupSetBits(ui_event_group2,flat_plot_BIT); play_music("/OK2.mp3"); break; } default: break; } } }