format code
This commit is contained in:
parent
da54029403
commit
3311e7d790
2 changed files with 115 additions and 111 deletions
|
@ -1,5 +1,5 @@
|
|||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include "pico/stdio.h"
|
||||
|
||||
|
@ -7,8 +7,9 @@
|
|||
|
||||
MorseCode::MorseCode() { buildMap(); }
|
||||
|
||||
bool MorseCode::charToMorse(const unsigned char ch, char *morseSymbols) {
|
||||
size_t index{0};
|
||||
bool MorseCode::charToMorse(const unsigned char ch, char *morseSymbols)
|
||||
{
|
||||
size_t index {0};
|
||||
|
||||
if (ch != ' ' && morseMap[ch] == nullptr) {
|
||||
return false;
|
||||
|
@ -35,8 +36,9 @@ bool MorseCode::charToMorse(const unsigned char ch, char *morseSymbols) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void MorseCode::sendCharacter(const char ch) {
|
||||
char morseSymbols[32]{0};
|
||||
void MorseCode::sendCharacter(const char ch)
|
||||
{
|
||||
char morseSymbols[32] {0};
|
||||
|
||||
if (!charToMorse(ch, morseSymbols)) {
|
||||
return;
|
||||
|
@ -47,7 +49,8 @@ void MorseCode::sendCharacter(const char ch) {
|
|||
}
|
||||
}
|
||||
|
||||
void MorseCode::buildMap() {
|
||||
void MorseCode::buildMap()
|
||||
{
|
||||
for (size_t i = 0; i < 256; i++) {
|
||||
if (i == '\"')
|
||||
morseMap[i] = morseTable[0];
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
class MorseCode final {
|
||||
public:
|
||||
class MorseCode final
|
||||
{
|
||||
public:
|
||||
MorseCode();
|
||||
void sendCharacter(const char ch);
|
||||
bool charToMorse(const unsigned char ch, char *morseSymbols);
|
||||
|
||||
private:
|
||||
private:
|
||||
void buildMap();
|
||||
const char *morseMap[256] {nullptr};
|
||||
static constexpr const char *morseTable[] = {
|
||||
|
|
Loading…
Reference in a new issue