Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
vad7 committed Mar 24, 2023
1 parent 41fbbbf commit 961ab3f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 54 deletions.
31 changes: 23 additions & 8 deletions Distr/nrf24batch/CO2_mini.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ DPL: 0
RETR: 0x0F
Resend: 3
Delay_ms: 30
Read repeat: 10
Listen repeat: 3

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

R default: ,EEPROM,0xC1
W default: n,,0x81
Expand All @@ -19,9 +19,15 @@ Write start: 0,0,0x8F
Listen: C8C8C1=CO2,Alarm,-

R: ID*=,ID
R: OSCCAL=0x51,RAM

R: _CO2*2=0x6C,RAM,0xC2
R: _PORTA=0x39,RAM
W: _PORTA=,0x3B,WRAM
R: _PORTB=0x36,RAM
W: _PORTB=,0x38,WRAM
R: _OSCCAL=0x51,RAM
W: _OSCCAL=,0x51,WRAM
R: OSCCAL_EMEM=0
R: CO2*2=0x6B,RAM,0xC2

R: RxAddr=1#
W: RxAddr=,1
Expand All @@ -44,25 +50,34 @@ W: CO2 correct=,7,0x82
R: FanLSB[10]=i:9#
W: FanLSB=,i:9

R: Send pause=19
W: Send pause=,19
R: Transmit pause=19
W: Transmit pause=,19

R: Flags=20#
W: Flags=,20

W: Reset=,RESET,0xC1

R: _LED Warning=0x74,RAM
W: _LED Warning=,0x74,WRAM

S: LED=,0,0x40

SBatch: LED On: LED=1
SBatch: LED Off: LED=0

RBatch: Settings: ID;RxAddr;Ch;Send period;CO2 threshold;CO2 correct;FanLSB;nRF RETR;Send pause;Flags

WBatch: Default: RxAddr=0xCF;Ch=122;Send period=30;CO2 threshold=1000;CO2 correct=0;FanLSB={0xC1,0,0,0,0,0,0,0};nRF RETR=0x3;Send pause=1;Flags=0;Reset
WBatch: Default: RxAddr=0xCF;Ch=122;Send period=30;CO2 threshold=1000;CO2 correct=0;FanLSB={0xC1,0,0,0,0,0,0,0};nRF RETR=0x3;Transmit pause=1;Flags=0;Reset
WBatch: CO2: CO2 threshold=1000;CO2 correct=0
WBatch: Fan: FanLSB={0xC1,0,0,0,0,0,0,0,0,0};Reset
WBatch: RETR: nRF RETR=0x2F;Reset
WBatch: Send pause: Send pause=30
WBatch: Transmit pause: Transmit pause=30
WBatch: Flags: Flags=0x00

WBatch: LED Warning: _LED Warning=0x30
WBatch: PORTA: _PORTA=0x0C
WBatch: PORTB: _PORTB=0xC
WBatch: OSCCAL: _OSCCAL=128

WBatch: Reset: Reset
63 changes: 34 additions & 29 deletions Distr/nrf24batch/Kitchen Vent.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ Resend: 3
Delay_ms: 30

Payload struct: 2,1,1
EEPROM=0; RAM=1; PROGMEM=2; ID=3; RESET=4, WRAM=0x89
EEPROM=0; RAM=1; PROGMEM=2; ID=3; RESET=4; WRAM=0x89; R1=0xC1; R2=0xC2; W1=0x81; W2=0x82

R default: ,EEPROM,0xC1
W default: n,,0x81
R default: ,EEPROM,R1
W default: n,,W1
Write start: 0,0,0x8F

R: ID*=,ID

R: CO2 level*2[3]=i:4,,0xC2
W: CO2 level*2=,i:4,0x82
R: CO2 level*2[3]=i:4,,R2
W: CO2 level*2=,i:4,W2

R: FanSpeed[3]=i:19
W: FanSpeed=,i:19
Expand Down Expand Up @@ -52,8 +52,8 @@ W: SpeedKeyIdx=,17
R: IRRemotes=32
W: IRRemotes=,32

R: IRRemotesHash*2[80]=i:32#
W: IRRemotesHash*2=,i:32
R: IRRemotesHash*2[80]=i:32#,,R2
W: IRRemotesHash*2=,i:32,W2

R: OutPeriod=18
W: OutPeriod=,18
Expand All @@ -67,48 +67,53 @@ W: RxAddr=,2
R: Ch=3
W: Ch=,3

