Nol.A SDK Library 26.11.2
For IoT System Software Development
Loading...
Searching...
No Matches
ConfigBool Class Reference
Inheritance diagram for ConfigBool:
ConfigNumber< bool > ConfigItem

Public Member Functions

 ConfigBool (const char *name, Storage &s, uint64_t addr, void(*onSet)(bool)=nullptr)
bool handleCommand (const char *input, Print &p) override
void print (Print &p) override
bool isValid () override
bool getValue () override
void printHelp (Print &p)
Public Member Functions inherited from ConfigNumber< bool >
 ConfigNumber (const char *name, Storage &s, uint64_t addr, bool min, bool max, void(*onSet)(bool)=nullptr)
const char * getName () override
virtual error_t setValue (bool newValue)

Additional Inherited Members

Protected Member Functions inherited from ConfigNumber< bool >
virtual void onValueSet () override
Protected Attributes inherited from ConfigNumber< bool >
char * name
Storage & flash
const uint64_t addr
bool min
bool max
void(* onSet )(bool)

Detailed Description

Constructor & Destructor Documentation

◆ ConfigBool()

ConfigBool::ConfigBool ( const char * name,
Storage & s,
uint64_t addr,
void(* onSet )(bool) = nullptr )
inline
9 : ConfigNumber<bool>(name, s, addr, false, true, onSet) {
10 };

Member Function Documentation

◆ getValue()

bool ConfigBool::getValue ( )
inlineoverridevirtual

Reimplemented from ConfigNumber< bool >.

69 {
70 bool val;
71 this->flash.read(&val, this->addr, sizeof(bool));
72 return val;
73 };

◆ handleCommand()

bool ConfigBool::handleCommand ( const char * input,
Print & p )
inlineoverridevirtual

Reimplemented from ConfigNumber< bool >.

12 {
13 std::string command = "get ";
14 command += this->name;
15
16 if (command == input) {
17 p.printf("\"result\":\"OK\",\"%s\":", this->name);
18 this->print(p);
19 return true;
20 }
21
22 command = "set ";
23 command += this->name;
24 command += ' ';
25
26 std::string inputCommand = input;
27 if (inputCommand.find(command) == 0) {
28 inputCommand = inputCommand.substr(command.length());
29 bool v;
30 if (inputCommand == "true") {
31 v = true;
32 } else if (inputCommand == "false") {
33 v = false;
34 } else {
35 p.printf("\"result\":\"parsing error: %s\"", inputCommand.c_str());
36 return true;
37 }
38
39 error_t err = this->flash.write((const uint8_t *) &v, this->addr, sizeof(bool));
40 if (err == ERROR_SUCCESS) {
41 p.printf("\"result\":\"OK\",\"%s\":", this->name);
42 this->print(p);
43 this->onValueSet();
44 } else {
45 p.printf("\"result\":\"error (%d)\"", err);
46 }
47 return true;
48 }
49
50 return false;
51 };
virtual int printf(const char *,...)
printf 출력을 내보냅니다.
Definition Print.hpp:234
@ ERROR_SUCCESS
Definition nola-common.h:119

◆ isValid()

bool ConfigBool::isValid ( )
inlineoverridevirtual

Reimplemented from ConfigNumber< bool >.

64 {
65 bool val = this->getValue();
66 return (val == true || val == false);
67 };

◆ print()

void ConfigBool::print ( Print & p)
inlineoverridevirtual

Reimplemented from ConfigNumber< bool >.

53 {
54 bool val = this->getValue();
55 if (val == true) {
56 p.print("true");
57 } else if (val == false) {
58 p.print("false");
59 } else {
60 p.printf("%d /* ? */", val);
61 }
62 };
size_t print(const __FlashStringHelper *)
프로그램 메모리(읽기 전용 플래시) 영역에 저장된 문자열을 출력합니다.

◆ printHelp()

void ConfigBool::printHelp ( Print & p)
inlinevirtual

Reimplemented from ConfigNumber< bool >.

75 {
76 p.printf("[\"get %s\"", this->getName());
77 p.printf(",\"set %s [true or false]\"]", this->getName());
78 }

The documentation for this class was generated from the following file: