static void my_max(RESULT * result, RESULT * arg1, RESULT * arg2) { double a1 = R2N(arg1); double a2 = R2N(arg2); double value = a1 > a2 ? a1 : a2; SetResult(&result, R_NUMBER, &value); }
static void my_diff(RESULT * result, RESULT * arg1, RESULT * arg2) { /* do it all in one line */ double value = R2N(arg1) - R2N(arg2); /* some more calculations... */ if (value < 0) value = -value; /* store result */ SetResult(&result, R_NUMBER, &value); }
static void plugin_backlight(RESULT * result, RESULT * arg1) { int bl_on; bl_on = (R2N(arg1) == 0 ? 0 : 1); st2205_backlight(h, bl_on); SetResult(&result, R_NUMBER, &bl_on); }
static void my_proc_stat(RESULT * result, const int argc, RESULT * argv[]) { char *string; double number; if (parse_proc_stat() < 0) { SetResult(&result, R_STRING, ""); return; } switch (argc) { case 1: string = hash_get(&Stat, R2S(argv[0]), NULL); if (string == NULL) string = ""; SetResult(&result, R_STRING, string); break; case 2: number = hash_get_delta(&Stat, R2S(argv[0]), NULL, R2N(argv[1])); SetResult(&result, R_NUMBER, &number); break; default: error("proc_stat(): wrong number of parameters"); SetResult(&result, R_STRING, ""); } }
static void plugin_gpi(RESULT * result, RESULT * arg1) { double gpi; gpi = drv_BuE_CT_gpi(R2N(arg1)); SetResult(&result, R_NUMBER, &gpi); }
static void plugin_contrast(RESULT * result, RESULT * arg1) { double contrast; contrast = drv_PICGraphic_contrast(R2N(arg1)); SetResult(&result, R_NUMBER, &contrast); }
static void plugin_backlight(RESULT * result, RESULT * arg1) { double backlight; backlight = drv_TF_backlight(R2N(arg1)); SetResult(&result, R_NUMBER, &backlight); }
double P2N(PROPERTY * prop) { if (prop == NULL) { error("Property: internal error: NULL property"); return 0.0; } return R2N(&prop->result); }
static void my_mul3(RESULT * result, RESULT * arg1) { /* do it all in one line */ double value = R2N(arg1) * 3.0; /* store result */ SetResult(&result, R_NUMBER, &value); }
static void plugin_gpo(RESULT * result, const int argc, RESULT * argv[]) { double gpo; switch (argc) { case 1: gpo = drv_BuE_CT_gpo(R2N(argv[0]), -1); SetResult(&result, R_NUMBER, &gpo); break; case 2: gpo = drv_BuE_CT_gpo(R2N(argv[0]), R2N(argv[1])); SetResult(&result, R_NUMBER, &gpo); break; default: error("%s::gpo(): wrong number of parameters", Name); SetResult(&result, R_STRING, ""); } }
static VALUE find_fracs(VALUE mod, VALUE rv, VALUE dv) { N_TYPE m[2][2], ai, maxden = R2N(rb_Integer(dv)); double startx, x = RFLOAT_VALUE(rb_Float(rv)); int sign = 1; if (maxden <= 0) rb_raise(rb_eArgError, "maximum denominator should be > 0"); if (x < 0) { sign = -1; x = -x; } startx = x; /* initialize matrix */ m[0][0] = m[1][1] = 1; m[0][1] = m[1][0] = 0; /* loop finding terms until denom gets too big */ while (m[1][0] * ( ai = (N_TYPE)x ) + m[1][1] <= maxden) { N_TYPE t; t = m[0][0] * ai + m[0][1]; m[0][1] = m[0][0]; m[0][0] = t; t = m[1][0] * ai + m[1][1]; m[1][1] = m[1][0]; m[1][0] = t; if(x==(double)ai) break; // AF: division by zero x = 1/(x - (double) ai); if(x>(double)0x7FFFFFFF) break; // AF: representation failure } { /* now remaining x is between 0 and 1/ai */ /* approx as either 0 or 1/m where m is max that will fit in maxden */ /* first try zero */ VALUE num1, den1, err1, num2, den2, err2; num1 = N2R(sign*m[0][0]); den1 = N2R(m[1][0]); err1 = rb_float_new(startx - ((double) m[0][0] / (double) m[1][0])); /* now try other possibility */ ai = (maxden - m[1][1]) / m[1][0]; m[0][0] = m[0][0] * ai + m[0][1]; m[1][0] = m[1][0] * ai + m[1][1]; num2 = N2R(sign*m[0][0]); den2 = N2R(m[1][0]); err2 = rb_float_new(startx - ((double) m[0][0] / (double) m[1][0])); return rb_ary_new3(6, num1, den1, err1, num2, den2, err2); } }
static void plugin_backlight(RESULT * result, RESULT * arg1) { int b = R2N(arg1); if (b < 0) b = 0; if (b > 7) b = 7; dpf_ax_setbacklight(dpf.dpfh, b); SetResult(&result, R_NUMBER, &b); }
static void my_cpu(RESULT * result, RESULT * arg1, RESULT * arg2) { char *key; int delay; double value; double cpu_user, cpu_nice, cpu_system, cpu_idle, cpu_total; double cpu_iow, cpu_irq, cpu_sirq; if (parse_proc_stat() < 0) { SetResult(&result, R_STRING, ""); return; } key = R2S(arg1); delay = R2N(arg2); cpu_user = hash_get_delta(&Stat, "cpu.user", NULL, delay); cpu_nice = hash_get_delta(&Stat, "cpu.nice", NULL, delay); cpu_system = hash_get_delta(&Stat, "cpu.system", NULL, delay); cpu_idle = hash_get_delta(&Stat, "cpu.idle", NULL, delay); /* new fields for kernel 2.6 */ /* even if we dont have this param (ie kernel 2.4) */ /* the return is 0.0 and not change the results */ cpu_iow = hash_get_delta(&Stat, "cpu.iow", NULL, delay); cpu_irq = hash_get_delta(&Stat, "cpu.irq", NULL, delay); cpu_sirq = hash_get_delta(&Stat, "cpu.sirq", NULL, delay); cpu_total = cpu_user + cpu_nice + cpu_system + cpu_idle + cpu_iow + cpu_irq + cpu_sirq; if (strcasecmp(key, "user") == 0) value = cpu_user; else if (strcasecmp(key, "nice") == 0) value = cpu_nice; else if (strcasecmp(key, "system") == 0) value = cpu_system; else if (strcasecmp(key, "idle") == 0) value = cpu_idle; else if (strcasecmp(key, "iowait") == 0) value = cpu_iow; else if (strcasecmp(key, "irq") == 0) value = cpu_irq; else if (strcasecmp(key, "softirq") == 0) value = cpu_sirq; else if (strcasecmp(key, "busy") == 0) value = cpu_total - cpu_idle; if (cpu_total > 0.0) value = 100 * value / cpu_total; else value = 0.0; SetResult(&result, R_NUMBER, &value); }
static void drv_generic_gpio_plugin_gpo(RESULT * result, const int argc, RESULT * argv[]) { int num, val; double gpo; switch (argc) { case 1: num = R2N(argv[0]); if (num <= 0 || num > GPOS) { error("%s::GPO(%d): GPO out of range (1..%d)", Driver, num, GPOS); SetResult(&result, R_STRING, ""); return; } gpo = GPO[num - 1]; SetResult(&result, R_NUMBER, &gpo); break; case 2: num = R2N(argv[0]); val = R2N(argv[1]); if (num <= 0 || num > GPOS) { error("%s::GPO(%d): GPO out of range (1..%d)", Driver, num, GPOS); SetResult(&result, R_STRING, ""); return; } if (GPO[num - 1] != val) { if (drv_generic_gpio_real_set) GPO[num - 1] = drv_generic_gpio_real_set(num - 1, val); } gpo = GPO[num - 1]; SetResult(&result, R_NUMBER, &gpo); break; default: error("%s::GPO(): wrong number of parameters", Driver); SetResult(&result, R_STRING, ""); } }
static void drv_generic_gpio_plugin_gpi(RESULT * result, RESULT * arg1) { int num; double val; num = R2N(arg1); if (num <= 0 || num > GPIS) { error("%s::GPI(%d): GPI out of range (1..%d)", Driver, num, GPIS); SetResult(&result, R_STRING, ""); return; } val = drv_generic_gpio_get(num - 1); SetResult(&result, R_NUMBER, &val); }
static void my_mul2(RESULT * result, RESULT * arg1) { double param; double value; /* Get Parameter */ /* R2N stands for 'Result to Number' */ param = R2N(arg1); /* calculate value */ value = param * 2.0; /* store result */ /* when called with R_NUMBER, it assumes the */ /* next parameter to be a pointer to double */ SetResult(&result, R_NUMBER, &value); }
static void plugin_contrast(RESULT * result, const int argc, RESULT * argv[]) { double contrast; switch (argc) { case 0: contrast = drv_BuE_CT_contrast(-1); SetResult(&result, R_NUMBER, &contrast); break; case 1: contrast = drv_BuE_CT_contrast(R2N(argv[0])); SetResult(&result, R_NUMBER, &contrast); break; default: error("%s::contrast(): wrong number of parameters", Name); SetResult(&result, R_STRING, ""); } }
static void plugin_pwm(RESULT * result, const int argc, RESULT * argv[]) { double pwm; switch (argc) { case 0: pwm = drv_BuE_CT_pwm(-1); SetResult(&result, R_NUMBER, &pwm); break; case 1: pwm = drv_BuE_CT_pwm(R2N(argv[0])); SetResult(&result, R_NUMBER, &pwm); break; default: error("%s::pwm(): wrong number of parameters", Name); SetResult(&result, R_STRING, ""); } }
static void formatTimeDDHHMM(RESULT * result, RESULT * param) { long sec; char myTime[16] = " "; sec = R2N(param); if (sec >= 0) { int days = sec / 86400; int hours = (sec % 86400) / 3600; int minutes = (sec % 3600) / 60; sprintf(myTime, "%dd%02dh%02dm", days, hours, minutes); /* 3d 12:33h */ } else strcpy(myTime, "ERROR"); /* store result */ SetResult(&result, R_STRING, myTime); }
static void plugin_backlight(RESULT * result, const int argc, RESULT * argv[]) { double backlight; switch (argc) { case 0: backlight = drv_MO_backlight(-1); SetResult(&result, R_NUMBER, &backlight); break; case 1: backlight = drv_MO_backlight(R2N(argv[0])); SetResult(&result, R_NUMBER, &backlight); break; default: error("%s::backlight(): wrong number of parameters", Name); SetResult(&result, R_STRING, ""); } }
static void formatTimeMMSS(RESULT * result, RESULT * param) { long sec; char myTime[6] = " "; sec = R2N(param); if ((sec >= 0) && (sec < 6000)) { const int minutes = (int) (sec / 60); const int seconds = (int) (sec % 60); sprintf(myTime, "%02d:%02d", minutes, seconds); } else if (sec >= 6000) { strcpy(myTime, "LONG"); } else strcpy(myTime, "ERROR"); /* store result */ SetResult(&result, R_STRING, myTime); }
static void my_decode(RESULT * result, int argc, RESULT * argv[]) { int index; if (argc < 2) { error("decode(): wrong number of parameters"); SetResult(&result, R_STRING, ""); return; } index = R2N(argv[0]); if (index < 0 || index >= argc - 1) { SetResult(&result, R_STRING, ""); return; } CopyResult(&result, argv[index + 1]); }
static void my_disk(RESULT * result, RESULT * arg1, RESULT * arg2, RESULT * arg3) { char *dev, *key, buffer[32]; int delay; double value; if (parse_proc_stat() < 0) { SetResult(&result, R_STRING, ""); return; } dev = R2S(arg1); key = R2S(arg2); delay = R2N(arg3); qprintf(buffer, sizeof(buffer), "disk_io\\.%s\\.%s", dev, key); value = hash_get_regex(&Stat, buffer, NULL, delay); SetResult(&result, R_NUMBER, &value); }
void _sin(RESULT *result, RESULT *arg1) { double val = R2N(arg1); double s = sin(val); SetResult(&result, R_NUMBER, &s); return; }
void _cos(RESULT *result, RESULT *arg1) { double val = R2N(arg1); double c = cos(val); SetResult(&result, R_NUMBER, &c); return; }
int scope_run(SuperScopePrivate *priv, ScopeRunnable runnable) { RESULT result; SetVariableNumeric("n", priv->n); SetVariableNumeric("b", priv->b); SetVariableNumeric("x", priv->x); SetVariableNumeric("y", priv->y); SetVariableNumeric("i", priv->i); SetVariableNumeric("v", priv->v); SetVariableNumeric("w", priv->w); SetVariableNumeric("h", priv->h); SetVariableNumeric("red", priv->red); SetVariableNumeric("green", priv->green); SetVariableNumeric("blue", priv->blue); SetVariableNumeric("linesize", priv->linesize); SetVariableNumeric("skip", priv->skip); SetVariableNumeric("drawmode", priv->drawmode); SetVariableNumeric("t", priv->t); SetVariableNumeric("d", priv->d); switch(runnable) { case SCOPE_RUNNABLE_INIT: Eval(priv->init, &result); break; case SCOPE_RUNNABLE_BEAT: Eval(priv->beat, &result); break; case SCOPE_RUNNABLE_FRAME: Eval(priv->frame, &result); break; case SCOPE_RUNNABLE_POINT: Eval(priv->point, &result); break; } //(FindVariable("n"))->value = NULL; VARIABLE var; var.value = NULL; priv->n = R2N(FindVariable("n")->value); priv->b = R2N(FindVariable("b")->value); priv->x = R2N(FindVariable("x")->value); priv->y = R2N(FindVariable("y")->value); priv->i = R2N(FindVariable("i")->value); priv->v = R2N(FindVariable("v")->value); priv->w = R2N(FindVariable("w")->value); priv->h = R2N(FindVariable("h")->value); priv->red = R2N(FindVariable("red")->value); priv->green = R2N(FindVariable("green")->value); priv->blue = R2N(FindVariable("blue")->value); priv->linesize = R2N(FindVariable("linesize")->value); priv->skip = R2N(FindVariable("skip")->value); priv->drawmode = R2N(FindVariable("drawmode")->value); priv->t = R2N(FindVariable("t")->value); priv->d = R2N(FindVariable("d")->value); return 0; }
static void my_ceil(RESULT * result, RESULT * arg) { double value = ceil(R2N(arg)); SetResult(&result, R_NUMBER, &value); }
static void my_tan(RESULT * result, RESULT * arg1) { double value = tan(R2N(arg1)); SetResult(&result, R_NUMBER, &value); }