Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 253 lines (225 sloc) 9.511 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
using GLib;

[DBus (name = "com.ridgerun.dm365ipipeInterface")]
public interface Idm365ipipe: Object{
    public abstract bool set_previewer_mode(string mode_s) throws IOError;
    public abstract bool set_color_pattern(string colorptn) throws IOError;
    public abstract bool set_digital_gain(double red_gain, double green_gain,
        double blue_gain) throws IOError;
    public abstract bool get_digital_gain(out double _red_gain,
        out double blue_gain, out double green_gain) throws IOError;
    public abstract bool set_luminance_adj(int bright, double contr) throws IOError;
    public abstract bool get_luminance_adj(out int bright, out double contr) throws IOError;
    public abstract bool config_bsc(uint inwidth, uint inheight) throws IOError;
}

public class cli_dm365ipipe : AbstcCliRegister{
    static bool _debug = false;
    public Idm365ipipe ipipe;
    public cli_dm365ipipe(bool debug) throws IOError{
        _debug = debug;
    }

    private int cmd_set_previewer_mode(string[]? args) {
        if (args[1] == null) {
            stdout.printf("Error:\nMissing argument.Execute:'help <command>'\n");
            return -1;
        }

        try {
            if (!ipipe.set_previewer_mode(args[1])) {
                stderr.printf("Error:\n Failed to configure previewer\n");
                return -1;
            } else {
                if (_debug){
                    stdout.printf("Ipipe Previewer has been configured\n");
                    stdout.printf("Ok.\n");
                }
                return 0;
            }

        }
        catch(Error e) {
            stderr.printf("Fail to execute command:%s\n", e.message);
            return -1;
        }

    }

    private int cmd_set_digital_gain(string[]? args) {

        if (args[1] == null || args[2] == null || args[3] == null) {
            stdout.printf("Error:\nMissing argument.Execute:'help <command>'\n");
            return -1;
        }

        double red = double.parse(args[1]);
        double green = double.parse(args[2]);
        double blue = double.parse(args[3]);

        try {
            if (!ipipe.set_digital_gain(red, green, blue)) {
                stderr.printf("Error:\n Failed to set the digital gain\n");
                return -1;
            } else {
                if (_debug)
                    stdout.printf("Ok.Set digital gain\n");
                return 0;
            }
        }
        catch(Error e) {
            stderr.printf("Fail to execute command:%s\n", e.message);
            return -1;
        }

    }

    private int cmd_get_digital_gain(string[]? args) {
        try {
            double red_gain = 0, green_gain = 0, blue_gain = 0;

            if (!ipipe.get_digital_gain(out red_gain,
                    out green_gain, out blue_gain)) {
                stderr.printf("Error:\n Failed to get the digital gain\n");
                return -1;
            } else {
                Posix.stdout.printf("Digital gain: R=%f G=%f B=%f\n",
                    red_gain,green_gain,blue_gain);
                if (_debug)
                    stdout.printf("Ok.Get digital gain\n");
                return 0;
            }
        }
        catch(Error e) {
            stderr.printf("Fail to execute command:%s\n", e.message);
            return -1;
        }

    }

    private int cmd_set_lum_adj(string[]? args) {

        if (args[1] == null || args[2] == null) {
            stdout.printf("Error:\nMissing argument.Execute:'help <command>'\n");
            return -1;
        }

        int brightness = int.parse(args[1]);
        double contrast = double.parse(args[2]);

        try {
            if (!ipipe.set_luminance_adj(brightness, contrast)) {
                stderr.
                    printf("Error:\n Failed to set the luminant adjusment\n");
                return -1;
            } else {
                if (_debug)
                    stdout.printf("Ok.Set luminance adjusment\n");
                return 0;
            }
        }
        catch(Error e) {
            stderr.printf("Fail to execute command:%s\n", e.message);
            return -1;
        }
    }

    private int cmd_get_lum_adj(string[]? args) {
       int brightness;
       double contrast;

       try {
            if (!ipipe.get_luminance_adj(out brightness, out contrast)) {
                stderr.
                    printf("Error:\n Failed to get the luminant adjusment\n");
                return -1;
            } else {
                Posix.stdout.printf("Luminance adjustment: Brightness=%d," +
                   " Contrast=%f\n", brightness, contrast);
                if (_debug)
                    stdout.printf("Ok.Get luminance adjusment\n");
                return 0;
            }
        }
        catch(Error e) {
            stderr.printf("Fail to execute command:%s\n", e.message);
            return -1;
        }
    }

