@@ -93,87 +93,96 @@ int get_command(const char* str)
93
93
94
94
int take_picture (uint8_t size )
95
95
{
96
- int32_t status = OS_SUCCESS ;
96
+ uint8_t status = 1 ;
97
97
uint32_t length = 0 ;
98
98
uint8_t data [CAM_DATA_SIZE ];
99
99
uint16_t x = 0 ;
100
+ int32_t result = OS_ERROR ;
101
+ int32_t read_result = OS_SUCCESS ;
100
102
101
- // Initialize Inter-Integrated Circuit
102
- status = CAM_init_i2c ();
103
- if (status != OS_SUCCESS ) return OS_ERROR ;
103
+ while ( status == 1 )
104
+ {
105
+ // Initialize Inter-Integrated Circuit
106
+ result = CAM_init_i2c ();
107
+ if (result != OS_SUCCESS ) return OS_ERROR ;
104
108
OS_printf ("I2C initialization success\n" );
105
109
106
110
// Initialize Serial Peripheral Interface
107
- status = CAM_init_spi ();
108
- if (status != OS_SUCCESS ) return OS_ERROR ;
111
+ result = CAM_init_spi ();
112
+ if (result != OS_SUCCESS ) return OS_ERROR ;
109
113
OS_printf ("SPI initialization success\n" );
110
114
111
115
// Configure Camera for Upload
112
- status = CAM_config ();
113
- if (status != OS_SUCCESS ) return OS_ERROR ;
116
+ result = CAM_config ();
117
+ if (result != OS_SUCCESS ) return OS_ERROR ;
114
118
OS_printf ("Configuration success\n" );
115
119
116
120
// Configure Registers
117
- status = CAM_jpeg_init ();
118
- if (status != OS_SUCCESS ) return OS_ERROR ;
121
+ result = CAM_jpeg_init ();
122
+ if (result != OS_SUCCESS ) return OS_ERROR ;
119
123
OS_printf ("JPEG init success\n" );
120
124
121
125
// Configure Registers
122
- status = CAM_yuv422 ();
123
- if (status != OS_SUCCESS ) return OS_ERROR ;
126
+ result = CAM_yuv422 ();
127
+ if (result != OS_SUCCESS ) return OS_ERROR ;
124
128
OS_printf ("YUV422 success\n" );
125
129
126
130
// Configure Registers
127
- status = CAM_jpeg ();
128
- if (status != OS_SUCCESS ) return OS_ERROR ;
131
+ result = CAM_jpeg ();
132
+ if (result != OS_SUCCESS ) return OS_ERROR ;
129
133
OS_printf ("JPEG success\n" );
130
134
131
135
// Configure Camera for Size
132
- status = CAM_setup ();
133
- if (status != OS_SUCCESS ) return OS_ERROR ;
136
+ result = CAM_setup ();
137
+ if (result != OS_SUCCESS ) return OS_ERROR ;
134
138
OS_printf ("Configuration success\n" );
135
139
136
140
// Upload Size
137
- status = CAM_setSize (size );
138
- if (status != OS_SUCCESS ) return OS_ERROR ;
141
+ result = CAM_setSize (size );
142
+ if (result != OS_SUCCESS ) return OS_ERROR ;
139
143
OS_printf ("Set size success\n" );
140
144
141
145
// Prepare for Capture
142
- status = CAM_capture_prep ();
143
- if (status != OS_SUCCESS ) return OS_ERROR ;
146
+ result = CAM_capture_prep ();
147
+ if (result != OS_SUCCESS ) return OS_ERROR ;
144
148
OS_printf ("Capture prep success\n" );
145
149
146
150
// Capture Image
147
- status = CAM_capture ();
148
- if (status != OS_SUCCESS ) return OS_ERROR ;
151
+ result = CAM_capture ();
152
+ if (result != OS_SUCCESS ) return OS_ERROR ;
149
153
OS_printf ("Capture success\n" );
150
154
151
155
// Read FIFO Size
152
- status = CAM_read_fifo_length (& length );
153
- if (status != OS_SUCCESS ) return OS_ERROR ;
156
+ result = CAM_read_fifo_length (& length );
157
+ if (result != OS_SUCCESS ) return OS_ERROR ;
154
158
OS_printf ("Read fifo length success\n" );
155
159
156
160
// Prepare for FIFO Read
157
- status = CAM_read_prep ((char * ) & data , (uint16_t * ) & x );
158
- if (status != OS_SUCCESS ) return OS_ERROR ;
161
+ result = CAM_read_prep ((char * ) & data , (uint16_t * ) & x );
162
+ if (result != OS_SUCCESS ) return OS_ERROR ;
159
163
OS_printf ("Read prep success\n" );
160
164
161
165
//// Read FIFO
162
- FILE * expFile ;
163
- expFile = fopen ("exp.jpg" , "wb" );
164
-
165
- if (expFile == NULL )
166
+ while ( (status > 0 ) && (status <= 8 ) )
166
167
{
167
- OS_printf ("Error opening file!\n" );
168
- status = OS_ERROR ;
169
- }
170
168
171
- status = CAM_read ((char * ) & data , (uint16_t * ) & x , (uint8_t * ) & status );
169
+ read_result = CAM_read ((char * ) & data , (uint16_t * ) & x , (uint8_t * ) & status );
170
+
171
+ if (read_result != OS_SUCCESS )
172
+ {
173
+ OS_printf ("CAM read error" );
174
+ }
175
+ if (read_result != OS_SUCCESS ) break ;
176
+ x = 0 ;
177
+
178
+ OS_TaskDelay (250 );
179
+ }
172
180
173
- fwrite (data , x , 1 , expFile );
174
- fclose (expFile );
175
181
if (status != OS_SUCCESS ) return OS_ERROR ;
176
182
OS_printf ("FIFO success\n" );
183
+ break ;
184
+ }
185
+
177
186
178
187
return OS_SUCCESS ;
179
188
}
0 commit comments