Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion OIL.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Status: `open`, `in progress`, `done`, `dropped` (with the reason in the item).
| 38 | Results that must not be ignored | 36 | done | #94 |
| 39 | MC/DC coverage | 34 | done | #95, #96 |
| 40 | Braced initialization checked | 34 | done | #93 |
| 41 | The template's rules that review checks | 36 | in progress | #99, #100, #101, #102, #104, #105, #106, #107, #113, #115, #116, #117, #118, #121, #122, #124, #125, #126, #127, #128, #129, #130 |
| 41 | The template's rules that review checks | 36 | in progress | #99, #100, #101, #102, #104, #105, #106, #107, #113, #115, #116, #117, #118, #121, #122, #124, #125, #126, #127, #128, #129, #130, #132 |
| 42 | A newer avr-gcc as a cross-check | 41 | done | |
| 43 | Bit operations in one class, from the template | 41 | done | #109 |

Expand Down Expand Up @@ -1233,6 +1233,19 @@ as `lround()` did, which takes its `double` (H-7). Left for the compiler that is
container: the Windows half of the serial port declares some variables ahead, which only got
their initializers here.

As reviewed for the chapter Classes on 2026-11-17, its review parts C-2, C-3, C-6, C-8, C-11 and
C-13, in the library and the host code. Every class but those of `src/Utility/` began with its
private members; all are in the order of C-2 now, public, protected, private, and in each types
and constants, constructors, functions, data members, the text moved and not changed. A class
that declares a special member declares all six (C-3): the moves are deleted where the copies
were, and `Matrix` and `Batch` delete their default constructor; `SimulatorWebHost`, which held
sockets without a destructor and so kept its port taken until the program ended, closes them
now, which a test checks. The virtual functions of `ControlPort` give a reason C-6 takes, the
cost that does not count on a PC and one class for both kinds of port, not a test's; `MatrixOf`
and the control program's windows say why they derive (C-8). Nothing to change for C-11, as no
member is `mutable`, nor for C-13, as the operators are the bitwise ones of `Byte` and the
comparisons of `Status` and `Result`.

### 42 A newer avr-gcc as a cross-check

`max_matrix::Byte` (41) made the examples 30 to 50 bytes of flash larger on the Uno at first,
Expand Down
60 changes: 31 additions & 29 deletions control/ControlDotPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,10 @@
* simulator's page draws them. What it shows is the last picture it was given,
* from SerialControl's answer to `picture`; a click or Clear() changes it at
* once, so that the click shows before the next picture does.
*
* Derived from wxPanel, as wxWidgets makes a control of its own (C-8).
*/
class ControlDotPanel : public wxPanel {
private:
/* the LED under a point, as GetDotAt() finds it, if there is one: named
* members, which a call cannot swap (FN-16) */
struct Dot {
bool found;
uint8_t column;
uint8_t row;
};

/* one byte per column, bit 0 the top row, as SerialControl answers picture */
std::vector<uint8_t> columns_;
std::function<void(uint8_t, uint8_t, bool)> on_switch_;
/* while the button is held: the state every LED passed takes, and the LED the
* mouse was on last, if it was on one */
bool painting_{false};
bool paint_lit_{false};
bool on_dot_{false};
uint8_t last_column_{0};
uint8_t last_row_{0};

void OnPaint(wxPaintEvent& event);
void OnLeftDown(wxMouseEvent& event);
void OnMotion(wxMouseEvent& event);
void OnLeftUp(wxMouseEvent& event);
void OnCaptureLost(wxMouseCaptureLostEvent& event);
void PaintDot(uint8_t column, uint8_t row);
MAXMATRIX_NODISCARD bool IsLit(uint8_t column, uint8_t row) const;
MAXMATRIX_NODISCARD Dot GetDotAt(wxPoint point) const;

public:
/*!
* \brief Makes the panel with every LED off.
Expand All @@ -84,6 +57,35 @@ class ControlDotPanel : public wxPanel {

/*! \brief Turns every LED off. */
void Clear();

private:
/* the LED under a point, as GetDotAt() finds it, if there is one: named
* members, which a call cannot swap (FN-16) */
struct Dot {
bool found;
uint8_t column;
uint8_t row;
};

void OnPaint(wxPaintEvent& event);
void OnLeftDown(wxMouseEvent& event);
void OnMotion(wxMouseEvent& event);
void OnLeftUp(wxMouseEvent& event);
void OnCaptureLost(wxMouseCaptureLostEvent& event);
void PaintDot(uint8_t column, uint8_t row);
MAXMATRIX_NODISCARD bool IsLit(uint8_t column, uint8_t row) const;
MAXMATRIX_NODISCARD Dot GetDotAt(wxPoint point) const;

/* one byte per column, bit 0 the top row, as SerialControl answers picture */
std::vector<uint8_t> columns_;
std::function<void(uint8_t, uint8_t, bool)> on_switch_;
/* while the button is held: the state every LED passed takes, and the LED the
* mouse was on last, if it was on one */
bool painting_{false};
bool paint_lit_{false};
bool on_dot_{false};
uint8_t last_column_{0};
uint8_t last_row_{0};
};