R: OSCCAL#=0x51,RAM
W: OSCCAL#=,0x51,WRAM
R: _OSCCAL=0x51,RAM
W: _OSCCAL=,0x51,WRAM
R: OSCCAL_EMEM=0

R: PORTA#=0x39,RAM
W: PORTA#=,0x3B,WRAM
R: PORTB#=0x36,RAM
W: PORTB#=,0x38,WRAM
R: _PORTA=0x39,RAM
W: _PORTA=,0x3B,WRAM
R: _PORTB=0x36,RAM
W: _PORTB=,0x38,WRAM

R: LED Warning#=0x6C,RAM
W: LED Warning#=,0x6C,WRAM
R: _LED Warning=0x6B,RAM
W: _LED Warning=,0x6B,WRAM

R: FanOn=0x76,RAM
R: FanOnNext=0x74,RAM
R: FanOnNextCnt=0x72,RAM
R: FanOnLast=0x73,RAM
R: Fanspeed=0x75,RAM
R: _FanOn=0x75,RAM
R: _FanOnNext=0x73,RAM
R: _FanOnNextCnt=0x71,RAM
R: _FanOnLast=0x72,RAM
R: _Fanspeed=0x74,RAM
R: _IRHashLast*2=0x79,RAM,R2

W: Reset=,RESET,0xC1

S: Lamp=,0,0x40
S: Fan=,1,0x40
S: FanSpdUp=,2,0x40
S: FanSpdDn=,3,0x40
S: SetupIR=,4,0x40
S: FanSpdSave=,4,0x40
S: SetupIR=,5,0x40

SBatch: Fan Off: Fan=0
SBatch: Fan On: Fan=3
SBatch: Fan Cooker On: Fan=6
SBatch: Fan Up: FanSpdUp=0
SBatch: Fan Down: FanSpdDn=0
SBatch: Fan On: Fan=3
SBatch: Fan Off: Fan=0
SBatch: Lamp On: Lamp=1
SBatch: Lamp Off: Lamp=0
SBatch: Fan Up: FanSpdUp=0
SBatch: Fan Down: FanSpdDn=0
SBatch: Fan SAVE: FanSpdSave=0;
SBatch: Add new IR: SetupIR=1

RBatch: Work: ID;CO2 level;FanCookSpeed;FanCookOnTime;FanCookOffTime;FanCookSleep;FanSpeed;FanOnTime;FanOffTime;FanSleep
RBatch: Hardware: ID;RxAddr;Ch;SpeedInitIdx;Flags;OutPeriod;IRRemotes;OSCCAL_EMEM
RBatch: All: ID;CO2 level;FanCookSpeed;FanCookOnTime;FanCookOffTime;FanCookSleep;FanSpeed;FanOnTime;FanOffTime;FanSleep;RxAddr;Ch;SpeedInitIdx;Flags;OutPeriod;IRRemotes;IRRemotesHash

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
WBatch: LED Warning: LED Warning#=0x10
WBatch: PORTA: PORTA#=0x0C
WBatch: PORTB: PORTB#=0xC
WBatch: OSCCAL: OSCCAL#=128
WBatch: IRRemotes: IRRemotes=0
WBatch: LED Warning: _LED Warning=0x10
WBatch: PORTA: _PORTA=0x0C
WBatch: PORTB: _PORTB=0xC
WBatch: OSCCAL: _OSCCAL=128
WBatch: CO2 Level+Fan speed: CO2 level={700,850,1000};FanSpeed={3,5,6}
WBatch: Reset: Reset
35 changes: 18 additions & 17 deletions nrf24batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const char SettingsFld_ReadBatch[] = "RBatch:";
const char SettingsFld_WriteBatch[] = "WBatch:";
const char SettingsFld_SetBatch[] = "SBatch:";
const char SettingsFld_Listen[] = "Listen:";
const char SettingsFld_ReadRepeatPeriod[] = "Read repeat:";
const char SettingsFld_ListenRepeatPeriod[] = "Listen repeat:";
const char AskQuestion_Save[] = "SAVE BATCH?";
#define Settings_i 'i'
#define Settings_n 'n'
Expand Down Expand Up @@ -95,7 +95,7 @@ uint8_t NRF_last_packet_send_st = 0;
uint8_t NRF_resend = 1; // number of transaction attempts
int8_t NRF_repeat = 0; // count number of repeated requests (until < NRF_resend)
uint32_t NRF_time;
uint16_t ReadRepeatPeriod = 10; // s
uint16_t ListenRepeatPeriod = 10; // s
bool ReadRepeat = false;
uint32_t delay_between_pkt = 10;// ms

Expand Down Expand Up @@ -854,8 +854,8 @@ static uint8_t load_settings_file() {
NRF_resend = str_to_int(p + sizeof(SettingsFld_Resend));
} else if(strncmp(p, SettingsFld_Delay, sizeof(SettingsFld_Delay)-1) == 0) {
delay_between_pkt = str_to_int(p + sizeof(SettingsFld_Delay));
} else if(strncmp(p, SettingsFld_ReadRepeatPeriod, sizeof(SettingsFld_ReadRepeatPeriod)-1) == 0) {
ReadRepeatPeriod = str_to_int(p + sizeof(SettingsFld_ReadRepeatPeriod));
} else if(strncmp(p, SettingsFld_ListenRepeatPeriod, sizeof(SettingsFld_ListenRepeatPeriod)-1) == 0) {
ListenRepeatPeriod = str_to_int(p + sizeof(SettingsFld_ListenRepeatPeriod));
} else if(strncmp(p, SettingsFld_Payload, sizeof(SettingsFld_Payload)-1) == 0) {
p += sizeof(SettingsFld_Payload);
payload_fields = 0;
Expand Down Expand Up @@ -1000,6 +1000,18 @@ static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queu
furi_message_queue_put(event_queue, &event, FuriWaitForever);
}

void display_remove_asterisk(char *fsp, uint8_t vx)
{
char *p2 = strchr(fsp, '*');
if(p2) { // remove '*' or '*n'
int pos = p2 - fsp;
if((pos -= vx) < 0) pos = 0;
char c = *(p2 + 1);
if(*(screen_buf + pos))
memmove(screen_buf + pos, screen_buf + pos + (c == ':' || c == '=' ? 1 : 2), FONT_5x7_SCREEN_WIDTH + 1 + 2 - pos);
}
}

void render_display_list(Canvas* const canvas, FuriString ***fsa, char delim, uint16_t view_pos, uint16_t max_i)
{
uint16_t page = view_pos & ~7;
Expand All @@ -1010,12 +1022,11 @@ void render_display_list(Canvas* const canvas, FuriString ***fsa, char delim, ui
p = (char*) furi_string_get_cstr((*fsa)[page + i]);
end = strchr(p, delim);
if(end) {
if(*(end - 1) == '*') end--; // skip *
else if(*(end - 2) == '*') end -= 2; // skip *?
len = MIN(end - p, view_x);
len = MIN(end - p - len, FONT_5x7_SCREEN_WIDTH);
strncpy(screen_buf, p + view_x, len);
screen_buf[len] = '\0';
display_remove_asterisk(p, MIN(end - p, view_x));
canvas_draw_str(canvas, 5, y, screen_buf);
}
if((view_pos & 7) == i) {
Expand All @@ -1025,16 +1036,6 @@ void render_display_list(Canvas* const canvas, FuriString ***fsa, char delim, ui
}
}

void display_remove_asterisk(char *fsp, uint8_t vx)
{
char *p2 = strchr(fsp, '*');
if(p2) { // remove '*' or '*n'
int pos = p2 - fsp;
if((pos -= vx) < 0) pos = 0;
memmove(screen_buf + pos, screen_buf + pos + (*(p2 + 1) == ':' ? 1 : 2), FONT_5x7_SCREEN_WIDTH + 1 + 2);
}
}

void display_edit_ttf_font(Canvas* const canvas, uint8_t start_x, uint8_t start_y)
{
screen_buf[0] = *Edit_pos; screen_buf[1] = '\0';
Expand Down Expand Up @@ -1392,7 +1393,7 @@ int32_t nrf24batch_app(void* p) {
FuriLogLevel = furi_log_get_level();
if(FuriLogLevel == FuriLogLevelDebug) furi_hal_uart_set_br(FuriHalUartIdUSART1, 1843200);
}
if(what_doing == 2 && rw_type == rwt_read_cmd && ReadRepeat && furi_get_tick() - NRF_time > (uint32_t)(ReadRepeatPeriod * 1000)) {
if(what_doing == 2 && rw_type == rwt_read_cmd && ReadRepeat && furi_get_tick() - NRF_time > (uint32_t)(ListenRepeatPeriod * 1000)) {
ERR = 0;
free_Log();
Run_Read_cmd(Read_cmd[view_cmd[rwt_read_cmd]]);
Expand Down

0 comments on commit 961ab3f

Please sign in to comment.