Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8488a38

Browse files
Added code to fail gracefully if screen is rotated.
1 parent 877b0a6 commit 8488a38

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

raspi2png

792 Bytes
Binary file not shown.

raspi2png.c

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,53 @@ int main(int argc, char *argv[])
309309

310310
//-------------------------------------------------------------------
311311

312+
bcm_host_init();
313+
314+
//-------------------------------------------------------------------
315+
//
316+
// Calling vc_dispmanx_snapshot() fails when the display is rotate
317+
// either 90 or 270 degrees. It sometimes causes the program to hang.
318+
// check the config to make sure the screen is not rotated.
319+
//
320+
321+
char response[1024];
322+
int display_rotate = 0;
323+
324+
if (vc_gencmd(response, sizeof(response), "get_config int") == 0)
325+
{
326+
char *saveptr = NULL;
327+
char *token = strtok_r(response, "\n", &saveptr);
328+
329+
while (token != NULL)
330+
{
331+
char setting[100];
332+
char value[100];
333+
334+
if (sscanf(token, "%[^=]=%s", setting, value) == 2)
335+
{
336+
if (strcmp(setting, "display_rotate") == 0)
337+
{
338+
display_rotate = strtod(value, NULL);
339+
}
340+
}
341+
342+
token = strtok_r(NULL, "\n", &saveptr);
343+
}
344+
}
345+
346+
// only need to check low bit of display_rotate (value of 1 or 3).
347+
348+
if (display_rotate & 1)
349+
{
350+
fprintf(stderr,
351+
"%s: cannot create screenshot for rotated display\n",
352+
program);
353+
354+
exit(EXIT_FAILURE);
355+
}
356+
357+
//-------------------------------------------------------------------
358+
312359
if (delay)
313360
{
314361
if (verbose)
@@ -321,8 +368,6 @@ int main(int argc, char *argv[])
321368

322369
//-------------------------------------------------------------------
323370

324-
bcm_host_init();
325-
326371
DISPMANX_DISPLAY_HANDLE_T displayHandle = vc_dispmanx_display_open(0);
327372

328373
DISPMANX_MODEINFO_T modeInfo;

0 commit comments

Comments
 (0)