1
1
#include "i2ctools_i.h"
2
2
3
3
void i2ctools_draw_callback (Canvas * canvas , void * ctx ) {
4
+ furi_assert (ctx );
4
5
i2cTools * i2ctools = ctx ;
5
- if (furi_mutex_acquire (i2ctools -> mutex , 200 ) != FuriStatusOk ) {
6
- return ;
7
- }
6
+ furi_mutex_acquire (i2ctools -> mutex , FuriWaitForever );
8
7
9
8
switch (i2ctools -> main_view -> current_view ) {
10
9
case MAIN_VIEW :
@@ -46,6 +45,11 @@ int32_t i2ctools_app(void* p) {
46
45
// Alloc i2ctools
47
46
i2cTools * i2ctools = malloc (sizeof (i2cTools ));
48
47
i2ctools -> mutex = furi_mutex_alloc (FuriMutexTypeNormal );
48
+ if (!i2ctools -> mutex ) {
49
+ FURI_LOG_E (APP_NAME , "cannot create mutex\r\n" );
50
+ free (i2ctools );
51
+ return -1 ;
52
+ }
49
53
50
54
// Alloc viewport
51
55
i2ctools -> view_port = view_port_alloc ();
@@ -69,143 +73,145 @@ int32_t i2ctools_app(void* p) {
69
73
// Share scanner with sender
70
74
i2ctools -> sender -> scanner = i2ctools -> scanner ;
71
75
72
- while (furi_message_queue_get (event_queue , & event , FuriWaitForever ) == FuriStatusOk ) {
73
- // Back
74
- if (event .key == InputKeyBack && event .type == InputTypeRelease ) {
75
- if (i2ctools -> main_view -> current_view == MAIN_VIEW ) {
76
- break ;
77
- } else {
78
- if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
79
- stop_interrupts ();
80
- i2ctools -> sniffer -> started = false;
81
- i2ctools -> sniffer -> state = I2C_BUS_FREE ;
82
- }
83
- i2ctools -> main_view -> current_view = MAIN_VIEW ;
84
- }
85
- }
86
- // Up
87
- else if (event .key == InputKeyUp && event .type == InputTypeRelease ) {
88
- if (i2ctools -> main_view -> current_view == MAIN_VIEW ) {
89
- if ((i2ctools -> main_view -> menu_index > SCAN_VIEW )) {
90
- i2ctools -> main_view -> menu_index -- ;
91
- }
92
- } else if (i2ctools -> main_view -> current_view == SCAN_VIEW ) {
93
- if (i2ctools -> scanner -> menu_index > 0 ) {
94
- i2ctools -> scanner -> menu_index -- ;
95
- }
96
- } else if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
97
- if (i2ctools -> sniffer -> row_index > 0 ) {
98
- i2ctools -> sniffer -> row_index -- ;
99
- }
100
- } else if (i2ctools -> main_view -> current_view == SEND_VIEW ) {
101
- if (i2ctools -> sender -> value < 0xFF ) {
102
- i2ctools -> sender -> value ++ ;
103
- i2ctools -> sender -> sended = false;
104
- }
105
- }
106
- }
107
- // Long Up
108
- else if (
109
- event .key == InputKeyUp &&
110
- (event .type == InputTypeLong || event .type == InputTypeRepeat )) {
111
- if (i2ctools -> main_view -> current_view == SCAN_VIEW ) {
112
- if (i2ctools -> scanner -> menu_index > 5 ) {
113
- i2ctools -> scanner -> menu_index -= 5 ;
114
- }
115
- } else if (i2ctools -> main_view -> current_view == SEND_VIEW ) {
116
- if (i2ctools -> sender -> value < 0xF9 ) {
117
- i2ctools -> sender -> value += 5 ;
118
- i2ctools -> sender -> sended = false;
119
- }
120
- } else if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
121
- if (i2ctools -> sniffer -> row_index > 5 ) {
122
- i2ctools -> sniffer -> row_index -= 5 ;
76
+ while (1 ) {
77
+ if (furi_message_queue_get (event_queue , & event , 100 ) == FuriStatusOk ) {
78
+ // Back
79
+ if (event .key == InputKeyBack && event .type == InputTypeRelease ) {
80
+ if (i2ctools -> main_view -> current_view == MAIN_VIEW ) {
81
+ break ;
123
82
} else {
124
- i2ctools -> sniffer -> row_index = 0 ;
83
+ if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
84
+ stop_interrupts ();
85
+ i2ctools -> sniffer -> started = false;
86
+ i2ctools -> sniffer -> state = I2C_BUS_FREE ;
87
+ }
88
+ i2ctools -> main_view -> current_view = MAIN_VIEW ;
125
89
}
126
90
}
127
- }
128
- // Down
129
- else if (event .key == InputKeyDown && event .type == InputTypeRelease ) {
130
- if (i2ctools -> main_view -> current_view == MAIN_VIEW ) {
131
- if (i2ctools -> main_view -> menu_index < MENU_SIZE - 1 ) {
132
- i2ctools -> main_view -> menu_index ++ ;
133
- }
134
- } else if (i2ctools -> main_view -> current_view == SCAN_VIEW ) {
135
- if (i2ctools -> scanner -> menu_index < ((int )i2ctools -> scanner -> nb_found / 3 )) {
136
- i2ctools -> scanner -> menu_index ++ ;
137
- }
138
- } else if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
139
- if ((i2ctools -> sniffer -> row_index + 3 ) <
140
- (int )i2ctools -> sniffer -> frames [i2ctools -> sniffer -> menu_index ].data_index ) {
141
- i2ctools -> sniffer -> row_index ++ ;
142
- }
143
- } else if (i2ctools -> main_view -> current_view == SEND_VIEW ) {
144
- if (i2ctools -> sender -> value > 0x00 ) {
145
- i2ctools -> sender -> value -- ;
146
- i2ctools -> sender -> sended = false;
91
+ // Up
92
+ else if (event .key == InputKeyUp && event .type == InputTypeRelease ) {
93
+ if (i2ctools -> main_view -> current_view == MAIN_VIEW ) {
94
+ if ((i2ctools -> main_view -> menu_index > SCAN_VIEW )) {
95
+ i2ctools -> main_view -> menu_index -- ;
96
+ }
97
+ } else if (i2ctools -> main_view -> current_view == SCAN_VIEW ) {
98
+ if (i2ctools -> scanner -> menu_index > 0 ) {
99
+ i2ctools -> scanner -> menu_index -- ;
100
+ }
101
+ } else if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
102
+ if (i2ctools -> sniffer -> row_index > 0 ) {
103
+ i2ctools -> sniffer -> row_index -- ;
104
+ }
105
+ } else if (i2ctools -> main_view -> current_view == SEND_VIEW ) {
106
+ if (i2ctools -> sender -> value < 0xFF ) {
107
+ i2ctools -> sender -> value ++ ;
108
+ i2ctools -> sender -> sended = false;
109
+ }
147
110
}
148
111
}
149
- }
150
- // Long Down
151
- else if (
152
- event .key == InputKeyDown &&
153
- (event .type == InputTypeLong || event .type == InputTypeRepeat )) {
154
- if (i2ctools -> main_view -> current_view == SEND_VIEW ) {
155
- if (i2ctools -> sender -> value > 0x05 ) {
156
- i2ctools -> sender -> value -= 5 ;
157
- i2ctools -> sender -> sended = false;
158
- } else {
159
- i2ctools -> sender -> value = 0 ;
160
- i2ctools -> sender -> sended = false;
161
- }
162
- } else if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
163
- if ((i2ctools -> sniffer -> row_index + 8 ) <
164
- (int )i2ctools -> sniffer -> frames [i2ctools -> sniffer -> menu_index ].data_index ) {
165
- i2ctools -> sniffer -> row_index += 5 ;
112
+ // Long Up
113
+ else if (
114
+ event .key == InputKeyUp &&
115
+ (event .type == InputTypeLong || event .type == InputTypeRepeat )) {
116
+ if (i2ctools -> main_view -> current_view == SCAN_VIEW ) {
117
+ if (i2ctools -> scanner -> menu_index > 5 ) {
118
+ i2ctools -> scanner -> menu_index -= 5 ;
119
+ }
120
+ } else if (i2ctools -> main_view -> current_view == SEND_VIEW ) {
121
+ if (i2ctools -> sender -> value < 0xF9 ) {
122
+ i2ctools -> sender -> value += 5 ;
123
+ i2ctools -> sender -> sended = false;
124
+ }
125
+ } else if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
126
+ if (i2ctools -> sniffer -> row_index > 5 ) {
127
+ i2ctools -> sniffer -> row_index -= 5 ;
128
+ } else {
129
+ i2ctools -> sniffer -> row_index = 0 ;
130
+ }
166
131
}
167
132
}
168
-
169
- } else if (event .key == InputKeyOk && event .type == InputTypeRelease ) {
170
- if (i2ctools -> main_view -> current_view == MAIN_VIEW ) {
171
- i2ctools -> main_view -> current_view = i2ctools -> main_view -> menu_index ;
172
- } else if (i2ctools -> main_view -> current_view == SCAN_VIEW ) {
173
- scan_i2c_bus (i2ctools -> scanner );
174
- } else if (i2ctools -> main_view -> current_view == SEND_VIEW ) {
175
- i2ctools -> sender -> must_send = true;
176
- } else if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
177
- if (i2ctools -> sniffer -> started ) {
178
- stop_interrupts ();
179
- i2ctools -> sniffer -> started = false;
180
- i2ctools -> sniffer -> state = I2C_BUS_FREE ;
181
- } else {
182
- start_interrupts (i2ctools -> sniffer );
183
- i2ctools -> sniffer -> started = true;
184
- i2ctools -> sniffer -> state = I2C_BUS_FREE ;
185
- }
186
- }
187
- } else if (event .key == InputKeyRight && event .type == InputTypeRelease ) {
188
- if (i2ctools -> main_view -> current_view == SEND_VIEW ) {
189
- if (i2ctools -> sender -> address_idx < (i2ctools -> scanner -> nb_found - 1 )) {
190
- i2ctools -> sender -> address_idx ++ ;
191
- i2ctools -> sender -> sended = false;
192
- }
193
- } else if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
194
- if (i2ctools -> sniffer -> menu_index < i2ctools -> sniffer -> frame_index ) {
195
- i2ctools -> sniffer -> menu_index ++ ;
196
- i2ctools -> sniffer -> row_index = 0 ;
133
+ // Down
134
+ else if (event .key == InputKeyDown && event .type == InputTypeRelease ) {
135
+ if (i2ctools -> main_view -> current_view == MAIN_VIEW ) {
136
+ if (i2ctools -> main_view -> menu_index < MENU_SIZE - 1 ) {
137
+ i2ctools -> main_view -> menu_index ++ ;
138
+ }
139
+ } else if (i2ctools -> main_view -> current_view == SCAN_VIEW ) {
140
+ if (i2ctools -> scanner -> menu_index < ((int )i2ctools -> scanner -> nb_found / 3 )) {
141
+ i2ctools -> scanner -> menu_index ++ ;
142
+ }
143
+ } else if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
144
+ if ((i2ctools -> sniffer -> row_index + 3 ) <
145
+ (int )i2ctools -> sniffer -> frames [i2ctools -> sniffer -> menu_index ].data_index ) {
146
+ i2ctools -> sniffer -> row_index ++ ;
147
+ }
148
+ } else if (i2ctools -> main_view -> current_view == SEND_VIEW ) {
149
+ if (i2ctools -> sender -> value > 0x00 ) {
150
+ i2ctools -> sender -> value -- ;
151
+ i2ctools -> sender -> sended = false;
152
+ }
197
153
}
198
154
}
199
- } else if (event .key == InputKeyLeft && event .type == InputTypeRelease ) {
200
- if (i2ctools -> main_view -> current_view == SEND_VIEW ) {
201
- if (i2ctools -> sender -> address_idx > 0 ) {
202
- i2ctools -> sender -> address_idx -- ;
203
- i2ctools -> sender -> sended = false;
204
- }
205
- } else if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
206
- if (i2ctools -> sniffer -> menu_index > 0 ) {
207
- i2ctools -> sniffer -> menu_index -- ;
208
- i2ctools -> sniffer -> row_index = 0 ;
155
+ // Long Down
156
+ else if (
157
+ event .key == InputKeyDown &&
158
+ (event .type == InputTypeLong || event .type == InputTypeRepeat )) {
159
+ if (i2ctools -> main_view -> current_view == SEND_VIEW ) {
160
+ if (i2ctools -> sender -> value > 0x05 ) {
161
+ i2ctools -> sender -> value -= 5 ;
162
+ i2ctools -> sender -> sended = false;
163
+ } else {
164
+ i2ctools -> sender -> value = 0 ;
165
+ i2ctools -> sender -> sended = false;
166
+ }
167
+ } else if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
168
+ if ((i2ctools -> sniffer -> row_index + 8 ) <
169
+ (int )i2ctools -> sniffer -> frames [i2ctools -> sniffer -> menu_index ].data_index ) {
170
+ i2ctools -> sniffer -> row_index += 5 ;
171
+ }
172
+ }
173
+
174
+ } else if (event .key == InputKeyOk && event .type == InputTypeRelease ) {
175
+ if (i2ctools -> main_view -> current_view == MAIN_VIEW ) {
176
+ i2ctools -> main_view -> current_view = i2ctools -> main_view -> menu_index ;
177
+ } else if (i2ctools -> main_view -> current_view == SCAN_VIEW ) {
178
+ scan_i2c_bus (i2ctools -> scanner );
179
+ } else if (i2ctools -> main_view -> current_view == SEND_VIEW ) {
180
+ i2ctools -> sender -> must_send = true;
181
+ } else if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
182
+ if (i2ctools -> sniffer -> started ) {
183
+ stop_interrupts ();
184
+ i2ctools -> sniffer -> started = false;
185
+ i2ctools -> sniffer -> state = I2C_BUS_FREE ;
186
+ } else {
187
+ start_interrupts (i2ctools -> sniffer );
188
+ i2ctools -> sniffer -> started = true;
189
+ i2ctools -> sniffer -> state = I2C_BUS_FREE ;
190
+ }
191
+ }
192
+ } else if (event .key == InputKeyRight && event .type == InputTypeRelease ) {
193
+ if (i2ctools -> main_view -> current_view == SEND_VIEW ) {
194
+ if (i2ctools -> sender -> address_idx < (i2ctools -> scanner -> nb_found - 1 )) {
195
+ i2ctools -> sender -> address_idx ++ ;
196
+ i2ctools -> sender -> sended = false;
197
+ }
198
+ } else if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
199
+ if (i2ctools -> sniffer -> menu_index < i2ctools -> sniffer -> frame_index ) {
200
+ i2ctools -> sniffer -> menu_index ++ ;
201
+ i2ctools -> sniffer -> row_index = 0 ;
202
+ }
203
+ }
204
+ } else if (event .key == InputKeyLeft && event .type == InputTypeRelease ) {
205
+ if (i2ctools -> main_view -> current_view == SEND_VIEW ) {
206
+ if (i2ctools -> sender -> address_idx > 0 ) {
207
+ i2ctools -> sender -> address_idx -- ;
208
+ i2ctools -> sender -> sended = false;
209
+ }
210
+ } else if (i2ctools -> main_view -> current_view == SNIFF_VIEW ) {
211
+ if (i2ctools -> sniffer -> menu_index > 0 ) {
212
+ i2ctools -> sniffer -> menu_index -- ;
213
+ i2ctools -> sniffer -> row_index = 0 ;
214
+ }
209
215
}
210
216
}
211
217
}
@@ -218,6 +224,7 @@ int32_t i2ctools_app(void* p) {
218
224
i2c_scanner_free (i2ctools -> scanner );
219
225
i2c_sender_free (i2ctools -> sender );
220
226
i2c_main_view_free (i2ctools -> main_view );
227
+ furi_mutex_free (i2ctools -> mutex );
221
228
free (i2ctools );
222
229
furi_record_close (RECORD_GUI );
223
230
return 0 ;
0 commit comments