Rev 991 | Rev 993 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 991 | Rev 992 | ||
---|---|---|---|
1 | // ######################## SPI - FlightCtrl ################### |
1 | // ######################## SPI - FlightCtrl ################### |
2 | #include "main.h" |
2 | #include "main.h" |
3 | 3 | ||
4 | 4 | ||
5 | //struct str_ToNaviCtrl_Version ToNaviCtrl_Version; |
5 | //struct str_ToNaviCtrl_Version ToNaviCtrl_Version; |
6 | //struct str_FromNaviCtrl_Version FromNaviCtrl_Version; |
6 | //struct str_FromNaviCtrl_Version FromNaviCtrl_Version; |
7 | struct str_ToNaviCtrl ToNaviCtrl; |
7 | struct str_ToNaviCtrl ToNaviCtrl; |
8 | struct str_FromNaviCtrl FromNaviCtrl; |
8 | struct str_FromNaviCtrl FromNaviCtrl; |
9 | struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
9 | struct str_FromNaviCtrl_Value FromNaviCtrl_Value; |
10 | 10 | ||
11 | unsigned char SPI_BufferIndex; |
11 | unsigned char SPI_BufferIndex; |
12 | unsigned char SPI_RxBufferIndex; |
12 | unsigned char SPI_RxBufferIndex; |
13 | 13 | ||
14 | volatile unsigned char SPI_Buffer[sizeof(FromNaviCtrl)]; |
14 | volatile unsigned char SPI_Buffer[sizeof(FromNaviCtrl)]; |
15 | unsigned char *SPI_TX_Buffer; |
15 | unsigned char *SPI_TX_Buffer; |
16 | 16 | ||
17 | unsigned char SPITransferCompleted, SPI_ChkSum; |
17 | unsigned char SPITransferCompleted, SPI_ChkSum; |
18 | unsigned char SPI_RxDataValid; |
18 | unsigned char SPI_RxDataValid; |
19 | 19 | ||
20 | unsigned char SPI_CommandSequence[] = { SPI_CMD_USER, SPI_CMD_STICK, SPI_CMD_PARAMETER1, SPI_CMD_STICK, SPI_CMD_CAL_COMPASS, SPI_CMD_VERSION }; |
20 | unsigned char SPI_CommandSequence[] = { SPI_CMD_USER, SPI_CMD_STICK, SPI_CMD_PARAMETER1, SPI_CMD_STICK, SPI_CMD_CAL_COMPASS, SPI_CMD_VERSION }; |
21 | unsigned char SPI_CommandCounter = 0; |
21 | unsigned char SPI_CommandCounter = 0; |
22 | 22 | ||
23 | #ifdef USE_SPI_COMMUNICATION |
23 | #ifdef USE_SPI_COMMUNICATION |
24 | 24 | ||
25 | //------------------------------------------------------ |
25 | //------------------------------------------------------ |
26 | void SPI_MasterInit(void) |
26 | void SPI_MasterInit(void) |
27 | { |
27 | { |
28 | DDR_SPI |= (1<<DD_MOSI)|(1<<DD_SCK); // Set MOSI and SCK output, all others input |
28 | DDR_SPI |= (1<<DD_MOSI)|(1<<DD_SCK); // Set MOSI and SCK output, all others input |
29 | SLAVE_SELECT_DDR_PORT |= (1 << SPI_SLAVE_SELECT); |
29 | SLAVE_SELECT_DDR_PORT |= (1 << SPI_SLAVE_SELECT); |
30 | 30 | ||
31 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(0<<SPR0)|(0<<SPIE); // Enable SPI, Master, set clock rate fck/64 |
31 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(0<<SPR0)|(0<<SPIE); // Enable SPI, Master, set clock rate fck/64 |
32 | SPSR = 0;//(1<<SPI2X); |
32 | SPSR = 0;//(1<<SPI2X); |
33 | 33 | ||
34 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); |
34 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); |
35 | SPITransferCompleted = 1; |
35 | SPITransferCompleted = 1; |
36 | 36 | ||
37 | //SPDR = 0x00; // dummy write |
37 | //SPDR = 0x00; // dummy write |
38 | 38 | ||
39 | ToNaviCtrl.Sync1 = 0xAA; |
39 | ToNaviCtrl.Sync1 = 0xAA; |
40 | ToNaviCtrl.Sync2 = 0x83; |
40 | ToNaviCtrl.Sync2 = 0x83; |
41 | 41 | ||
42 | ToNaviCtrl.Command = SPI_CMD_USER; |
42 | ToNaviCtrl.Command = SPI_CMD_USER; |
43 | ToNaviCtrl.IntegralNick = 0; |
43 | ToNaviCtrl.IntegralNick = 0; |
44 | ToNaviCtrl.IntegralRoll = 0; |
44 | ToNaviCtrl.IntegralRoll = 0; |
45 | SPI_RxDataValid = 0; |
45 | SPI_RxDataValid = 0; |
46 | } |
46 | } |
47 | 47 | ||
48 | //------------------------------------------------------ |
48 | //------------------------------------------------------ |
49 | void SPI_StartTransmitPacket(void) |
49 | void SPI_StartTransmitPacket(void) |
50 | { |
50 | { |
51 | //if ((SLAVE_SELECT_PORT & (1 << SPI_SLAVE_SELECT)) == 0) return; // transfer of prev. packet not completed |
51 | //if ((SLAVE_SELECT_PORT & (1 << SPI_SLAVE_SELECT)) == 0) return; // transfer of prev. packet not completed |
52 | if (!SPITransferCompleted) return; |
52 | if (!SPITransferCompleted) return; |
53 | // _delay_us(30); |
53 | // _delay_us(30); |
54 | 54 | ||
55 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
55 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
56 | SPI_TX_Buffer = (unsigned char *) &ToNaviCtrl; |
56 | SPI_TX_Buffer = (unsigned char *) &ToNaviCtrl; |
57 | 57 | ||
58 | ToNaviCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
58 | ToNaviCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
59 | if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
59 | if (SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
60 | 60 | ||
61 | SPITransferCompleted = 0; |
61 | SPITransferCompleted = 0; |
62 | UpdateSPI_Buffer(); // update buffer |
62 | UpdateSPI_Buffer(); // update buffer |
63 | 63 | ||
64 | SPI_BufferIndex = 1; |
64 | SPI_BufferIndex = 1; |
65 | //ebugOut.Analog[16]++; |
65 | //ebugOut.Analog[16]++; |
66 | // -- Debug-Output --- |
66 | // -- Debug-Output --- |
67 | //---- |
67 | //---- |
68 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
68 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
69 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
69 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
70 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
70 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
71 | ToNaviCtrl.Chksum = ToNaviCtrl.Sync1; |
71 | ToNaviCtrl.Chksum = ToNaviCtrl.Sync1; |
72 | SPDR = ToNaviCtrl.Sync1; // Start transmission |
72 | SPDR = ToNaviCtrl.Sync1; // Start transmission |
73 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
73 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
74 | 74 | ||
75 | } |
75 | } |
76 | 76 | ||
77 | //------------------------------------------------------ |
77 | //------------------------------------------------------ |
78 | //SIGNAL(SIG_SPI) |
78 | //SIGNAL(SIG_SPI) |
79 | void SPI_TransmitByte(void) |
79 | void SPI_TransmitByte(void) |
80 | { |
80 | { |
81 | static unsigned char SPI_RXState = 0; |
81 | static unsigned char SPI_RXState = 0; |
82 | unsigned char rxdata; |
82 | unsigned char rxdata; |
83 | static unsigned char rxchksum; |
83 | static unsigned char rxchksum; |
84 | 84 | ||
85 | if (SPITransferCompleted) return; |
85 | if (SPITransferCompleted) return; |
86 | if (!(SPSR & (1 << SPIF))) return; |
86 | if (!(SPSR & (1 << SPIF))) return; |
87 | SendSPI = 4; |
87 | SendSPI = 4; |
88 | 88 | ||
89 | // _delay_us(30); |
89 | // _delay_us(30); |
90 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
90 | SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
91 | 91 | ||
92 | rxdata = SPDR; |
92 | rxdata = SPDR; |
93 | switch ( SPI_RXState) |
93 | switch ( SPI_RXState) |
94 | { |
94 | { |
95 | case 0: |
95 | case 0: |
96 | 96 | ||
97 | SPI_RxBufferIndex = 0; |
97 | SPI_RxBufferIndex = 0; |
98 | //DebugOut.Analog[17]++; |
98 | //DebugOut.Analog[17]++; |
99 | rxchksum = rxdata; |
99 | rxchksum = rxdata; |
100 | if (rxdata == 0x81 ) { SPI_RXState = 1; } // 1. Syncbyte ok |
100 | if (rxdata == 0x81 ) { SPI_RXState = 1; } // 1. Syncbyte ok |
101 | 101 | ||
102 | break; |
102 | break; |
103 | 103 | ||
104 | case 1: |
104 | case 1: |
105 | if (rxdata == 0x55) { rxchksum += rxdata; SPI_RXState = 2; } // 2. Syncbyte ok |
105 | if (rxdata == 0x55) { rxchksum += rxdata; SPI_RXState = 2; } // 2. Syncbyte ok |
106 | else SPI_RXState = 0; |
106 | else SPI_RXState = 0; |
107 | //DebugOut.Analog[18]++; |
107 | //DebugOut.Analog[18]++; |
108 | break; |
108 | break; |
109 | 109 | ||
110 | case 2: |
110 | case 2: |
111 | SPI_Buffer[SPI_RxBufferIndex++]= rxdata; // get data |
111 | SPI_Buffer[SPI_RxBufferIndex++]= rxdata; // get data |
112 | //DebugOut.Analog[19]++; |
112 | //DebugOut.Analog[19]++; |
113 | if (SPI_RxBufferIndex >= sizeof(FromNaviCtrl)) |
113 | if (SPI_RxBufferIndex >= sizeof(FromNaviCtrl)) |
114 | { |
114 | { |
115 | 115 | ||
116 | if (rxdata == rxchksum) |
116 | if (rxdata == rxchksum) |
117 | { |
117 | { |
118 | unsigned char *ptr = (unsigned char *)&FromNaviCtrl; |
118 | unsigned char *ptr = (unsigned char *)&FromNaviCtrl; |
119 | 119 | ||
120 | memcpy(ptr, (unsigned char *) SPI_Buffer, sizeof(SPI_Buffer)); |
120 | memcpy(ptr, (unsigned char *) SPI_Buffer, sizeof(SPI_Buffer)); |
121 | 121 | ||
122 | SPI_RxDataValid = 1; |
122 | SPI_RxDataValid = 1; |
123 | } |
123 | } |
124 | else SPI_RxDataValid = 0; |
124 | else SPI_RxDataValid = 0; |
125 | 125 | ||
126 | SPI_RXState = 0; |
126 | SPI_RXState = 0; |
127 | } |
127 | } |
128 | else rxchksum += rxdata; |
128 | else rxchksum += rxdata; |
129 | break; |
129 | break; |
130 | 130 | ||
131 | } |
131 | } |
132 | 132 | ||
133 | if (SPI_BufferIndex < sizeof(ToNaviCtrl)) |
133 | if (SPI_BufferIndex < sizeof(ToNaviCtrl)) |
134 | { |
134 | { |
135 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
135 | SLAVE_SELECT_PORT &= ~(1 << SPI_SLAVE_SELECT); // SelectSlave |
136 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
136 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
137 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
137 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
138 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
138 | asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); asm volatile ("nop"); |
139 | 139 | ||
140 | SPDR = SPI_TX_Buffer[SPI_BufferIndex]; |
140 | SPDR = SPI_TX_Buffer[SPI_BufferIndex]; |
141 | ToNaviCtrl.Chksum += SPI_TX_Buffer[SPI_BufferIndex]; |
141 | ToNaviCtrl.Chksum += SPI_TX_Buffer[SPI_BufferIndex]; |
142 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
142 | // SLAVE_SELECT_PORT |= (1 << SPI_SLAVE_SELECT); // DeselectSlave |
143 | 143 | ||
144 | } |
144 | } |
145 | else SPITransferCompleted = 1; |
145 | else SPITransferCompleted = 1; |
146 | 146 | ||
147 | SPI_BufferIndex++; |
147 | SPI_BufferIndex++; |
148 | } |
148 | } |
149 | 149 | ||
150 | 150 | ||
151 | //------------------------------------------------------ |
151 | //------------------------------------------------------ |
152 | void UpdateSPI_Buffer(void) |
152 | void UpdateSPI_Buffer(void) |
153 | { |
153 | { |
154 | static unsigned char i =0; |
154 | static unsigned char i =0; |
155 | signed int tmp; |
155 | signed int tmp; |
156 | cli(); |
156 | cli(); |
157 | 157 | ||
158 | ToNaviCtrl.IntegralNick = (int) (IntegralNick / 108); |
158 | ToNaviCtrl.IntegralNick = (int) (IntegralNick / 108); |
159 | ToNaviCtrl.IntegralRoll = (int) (IntegralRoll / 108); |
159 | ToNaviCtrl.IntegralRoll = (int) (IntegralRoll / 108); |
160 | ToNaviCtrl.GyroCompass = ErsatzKompass / GIER_GRAD_FAKTOR; |
160 | ToNaviCtrl.GyroCompass = ErsatzKompass / GIER_GRAD_FAKTOR; |
161 | ToNaviCtrl.AccNick = (int) ACC_AMPLIFY * (NaviAccNick / NaviCntAcc); |
161 | ToNaviCtrl.AccNick = (int) ACC_AMPLIFY * (NaviAccNick / NaviCntAcc); |
162 | ToNaviCtrl.AccRoll = (int) ACC_AMPLIFY * (NaviAccRoll / NaviCntAcc); |
162 | ToNaviCtrl.AccRoll = (int) ACC_AMPLIFY * (NaviAccRoll / NaviCntAcc); |
163 | NaviCntAcc = 0; NaviAccNick = 0; NaviAccRoll = 0; |
163 | NaviCntAcc = 0; NaviAccNick = 0; NaviAccRoll = 0; |
164 | // ToNaviCtrl.User8 = Parameter_UserParam8; |
164 | // ToNaviCtrl.User8 = Parameter_UserParam8; |
165 | // ToNaviCtrl.CalState = WinkelOut.CalcState; |
165 | // ToNaviCtrl.CalState = WinkelOut.CalcState; |
166 | 166 | ||
167 | switch(ToNaviCtrl.Command) // |
167 | switch(ToNaviCtrl.Command) // |
168 | { |
168 | { |
169 | case SPI_CMD_USER: |
169 | case SPI_CMD_USER: |
170 | ToNaviCtrl.Param.Byte[0] = Parameter_UserParam1; |
170 | ToNaviCtrl.Param.Byte[0] = Parameter_UserParam1; |
171 | ToNaviCtrl.Param.Byte[1] = Parameter_UserParam2; |
171 | ToNaviCtrl.Param.Byte[1] = Parameter_UserParam2; |
172 | ToNaviCtrl.Param.Byte[2] = Parameter_UserParam3; |
172 | ToNaviCtrl.Param.Byte[2] = Parameter_UserParam3; |
173 | ToNaviCtrl.Param.Byte[3] = Parameter_UserParam4; |
173 | ToNaviCtrl.Param.Byte[3] = Parameter_UserParam4; |
174 | ToNaviCtrl.Param.Byte[4] = Parameter_UserParam5; |
174 | ToNaviCtrl.Param.Byte[4] = Parameter_UserParam5; |
175 | ToNaviCtrl.Param.Byte[5] = Parameter_UserParam6; |
175 | ToNaviCtrl.Param.Byte[5] = Parameter_UserParam6; |
176 | ToNaviCtrl.Param.Byte[6] = Parameter_UserParam7; |
176 | ToNaviCtrl.Param.Byte[6] = Parameter_UserParam7; |
177 | ToNaviCtrl.Param.Byte[7] = Parameter_UserParam8; |
177 | ToNaviCtrl.Param.Byte[7] = Parameter_UserParam8; |
178 | ToNaviCtrl.Param.Byte[8] = (unsigned char) MikroKopterFlags; |
178 | ToNaviCtrl.Param.Byte[8] = (unsigned char) MikroKopterFlags; |
179 | MikroKopterFlags &= ~(FLAG_CALIBRATE | FLAG_START); |
179 | MikroKopterFlags &= ~(FLAG_CALIBRATE | FLAG_START); |
180 | ToNaviCtrl.Param.Byte[9] = (unsigned char) UBat; |
180 | ToNaviCtrl.Param.Byte[9] = (unsigned char) UBat; |
181 | ToNaviCtrl.Param.Byte[10] =(unsigned char) EE_Parameter.UnterspannungsWarnung; |
181 | ToNaviCtrl.Param.Byte[10] =(unsigned char) EE_Parameter.UnterspannungsWarnung; |
182 | ToNaviCtrl.Param.Byte[11] =(unsigned char) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
182 | ToNaviCtrl.Param.Byte[11] =(unsigned char) eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
183 | break; |
183 | break; |
184 | 184 | ||
185 | case SPI_CMD_PARAMETER1: |
185 | case SPI_CMD_PARAMETER1: |
186 | ToNaviCtrl.Param.Byte[0] = Parameter_NaviGpsModeControl; // Parameters for the Naviboard |
186 | ToNaviCtrl.Param.Byte[0] = Parameter_NaviGpsModeControl; // Parameters for the Naviboard |
187 | ToNaviCtrl.Param.Byte[1] = Parameter_NaviGpsGain; |
187 | ToNaviCtrl.Param.Byte[1] = Parameter_NaviGpsGain; |
188 | ToNaviCtrl.Param.Byte[2] = Parameter_NaviGpsP; |
188 | ToNaviCtrl.Param.Byte[2] = Parameter_NaviGpsP; |
189 | ToNaviCtrl.Param.Byte[3] = Parameter_NaviGpsI; |
189 | ToNaviCtrl.Param.Byte[3] = Parameter_NaviGpsI; |
190 | ToNaviCtrl.Param.Byte[4] = Parameter_NaviGpsD; |
190 | ToNaviCtrl.Param.Byte[4] = Parameter_NaviGpsD; |
191 | ToNaviCtrl.Param.Byte[5] = Parameter_NaviGpsACC; |
191 | ToNaviCtrl.Param.Byte[5] = Parameter_NaviGpsACC; |
192 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsMinSat; |
192 | ToNaviCtrl.Param.Byte[6] = EE_Parameter.NaviGpsMinSat; |
193 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviStickThreshold; |
193 | ToNaviCtrl.Param.Byte[7] = EE_Parameter.NaviStickThreshold; |
194 | ToNaviCtrl.Param.Byte[8] = 15; // MaxRadius |
194 | ToNaviCtrl.Param.Byte[8] = 15; // MaxRadius |
195 | break; |
195 | break; |
196 | 196 | ||
197 | case SPI_CMD_STICK: |
197 | case SPI_CMD_STICK: |
198 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
198 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GAS]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
199 | ToNaviCtrl.Param.Byte[0] = (char) tmp; |
199 | ToNaviCtrl.Param.Byte[0] = (char) tmp; |
200 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
200 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_GIER]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
201 | ToNaviCtrl.Param.Byte[1] = (char) tmp; |
201 | ToNaviCtrl.Param.Byte[1] = (char) tmp; |
202 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
202 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_ROLL]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
203 | ToNaviCtrl.Param.Byte[2] = (char) tmp; |
203 | ToNaviCtrl.Param.Byte[2] = (char) tmp; |
204 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
204 | tmp = PPM_in[EE_Parameter.Kanalbelegung[K_NICK]]; if(tmp > 127) tmp = 127; else if(tmp < -127) tmp = -127; |
205 | ToNaviCtrl.Param.Byte[3] = (char) tmp; |
205 | ToNaviCtrl.Param.Byte[3] = (char) tmp; |
206 | ToNaviCtrl.Param.Byte[4] = (unsigned char) Poti1; |
206 | ToNaviCtrl.Param.Byte[4] = (unsigned char) Poti1; |
207 | ToNaviCtrl.Param.Byte[5] = (unsigned char) Poti2; |
207 | ToNaviCtrl.Param.Byte[5] = (unsigned char) Poti2; |
208 | ToNaviCtrl.Param.Byte[6] = (unsigned char) Poti3; |
208 | ToNaviCtrl.Param.Byte[6] = (unsigned char) Poti3; |
209 | ToNaviCtrl.Param.Byte[7] = (unsigned char) Poti4; |
209 | ToNaviCtrl.Param.Byte[7] = (unsigned char) Poti4; |
210 | ToNaviCtrl.Param.Byte[8] = (unsigned char) SenderOkay; |
210 | ToNaviCtrl.Param.Byte[8] = (unsigned char) SenderOkay; |
211 | break; |
211 | break; |
212 | case SPI_CMD_CAL_COMPASS: |
212 | case SPI_CMD_CAL_COMPASS: |
213 | if(WinkelOut.CalcState > 5) |
213 | if(WinkelOut.CalcState > 5) |
214 | { |
214 | { |
215 | WinkelOut.CalcState = 0; |
215 | WinkelOut.CalcState = 0; |
216 | ToNaviCtrl.Param.Byte[0] = 5; |
216 | ToNaviCtrl.Param.Byte[0] = 5; |
217 | } |
217 | } |
218 | else ToNaviCtrl.Param.Byte[0] = WinkelOut.CalcState; |
218 | else ToNaviCtrl.Param.Byte[0] = WinkelOut.CalcState; |
219 | break; |
219 | break; |
220 | 220 | ||
221 | case SPI_CMD_VERSION: |
221 | case SPI_CMD_VERSION: |
222 | ToNaviCtrl.Param.Byte[0] = VersionInfo.Hauptversion; |
222 | ToNaviCtrl.Param.Byte[0] = VersionInfo.Hauptversion; |
223 | ToNaviCtrl.Param.Byte[1] = VersionInfo.Nebenversion; |
223 | ToNaviCtrl.Param.Byte[1] = VersionInfo.Nebenversion; |
224 | ToNaviCtrl.Param.Byte[2] = VersionInfo.PCKompatibel; |
224 | ToNaviCtrl.Param.Byte[2] = VersionInfo.PCKompatibel; |
225 | ToNaviCtrl.Param.Byte[3] = VersionInfo.Patch; |
225 | ToNaviCtrl.Param.Byte[3] = VersionInfo.Patch; |
226 | break; |
226 | break; |
227 | } |
227 | } |
228 | 228 | ||
229 | sei(); |
229 | sei(); |
230 | 230 | ||
231 | if (SPI_RxDataValid) |
231 | if (SPI_RxDataValid) |
232 | { |
232 | { |
233 | if(abs(FromNaviCtrl.GPS_Nick) < 512 && abs(FromNaviCtrl.GPS_Roll) < 512 && (EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)) |
233 | if(abs(FromNaviCtrl.GPS_Nick) < 512 && abs(FromNaviCtrl.GPS_Roll) < 512 && (EE_Parameter.GlobalConfig & CFG_GPS_AKTIV)) |
234 | { |
234 | { |
235 | GPS_Nick = FromNaviCtrl.GPS_Nick; |
235 | GPS_Nick = FromNaviCtrl.GPS_Nick; |
236 | GPS_Roll = FromNaviCtrl.GPS_Roll; |
236 | GPS_Roll = FromNaviCtrl.GPS_Roll; |
237 | } |
237 | } |
238 | if(FromNaviCtrl.CompassValue <= 360) KompassValue = FromNaviCtrl.CompassValue; |
238 | if(FromNaviCtrl.CompassValue <= 360) KompassValue = FromNaviCtrl.CompassValue; |
239 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
239 | KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180; |
240 | 240 | ||
241 | if(FromNaviCtrl.BeepTime > beeptime && !WinkelOut.CalcState) beeptime = FromNaviCtrl.BeepTime; |
241 | if(FromNaviCtrl.BeepTime > beeptime && !WinkelOut.CalcState) beeptime = FromNaviCtrl.BeepTime; |
242 | 242 | ||
243 | switch (FromNaviCtrl.Command) |
243 | switch (FromNaviCtrl.Command) |
244 | { |
244 | { |
- | 245 | case SPI_KALMAN: |
|
- | 246 | FromNaviCtrl_Value.Kalman_K = FromNaviCtrl.Param.Byte[0]; |
|
- | 247 | FromNaviCtrl_Value.Kalman_MaxFusion = FromNaviCtrl.Param.Byte[1]; |
|
- | 248 | FromNaviCtrl_Value.Kalman_MaxDrift = FromNaviCtrl.Param.Byte[2]; |
|
- | 249 | break; |
|
- | 250 | ||
245 | case SPI_CMD_OSD_DATA: |
251 | case SPI_CMD_OSD_DATA: |
246 | FromNaviCtrl_Value.OsdBar = FromNaviCtrl.Param.Byte[0]; |
252 | FromNaviCtrl_Value.OsdBar = FromNaviCtrl.Param.Byte[0]; |
247 | FromNaviCtrl_Value.Distance = FromNaviCtrl.Param.Int[1]; |
253 | FromNaviCtrl_Value.Distance = FromNaviCtrl.Param.Int[1]; |
248 | break; |
254 | break; |
249 | 255 | ||
250 | case SPI_CMD_GPS_POS: |
256 | case SPI_CMD_GPS_POS: |
251 | // ToFlightCtrl.Param.Long[0] = GPS_Data.Longitude; |
257 | // ToFlightCtrl.Param.Long[0] = GPS_Data.Longitude; |
252 | // ToFlightCtrl.Param.Long[1] = GPS_Data.Latitude; |
258 | // ToFlightCtrl.Param.Long[1] = GPS_Data.Latitude; |
253 | break; |
259 | break; |
254 | 260 | ||
255 | case SPI_CMD_GPS_TARGET: |
261 | case SPI_CMD_GPS_TARGET: |
256 | // ToFlightCtrl.Param.Long[0] = GPS_Data.TargetLongitude; |
262 | // ToFlightCtrl.Param.Long[0] = GPS_Data.TargetLongitude; |
257 | // ToFlightCtrl.Param.Long[1] = GPS_Data.TargetLatitude; |
263 | // ToFlightCtrl.Param.Long[1] = GPS_Data.TargetLatitude; |
258 | break; |
264 | break; |
259 | 265 | ||
260 | default: |
266 | default: |
261 | break; |
267 | break; |
262 | } |
268 | } |
263 | } |
269 | } |
264 | else |
270 | else |
265 | { |
271 | { |
266 | // KompassValue = 0; |
272 | // KompassValue = 0; |
267 | // KompassRichtung = 0; |
273 | // KompassRichtung = 0; |
268 | 274 | ||
269 | GPS_Nick = 0; |
275 | GPS_Nick = 0; |
270 | GPS_Roll = 0; |
276 | GPS_Roll = 0; |
271 | } |
277 | } |
272 | } |
278 | } |
273 | 279 | ||
274 | #endif |
280 | #endif |
275 | 281 | ||
276 | 282 | ||
277 | 283 |