Skip to content

Commit fad26ce

Browse files
authored
Merge pull request #3 from FreeSK8/0.9.0
0.9.0
2 parents 9889947 + 55cb506 commit fad26ce

File tree

7 files changed

+138
-77
lines changed

7 files changed

+138
-77
lines changed

SSD1306/SSD1306.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ static int getRotation() {return 2;}
208208
static const int WIDTH = SSD1306_LCDWIDTH;
209209
static const int HEIGHT = SSD1306_LCDHEIGHT;
210210
static int8_t _i2caddr, _vccstate;
211+
static bool display_responding = true;
211212

212213
// the most basic function, set a single pixel
213214
void SSD1306_drawPixel(int16_t x, int16_t y, uint16_t color) {
@@ -340,6 +341,11 @@ void SSD1306_invertDisplay(uint8_t i) {
340341
#include "nrf_log_ctrl.h"
341342
void SSD1306_command(uint8_t c)
342343
{
344+
if (!display_responding)
345+
{
346+
// Do not attempt to communicate with the display
347+
return;
348+
}
343349
ret_code_t ret;
344350
static uint8_t data[2] = {0};
345351
data[1] = c;
@@ -348,8 +354,8 @@ void SSD1306_command(uint8_t c)
348354
{
349355
NRF_LOG_INFO("SSD1306_command twi failed with: %d", ret);
350356
NRF_LOG_FLUSH();
357+
display_responding = false;
351358
}
352-
APP_ERROR_CHECK(ret);
353359
}
354360

355361
// startscrollright
@@ -442,6 +448,11 @@ void SSD1306_dim(bool dim) {
442448
}
443449

444450
void SSD1306_display(void) {
451+
if (!display_responding)
452+
{
453+
// Do not attempt to communicate with the display
454+
return;
455+
}
445456
SSD1306_command(SSD1306_COLUMNADDR);
446457
SSD1306_command(0); // Column start address (0 = reset)
447458
SSD1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset)

buzzer/melody_notes.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@
9393
#define REST 0
9494

9595
enum {
96+
MELODY_NONE,
9697
MELODY_GOTCHI_FAULT,
9798
MELODY_ESC_FAULT,
9899
MELODY_BLE_FAIL,
99-
MELODY_NOKIA,
100100
MELODY_BLE_SUCCESS,
101101
MELODY_STORAGE_LIMIT,
102102
MELODY_ESC_TEMP,
103103
MELODY_MOTOR_TEMP,
104104
MELODY_VOLTAGE_LOW,
105-
MELODY_ASC,
106-
MELODY_DESC,
105+
MELODY_LOG_START,
106+
MELODY_LOG_STOP,
107107
MELODY_STARTUP,
108108
MELODY_GPS_LOCK,
109109
MELODY_GPS_LOST,
@@ -148,16 +148,6 @@ const int melody_ble_fail[] = {
148148
};
149149
const int tempo_ble_fail = 360;
150150

151-
const int melody_nokia[] = {
152-
// Nokia Ringtone
153-
// Score available at https://musescore.com/user/29944637/scores/5266155
154-
NOTE_E5, 8, NOTE_D5, 8, NOTE_FS4, 4, NOTE_GS4, 4,
155-
NOTE_CS5, 8, NOTE_B4, 8, NOTE_D4, 4, NOTE_E4, 4,
156-
NOTE_B4, 8, NOTE_A4, 8, NOTE_CS4, 4, NOTE_E4, 4,
157-
NOTE_A4, 2,
158-
};
159-
const int tempo_nokia = 180;
160-
161151
const int melody_ble_success[] = {
162152
NOTE_D4,4, NOTE_D4,4, NOTE_G4,4
163153
};

command_interface.c

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "nrf_ble_gatt.h"
1010
#include "user_cfg.h"
1111

12+
extern uint16_t melody_snooze_seconds;
1213
extern uint16_t lfs_file_count;
1314
extern void display_file_count(void);
1415
extern uint8_t lfs_free_space_check(void);
@@ -21,41 +22,41 @@ extern uint16_t m_ble_fus_max_data_len;
2122
extern void user_cfg_set(bool restart_telemetry_timer);
2223
extern struct gotchi_configuration gotchi_cfg_user;
2324

24-
static lfs_file_t file;
25+
extern bool sync_in_progress;
26+
extern struct lfs_config cfg;
27+
extern volatile bool update_rtc;
28+
29+
extern volatile bool log_file_active;
30+
31+
static lfs_file_t file_command_interface;
2532
static uint8_t lfs_file_buf[256]; // Must be cache size
2633
static struct lfs_file_config lfs_file_config;
2734
static lfs_dir_t directory;
2835
static int32_t bytes_sent = -1; //file.ctz.size;
2936

30-
void (*m_ble_tx_logbuffer)(unsigned char *data, unsigned int len);
37+
static void (*m_ble_tx_logbuffer)(unsigned char *data, unsigned int len);
3138
static lfs_t *m_lfs;
3239

3340
static int command_input_index = 0;
3441
static char command_input_buffer[ 128 ] = { 0 };
35-
static unsigned char command_response_buffer[512];
42+
static unsigned char command_response_buffer[256];
3643

37-
extern bool sync_in_progress;
44+
static void (*m_update_time)(int syear, int smonth, int sday, int shour, int sminute, int ssecond);
3845

39-
void command_interface_init(void (*ble_send_logbuffer)(unsigned char *, unsigned int), lfs_t *lfs)
46+
void command_interface_init(void (*ble_send_logbuffer)(unsigned char *, unsigned int), lfs_t *lfs, void (*update_time)(int, int, int, int, int, int))
4047
{
4148
ASSERT(lfs != NULL);
4249
ASSERT(ble_send_logbuffer != NULL);
4350
m_lfs = lfs;
4451
m_ble_tx_logbuffer = ble_send_logbuffer;
52+
m_update_time = update_time;
4553

4654
// Prepare the static file buffer
4755
memset(&lfs_file_config, 0, sizeof(struct lfs_file_config));
4856
lfs_file_config.buffer = lfs_file_buf;
4957
lfs_file_config.attr_count = 0;
5058
}
5159

52-
extern time_t currentTime;
53-
extern struct tm * tmTime;
54-
extern struct lfs_config cfg;
55-
extern volatile bool update_rtc;
56-
57-
extern volatile bool log_file_active;
58-
5960
void command_interface_process_byte(char incoming)
6061
{
6162
command_input_buffer[ command_input_index++ ] = incoming;
@@ -88,7 +89,7 @@ void command_interface_process_byte(char incoming)
8889
if(strncmp(command_input_buffer, "cat", 3) == 0)
8990
{
9091
// Set the file position to what we've received on the client side
91-
lfs_file_seek(m_lfs, &file, atoi(command_input_buffer+4), LFS_SEEK_SET);
92+
lfs_file_seek(m_lfs, &file_command_interface, atoi(command_input_buffer+4), LFS_SEEK_SET);
9293
}
9394
// Continue to send data to the client
9495
command_interface_continue_transfer(command_input_buffer);
@@ -126,13 +127,7 @@ void command_interface_process_byte(char incoming)
126127
NRF_LOG_FLUSH();
127128

128129
// Update time in memory
129-
tmTime->tm_year = syear - 1900;
130-
tmTime->tm_mon = smonth - 1;
131-
tmTime->tm_mday = sday;
132-
tmTime->tm_hour = shour;
133-
tmTime->tm_min = sminute;
134-
tmTime->tm_sec = ssecond;
135-
currentTime = mktime(tmTime);
130+
m_update_time(syear, smonth, sday, shour, sminute, ssecond);
136131

137132
// Update time on RTC
138133
update_rtc = true;
@@ -189,7 +184,7 @@ void command_interface_process_byte(char incoming)
189184

190185
NRF_LOG_INFO("filename %s", filename);
191186
NRF_LOG_FLUSH();
192-
if(lfs_file_opencfg(m_lfs, &file, filename, LFS_O_RDONLY, &lfs_file_config) >= 0)
187+
if(lfs_file_opencfg(m_lfs, &file_command_interface, filename, LFS_O_RDONLY, &lfs_file_config) >= 0)
193188
{
194189
sprintf((char *)command_response_buffer, "cat,%s", filename);
195190
m_ble_tx_logbuffer(command_response_buffer, (size_t)strlen((const char *)command_response_buffer));
@@ -246,7 +241,7 @@ void command_interface_process_byte(char incoming)
246241
}
247242
else if(strncmp(command_input_buffer, "version", 7) == 0)
248243
{
249-
sprintf((char *)command_response_buffer, "version,0.8.2,beta");
244+
sprintf((char *)command_response_buffer, "version,0.9.0,beta");
250245
m_ble_tx_logbuffer(command_response_buffer, strlen((const char *)command_response_buffer));
251246
}
252247
else if(strncmp(command_input_buffer, "getcfg", 6) == 0)
@@ -358,7 +353,7 @@ void command_interface_process_byte(char incoming)
358353
NRF_LOG_FLUSH();
359354
if (sync_in_progress)
360355
{
361-
int close_result = lfs_file_close(m_lfs, &file);
356+
int close_result = lfs_file_close(m_lfs, &file_command_interface);
362357
NRF_LOG_INFO("lfs close result: %d", close_result);
363358
NRF_LOG_FLUSH();
364359
sync_in_progress = false;
@@ -367,6 +362,21 @@ void command_interface_process_byte(char incoming)
367362
NRF_LOG_FLUSH();
368363
}
369364
}
365+
else if(strncmp(command_input_buffer, "snooze,", 7) == 0)
366+
{
367+
// Set melody snooze duration
368+
NRF_LOG_INFO("snooze command received: %s seconds", command_input_buffer+7);
369+
NRF_LOG_FLUSH();
370+
melody_snooze_seconds = atoi(command_input_buffer+7);
371+
}
372+
else if(strncmp(command_input_buffer, "roboid", 6) == 0)
373+
{
374+
// Return robogotchi unique ID
375+
NRF_LOG_INFO("robogotchi ID command received");
376+
NRF_LOG_FLUSH();
377+
sprintf((char *)command_response_buffer, "roboid,%02x%02x", NRF_FICR->DEVICEID[0], NRF_FICR->DEVICEID[1]);
378+
m_ble_tx_logbuffer(command_response_buffer, strlen((const char *)command_response_buffer));
379+
}
370380

371381
memset(command_input_buffer, 0, sizeof(command_input_buffer));
372382
command_input_index = 0;
@@ -417,23 +427,23 @@ void command_interface_continue_transfer(char* command)
417427
NRF_LOG_INFO("command_interface_continue_transfer(TRANSFER_MODE_CAT)");
418428
NRF_LOG_FLUSH();
419429

420-
if(bytes_sent >= file.ctz.size)
430+
if(bytes_sent >= file_command_interface.ctz.size)
421431
{
422432
m_ble_tx_logbuffer((unsigned char *)"cat,complete", strlen("cat,complete"));
423433

424434
NRF_LOG_INFO("finished cat");
425435
NRF_LOG_FLUSH();
426436

427-
int close_result = lfs_file_close(m_lfs, &file);
437+
int close_result = lfs_file_close(m_lfs, &file_command_interface);
428438

429439
NRF_LOG_INFO("cat close result: %d", close_result);
430440
NRF_LOG_FLUSH();
431441

432442
sync_in_progress = false;
433443
}
434-
else if(bytes_sent < file.ctz.size)
444+
else if(bytes_sent < file_command_interface.ctz.size)
435445
{
436-
int32_t read_response = lfs_file_read(m_lfs, &file, &command_response_buffer, m_ble_fus_max_data_len);
446+
int32_t read_response = lfs_file_read(m_lfs, &file_command_interface, &command_response_buffer, m_ble_fus_max_data_len);
437447
if(read_response > 0)
438448
{
439449
m_ble_tx_logbuffer(command_response_buffer, read_response);

command_interface.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ enum{
1212

1313

1414
void command_interface_process_byte( char incoming );
15-
void command_interface_init(void (*ble_send_logbuffer)(unsigned char *, unsigned int), lfs_t *lfs );
15+
void command_interface_init(
16+
void (*ble_send_logbuffer)(unsigned char *, unsigned int),
17+
lfs_t *lfs,
18+
void (*update_time)(int, int, int, int, int, int)
19+
);
1620
void command_interface_continue_transfer();
1721

1822

0 commit comments

Comments
 (0)