Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Inputの抽象クラスを実装 #7
Browse files Browse the repository at this point in the history
  • Loading branch information
H1rono committed Jul 20, 2022
1 parent ce5dd54 commit ec1d426
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 3 additions & 2 deletions include/ssr/AnalogIn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

#include <Arduino.h>
#include "ssr/Types.hpp"
#include "ssr/Input.hpp"

// このライブラリが使う名前空間
namespace ssr {

// アナログ入力ピンを扱う
class AnalogIn {
class AnalogIn : public Input<uint16_t> {
public:
// 接続ピン
const PinType pin;
Expand All @@ -26,7 +27,7 @@ class AnalogIn {
* 接続したピンの値を読む
* @return uint16_t 読んだ値
*/
uint16_t read();
uint16_t read() override;
};

}
Expand Down
5 changes: 3 additions & 2 deletions include/ssr/DigitalIn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

#include <Arduino.h>
#include "ssr/Types.hpp"
#include "ssr/Input.hpp"

// このライブラリが使う名前空間
namespace ssr {

// デジタル入力ピンを扱う
class DigitalIn {
class DigitalIn : Input<bool> {
public:
// 接続ピン
const PinType pin;
Expand All @@ -26,7 +27,7 @@ class DigitalIn {
* 接続したピンの値を読む
* @return bool HIGHならtrue
*/
bool read();
bool read() override;
};

}
Expand Down
24 changes: 24 additions & 0 deletions include/ssr/Input.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#ifndef SSR_INPUT_HPP
#define SSR_INPUT_HPP

// このライブラリが使う名前空間
namespace ssr {

/**
* 入力を受け取るもの全般の抽象型
* @tparam ResultT 読んだ値の型
*/
template<typename ResultT> class Input {
public:
/**
* 値を読む
* @return ResultT 読み取った値
*/
virtual ResultT read() = 0;
};

} /* namespace ssr */

#endif /* SSR_INPUT_HPP */

0 comments on commit ec1d426

Please sign in to comment.