+// Copyright (C) 2019 Jaslo Ziska
+
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <qrencode.h>
#include "photobox_photo.h"
-#include "apikey.h"
+#include "apikey.h" // are you looking for this? :)
-// fehlt in glib??
+// missing in glib???
#define G_SOURCE_FUNC(f) ((GSourceFunc) (void (*)(void)) (f))
void pb_exit(void);
int main(int argc, char *argv[])
{
if (pb_ph_init() != 0) {
- fprintf(stderr, "ERROR: pb_ph_init\n");
- return 1;
+ fprintf(stderr, "ERROR in pb_ph_init\n");
+ return EXIT_FAILURE;
}
if (gpio_map() == NULL) {
- fprintf(stderr, "ERROR: gpio_map\n");
- return 1;
+ fprintf(stderr, "ERROR in gpio_map\n");
+ return EXIT_FAILURE;
}
gtk_init(&argc, &argv);
gtk_main();
- return 0;
+ return EXIT_SUCCESS;
}
void pb_exit(void)
{
gpio_unmap();
+ pb_ph_uninit();
gtk_main_quit();
}
gtk_widget_show(button_take);
- // take picture with button
+ // take picture with button (ugly)
g_idle_add(G_SOURCE_FUNC(pb_poll_buttton), NULL);
}
pid_t pid = fork();
if (pid == 0) {
// child -> copy and upload
- if (pb_cp_dp(id) < 0) {
- fprintf(stderr, "Error: pb_cp_dp\n");
+ if (pb_cp_dp(id) != 0) {
+ fprintf(stderr, "ERROR in pb_cp_dp\n");
exit(EXIT_FAILURE);
} else {
exit(EXIT_SUCCESS);
}
} else if (pid < 0) {
- fprintf(stderr, "FORK ERROR!!!!!\n");
- // TODO: dont show qr
+ fprintf(stderr, "ERROR in fork (big problem)\n");
+
+ // try to at least save the picture (the ugly way)
+ char *cmd = "cp tmp.jpg bilder/xxxxxx.jpg";
+ for (unsigned int i = 0; i < 6; ++i) {
+ cmd[i + 18] = id[i];
+ }
+ if (system(cmd) != 0)
+ perror("ERROR in system(), picture could not be saved");
+
+ // go back to start, dont show qr
+ pb_show_main();
+ return;
}
+ // parent -> continue GUI
+
// url qr should point to
// example: https://www.dropbox.com/sh/3pq0pwednyuig86/AACx0_vjn-liY5_pP_C3nJD8a?dl=0&preview=c1b052c5.jpg
char url[] = "https://www.dropbox.com/sh/3pq0pwednyuig86/AACx0_vjn-liY5_pP_C3nJD8a?dl=0&preview=xxxxxx.jpg";
QRcode *qr = QRcode_encodeString(url, 0, QR_ECLEVEL_H, QR_MODE_8, 1);
if (qr == NULL) {
perror("Failed to generate QR-Code");
- pb_exit();
+ pb_show_main();
+ return;
}
unsigned int size = qr->width;
gtk_label_set_markup(GTK_LABEL(qr_label), text);
}
+// not proud of this
gboolean pb_poll_buttton(void)
{
if (gpio_tst(button_pin) == 0) {
}
}
+// neither of this
gboolean pb_countdown(void)
{
static int num = 0;
gtk_label_set_markup(GTK_LABEL(label_countdown),
"<span font='300' color='red'>0</span>");
- // 0 zeigen bevor der anfÃĪngt zu rechnen
+ // do all pendfing events (show 0) before taking picture
while (gtk_events_pending()) {
gtk_main_iteration();
}
- // bild aufnehmen
+ // take pic
pb_takepic();
pb_show_send();
return G_SOURCE_REMOVE;
}
- // wenn das passiert ist was schief gelaufen
- printf("etwas ist sehr schief gelaufen\n");
+
+ printf("ERROR: this should never happen?\n");
return G_SOURCE_REMOVE;
}
{
char *fn = "tmp.jpg";
if (pb_ph_capture_file(fn) != 0) {
- fprintf(stderr, "ERROR: pb_ph_capture_file\n");
+ fprintf(stderr, "ERROR in pb_ph_capture_file\n");
gtk_main_quit();
return;
}
FILE *src_file = fopen(src, "rb");
if (src_file == NULL) {
- perror("Error opening \"tmp.jpg\"");
+ perror("Error opening tmp.jpg");
return -1;
}
FILE *dest_file = fopen(dest, "wb+");
return -1;
}
+ // copy file
do {
num_read = fread(buffer, 1, 4096, src_file);
dest_fsize += num_read;
if (fwrite(buffer, 1, num_read, dest_file) != num_read && ferror(dest_file) != 0) {
fprintf(stderr, "Error writing to destination file");
+ fclose(src_file);
goto error_file;
}
} while(num_read == 4096);
+
if (ferror(src_file) != 0) {
- fprintf(stderr, "Error reading from \"tmp.jpg\"");
+ fclose(src_file);
+ fprintf(stderr, "Error reading from tmp.jpg\n");
+ perror("^");
goto error_file;
}
fclose(src_file);
+
rewind(dest_file); // from beginning for upload
// upload
curl_global_init(CURL_GLOBAL_ALL);
CURL *curl = curl_easy_init();
if (curl == NULL) {
- fprintf(stderr, "ERROR: curl_easy_init\n");
+ fprintf(stderr, "ERROR in curl_easy_init\n");
curl_global_cleanup();
goto error_file;
}
CURLcode ret = curl_easy_perform(curl);
if (ret != CURLE_OK) {
- fprintf(stderr, "ERROR: curl_easy_perform: %s\n", curl_easy_strerror(ret));
+ fprintf(stderr, "ERROR in curl_easy_perform: %s\n", curl_easy_strerror(ret));
goto error_curl;
}
- curl_slist_free_all(header);
- curl_easy_cleanup(curl);
-
- curl_global_cleanup();
-
- fclose(dest_file);
-
- return 0;
-
error_curl:
curl_slist_free_all(header);
curl_easy_cleanup(curl);
error_file:
fclose(dest_file);
- return -1;
+ return ret;
}
+// Copyright (C) 2019 Jaslo Ziska
+
#include "photobox_photo.h"
#include <stdio.h>
static Camera *camera;
static GPContext *context;
-void dumperror(GPLogLevel level, const char *domain, const char *str, void *data)
+static void dumperror(GPLogLevel level, const char *domain, const char *str, void *data)
{
// suppress unused parameter errors (ugly):
(void) level;
gp_context_unref(context);
return ret;
}
-int pb_ph_uninit(void)
+void pb_ph_uninit(void)
{
- int ret;
-
- ret = gp_camera_exit(camera, context);
+ gp_camera_exit(camera, context);
gp_context_unref(context);
-
- return ret;
}
// unused, unmaintained:
if (ret != GP_OK)
goto error_fd;
- //
ret = gp_camera_file_get(camera, camera_file_path.folder,
camera_file_path.name, GP_FILE_TYPE_NORMAL, file, context);