Formatted code (#1007)

* Updated style

* Updated files

* fixed new line

* Updated spacing

* File fix WIP

* Updated to clang 13

* updated comment style

* Removed old comment code
This commit is contained in:
jLynx 2023-05-19 08:16:05 +12:00 committed by GitHub
parent 7aca7ce74d
commit 033c4e9a5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
599 changed files with 70746 additions and 66896 deletions

View file

@ -31,61 +31,59 @@ using namespace portapack;
namespace morse {
// Returns 0 if message is too long
size_t morse_encode(std::string& message, const uint32_t time_unit_ms,
const uint32_t tone, uint32_t * const time_units) {
size_t i, c;
uint16_t code, code_size;
uint8_t morse_message[256];
uint32_t delta;
*time_units = 0;
i = 0;
for (char& ch : message) {
if (i > 256) return 0; // Message too long
if ((ch >= 'a') && (ch <= 'z')) // Make uppercase
ch -= 32;
if ((ch >= '!') && (ch <= '_')) {
code = morse_ITU[ch - '!'];
} else {
code = 0; // Default to space char
}
if (!code) {
if (i)
morse_message[i - 1] = 4; // Word space
} else {
code_size = code & 7;
for (c = 0; c < code_size; c++) {
morse_message[i++] = ((code << c) & 0x8000) ? 1 : 0; // Dot/dash
morse_message[i++] = 2; // Symbol space
}
morse_message[i - 1] = 3; // Letter space
}
}
// Count time units
for (c = 0; c < i; c++) {
*time_units += morse_symbols[morse_message[c]];
}
memcpy(shared_memory.bb_data.tones_data.message, morse_message, i);
// Setup tone "symbols"
for (c = 0; c < 5; c++) {
if (c < 2)
delta = TONES_F2D(tone, TONES_SAMPLERATE); // Dot and dash
else
delta = 0; // Pause
baseband::set_tone(c, delta, (TONES_SAMPLERATE * morse_symbols[c] * time_unit_ms) / 1000);
}
return i;
size_t morse_encode(std::string& message, const uint32_t time_unit_ms, const uint32_t tone, uint32_t* const time_units) {
size_t i, c;
uint16_t code, code_size;
uint8_t morse_message[256];
uint32_t delta;
*time_units = 0;
i = 0;
for (char& ch : message) {
if (i > 256) return 0; // Message too long
if ((ch >= 'a') && (ch <= 'z')) // Make uppercase
ch -= 32;
if ((ch >= '!') && (ch <= '_')) {
code = morse_ITU[ch - '!'];
} else {
code = 0; // Default to space char
}
if (!code) {
if (i)
morse_message[i - 1] = 4; // Word space
} else {
code_size = code & 7;
for (c = 0; c < code_size; c++) {
morse_message[i++] = ((code << c) & 0x8000) ? 1 : 0; // Dot/dash
morse_message[i++] = 2; // Symbol space
}
morse_message[i - 1] = 3; // Letter space
}
}
// Count time units
for (c = 0; c < i; c++) {
*time_units += morse_symbols[morse_message[c]];
}
memcpy(shared_memory.bb_data.tones_data.message, morse_message, i);
// Setup tone "symbols"
for (c = 0; c < 5; c++) {
if (c < 2)
delta = TONES_F2D(tone, TONES_SAMPLERATE); // Dot and dash
else
delta = 0; // Pause
baseband::set_tone(c, delta, (TONES_SAMPLERATE * morse_symbols[c] * time_unit_ms) / 1000);
}
return i;
}
} /* namespace morse */