Skip to content

Commit cdf8daf

Browse files
committed
add tx 2
1 parent 3f33fe8 commit cdf8daf

File tree

7 files changed

+152
-32
lines changed

7 files changed

+152
-32
lines changed

applications/external/subghz_remote_new/helpers/subrem_custom_event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ typedef enum {
1717
SubRemCustomEventViewRemoteStartRIGHT,
1818
SubRemCustomEventViewRemoteStartOK,
1919
SubRemCustomEventViewRemoteStop,
20+
SubRemCustomEventViewRemoteForceStop,
2021

2122
// SubRemCustomEventSceneDeleteSuccess = 100,
2223
// SubRemCustomEventSceneDelete,

applications/external/subghz_remote_new/scenes/subrem_scene_remote.c

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "../subghz_remote_app_i.h"
22
#include "../views/transmitter.h"
33

4+
#include <lib/subghz/protocols/raw.h>
5+
46
// TODO:
57
// #include <lib/subghz/protocols/keeloq.h>
68
// #include <lib/subghz/protocols/star_line.h>
@@ -13,6 +15,12 @@ void subrem_scene_remote_callback(SubRemCustomEvent event, void* context) {
1315
view_dispatcher_send_custom_event(app->view_dispatcher, event);
1416
}
1517

18+
void subrem_scene_remote_raw_callback_end_tx(void* context) {
19+
furi_assert(context);
20+
SubGhzRemoteApp* app = context;
21+
view_dispatcher_send_custom_event(app->view_dispatcher, SubRemCustomEventViewRemoteForceStop);
22+
}
23+
1624
bool subrem_scene_remote_update_data_show(void* context) {
1725
SubGhzRemoteApp* app = context;
1826
//UNUSED(app);
@@ -113,12 +121,65 @@ bool subrem_scene_remote_on_event(void* context, SceneManagerEvent event) {
113121
app->scene_manager, SubRemSceneStart);
114122
return true;
115123
} else if(event.event == SubRemCustomEventViewRemoteStartUP) {
116-
if(subghz_tx_start_sub(app, app->subs_preset[0])) {
124+
if(subghz_tx_start_sub(
125+
app, app->subs_preset[0], subrem_scene_remote_raw_callback_end_tx)) {
126+
app->chusen_sub = 0;
127+
subrem_view_remote_set_state(app->subrem_remote_view, 1);
128+
notification_message(app->notifications, &sequence_blink_start_magenta);
129+
}
130+
return true;
131+
} else if(event.event == SubRemCustomEventViewRemoteStartDOWN) {
132+
if(subghz_tx_start_sub(
133+
app, app->subs_preset[1], subrem_scene_remote_raw_callback_end_tx)) {
134+
app->chusen_sub = 1;
135+
subrem_view_remote_set_state(app->subrem_remote_view, 2);
136+
notification_message(app->notifications, &sequence_blink_start_magenta);
137+
}
138+
return true;
139+
} else if(event.event == SubRemCustomEventViewRemoteStartLEFT) {
140+
if(subghz_tx_start_sub(
141+
app, app->subs_preset[2], subrem_scene_remote_raw_callback_end_tx)) {
142+
app->chusen_sub = 2;
143+
subrem_view_remote_set_state(app->subrem_remote_view, 3);
117144
notification_message(app->notifications, &sequence_blink_start_magenta);
118145
}
146+
return true;
147+
} else if(event.event == SubRemCustomEventViewRemoteStartRIGHT) {
148+
if(subghz_tx_start_sub(
149+
app, app->subs_preset[3], subrem_scene_remote_raw_callback_end_tx)) {
150+
app->chusen_sub = 3;
151+
subrem_view_remote_set_state(app->subrem_remote_view, 4);
152+
notification_message(app->notifications, &sequence_blink_start_magenta);
153+
}
154+
return true;
155+
} else if(event.event == SubRemCustomEventViewRemoteStartOK) {
156+
if(subghz_tx_start_sub(
157+
app, app->subs_preset[4], subrem_scene_remote_raw_callback_end_tx)) {
158+
app->chusen_sub = 4;
159+
subrem_view_remote_set_state(app->subrem_remote_view, 5);
160+
notification_message(app->notifications, &sequence_blink_start_magenta);
161+
}
162+
return true;
163+
} else if(event.event == SubRemCustomEventViewRemoteForceStop) {
164+
if(app->tx_running) {
165+
subghz_tx_stop_sub(app);
166+
subrem_view_remote_set_state(app->subrem_remote_view, 0);
167+
}
168+
notification_message(app->notifications, &sequence_blink_stop);
169+
return true;
119170
} else if(event.event == SubRemCustomEventViewRemoteStop) {
120-
subghz_tx_stop_sub(app, app->subs_preset[0]);
171+
// if(app->tx_running &&
172+
// (app->subs_preset[app->chusen_sub]->type == SubRemSubKeyTypeRawKey)) {
173+
// subghz_tx_stop_sub(app);
174+
// subrem_view_remote_set_state(app->subrem_remote_view, 0);
175+
// }
176+
// notification_message(app->notifications, &sequence_blink_stop);
177+
if(app->tx_running) {
178+
subghz_tx_stop_sub(app);
179+
subrem_view_remote_set_state(app->subrem_remote_view, 0);
180+
}
121181
notification_message(app->notifications, &sequence_blink_stop);
182+
return true;
122183
}
123184
// notification_message(app->notification, &sequence_blink_stop);
124185

applications/external/subghz_remote_new/subghz_remote_app.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ SubGhzRemoteApp* subghz_remote_app_alloc() {
137137

138138
app->receiver = subghz_receiver_alloc_init(app->environment);
139139

140+
app->tx_running = false;
141+
140142
scene_manager_next_scene(app->scene_manager, SubRemSceneStart);
141143

142144
return app;

applications/external/subghz_remote_new/subghz_remote_app_i.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ static bool subrem_sub_file_presets_load(SubGhzRemoteApp* app, FlipperFormat* ff
115115
return ret;
116116
}
117117

118-
bool subghz_tx_start_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) {
118+
bool subghz_tx_start_sub(
119+
SubGhzRemoteApp* app,
120+
SubRemSubFilePreset* sub_preset,
121+
SubGhzProtocolEncoderRAWCallbackEnd callback) {
119122
furi_assert(app);
120123
furi_assert(sub_preset);
121124
bool ret = false;
@@ -152,19 +155,26 @@ bool subghz_tx_start_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset)
152155
break;
153156
}
154157

158+
if(sub_preset->type == SubRemSubKeyTypeRawKey) {
159+
subghz_protocol_raw_file_encoder_worker_set_callback_end(
160+
(SubGhzProtocolEncoderRAW*)subghz_transmitter_get_protocol_instance(
161+
app->transmitter),
162+
callback,
163+
app);
164+
}
165+
155166
furi_hal_subghz_start_async_tx(subghz_transmitter_yield, app->transmitter);
156167

157168
ret = true;
158169
}
159170
} while(false);
171+
app->tx_running = ret; // TODO:
160172

161-
// ret = false; // TODO:
162173
return ret;
163174
}
164175

165-
void subghz_tx_stop_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) {
176+
void subghz_tx_stop_sub(SubGhzRemoteApp* app) {
166177
furi_assert(app);
167-
furi_assert(sub_preset);
168178

169179
//Stop TX
170180
furi_hal_subghz_stop_async_tx();
@@ -173,7 +183,10 @@ void subghz_tx_stop_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) {
173183
subghz_transmitter_free(app->transmitter);
174184
furi_hal_subghz_idle();
175185

186+
// SubRemSubFilePreset* sub_preset = app->subs_preset[app->chusen_sub];
187+
176188
// TODO: need saving logic
189+
app->tx_running = false;
177190
}
178191

179192
static bool subrem_sub_presets_check(SubGhzRemoteApp* app, FlipperFormat* fff_data_file) {

applications/external/subghz_remote_new/subghz_remote_app_i.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <storage/storage.h>
1919
#include <gui/modules/popup.h>
2020

21+
#include <lib/subghz/protocols/raw.h>
22+
2123
#include <lib/subghz/subghz_setting.h>
2224
#include <lib/subghz/receiver.h>
2325
#include <lib/subghz/transmitter.h>
@@ -75,6 +77,10 @@ typedef struct {
7577
SubGhzReceiver* receiver;
7678
SubGhzTransmitter* transmitter;
7779

80+
bool tx_running;
81+
82+
uint8_t chusen_sub;
83+
7884
// AvrIspProgrammerView* subghz_remote_programmer_view;
7985
// AvrIspReaderView* subghz_remote_reader_view;
8086
// AvrIspWriterView* subghz_remote_writer_view;
@@ -85,5 +91,8 @@ typedef struct {
8591

8692
bool subrem_load_from_file(SubGhzRemoteApp* app);
8793

88-
bool subghz_tx_start_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset);
89-
void subghz_tx_stop_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset);
94+
bool subghz_tx_start_sub(
95+
SubGhzRemoteApp* app,
96+
SubRemSubFilePreset* sub_preset,
97+
SubGhzProtocolEncoderRAWCallbackEnd callback);
98+
void subghz_tx_stop_sub(SubGhzRemoteApp* app);

applications/external/subghz_remote_new/views/transmitter.c

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ void subrem_view_remote_add_data_to_show(
8585
true);
8686
}
8787

88+
void subrem_view_remote_set_state(SubRemViewRemote* subrem_view_remote, uint8_t state) {
89+
furi_assert(subrem_view_remote);
90+
with_view_model(
91+
subrem_view_remote->view,
92+
SubRemViewRemoteModel * model,
93+
{ model->pressed_btn = state; },
94+
true);
95+
}
96+
8897
void subrem_view_remote_draw(Canvas* canvas, SubRemViewRemoteModel* model) {
8998
canvas_clear(canvas);
9099
canvas_set_color(canvas, ColorBlack);
@@ -139,10 +148,10 @@ void subrem_view_remote_draw(Canvas* canvas, SubRemViewRemoteModel* model) {
139148
canvas_draw_icon_ex(canvas, 116, 17, &I_Pin_arrow_up_7x9, IconRotation180);
140149
break;
141150
case 3:
142-
canvas_draw_icon_ex(canvas, 115, 18, &I_Pin_arrow_up_7x9, IconRotation90);
151+
canvas_draw_icon_ex(canvas, 115, 18, &I_Pin_arrow_up_7x9, IconRotation270);
143152
break;
144153
case 4:
145-
canvas_draw_icon_ex(canvas, 115, 18, &I_Pin_arrow_up_7x9, IconRotation270);
154+
canvas_draw_icon_ex(canvas, 115, 18, &I_Pin_arrow_up_7x9, IconRotation90);
146155
break;
147156
case 5:
148157
canvas_draw_icon(canvas, 116, 18, &I_Pin_star_7x7);
@@ -177,28 +186,51 @@ bool subrem_view_remote_input(InputEvent* event, void* context) {
177186
// furi_string_reset(model->ok_label);
178187
},
179188
false);
180-
return false;
181-
} else if(event->key == InputKeyUp) {
182-
if(event->type == InputTypePress) {
183-
with_view_model(
184-
subrem_view_remote->view,
185-
SubRemViewRemoteModel * model,
186-
{ model->pressed_btn = 1; },
187-
true);
188-
subrem_view_remote->callback(
189-
SubRemCustomEventViewRemoteStartUP, subrem_view_remote->context);
190-
return true;
191-
} else if(event->type == InputTypeRelease) {
192-
with_view_model(
193-
subrem_view_remote->view,
194-
SubRemViewRemoteModel * model,
195-
{ model->pressed_btn = 0; },
196-
true);
197-
subrem_view_remote->callback(
198-
SubRemCustomEventViewRemoteStop, subrem_view_remote->context);
199-
return true;
200-
}
189+
return false; // TODO: check
190+
} else if(event->key == InputKeyBack && event->type == InputTypeShort) {
191+
with_view_model(
192+
subrem_view_remote->view,
193+
SubRemViewRemoteModel * model,
194+
{ model->pressed_btn = 0; },
195+
true);
196+
subrem_view_remote->callback(
197+
SubRemCustomEventViewRemoteForceStop, subrem_view_remote->context);
198+
return true;
199+
} else if(event->key == InputKeyBack) {
200+
return true;
201201
}
202+
// BACK button processing end
203+
204+
if(event->key == InputKeyUp && event->type == InputTypePress) {
205+
subrem_view_remote->callback(
206+
SubRemCustomEventViewRemoteStartUP, subrem_view_remote->context);
207+
return true;
208+
} else if(event->key == InputKeyDown && event->type == InputTypePress) {
209+
subrem_view_remote->callback(
210+
SubRemCustomEventViewRemoteStartDOWN, subrem_view_remote->context);
211+
return true;
212+
} else if(event->key == InputKeyLeft && event->type == InputTypePress) {
213+
subrem_view_remote->callback(
214+
SubRemCustomEventViewRemoteStartLEFT, subrem_view_remote->context);
215+
return true;
216+
} else if(event->key == InputKeyRight && event->type == InputTypePress) {
217+
subrem_view_remote->callback(
218+
SubRemCustomEventViewRemoteStartRIGHT, subrem_view_remote->context);
219+
return true;
220+
} else if(event->key == InputKeyOk && event->type == InputTypePress) {
221+
subrem_view_remote->callback(
222+
SubRemCustomEventViewRemoteStartOK, subrem_view_remote->context);
223+
return true;
224+
} else if(event->type == InputTypeRelease) {
225+
with_view_model(
226+
subrem_view_remote->view,
227+
SubRemViewRemoteModel * model,
228+
{ model->pressed_btn = 0; },
229+
true);
230+
subrem_view_remote->callback(SubRemCustomEventViewRemoteStop, subrem_view_remote->context);
231+
return true;
232+
}
233+
202234
return true;
203235
}
204236

applications/external/subghz_remote_new/views/transmitter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ void subrem_view_remote_add_data_to_show(
2424
const char* down_label,
2525
const char* left_label,
2626
const char* right_label,
27-
const char* ok_label);
27+
const char* ok_label);
28+
29+
void subrem_view_remote_set_state(SubRemViewRemote* subrem_view_remote, uint8_t state);

0 commit comments

Comments
 (0)