Example #1
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    char buf[100], buf2[5];

    sprintf(buf, "%10.6f\n%10.6f", (double) priv->gps_lat, (double) priv->gps_lon);
    draw_str(buf, 0, 0, ca, priv->font_id);

    if (priv->gps_fix_type < 2) {
        buf2[0] = '\0';
    } else if (priv->gps_fix_type < 4) {
        sprintf(buf2, "%dD", priv->gps_fix_type);
    } else if (priv->gps_fix_type < 5) {
        strcpy(buf2, "DGPS");
    } else if (priv->gps_fix_type < 6) {
        strcpy(buf2, "RTK");
    } else {
        strcpy(buf2, "?");
    }

    sprintf(buf, "%d %s\n%2.1f HDP",
                priv->gps_nrsats, buf2,
                (double) priv->gps_eph);
    draw_jstr(buf, ca->width, 0, JUST_RIGHT, ca, priv->font_id);
}
Example #2
0
static void render_gauge(struct widget *w, int speed_i)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    int i, j, y = -1;
    long yy;
    char buf[10], d = 0;
    int major_tick = priv->range / 5;
    int minor_tick = major_tick / 4;

    for (i = 0; i < priv->range; i++) {
        yy = ((long) i * Y_SIZE) / priv->range;
        if ((yy == y) && (d == 1))
            continue;
        y = Y_SIZE - (int) yy;
        j = speed_i + i - priv->range/2;
        if(j < 0)
            continue;
        if (j % major_tick == 0) {
            sprintf(buf, "%d", j);
            draw_jstr(buf, 2, y, JUST_VCENTER, ca, 0);
            draw_oline(X_CENTER - 2, y, X_CENTER + 4, y, 1, ca);
            d = 1;
        } else if (j % minor_tick == 0) {
            draw_oline(X_CENTER - 2, y, X_CENTER + 2, y, 1, ca);
            d = 1;
        } else {
            d = 0;
        }
    }

    draw_frect(1, Y_CENTER-5, X_CENTER - 10, Y_CENTER + 5, 0, ca);
    sprintf(buf, "%d", (int) speed_i);
    draw_jstr(buf, 2, Y_CENTER, JUST_VCENTER, ca, 0);

    draw_hline(0, X_CENTER - 10, Y_CENTER - 6, 1, ca);
    draw_hline(0, X_CENTER - 10, Y_CENTER + 6, 1, ca);
    draw_vline(0, Y_CENTER - 5 , Y_CENTER + 5, 1, ca);

    draw_line(X_CENTER-10, Y_CENTER-6, X_CENTER-10+5, Y_CENTER, 1, ca);
    draw_line(X_CENTER-10, Y_CENTER+6, X_CENTER-10+5, Y_CENTER, 1, ca);
}
Example #3
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    int i, j, y = -1;
    long yy;
    char buf[10], d = 0;
    int major_tick = priv->range / 5;
    int minor_tick = major_tick / 4;

    for (i = 0; i < priv->range; i++) {
        yy = ((long) i * Y_SIZE) / priv->range;
        if ((yy == y) && (d == 1))
            continue;
        y = Y_SIZE - (int) yy;
        j = priv->altitude + i - priv->range/2;
        if (j % major_tick == 0) {
            draw_ohline(X_CENTER + 2, X_CENTER - 4, y, 1, 3, ca);
            sprintf(buf, "%d", j);
            draw_jstr(buf, X_SIZE-2, y, JUST_RIGHT | JUST_VCENTER, ca, 0);
            d = 1;
        } else if (j % minor_tick == 0) {
            draw_ohline(X_CENTER + 2, X_CENTER - 2, y, 1, 3, ca);
            d = 1;
        } else {
            d = 0;
        }
    }

    draw_frect(X_CENTER + 11, Y_CENTER-5, X_SIZE-2, Y_CENTER + 5, 0, ca);

    draw_hline(X_CENTER + 10, X_SIZE - 1, Y_CENTER-6, 1, ca);
    draw_hline(X_CENTER + 10, X_SIZE - 1, Y_CENTER+6, 1, ca);
    draw_vline(X_SIZE - 1, Y_CENTER-5, Y_CENTER+5, 1, ca);

    /* draw arrow */
    draw_line(X_CENTER+10, Y_CENTER-6, X_CENTER+10-5, Y_CENTER, 1, ca);
    draw_line(X_CENTER+10, Y_CENTER+6, X_CENTER+10-5, Y_CENTER, 1, ca);

    sprintf(buf, "%d", (unsigned int) priv->altitude);
    draw_jstr(buf, X_SIZE-2, Y_CENTER, JUST_RIGHT | JUST_VCENTER, ca, 0);
}
Example #4
0
static void render(struct widget *w)
{
    struct canvas *ca = &w->ca;
    char buf[10];
    mavlink_scaled_pressure_t *sp = mavdata_get(MAVLINK_MSG_ID_SCALED_PRESSURE);
    float temperature = sp->temperature / 100.0;
    char unit_char = 'C';

    if (get_units(w->cfg) == UNITS_IMPERIAL) {
        temperature = temperature * 1.8 + 32;
        unit_char = 'F';
    }
    
    sprintf(buf, "%.2f%c", (double) temperature, unit_char);
    draw_jstr(buf, X_SIZE, Y_SIZE/2, JUST_RIGHT | JUST_VCENTER, ca, 2);
}
Example #5
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    char buf[10], text[5];
    int speed_i;

    switch (get_units(w->cfg)) {
        case UNITS_METRIC:
        default:
            speed_i = (int) ((priv->speed * 3600) / 1000);
            strcpy(text, "km/h");
            break;
        case UNITS_IMPERIAL:
            speed_i = (int) ((priv->speed * 3600) * M2MILE);
            strcpy(text, "mph");
            break;
        case UNITS_CUSTOM_1:
            speed_i = (int) (priv->speed);
            strcpy(text, "m/s");
            break;
        case UNITS_CUSTOM_2:
            speed_i = (int) (priv->speed * M2FEET);
            strcpy(text, "f/s");
            break;
        case UNITS_CUSTOM_3:
            speed_i = (int) ((priv->speed * 3600 * 1.852) / 1000);
            strcpy(text, "kn");
            break;
    }
    
    switch (w->cfg->props.mode) {
        case 0:
        default:
            render_gauge(w, speed_i);
            break;
        case 1:
            snprintf(buf, 10, "%d%s", speed_i, text);
            draw_jstr(buf, X_SIZE_TEXT - 1, 10, JUST_RIGHT | JUST_VCENTER, ca, 1);
            break;
    }
}
Example #6
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    int y, i, j;
    int x0, x1, y0, y1, offset, cx, cy;
    unsigned char size, gap;
    char buf[10];

    for (i = -RANGE/2; i <= RANGE/2; i++) {
        y = Y_CENTER - i;
        //j = priv->pitch_deg*SCALE + i;
        j = priv->pitch_deg + i;

        if (j % (MINOR_TICK*SCALE) == 0) {
            if (j == 0) {
                size = 40;
                gap = 10;
            } else {
                if (j % (MAJOR_TICK*SCALE) == 0)
                    size = 20;
                else
                    size = 10;
                gap = 10;
            }

            cx = X_CENTER + (int) (i * priv->sin_roll);
            cy = y + i - (int) (i * priv->cos_roll);

            if ((j != 0) && (j % (MAJOR_TICK*SCALE) == 0)) {
                sprintf(buf, "%d", j / SCALE);
                draw_jstr(buf, cx, cy, JUST_HCENTER | JUST_VCENTER, ca, 0);
            }
            
            offset = (int) gap * priv->cos_roll;
            x0 = cx + offset;
            offset = (int) size * priv->cos_roll;
            x1 = x0 + offset;

            
            offset = (int) gap * priv->sin_roll;
            y0 = cy + offset;
            offset = (int) size * priv->sin_roll;
            y1 = y0 + offset;
            
            if (j == 0) {
                draw_line(x0-1, y0-1, x1+1, y1-1, 3, ca);
                //draw_line(x0, y0-1, x1, y1-1, 1, ca);
            }
            draw_line(x0-1, y0+1, x1+1, y1+1, 3, ca);
            draw_line(x0, y0, x1, y1, 1, ca);

            offset = (int) gap * priv->cos_roll;
            x0 = cx - offset;
            offset = (int) size * priv->cos_roll;
            x1 = x0 - offset;


            offset = (int) gap * priv->sin_roll;
            y0 = cy - offset;
            offset = (int) size * priv->sin_roll;
            y1 = y0 - offset;

            if (j == 0) {
                draw_line(x0-1, y0-1, x1+1, y1-1, 3, ca);
                //draw_line(x0, y0-1, x1, y1-1, 1, ca);
            }
            draw_line(x0-1, y0+1, x1+1, y1+1, 3, ca);
            draw_line(x0, y0, x1, y1, 1, ca);

        }
    }


    draw_ohline(X_CENTER - 3, X_CENTER + 3, Y_CENTER, 1, 3, ca);
    draw_vline(X_CENTER, Y_CENTER - 3, Y_CENTER + 3, 1, ca);

    
    float cos_i, sin_i;

    for (i = -ROLL_RANGE/2; i <= ROLL_RANGE/2; i++) {
        y = Y_CENTER - i;
        //j = priv->pitch_deg*SCALE + i;
        //j = priv->roll_deg + i;

        if (i % (MINOR_ROLL_TICK) == 0) {
            gap = 70;
            if (i == 0) {
                size = 10;
            } else {
                if (i % (MAJOR_ROLL_TICK) == 0)
                    size = 10;
                else
                    size = 5;
            }

            cos_i = cos(DEG2RAD(i));
            sin_i = sin(DEG2RAD(i));
            
            cx = X_CENTER;// + (int) (gap * cos_i);
            cy = Y_CENTER;// - (int) (gap * sin_i);


            offset = (int) gap * cos_i;
            x0 = cx + offset;
            offset = (int) size * cos_i;
            x1 = x0 + offset;


            offset = (int) gap * sin_i;
            y0 = cy - offset;
            offset = (int) size * sin_i;
            y1 = y0 - offset;

            draw_line(x0, y0, x1, y1, 1, ca);

            if ((i != 0) && (i % (MAJOR_ROLL_TICK) == 0)) {
                sprintf(buf, "%d", i);
                draw_jstr(buf, x1, y1, JUST_VCENTER, ca, 0);
            }
        }
    }

    cx = X_CENTER; // + (int) (gap * priv->sin_roll);
    cy = Y_CENTER ; //- (int) (gap * priv->cos_roll);
    size = 10;

    offset = (int) (gap-size) * priv->cos_roll;
    x0 = cx + offset;
    offset = (int) size * priv->cos_roll;
    x1 = x0 + offset;


    offset = (int) (gap-size) * priv->sin_roll;
    y0 = cy + offset;
    offset = (int) size * priv->sin_roll;
    y1 = y0 + offset;


    draw_line(x0-1, y0-1, x1+1, y1-1, 3, ca);
    draw_line(x0-1, y0+1, x1+1, y1+1, 3, ca);
    draw_line(x0, y0, x1, y1, 1, ca);
}