[chronojump] Added lapse in animation reaction time lights. Cleaned code
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Added lapse in animation reaction time lights. Cleaned code
- Date: Thu, 23 Apr 2015 19:19:22 +0000 (UTC)
commit 49c8942f588e80594a7d357cf552863c1cbf43e4
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Apr 23 21:17:47 2015 +0200
Added lapse in animation reaction time lights. Cleaned code
.../chronopic-firmware-multitest.c | 268 ++++++++++++++------
glade/chronojump.glade | 105 ++++++++-
src/chronopic.cs | 17 ++
src/constants.cs | 4 +-
src/gui/chronojump.cs | 9 +
5 files changed, 319 insertions(+), 84 deletions(-)
---
diff --git a/chronopic-firmware/chronopic-firmware-c/chronopic-firmware-multitest.c
b/chronopic-firmware/chronopic-firmware-c/chronopic-firmware-multitest.c
index 989527d..108af91 100644
--- a/chronopic-firmware/chronopic-firmware-c/chronopic-firmware-multitest.c
+++ b/chronopic-firmware/chronopic-firmware-c/chronopic-firmware-multitest.c
@@ -1,5 +1,18 @@
/*
- * Version 8.1
+ * Version 2015.x
+ *
+ 2005 Original Firmware from Juan González <juan iearobotics com>
+ 2010 Translated comments to english by Xavi de Blas <xaviblas gmail com>
+ 2011-2013 Conversion to C by Teng Wei Hua <wadegang gmail com>
+ 2014 Xavier de Blas: Improvements on Read/send version; Change debounce
+ 2015 Ferran Suarez & Xavier de Blas:
+ implementation of new outputs
+ anticipation in an animated "led-wheel", using pauses on Timer2
+ fast blinking led (flickr)
+
+
+ *
+ *
* Translating firmware to SDCC:
* source: http://git.gnome.org/browse/chronojump/plain/chronopic-firmware/chronopic-firmware.asm
@@ -36,6 +49,8 @@ History:
#include <pic16f876a.h> //sdcc for Linux
+
+
//*****************************************
//* CONSTANTS *
//*****************************************
@@ -121,10 +136,29 @@ unsigned char command_reaction_time_rb3_off = 'r';
unsigned char command_reaction_time_rb6_off = 's';
unsigned char command_reaction_time_rb7_off = 't';
unsigned char command_reaction_time_animation_light = 'l';
+unsigned char command_reaction_time_animation_flicker = 'f';
+unsigned char command_reaction_time_animation_buzzer = 'z';
+unsigned char position = 0;
+unsigned int timer2Times;
+
+//in timer 2 prescaler
+//160 times x 61 = 1/2 second
+//TODO: fix this comment:
+//Chronojump will pass the 160
+//then max value will be 255 == 0,8 seconds
+//min 1 == 0.003125
+//TODO: maybe n_times have to be done 4 times to have reasonable values (between 0.0125 and 3.2 seconds)
+unsigned int animation_tick = 61;
+unsigned int animation_tick_n_times = 160;
+
+unsigned char animation_light_should_run = 0; //0 until and 'l' is sent from Chronojump
char version_major = '1';
char version_minor = '1';
+
+
+
//-- encoder's valus
//char encoder_count = 0; //wade
@@ -136,6 +170,9 @@ void isr(void) __interrupt 0
//while (!TXIF);
//TXREG = 0xaa;
+ //RB7 = 0; RB3 = 1; RB0 = 0; RB2 = 0; timer2_delay_long(10);
+
+
if (option == 0)
{
@@ -364,91 +401,104 @@ void update_led()
//-- Led is on bit RB1. Input variable contains
//-- only an information bit (1,0) on less signficant bit
RB1 = !input;
- // 2012-04-02
- if (option == 1)
- {
- RB1 = 1;
- }
}
-//experimental code
-void reaction_time_animation_lights_start()
+//Timer 2 delays ----
+/*
+void timer2_delay_long(unsigned char t2ini)
{
- /*
-
- int min = 200;
- int max = 1000;
- int current = max;
- int step = 200;
- */
- //long time7 = 10000; //1/3 s aprox
- //long time7 = 1000; //casi la hostia
- //long time7 = 500; //la hostia pero apreciable canvi
- //long time7 = 420; //la hostia pero apreciable canvi
- //long time7 = 330; //sembla quasi sempre ences
- //long time7 = 250; //sembla sempre ences
- //1 o 10 sempre ences
+ //-- Dar valor inicial del timer
+ TMR2=t2ini;
+
+ //-- Flag de interrupcion a cero
+ TMR2IF=0;
+
+ //-- Esperar a que transcurra el tiempo indicado
+ while(TMR2IF==0);
+}
+*/
- /*
- * blink
- *
- while(1) {
- RB1 = 1;
- pause2(420);
- RB1 = 0;
- pause2(420);
-
- current = current - step;
- //if(current < 1) {
- // current = max;
- //}
- }
- */
+void timer2_start() {
+ TMR2=animation_tick;
+ //TODO: we are counting 61 (50ms) 160 times.
+ //It will be much better to count a higher value, less times
+ //need to check what's the maximum value allowed
- //animation changing lights
- long time7 = 400;
- long multiplier = 1;
- while(1) {
- RB0 = 0; RB2 = 0; RB3 = 0; RB6 = 0; pause2(time7 * multiplier);
- RB0 = 0; RB2 = 0; RB3 = 0; RB6 = 1; pause2(time7 * multiplier);
- RB0 = 0; RB2 = 0; RB3 = 1; RB6 = 0; pause2(time7 * multiplier);
- RB0 = 0; RB2 = 0; RB3 = 1; RB6 = 1; pause2(time7 * multiplier);
- RB0 = 0; RB2 = 1; RB3 = 0; RB6 = 0; pause2(time7 * multiplier);
- RB0 = 0; RB2 = 1; RB3 = 0; RB6 = 1; pause2(time7 * multiplier);
- RB0 = 0; RB2 = 1; RB3 = 1; RB6 = 0; pause2(time7 * multiplier);
- RB0 = 0; RB2 = 1; RB3 = 1; RB6 = 1; pause2(time7 * multiplier);
- RB0 = 1; RB2 = 0; RB3 = 0; RB6 = 0; pause2(time7 * multiplier);
- RB0 = 1; RB2 = 0; RB3 = 0; RB6 = 1; pause2(time7 * multiplier);
- RB0 = 1; RB2 = 0; RB3 = 1; RB6 = 0; pause2(time7 * multiplier);
- RB0 = 1; RB2 = 0; RB3 = 1; RB6 = 1; pause2(time7 * multiplier);
- RB0 = 1; RB2 = 1; RB3 = 0; RB6 = 0; pause2(time7 * multiplier);
- RB0 = 1; RB2 = 1; RB3 = 0; RB6 = 1; pause2(time7 * multiplier);
- RB0 = 1; RB2 = 1; RB3 = 1; RB6 = 0; pause2(time7 * multiplier);
- RB0 = 1; RB2 = 1; RB3 = 1; RB6 = 1; pause2(time7 * multiplier);
-
- multiplier ++;
- //if(multiplier > 7)
- // multiplier = 1;
- }
-
- /* don't know why this doesn't work properly
- unsigned int a,b,c,d;
- while(1) {
- for (a = 0; a <= 1; a++) {
- for (b = 0; b <= 1; b++) {
- for (c = 0; c <= 1; c++) {
- for (d = 0; d <= 1; d++) {
- RB0 = a;
- RB2 = b;
- RB3 = c;
- RB6 = d;
- pause2(time7);
- }
- }
- }
+ //-- Flag de interrupcion a cero
+ TMR2IF=0;
+}
+
+//end of Timer 2 delays ----
+
+
+void reaction_time_animation_lights_do()
+{
+ if(TMR2IF == 1) {
+
+ timer2_start();
+ timer2Times --;
+
+ if(timer2Times <= 0) {
+
+ //RB7 = 0; RB3 = 0; RB0 = 0; RB2 = 0; //OFF
+ switch(position) {
+ case 0:
+ RB7 = 1; RB3 = 0; RB0 = 1; RB2 = 0;
+ break;
+ case 1:
+ RB7 = 1; RB3 = 0; RB0 = 1; RB2 = 1;
+ break;
+ case 2:
+ RB7 = 1; RB3 = 0; RB0 = 0; RB2 = 0;
+ break;
+ case 3:
+ RB7 = 1; RB3 = 0; RB0 = 0; RB2 = 1;
+ break;
+ case 4:
+ RB7 = 1; RB3 = 1; RB0 = 1; RB2 = 0;
+ break;
+ case 5:
+ RB7 = 1; RB3 = 1; RB0 = 1; RB2 = 1;
+ break;
+ case 6:
+ RB7 = 1; RB3 = 1; RB0 = 0; RB2 = 0;
+ break;
+ case 7:
+ RB7 = 1; RB3 = 1; RB0 = 0; RB2 = 1;
+ break;
+ case 8:
+ RB7 = 0; RB3 = 0; RB0 = 1; RB2 = 0;
+ break;
+ case 9:
+ RB7 = 0; RB3 = 0; RB0 = 0; RB2 = 1;
+ break;
+ case 10:
+ RB7 = 0; RB3 = 0; RB0 = 1; RB2 = 1;
+ break;
+ case 11:
+ RB7 = 0; RB3 = 1; RB0 = 0; RB2 = 0;
+ break;
+ case 12:
+ RB7 = 0; RB3 = 1; RB0 = 0; RB2 = 1;
+ break;
+ case 13:
+ RB7 = 0; RB3 = 1; RB0 = 1; RB2 = 0;
+ break;
+ case 14:
+ RB7 = 0; RB3 = 1; RB0 = 1; RB2 = 1;
+ }
+
+ timer2Times = animation_tick_n_times;
+
+ position ++;
+ if(position > 14)
+ position = 0;
}
- }
- */
+
+ }
+
+ //-- Esperar a que transcurra el tiempo indicado
+ //while(TMR2IF==0);
}
@@ -489,6 +539,36 @@ static void asm_ledon()
MOVWF PORTC
__endasm;
}
+
+static void animation_light_convert(char sentData)
+{
+ switch(sentData) {
+ case 0:
+ animation_tick_n_times = 5;
+ break;
+ case 1:
+ animation_tick_n_times = 10;
+ break;
+ case 2:
+ animation_tick_n_times = 20;
+ break;
+ case 3:
+ animation_tick_n_times = 40;
+ break;
+ case 4:
+ animation_tick_n_times = 80;
+ break;
+ case 5:
+ animation_tick_n_times = 160; //160[default] * 61 = ,5 seconds
+ break;
+ case 6:
+ animation_tick_n_times = 320; //1 second
+ break;
+ case 7:
+ animation_tick_n_times = 640; //2 seconds
+ break;
+ }
+}
void main(void)
{
@@ -520,6 +600,13 @@ void main(void)
//----------------------------------------------
sci_configuration();
+ //-- Configure Timer 2
+ //-- Temporizer mode
+ TOUTPS2=0; TOUTPS1=0; TOUTPS0=0;
+ //-- Set Prescaler at 16
+ T2CKPS1=1; T2CKPS0=1;
+ //Start temporizer
+ TMR2ON=1;
//----------------------------------------------
//- CONFIGURATION OF TIMER 0
//----------------------------------------------
@@ -619,8 +706,15 @@ void main(void)
//-- Activate peripheral interruptions
PEIE = 1;
//-- Activate global interruptions
+
GIE = 1;
+ //initialize lights stuff for animation wheel
+ position = 0;
+ timer2Times = animation_tick_n_times;
+ timer2_start();
+
+
//****************************
//* MAIN LOOP
//****************************
@@ -664,8 +758,10 @@ void main(void)
RB2 = 0; //RB6 = 0
else if (my_char == command_reaction_time_rb7_off) // 't'
RB7 = 0;
- else if (my_char == command_reaction_time_animation_light) // 'l'
- reaction_time_animation_lights_start();
+ else if (my_char == command_reaction_time_animation_light) { // 'l'
+ animation_light_convert(sci_readchar());
+ animation_light_should_run = 1;
+ }
else
send_error();
}
@@ -675,6 +771,9 @@ void main(void)
//------------------------------------------------------
if (status == STAT_WAITING_EVENT) // status = STAT_WAITING_EVENT?
{
+ //TODO: only if an 'l' has been sent before
+ if(animation_light_should_run == 1)
+ reaction_time_animation_lights_do();
}
else if (status == STAT_DEBOUNCE) // status = DEBOUNCE?
{
@@ -726,6 +825,11 @@ void main(void)
//----------------------------
//- STATUS FRAMEX
//----------------------------
+ //
+ //stop animation light, and go to the beginning
+ animation_light_should_run = 0;
+ position = 0;
+
//-- Send frame of changing input
//-- First the frame identifier
sci_sendchar(FCHANGE);
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 5782898..cff87a1 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -5256,6 +5256,7 @@ It starts before and arrives there with some speed.</property>
</child>
<child>
<widget class="GtkVBox"
id="vbox_reaction_time_experimental">
+ <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">8</property>
<property name="spacing">10</property>
@@ -5273,7 +5274,6 @@ It starts before and arrives there with some speed.</property>
</child>
<child>
<widget class="GtkTable" id="table11">
- <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">2</property>
<property name="n_columns">3</property>
@@ -5364,6 +5364,52 @@ It starts before and arrives there with some speed.</property>
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <widget class="GtkHBox" id="hbox147">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">12</property>
+ <child>
+ <widget class="GtkSpinButton"
id="spinbutton_animation_lights_speed">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ <property
name="invisible_char_set">True</property>
+ <property
name="primary_icon_activatable">False</property>
+ <property
name="secondary_icon_activatable">False</property>
+ <property
name="primary_icon_sensitive">True</property>
+ <property
name="secondary_icon_sensitive">True</property>
+ <property name="adjustment">5 0 7 1 1
0</property>
+ <property name="climb_rate">1</property>
+ <property name="numeric">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkButton"
id="button_animation_lights_start">
+ <property name="label">Animation ligths -
start</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked"
handler="on_button_animation_lights_start_clicked" swapped="no"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="expand">True</property>
@@ -6703,6 +6749,9 @@ Second Chronopic to platforms.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">True</property>
@@ -7595,6 +7644,9 @@ Second Chronopic to platforms.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
<child>
@@ -8739,6 +8791,9 @@ Second Chronopic to platforms.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="position">2</property>
@@ -9524,6 +9579,9 @@ Second Chronopic to platforms.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="position">4</property>
@@ -20363,6 +20421,9 @@ by you</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
</widget>
@@ -21056,6 +21117,9 @@ by you</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
</widget>
@@ -22241,6 +22305,9 @@ by you</property>
<placeholder/>
</child>
<child>
+ <placeholder/>
+ </child>
+ <child>
<widget class="GtkButton" id="button_video_url">
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -22483,6 +22550,9 @@ by you</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">True</property>
@@ -32580,6 +32650,24 @@ options</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
</widget>
@@ -34653,6 +34741,9 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
</widget>
@@ -35384,6 +35475,9 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
</widget>
@@ -38081,6 +38175,9 @@ show elevation as:</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="left_attach">2</property>
@@ -38438,6 +38535,9 @@ show elevation as:</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
</widget>
@@ -38810,6 +38910,9 @@ show elevation as:</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
</widget>
diff --git a/src/chronopic.cs b/src/chronopic.cs
index fdb169d..6289a56 100644
--- a/src/chronopic.cs
+++ b/src/chronopic.cs
@@ -621,6 +621,23 @@ public class ChronopicStartReactionTime : ChronopicAuto
}
}
+//like above method but sending the waiting time between each light
+public class ChronopicStartReactionTimeAnimation : ChronopicAuto
+{
+ protected internal override string Communicate()
+ {
+ try {
+ //values go from 0 to 7
+ byte[] bytesToSend = new byte[2] { 0x6c, BitConverter.GetBytes(sendNum)[0] }; //l, 05
+ sp.Write(bytesToSend,0,2);
+
+ } catch {
+ return "ERROR";
+ }
+ return "SUCCESS";
+ }
+}
+
public static class ChronopicPorts
{
public static string [] GetPorts() {
diff --git a/src/constants.cs b/src/constants.cs
index 21cc26e..a3a5db4 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -45,6 +45,7 @@ public class Constants
"Teng Wei Hua (wadedang gmail com)\n\t" + Catalog.GetString("Translation of Firmware to C.")
+ "\n\t" +
Catalog.GetString("New firmware features.") + " " + Catalog.GetString("Encoder
hardware layer.") + "\n",
"Juan Gonzalez Gómez (http://www.iearobotics.com)\n\t" + Catalog.GetString("Skypic,
Chronopic, connection between hardware and software.") + "\n",
+ "Ferran Suárez Rodríguez (ferransuarez2 gmail com)\n\t" + Catalog.GetString("Chronopic
reaction time advanced implementation.") + "\n",
"Ricardo Gómez González (http://www.iearobotics.com)\n\t" + Catalog.GetString("Chronopic3
industrial prototype.") + "\n",
"Juan Fernando Pardo (juanfer juanfer com ar)\n\t" + "Chronopic2."
};
@@ -53,7 +54,8 @@ public class Constants
"Anna Padullés (hardware chronojump org)\n",
"Xavier Padullés (testing chronojump org)\n",
"Teng Wei Hua (wadedang gmail com)\n",
- "Xavier de Blas Foix (info chronojump org)"
+ "Xavier de Blas Foix (info chronojump org)\n",
+ "Ferran Suárez Rodríguez (ferransuarez2 gmail com)\n"
};
public static string [] AuthorsMath = {
"Carlos J. Gil Bellosta (http://www.datanalytics.com)\n",
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index dd01614..5363f05 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -194,6 +194,8 @@ public partial class ChronoJumpWindow
[Widget] Gtk.Button button_edit_selected_reaction_time;
[Widget] Gtk.Button button_video_play_selected_reaction_time;
[Widget] Gtk.Button button_delete_selected_reaction_time;
+ [Widget] Gtk.SpinButton spinbutton_animation_lights_speed;
+
//pulse
[Widget] Gtk.Button button_edit_selected_pulse;
[Widget] Gtk.Button button_video_play_selected_pulse;
@@ -4479,6 +4481,13 @@ public partial class ChronoJumpWindow
cs.CharToSend = "T";
cs.Write(chronopicWin.SP,0);
}
+
+ private void on_button_animation_lights_start_clicked (object o, EventArgs args) {
+ int speed = Convert.ToInt32(spinbutton_animation_lights_speed.Value);
+ ChronopicAuto cs = new ChronopicStartReactionTimeAnimation();
+ cs.CharToSend = "l";
+ cs.Write(chronopicWin.SP,speed);
+ }
/* ---------------------------------------------------------
* ---------------- PULSES EXECUTION ----------------------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]