aboutsummaryrefslogtreecommitdiffstats
path: root/cphidgetadvancedservo.c
diff options
context:
space:
mode:
authorJonathan McCrohan <jmccrohan@gmail.com>2012-05-09 00:47:30 +0100
committerJonathan McCrohan <jmccrohan@gmail.com>2012-05-09 00:47:30 +0100
commit260123716172d33f44bdc0e4e5422554d139215c (patch)
tree840e8e6387b96bd6f9afe3ffebc19c781a112f1b /cphidgetadvancedservo.c
parent0b624384cd52be20e61284551d832b499d7b7707 (diff)
downloadlibphidget21-260123716172d33f44bdc0e4e5422554d139215c.tar.gz
Imported Upstream version 2.1.8.20120507upstream/2.1.8.20120507
Diffstat (limited to 'cphidgetadvancedservo.c')
-rw-r--r--cphidgetadvancedservo.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/cphidgetadvancedservo.c b/cphidgetadvancedservo.c
index 12419cb..8b5624b 100644
--- a/cphidgetadvancedservo.c
+++ b/cphidgetadvancedservo.c
@@ -310,7 +310,7 @@ CPHIDGETDATA(AdvancedServo)
else
phid->motorPositionEcho[i] = position[i];
if(velocity[i] > phid->velocityMaxLimit || velocity[i] < -phid->velocityMaxLimit)
- LOG(PHIDGET_LOG_WARNING, "Phidget advanced servo recieved out of range velocity data: %lE", velocity[i]);
+ LOG(PHIDGET_LOG_WARNING, "Phidget advanced servo received out of range velocity data: %lE", velocity[i]);
else
phid->motorVelocityEcho[i] = velocity[i];
@@ -570,8 +570,8 @@ CSETINDEX(AdvancedServo,Acceleration,double)
TESTDEVICETYPE(PHIDCLASS_ADVANCEDSERVO)
TESTATTACHED
TESTINDEX(phid.attr.advancedservo.numMotors)
- TESTRANGE(servo_us_to_degrees_vel(phid->servoParams[Index], phid->accelerationMin, PFALSE),
- servo_us_to_degrees_vel(phid->servoParams[Index], phid->accelerationMax, PFALSE))
+ TESTRANGE(servo_us_to_degrees_vel(phid->servoParams[Index], phid->accelerationMin, PFALSE)-0.5,
+ servo_us_to_degrees_vel(phid->servoParams[Index], phid->accelerationMax, PFALSE)+0.5)
newVal = servo_degrees_to_us_vel(phid->servoParams[Index], newVal);
@@ -620,8 +620,8 @@ CSETINDEX(AdvancedServo,VelocityLimit,double)
TESTDEVICETYPE(PHIDCLASS_ADVANCEDSERVO)
TESTATTACHED
TESTINDEX(phid.attr.advancedservo.numMotors)
- TESTRANGE(servo_us_to_degrees_vel(phid->servoParams[Index], phid->velocityMin, PTRUE)-0.5,
- servo_us_to_degrees_vel(phid->servoParams[Index], phid->velocityMax[Index]+0.5, PTRUE))
+ TESTRANGE(servo_us_to_degrees_vel(phid->servoParams[Index], phid->velocityMin, PFALSE)-0.5,
+ servo_us_to_degrees_vel(phid->servoParams[Index], phid->velocityMax[Index], PFALSE)+0.5)
newVal = servo_degrees_to_us_vel(phid->servoParams[Index], newVal);
@@ -684,8 +684,8 @@ CSETINDEX(AdvancedServo,Position,double)
TESTDEVICETYPE(PHIDCLASS_ADVANCEDSERVO)
TESTATTACHED
TESTINDEX(phid.attr.advancedservo.numMotors)
- TESTRANGE(servo_us_to_degrees(phid->servoParams[Index], phid->motorPositionMin[Index], PTRUE)-0.5,
- servo_us_to_degrees(phid->servoParams[Index], phid->motorPositionMax[Index], PTRUE)+0.5)
+ TESTRANGE(servo_us_to_degrees(phid->servoParams[Index], phid->motorPositionMin[Index], PFALSE)-0.5,
+ servo_us_to_degrees(phid->servoParams[Index], phid->motorPositionMax[Index], PFALSE)+0.5)
newVal = servo_degrees_to_us(phid->servoParams[Index], newVal);
.highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* $Id: widget_timer.c,v 1.2 2006/02/25 13:36:33 geronet Exp $
 *
 * timer widget handling
 *
 * Copyright (C) 2006 Michael Reinelt <reinelt@eunet.at>
 * Copyright (C) 2006 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *
 * $Log: widget_timer.c,v $
 * Revision 1.2  2006/02/25 13:36:33  geronet
 * updated indent.sh, applied coding style
 *
 * Revision 1.1  2006/01/23 06:17:18  reinelt
 * timer widget added
 *
 */

