FrogPilot setup - Handle integer and float parameters
This commit is contained in:
parent
fabfc69788
commit
851f082705
@ -43,6 +43,14 @@ public:
|
|||||||
inline bool getBool(const std::string &key, bool block = false) {
|
inline bool getBool(const std::string &key, bool block = false) {
|
||||||
return get(key, block) == "1";
|
return get(key, block) == "1";
|
||||||
}
|
}
|
||||||
|
inline int getInt(const std::string &key, bool block = false) {
|
||||||
|
std::string value = get(key, block);
|
||||||
|
return value.empty() ? 0 : std::stoi(value);
|
||||||
|
}
|
||||||
|
inline float getFloat(const std::string &key, bool block = false) {
|
||||||
|
std::string value = get(key, block);
|
||||||
|
return value.empty() ? 0.0 : std::stof(value);
|
||||||
|
}
|
||||||
std::map<std::string, std::string> readAll();
|
std::map<std::string, std::string> readAll();
|
||||||
|
|
||||||
// helpers for writing values
|
// helpers for writing values
|
||||||
@ -53,10 +61,24 @@ public:
|
|||||||
inline int putBool(const std::string &key, bool val) {
|
inline int putBool(const std::string &key, bool val) {
|
||||||
return put(key.c_str(), val ? "1" : "0", 1);
|
return put(key.c_str(), val ? "1" : "0", 1);
|
||||||
}
|
}
|
||||||
|
inline int putInt(const std::string &key, int val) {
|
||||||
|
return put(key.c_str(), std::to_string(val).c_str(), std::to_string(val).size());
|
||||||
|
}
|
||||||
|
inline int putFloat(const std::string &key, float val) {
|
||||||
|
return put(key.c_str(), std::to_string(val).c_str(), std::to_string(val).size());
|
||||||
|
}
|
||||||
void putNonBlocking(const std::string &key, const std::string &val);
|
void putNonBlocking(const std::string &key, const std::string &val);
|
||||||
inline void putBoolNonBlocking(const std::string &key, bool val) {
|
inline void putBoolNonBlocking(const std::string &key, bool val) {
|
||||||
putNonBlocking(key, val ? "1" : "0");
|
putNonBlocking(key, val ? "1" : "0");
|
||||||
}
|
}
|
||||||
|
void putIntNonBlocking(const std::string &key, const std::string &val);
|
||||||
|
inline void putIntNonBlocking(const std::string &key, int val) {
|
||||||
|
putNonBlocking(key, std::to_string(val));
|
||||||
|
}
|
||||||
|
void putFloatNonBlocking(const std::string &key, const std::string &val);
|
||||||
|
inline void putFloatNonBlocking(const std::string &key, float val) {
|
||||||
|
putNonBlocking(key, std::to_string(val));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void asyncWriteThread();
|
void asyncWriteThread();
|
||||||
|
@ -17,11 +17,17 @@ cdef extern from "common/params.h":
|
|||||||
c_Params(string) except + nogil
|
c_Params(string) except + nogil
|
||||||
string get(string, bool) nogil
|
string get(string, bool) nogil
|
||||||
bool getBool(string, bool) nogil
|
bool getBool(string, bool) nogil
|
||||||
|
int getInt(string, bool) nogil
|
||||||
|
float getFloat(string, bool) nogil
|
||||||
int remove(string) nogil
|
int remove(string) nogil
|
||||||
int put(string, string) nogil
|
int put(string, string) nogil
|
||||||
void putNonBlocking(string, string) nogil
|
void putNonBlocking(string, string) nogil
|
||||||
void putBoolNonBlocking(string, bool) nogil
|
void putBoolNonBlocking(string, bool) nogil
|
||||||
|
void putIntNonBlocking(string, int) nogil
|
||||||
|
void putFloatNonBlocking(string, float) nogil
|
||||||
int putBool(string, bool) nogil
|
int putBool(string, bool) nogil
|
||||||
|
int putInt(string, int) nogil
|
||||||
|
int putFloat(string, float) nogil
|
||||||
bool checkKey(string) nogil
|
bool checkKey(string) nogil
|
||||||
string getParamPath(string) nogil
|
string getParamPath(string) nogil
|
||||||
void clearAll(ParamKeyType)
|
void clearAll(ParamKeyType)
|
||||||
@ -77,6 +83,20 @@ cdef class Params:
|
|||||||
r = self.p.getBool(k, block)
|
r = self.p.getBool(k, block)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
def get_int(self, key, bool block=False):
|
||||||
|
cdef string k = self.check_key(key)
|
||||||
|
cdef int r
|
||||||
|
with nogil:
|
||||||
|
r = self.p.getInt(k, block)
|
||||||
|
return r
|
||||||
|
|
||||||
|
def get_float(self, key, bool block=False):
|
||||||
|
cdef string k = self.check_key(key)
|
||||||
|
cdef float r
|
||||||
|
with nogil:
|
||||||
|
r = self.p.getFloat(k, block)
|
||||||
|
return r
|
||||||
|
|
||||||
def put(self, key, dat):
|
def put(self, key, dat):
|
||||||
"""
|
"""
|
||||||
Warning: This function blocks until the param is written to disk!
|
Warning: This function blocks until the param is written to disk!
|
||||||
@ -94,6 +114,16 @@ cdef class Params:
|
|||||||
with nogil:
|
with nogil:
|
||||||
self.p.putBool(k, val)
|
self.p.putBool(k, val)
|
||||||
|
|
||||||
|
def put_int(self, key, int val):
|
||||||
|
cdef string k = self.check_key(key)
|
||||||
|
with nogil:
|
||||||
|
self.p.putInt(k, val)
|
||||||
|
|
||||||
|
def put_float(self, key, float val):
|
||||||
|
cdef string k = self.check_key(key)
|
||||||
|
with nogil:
|
||||||
|
self.p.putFloat(k, val)
|
||||||
|
|
||||||
def put_nonblocking(self, key, dat):
|
def put_nonblocking(self, key, dat):
|
||||||
cdef string k = self.check_key(key)
|
cdef string k = self.check_key(key)
|
||||||
cdef string dat_bytes = ensure_bytes(dat)
|
cdef string dat_bytes = ensure_bytes(dat)
|
||||||
@ -105,6 +135,16 @@ cdef class Params:
|
|||||||
with nogil:
|
with nogil:
|
||||||
self.p.putBoolNonBlocking(k, val)
|
self.p.putBoolNonBlocking(k, val)
|
||||||
|
|
||||||
|
def put_int_nonblocking(self, key, int val):
|
||||||
|
cdef string k = self.check_key(key)
|
||||||
|
with nogil:
|
||||||
|
self.p.putIntNonBlocking(k, val)
|
||||||
|
|
||||||
|
def put_float_nonblocking(self, key, float val):
|
||||||
|
cdef string k = self.check_key(key)
|
||||||
|
with nogil:
|
||||||
|
self.p.putFloatNonBlocking(k, val)
|
||||||
|
|
||||||
def remove(self, key):
|
def remove(self, key):
|
||||||
cdef string k = self.check_key(key)
|
cdef string k = self.check_key(key)
|
||||||
with nogil:
|
with nogil:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user