    private int cmd_set_color_pattern(string[]? args){
         if (args[1] == null) {
            stdout.printf("Error:\nMissing argument.Execute:'help <command>'\n");
            return -1;
        }
        try {
            if (!ipipe.set_color_pattern(args[1])) {
                stderr.printf("Error:\n Failed to set color_pattern\n");
                return -1;
            } else {
                if (_debug)
                    stdout.printf("Ok.Set bayer pattern\n");
                return 0;
            }
        }
        catch(Error e) {
            stderr.printf("Fail to execute command:%s\n", e.message);
            return -1;
        }
    }

    private int cmd_config_video_stabilization(string[]? args) {
#if BSC_ENABLE
        if (args[1] == null || args[2] == null) {
            stdout.printf("Error:\nMissing argument.Execute:'help config_video_stabilization'\n");
            return -1;
        }
        uint width = int.parse(args[1]);
        uint height = int.parse(args[2]);

        try {
            if (!ipipe.config_bsc(width, height)) {
                stderr.
                    printf("Error:\n Failed to config bsc\n");
                return -1;
            } else {
                if (_debug)
                    stdout.printf("Ok.Set bsc configuration\n");
                return 0;
            }
        }
        catch(Error e) {
            stderr.printf("Fail to execute command:%s\n", e.message);
            return -1;
        }
#else
        stdout.printf("Video stabilization not supported\n");
        return 0;
#endif
    }

    /* Initialize the Command Array. */
    public override void registration(IpipeCli cli) throws IOError{
        cli.cmd.new_command("set-previewer-mode", cmd_set_previewer_mode,
            "\033[1mset_previewer_mode\033[m <cont/one-shot>",
            "Configure previewer on continuous or one-shot mode", "",
            "\n\tcont: sets previewer on continous mode"
            + "\n\tone-shot: sets previewer on one shot mode");
        cli.cmd.new_command("set-bayer-pattern", cmd_set_color_pattern,
            "\033[1mset-bayer-pattern\033[m ptrn","Sets R/Gr/Gb/B color pattern "
            + "to the previewer", "", "\n\tThe argument ptrn is the specific "
            + "color pattern, \n\tthe options are: "
            + "\n\tGrRBGb: \n\t\tGr R\n\t\tB Gb\n\tBGbGrR: \n\t\tB Gb\n\t\tGr R"
            + "\n\tRGrGbB: \n\t\tR Gr\n\t\tGb B\n\tGbBRGr: \n\t\tGb B\n\t\tR Gr");
        cli.cmd.new_command("set-digital-gain", cmd_set_digital_gain,
            "\033[1mset-digital-gain\033[m R G B", "Sets red (R), green (G)"
            + " and blue gains (G) on the ipipe",
            "\tEach gain component can range from 0 to 15.998 in steps of 1/512:",
            "\n\tR: red gain\n\tG: green gain\n\tB: blue gain\n");
        cli.cmd.new_command("get-digital-gain", cmd_get_digital_gain,
            "\033[1mget-digital-gain\033[m",
            "Returns the gain value for each color component(RGB)", "", "");
        cli.cmd.new_command("set-luminance", cmd_set_lum_adj,
            "\033[1mset-luminance\033[m Br C",
            "Brightness(Br) and contrast(C) adjustment", "\tThis ajustment "
            +"is applied to the luminance(Y) component, using the following "
            +"equation Yctr_ brt = (Y x C) + Br ",
            "\n\tBr: brightness offset value for ipipe's brightness control,"
            +" it's an integer value that can range from 0 to 255"
            +"\n\tC: contrast multiplier coefficient, it's a float value"
            +" that can range from 0 to 15.94");
        cli.cmd.new_command("get-luminance", cmd_get_lum_adj,
            "\033[1mget-luminance\033[m",
            "Returns the value of the Brightness(Br) and contrast(C) adjustment",
            "", "");
        cli.cmd.new_command("config-vs", cmd_config_video_stabilization,
            "\033[1mconfig-vs\033[m width height",
            "Configures the boundary signal calculator module(bsc)"
            +" needed by the video stabilization",
            "\tThe video stabilization algorithm uses the vectors of sums"
            +"\n\tgiven by the bsc to calculate the compensation for"
            +"\n\tthe camera shaking."
            +"\n\tThe bsc is configured for an image of the given dimensions.",
            "\n\twidth: input image's width"
            +"\n\theight: input image's height");

        ipipe = Bus.get_proxy_sync (BusType.SYSTEM, "com.ridgerun.ipiped",
                                                        "/com/ridgerun/ipiped/ipipe");
        return;
    }
}


Something went wrong with that request. Please try again.