work
This commit is contained in:
parent
6793f10927
commit
e3e4f97a94
72
gtk2-gui.c
72
gtk2-gui.c
@ -16,8 +16,15 @@
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "gtk2-gui.h"
|
||||
#include "i2c.h"
|
||||
@ -181,12 +188,6 @@ static void on_button103_clicked(GtkButton *button, gpointer user_data)
|
||||
g_timeout_add(150, application_cb, NULL);
|
||||
}
|
||||
|
||||
/* FLASH-READ Button */
|
||||
static void on_button201_clicked(GtkButton *button, gpointer user_data)
|
||||
{
|
||||
add_message("sorry, not implemented yet\n");
|
||||
}
|
||||
|
||||
/* progress-bar callback */
|
||||
static void progress_cb(int pos, int size)
|
||||
{
|
||||
@ -198,21 +199,74 @@ static void progress_cb(int pos, int size)
|
||||
gdk_window_process_updates(gtk_widget_get_parent_window(progressbar201), 1);
|
||||
}
|
||||
|
||||
static char * load_file(const char *filename, int *filesize)
|
||||
{
|
||||
int fd = open(filename, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror("open()");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct stat statbuf;
|
||||
if (fstat(fd, &statbuf) == -1) {
|
||||
perror("stat()");
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*filesize = statbuf.st_size;
|
||||
|
||||
char *data = malloc(*filesize);
|
||||
if (data == NULL) {
|
||||
perror("malloc()");
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
read(fd, data, *filesize);
|
||||
close(fd);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/* FLASH-READ Button */
|
||||
static void on_button201_clicked(GtkButton *button, gpointer user_data)
|
||||
{
|
||||
add_message("sorry, not implemented yet\n");
|
||||
}
|
||||
|
||||
/* FLASH-WRITE Button */
|
||||
static void on_button202_clicked(GtkButton *button, gpointer user_data)
|
||||
{
|
||||
char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filechooserbutton201));
|
||||
int size = i2c_write_flash(i2c_fd, filename, progress_cb);
|
||||
|
||||
int filesize;
|
||||
char *filedata = load_file(filename, &filesize);
|
||||
if (filedata != NULL) {
|
||||
int size = i2c_write_flash(i2c_fd, filedata, filesize, progress_cb);
|
||||
free(filedata);
|
||||
|
||||
char msg_buf[64];
|
||||
snprintf(msg_buf, sizeof(msg_buf), "FLASH: %d bytes written and verified\n", size);
|
||||
snprintf(msg_buf, sizeof(msg_buf), "FLASH: %d bytes written\n", size);
|
||||
add_message(msg_buf);
|
||||
}
|
||||
}
|
||||
|
||||
/* FLASH-VERIFY Button */
|
||||
static void on_button203_clicked(GtkButton *button, gpointer user_data)
|
||||
{
|
||||
add_message("sorry, not implemented yet\n");
|
||||
char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filechooserbutton201));
|
||||
|
||||
int filesize;
|
||||
char *filedata = load_file(filename, &filesize);
|
||||
if (filedata != NULL) {
|
||||
int size = i2c_verify_flash(i2c_fd, filedata, filesize, progress_cb);
|
||||
free(filedata);
|
||||
|
||||
char msg_buf[64];
|
||||
snprintf(msg_buf, sizeof(msg_buf), "FLASH: %d bytes verified\n", size);
|
||||
add_message(msg_buf);
|
||||
}
|
||||
}
|
||||
|
||||
/* FLASH-CLEAR Button */
|
||||
|
28
i2c.c
28
i2c.c
@ -201,7 +201,7 @@ void i2c_cmd_setparameters(int fd, struct blmc_parameter *blmc, int persistent)
|
||||
write(fd, cmd, sizeof(struct blmc_parameter) + (persistent ? 1 : -1));
|
||||
}
|
||||
|
||||
int i2c_write_flash_buf(int fd, char *data, int size, void (*progress_cb)(int pos, int size))
|
||||
int i2c_write_flash(int fd, char *data, int size, void (*progress_cb)(int pos, int size))
|
||||
{
|
||||
int pos = 0;
|
||||
while (pos < size) {
|
||||
@ -227,7 +227,7 @@ int i2c_write_flash_buf(int fd, char *data, int size, void (*progress_cb)(int po
|
||||
return pos;
|
||||
}
|
||||
|
||||
int i2c_read_flash_buf(int fd, char *data, int size, void (*progress_cb)(int pos, int size))
|
||||
int i2c_read_flash(int fd, char *data, int size, void (*progress_cb)(int pos, int size))
|
||||
{
|
||||
int pos = 0;
|
||||
while (pos < size) {
|
||||
@ -249,7 +249,7 @@ int i2c_read_flash_buf(int fd, char *data, int size, void (*progress_cb)(int pos
|
||||
return pos;
|
||||
}
|
||||
|
||||
int i2c_verify_flash_buf(int fd, char *data, int size, void (*progress_cb)(int pos, int size))
|
||||
int i2c_verify_flash(int fd, char *data, int size, void (*progress_cb)(int pos, int size))
|
||||
{
|
||||
int pos = 0;
|
||||
while (pos < size) {
|
||||
@ -275,28 +275,6 @@ int i2c_verify_flash_buf(int fd, char *data, int size, void (*progress_cb)(int p
|
||||
return pos;
|
||||
}
|
||||
|
||||
int i2c_write_flash(int fd, const char *filename, void (*progress_cb)(int pos, int size))
|
||||
{
|
||||
int fd_file = open(filename, O_RDONLY);
|
||||
if (fd_file < 0) {
|
||||
perror("open()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct stat statbuf;
|
||||
if (fstat(fd_file, &statbuf) == -1) {
|
||||
perror("stat()");
|
||||
close(fd_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *data = malloc(statbuf.st_size);
|
||||
if (data == NULL)
|
||||
return -1;
|
||||
|
||||
return i2c_write_flash_buf(fd, data, statbuf.st_size, progress_cb);
|
||||
}
|
||||
|
||||
void i2c_cmd_setpwm(int fd, int pwm)
|
||||
{
|
||||
char cmd[] = { CMD_SET_PWM, pwm };
|
||||
|
8
i2c.h
8
i2c.h
@ -37,11 +37,9 @@ struct blmc_parameter {
|
||||
void i2c_cmd_getparameters(int fd, struct blmc_parameter *blmc);
|
||||
void i2c_cmd_setparameters(int fd, struct blmc_parameter *blmc, int persistent);
|
||||
|
||||
int i2c_write_flash(int fd, const char *filename, void (*progress_cb)(int pos, int size));
|
||||
|
||||
int i2c_write_flash_buf(int fd, char *data, int size, void (*progress_cb)(int pos, int size));
|
||||
int i2c_read_flash_buf(int fd, char *data, int size, void (*progress_cb)(int pos, int size));
|
||||
int i2c_verify_flash_buf(int fd, char *data, int size, void (*progress_cb)(int pos, int size));
|
||||
int i2c_write_flash(int fd, char *data, int size, void (*progress_cb)(int pos, int size));
|
||||
int i2c_read_flash(int fd, char *data, int size, void (*progress_cb)(int pos, int size));
|
||||
int i2c_verify_flash(int fd, char *data, int size, void (*progress_cb)(int pos, int size));
|
||||
|
||||
void i2c_cmd_setpwm(int fd, int pwm);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user