format code

This commit is contained in:
Martin Brodbeck 2024-02-29 09:27:59 +01:00
parent da54029403
commit 3311e7d790
2 changed files with 115 additions and 111 deletions

View file

@ -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];

View file

@ -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[] = {