Wumpus Posted June 13, 2012 at 10:32 PM Posted June 13, 2012 at 10:32 PM Folgendes Problem: Es soll ein Callback-Event ausgelöst werden, wenn beim Distance IR Bricklet die gemessene Entfernung einen Schwellwert unterschreitet. Allerdings soll der Callback dann nicht periodisch aufgerufen werden, sondern erst wieder, wenn der Schwellwert wieder überschritten wird (quasi Gut- und Schlecht-Alarm). Vermutlich gibt das bisher die API nicht her. Ich stelle mir vor, dass dieses Verhalten durch eine "-1" bei der debounce_period dargestellt werden könnte: distance_ir_set_debounce_period(&dist, -1); distance_ir_register_callback(&dist, DISTANCE_IR_CALLBACK_DISTANCE_REACHED, cb_distance_ir); distance_ir_set_distance_callback_threshold(&dist, '<', 1000, 0; In der Bricklet Library müsste dann in simple_tick() der Part von "Handle threshold signals" so angepasst werden, dass if (BC->signal_period[i] == -1) { switch(BC->threshold_option[i]) { case 'o': BC->threshold_option[i] = 'i'; break; case 'i': BC->threshold_option[i] = 'o'; break; case '<': BC->threshold_option[i] = '>'; break; case '>': BC->threshold_option[i] = '<'; break; } } Auf diese Weise würde man dann jeweils beim Überschreiten der Thresholds in beide Richtungen einen Event bekommen.Supertoll wäre es noch, wenn die Art des Events (Alarm true/false) auch beim Callback-Aufruf aus einem Parameter hervorgehen würde, aber das ging zu Not auch ohne. @TF: Liesse sich das einbauen? Quote
jan Posted June 14, 2012 at 06:13 AM Posted June 14, 2012 at 06:13 AM So etwas nennt man Hysterese. Wäre bestimmt noch eine sinnvolle Implementierung für API(?) --> so dass es gleich als Funktion zum Ausführen vorhanden ist. Quote
borg Posted June 14, 2012 at 06:51 AM Posted June 14, 2012 at 06:51 AM Habs mir mal auf die TODO Liste geschrieben mir das genauer anzugucken. Quote
Wumpus Posted June 23, 2012 at 09:33 AM Author Posted June 23, 2012 at 09:33 AM Hier mein Vorschlag für eine Anpassung der Firmware (Bricklet): diff --git a/software/src/config.h b/software/src/config.h index 531eaa3..71a3b9f 100644 --- a/software/src/config.h +++ b/software/src/config.h @@ -10,7 +10,7 @@ #define BRICKLET_HARDWARE_NAME "Distance IR Bricklet 1.0" #define BRICKLET_FIRMWARE_VERSION_MAJOR 1 #define BRICKLET_FIRMWARE_VERSION_MINOR 1 -#define BRICKLET_FIRMWARE_VERSION_REVISION 1 +#define BRICKLET_FIRMWARE_VERSION_REVISION 2 #define LOGGING_LEVEL LOGGING_DEBUG #define DEBUG_BRICKLET 0 @@ -28,8 +28,8 @@ typedef struct { uint32_t signal_period[NUM_SIMPLE_VALUES]; uint32_t signal_period_counter[NUM_SIMPLE_VALUES]; - uint32_t threshold_debounce; - uint32_t threshold_period_current[NUM_SIMPLE_VALUES]; + int32_t threshold_debounce; + int32_t threshold_period_current[NUM_SIMPLE_VALUES]; int32_t threshold_min[NUM_SIMPLE_VALUES]; int32_t threshold_max[NUM_SIMPLE_VALUES]; char threshold_option[NUM_SIMPLE_VALUES]; und für die Brickletlib: diff --git a/bricklet_simple.c b/bricklet_simple.c index 3574134..80e1890 100644 --- a/bricklet_simple.c +++ b/bricklet_simple.c @@ -276,7 +276,19 @@ void simple_tick(uint8_t tick_type) { BA->send_blocking_with_timeout(&sgvr, sizeof(SimpleGetValueReturn), *BA->com_current); - BC->threshold_period_current[i] = 0; + + // Toggle threshold trigger if debounce has been set to -1 + if(BC->threshold_debounce == -1) { + switch(BC->threshold_option[i]) { + case 'o': BC->threshold_option[i] = 'i'; + break; + case 'i': BC->threshold_option[i] = 'o'; + break; + } + BC->threshold_period_current[i] = -500; + } else { + BC->threshold_period_current[i] = 0; + } logbli("threshold value: %d\n\r", BC->value[i]); } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.