This commit is contained in:
Jean LE QUELLEC 2022-11-19 13:46:26 +01:00
parent 17cb7533cb
commit fae17d2eb9
17 changed files with 161 additions and 100 deletions

View file

@ -1,9 +1,10 @@
# flipperzero-i2ctools # flipperzero-i2ctools
[Original link](https://github.com/NaejEL/flipperzero-i2ctools) [Original link](https://github.com/NaejEL/flipperzero-i2ctools)
Set of i2c tools for Flipper Zero Set of i2c tools for Flipper Zero
![Preview](i2ctools.gif)
## Wiring ## Wiring
C0 -> SCL C0 -> SCL
@ -28,18 +29,16 @@ Spy i2c traffic
Send command to i2c peripherals and read result Send command to i2c peripherals and read result
### Player
> Not implemented yet
Send command from file
## TODO ## TODO
- [ ] Read more than 2 bytes in sender mode - [ ] Read more than 2 bytes in sender mode
- [ ] Add 10-bits adresses support
- [ ] Test with rate > 100khz
- [ ] Save records - [ ] Save records
- [ ] Play from files - [ ] Play from files
- [ ] Kicad module - [ ] Kicad module
- [ ] Improve UI - [ ] Improve UI
- [ ] Refactor Menu Management Code - [ ] Refactor Event Management Code
- [ ] Add Documentation - [ ] Add Documentation
- [ ] Remove max data size
- [ ] Remove max frames read size

View file

@ -86,6 +86,8 @@ void SCLcallback(void* _i2c_sniffer) {
i2cSniffer* i2c_sniffer_alloc() { i2cSniffer* i2c_sniffer_alloc() {
i2cSniffer* i2c_sniffer = malloc(sizeof(i2cSniffer)); i2cSniffer* i2c_sniffer = malloc(sizeof(i2cSniffer));
i2c_sniffer->started = false; i2c_sniffer->started = false;
i2c_sniffer->row_index = 0;
i2c_sniffer->menu_index = 0;
clear_sniffer_buffers(i2c_sniffer); clear_sniffer_buffers(i2c_sniffer);
return i2c_sniffer; return i2c_sniffer;
} }

View file

@ -33,6 +33,7 @@ typedef struct {
i2cFrame frames[MAX_RECORDS]; i2cFrame frames[MAX_RECORDS];
uint8_t frame_index; uint8_t frame_index;
uint8_t menu_index; uint8_t menu_index;
uint8_t row_index;
} i2cSniffer; } i2cSniffer;
void clear_sniffer_buffers(i2cSniffer* i2c_sniffer); void clear_sniffer_buffers(i2cSniffer* i2c_sniffer);

View file

@ -68,6 +68,7 @@ int32_t i2ctools_app(void* p) {
i2ctools->sender->scanner = i2ctools->scanner; i2ctools->sender->scanner = i2ctools->scanner;
while(furi_message_queue_get(event_queue, &event, FuriWaitForever) == FuriStatusOk) { while(furi_message_queue_get(event_queue, &event, FuriWaitForever) == FuriStatusOk) {
// Back
if(event.key == InputKeyBack && event.type == InputTypeRelease) { if(event.key == InputKeyBack && event.type == InputTypeRelease) {
if(i2ctools->main_view->current_view == MAIN_VIEW) { if(i2ctools->main_view->current_view == MAIN_VIEW) {
break; break;
@ -79,7 +80,9 @@ int32_t i2ctools_app(void* p) {
} }
i2ctools->main_view->current_view = MAIN_VIEW; i2ctools->main_view->current_view = MAIN_VIEW;
} }
} else if(event.key == InputKeyUp && event.type == InputTypeRelease) { }
// Up
else if(event.key == InputKeyUp && event.type == InputTypeRelease) {
if(i2ctools->main_view->current_view == MAIN_VIEW) { if(i2ctools->main_view->current_view == MAIN_VIEW) {
if((i2ctools->main_view->menu_index > SCAN_VIEW)) { if((i2ctools->main_view->menu_index > SCAN_VIEW)) {
i2ctools->main_view->menu_index--; i2ctools->main_view->menu_index--;
@ -88,41 +91,76 @@ int32_t i2ctools_app(void* p) {
if(i2ctools->scanner->menu_index > 0) { if(i2ctools->scanner->menu_index > 0) {
i2ctools->scanner->menu_index--; i2ctools->scanner->menu_index--;
} }
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
if(i2ctools->sniffer->row_index > 0) {
i2ctools->sniffer->row_index--;
}
} else if(i2ctools->main_view->current_view == SEND_VIEW) { } else if(i2ctools->main_view->current_view == SEND_VIEW) {
if(i2ctools->sender->value < 0xFF) { if(i2ctools->sender->value < 0xFF) {
i2ctools->sender->value++; i2ctools->sender->value++;
i2ctools->sender->sended = false; i2ctools->sender->sended = false;
} }
} }
} else if( }
// Long Up
else if(
event.key == InputKeyUp && event.key == InputKeyUp &&
(event.type == InputTypeLong || event.type == InputTypeRepeat)) { (event.type == InputTypeLong || event.type == InputTypeRepeat)) {
if(i2ctools->main_view->current_view == SEND_VIEW) { if(i2ctools->main_view->current_view == SCAN_VIEW) {
if(i2ctools->scanner->menu_index > 5) {
i2ctools->scanner->menu_index -= 5;
}
} else if(i2ctools->main_view->current_view == SEND_VIEW) {
if(i2ctools->sender->value < 0xF9) { if(i2ctools->sender->value < 0xF9) {
i2ctools->sender->value += 5; i2ctools->sender->value += 5;
i2ctools->sender->sended = false; i2ctools->sender->sended = false;
} }
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
if(i2ctools->sniffer->row_index > 5) {
i2ctools->sniffer->row_index -= 5;
} else {
i2ctools->sniffer->row_index = 0;
} }
} else if(event.key == InputKeyDown && event.type == InputTypeRelease) { }
}
// Down
else if(event.key == InputKeyDown && event.type == InputTypeRelease) {
if(i2ctools->main_view->current_view == MAIN_VIEW) { if(i2ctools->main_view->current_view == MAIN_VIEW) {
if(i2ctools->main_view->menu_index < 3) { if(i2ctools->main_view->menu_index < MENU_SIZE - 1) {
i2ctools->main_view->menu_index++; i2ctools->main_view->menu_index++;
} }
} else if(i2ctools->main_view->current_view == SCAN_VIEW) { } else if(i2ctools->main_view->current_view == SCAN_VIEW) {
if(i2ctools->scanner->menu_index < ((int)i2ctools->scanner->nb_found / 3)) { if(i2ctools->scanner->menu_index < ((int)i2ctools->scanner->nb_found / 3)) {
i2ctools->scanner->menu_index++; i2ctools->scanner->menu_index++;
} }
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
if((i2ctools->sniffer->row_index + 3) <
(int)i2ctools->sniffer->frames[i2ctools->sniffer->menu_index].data_index) {
i2ctools->sniffer->row_index++;
}
} else if(i2ctools->main_view->current_view == SEND_VIEW) { } else if(i2ctools->main_view->current_view == SEND_VIEW) {
if(i2ctools->sender->value > 0x00) { if(i2ctools->sender->value > 0x00) {
i2ctools->sender->value--; i2ctools->sender->value--;
i2ctools->sender->sended = false; i2ctools->sender->sended = false;
} }
} }
} else if(event.key == InputKeyDown && event.type == InputTypeLong) { }
// Long Down
else if(
event.key == InputKeyDown &&
(event.type == InputTypeLong || event.type == InputTypeRepeat)) {
if(i2ctools->main_view->current_view == SEND_VIEW) { if(i2ctools->main_view->current_view == SEND_VIEW) {
if(i2ctools->sender->value > 0x05) { if(i2ctools->sender->value > 0x05) {
i2ctools->sender->value -= 5; i2ctools->sender->value -= 5;
i2ctools->sender->sended = false; i2ctools->sender->sended = false;
} else {
i2ctools->sender->value = 0;
i2ctools->sender->sended = false;
}
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
if((i2ctools->sniffer->row_index + 8) <
(int)i2ctools->sniffer->frames[i2ctools->sniffer->menu_index].data_index) {
i2ctools->sniffer->row_index += 5;
} }
} }
@ -153,6 +191,7 @@ int32_t i2ctools_app(void* p) {
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) { } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
if(i2ctools->sniffer->menu_index < i2ctools->sniffer->frame_index) { if(i2ctools->sniffer->menu_index < i2ctools->sniffer->frame_index) {
i2ctools->sniffer->menu_index++; i2ctools->sniffer->menu_index++;
i2ctools->sniffer->row_index = 0;
} }
} }
} else if(event.key == InputKeyLeft && event.type == InputTypeRelease) { } else if(event.key == InputKeyLeft && event.type == InputTypeRelease) {
@ -164,6 +203,7 @@ int32_t i2ctools_app(void* p) {
} else if(i2ctools->main_view->current_view == SNIFF_VIEW) { } else if(i2ctools->main_view->current_view == SNIFF_VIEW) {
if(i2ctools->sniffer->menu_index > 0) { if(i2ctools->sniffer->menu_index > 0) {
i2ctools->sniffer->menu_index--; i2ctools->sniffer->menu_index--;
i2ctools->sniffer->row_index = 0;
} }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -4,9 +4,8 @@ void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
canvas_clear(canvas); canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
canvas_draw_rframe(canvas, 0, 0, 128, 64, 3); canvas_draw_rframe(canvas, 0, 0, 128, 64, 3);
canvas_draw_icon(canvas, 2, 13, &I_passport_bad3_46x49); canvas_draw_icon(canvas, 2, 2, &I_i2ctools_main_76x59);
canvas_set_font(canvas, FontPrimary); canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, APP_NAME);
switch(main_view->menu_index) { switch(main_view->menu_index) {
case SCAN_VIEW: case SCAN_VIEW:
@ -15,7 +14,7 @@ void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT); canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
canvas_draw_str_aligned( canvas_draw_str_aligned(
canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT); canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
canvas_draw_rbox(canvas, 60, SCAN_MENU_Y - 2, 60, 13, 3); canvas_draw_rbox(canvas, 80, SCAN_MENU_Y - 2, 43, 13, 3);
canvas_set_color(canvas, ColorWhite); canvas_set_color(canvas, ColorWhite);
canvas_draw_str_aligned( canvas_draw_str_aligned(
canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT); canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
@ -27,7 +26,7 @@ void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT); canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
canvas_draw_str_aligned( canvas_draw_str_aligned(
canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT); canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
canvas_draw_rbox(canvas, 60, SNIFF_MENU_Y - 2, 60, 13, 3); canvas_draw_rbox(canvas, 80, SNIFF_MENU_Y - 2, 43, 13, 3);
canvas_set_color(canvas, ColorWhite); canvas_set_color(canvas, ColorWhite);
canvas_draw_str_aligned( canvas_draw_str_aligned(
canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT); canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
@ -39,7 +38,7 @@ void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT); canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
canvas_draw_str_aligned( canvas_draw_str_aligned(
canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT); canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
canvas_draw_rbox(canvas, 60, SEND_MENU_Y - 2, 60, 13, 3); canvas_draw_rbox(canvas, 80, SEND_MENU_Y - 2, 43, 13, 3);
canvas_set_color(canvas, ColorWhite); canvas_set_color(canvas, ColorWhite);
canvas_draw_str_aligned( canvas_draw_str_aligned(
canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT); canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);

View file

@ -5,16 +5,16 @@
#define APP_NAME "I2C Tools" #define APP_NAME "I2C Tools"
#define SCAN_MENU_TEXT "Scan" #define SCAN_MENU_TEXT "Scan"
#define SCAN_MENU_X 75 #define SCAN_MENU_X 90
#define SCAN_MENU_Y 6 #define SCAN_MENU_Y 13
#define SNIFF_MENU_TEXT "Sniff" #define SNIFF_MENU_TEXT "Sniff"
#define SNIFF_MENU_X 75 #define SNIFF_MENU_X 90
#define SNIFF_MENU_Y 20 #define SNIFF_MENU_Y 27
#define SEND_MENU_TEXT "Send" #define SEND_MENU_TEXT "Send"
#define SEND_MENU_X 75 #define SEND_MENU_X 90
#define SEND_MENU_Y 34 #define SEND_MENU_Y 41
// Menu // Menu
typedef enum { typedef enum {

View file

@ -4,15 +4,12 @@ void draw_scanner_view(Canvas* canvas, i2cScanner* i2c_scanner) {
canvas_clear(canvas); canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
canvas_draw_rframe(canvas, 0, 0, 128, 64, 3); canvas_draw_rframe(canvas, 0, 0, 128, 64, 3);
canvas_draw_icon(canvas, 2, 13, &I_passport_happy3_46x49);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, SCAN_MENU_TEXT);
char count_text[46]; char count_text[46];
char count_text_fmt[] = "Found: %d"; char count_text_fmt[] = "Peripherals Found: %d";
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
snprintf(count_text, sizeof(count_text), count_text_fmt, (int)i2c_scanner->nb_found); snprintf(count_text, sizeof(count_text), count_text_fmt, (int)i2c_scanner->nb_found);
canvas_draw_str_aligned(canvas, 50, 3, AlignLeft, AlignTop, count_text); canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, count_text);
uint8_t x_pos = 0; uint8_t x_pos = 0;
uint8_t y_pos = 0; uint8_t y_pos = 0;
uint8_t idx_to_print = 0; uint8_t idx_to_print = 0;
@ -23,21 +20,16 @@ void draw_scanner_view(Canvas* canvas, i2cScanner* i2c_scanner) {
} }
snprintf( snprintf(
count_text, sizeof(count_text), "0x%02x ", (int)i2c_scanner->addresses[idx_to_print]); count_text, sizeof(count_text), "0x%02x ", (int)i2c_scanner->addresses[idx_to_print]);
if(i < 3) { const uint8_t x_start = 3;
x_pos = 50 + (i * 26); if(i < 4) {
x_pos = x_start + (i * 26);
y_pos = 15; y_pos = 15;
} else if(i < 6) { } else if(i < 8) {
x_pos = 50 + ((i - 3) * 26); x_pos = x_start + ((i - 4) * 26);
y_pos = 25; y_pos = 25;
} else if(i < 9) {
x_pos = 50 + ((i - 6) * 26);
y_pos = 35;
} else if(i < 12) { } else if(i < 12) {
x_pos = 50 + ((i - 9) * 26); x_pos = x_start + ((i - 8) * 26);
y_pos = 45; y_pos = 35;
} else if(i < 15) {
x_pos = 50 + ((i - 12) * 26);
y_pos = 55;
} else { } else {
break; break;
} }
@ -48,8 +40,8 @@ void draw_scanner_view(Canvas* canvas, i2cScanner* i2c_scanner) {
canvas_draw_rbox(canvas, 125, y_pos, 3, 10, 1); canvas_draw_rbox(canvas, 125, y_pos, 3, 10, 1);
// Button // Button
canvas_draw_rbox(canvas, 70, 48, 45, 13, 3); canvas_draw_rbox(canvas, 45, 48, 45, 13, 3);
canvas_set_color(canvas, ColorWhite); canvas_set_color(canvas, ColorWhite);
canvas_draw_icon(canvas, 75, 50, &I_Ok_btn_9x9); canvas_draw_icon(canvas, 50, 50, &I_Ok_btn_9x9);
canvas_draw_str_aligned(canvas, 85, 51, AlignLeft, AlignTop, "Scan"); canvas_draw_str_aligned(canvas, 62, 51, AlignLeft, AlignTop, "Scan");
} }

View file

@ -4,8 +4,6 @@
#include <i2cTools_icons.h> #include <i2cTools_icons.h>
#include "../i2cscanner.h" #include "../i2cscanner.h"
#define SCAN_MENU_TEXT "Scan" #define SCAN_TEXT "SCAN"
#define SCAN_MENU_X 75
#define SCAN_MENU_Y 6
void draw_scanner_view(Canvas* canvas, i2cScanner* i2c_scanner); void draw_scanner_view(Canvas* canvas, i2cScanner* i2c_scanner);

View file

@ -4,9 +4,6 @@ void draw_sender_view(Canvas* canvas, i2cSender* i2c_sender) {
canvas_clear(canvas); canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
canvas_draw_rframe(canvas, 0, 0, 128, 64, 3); canvas_draw_rframe(canvas, 0, 0, 128, 64, 3);
canvas_draw_icon(canvas, 2, 13, &I_passport_happy2_46x49);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, SEND_MENU_TEXT);
if(!i2c_sender->scanner->scanned) { if(!i2c_sender->scanner->scanned) {
scan_i2c_bus(i2c_sender->scanner); scan_i2c_bus(i2c_sender->scanner);
@ -14,39 +11,60 @@ void draw_sender_view(Canvas* canvas, i2cSender* i2c_sender) {
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
if(i2c_sender->scanner->nb_found <= 0) { if(i2c_sender->scanner->nb_found <= 0) {
canvas_draw_str_aligned(canvas, 60, 5, AlignLeft, AlignTop, "No peripherals"); canvas_draw_str_aligned(canvas, 20, 5, AlignLeft, AlignTop, "No peripherals found");
canvas_draw_str_aligned(canvas, 60, 15, AlignLeft, AlignTop, "Found");
return; return;
} }
canvas_draw_rbox(canvas, 70, 48, 45, 13, 3); // Send Button
canvas_draw_rbox(canvas, 45, 48, 45, 13, 3);
canvas_set_color(canvas, ColorWhite); canvas_set_color(canvas, ColorWhite);
canvas_draw_icon(canvas, 75, 50, &I_Ok_btn_9x9); canvas_draw_icon(canvas, 50, 50, &I_Ok_btn_9x9);
canvas_draw_str_aligned(canvas, 85, 51, AlignLeft, AlignTop, "Send"); canvas_draw_str_aligned(canvas, 62, 51, AlignLeft, AlignTop, "Send");
// Addr
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
canvas_draw_str_aligned(canvas, 50, 5, AlignLeft, AlignTop, "Addr: "); canvas_draw_str_aligned(canvas, 3, 5, AlignLeft, AlignTop, "Addr: ");
canvas_draw_icon(canvas, 80, 5, &I_ButtonLeft_4x7); canvas_draw_icon(canvas, 33, 5, &I_ButtonLeft_4x7);
canvas_draw_icon(canvas, 115, 5, &I_ButtonRight_4x7); canvas_draw_icon(canvas, 68, 5, &I_ButtonRight_4x7);
char addr_text[8]; char addr_text[8];
snprintf( snprintf(
addr_text, addr_text,
sizeof(addr_text), sizeof(addr_text),
"0x%02x", "0x%02x",
(int)i2c_sender->scanner->addresses[i2c_sender->address_idx]); (int)i2c_sender->scanner->addresses[i2c_sender->address_idx]);
canvas_draw_str_aligned(canvas, 90, 5, AlignLeft, AlignTop, addr_text); canvas_draw_str_aligned(canvas, 43, 5, AlignLeft, AlignTop, addr_text);
canvas_draw_str_aligned(canvas, 50, 15, AlignLeft, AlignTop, "Value: "); // Value
canvas_draw_str_aligned(canvas, 3, 15, AlignLeft, AlignTop, "Value: ");
canvas_draw_icon(canvas, 80, 17, &I_ButtonUp_7x4); canvas_draw_icon(canvas, 33, 17, &I_ButtonUp_7x4);
canvas_draw_icon(canvas, 115, 17, &I_ButtonDown_7x4); canvas_draw_icon(canvas, 68, 17, &I_ButtonDown_7x4);
snprintf(addr_text, sizeof(addr_text), "0x%02x", (int)i2c_sender->value); snprintf(addr_text, sizeof(addr_text), "0x%02x", (int)i2c_sender->value);
canvas_draw_str_aligned(canvas, 90, 15, AlignLeft, AlignTop, addr_text); canvas_draw_str_aligned(canvas, 43, 15, AlignLeft, AlignTop, addr_text);
if(i2c_sender->must_send) { if(i2c_sender->must_send) {
i2c_send(i2c_sender); i2c_send(i2c_sender);
} }
canvas_draw_str_aligned(canvas, 50, 25, AlignLeft, AlignTop, "Result: "); // Result
canvas_draw_str_aligned(canvas, 3, 25, AlignLeft, AlignTop, "Result: ");
if(i2c_sender->sended) { if(i2c_sender->sended) {
uint8_t row = 1;
uint8_t column = 1;
const uint8_t x_min = 3;
const uint8_t y_min = 25;
uint8_t x_pos = 0;
uint8_t y_pos = 0;
for(uint8_t i = 0; i < sizeof(i2c_sender->recv); i++) { for(uint8_t i = 0; i < sizeof(i2c_sender->recv); i++) {
x_pos = x_min + (column - 1) * 35;
if(row == 1) {
x_pos += 40;
}
y_pos = y_min + (row - 1) * 10;
snprintf(addr_text, sizeof(addr_text), "0x%02x", (int)i2c_sender->recv[i]); snprintf(addr_text, sizeof(addr_text), "0x%02x", (int)i2c_sender->recv[i]);
canvas_draw_str_aligned(canvas, 90, 25 + (i * 10), AlignLeft, AlignTop, addr_text); canvas_draw_str_aligned(canvas, x_pos, y_pos, AlignLeft, AlignTop, addr_text);
column++;
if((row > 1 && column > 3) || (row == 1 && column > 2)) {
column = 1;
row++;
}
if(row > 2) {
break;
}
} }
} }
} }

View file

@ -4,8 +4,6 @@
#include <i2cTools_icons.h> #include <i2cTools_icons.h>
#include "../i2csender.h" #include "../i2csender.h"
#define SEND_MENU_TEXT "Send" #define SEND_TEXT "SEND"
#define SEND_MENU_X 75
#define SEND_MENU_Y 34
void draw_sender_view(Canvas* canvas, i2cSender* i2c_sender); void draw_sender_view(Canvas* canvas, i2cSender* i2c_sender);

View file

@ -4,73 +4,89 @@ void draw_sniffer_view(Canvas* canvas, i2cSniffer* i2c_sniffer) {
canvas_clear(canvas); canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
canvas_draw_rframe(canvas, 0, 0, 128, 64, 3); canvas_draw_rframe(canvas, 0, 0, 128, 64, 3);
canvas_draw_icon(canvas, 2, 13, &I_passport_happy2_46x49);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
// Button // Button
canvas_draw_rbox(canvas, 70, 48, 45, 13, 3); canvas_draw_rbox(canvas, 40, 48, 45, 13, 3);
canvas_set_color(canvas, ColorWhite); canvas_set_color(canvas, ColorWhite);
canvas_draw_icon(canvas, 75, 50, &I_Ok_btn_9x9); canvas_draw_icon(canvas, 45, 50, &I_Ok_btn_9x9);
if(!i2c_sniffer->started) { if(!i2c_sniffer->started) {
canvas_draw_str_aligned(canvas, 85, 51, AlignLeft, AlignTop, "Start"); canvas_draw_str_aligned(canvas, 57, 51, AlignLeft, AlignTop, "Start");
} else { } else {
canvas_draw_str_aligned(canvas, 85, 51, AlignLeft, AlignTop, "Stop"); canvas_draw_str_aligned(canvas, 57, 51, AlignLeft, AlignTop, "Stop");
} }
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
if(i2c_sniffer->first) { if(i2c_sniffer->first) {
canvas_draw_str_aligned(canvas, 50, 3, AlignLeft, AlignTop, "Nothing Recorded"); canvas_draw_str_aligned(canvas, 30, 3, AlignLeft, AlignTop, "Nothing Recorded");
return; return;
} }
char text_buffer[8]; char text_buffer[10];
// nbFrame text // nbFrame text
canvas_draw_str_aligned(canvas, 50, 3, AlignLeft, AlignTop, "Frame: "); canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, "Frame: ");
snprintf(text_buffer, sizeof(text_buffer), "%d", (int)i2c_sniffer->menu_index + 1); snprintf(
canvas_draw_str_aligned(canvas, 85, 3, AlignLeft, AlignTop, text_buffer); text_buffer,
canvas_draw_str_aligned(canvas, 100, 3, AlignLeft, AlignTop, "/"); sizeof(text_buffer),
snprintf(text_buffer, sizeof(text_buffer), "%d", (int)i2c_sniffer->frame_index + 1); "%d/%d",
canvas_draw_str_aligned(canvas, 110, 3, AlignLeft, AlignTop, text_buffer); (int)i2c_sniffer->menu_index + 1,
(int)i2c_sniffer->frame_index + 1);
canvas_draw_str_aligned(canvas, 38, 3, AlignLeft, AlignTop, text_buffer);
// Address text // Address text
snprintf( snprintf(
text_buffer, text_buffer,
sizeof(text_buffer), sizeof(text_buffer),
"0x%02x", "0x%02x",
(int)(i2c_sniffer->frames[i2c_sniffer->menu_index].data[0] >> 1)); (int)(i2c_sniffer->frames[i2c_sniffer->menu_index].data[0] >> 1));
canvas_draw_str_aligned(canvas, 50, 13, AlignLeft, AlignTop, "Addr: "); canvas_draw_str_aligned(canvas, 3, 13, AlignLeft, AlignTop, "Addr: ");
canvas_draw_str_aligned(canvas, 75, 13, AlignLeft, AlignTop, text_buffer); canvas_draw_str_aligned(canvas, 30, 13, AlignLeft, AlignTop, text_buffer);
// R/W // R/W
if((int)(i2c_sniffer->frames[i2c_sniffer->menu_index].data[0]) % 2 == 0) { if((int)(i2c_sniffer->frames[i2c_sniffer->menu_index].data[0]) % 2 == 0) {
canvas_draw_str_aligned(canvas, 105, 13, AlignLeft, AlignTop, "W"); canvas_draw_str_aligned(canvas, 58, 13, AlignLeft, AlignTop, "Write");
} else { } else {
canvas_draw_str_aligned(canvas, 105, 13, AlignLeft, AlignTop, "R"); canvas_draw_str_aligned(canvas, 58, 13, AlignLeft, AlignTop, "Read");
}
// ACK
if(i2c_sniffer->frames[i2c_sniffer->menu_index].ack[0]) {
canvas_draw_str_aligned(canvas, 90, 13, AlignLeft, AlignTop, "ACK");
} else {
canvas_draw_str_aligned(canvas, 90, 13, AlignLeft, AlignTop, "NACK");
} }
// Frames content // Frames content
const uint8_t x_min = 50; const uint8_t x_min = 3;
const uint8_t y_min = 23; const uint8_t y_min = 23;
uint8_t x_pos = 0; uint8_t x_pos = 0;
uint8_t y_pos = 0; uint8_t y_pos = 0;
uint8_t row = 1; uint8_t row = 1;
uint8_t column = 1; uint8_t column = 1;
for(uint8_t i = 1; i < i2c_sniffer->frames[i2c_sniffer->menu_index].data_index; i++) { uint8_t frame_size = i2c_sniffer->frames[i2c_sniffer->menu_index].data_index;
uint8_t offset = i2c_sniffer->row_index;
if(i2c_sniffer->row_index > 0) {
offset += 1;
}
canvas_draw_str_aligned(canvas, x_min, y_min, AlignLeft, AlignTop, "Data:");
for(uint8_t i = 1 + offset; i < frame_size; i++) {
snprintf( snprintf(
text_buffer, text_buffer,
sizeof(text_buffer), sizeof(text_buffer),
"0x%02x", "0x%02x",
(int)i2c_sniffer->frames[i2c_sniffer->menu_index].data[i]); (int)i2c_sniffer->frames[i2c_sniffer->menu_index].data[i]);
x_pos = x_min + (column - 1) * 35; x_pos = x_min + (column - 1) * 35;
y_pos = y_min + (row - 1) * 10; if(row == 1) {
column++; x_pos += 30;
if(column > 2) {
column = 1;
row++;
} }
y_pos = y_min + (row - 1) * 10;
canvas_draw_str_aligned(canvas, x_pos, y_pos, AlignLeft, AlignTop, text_buffer); canvas_draw_str_aligned(canvas, x_pos, y_pos, AlignLeft, AlignTop, text_buffer);
if(i2c_sniffer->frames[i2c_sniffer->menu_index].ack[i]) { if(i2c_sniffer->frames[i2c_sniffer->menu_index].ack[i]) {
canvas_draw_str_aligned(canvas, x_pos + 24, y_pos, AlignLeft, AlignTop, "A"); canvas_draw_str_aligned(canvas, x_pos + 24, y_pos, AlignLeft, AlignTop, "A");
} else { } else {
canvas_draw_str_aligned(canvas, x_pos + 24, y_pos, AlignLeft, AlignTop, "N"); canvas_draw_str_aligned(canvas, x_pos + 24, y_pos, AlignLeft, AlignTop, "N");
} }
column++;
if((row > 1 && column > 3) || (row == 1 && column > 2)) {
column = 1;
row++;
}
if(row > 2) {
break;
}
} }
} }

View file

@ -4,8 +4,6 @@
#include <i2cTools_icons.h> #include <i2cTools_icons.h>
#include "../i2csniffer.h" #include "../i2csniffer.h"
#define SNIFF_MENU_TEXT "Sniff" #define SNIFF_TEXT "SNIFF"
#define SNIFF_MENU_X 75
#define SNIFF_MENU_Y 20
void draw_sniffer_view(Canvas* canvas, i2cSniffer* i2c_sniffer); void draw_sniffer_view(Canvas* canvas, i2cSniffer* i2c_sniffer);