Skip to content

Commit

Permalink
New functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Marisa-Chan committed May 2, 2012
1 parent 1d8b22e commit 403fb5d
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 55 deletions.
2 changes: 1 addition & 1 deletion a4_tool/a4_tool.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<CodeBlocks_layout_file>
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="1" tabpos="1">
<Cursor position="2024" topLine="85" />
<Cursor position="3861" topLine="163" />
</File>
</CodeBlocks_layout_file>
144 changes: 144 additions & 0 deletions a4_tool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ int channel_func(a4_device *dev, int argc, char *argv[]);
int distance_func(a4_device *dev, int argc, char *argv[]);
int wake_func(a4_device *dev, int argc, char *argv[]);
int mrr_func(a4_device *dev, int argc, char *argv[]);
int bat_func(a4_device *dev, int argc, char *argv[]);
int sig_func(a4_device *dev, int argc, char *argv[]);
int prof_func(a4_device *dev, int argc, char *argv[]);
int dump_func(a4_device *dev, int argc, char *argv[]);


struct funcs
Expand Down Expand Up @@ -60,6 +64,30 @@ static funcs functions[] =
NULL,
mrr_func
},
{
"profile",
"get | set (1 | 2 |3 |4 | 5)",
NULL,
prof_func
},
{
"bat",
"",
NULL,
bat_func
},
{
"siglevel",
"",
NULL,
sig_func
},
{
"dump",
"file",
NULL,
dump_func
},
{
NULL,
NULL,
Expand All @@ -68,6 +96,122 @@ static funcs functions[] =
}
};

int prof_func(a4_device *dev, int argc, char *argv[])
{
if (argc > 0)
{
if (strcmp(argv[0],"get") == 0)
{
int prof = a4_profile_get(dev);

if (prof == A4_ERROR)
{
fprintf(stderr, "IO Error\n");
return EXIT_FAILURE;
}

printf("Current profile: %d\n", prof+1);
}
else if (strcmp(argv[0],"set") == 0)
{
if (argc < 2)
{
fprintf(stderr, "No profile number specified\n");
return EXIT_FAILURE;
}

int prof = 0;

prof = -1;
sscanf(argv[1],"%d",&prof);

prof--;


if (prof < 0 || prof > 4)
{
fprintf(stderr, "Invalid profile number \"%s\"\n", argv[1]);
return EXIT_FAILURE;
}

printf("Setting profile to %d...\n",prof+1);

usleep(LITLE_SLEEP);

if (a4_profile_set(dev, prof) == A4_SUCCESS)
printf("Success.\n");
else
{
fprintf(stderr, "IO Error\n");
return EXIT_FAILURE;
}
}
else
{
fprintf(stderr, "Unknown option \"%s\"\n",argv[0]);
return EXIT_FAILURE;
}
}
else
{
fprintf(stderr, "No options specified\n");
return EXIT_FAILURE;
}

return 0;
}

int sig_func(a4_device *dev, int argc, char *argv[])
{
printf("Signal level: %d%%\n", (int)((255.0 - (float)a4_rf_get_signal_level(dev)) / 2.55) );

return 0;
}

int last = -1;

void progress_print(int prog)
{
if (((prog % 10) == 0) && (prog != last))
{
last = prog;
printf("%d %%\n",prog);
}
}

int dump_func(a4_device *dev, int argc, char *argv[])
{
if (argc > 0)
{
if(a4_dump(dev,argv[0],progress_print) == A4_SUCCESS)
printf("Success\n");
else
printf("Fail\n");
}
else
{
fprintf(stderr, "No file specified\n");
return EXIT_FAILURE;
}

return 0;
}

int bat_func(a4_device *dev, int argc, char *argv[])
{
if (a4_device_mouse_count(dev) > 0)
printf("Mouse bat: %d%%\n",a4_power_mouse_get(dev));
else
printf("No mouses found.\n");

if (a4_device_keybd_count(dev) > 0)
printf("Keyboard bat: %d%%\n",a4_power_keybd_get(dev));
else
printf("No keyboards found.\n");

return 0;
}


