problem compiling my first module

Started by alext, August 02, 2017, 03:54:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

alext

This is my first try on writing modules and I wrote a few lines and wanted to try it out and see if it works like intended. I took the makefile from the ettr module and changed the names for the output but if I run make, no *.o file is produced. compiling the other modules works fine but not with my *.c file. I looked through other *.c and makefiles but could not solve it.

I work with the lua_fix branch and took a lot of code from the sourcefiles or other modules (especially lua module, I tried some of this with a lua sript). I'm not very experienced with programming in C so feel free to comment  ;)

my makefile:

# this is a very simple makefile for modules
TOP_DIR=../..

# define the module name - make sure name is max 8 characters
MODULE_NAME=ortho
MODULE_OBJS=ortho.o

# include modules environment
include $(TOP_DIR)/modules/Makefile.modules


and my .c file:


#include "module.h"
#include "focus.h"
#include "dryos.h"
#include "bmp.h"
#include "menu.h"
#include "property.h"
#include "config.h"
#include "af_patterns.h"
#include "lens.h"
#include "lvinfo.h"
#include "shoot.h"
extern void bmp_on;
extern void bmp_off;
static int afp[2];
static int afp_len = 0;
static int x=720;
static int y=480;
PROP_HANDLER(PROP_AFPOINT)
{
    afp[0] = buf[0];
    afp[1] = buf[1];
    afp_len = len;
}

static int autofocus()
{
msleep(500);
module_send_keypress(MODULE_KEY_PRESS_HALFSHUTTER);
if (wait_focus_status(3000, 3, 3))
    {
        if (wait_focus_status(5000, 1, 2))
        {
            module_send_keypress(MODULE_KEY_UNPRESS_HALFSHUTTER);
            lens_focus(1,1,1,0);
            lens_focus(1,-1,1,0);
            msleep(500);
            return 1;
        }
}
    else
    {
module_send_keypress(MODULE_KEY_UNPRESS_HALFSHUTTER);
        return 0;
    }

}

static void orthogonator()
{
msleep(2000);
force_liveview();
bmp_off();
bmp_on();
if (!afp_len || !lens_info.name) return;
lens_setup_af(AF_ENABLE);
afp[0] = AF_POINT_C;
prop_request_change(PROP_AFPOINT, afp, afp_len);
if(autofocus()) bmp_printf(FONT_MED,x/2,y/2,"%d",lens_info.focus_pos);
afp[0] = AF_POINT_T;
prop_request_change(PROP_AFPOINT, afp, afp_len);
if(autofocus()) bmp_printf(FONT_MED,x/2,y/4,"%d",lens_info.focus_pos);
afp[0] = AF_POINT_R;
prop_request_change(PROP_AFPOINT, afp, afp_len);
if(autofocus()) bmp_printf(FONT_MED,3*x/4,y/2,"%d",lens_info.focus_pos);
afp[0] = AF_POINT_B;
prop_request_change(PROP_AFPOINT, afp, afp_len);
if(autofocus()) bmp_printf(FONT_MED,x/2,y*3/4,"%d",lens_info.focus_pos);
afp[0] = AF_POINT_L;
prop_request_change(PROP_AFPOINT, afp, afp_len);
if(autofocus()) bmp_printf(FONT_MED,x/4,y/2,"%d",lens_info.focus_pos);
}

static struct menu_entry ortho_menu[] =
{
    {
        .name       = "Orthogonator",
        .select     = run_in_separate_task,
        .priv       = orthogonator,
        .help       = "",
    },
};

static unsigned int ortho_init()
{
    menu_add("Focus", ortho_menu, COUNT(ortho_menu));
    return 0;
}

static unsigned int ortho_deinit()
{
    return 0;
}

MODULE_INFO_START()
    MODULE_INIT(ortho_init)
    MODULE_DEINIT(ortho_deinit)
MODULE_INFO_END()

MODULE_PROPHANDLERS_START()
    MODULE_PROPHANDLER(PROP_AFPOINT)
MODULE_PROPHANDLERS_END()

a1ex

The size_t error goes away if you keep dryos.h and module.h at the top, as in the tutorial.

To find what header you need for some particular function, you could do something like:


grep -nr bmp_on src/*.h


If you really want to declare something twice, you should declare it in the same way in both places. This trick is useful if you want to use a function that's not available on all models (WEAK_FUNC), but it's not the case here, so you should delete the "extern void bmp_on" and just use the definition from bmp.h (which you have already included).

Are you trying to do some sort of AFMA calibration on all the focus points?

PROP_AFPOINT will change the active AF point used with phase detection. If you want to cross-check it with contrast-detect AF, try move_lv_afframe and get_afframe_pos. You'll probably also want to change PROP_LVAF_MODE to switch between the two methods.

alext

I put dryos.h and module.h at the top and checked if I got every header needed but I get the same error as before: no *.o file. What does the *.o file contain and how is it created? probably I can dig into it and find my mistake if I know what to look for.

The idea behind this module is to focus on different points an a plane (e.g. painting, poster...) and to turn and tilt the camera with the information of the focus position until the optical axis is (nearly) orthogonal to the plane. This is a project I'm doing for university and the fist step is to test under which conditions it is possible to record small changes of the angle. If I manage to get this module running, those tests would be a lot easier than with the lua script I allready wrote.

@a1ex
I have to admit that I did not think about the different focus modes in LV, thanks for reminding me. I think I'll use the contrast detection in a different stage of this project  ;)
Thanks for always helping with my questions and my full respect for all the work you put in magic lantern and this community

a1ex

Quote from: alext on August 03, 2017, 05:30:49 PM
the fist step is to test under which conditions it is possible to record small changes of the angle

Be sure to check http://www.magiclantern.fm/forum/index.php?topic=4997 . The focus distance is reported in very coarse increments, but there is also a counter that appears to be the motor encoder. That counter is fine enough to detect small changes, but unfortunately it appears to be reset during autofocus. You can find some ways to work around it (worst case, a custom AF algorithm that doesn't reset that counter).

Quote from: alext on August 03, 2017, 05:30:49 PM
The idea behind this module is to focus on different points an a plane (e.g. painting, poster...) and to turn and tilt the camera with the information of the focus position until the optical axis is (nearly) orthogonal to the plane.

If the subject is rectangular, you may want to consider identifying the edges and/or corners; that would be a lot faster, and likely more sensitive to small changes in orientation.

Quote from: alext on August 03, 2017, 05:30:49 PM
What does the *.o file contain and how is it created?

http://www.thegeekstuff.com/2011/10/c-program-to-an-executable/
http://faculty.cs.niu.edu/~mcmahon/CS241/Notes/compile.html
https://www.calleerlandsson.com/the-four-stages-of-compiling-a-c-program/

Here, the executable is autoexec.bin (raw machine code), and the modules (*.mo) are actually .o files (elf format) with some additional metadata; the linking stage for modules is done in the camera, using TCC as elf loader and linker.