1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
#include <stdlib.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include <termios.h>
#include <sys/fcntl.h>
void OnScrollbarChange(GtkWidget *pWidget, gpointer data)
{
gchar* sLabel2;
gfloat iValue;
/* Récupération de la valeur de la scrollbar */
iValue = gtk_range_get_value(GTK_RANGE(pWidget));
/* Création du nouveau label */
sLabel2 = g_strdup_printf("%f", iValue);
/* Modification du label */
gtk_label_set_text(GTK_LABEL(data), sLabel2);
/* Liberation memoire */
g_free(sLabel2);
}
void fonctionharmonique(GtkSpinButton *spin_button, gpointer data)
{
gchar* sLabel;
gchar* sLabel2;
gchar* sLabel3;
gchar* sLabel4;
gchar* sLabel5;
gchar* sLabel6;
gchar* sLabel7;
gchar* sLabel8;
gchar* sLabel9;
gchar* sLabel10;
gchar* sLabel11;
gchar* sLabel12;
gchar* sLabel13;
gchar* sLabel14;
gchar* sLabel15;
gchar* sLabel16;
gfloat Value;
GtkAdjustment *adjustment;
/* Récupération de la valeur de la scrollbar */
adjustment = gtk_spin_button_get_adjustment (spin_button);
Value = (float)gtk_adjustment_get_value (adjustment);
/* Création du nouveau label */
sLabel = g_strdup_printf("%f Hz", Value);
sLabel2 = g_strdup_printf("%f Hz", Value*2);
sLabel3 = g_strdup_printf("%f Hz", Value*4);
sLabel4 = g_strdup_printf("%f Hz", Value*8);
sLabel5 = g_strdup_printf("%f Hz", Value*16);
sLabel6 = g_strdup_printf("%f Hz", Value*32);
sLabel7 = g_strdup_printf("%f Hz", Value*64);
sLabel8 = g_strdup_printf("%f Hz", Value*128);
sLabel9 = g_strdup_printf("%f Hz", Value*256);
sLabel10 = g_strdup_printf("%f Hz", Value*512);
sLabel11 = g_strdup_printf("%f Hz", Value*1024);
sLabel12 = g_strdup_printf("%f Hz", Value*2048);
sLabel13 = g_strdup_printf("%f Hz", Value*4096);
sLabel14 = g_strdup_printf("%f Hz", Value*8192);
sLabel15 = g_strdup_printf("%f Hz", Value*16384);
sLabel16 = g_strdup_printf("%f Hz", Value*32768);
/* Modification du label */
gtk_label_set_text(GTK_LABEL(data), sLabel);
gtk_label_set_text(GTK_LABEL(data), sLabel2);
gtk_label_set_text(GTK_LABEL(data), sLabel3);
gtk_label_set_text(GTK_LABEL(data), sLabel4);
gtk_label_set_text(GTK_LABEL(data), sLabel5);
gtk_label_set_text(GTK_LABEL(data), sLabel6);
gtk_label_set_text(GTK_LABEL(data), sLabel7);
gtk_label_set_text(GTK_LABEL(data), sLabel8);
gtk_label_set_text(GTK_LABEL(data), sLabel9);
gtk_label_set_text(GTK_LABEL(data), sLabel10);
gtk_label_set_text(GTK_LABEL(data), sLabel11);
gtk_label_set_text(GTK_LABEL(data), sLabel12);
gtk_label_set_text(GTK_LABEL(data), sLabel13);
gtk_label_set_text(GTK_LABEL(data), sLabel14);
gtk_label_set_text(GTK_LABEL(data), sLabel15);
gtk_label_set_text(GTK_LABEL(data), sLabel16);
/* Liberation memoire */
g_free(sLabel);
}
void connection(void)
{
int fd;
char c;
struct termios termios_p;
/* Ouverture de la liaison serie */
if ( (fd=open("/dev/ttyUSB0",O_RDWR)) == -1 ) {
perror("open");
exit(-1);
}
/* Lecture des parametres courants */
tcgetattr(fd,&termios_p);
/* On ignore les BREAK et les caracteres avec erreurs de parite */
termios_p.c_iflag = IGNBRK | IGNPAR;
/* Pas de mode de sortie particulier */
termios_p.c_oflag = 0;
/* Liaison a 9600 bps avec 7 bits de donnees et une parite paire */
termios_p.c_cflag = B9600 | CS7 | PARENB;
/* Mode non-canonique avec echo */
termios_p.c_lflag = ECHO;
/* Caracteres immediatement disponibles */
termios_p.c_cc[VMIN] = 1;
termios_p.c_cc[VTIME] = 0;
/* Sauvegarde des nouveaux parametres */
tcsetattr(fd,TCSANOW,&termios_p);
/* Boucle d'écriture */
while ( 1 ) {
write(fd,"Tapez Ctrl-C pour quitter\n",26);
if ( c == 0x03 ) /* Ctrl-C */
break;
printf("%03u %02x %c\n",c&0xff,c&0xff,c);
}
/* Fermeture */
close(fd);
/* Bye... */
//exit(0);
}
int main(int argc,char **argv)
{
GtkWidget* pWindow;
GtkWidget *pMainVBox;
GtkWidget *pFrame;
GtkWidget *pLabel;
GtkWidget *pScale;
GtkWidget *pScale2;
GtkWidget *pEntry;
GtkWidget *pButton;
GtkWidget *pSpin;
GtkWidget *pToggleBtn;
gchar *sLabel;
GtkWidget *Adjust;
long harmonique;
gtk_init(&argc,&argv);
pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(pWindow), "Moppa");
gtk_window_set_default_size(GTK_WINDOW(pWindow), 200, 400);
gtk_container_set_border_width(GTK_CONTAINER(pWindow), 4);
pMainVBox = gtk_box_new(TRUE, 0);
gtk_container_add(GTK_CONTAINER(pWindow), pMainVBox);
pButton = gtk_button_new_with_label("Envoyer");
gtk_box_pack_start(GTK_BOX(pMainVBox), pButton, FALSE, TRUE, 0);
pLabel = gtk_label_new(NULL);
gtk_box_pack_start(GTK_BOX(pMainVBox), pLabel, FALSE, FALSE, 0);
/* Connexion du signal "clicked" pour ouvrir la boite de dialogue */
g_signal_connect(G_OBJECT(pButton), "clicked", G_CALLBACK(connection), NULL);
pFrame = gtk_frame_new("Harmonique en Hz");
pSpin = gtk_spin_button_new_with_range(0, 20000000, 0.0001);
gtk_container_add(GTK_CONTAINER(pFrame), pSpin);
gtk_box_pack_start(GTK_BOX(pMainVBox), pFrame, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(pSpin), "value-changed",
G_CALLBACK(fonctionharmonique), (GtkWidget*)pLabel);
pEntry = gtk_entry_new();
pFrame = gtk_frame_new("X");
/* Création du widget GtkHScale */
pScale = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,-360 , 0, 0.5);
gtk_container_add(GTK_CONTAINER(pFrame), pScale);
gtk_box_pack_start(GTK_BOX(pMainVBox), pFrame, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(pScale), "value-changed",
G_CALLBACK(OnScrollbarChange), (GtkWidget*)pLabel);
pFrame = gtk_frame_new("Y");
pScale = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL,0 , 200, 0.5);
/* Position du label en dessous */
gtk_scale_set_value_pos(GTK_SCALE(pScale2), GTK_POS_BOTTOM);
gtk_container_add(GTK_CONTAINER(pFrame), pScale);
gtk_box_pack_start(GTK_BOX(pMainVBox), pFrame, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(pScale), "value-changed",
G_CALLBACK(OnScrollbarChange), (GtkWidget*)pLabel);
gtk_widget_show_all(pWindow);
g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_main();
return EXIT_SUCCESS;
} |
Partager