Esempio n. 1
0
static int open(struct widget *w)
{
    struct widget_priv *priv;

    priv = (struct widget_priv*) widget_malloc(sizeof(struct widget_priv));
    if (priv == NULL)
        return -1;
    w->priv = priv;

    priv->home = get_home_data();
    priv->stats = get_flight_stats();

    if (w->cfg->props.mode & 1) {
        w->ca.width = 84*2;
        w->ca.height = 84*2;
    } else {
        w->ca.width = 84;
        w->ca.height = 84;
    }

    add_mavlink_callback(MAVLINK_MSG_ID_VFR_HUD, mav_callback, CALLBACK_WIDGET, w);
    add_mavlink_callback(MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT, mav_callback_nav, CALLBACK_WIDGET, w);
    add_mavlink_callback(MAVLINK_MSG_ID_MISSION_CURRENT, mav_callback_wp_seq, CALLBACK_WIDGET, w);

    /* refresh rate of 0.2 sec */
    add_timer(TIMER_WIDGET, 2, timer_callback, w);
    return 0;
}
Esempio n. 2
0
static int open(struct widget *w)
{
    w->priv = (struct flight_stats*) get_flight_stats();

    w->ca.width = 4*60;
    w->ca.height = 12*8;

    /* refresh rate of 0.2 sec */
    add_timer(TIMER_WIDGET, 2, timer_callback, w);
    return 0;
}
Esempio n. 3
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    struct home_data *home = get_home_data();
    struct flight_stats *fstats = get_flight_stats();

    mavlink_attitude_t *att = mavdata_get(MAVLINK_MSG_ID_ATTITUDE);
    mavlink_vfr_hud_t *hud = mavdata_get(MAVLINK_MSG_ID_VFR_HUD);
    unsigned long d = (unsigned long) home->distance;
    unsigned int r = (w->ca.width/2)-2;
    u8 i;
    
    struct point ils_screen[5];
    struct point ils_points[5] = { {-35, -100}, {-35, 100}, {0, 130}, {35, 100}, {35, -100} };
    struct polygon ils = {
        .len = 5,
        .points = ils_points,
    };

    
    
    float x,y,z;
    
    eye.x = 0; //X_SIZE/2;
    eye.y = 0; //Y_SIZE/2;
    eye.z = 10;

    x = sin(DEG2RAD(home->direction)) * d;
    z = cos(DEG2RAD(home->direction)) * d;
    y = home->altitude;
    
    ls.x = (s32) x;
    ls.y = (s32) y;
    ls.z = (s32) z;
    
    if (ls.z <= 0)
        return;
    
    //ls.x = XX;
    //ls.y = YY;
    //ls.z = ZZ;
    
    eye.z = ZZ;
    
    p.x = (eye.z * (ls.x-eye.x)) / (eye.z + ls.z) + eye.x;
    p.y = (eye.z * (ls.y-eye.y)) / (eye.z + ls.z) + eye.y;
    
    draw_circle(X_SIZE/2 + p.x, Y_SIZE/2 + p.y, 5, 1, ca);

    
    transform_polygon(&ils, x, z,  - (fstats->launch_heading - hud->heading));
    for (i = 0; i < 5; i++) {
        ils_screen[i].x = (eye.z * (ils_points[i].x-eye.x)) / (eye.z + ils_points[i].y) + eye.x;
        ils_screen[i].y = (eye.z * (ls.y-eye.y)) / (eye.z + ils_points[i].y) + eye.y;
    }
    ils.points = ils_screen;
    transform_polygon(&ils, X_SIZE/2, Y_SIZE/2, 0);
    draw_polygon(&ils, 1, ca);

    
}

const struct widget_ops ils_widget_ops = {
    .name = "Imaginary LS",
    .mavname = "ILS",
    .id = WIDGET_ILS_ID,
    .init = NULL,
    .open = open,
    .render = render,
    .close = NULL,
};