int mrr_func(a4_device *dev, int argc, char *argv[])
{
Expand Down
2 changes: 1 addition & 1 deletion include/dips.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef DIPS_H_INCLUDED
#define DIPS_H_INCLUDED
uint16_t get_dpi(int8_t dpi_w, int8_t dpi_h);
unsigned short get_dpi(int dpi_w, int dpi_h);


#endif // DIPS_H_INCLUDED
2 changes: 1 addition & 1 deletion include/mouse_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ int a4_mem_mov_word(a4_device *dev, unsigned short addr);
int a4_mem_write_word(a4_device *dev, unsigned short offset, unsigned short word);
unsigned short a4_mem_read_word(a4_device *dev, unsigned short addr);
int a4_mem_read_block(a4_device *dev, unsigned short addr, unsigned short word_sz, void *buf,void (*progress)(int));
int a4_mem_write_block(a4_device *dev, unsigned short addr, unsigned short words_sz, void *inbuf);
int a4_mem_write_block(a4_device *dev, unsigned short addr, unsigned short words_sz, void *inbuf, void (*progress)(int));

#endif // MOUSE_MEMORY_H_INCLUDED
8 changes: 6 additions & 2 deletions include/system_a4.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ void a4_close_device(a4_device *dev);

int a4_dongle_read(a4_device *dev, unsigned short address, unsigned short pin, void *buffer, int bf_size);
int a4_dongle_write(a4_device *dev, unsigned short addr_pin, unsigned short word);
int a4_dump(a4_device *dev, const char *file);
int a4_dump(a4_device *dev, const char *file, void (*progress)(int));

int a4_device_number(a4_device *dev);
int a4_device_number(a4_device *dev);

int a4_id_check(unsigned int id);
int a4_device_keybd_count(a4_device *dev);
int a4_device_mouse_count(a4_device *dev);

#endif // SYSTEM_A4_H_INCLUDED
38 changes: 10 additions & 28 deletions libgmouse/control_a4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,20 +332,11 @@ int a4_power_mouse_get(a4_device *dev)
{
switch (ret[7])
{
case 0x32:
case 0x33:
case 0x34:
case 0x35:
case 0x36:
case 0x37:
case 0x38:
case 0x39:
case 0x3A:
case 0x3B:
case 0x3C:
case 0x3D:
case 0x3E:
case 0x3F:
case 0x32: case 0x33: case 0x34:
case 0x35: case 0x36: case 0x37:
case 0x38: case 0x39: case 0x3A:
case 0x3B: case 0x3C: case 0x3D:
case 0x3E: case 0x3F:
return 100;
case 0x31:
return 90;
Expand Down Expand Up @@ -424,20 +415,11 @@ int a4_power_keybd_get(a4_device *dev)
{
switch (ret[6])
{
case 0x32:
case 0x33:
case 0x34:
case 0x35:
case 0x36:
case 0x37:
case 0x38:
case 0x39:
case 0x3A:
case 0x3B:
case 0x3C:
case 0x3D:
case 0x3E:
case 0x3F:
case 0x32: case 0x33: case 0x34:
case 0x35: case 0x36: case 0x37:
case 0x38: case 0x39: case 0x3A:
case 0x3B: case 0x3C: case 0x3D:
case 0x3E: case 0x3F:
return 100;
case 0x31:
return 90;
Expand Down
10 changes: 7 additions & 3 deletions libgmouse/libgmouse.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<CodeBlocks_layout_file>
<ActiveTarget name="Release" />
<File name="control_a4.cpp" open="1" top="1" tabpos="1">
<<<<<<< HEAD
<Cursor position="7103" topLine="318" />
=======
<Cursor position="4023" topLine="155" />
>>>>>>> 1d8b22e81fd60da9da176008a0e43c8c46e06fc3
</File>
<File name="control_a4.h" open="1" top="0" tabpos="7">
<Cursor position="512" topLine="15" />
Expand All @@ -14,7 +18,7 @@
<Cursor position="1" topLine="18" />
</File>
<File name="mouse_memory.cpp" open="1" top="0" tabpos="3">
<Cursor position="1612" topLine="52" />
<Cursor position="3244" topLine="124" />
</File>
<File name="pairing.cpp" open="1" top="0" tabpos="4">
<Cursor position="770" topLine="9" />
Expand All @@ -23,9 +27,9 @@
<Cursor position="1420" topLine="0" />
</File>
<File name="system_a4.cpp" open="1" top="0" tabpos="5">
<Cursor position="2779" topLine="122" />
<Cursor position="2725" topLine="100" />
</File>
<File name="system_a4.h" open="1" top="0" tabpos="8">
<Cursor position="584" topLine="0" />
<Cursor position="568" topLine="0" />
</File>
</CodeBlocks_layout_file>
28 changes: 27 additions & 1 deletion libgmouse/mouse_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,22 @@ int a4_mem_read_block(a4_device *dev, unsigned short addr, unsigned short words_
int big = words_sz / 4;
int small = words_sz % 4;

float pone = 1.0;
if (big > 0)
pone = 100.0 / big;

float ptwo = 0;

for(int i = 0; i < big; i++)
{
int res = a4_dongle_read(dev, 0xB501, addr + (i*4), sbuf + (i*4), 8);

if (res != 8)
return A4_ERROR;

ptwo += pone;
if (progress != NULL)
progress(ptwo);
}

for(int i = 0; i < small; i++)
Expand All @@ -107,10 +117,13 @@ int a4_mem_read_block(a4_device *dev, unsigned short addr, unsigned short words_
return A4_ERROR;
}

if ( progress != NULL)
progress(100);

return A4_SUCCESS;
}

int a4_mem_write_block(a4_device *dev, unsigned short addr, unsigned short words_sz, void *inbuf)
int a4_mem_write_block(a4_device *dev, unsigned short addr, unsigned short words_sz, void *inbuf, void (*progress)(int))
{
if (!dev)
return A4_ERROR;
Expand All @@ -123,11 +136,19 @@ int a4_mem_write_block(a4_device *dev, unsigned short addr, unsigned short words

int error = A4_SUCCESS;

float pone = 1.0;
if (to_write > 0)
pone = 100.0 / to_write;

float ptwo = 0;

for (int i=0; i < to_write && error == A4_SUCCESS; i++)
{
unsigned int k = i;
if ((k & 0xFFFFFF80) == k)
{
if ( progress != NULL)
progress(ptwo);
//printf("set page 0x%x\n",addr + i);
error = a4_mem_erase_block(dev,addr + k);
}
Expand All @@ -142,7 +163,12 @@ int a4_mem_write_block(a4_device *dev, unsigned short addr, unsigned short words
//printf("mouse_move_block to 0x%x\n",((addr + i) & 0xFFFFFFE0) | 0x8000 );
error = a4_mem_mov_block(dev, ((addr + i) & 0xFFFFFFE0) | 0x8000 );
}

ptwo += pone;
}

if ( progress != NULL)
progress(100);

return error;
}
2 changes: 1 addition & 1 deletion libgmouse/mouse_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ int a4_mem_mov_word(a4_device *dev, unsigned short addr);
int a4_mem_write_word(a4_device *dev, unsigned short offset, unsigned short word);
unsigned short a4_mem_read_word(a4_device *dev, unsigned short addr);
int a4_mem_read_block(a4_device *dev, unsigned short addr, unsigned short word_sz, void *buf,void (*progress)(int));
int a4_mem_write_block(a4_device *dev, unsigned short addr, unsigned short words_sz, void *inbuf);
int a4_mem_write_block(a4_device *dev, unsigned short addr, unsigned short words_sz, void *inbuf, void (*progress)(int));

#endif // MOUSE_MEMORY_H_INCLUDED
Loading

0 comments on commit 403fb5d

Please sign in to comment.