Anatoliy Chigirinskiy před 1 rokem
rodič
revize
50071ea3d9
2 změnil soubory, kde provedl 14 přidání a 7 odebrání
  1. 12 7
      Devices/potentiometer.c
  2. 2 0
      Devices/potentiometer.h

+ 12 - 7
Devices/potentiometer.c

@@ -2,9 +2,9 @@
 #include "tmsgheaders.h"
 
 uint32_t pot_array [2]  = {0,0};
-double freq_file [50] = {0};
-uint32_t pot_offset [50]= {0};
-uint32_t pot_slope [50]= {0};
+double freq_file [FILE_ROWS] = {0};
+uint32_t pot_offset [FILE_ROWS]= {0};
+uint32_t pot_slope [FILE_ROWS]= {0};
 
 uint32_t pot_ch_a_file;
 uint32_t pot_ch_b_file;
@@ -43,18 +43,23 @@ void read_pot_file (const char* filename) {
         return;
     }
     int i = 0;
-    while (fscanf(file, "%lf %u %u", &freq_file[i], &pot_offset[i], &pot_slope[i]) != EOF) {
+    while (fscanf(file, "%lf %u %u", &freq_file[i], &pot_slope[i], &pot_offset[i]) != EOF) {
         i++;
     }
     fclose(file);
 }
 
 void set_pot_values(double freq){
-    for (int i = 0; i < 50; i++) {
+    for (int i = 0; i < FILE_ROWS; i++) {
         if (freq <= freq_file[i]) {
-            pot_ch_a_file = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_A_ENUM << TPL0202_ADR_BITP)|(pot_offset[i-1] << TPL0202_DATA_BITP);
-            pot_ch_b_file = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_B_ENUM << TPL0202_ADR_BITP)|(pot_slope[i-1]<< TPL0202_DATA_BITP);
+          if (i == 0) {
+            pot_ch_a_file = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_A_ENUM << TPL0202_ADR_BITP)|(pot_offset[i] << TPL0202_DATA_BITP);
+            pot_ch_b_file = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_B_ENUM << TPL0202_ADR_BITP)|(pot_slope[i]<< TPL0202_DATA_BITP);
             break;
+          }
+          pot_ch_a_file = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_A_ENUM << TPL0202_ADR_BITP)|(pot_offset[i-1] << TPL0202_DATA_BITP);
+          pot_ch_b_file = (TPL0202_CMD_WR_WIPER_REG_ENUM << TPL0202_CMD_BITP)|(TPL0202_ADR_B_ENUM << TPL0202_ADR_BITP)|(pot_slope[i-1]<< TPL0202_DATA_BITP);
+          break;
         }
     }
 }

+ 2 - 0
Devices/potentiometer.h

@@ -19,6 +19,8 @@
 #define		TPL0202_DATA_BITP						0
 #define		TPL0202_DATA_BITM						(0xFF<<TPL0202_DATA_BITP)
 
+#define     FILE_ROWS                               12
+
 
 extern uint32_t pot_array [2];