#include "jj_param.h" #include "./page/page_ui_widget.h" #include "./page/page.h" #include "zf_common_headfile.h" #include "jj_motion.h" #include "jj_blueteeth.h" PARAM_INFO Param_Data[DATA_NUM]; soft_iic_info_struct eeprom_param; TYPE_UNION iic_buffer[DATA_IN_FLASH_NUM]; TYPE_UNION temp_frame_param[20]; /** * @brief 参数初始化注册 * */ void jj_param_eeprom_init(void) { soft_iic_init(&eeprom_param, K24C02_DEV_ADDR, K24C02_SOFT_IIC_DELAY, K24C02_SCL_PIN, K24C02_SDA_PIN); // eeprom初始化 PARAM_REG(angle_Kp0, &an_Kp0, EFLOAT, 1, "an_P0:"); // 注冊 PARAM_REG(angle_Ki0, &an_Ki0, EFLOAT, 1, "an_I0:"); // 注冊 PARAM_REG(angle_Kd0, &an_Kd0, EFLOAT, 1, "an_D0:"); PARAM_REG(gyro_Kp0, &gy_Kp0, EFLOAT, 1, "gy_P0:"); // 注冊 PARAM_REG(gyro_Ki0, &gy_Ki0, EFLOAT, 1, "gy_I0:"); // 注冊 PARAM_REG(gyro_Kd0, &gy_Kd0, EFLOAT, 1, "gy_D0:"); PARAM_REG(can_Kp1, &cn_Kp1, EFLOAT, 1, "cn_P1:"); // 注冊 PARAM_REG(can_Ki1, &cn_Ki1, EFLOAT, 1, "cn_I1:"); // 注冊 PARAM_REG(can_Kd1, &cn_Kd1, EFLOAT, 1, "cn_D1:"); PARAM_REG(fly_pwm, &bt_fly, EFLOAT, 1, "fly:"); PARAM_REG(param_set_speed0, &set_speed0, EFLOAT, 1, "rate0:"); PARAM_REG(angle_Kp1, &an_Kp1, EFLOAT, 1, "an_P1:"); // 注冊 PARAM_REG(angle_Ki1, &an_Ki1, EFLOAT, 1, "an_I1:"); // 注冊 PARAM_REG(angle_Kd1, &an_Kd1, EFLOAT, 1, "an_D1:"); PARAM_REG(gyro_Kp1, &gy_Kp1, EFLOAT, 1, "gy_P1:"); // 注冊 PARAM_REG(gyro_Ki1, &gy_Ki1, EFLOAT, 1, "gy_I1:"); // 注冊 PARAM_REG(gyro_Kd1, &gy_Kd1, EFLOAT, 1, "gy_D1:"); PARAM_REG(pos_Kp1, &po_Kp1, EFLOAT, 1, "po_P1:"); // 注冊 PARAM_REG(pos_Ki1, &po_Ki1, EFLOAT, 1, "po_I1:"); // 注冊 PARAM_REG(pos_Kd1, &po_Kd1, EFLOAT, 1, "po_D1:"); PARAM_REG(param_set_speed1, &set_speed1, EFLOAT, 1, "rate1:"); PARAM_REG(yuan_Kp0, &yu_Kp0, EFLOAT, 1, "an_P0:"); // 注冊 PARAM_REG(yuan_Ki0, &yu_Ki0, EFLOAT, 1, "an_I0:"); // 注冊 PARAM_REG(yuan_Kd0, &yu_Kd0, EFLOAT, 1, "an_D0:"); PARAM_REG(yugyro_Kp0, &ygy_Kp0, EFLOAT, 1, "gy_P0:"); // 注冊 PARAM_REG(yugyro_Ki0, &ygy_Ki0, EFLOAT, 1, "gy_I0:"); // 注冊 PARAM_REG(yugyro_Kd0, &ygy_Kd0, EFLOAT, 1, "gy_D0:"); PARAM_REG(speed_Kp, &sp_Kp, EFLOAT, 1, "sp_P:"); // 注冊 PARAM_REG(speed_Ki, &sp_Ki, EFLOAT, 1, "sp_I:"); // 注冊 PARAM_REG(speed_Kd, &sp_Kd, EFLOAT, 1, "sp_D:"); PARAM_REG(param_set_speed2, &set_speed2, EFLOAT, 1, "rate2:"); jj_param_read(); // 注冊 } /** * @brief 参数写入 * */ void jj_param_write(void) { for (uint8 i = 0; i < DATA_IN_FLASH_NUM; i++) { switch (Param_Data[i].type) { case EFLOAT: iic_buffer[i].f32 = *((float *)(Param_Data[i].p_data)); break; case EUINT32: iic_buffer[i].u32 = *((uint32 *)(Param_Data[i].p_data)); break; case EINT32: iic_buffer[i].s32 = *((int32 *)(Param_Data[i].p_data)); break; default: break; } eep_soft_iic_write_8bit_registers(&eeprom_param, (4 * i) >> 8, (4 * i), (uint8 *)&iic_buffer[i], 4); system_delay_ms(10); } } /** * @brief 参数读出 * */ void jj_param_read(void) { for (uint8 i = 0; i < DATA_IN_FLASH_NUM; i++) { eep_soft_iic_read_8bit_registers(&eeprom_param, (4 * i) >> 8, (4 * i), (uint8 *)&iic_buffer[i], 4); switch (Param_Data[i].type) { case EFLOAT: *((float *)(Param_Data[i].p_data)) = iic_buffer[i].f32; break; case EUINT32: *((uint32 *)(Param_Data[i].p_data)) = iic_buffer[i].u32; break; case EINT32: *((int32 *)(Param_Data[i].p_data)) = iic_buffer[i].s32; break; default: break; } system_delay_ms(10); } }