#endif // MAXMATRIX_CONTROL_CONTROLDOTPANEL_H_
40 changes: 20 additions & 20 deletions control/ControlLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,6 @@ struct ControlLinkLines {
* passed on as a line.
*/
class ControlLink {
private:
std::reference_wrapper<ControlPort> port_;
bool ready_{false};
/* what has arrived after the last line feed */
std::string received_;
std::vector<uint8_t> picture_;
/*
* Whether an answer to picture is due, and since when; picture_asked_at_
* holds a time only once the picture has been asked for since Begin(), so
* that the first time it is at once. SerialControl answers in order, so an
* answer to a picture asked for before a command shows the matrix before it,
* and is dropped as stale.
*/
bool picture_asked_{false};
bool picture_stale_{false};
bool picture_timed_{false};
uint32_t picture_asked_at_{0};

MAXMATRIX_NODISCARD bool Take(std::string const& line);

public:
/*!
* \brief Makes a link over `port`, which is not ready until Begin().
Expand Down Expand Up @@ -139,6 +119,26 @@ class ControlLink {
* \return The lines that have arrived, and whether the port is still open.
*/
MAXMATRIX_NODISCARD ControlLinkLines Task();

private:
MAXMATRIX_NODISCARD bool Take(std::string const& line);

std::reference_wrapper<ControlPort> port_;
bool ready_{false};
/* what has arrived after the last line feed */
std::string received_;
std::vector<uint8_t> picture_;
/*
* Whether an answer to picture is due, and since when; picture_asked_at_
* holds a time only once the picture has been asked for since Begin(), so
* that the first time it is at once. SerialControl answers in order, so an
* answer to a picture asked for before a command shows the matrix before it,
* and is dropped as stale.
*/
bool picture_asked_{false};
bool picture_stale_{false};
bool picture_timed_{false};
uint32_t picture_asked_at_{0};
};

#endif // MAXMATRIX_CONTROL_CONTROLLINK_H_
7 changes: 4 additions & 3 deletions control/ControlPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
* ControlLink needs to know neither. How a port is opened differs, so each kind
* has an Open() of its own.
*
* Virtual functions, which the library avoids for the RAM of their tables on
* the Uno: the program runs on a PC, and a test hands ControlLink a port of its
* own.
* C-6, virtual functions, which the library avoids for the RAM of their tables
* on the Uno and for calls that cannot be inlined: the program runs on a PC,
* where neither counts, and the window holds a link over each kind of port, as
* one class rather than a template made twice of the same code.
*/
class ControlPort {
public:
Expand Down
21 changes: 12 additions & 9 deletions control/ControlSerialPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@
* say `ready`.
*/
class ControlSerialPort final : public ControlPort {
private:
#ifdef _WIN32
void* handle_;
#else
int descriptor_{-1};

MAXMATRIX_NODISCARD bool Configure(uint32_t baud_rate);
#endif

public:
/*! \brief Makes a port that is closed until Open(). */
ControlSerialPort();
Expand All @@ -49,6 +40,9 @@ class ControlSerialPort final : public ControlPort {
// A copy would close the port of the original a second time.
ControlSerialPort(ControlSerialPort const&) = delete;
ControlSerialPort& operator=(ControlSerialPort const&) = delete;
// Nor a move, which nothing needs.
ControlSerialPort(ControlSerialPort&&) = delete;
ControlSerialPort& operator=(ControlSerialPort&&) = delete;

/*!
* \brief Opens the port `name` at `baud_rate`.
Expand Down Expand Up @@ -78,6 +72,15 @@ class ControlSerialPort final : public ControlPort {
bool Write(std::string const& data) override;
bool Read(std::string& data) override;
void Close() override;

private:
#ifdef _WIN32
void* handle_;
#else
int descriptor_{-1};

MAXMATRIX_NODISCARD bool Configure(uint32_t baud_rate);
#endif
};

#endif // MAXMATRIX_CONTROL_CONTROLSERIALPORT_H_
13 changes: 8 additions & 5 deletions control/ControlTcpPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
* as an end that is gone.
*/
class ControlTcpPort final : public ControlPort {
private:
// A POSIX descriptor or a Winsock SOCKET, which is an unsigned integer as
// wide as a pointer; -1 for none, which is what INVALID_SOCKET is as well.
intptr_t socket_;

public:
/*! \brief Makes a port that is closed until Open(). */
ControlTcpPort();
Expand All @@ -41,6 +36,9 @@ class ControlTcpPort final : public ControlPort {
// A copy would close the socket of the original a second time.
ControlTcpPort(ControlTcpPort const&) = delete;
ControlTcpPort& operator=(ControlTcpPort const&) = delete;
// Nor a move, which nothing needs.
ControlTcpPort(ControlTcpPort&&) = delete;
ControlTcpPort& operator=(ControlTcpPort&&) = delete;

/*!
* \brief Connects to the simulator on localhost.
Expand All @@ -56,6 +54,11 @@ class ControlTcpPort final : public ControlPort {
bool Write(std::string const& data) override;
bool Read(std::string& data) override;
void Close() override;

private:
// A POSIX descriptor or a Winsock SOCKET, which is an unsigned integer as
// wide as a pointer; -1 for none, which is what INVALID_SOCKET is as well.
intptr_t socket_;
};

#endif // MAXMATRIX_CONTROL_CONTROLTCPPORT_H_
57 changes: 29 additions & 28 deletions control/ControlWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,15 @@ class ControlDotPanel;
* that the two agree.
*
* It holds no logic a test would need: the lines are ControlCommand's, the
* connections ControlLink's, so the window itself is checked by hand.
* connections ControlLink's, so the window itself is checked by hand. Derived
* from wxFrame, as wxWidgets makes a window of its own (C-8).
*/
class ControlWindow : public wxFrame {
private:
ControlSerialPort serial_port_;
ControlTcpPort tcp_port_;
ControlLink board_link_;
ControlLink simulator_link_;
wxTimer timer_;
std::string last_setting_;

wxWindow* controls_;
wxTextCtrl* text_{};
wxStaticText* bytes_left_{};
wxButton* send_{};
wxCheckBox* shift_{};
wxSpinCtrl* space_{};
wxSlider* intensity_{};
wxSlider* speed_{};
ControlDotPanel* dots_{};
wxComboBox* serial_port_name_{};
wxButton* board_button_{};
wxStaticText* board_status_{};
wxSpinCtrl* tcp_port_number_{};
wxButton* simulator_button_{};
wxStaticText* simulator_status_{};
wxTextCtrl* log_{};
public:
/*! \brief Makes the window, with nothing connected. */
ControlWindow();

private:
void MakeMenu();
MAXMATRIX_NODISCARD wxWindow* MakeMatrix(wxWindow* parent);
MAXMATRIX_NODISCARD wxWindow* MakeText(wxWindow* parent);
Expand Down Expand Up @@ -106,9 +87,29 @@ class ControlWindow : public wxFrame {
void Log(wxString const& text);
MAXMATRIX_NODISCARD static wxString ConvertToText(std::string const& line);

public:
/*! \brief Makes the window, with nothing connected. */
ControlWindow();
ControlSerialPort serial_port_;
ControlTcpPort tcp_port_;
ControlLink board_link_;
ControlLink simulator_link_;
wxTimer timer_;
std::string last_setting_;

wxWindow* controls_;
wxTextCtrl* text_{};
wxStaticText* bytes_left_{};
wxButton* send_{};
wxCheckBox* shift_{};
wxSpinCtrl* space_{};
wxSlider* intensity_{};
wxSlider* speed_{};
ControlDotPanel* dots_{};
wxComboBox* serial_port_name_{};
wxButton* board_button_{};
wxStaticText* board_status_{};
wxSpinCtrl* tcp_port_number_{};
wxButton* simulator_button_{};
wxStaticText* simulator_status_{};
wxTextCtrl* log_{};
};

#endif // MAXMATRIX_CONTROL_CONTROLWINDOW_H_
12 changes: 6 additions & 6 deletions docu/DocuSvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ struct DocuFont {

/*! \brief A picture as SVG text, for the pictures in docu/. */
class DocuSvg {
private:
uint16_t width_;
uint16_t height_;
int32_t top_;
std::ostringstream body_;

public:
/*!
* \brief Makes an empty picture with a white background.
Expand Down Expand Up @@ -109,6 +103,12 @@ class DocuSvg {
*/
void AddArrow(DocuPoint from, int32_t to_x, int32_t thickness,
char const* colour);

private:
uint16_t width_;
uint16_t height_;
int32_t top_;
std::ostringstream body_;
};

#endif // MAXMATRIX_DOCU_DOCUSVG_H_
Loading