/* 
 * exported functions:
 *
 * WIDGET_CLASS Widget_Timer
 *   the timer widget
 *
 */


#include "config.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#include "debug.h"
#include "cfg.h"
#include "qprintf.h"
#include "evaluator.h"
#include "timer.h"
#include "widget.h"
#include "widget_timer.h"

#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif

void widget_timer_update(void *Self)
{
    WIDGET *W = (WIDGET *) Self;
    WIDGET_TIMER *Timer = W->data;
    RESULT result = { 0, 0, 0, NULL };

    /* evaluate expressions */
    Timer->update = 10;
    if (Timer->update_tree != NULL) {
	Eval(Timer->update_tree, &result);
	Timer->update = R2N(&result);
	if (Timer->update < 10)
	    Timer->update = 10;
	DelResult(&result);
    }

    Timer->active = 1;
    if (Timer->active_tree != NULL) {
	Eval(Timer->active_tree, &result);
	Timer->active = R2N(&result);
	if (Timer->active < 0)
	    Timer->active = 0;
	DelResult(&result);
    }

    /* finally, fire it! */
    if (Timer->active) {
	Eval(Timer->expr_tree, &result);
	DelResult(&result);
    }

    /* add a new one-shot timer */
    timer_add(widget_timer_update, Self, Timer->update, 1);
}



int widget_timer_init(WIDGET * Self)
{
    char *section;
    WIDGET_TIMER *Timer;

    /* prepare config section */
    /* strlen("Widget:")=7 */
    section = malloc(strlen(Self->name) + 8);
    strcpy(section, "Widget:");
    strcat(section, Self->name);

    Timer = malloc(sizeof(WIDGET_TIMER));
    memset(Timer, 0, sizeof(WIDGET_TIMER));

    /* get raw expressions (we evaluate them ourselves) */
    Timer->expression = cfg_get_raw(section, "axpression", NULL);
    Timer->update_expr = cfg_get_raw(section, "update", "100");
    Timer->active_expr = cfg_get_raw(section, "active", "1");

    /* sanity checks */
    if (Timer->expression == NULL || *Timer->expression == '\0') {
	error("Timer %s has no expression, using '1'", Self->name);
	Timer->expression = "1";
    }
    if (Timer->update_expr == NULL || *Timer->update_expr == '\0') {
	error("Timer %s has no update, using '100'", Self->name);
	Timer->update_expr = "100";
    }

    /* compile'em */
    Compile(Timer->expression, &Timer->expr_tree);
    Compile(Timer->update_expr, &Timer->update_tree);
    Compile(Timer->active_expr, &Timer->active_tree);


    free(section);
    Self->data = Timer;

    /* just do it! */
    widget_timer_update(Self);

    return 0;
}


int widget_timer_quit(WIDGET * Self)
{
    if (Self) {
	/* do not deallocate child widget! */
	if (Self->parent == NULL) {
	    if (Self->data) {
		WIDGET_TIMER *Timer = Self->data;
		DelTree(Timer->expr_tree);
		DelTree(Timer->update_tree);
		DelTree(Timer->active_tree);
		free(Self->data);
		Self->data = NULL;
	    }
	}
    }

    return 0;

}


int widget_timer_register(void)
{
    WIDGET_CLASS wc;
    wc = Widget_Timer;
    widget_register(&wc);
    return 0;
}


WIDGET_CLASS Widget_Timer = {
  name:"timer",
  type:WIDGET_TYPE_TIMER,
  init:widget_timer_init,
  draw:NULL,
  quit:widget_timer_quit,
};