Commit 510c6bf1e3a6298cf244cc9bb1f75dc8442576ed
Exists in
master
Merge branch 'master' of https://gitlab.irap.omp.eu/guitastrolib/guitastro
Showing
2 changed files
with
172 additions
and
163 deletions
Show diff stats
gui/tp_audine_elec/main.cpp
1 | 1 | /* |
2 | - * Fichier pour travaux pratiques | |
3 | - * Universite de Toulouse | |
2 | + * Title: Code C de pilotage de camera Audine avec Raspberry | |
3 | + * Author: A. Klotz. Universite de Toulouse | |
4 | 4 | * |
5 | - * --- rappel des bits de donnes du port parallele pour Audine | |
6 | - * ordre : 87654321 | |
7 | - * bit 1 : horloge V1 | |
8 | - * bit 2 : horloge V2 | |
9 | - * bit 3 : horloge H1 | |
10 | - * bit 4 : horloge R (reset) | |
11 | - * bit 5 : horloge CL (clamp) | |
12 | - * bit 6 : horloge Start Convert (CAN) | |
13 | - * bit 7 : horloge Select Byte (CAN) | |
14 | - * bit 8 : horloge Select Nibble | |
5 | + * To install the GPIO access library BCM2835 for Ubuntu: | |
6 | + * Some infos: http://www.airspayce.com/mikem/bcm2835/ | |
7 | + * Install procedure: https://raspberry-projects.com/pi/programming-in-c/io-pins/bcm2835-by-mike-mccauley | |
8 | + * Do not forget to change the rights of the driver: | |
9 | + * $ sudo chown user:user /dev/gpiomem | |
10 | + * $ sudo crontab -e and add the line @reboot chown user:user /dev/gpiomem | |
15 | 11 | * |
12 | + * Code::Blocks configuration to use the GPIO library BCM2835 in C code: | |
13 | + * Menu Settings -> Compiler... | |
14 | + * Tab "Linker Settings", "Link libraries" [Add] bcm2835 [OK] | |
16 | 15 | */ |
17 | 16 | |
18 | - // https://raspberry-projects.com/pi/programming-in-c/io-pins/bcm2835-by-mike-mccauley | |
19 | -// http://www.airspayce.com/mikem/bcm2835/ | |
20 | -// sudo chown user:user /dev/gpiomem | |
21 | -// Dans CodeBlocks, Menu Settings -> Compiler Settings, tab Other compiler options: Add -lbcm2835 | |
22 | -// spyder : https://stackoverflow.com/questions/72114520/error-when-starting-spyder-on-ubuntu-22-04 | |
23 | - | |
24 | 17 | #include <stdlib.h> |
25 | 18 | #include <stdio.h> |
26 | 19 | #include <string.h> |
... | ... | @@ -46,8 +39,8 @@ |
46 | 39 | #define LEVEL_HIGH 0 |
47 | 40 | #define LEVEL_LOW 1 |
48 | 41 | |
42 | +// -- Structure of camera informations | |
49 | 43 | struct camprop { |
50 | - /* --- parametres standards, ne pas changer --- */ | |
51 | 44 | char msg[2048]; |
52 | 45 | float exptime; |
53 | 46 | int binx, biny; |
... | ... | @@ -62,30 +55,22 @@ struct camprop { |
62 | 55 | int nb_deadendphotoy; |
63 | 56 | int nb_photox; |
64 | 57 | int nb_photoy; |
65 | - unsigned short *p; | |
66 | - /* --- pour l'amplificateur des Kaf-401 --- */ | |
67 | - int ampliindex; | |
68 | - int nbampliclean; | |
69 | - timespec t1; | |
70 | - timespec t2; | |
58 | + float *p; | |
71 | 59 | }; |
72 | 60 | |
73 | -int cmdAudineAcqNormal(struct camprop *cam); | |
74 | - | |
61 | +// -- Declaration of functions | |
62 | +int tp_acquisition_fullframe(struct camprop *cam); | |
75 | 63 | static int tp_fast_vidage(struct camprop *cam); |
76 | -static int tp_read_win(struct camprop *cam); | |
77 | -static void libcam_sleep(float us); | |
78 | - | |
64 | +static int tp_read_frame(struct camprop *cam); | |
65 | +static void tp_sleep(float us); | |
79 | 66 | static int tp_zi_zh(struct camprop *cam); |
80 | 67 | static int tp_read_pel_fast2(struct camprop *cam); |
81 | - | |
82 | 68 | int tp_fast_line(struct camprop *cam); |
83 | 69 | |
84 | - | |
85 | 70 | /* |
86 | - * Attente en micro-secondes. | |
71 | + * Wait in micro-seconds. | |
87 | 72 | */ |
88 | -void libcam_sleep(float us) | |
73 | +void tp_sleep(float us) | |
89 | 74 | { |
90 | 75 | int i,n; |
91 | 76 | n = (int)(us*10); |
... | ... | @@ -94,32 +79,32 @@ void libcam_sleep(float us) |
94 | 79 | } |
95 | 80 | } |
96 | 81 | |
97 | -int cmdAudineAcqNormal(struct camprop *cam) | |
82 | +int tp_acquisition_fullframe(struct camprop *cam) | |
98 | 83 | { |
99 | 84 | int i; |
100 | - int nb_vidages = 1; | |
85 | + int nb_vidages = 2; | |
101 | 86 | /* =============================================== */ |
102 | 87 | /* === Etape de rincage de la matrice CCD === */ |
103 | 88 | /* =============================================== */ |
104 | - /* vidage de la matrice */ | |
89 | + // Vidage de la matrice | |
105 | 90 | for (i = 0; i < nb_vidages; i++) { |
106 | 91 | tp_fast_vidage(cam); |
107 | 92 | } |
108 | 93 | /* =============================================== */ |
109 | 94 | /* === Integration de l'image (attente) === */ |
110 | 95 | /* =============================================== */ |
111 | - /* Delais du temps de pose (en micro-secondes) */ | |
112 | - libcam_sleep((int) (1e6 * cam->exptime)); | |
96 | + // Delais du temps de pose (en micro-secondes) | |
97 | + tp_sleep((int) (1e6 * cam->exptime)); | |
113 | 98 | /* =============================================== */ |
114 | 99 | /* === Etape de lecture de la matrice CCD === */ |
115 | 100 | /* =============================================== */ |
116 | - /* Parametres de dimensions pour allouer le pointeur image */ | |
101 | + // Parametres de dimensions pour allouer le pointeur image | |
117 | 102 | cam->w = cam->nb_photox / cam->binx; |
118 | 103 | cam->h = cam->nb_photoy / cam->biny; |
119 | - /* Allocation memoire du pointeur image */ | |
120 | - cam->p = (unsigned short *) calloc(cam->w*cam->h, sizeof(unsigned short)); | |
121 | - /* Lecture et numรฏยฟยฝrisation de l'image vers le pointeur p */ | |
122 | - tp_read_win(cam); | |
104 | + // Allocation memoire du pointeur image | |
105 | + cam->p = (float *) calloc(cam->w*cam->h, sizeof(float)); | |
106 | + // Lecture et numรฏยฟยฝrisation de l'image vers le pointeur p | |
107 | + tp_read_frame(cam); | |
123 | 108 | return 0; |
124 | 109 | } |
125 | 110 | |
... | ... | @@ -133,25 +118,25 @@ int tp_fast_vidage(struct camprop *cam) |
133 | 118 | int i, j; |
134 | 119 | int imax, jmax, decaligne; |
135 | 120 | |
136 | - /* Nombre total de photocellules dans le registre horizontal. */ | |
121 | + // -- Nombre total de photocellules dans le registre horizontal. | |
137 | 122 | imax = cam->nb_photox + cam->nb_deadbeginphotox + cam->nb_deadendphotox; |
138 | 123 | |
139 | - /* Nombre total de photocellules dans une colonne de la matrice. */ | |
124 | + // -- Nombre total de photocellules dans une colonne de la matrice. | |
140 | 125 | jmax = cam->nb_photoy + cam->nb_deadbeginphotoy + cam->nb_deadendphotoy; |
141 | 126 | |
142 | - /* Nombre de lignes decalees a chaque boucle sur l'axe vertical. */ | |
127 | + // -- Nombre de lignes decalees a chaque boucle sur l'axe vertical. | |
143 | 128 | decaligne = 20; |
144 | 129 | |
145 | - /* Nombre total de boucles sur l'axe vertical. */ | |
130 | + // -- Nombre total de boucles sur l'axe vertical. | |
146 | 131 | jmax = (int) ceil (1. * jmax / decaligne) ; |
147 | 132 | |
148 | - /* Boucle sur les paquets de lignes. */ | |
133 | + // -- Boucle sur les paquets de lignes. | |
149 | 134 | for (j = 0; j < jmax; j++) { |
150 | - /* Decalage d'un paquet de 20 lignes. */ | |
135 | + // -- Decalage d'un paquet de 'decaligne' lignes. | |
151 | 136 | for (i = 0; i < decaligne; i++) { |
152 | 137 | tp_zi_zh(cam); |
153 | 138 | } |
154 | - /* Lecture du registre horizontal sans reset */ | |
139 | + // -- Lecture du registre horizontal sans reset | |
155 | 140 | for (i = 0; i < imax; i++) { |
156 | 141 | tp_read_pel_fast2(cam); |
157 | 142 | } |
... | ... | @@ -171,38 +156,38 @@ int tp_zi_zh(struct camprop *cam) |
171 | 156 | float tphiV=2.0; |
172 | 157 | float tphiHS=1.0; |
173 | 158 | // --- |
174 | - bcm2835_gpio_write (PHI_V1, LEVEL_HIGH) ; | |
175 | - libcam_sleep(tphiV); | |
176 | - bcm2835_gpio_write (PHI_V1, LEVEL_LOW) ; | |
177 | - bcm2835_gpio_write (PHI_V2, LEVEL_HIGH) ; | |
178 | - libcam_sleep(tphiV); | |
179 | - bcm2835_gpio_write (PHI_V1, LEVEL_HIGH) ; | |
180 | - bcm2835_gpio_write (PHI_V2, LEVEL_LOW) ; | |
181 | - libcam_sleep(tphiV); | |
182 | - bcm2835_gpio_write (PHI_V1, LEVEL_LOW) ; | |
183 | - libcam_sleep(tphiHS); | |
159 | + bcm2835_gpio_write (PHI_V1, LEVEL_HIGH); | |
160 | + tp_sleep(tphiV); | |
161 | + bcm2835_gpio_write (PHI_V1, LEVEL_LOW); | |
162 | + bcm2835_gpio_write (PHI_V2, LEVEL_HIGH); | |
163 | + tp_sleep(tphiV); | |
164 | + bcm2835_gpio_write (PHI_V1, LEVEL_HIGH); | |
165 | + bcm2835_gpio_write (PHI_V2, LEVEL_LOW); | |
166 | + tp_sleep(tphiV); | |
167 | + bcm2835_gpio_write (PHI_V1, LEVEL_LOW); | |
168 | + tp_sleep(tphiHS); | |
184 | 169 | return 0; |
185 | 170 | } |
186 | 171 | |
187 | 172 | /* |
188 | 173 | tp_read_pel_fast2(struct camprop *cam) -- |
189 | - Lecture rapide d'un pixel : decalage du registre horizontal | |
174 | + Lecture rapide d'une photocellule : decalage du registre horizontal | |
190 | 175 | sans Reset, mais sans lecture du CAN, |
191 | 176 | */ |
192 | 177 | int tp_read_pel_fast2(struct camprop *cam) |
193 | 178 | { |
194 | 179 | float tphiPIX=0.25; |
195 | 180 | // --- |
196 | - bcm2835_gpio_write (PHI_H1, LEVEL_LOW) ; | |
197 | - libcam_sleep(tphiPIX); | |
198 | - bcm2835_gpio_write (PHI_H1, LEVEL_HIGH) ; | |
199 | - libcam_sleep(tphiPIX); | |
181 | + bcm2835_gpio_write (PHI_H1, LEVEL_LOW); | |
182 | + tp_sleep(tphiPIX); | |
183 | + bcm2835_gpio_write (PHI_H1, LEVEL_HIGH); | |
184 | + tp_sleep(tphiPIX); | |
200 | 185 | return 0; |
201 | 186 | } |
202 | 187 | |
203 | 188 | /* |
204 | 189 | tp_read_pel_fast(struct camprop *cam) -- |
205 | - Lecture rapide d'un pixel : decalage du registre horizontal | |
190 | + Lecture rapide d'une photocellule : decalage du registre horizontal | |
206 | 191 | avec Reset, mais sans lecture du CAN, |
207 | 192 | */ |
208 | 193 | int tp_read_pel_fast(struct camprop *cam) |
... | ... | @@ -210,25 +195,25 @@ int tp_read_pel_fast(struct camprop *cam) |
210 | 195 | float tphiPIX=0.25; |
211 | 196 | float tphiR=0.020; |
212 | 197 | // --- |
213 | - bcm2835_gpio_write (PHI_R, LEVEL_HIGH) ; | |
214 | - libcam_sleep(tphiR); | |
215 | - bcm2835_gpio_write (PHI_R, LEVEL_LOW) ; | |
216 | - libcam_sleep(tphiR); | |
217 | - bcm2835_gpio_write (PHI_H1, LEVEL_LOW) ; | |
218 | - libcam_sleep(tphiPIX); | |
219 | - bcm2835_gpio_write (PHI_H1, LEVEL_HIGH) ; | |
220 | - libcam_sleep(tphiPIX); | |
198 | + bcm2835_gpio_write (PHI_R, LEVEL_HIGH); | |
199 | + tp_sleep(tphiR); | |
200 | + bcm2835_gpio_write (PHI_R, LEVEL_LOW); | |
201 | + tp_sleep(tphiR); | |
202 | + bcm2835_gpio_write (PHI_H1, LEVEL_LOW); | |
203 | + tp_sleep(tphiPIX); | |
204 | + bcm2835_gpio_write (PHI_H1, LEVEL_HIGH); | |
205 | + tp_sleep(tphiPIX); | |
221 | 206 | return 0; |
222 | 207 | } |
223 | 208 | |
224 | 209 | /* |
225 | 210 | tp_fast_line_() -- |
226 | - Lecture rapide du registre horizontal, avec la fonction read_pel_fast. | |
211 | + Lecture rapide du registre horizontal, avec la fonction tp_read_pel_fast. | |
227 | 212 | */ |
228 | 213 | int tp_fast_line(struct camprop *cam) |
229 | 214 | { |
230 | 215 | int i, imax; |
231 | - /* Nombre total de photocellules dans le registre horizontal. */ | |
216 | + // Nombre total de photocellules dans le registre horizontal. | |
232 | 217 | imax = cam->nb_photox + cam->nb_deadbeginphotox + cam->nb_deadendphotox; |
233 | 218 | for (i = 0; i < imax; i++) { |
234 | 219 | tp_read_pel_fast(cam); |
... | ... | @@ -236,7 +221,7 @@ int tp_fast_line(struct camprop *cam) |
236 | 221 | return 0; |
237 | 222 | } |
238 | 223 | |
239 | -int tp_read_win(struct camprop *cam) | |
224 | +int tp_read_frame(struct camprop *cam) | |
240 | 225 | { |
241 | 226 | |
242 | 227 | int i, j; |
... | ... | @@ -244,143 +229,148 @@ int tp_read_win(struct camprop *cam) |
244 | 229 | int imax, jmax; |
245 | 230 | int cx1, cx2, cy1; |
246 | 231 | unsigned short buffer[2048]; |
247 | - int x; | |
232 | + unsigned short x; | |
248 | 233 | |
249 | - /* dimensions de l'image a digitaliser */ | |
234 | + // -- Dimensions de l'image a digitaliser | |
250 | 235 | imax = cam->w; |
251 | 236 | jmax = cam->h; |
252 | - /* nombre de colonnes de debut a ne pas digitaliser */ | |
237 | + // -- Nombre de photocellules de debut de ligne a ne pas digitaliser | |
253 | 238 | cx1 = cam->nb_deadbeginphotox; |
254 | - /* nombre de colonnes de fin a ne pas digitaliser */ | |
239 | + // -- Nombre de photocellules de fin de ligne a ne pas digitaliser | |
255 | 240 | cx2 = cam->nb_deadendphotox; |
256 | - /* nombre de lignes de debut a ne pas digitaliser */ | |
241 | + // -- Nombre de lignes de debut a ne pas digitaliser | |
257 | 242 | cy1 = cam->nb_deadbeginphotoy; |
258 | 243 | |
259 | - /* On supprime les cy1 premieres lignes */ | |
244 | + // -- On supprime les cy1 premieres lignes | |
260 | 245 | for (i = 0; i < cy1; i++) { |
261 | 246 | tp_zi_zh(cam); |
262 | 247 | } |
263 | 248 | |
264 | - /* On nettoie le registre horizontal */ | |
249 | + // -- On nettoie le registre horizontal | |
265 | 250 | for (i = 0; i < 1; i++) { |
266 | 251 | tp_fast_line(cam); |
267 | 252 | } |
268 | 253 | |
269 | - /* boucle sur l'horloge verticale (transfert) */ | |
254 | + // -- Boucle sur le transfert vertical | |
270 | 255 | for (i = 0; i < jmax; i++) { |
271 | 256 | |
272 | - /* boucle de binning vertical */ | |
257 | + // -- Boucle de binning vertical | |
273 | 258 | for (k = 0; k < cam->biny; k++) { |
274 | 259 | tp_zi_zh(cam); |
275 | 260 | } |
276 | 261 | |
277 | - /* On retire les cx1 premiers pixels avec reset */ | |
262 | + // -- On retire les cx1 premieres photocellules avec reset | |
278 | 263 | for (j = 0; j < cx1; j++) { |
279 | 264 | tp_read_pel_fast(cam); |
280 | 265 | } |
281 | 266 | |
282 | - /* boucle sur l'horloge horizontale (registre de sortie) */ | |
267 | + // -- Boucle sur le transfert horizontal | |
283 | 268 | for (j = 0; j < imax; j++) { |
284 | - float tphiR=0.020; | |
269 | + float tphiR=2.0; //0.020; | |
285 | 270 | float tRef1=4.0; |
286 | 271 | float tRef2=1.0; |
287 | 272 | float tRef3=1.0; |
288 | - float tphiPIX=0.25; | |
273 | + float tphiPIX=1.0; // 0.25 | |
289 | 274 | float tVid1=4.0; |
290 | - // palier de reset | |
291 | - bcm2835_gpio_write (PHI_R, LEVEL_HIGH) ; | |
275 | + float tVid2=1.0; | |
276 | + float tSel=1.0; | |
277 | + | |
278 | + // -- Palier de reset | |
292 | 279 | bcm2835_gpio_write (PHI_H1, LEVEL_LOW) ; |
293 | - libcam_sleep(tphiR); | |
280 | + bcm2835_gpio_write (PHI_R, LEVEL_HIGH) ; | |
281 | + tp_sleep(tphiR); | |
294 | 282 | bcm2835_gpio_write (PHI_R, LEVEL_LOW) ; |
295 | - libcam_sleep(tphiR); | |
296 | - // palier de reference | |
297 | - libcam_sleep(tRef1); | |
283 | + | |
284 | + // -- Palier de reference | |
285 | + tp_sleep(tRef1); | |
298 | 286 | bcm2835_gpio_write (PHI_CL, LEVEL_HIGH) ; |
299 | - libcam_sleep(tRef2); | |
287 | + tp_sleep(tRef2); | |
300 | 288 | bcm2835_gpio_write (PHI_CL, LEVEL_LOW) ; |
301 | - libcam_sleep(tRef3); | |
289 | + tp_sleep(tRef3); | |
302 | 290 | |
303 | - /* boucle de binning horizontal */ | |
291 | + // -- Boucle de binning horizontal | |
304 | 292 | for (l = 0; l < cam->binx; l++) { |
305 | 293 | bcm2835_gpio_write (PHI_H1, LEVEL_LOW) ; |
306 | - libcam_sleep(tphiPIX); | |
294 | + tp_sleep(tphiPIX); | |
307 | 295 | bcm2835_gpio_write (PHI_H1, LEVEL_HIGH) ; |
308 | - libcam_sleep(tphiPIX); | |
296 | + tp_sleep(tphiPIX); | |
309 | 297 | } |
310 | 298 | |
311 | - // palier video | |
312 | - libcam_sleep(tVid1); | |
299 | + // -- Palier video | |
300 | + tp_sleep(tVid1); | |
313 | 301 | bcm2835_gpio_write (PHI_SC, LEVEL_HIGH) ; |
302 | + tp_sleep(tVid2); | |
314 | 303 | |
315 | - // -- recupere le nibble _ _ _ _ _ _ _ _ _ _ _ _ 3 2 1 0 | |
304 | + // -- Recupere le nibble _ _ _ _ _ _ _ _ _ _ _ _ 3 2 1 0 | |
316 | 305 | // SB = Select Byte <---- SB=1 ----> <---- SB=0 ----> |
317 | 306 | // SN = Select Nibble <SN=1 > <SN=0 > <SN=1 > <SN=0 > |
318 | 307 | bcm2835_gpio_write (PHI_SB, LEVEL_LOW) ; |
319 | 308 | bcm2835_gpio_write (PHI_SN, LEVEL_LOW) ; |
320 | - x = (int)bcm2835_gpio_lev(BIT_0); | |
321 | - x += (int)bcm2835_gpio_lev(BIT_1) << 1; | |
322 | - x += (int)bcm2835_gpio_lev(BIT_2) << 2; | |
323 | - x += (int)bcm2835_gpio_lev(BIT_3) << 3; | |
309 | + tp_sleep(tSel); | |
310 | + x = (unsigned short)bcm2835_gpio_lev(BIT_0) ; | |
311 | + x += (unsigned short)bcm2835_gpio_lev(BIT_1) << 1; | |
312 | + x += (unsigned short)bcm2835_gpio_lev(BIT_2) << 2; | |
313 | + x += (unsigned short)bcm2835_gpio_lev(BIT_3) << 3; | |
324 | 314 | |
325 | - // -- recupere le nibble _ _ _ _ _ _ _ _ 3 2 1 0 _ _ _ _ | |
315 | + // -- Recupere le nibble _ _ _ _ _ _ _ _ 3 2 1 0 _ _ _ _ | |
326 | 316 | bcm2835_gpio_write (PHI_SB, LEVEL_LOW) ; |
327 | 317 | bcm2835_gpio_write (PHI_SN, LEVEL_HIGH) ; |
328 | - x += (int)bcm2835_gpio_lev(BIT_0) << 4; | |
329 | - x += (int)bcm2835_gpio_lev(BIT_1) << 5; | |
330 | - x += (int)bcm2835_gpio_lev(BIT_2) << 6; | |
331 | - x += (int)bcm2835_gpio_lev(BIT_3) << 7; | |
318 | + tp_sleep(tSel); | |
319 | + x += (unsigned short)bcm2835_gpio_lev(BIT_0) << 4; | |
320 | + x += (unsigned short)bcm2835_gpio_lev(BIT_1) << 5; | |
321 | + x += (unsigned short)bcm2835_gpio_lev(BIT_2) << 6; | |
322 | + x += (unsigned short)bcm2835_gpio_lev(BIT_3) << 7; | |
332 | 323 | |
333 | - // -- recupere le nibble _ _ _ _ 3 2 1 0 _ _ _ _ _ _ _ _ | |
324 | + // -- Recupere le nibble _ _ _ _ 3 2 1 0 _ _ _ _ _ _ _ _ | |
334 | 325 | bcm2835_gpio_write (PHI_SB, LEVEL_HIGH) ; |
335 | 326 | bcm2835_gpio_write (PHI_SN, LEVEL_LOW) ; |
336 | - x += (int)bcm2835_gpio_lev(BIT_0) << 8; | |
337 | - x += (int)bcm2835_gpio_lev(BIT_1) << 9; | |
338 | - x += (int)bcm2835_gpio_lev(BIT_2) << 10; | |
339 | - x += (int)bcm2835_gpio_lev(BIT_3) << 11; | |
327 | + tp_sleep(tSel); | |
328 | + x += (unsigned short)bcm2835_gpio_lev(BIT_0) << 8; | |
329 | + x += (unsigned short)bcm2835_gpio_lev(BIT_1) << 9; | |
330 | + x += (unsigned short)bcm2835_gpio_lev(BIT_2) << 10; | |
331 | + x += (unsigned short)bcm2835_gpio_lev(BIT_3) << 11; | |
340 | 332 | |
341 | - // -- recupere le nibble 3 2 1 0 _ _ _ _ _ _ _ _ _ _ _ _ | |
333 | + // -- Recupere le nibble 3 2 1 0 _ _ _ _ _ _ _ _ _ _ _ _ | |
342 | 334 | bcm2835_gpio_write (PHI_SB, LEVEL_HIGH) ; |
343 | 335 | bcm2835_gpio_write (PHI_SN, LEVEL_HIGH) ; |
344 | - x += (int)bcm2835_gpio_lev(BIT_0) << 12; | |
345 | - x += (int)bcm2835_gpio_lev(BIT_1) << 13; | |
346 | - x += (int)bcm2835_gpio_lev(BIT_2) << 14; | |
347 | - x += (int)bcm2835_gpio_lev(BIT_3) << 15; | |
336 | + tp_sleep(tSel); | |
337 | + x += (unsigned short)bcm2835_gpio_lev(BIT_0) << 12; | |
338 | + x += (unsigned short)bcm2835_gpio_lev(BIT_1) << 13; | |
339 | + x += (unsigned short)bcm2835_gpio_lev(BIT_2) << 14; | |
340 | + x += (unsigned short)bcm2835_gpio_lev(BIT_3) << 15; | |
348 | 341 | |
349 | - // -- remises au niveaux bas | |
342 | + // -- Remises aux niveaux bas | |
350 | 343 | bcm2835_gpio_write (PHI_SC, LEVEL_LOW) ; |
351 | 344 | bcm2835_gpio_write (PHI_SB, LEVEL_LOW) ; |
352 | 345 | bcm2835_gpio_write (PHI_SN, LEVEL_LOW) ; |
353 | 346 | |
354 | - if (x > 32767) { | |
355 | - x = 32767; | |
356 | - } | |
357 | - /* Stockage dans un buffer dans la meme page mem */ | |
358 | - buffer[j] = (unsigned short) x; | |
347 | + // -- Stockage du pixel dans un buffer de ligne | |
348 | + buffer[j] = x; | |
359 | 349 | |
360 | 350 | } |
361 | 351 | |
362 | - /* On retire cx2 pixels a la fin */ | |
352 | + // -- On retire cx2 photocellules a la fin | |
363 | 353 | for (j = 0; j < cx2; j++) { |
364 | 354 | tp_read_pel_fast(cam); |
365 | 355 | } |
366 | 356 | |
367 | - /* On transfere le tableau vers la matrice image */ | |
357 | + // -- On transfere le buffer de ligne vers la matrice image | |
368 | 358 | if (i != 0) { |
369 | - cam->p[(i - 1) * imax] = buffer[0]; | |
359 | + cam->p[(i - 1) * imax] = (float)buffer[0]; | |
370 | 360 | } |
371 | 361 | for (j = 1; j < imax; j++) { |
372 | - cam->p[(i + 1) * imax - j] = buffer[j]; | |
362 | + cam->p[(i + 1) * imax - j] = (float)buffer[j]; | |
373 | 363 | } |
374 | 364 | |
375 | 365 | } |
376 | 366 | return 0; |
377 | 367 | } |
378 | 368 | |
379 | -void mc_savefits(struct camprop *cam, char *filename) | |
369 | +void tp_savefits(struct camprop *cam, char *filename) | |
380 | 370 | { |
381 | 371 | FILE *f; |
382 | 372 | char line[1024],car; |
383 | - float value0; | |
373 | + short value0; | |
384 | 374 | char *cars0; |
385 | 375 | int k,k0; |
386 | 376 | long one= 1; |
... | ... | @@ -396,9 +386,9 @@ void mc_savefits(struct camprop *cam, char *filename) |
396 | 386 | fwrite(line,80,sizeof(char),f); |
397 | 387 | sprintf(line,"NAXIS2 = %3d / length of data axis 2 ",cam->h); |
398 | 388 | fwrite(line,80,sizeof(char),f); |
399 | - strcpy(line,"BZERO = 32768 / uint16 "); | |
389 | + strcpy(line,"BZERO = 32768 / uint16 32768 "); | |
400 | 390 | fwrite(line,80,sizeof(char),f); |
401 | - strcpy(line,"BSCALE = 1 / uint16 "); | |
391 | + strcpy(line,"BSCALE = 1 / uint16 1 "); | |
402 | 392 | fwrite(line,80,sizeof(char),f); |
403 | 393 | k0=9; |
404 | 394 | strcpy(line,"END "); |
... | ... | @@ -407,25 +397,24 @@ void mc_savefits(struct camprop *cam, char *filename) |
407 | 397 | for (k=k0;k<=36;k++) { |
408 | 398 | fwrite(line,80,sizeof(char),f); |
409 | 399 | } |
410 | - /* byte order test */ | |
400 | + // -- Byte order test | |
411 | 401 | if (!(*((char *)(&one)))) { |
412 | 402 | big_endian=1; |
413 | 403 | } else { |
414 | 404 | big_endian=0; |
415 | 405 | } |
416 | - /* write data */ | |
406 | + // -- Write data | |
417 | 407 | for (k=0;k<cam->h*cam->w;k++) { |
418 | - value0=cam->p[k]; // 32=4*8bits | |
408 | + value0 = cam->p[k]-32768; | |
419 | 409 | if (big_endian==0) { |
420 | 410 | cars0=(char*)&value0; |
421 | 411 | car=cars0[0]; |
422 | 412 | cars0[0]=cars0[1]; |
423 | 413 | cars0[1]=car; |
424 | 414 | } |
425 | - fwrite(&value0,1,sizeof(unsigned short),f); | |
415 | + fwrite(&value0,1,sizeof(short),f); | |
426 | 416 | } |
427 | 417 | int n= (cam->h*cam->w) % 2880 -1; |
428 | - //printf("big_endian=%d n=%d",big_endian, n); | |
429 | 418 | value0=(float)0.; |
430 | 419 | for (k=0;k<n;k++) { |
431 | 420 | if (big_endian==0) { |
... | ... | @@ -434,22 +423,24 @@ void mc_savefits(struct camprop *cam, char *filename) |
434 | 423 | cars0[0]=cars0[1]; |
435 | 424 | cars0[1]=car; |
436 | 425 | } |
437 | - fwrite(&value0,1,sizeof(unsigned short),f); | |
426 | + fwrite(&value0,1,sizeof(short),f); | |
438 | 427 | } |
439 | 428 | fclose(f); |
440 | 429 | } |
441 | 430 | |
431 | +// -- This is the start point of the program | |
442 | 432 | int main(int argc, char* argv[]) |
443 | 433 | { |
444 | 434 | |
445 | - // decode la ligne de commandes. Exemple : tp_ccd.exe 0.5 1 | |
435 | + // -- Decode la ligne de commandes. Exemple : tp_ccd.exe full_frame 0.5 1 | |
446 | 436 | char method[1024]; |
447 | 437 | float exptime = 0.5; |
448 | 438 | int binning = 1; |
439 | + strcpy(method,"full_frame"); | |
449 | 440 | if(argc < 3) |
450 | 441 | { |
451 | 442 | printf("ERR 1 : Not enough command line parameters\n: method exptime binningn"); |
452 | - //exit(1); | |
443 | + return 1; | |
453 | 444 | } else { |
454 | 445 | strcpy(method,argv[1]); |
455 | 446 | exptime = atof(argv[2]); |
... | ... | @@ -457,8 +448,8 @@ int main(int argc, char* argv[]) |
457 | 448 | } |
458 | 449 | printf("ERR 0 : %s %f %d\n", method, exptime, binning); |
459 | 450 | |
451 | + // -- Initialise la structure des donnees de la camera | |
460 | 452 | struct camprop cam; |
461 | - // === initialise la structure des donnees de la camera | |
462 | 453 | strcpy(cam.msg,""); |
463 | 454 | cam.exptime=exptime; // sec |
464 | 455 | cam.binx=binning; |
... | ... | @@ -477,15 +468,14 @@ int main(int argc, char* argv[]) |
477 | 468 | cam.nb_deadbeginphotoy=4; |
478 | 469 | cam.nb_deadendphotoy=4; |
479 | 470 | cam.p=NULL; |
480 | - /* --- pour l'amplificateur des Kaf-401 --- */ | |
481 | - cam.ampliindex=0; | |
482 | - cam.nbampliclean=0; | |
483 | - // === initialise le GPIO | |
471 | + | |
472 | + // -- Initialise le GPIO | |
484 | 473 | if (!bcm2835_init()) { |
485 | 474 | printf("Probleme bcm2835_init"); |
486 | 475 | return 1; |
487 | 476 | } |
488 | - // Set the pin to be an output | |
477 | + | |
478 | + // -- Set the pin to be an output | |
489 | 479 | bcm2835_gpio_fsel(PHI_V1, BCM2835_GPIO_FSEL_OUTP); |
490 | 480 | bcm2835_gpio_fsel(PHI_V2, BCM2835_GPIO_FSEL_OUTP); |
491 | 481 | bcm2835_gpio_fsel(PHI_H1, BCM2835_GPIO_FSEL_OUTP); |
... | ... | @@ -495,12 +485,14 @@ int main(int argc, char* argv[]) |
495 | 485 | bcm2835_gpio_fsel(PHI_SC, BCM2835_GPIO_FSEL_OUTP); |
496 | 486 | bcm2835_gpio_fsel(PHI_SN, BCM2835_GPIO_FSEL_OUTP); |
497 | 487 | bcm2835_gpio_fsel(DELAY, BCM2835_GPIO_FSEL_OUTP); // special delay us |
498 | - // Set the pin to be an input | |
488 | + | |
489 | + // -- Set the pin to be an input | |
499 | 490 | bcm2835_gpio_fsel(BIT_0, BCM2835_GPIO_FSEL_INPT); |
500 | 491 | bcm2835_gpio_fsel(BIT_1, BCM2835_GPIO_FSEL_INPT); |
501 | 492 | bcm2835_gpio_fsel(BIT_2, BCM2835_GPIO_FSEL_INPT); |
502 | 493 | bcm2835_gpio_fsel(BIT_3, BCM2835_GPIO_FSEL_INPT); |
503 | - // Set default values for outputs | |
494 | + | |
495 | + // -- Set default values for outputs | |
504 | 496 | bcm2835_gpio_write (PHI_V1, LEVEL_LOW) ; |
505 | 497 | bcm2835_gpio_write (PHI_V2, LEVEL_LOW) ; |
506 | 498 | bcm2835_gpio_write (PHI_H1, LEVEL_HIGH) ; |
... | ... | @@ -510,14 +502,12 @@ int main(int argc, char* argv[]) |
510 | 502 | bcm2835_gpio_write (PHI_SC, LEVEL_LOW) ; |
511 | 503 | bcm2835_gpio_write (PHI_SN, LEVEL_LOW) ; |
512 | 504 | |
505 | + // -- Select the method to apply | |
513 | 506 | if (strcmp(method, "full_frame")==0) { |
514 | - printf("=== init OK\n"); | |
515 | - cmdAudineAcqNormal(&cam); | |
516 | - printf("=== acq OK\n"); | |
507 | + tp_acquisition_fullframe(&cam); | |
517 | 508 | char filename[1024]; |
518 | 509 | strcpy(filename,"/home/user/Documents/image.fit"); |
519 | - mc_savefits(&cam, filename); | |
520 | - | |
510 | + tp_savefits(&cam, filename); | |
521 | 511 | } else if (strcmp(method, "zi_zh")==0) { |
522 | 512 | for (int i = 0; i <1; i++) { |
523 | 513 | tp_zi_zh(&cam); |
... | ... | @@ -551,7 +541,7 @@ int main(int argc, char* argv[]) |
551 | 541 | bcm2835_gpio_write (PHI_SB, LEVEL_HIGH) ; |
552 | 542 | bcm2835_gpio_write (PHI_SC, LEVEL_HIGH) ; |
553 | 543 | bcm2835_gpio_write (PHI_SN, LEVEL_HIGH) ; |
554 | - libcam_sleep(tphiV); | |
544 | + tp_sleep(tphiV); | |
555 | 545 | bcm2835_gpio_write (PHI_V1, LEVEL_LOW) ; |
556 | 546 | bcm2835_gpio_write (PHI_V2, LEVEL_LOW) ; |
557 | 547 | bcm2835_gpio_write (PHI_H1, LEVEL_LOW) ; |
... | ... | @@ -560,8 +550,27 @@ int main(int argc, char* argv[]) |
560 | 550 | bcm2835_gpio_write (PHI_SB, LEVEL_LOW) ; |
561 | 551 | bcm2835_gpio_write (PHI_SC, LEVEL_LOW) ; |
562 | 552 | bcm2835_gpio_write (PHI_SN, LEVEL_LOW) ; |
563 | - libcam_sleep(tphiHS); | |
553 | + tp_sleep(tphiHS); | |
564 | 554 | } |
555 | + } else if (strcmp(method, "set_255")==0) { | |
556 | + bcm2835_gpio_write (PHI_V1, LEVEL_HIGH) ; | |
557 | + bcm2835_gpio_write (PHI_V2, LEVEL_HIGH) ; | |
558 | + bcm2835_gpio_write (PHI_H1, LEVEL_HIGH) ; | |
559 | + bcm2835_gpio_write (PHI_R, LEVEL_HIGH) ; | |
560 | + bcm2835_gpio_write (PHI_CL, LEVEL_HIGH) ; | |
561 | + bcm2835_gpio_write (PHI_SB, LEVEL_HIGH) ; | |
562 | + bcm2835_gpio_write (PHI_SC, LEVEL_HIGH) ; | |
563 | + bcm2835_gpio_write (PHI_SN, LEVEL_HIGH) ; | |
564 | + tp_sleep(5e6); | |
565 | + } else if (strcmp(method, "set_0")==0) { | |
566 | + bcm2835_gpio_write (PHI_V1, LEVEL_LOW) ; | |
567 | + bcm2835_gpio_write (PHI_V2, LEVEL_LOW) ; | |
568 | + bcm2835_gpio_write (PHI_H1, LEVEL_LOW) ; | |
569 | + bcm2835_gpio_write (PHI_R, LEVEL_LOW) ; | |
570 | + bcm2835_gpio_write (PHI_CL, LEVEL_LOW) ; | |
571 | + bcm2835_gpio_write (PHI_SB, LEVEL_LOW) ; | |
572 | + bcm2835_gpio_write (PHI_SC, LEVEL_LOW) ; | |
573 | + bcm2835_gpio_write (PHI_SN, LEVEL_LOW) ; | |
565 | 574 | } |
566 | 575 | printf("=== Termine\n"); |
567 | 576 | return 0; | ... | ... |
gui/tp_audine_elec/tp_audine_elec.py
... | ... | @@ -55,7 +55,7 @@ if __name__ == "__main__": |
55 | 55 | print(exc) |
56 | 56 | |
57 | 57 | # --- Global variable to select the method |
58 | - methods = ["full_frame", "zi_zh", "fast_line", "read_pel_fast", "read_pel_fast2", "fast_vidage", "square_signal"] | |
58 | + methods = ["full_frame", "zi_zh", "fast_line", "read_pel_fast", "read_pel_fast2", "fast_vidage"] #, "square_signal", "set_0", "set_255"] | |
59 | 59 | |
60 | 60 | # --- Global variable to define info messages |
61 | 61 | infos = {} |
... | ... | @@ -236,7 +236,7 @@ if __name__ == "__main__": |
236 | 236 | #entry_method('<<ComboboxSelected>>', var_method) |
237 | 237 | # --- |
238 | 238 | var_exp = tk.DoubleVar() |
239 | - var_exp.set(2.0) | |
239 | + var_exp.set(0.0) | |
240 | 240 | label_exp = tk.Label(frame101m, text="Temps de pose (s)") |
241 | 241 | label_exp.pack(side = tk.LEFT) |
242 | 242 | entry_exp = tk.Entry(frame101m, width=4, textvariable=var_exp) | ... | ... |