Read about our upcoming Code of Conduct on this issue

Commit ef01fef3 authored by alex@thinkpad's avatar alex@thinkpad
Browse files

Merged img_name into lua_fix

(required to test the file number updates, i.e. wrapping around at 9999->0001)

--HG--
branch : lua_fix
......@@ -13,6 +13,7 @@ ML_MODULES ?= \
autoexpo \
arkanoid \
deflick \
img_name \
lua \
bench \
selftest \
......
//TODO: save prefix config
#include <module.h>
#include <dryos.h>
#include <property.h>
#include <bmp.h>
#include <menu.h>
#include <fileprefix.h>
#include "../ime_base/ime_base.h"
static char prefix[8];
static int key = -1;
IME_DONE_FUNC(file_prefix_enter_done)
{
if(status == IME_OK) {
if(key != -1 && key != 0) file_prefix_reset(key);
key = file_prefix_set(prefix);
}
return IME_OK;
}
IME_UPDATE_FUNC(file_prefix_enter_upd)
{
return IME_OK;
}
static MENU_SELECT_FUNC(file_prefix_enter)
{
strcpy(prefix, get_file_prefix());
ime_base_start(
(unsigned char *)"Enter file prefix",
(unsigned char *)prefix,
4,
IME_UTF8,
IME_CHARSET_FILENAME,
file_prefix_enter_upd,
file_prefix_enter_done,
0, 0, 0, 0
);
}
static MENU_UPDATE_FUNC(file_prefix_upd)
{
MENU_SET_VALUE("%s", get_file_prefix());
if(key == 0)MENU_SET_RINFO("FAILED");
else MENU_SET_RINFO("");
}
static struct menu_entry ime_base_menu[] =
{
{
.name = "File prefix",
.select = file_prefix_enter,
.update = file_prefix_upd,
.help = "Custom file prefix (e.g. IMG_1234.JPG -> ABCD1234.JPG).",
.help2 = "There can be some conflict with Dual ISO prefixes.",
}
};
unsigned int filepref_init()
{
menu_add("Prefs", ime_base_menu, COUNT(ime_base_menu));
return 0;
}
unsigned int filepref_deinit()
{
return 0;
}
MODULE_INFO_START()
MODULE_INIT(filepref_init)
MODULE_DEINIT(filepref_deinit)
MODULE_INFO_END()
\ No newline at end of file
# define the module name - make sure name is max 8 characters
MODULE_NAME=filepref
MODULE_OBJS=filepref.o
MODULE_NAME=img_name
MODULE_OBJS=img_name.o
# include modules environment
include ../Makefile.modules
......
Image name preferences
======================
This module lets you customize image file names:
- custom file prefix (IMG_1234.CR2 -> ABCD1234.CR2)
- change file number (IMG_1234.CR2 -> IMG_5678.CR2;
requires restart)
- change folder number (DCIM/100CANON -> 123CANON)
You will find the new options under the Shoot menu.
:Authors: pravdomil, a1ex
:License: GPL
:Summary: Customize Canon's image file naming (IMG_1234.CR2 -> ABCD1234.CR2)
:Forum: http://www.magiclantern.fm/forum/index.php?topic=21111.0
//TODO: save prefix config
#include <module.h>
#include <dryos.h>
#include <property.h>
#include <bmp.h>
#include <menu.h>
#include <fileprefix.h>
#include <config.h>
#include "../ime_base/ime_base.h"
static char default_prefix[8];
static char prefix[8];
static int key = -1;
/* prefix has 4 characters - encode it as 32-bit integer */
static CONFIG_INT("image.prefix", prefix_enc, 0);
static IME_DONE_FUNC(file_prefix_enter_done)
{
if (status == IME_OK)
{
/* if user entered less than 4 characters, fill with _ */
prefix[4] = 0;
int len = strlen(prefix);
for (int i = len; i < 4; i++)
{
prefix[i] = '_';
}
/* any previously set prefix? */
if (key != -1 && key != 0)
{
file_prefix_reset(key);
key = -1;
}
/* set the new prefix, if different from default */
if (!streq(prefix, default_prefix))
{
key = file_prefix_set(prefix);
/* update encoded prefix (this goes into config file) */
prefix_enc = *(int*)prefix;
}
else
{
/* disable user-set prefix */
prefix_enc = 0;
}
}
return IME_OK;
}
static IME_UPDATE_FUNC(file_prefix_enter_upd)
{
return IME_OK;
}
static MENU_SELECT_FUNC(file_prefix_enter)
{
snprintf(prefix, sizeof(prefix), "%s", get_file_prefix());
ime_base_start(
"Enter file prefix",
prefix,
5,
IME_UTF8,
IME_CHARSET_FILENAME,
file_prefix_enter_upd,
file_prefix_enter_done,
0, 0, 0, 0
);
}
static MENU_UPDATE_FUNC(file_prefix_upd)
{
/* fixme: update menu backend so it doesn't require so many workarounds */
switch (key)
{
case -1:
MENU_SET_VALUE("OFF");
MENU_SET_RINFO(default_prefix);
MENU_SET_ENABLED(0);
MENU_SET_ICON(MNI_DICE_OFF, 0);
break;
case 0:
MENU_SET_VALUE("FAILED");
MENU_SET_RINFO(get_file_prefix());
MENU_SET_ICON(MNI_RECORD, 0);
break;
default:
MENU_SET_ENABLED(1);
MENU_SET_VALUE("%s", get_file_prefix());
MENU_SET_RINFO("");
MENU_SET_ICON(MNI_DICE_OFF, 1);
break;
}
if ((void *) &ime_base_start == (void *) &ret_0)
{
MENU_SET_WARNING(MENU_WARN_NOT_WORKING, "Please load the IME modules (ime_base.mo and one ime_*.mo)");
}
}
static int file_num = -1;
static int file_num_canon = -1;
static int file_num_requested = -1;
static int file_num_dirty = 0;
static int folder_num = -1;
static int folder_num_canon = -1;
static int folder_num_requested = -1;
static int folder_num_dirty = 0;
static void file_folder_number_refresh()
{
int file_num_canon_latest = get_shooting_card()->file_number;
int folder_num_canon_latest = get_shooting_card()->folder_number;
if (file_num_canon != file_num_canon_latest)
{
/* Canon code updated their file number */
if (file_num_canon_latest != file_num_requested)
{
/* maybe an image was taken? */
/* fixme: move this logic into property handlers */
file_num_dirty = 0;
folder_num_dirty = 0;
file_num = file_num_canon = file_num_canon_latest;
}
}
ASSERT(file_num != -1);
if (folder_num_canon != folder_num_canon_latest)
{
/* Canon code updated their folder number (e.g. file_num reached 9999) */
if (folder_num_canon_latest != folder_num_requested)
{
folder_num = folder_num_canon = folder_num_canon_latest;
}
}
ASSERT(folder_num != -1);
char shooting_drive_letter = get_shooting_card()->drive_letter[0];
if (folder_num != folder_num_canon_latest)
{
folder_num_requested = folder_num;
printf("Changing folder number from %d to %d...\n", folder_num_canon_latest, folder_num_requested);
int folder_number_prop = shooting_drive_letter == 'A' ? PROP_FOLDER_NUMBER_A : PROP_FOLDER_NUMBER_B;
prop_request_change_wait(folder_number_prop, &folder_num_requested, 4, 1000);
folder_num_dirty = 1;
}
if (file_num != file_num_canon_latest)
{
file_num_requested = file_num;
printf("Changing file number from %d to %d...\n", file_num_canon_latest, file_num_requested);
int file_number_prop = shooting_drive_letter == 'A' ? PROP_FILE_NUMBER_A : PROP_FILE_NUMBER_B;
prop_request_change_wait(PROP_NUMBER_OF_CONTINUOUS_MODE, &file_num_requested, 4, 1000);
prop_request_change_wait(file_number_prop, &file_num_requested, 4, 1000);
file_num_dirty = 1;
}
/* re-read the (possibly updated) file and folder number from Canon */
file_num = get_shooting_card()->file_number;
folder_num = get_shooting_card()->folder_number;
}
static MENU_UPDATE_FUNC(file_number_upd)
{
file_folder_number_refresh();
MENU_SET_VALUE("%04d", file_num);
if (file_num_dirty)
{
MENU_SET_RINFO("Restart");
MENU_SET_WARNING(MENU_WARN_INFO, "Please restart your camera to apply the changes.");
}
else
{
MENU_SET_ENABLED(0);
}
}
static const char * next_image_filename(int newline)
{
static char buf[32];
/* also print extension(s) based on picture quality setting */
int raw = pic_quality & 0x60000;
int jpg = pic_quality & 0x10000;
snprintf(buf, sizeof(buf),
"%03d%s/%s%s%04d.%s%s%s",
get_shooting_card()->folder_number + (get_shooting_card()->file_number == 9999 ? 1 : 0),
get_dcim_dir_suffix(),
newline ? "\n" : "",
get_file_prefix(),
get_shooting_card()->file_number < 9999 ? get_shooting_card()->file_number + 1 : 1,
raw ? "CR2" : "",
raw && jpg ? "/" : "",
jpg ? "JPG" : ""
);
return buf;
}
static MENU_UPDATE_FUNC(folder_number_upd)
{
file_folder_number_refresh();
/* fixme: hackish */
bmp_printf(FONT(FONT_LARGE, COLOR_GRAY(50), 0), 50, 350, "Next image: %s", next_image_filename(0));
if (folder_num_dirty)
{
MENU_SET_RINFO("Take pic");
MENU_SET_WARNING(MENU_WARN_INFO, "Please take a picture to apply the changes.");
}
else
{
MENU_SET_ENABLED(0);
}
}
/* main entry */
static MENU_UPDATE_FUNC(file_name_upd)
{
file_folder_number_refresh();
MENU_SET_RINFO(next_image_filename(1));
if (file_num_dirty)
{
MENU_SET_RINFO("Restart");
MENU_SET_WARNING(MENU_WARN_INFO, "Please restart your camera to apply the changes.");
}
else if (folder_num_dirty)
{
MENU_SET_RINFO("Take pic");
MENU_SET_WARNING(MENU_WARN_INFO, "Please take a picture to apply the changes.");
}
/* fixme: you can't change both at the same time */
}
static struct menu_entry img_name_menu[] =
{
{
.name = "Image file naming",
.select = menu_open_submenu,
.update = file_name_upd,
.help = "Customize image file naming for still pictures. Experimental.",
.help2 = "Examples: IMG_1234.JPG -> ABCD1234.JPG, IMG_1234.JPG -> IMG_0001.JPG.",
.submenu_width = 720,
.children = (struct menu_entry[]) {
{
.name = "Image file prefix",
.select = file_prefix_enter,
.update = file_prefix_upd,
.icon_type = IT_ACTION,
.help = "Custom image file prefix (e.g. IMG_1234.JPG -> ABCD1234.JPG).",
.help2 = "Might conflict with Dual ISO prefixes (to be tested).",
},
{
.name = "Image file number",
.priv = &file_num,
.min = 0, /* we can set to 0 and the next image will be IMG_0001 */
.max = 9999, /* setting it to 9999 => next image will be IMG_0001, too */
.unit = UNIT_DEC,
.icon_type = IT_DICE,
.update = file_number_upd,
.help = "Custom image file number (e.g. IMG_1234.JPG -> IMG_5678.JPG).",
.help2 = "You will need to restart the camera for the changes to take effect.",
},
{
.name = "Image folder number",
.priv = &folder_num,
.update = folder_number_upd,
.min = 100,
.max = 999,
.unit = UNIT_DEC,
.icon_type = IT_DICE,
.help = "Custom image folder num. You must take a picture to apply this setting.",
.help2 = "DCIM/100CANON/IMG_1234.JPG -> DCIM/123CANON/IMG_1234.JPG",
},
MENU_EOL,
},
},
};
static unsigned int img_name_init()
{
/* get default prefix at startup */
/* fixme: what if user changes it from Canon menu? */
snprintf(default_prefix, sizeof(default_prefix), "%s", get_file_prefix());
/* set image prefix from config file, if any saved */
if (prefix_enc)
{
/* note: CONFIG_INT's are of type int, which is int32_t on our target */
/* fixme: compile time assert to check sizeof(int) */
*(int*)prefix = prefix_enc; prefix[4] = 0;
key = file_prefix_set(prefix);
}
/* setup menus */
menu_add("Shoot", img_name_menu, COUNT(img_name_menu));
return 0;
}
static unsigned int img_name_deinit()
{
return 0;
}
MODULE_INFO_START()
MODULE_INIT(img_name_init)
MODULE_DEINIT(img_name_deinit)
MODULE_INFO_END()
MODULE_CONFIGS_START()
MODULE_CONFIG(prefix_enc)
MODULE_CONFIGS_END()
......@@ -390,4 +390,5 @@ REGISTER_PROP_HANDLER(PROP_WB_MODE_PH, NULL);
REGISTER_PROP_HANDLER(PROP_WB_KELVIN_PH, NULL);
REGISTER_PROP_HANDLER(PROP_ICU_AUTO_POWEROFF, NULL);
REGISTER_PROP_HANDLER(PROP_REBOOT, NULL);
REGISTER_PROP_HANDLER(PROP_NUMBER_OF_CONTINUOUS_MODE, NULL);
REGISTER_PROP_HANDLER(PROP_LV_AF_RESULT, NULL);
......@@ -431,6 +431,9 @@
#define PROP_CLUSTER_SIZE_C 0x02010008
#define PROP_FREE_SPACE_C 0x0201000b
#define PROP_CARD_RECORD_C 0x8003000d
#define PROP_FILE_NUMBERING_MODE 0x02040001
#define PROP_NUMBER_OF_CONTINUOUS_MODE 0x02040008
#endif
#define PROP_USER_FILE_PREFIX 0x02050004
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment