Skip to content

Commit 7c5cc8c

Browse files
committed
version 1.8
1 parent 961ab3f commit 7c5cc8c

File tree

5 files changed

+51
-27
lines changed

5 files changed

+51
-27
lines changed

Distr/nrf24batch/CO2_mini.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ DPL: 0
77
RETR: 0x0F
88
Resend: 3
99
Delay_ms: 30
10-
Listen repeat: 3
10+
ReadCmd repeat: 3
1111

1212
Payload struct: 2,1,1
1313
EEPROM=0; RAM=1; PROGMEM=2; ID=3; RESET=4; WRAM=0x89

Distr/nrf24batch/Kitchen Vent.txt

+17-9
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ R: ID*=,ID
2020
R: CO2 level*2[3]=i:4,,R2
2121
W: CO2 level*2=,i:4,W2
2222

23+
R: Fan speeds=25
24+
W: Fan speeds=,25
2325
R: FanSpeed[3]=i:19
2426
W: FanSpeed=,i:19
27+
R: FanCook speeds=26
28+
W: FanCook speeds=,26
2529
R: FanCookSpeed[3]=i:22
2630
W: FanCookSpeed=,i:22
2731

@@ -52,8 +56,8 @@ W: SpeedKeyIdx=,17
5256
R: IRRemotes=32
5357
W: IRRemotes=,32
5458

55-
R: IRRemotesHash*2[80]=i:32#,,R2
56-
W: IRRemotesHash*2=,i:32,W2
59+
R: IRRemotesHash*2[70]=i:33,,R2#
60+
W: IRRemotesHash*2=,i:33,W2
5761

5862
R: OutPeriod=18
5963
W: OutPeriod=,18
@@ -67,24 +71,27 @@ W: RxAddr=,2
6771
R: Ch=3
6872
W: Ch=,3
6973

74+
R: OSCCAL_EMEM=0
7075
R: _OSCCAL=0x51,RAM
7176
W: _OSCCAL=,0x51,WRAM
72-
R: OSCCAL_EMEM=0
7377

7478
R: _PORTA=0x39,RAM
7579
W: _PORTA=,0x3B,WRAM
7680
R: _PORTB=0x36,RAM
7781
W: _PORTB=,0x38,WRAM
7882

79-
R: _LED Warning=0x6B,RAM
80-
W: _LED Warning=,0x6B,WRAM
83+
R: _OutPeriod=0x8B,RAM
84+
W: _OutPeriod=,0x8B,WRAM
8185

86+
R: _Fanspeed=0x74,RAM
8287
R: _FanOn=0x75,RAM
8388
R: _FanOnNext=0x73,RAM
8489
R: _FanOnNextCnt=0x71,RAM
8590
R: _FanOnLast=0x72,RAM
86-
R: _Fanspeed=0x74,RAM
87-
R: _IRHashLast*2=0x79,RAM,R2
91+
R: _IRHashLast*2=0x79,RAM,R2#
92+
93+
R: _LED Warning=0x6B,RAM
94+
W: _LED Warning=,0x6B,WRAM
8895

8996
W: Reset=,RESET,0xC1
9097

@@ -109,11 +116,12 @@ RBatch: Work: ID;CO2 level;FanCookSpeed;FanCookOnTime;FanCookOffTime;FanCookSlee
109116
RBatch: Hardware: ID;RxAddr;Ch;SpeedInitIdx;Flags;OutPeriod;IRRemotes;OSCCAL_EMEM
110117
RBatch: All: ID;CO2 level;FanCookSpeed;FanCookOnTime;FanCookOffTime;FanCookSleep;FanSpeed;FanOnTime;FanOffTime;FanSleep;RxAddr;Ch;SpeedInitIdx;Flags;OutPeriod;IRRemotes;IRRemotesHash
111118

112-
WBatch: Init(Cook2spd,Lamp-F2.2): RxAddr=0xC1;Ch=122;CO2 level={700,850,1000};FanSpeed={3,5,6};FanCookSpeed={3,6,12};FanSleep=20;FanCookSleep=6;FanOnTime=150;FanCookOnTime=2;FanOffTime=100;FanCookOffTime=0;SpeedInitIdx=0;SpeedKeyIdx=6;Flags=0x49;OutPeriod=6;IRRemotes=0
119+
WBatch: Init(Cook2spd,Lamp-F2.2): RxAddr=0xC1;Ch=122;CO2 level={950,1050,1200};Fan speeds=1;FanSpeed={2,2,2};FanCook speeds=2;FanCookSpeed={2,4,4};FanSleep=20;FanCookSleep=6;FanOnTime=150;FanCookOnTime=0;FanOffTime=100;FanCookOffTime=0;SpeedInitIdx=0;SpeedKeyIdx=6;Flags=0x0D;OutPeriod=2;IRRemotes=0
113120
WBatch: IRRemotes: IRRemotes=0
114121
WBatch: LED Warning: _LED Warning=0x10
115122
WBatch: PORTA: _PORTA=0x0C
116123
WBatch: PORTB: _PORTB=0xC
124+
WBatch: OutPeriod: _OutPeriod=2
117125
WBatch: OSCCAL: _OSCCAL=128
118-
WBatch: CO2 Level+Fan speed: CO2 level={700,850,1000};FanSpeed={3,5,6}
126+
WBatch: CO2 Level: CO2 level={750,850,1000}
119127
WBatch: Reset: Reset

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Flipper Zero application for nRF24L01 external board. Sends batch commands.
1313
- Пакетная отправка (Set),
1414
- Режим прослушивания адреса (Listen).
1515
<br>
16-
Есть два вида команд: запрос-ответ и запись.<br>
17-
Запрос-ответ (Read) - отправка пакета, переключение на прием и отображение на экране, что получили.<br>
18-
Запись (Write) - фактически отправка пакетов подряд с нужными данными.<br>
19-
Пакетная отправка (Set) - режим пульта, отправка пакетов сразу из списка без вопросов и без преварительного пакета "Write start".<br>
20-
Режим прослушивания (Listen) - если в файле присутствует строка "Listen: <адрес>=<поле 1>,<поле 2>,...", где "поле.." название поля. Адрес пожно менять - долго нажать Ok.<br>
16+
Чтение по одной команде - отправка пакета, переключение на прием и отображение на экране, что получили. Длительное нажатие кнопки Ok включает режим автоматического повторного запроса через заданный интервал в секундах (настройка "ReadCmd repeat:").<br><br>
17+
Пакетное чтение - выполнение подряд нескольких команд чтения.<br><br>
18+
Пакетная запись - фактически отправка пакетов подряд с нужными данными. Предварительно отправляется пакет "Write start", если эта строка присутствует в файле настроек.<br><br>
19+
Пакетная отправка - режим пульта, отправка пакетов сразу из списка без вопросов и без преварительного пакета "Write start".<br><br>
20+
Режим прослушивания - если в файле присутствует строка "Listen: <адрес>=<поле 1>,<поле 2>,...", где "поле.." название поля. Адрес можно менять - долго нажать кнопку Ok.<br><br>
2121
<br>
2222
Формат пакета для отправки (payload) задается в виде размера полей структуры в байтах, например, так "Payload struct: 2,1,1", что означает структуру из 3 полей: 2 байта, 1 байт, 1 байт.<br>
2323
Полученный в ответ пакет (такой же длины как и отправленный) состоит из одного значения (остаток пакета не используется), размерность по умолчанию 1 байт (int8), при необходимости, она задается числом после '*' после имени команды.<br><br>

descript.txt

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ DPL: 0 <- nRF24 dynamic payload en/dis
77
RETR: 0x0F <- nRF24 SETUP_RETR register (address 04)
88
Resend: 3 <- resend attempts on error
99
Delay_ms: 30 <- delay between cmd and resend
10+
ReadCmd repeat: 3 <- seconds (long press "Ok" in ReadCmd mode turn on repeating)
1011

1112
Payload struct: 2,1,1 <- field sizes of send packet in bytes, received packet consists of 1 field with default size 1 byte (int8)
1213
EEPROM=0; RAM=1; PROGMEM=2; ID=3; RESET=4 <- Constants
@@ -34,3 +35,7 @@ RBatch: Settings: ID;OSCCAL;RxAddr;Ch;nRF RETR;CO2 threshold;CO2 correct;FanLSB
3435

3536
WBatch: Default: RxAddr=0xCF;CO2 threshold=1000;Reset <- Write Batch, Send: { 0,0,0,0x8F }, { 0xCF, 0, 1, 0x81 }, { 0xE8, 0x03, 5, 0x82 }, { 0, 0, 4, 0xC1 }
3637
WBatch: Fans: FanLSB={0xC2,0xC3,0} <- Write Batch, Send: { 0,0,0,0x8F }, { 0xC2, 0, 9, 0x81 }, { 0xC3, 0, 10, 0x81 }
38+
39+
S: Lamp=,0,0x40 <- Set cmd
40+
SBatch: Lamp On: Lamp=1 <- Set batch
41+
SBatch: Lamp Off: Lamp=0 <- Set batch

nrf24batch.c

+23-12
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <u8g2.h>
1515

1616
#define TAG "nrf24batch"
17-
#define VERSION "1.7"
17+
#define VERSION "1.8"
1818

1919
#define SCAN_APP_PATH_FOLDER "/ext/nrf24batch"
2020
#define LOG_FILEEXT ".txt"
@@ -44,7 +44,7 @@ const char SettingsFld_ReadBatch[] = "RBatch:";
4444
const char SettingsFld_WriteBatch[] = "WBatch:";
4545
const char SettingsFld_SetBatch[] = "SBatch:";
4646
const char SettingsFld_Listen[] = "Listen:";
47-
const char SettingsFld_ListenRepeatPeriod[] = "Listen repeat:";
47+
const char SettingsFld_ReadCmdRepeatPeriod[] = "ReadCmd repeat:";
4848
const char AskQuestion_Save[] = "SAVE BATCH?";
4949
#define Settings_i 'i'
5050
#define Settings_n 'n'
@@ -95,7 +95,7 @@ uint8_t NRF_last_packet_send_st = 0;
9595
uint8_t NRF_resend = 1; // number of transaction attempts
9696
int8_t NRF_repeat = 0; // count number of repeated requests (until < NRF_resend)
9797
uint32_t NRF_time;
98-
uint16_t ListenRepeatPeriod = 10; // s
98+
uint16_t ReadCmdRepeatPeriod = 10; // s
9999
bool ReadRepeat = false;
100100
uint32_t delay_between_pkt = 10;// ms
101101

@@ -550,7 +550,13 @@ bool fill_payload(char *p, uint8_t *idx_i, int32_t var_n)
550550
} else if(*p == 'n' && *(p + 1) < '0') { // var_n
551551
if(var_n != VAR_EMPTY) b = var_n;
552552
} else if(*p >= 'A') { // constant found
553-
b = subs_constant(p, end ? (uint8_t)(end - p) : strlen(p));
553+
uint8_t len;
554+
if(end) len = end - p;
555+
else {
556+
len = strlen(p);
557+
if(*(p + len - 1) == '#') len--;
558+
}
559+
b = subs_constant(p, len);
554560
if(b == VAR_EMPTY) {
555561
ERR = 1;
556562
memset(ERR_STR, 0, sizeof(ERR_STR));
@@ -854,8 +860,8 @@ static uint8_t load_settings_file() {
854860
NRF_resend = str_to_int(p + sizeof(SettingsFld_Resend));
855861
} else if(strncmp(p, SettingsFld_Delay, sizeof(SettingsFld_Delay)-1) == 0) {
856862
delay_between_pkt = str_to_int(p + sizeof(SettingsFld_Delay));
857-
} else if(strncmp(p, SettingsFld_ListenRepeatPeriod, sizeof(SettingsFld_ListenRepeatPeriod)-1) == 0) {
858-
ListenRepeatPeriod = str_to_int(p + sizeof(SettingsFld_ListenRepeatPeriod));
863+
} else if(strncmp(p, SettingsFld_ReadCmdRepeatPeriod, sizeof(SettingsFld_ReadCmdRepeatPeriod)-1) == 0) {
864+
ReadCmdRepeatPeriod = str_to_int(p + sizeof(SettingsFld_ReadCmdRepeatPeriod));
859865
} else if(strncmp(p, SettingsFld_Payload, sizeof(SettingsFld_Payload)-1) == 0) {
860866
p += sizeof(SettingsFld_Payload);
861867
payload_fields = 0;
@@ -1073,7 +1079,7 @@ void display_add_status(void)
10731079
static void render_callback(Canvas* const canvas, void* ctx) {
10741080
if(ctx == NULL) return;
10751081
const PluginState* plugin_state = ctx;
1076-
if(furi_mutex_acquire(plugin_state->mutex, 25) != FuriStatusOk) return;
1082+
if(furi_mutex_acquire(plugin_state->mutex, 5) != FuriStatusOk) return;
10771083

10781084
//canvas_draw_frame(canvas, 0, 0, 128, 64); // border around the edge of the screen
10791085
if(what_doing == 0) {
@@ -1348,6 +1354,7 @@ void next_rw_type(int8_t add)
13481354

13491355
void next_view_cmd(int8_t add)
13501356
{
1357+
if(rw_type == rwt_listen) return;
13511358
uint16_t max = (rw_type == rwt_read_batch ? ReadBatch_cmd_Total :
13521359
rw_type == rwt_read_cmd ? Read_cmd_Total :
13531360
rw_type == rwt_set_batch ? SetBatch_cmd_Total : WriteBatch_cmd_Total);
@@ -1393,7 +1400,7 @@ int32_t nrf24batch_app(void* p) {
13931400
FuriLogLevel = furi_log_get_level();
13941401
if(FuriLogLevel == FuriLogLevelDebug) furi_hal_uart_set_br(FuriHalUartIdUSART1, 1843200);
13951402
}
1396-
if(what_doing == 2 && rw_type == rwt_read_cmd && ReadRepeat && furi_get_tick() - NRF_time > (uint32_t)(ListenRepeatPeriod * 1000)) {
1403+
if(what_doing == 2 && rw_type == rwt_read_cmd && ReadRepeat && furi_get_tick() - NRF_time > (uint32_t)(ReadCmdRepeatPeriod * 1000)) {
13971404
ERR = 0;
13981405
free_Log();
13991406
Run_Read_cmd(Read_cmd[view_cmd[rwt_read_cmd]]);
@@ -1468,8 +1475,10 @@ int32_t nrf24batch_app(void* p) {
14681475
else if(*(Edit_pos - 1) == ',') Edit_pos -= 2;
14691476
}
14701477
} else if(what_doing == 0) {
1471-
rw_type = rwt_listen;
1472-
what_doing = 1;
1478+
if(addr_len) {
1479+
rw_type = rwt_listen;
1480+
what_doing = 1;
1481+
}
14731482
} else if(what_doing == 1) {
14741483
if(event.input.type == InputTypeShort) next_rw_type(-1); else if(view_x) view_x--;
14751484
} else if(what_doing == 2) if(view_x) view_x--;
@@ -1492,8 +1501,10 @@ int32_t nrf24batch_app(void* p) {
14921501
if(*(Edit_pos + 1) == 'x') Edit_pos += 2;
14931502
}
14941503
} else if(what_doing == 0) {
1495-
rw_type = rwt_set_batch;
1496-
what_doing = 1;
1504+
if(addr_len) {
1505+
rw_type = rwt_set_batch;
1506+
what_doing = 1;
1507+
}
14971508
} else if(what_doing == 1) {
14981509
if(event.input.type == InputTypeShort) next_rw_type(+1); else view_x++;
14991510
} else if(what_doing == 2) view_x++;

0 commit comments

Comments
 (0)