Permalink
Browse files

multi-channel operation (still buggy)

  • Loading branch information...
1 parent d0e216e commit 651b9424c8a5536fca478a6606939aa6893dea69 @alvieboy committed Dec 2, 2009
Showing with 131 additions and 74 deletions.
  1. +8 −1 README.protocol
  2. +22 −9 UI/display.c
  3. +27 −33 UI/scope.c
  4. +2 −2 UI/scope.h
  5. +9 −9 UI/serial.c
  6. +1 −1 UI/serial.h
  7. +60 −17 oscope.pde
  8. +2 −2 protocol.h
View
@@ -147,6 +147,7 @@
3 - ACD prescaler
4,5 - Number of samples (NUM_SAMPLES). Big-endian.
6 (v1.4) - Capture flags
+ 7 (v2.2) - Number of channels
* COMMAND_PONG 0xE3
> Payload size: variable
@@ -173,6 +174,12 @@
Set capture flags. Will reply with COMMAND_PARAMETERS_REPLY.
Bitmap of following values:
bit 0 - Invert trigger
- bit 1 - Set dual-channel
+ bit 1 - Set dual-channel (deprecated in v2.2 - see COMMAND_SET_CHANNELS)
+
+ * COMMAND_SET_CHANNELS 0x51
+ > Payload size: 1
+ > Since: v2.2
+
+ Set number of channels (1 to 4). Will reply with COMMAND_PARAMETERS_REPLY.
View
@@ -36,6 +36,7 @@ GtkWidget *scale_trigger;
GtkWidget *scale_holdoff;
GtkWidget *combo_prescaler;
GtkWidget *combo_vref;
+GtkWidget *combo_channels;
GtkWidget *shot_button;
GtkWidget *freeze_button;
@@ -61,13 +62,13 @@ void scope_got_parameters(unsigned char triggerLevel,
unsigned char adcref,
unsigned char prescale,
unsigned short numS,
- unsigned char flags)
+ unsigned char flags,
+ unsigned char num_channels)
{
numSamples=numS;
gtk_widget_set_size_request(image,numS,256);
scope_display_set_samples(image,numS);
- printf("DUAL: %d\n",!!(flags & FLAG_DUAL_CHANNEL));
- scope_display_set_dual(image,!!(flags & FLAG_DUAL_CHANNEL));
+ scope_display_set_channels(image,num_channels);
gtk_range_set_value(GTK_RANGE(scale_trigger),triggerLevel);
gtk_range_set_value(GTK_RANGE(scale_holdoff),holdoffSamples);
@@ -82,6 +83,7 @@ void scope_got_parameters(unsigned char triggerLevel,
}
gtk_combo_box_set_active(GTK_COMBO_BOX(combo_prescaler),7-prescale);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(combo_channels),num_channels-1);
}
@@ -156,10 +158,10 @@ void trigger_toggle_changed(GtkWidget *widget)
serial_set_trigger_invert(active);
}
-void dual_toggle_changed(GtkWidget *widget)
+void channels_changed(GtkWidget *widget)
{
- gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
- serial_set_dual_channel(active);
+ char *active_s = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widget));
+ serial_set_channels(atoi(active_s));
}
void cancel_trigger(GtkDialog *widget)
@@ -300,6 +302,20 @@ int main(int argc,char **argv)
gtk_combo_box_append_text(GTK_COMBO_BOX(combo_vref),"AVcc");
gtk_combo_box_append_text(GTK_COMBO_BOX(combo_vref),"Internal 1.1V");
+
+ hbox = gtk_hbox_new(FALSE,4);
+ gtk_box_pack_start(GTK_BOX(vbox),hbox,TRUE,TRUE,0);
+ gtk_box_pack_start(GTK_BOX(hbox),gtk_label_new("Channels:"),TRUE,TRUE,0);
+ combo_channels = gtk_combo_box_new_text();
+ gtk_box_pack_start(GTK_BOX(hbox),combo_channels,TRUE,TRUE,0);
+
+ gtk_combo_box_append_text(GTK_COMBO_BOX(combo_channels),"1");
+ gtk_combo_box_append_text(GTK_COMBO_BOX(combo_channels),"2");
+ gtk_combo_box_append_text(GTK_COMBO_BOX(combo_channels),"3");
+ gtk_combo_box_append_text(GTK_COMBO_BOX(combo_channels),"4");
+ g_signal_connect(G_OBJECT(combo_channels),"changed",G_CALLBACK(&channels_changed),NULL);
+
+
hbox = gtk_hbox_new(FALSE,4);
gtk_box_pack_start(GTK_BOX(vbox),hbox,TRUE,TRUE,0);
@@ -315,9 +331,6 @@ int main(int argc,char **argv)
gtk_box_pack_start(GTK_BOX(hbox),tog,TRUE,TRUE,0);
g_signal_connect(G_OBJECT(tog),"toggled",G_CALLBACK(&trigger_toggle_changed),NULL);
- GtkWidget *dual_check_button = gtk_check_button_new_with_label("Dual Channel");
- gtk_box_pack_start(GTK_BOX(hbox),dual_check_button,TRUE,TRUE,0);
- g_signal_connect(G_OBJECT(dual_check_button),"toggled",G_CALLBACK(&dual_toggle_changed),NULL);
gtk_widget_show_all(window);
View
@@ -27,7 +27,6 @@ static void scope_display_init (ScopeDisplay *scope)
{
scope->zoom=1;
scope->dbuf = NULL;
- scope->dual = FALSE;
scope->xy = FALSE;
#ifdef HAVE_DFT
scope->mode = MODE_NORMAL;
@@ -74,6 +73,13 @@ static void draw_grid(cairo_t *cr,const GtkAllocation *allocation)
}
}
+struct { double r,g,b; } colors[] = {
+ { 0.0,1.0,0.0 }, // Channel 0 - green
+ { 1.0,1.0,0.0 }, // Channel 1 - yellow
+ { 0.99,0.75,0.57 }, // Channel 2
+ { 0.89,0.73,0.86 } // Channel 3
+};
+
static void draw(GtkWidget *scope, cairo_t *cr)
{
ScopeDisplay *self = SCOPE_DISPLAY(scope);
@@ -120,44 +126,32 @@ static void draw(GtkWidget *scope, cairo_t *cr)
#else
if (NULL!=self->dbuf) {
- if (!self->dual) {
- for (i=0; i<self->numSamples/self->zoom; i++) {
- cairo_move_to(cr,lx,ly);
+ if (self->xy && self->channels == 2) {
+
+ lx=scope->allocation.x + scope->allocation.width / 2;
+ ly=scope->allocation.y + scope->allocation.height / 2;
+
+ for (i=0; i<self->numSamples; i+=2) {
+ cairo_move_to(cr,
+ lx + ((int)self->dbuf[i])-127 ,
+ ly + ((int)self->dbuf[i+1])-127
+ );
lx=scope->allocation.x + i*self->zoom;
ly=scope->allocation.y+scope->allocation.height - self->dbuf[i];
cairo_line_to(cr,lx,ly);
}
cairo_stroke (cr);
- } else {
- if (self->xy) {
- lx=scope->allocation.x + scope->allocation.width / 2;
- ly=scope->allocation.y + scope->allocation.height / 2;
+ } else {
+ int start;
+ for (start=0; start<self->channels; start++) {
- for (i=0; i<self->numSamples; i+=2) {
- cairo_move_to(cr,
- lx + ((int)self->dbuf[i])-127 ,
- ly + ((int)self->dbuf[i+1])-127
- );
- lx=scope->allocation.x + i*self->zoom;
- ly=scope->allocation.y+scope->allocation.height - self->dbuf[i];
- cairo_line_to(cr,lx,ly);
- }
- cairo_stroke (cr);
+ cairo_set_source_rgb(cr, colors[start].r,colors[start].g,colors[start].b);
- } else {
- for (i=0; i<self->numSamples/self->zoom; i+=2) {
- cairo_move_to(cr,lx,ly);
- lx=scope->allocation.x + i*self->zoom;
- ly=scope->allocation.y+scope->allocation.height - self->dbuf[i];
- cairo_line_to(cr,lx,ly);
- }
- cairo_stroke (cr);
- cairo_set_source_rgb(cr,255,255,0);
- lx=scope->allocation.x+1;
+ lx=scope->allocation.x+start;
ly=scope->allocation.y+scope->allocation.height;
- for (i=1; i<self->numSamples/self->zoom; i+=2) {
+ for (i=start; i<self->numSamples/self->zoom; i+=self->channels) {
cairo_move_to(cr,lx,ly);
lx=scope->allocation.x + i*self->zoom;
ly=scope->allocation.y+scope->allocation.height - self->dbuf[i];
@@ -188,8 +182,8 @@ static void draw(GtkWidget *scope, cairo_t *cr)
);
cairo_show_text(cr, text);
- if (self->dual) {
- sprintf(text,"fMax/chan: %.02fHz", self->freq/4);
+ if (self->channels>1) {
+ sprintf(text,"fMax/chan: %.02fHz", self->freq/(2*self->channels));
} else {
sprintf(text,"fMax: %.02fHz", self->freq/2);
}
@@ -278,11 +272,11 @@ void scope_display_set_trigger_level(GtkWidget *scope, unsigned char level)
gtk_widget_queue_draw(scope);
}
-void scope_display_set_dual(GtkWidget *scope, gboolean value)
+void scope_display_set_channels(GtkWidget *scope, unsigned char channels)
{
ScopeDisplay *self = SCOPE_DISPLAY(scope);
- self->dual=value;
+ self->channels=channels;
gtk_widget_queue_draw(scope);
}
View
@@ -36,7 +36,7 @@ struct _ScopeDisplay
unsigned short numSamples;
unsigned char tlevel;
unsigned int zoom;
- gboolean dual;
+ unsigned char channels;
gboolean xy;
double freq;
#ifdef HAVE_DFT
@@ -66,6 +66,6 @@ void scope_display_set_trigger_level(GtkWidget *scope, unsigned char level);
void scope_display_set_zoom(GtkWidget *scope, unsigned int zoom);
void scope_display_set_samples(GtkWidget *scope, unsigned short numSamples);
void scope_display_set_sample_freq(GtkWidget *scope, double freq);
-void scope_display_set_dual(GtkWidget *scope, gboolean);
+void scope_display_set_channels(GtkWidget *scope, unsigned char);
#endif
View
@@ -34,7 +34,6 @@ static gboolean in_request;
static gboolean freeze = FALSE;
static gboolean delay_request = FALSE;
static gboolean is_trigger_invert;
-static gboolean is_dual_channel;
#ifdef STANDALONE
GMainLoop *loo;
@@ -49,7 +48,8 @@ extern void scope_got_parameters(unsigned char triggerLevel,
unsigned char adcref,
unsigned char prescale,
unsigned short numSamples,
- unsigned char flags);
+ unsigned char flags,
+ unsigned char numChannels);
void sendchar(int i) {
char t = i &0xff;
@@ -116,10 +116,10 @@ void process_packet(unsigned char command, unsigned char *buf, unsigned short si
ns += buf[5];
is_trigger_invert = buf[6] & FLAG_INVERT_TRIGGER;
- is_dual_channel = buf[6] & FLAG_DUAL_CHANNEL;
- scope_got_parameters(buf[0],buf[1],buf[2],buf[3],ns,buf[6]);
+ scope_got_parameters(buf[0],buf[1],buf[2],buf[3],ns,buf[6],buf[7]);
printf("Num samples: %d %d %d \n", ns, buf[4],buf[5]);
+ printf("Channels: %d \n",buf[7]);
}
switch(state) {
@@ -346,8 +346,6 @@ void serial_set_vref(unsigned char vref)
static void set_flags()
{
unsigned char c=0;
- if (is_dual_channel)
- c|=FLAG_DUAL_CHANNEL;
if (is_trigger_invert)
c|=FLAG_INVERT_TRIGGER;
send_packet(COMMAND_SET_FLAGS,&c,1);
@@ -359,10 +357,12 @@ void serial_set_trigger_invert(gboolean active)
is_trigger_invert = active;
set_flags();
}
-void serial_set_dual_channel(gboolean active)
+void serial_set_channels(int channels)
{
- is_dual_channel = active;
- set_flags();
+ if (channels<1 || channels>4)
+ return;
+ unsigned char c = channels;
+ send_packet(COMMAND_SET_CHANNELS, &c, 1);
}
int serial_run( void (*setdata)(unsigned char *data,size_t size))
View
@@ -28,7 +28,7 @@ void serial_set_holdoff(unsigned char holdoff);
void serial_set_prescaler(unsigned char prescaler);
void serial_set_vref(unsigned char vref);
void serial_set_trigger_invert(gboolean active);
-void serial_set_dual_channel(gboolean active);
+void serial_set_channels(int channels);
double get_sample_frequency(unsigned long freq, unsigned long prescaler);
void serial_set_oneshot( void(*callback)(void*) , void *data);
Oops, something went wrong.

0 comments on commit 651b942

Please sign in to comment.