Skip to content

Commit 1305ce9

Browse files
authored
Merge pull request #366 from FujiNetWIFI/sam
cat 40-char print buffers for SAM
2 parents 50c31a7 + f0a6528 commit 1305ce9

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

include/version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#define FN_VERSION_MAJOR 0
1111
#define FN_VERSION_MINOR 1
1212

13-
#define FN_VERSION_BUILD "f201abd2"
13+
#define FN_VERSION_BUILD "50c31a74"
1414

15-
#define FN_VERSION_DATE "2020-09-20 20:18:37"
15+
#define FN_VERSION_DATE "2020-09-24 02:16:34"
1616

17-
#define FN_VERSION_FULL "0.1.f201abd2"
17+
#define FN_VERSION_FULL "0.1.50c31a74"

lib/sam/sam.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void Init()
9898
#ifdef BOARD_HAS_PSRAM
9999
//buffer = (char*)ps_malloc(22050 * 5);
100100
// switch to ESP-IDF equivalent
101-
buffer = (char *)heap_caps_malloc(22050 * 5, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
101+
buffer = (char *)heap_caps_malloc(22050 * 10, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
102102
#else
103103
buffer = malloc(22050 * 5); // careful not to malloc too much!
104104
#endif

lib/sio/voice.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using namespace std;
88

99
void sioVoice::sio_sam_parameters()
1010
{
11-
string s = string((char *)sioBuffer);
11+
string s = string((char *)lineBuffer); // change to lineBuffer
1212
vector<string> tokens = util_tokenize(s, ' ');
1313

1414
for (vector<string>::iterator it = tokens.begin(); it != tokens.end(); ++it)
@@ -56,17 +56,10 @@ void sioVoice::sio_sam()
5656
{
5757
int n = 0;
5858
char *a[16];
59-
int i = 0;
59+
// int i = 0;
6060

61-
memset(samBuffer,0,sizeof(samBuffer));
62-
memset(a,0,sizeof(a));
63-
64-
while (sioBuffer[i] != EOL && i < 39)
65-
{
66-
i++;
67-
}
68-
69-
sioBuffer[i] = '\0';
61+
memset(samBuffer, 0, sizeof(samBuffer));
62+
memset(a, 0, sizeof(a));
7063

7164
// Construct parameter buffer.
7265
a[n++] = (char *)("sam");
@@ -126,7 +119,27 @@ void sioVoice::sio_write()
126119

127120
if (ck == sio_checksum(sioBuffer, n))
128121
{
129-
sio_sam();
122+
// append sioBuffer onto lineBuffer until EOL is reached
123+
// move this logic to append \0 into sio_write
124+
uint8_t i = 0;
125+
while (i < 40)
126+
{
127+
if (sioBuffer[i] != EOL && buffer_idx < 121)
128+
{
129+
lineBuffer[buffer_idx] = sioBuffer[i];
130+
buffer_idx++;
131+
}
132+
else
133+
{
134+
lineBuffer[buffer_idx] = '\0';
135+
buffer_idx = 0;
136+
sio_sam();
137+
// clear lineBuffer
138+
memset(lineBuffer, 0, sizeof(lineBuffer));
139+
break;
140+
}
141+
i++;
142+
}
130143
sio_complete();
131144
}
132145
else
@@ -143,7 +156,7 @@ void sioVoice::sio_status()
143156

144157
status[0] = 0;
145158
status[1] = lastAux1;
146-
status[2] = 5;
159+
status[2] = 15; // set timeout > 10 seconds (SAM audio buffer)
147160
status[3] = 0;
148161

149162
sio_to_computer(status, sizeof(status), false);

lib/sio/voice.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ class sioVoice : public sioDevice
1010
protected:
1111
// act like a printer for POC
1212
uint8_t lastAux1 = 0;
13-
13+
uint8_t buffer_idx = 0;
1414
uint8_t sioBuffer[41];
15-
uint8_t samBuffer[41];
15+
uint8_t lineBuffer[121];
16+
uint8_t samBuffer[121];
1617
void sio_write();
1718

1819
void sio_process(uint32_t commanddata, uint8_t checksum) override;

0 commit comments

Comments
 (0)