pwm period is now 200us instead of the default 20ms veml6040 config is now AF_BIT | TRIG_BIT

Dependencies:   mbed MMA8451Q USBDevice WakeUp vt100

Fork of afero_node_suntory_2017_06_15 by Orefatoi

Revision:
0:20bce0dcc921
Child:
1:b2a9a6f2c30e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/afLib/StatusCommand.cpp	Tue Dec 20 01:51:02 2016 +0000
@@ -0,0 +1,133 @@
+/**
+ * Copyright 2015 Afero, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "StatusCommand.h"
+
+StatusCommand::StatusCommand(uint16_t bytesToSend) {
+    _cmd = 0x30;
+    _bytesToSend = bytesToSend;
+    _bytesToRecv = 0;
+}
+
+StatusCommand::StatusCommand() {
+    _cmd = 0x30;
+    _bytesToSend = 0;
+    _bytesToRecv = 0;
+}
+
+StatusCommand::~StatusCommand() {
+}
+
+uint16_t StatusCommand::getSize() {
+    return sizeof(_cmd) + sizeof(_bytesToSend) + sizeof(_bytesToRecv);
+}
+
+uint16_t StatusCommand::getBytes(int *bytes) {
+    int index = 0;
+
+    bytes[index++] = (_cmd);
+    bytes[index++] = (_bytesToSend & 0xff);
+    bytes[index++] = ((_bytesToSend >> 8) & 0xff);
+    bytes[index++] = (_bytesToRecv & 0xff);
+    bytes[index++] = ((_bytesToRecv >> 8) & 0xff);
+
+    return index;
+}
+
+uint8_t StatusCommand::calcChecksum() {
+    uint8_t result = 0;
+
+    result += (_cmd);
+    result += (_bytesToSend & 0xff);
+    result += ((_bytesToSend >> 8) & 0xff);
+    result += (_bytesToRecv & 0xff);
+    result += ((_bytesToRecv >> 8) & 0xff);
+
+    return result;
+}
+
+void StatusCommand::setChecksum(uint8_t checksum) {
+    _checksum = checksum;
+}
+
+uint8_t StatusCommand::getChecksum() {
+    uint8_t result = 0;
+
+    result += (_cmd);
+    result += (_bytesToSend & 0xff);
+    result += ((_bytesToSend >> 8) & 0xff);
+    result += (_bytesToRecv & 0xff);
+    result += ((_bytesToRecv >> 8) & 0xff);
+
+    return result;
+}
+
+void StatusCommand::setAck(bool ack) {
+    _cmd = ack ? 0x31 : 0x30;
+}
+
+void StatusCommand::setBytesToSend(uint16_t bytesToSend) {
+    _bytesToSend = bytesToSend;
+}
+
+uint16_t StatusCommand::getBytesToSend() {
+    return _bytesToSend;
+}
+
+void StatusCommand::setBytesToRecv(uint16_t bytesToRecv) {
+    _bytesToRecv = bytesToRecv;
+}
+
+uint16_t StatusCommand::getBytesToRecv() {
+    return _bytesToRecv;
+}
+
+bool StatusCommand::equals(StatusCommand *statusCommand) {
+    return (_cmd == statusCommand->_cmd && _bytesToSend == statusCommand->_bytesToSend &&
+            _bytesToRecv == statusCommand->_bytesToRecv);
+}
+
+bool StatusCommand::isValid() {
+    return (_checksum == calcChecksum()) && (_cmd == 0x30 || _cmd == 0x31);
+}
+
+void StatusCommand::dumpBytes() {
+    int len = getSize();
+    int bytes[len];
+    getBytes(bytes);
+
+    SERIAL_PRINT_DBG("len  : %d\n",len);
+    SERIAL_PRINT_DBG("data : ");
+    for (int i = 0; i < len; i++) {
+        if (i > 0) {
+            SERIAL_PRINT_DBG(", ");
+        }
+        int b = bytes[i] & 0xff;
+        if (b < 0x10) {
+            SERIAL_PRINT_DBG("0x%08x",b);
+        } else {
+            SERIAL_PRINT_DBG("0x%08x",b);
+        }
+    }
+    SERIAL_PRINT_DBG("\n");
+}
+
+void StatusCommand::dump() {
+    SERIAL_PRINT_DBG("cmd              : %s\n",_cmd == 0x30 ? "STATUS" : "STATUS_ACK");
+    SERIAL_PRINT_DBG("bytes to send    : %d\n",_bytesToSend);
+    SERIAL_PRINT_DBG("bytes to receive : %d\n",_bytesToRecv);
+}
+