Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DmTftLibrary eeprom SX1280Lib filesystem mbed
Fork of MSNV2-Terminal_V1-5 by
Diff: COMPONENTS/generic_component.hpp
- Revision:
- 32:3bef9b81f639
- Parent:
- 31:2b8b98f3feed
--- a/COMPONENTS/generic_component.hpp Wed Oct 03 17:22:58 2018 +0000
+++ b/COMPONENTS/generic_component.hpp Thu Oct 04 07:24:28 2018 +0000
@@ -22,6 +22,10 @@
float val;
char bytes[4];
} FLOATUNION_t;
+typedef union{
+ double val;
+ char bytes[8];
+} DOUBLEUNION_t;
class generic_component : public Component{
@@ -38,7 +42,6 @@
void init(void){
}
-
void readValues(void){
for (std::vector<misnet::Service*>::iterator
srvIt = this->getServices().begin();
@@ -46,8 +49,7 @@
srvIt++) {
(*srvIt)->readValue();
}
- }
-
+ }
InterruptIn interrupt(D9);
private:
@@ -71,36 +73,51 @@
OUTPUT_MODE output_mode,
string comment,
generic_component* parent
- )
+ ) :
+ Service(type, misnet_code, state, access_type, request_mode,
+ up_mode, access_pins, subsample_rate, action, output_mode, comment)
{
this->parent = parent;
- this->setDeviceType(type);
- this->setMisnetCode(misnet_code);
- this->setState(state);
- this->setAccessType(access_type);
- this->setRequestMode(request_mode);
- this->setUpMode(up_mode);
- this->setAction(action);
- this->setOutputMode(output_mode);
- this->setComment(comment);
- this->setSubsampleRate(subsample_rate);
}
virtual ~generic_value() {}
- Value readValue(void){
+ bool readValue(void){
- misnet::Value val;
FLOATUNION_t flt;
char bfr[8];
bfr[0] = this->getMisnetCode(); // service code
- bfr[1] = 0x01; // request value command
+ // TODO handle async calls
+ //switch(this.CALL_TYPE){
+ // case SYNC: bfr[1] = 0x01; break;
+ // case ASYNC: bfr[1] = 0x02; break;
+ //}
+ bfr[1] = 0x01;
i2c.write(address, bfr, 2, false);
+// switch(this.CALL_TYPE){
+// case SYNC:
+// switch(this->getValueAddress().VALUE_TYPE){
+// case Value::NOT_SET : break;
+// case Value::BOOLEAN : break;
+// case Value::CHAR : break;
+// case Value::UINT8_T : break;
+// case Value::INT8_T : break;
+// case Value::UINT16_T : break;
+// case Value::INT16_T : break;
+// case Value::UINT32_T : break;
+// case Value::INT32_T : break;
+// case Value::FLOAT : i2c.read(address, &flt.bytes[0], 4); this->getValueAddress().setFloatValue(flt.val); break; // 32 bits
+// case Value::DOUBLE : break; // 64 bits
+// case Value::TIME : break; // unix time
+// }
+// break;
+// case ASYNC: break;
+// }
i2c.read(address, &flt.bytes[0], 4);
- val.setFloatValue( flt.val);
+ this->getValueAddress().setFloatValue(flt.val);
+ this->savePreviousValue();
DEBUG("received from I2C : %3f - 0x%02x 0x%02x 0x%02x 0x%02x\n",flt.val, flt.bytes[0],flt.bytes[1],flt.bytes[2],flt.bytes[3]);
- return val;
+ return false;
}
-
bool setIrqParams(Service* service, Value threshold, Value up, Value down ){
char bfr[16];
@@ -123,7 +140,6 @@
//else return 1;
return 0;
}
-
void setIrq(Callback <void()> cbck, bool enable){
//parent->interrupt.rise(cbck);
@@ -132,9 +148,8 @@
}
private:
generic_component *parent;
-
+ Timeout reader;
};
};
#endif /* COMPONENTS_GENERIC_COMPONENT_HPP_ */
-
