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

Committer:
Rhyme
Date:
Wed Oct 18 00:31:13 2017 +0000
Revision:
23:e4d2316383a1
Parent:
1:b2a9a6f2c30e
pwm period is now 200us from default 20ms; veml6040->setCOLORCOnf is now AF_BIT | TRIG_BIT from 0x00;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wataloh 0:20bce0dcc921 1 /**
wataloh 0:20bce0dcc921 2 * Copyright 2015 Afero, Inc.
wataloh 0:20bce0dcc921 3 *
wataloh 0:20bce0dcc921 4 * Licensed under the Apache License, Version 2.0 (the "License");
wataloh 0:20bce0dcc921 5 * you may not use this file except in compliance with the License.
wataloh 0:20bce0dcc921 6 * You may obtain a copy of the License at
wataloh 0:20bce0dcc921 7 *
wataloh 0:20bce0dcc921 8 * http://www.apache.org/licenses/LICENSE-2.0
wataloh 0:20bce0dcc921 9 *
wataloh 0:20bce0dcc921 10 * Unless required by applicable law or agreed to in writing, software
wataloh 0:20bce0dcc921 11 * distributed under the License is distributed on an "AS IS" BASIS,
wataloh 0:20bce0dcc921 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
wataloh 0:20bce0dcc921 13 * See the License for the specific language governing permissions and
wataloh 0:20bce0dcc921 14 * limitations under the License.
wataloh 0:20bce0dcc921 15 */
wataloh 0:20bce0dcc921 16
wataloh 0:20bce0dcc921 17 #include "StatusCommand.h"
wataloh 0:20bce0dcc921 18
wataloh 0:20bce0dcc921 19 StatusCommand::StatusCommand(uint16_t bytesToSend) {
wataloh 0:20bce0dcc921 20 _cmd = 0x30;
wataloh 0:20bce0dcc921 21 _bytesToSend = bytesToSend;
wataloh 0:20bce0dcc921 22 _bytesToRecv = 0;
wataloh 0:20bce0dcc921 23 }
wataloh 0:20bce0dcc921 24
wataloh 0:20bce0dcc921 25 StatusCommand::StatusCommand() {
wataloh 0:20bce0dcc921 26 _cmd = 0x30;
wataloh 0:20bce0dcc921 27 _bytesToSend = 0;
wataloh 0:20bce0dcc921 28 _bytesToRecv = 0;
wataloh 0:20bce0dcc921 29 }
wataloh 0:20bce0dcc921 30
wataloh 0:20bce0dcc921 31 StatusCommand::~StatusCommand() {
wataloh 0:20bce0dcc921 32 }
wataloh 0:20bce0dcc921 33
wataloh 0:20bce0dcc921 34 uint16_t StatusCommand::getSize() {
wataloh 0:20bce0dcc921 35 return sizeof(_cmd) + sizeof(_bytesToSend) + sizeof(_bytesToRecv);
wataloh 0:20bce0dcc921 36 }
wataloh 0:20bce0dcc921 37
wataloh 0:20bce0dcc921 38 uint16_t StatusCommand::getBytes(int *bytes) {
wataloh 0:20bce0dcc921 39 int index = 0;
wataloh 0:20bce0dcc921 40
wataloh 0:20bce0dcc921 41 bytes[index++] = (_cmd);
wataloh 0:20bce0dcc921 42 bytes[index++] = (_bytesToSend & 0xff);
wataloh 0:20bce0dcc921 43 bytes[index++] = ((_bytesToSend >> 8) & 0xff);
wataloh 0:20bce0dcc921 44 bytes[index++] = (_bytesToRecv & 0xff);
wataloh 0:20bce0dcc921 45 bytes[index++] = ((_bytesToRecv >> 8) & 0xff);
wataloh 0:20bce0dcc921 46
wataloh 0:20bce0dcc921 47 return index;
wataloh 0:20bce0dcc921 48 }
wataloh 0:20bce0dcc921 49
wataloh 0:20bce0dcc921 50 uint8_t StatusCommand::calcChecksum() {
wataloh 0:20bce0dcc921 51 uint8_t result = 0;
wataloh 0:20bce0dcc921 52
wataloh 0:20bce0dcc921 53 result += (_cmd);
wataloh 0:20bce0dcc921 54 result += (_bytesToSend & 0xff);
wataloh 0:20bce0dcc921 55 result += ((_bytesToSend >> 8) & 0xff);
wataloh 0:20bce0dcc921 56 result += (_bytesToRecv & 0xff);
wataloh 0:20bce0dcc921 57 result += ((_bytesToRecv >> 8) & 0xff);
wataloh 0:20bce0dcc921 58
wataloh 0:20bce0dcc921 59 return result;
wataloh 0:20bce0dcc921 60 }
wataloh 0:20bce0dcc921 61
wataloh 0:20bce0dcc921 62 void StatusCommand::setChecksum(uint8_t checksum) {
wataloh 0:20bce0dcc921 63 _checksum = checksum;
wataloh 0:20bce0dcc921 64 }
wataloh 0:20bce0dcc921 65
wataloh 0:20bce0dcc921 66 uint8_t StatusCommand::getChecksum() {
wataloh 0:20bce0dcc921 67 uint8_t result = 0;
wataloh 0:20bce0dcc921 68
wataloh 0:20bce0dcc921 69 result += (_cmd);
wataloh 0:20bce0dcc921 70 result += (_bytesToSend & 0xff);
wataloh 0:20bce0dcc921 71 result += ((_bytesToSend >> 8) & 0xff);
wataloh 0:20bce0dcc921 72 result += (_bytesToRecv & 0xff);
wataloh 0:20bce0dcc921 73 result += ((_bytesToRecv >> 8) & 0xff);
wataloh 0:20bce0dcc921 74
wataloh 0:20bce0dcc921 75 return result;
wataloh 0:20bce0dcc921 76 }
wataloh 0:20bce0dcc921 77
wataloh 0:20bce0dcc921 78 void StatusCommand::setAck(bool ack) {
wataloh 0:20bce0dcc921 79 _cmd = ack ? 0x31 : 0x30;
wataloh 0:20bce0dcc921 80 }
wataloh 0:20bce0dcc921 81
wataloh 0:20bce0dcc921 82 void StatusCommand::setBytesToSend(uint16_t bytesToSend) {
wataloh 0:20bce0dcc921 83 _bytesToSend = bytesToSend;
wataloh 0:20bce0dcc921 84 }
wataloh 0:20bce0dcc921 85
wataloh 0:20bce0dcc921 86 uint16_t StatusCommand::getBytesToSend() {
wataloh 0:20bce0dcc921 87 return _bytesToSend;
wataloh 0:20bce0dcc921 88 }
wataloh 0:20bce0dcc921 89
wataloh 0:20bce0dcc921 90 void StatusCommand::setBytesToRecv(uint16_t bytesToRecv) {
wataloh 0:20bce0dcc921 91 _bytesToRecv = bytesToRecv;
wataloh 0:20bce0dcc921 92 }
wataloh 0:20bce0dcc921 93
wataloh 0:20bce0dcc921 94 uint16_t StatusCommand::getBytesToRecv() {
wataloh 0:20bce0dcc921 95 return _bytesToRecv;
wataloh 0:20bce0dcc921 96 }
wataloh 0:20bce0dcc921 97
wataloh 0:20bce0dcc921 98 bool StatusCommand::equals(StatusCommand *statusCommand) {
wataloh 0:20bce0dcc921 99 return (_cmd == statusCommand->_cmd && _bytesToSend == statusCommand->_bytesToSend &&
wataloh 0:20bce0dcc921 100 _bytesToRecv == statusCommand->_bytesToRecv);
wataloh 0:20bce0dcc921 101 }
wataloh 0:20bce0dcc921 102
wataloh 0:20bce0dcc921 103 bool StatusCommand::isValid() {
wataloh 0:20bce0dcc921 104 return (_checksum == calcChecksum()) && (_cmd == 0x30 || _cmd == 0x31);
wataloh 0:20bce0dcc921 105 }
wataloh 0:20bce0dcc921 106
wataloh 0:20bce0dcc921 107 void StatusCommand::dumpBytes() {
wataloh 0:20bce0dcc921 108 int len = getSize();
wataloh 0:20bce0dcc921 109 int bytes[len];
wataloh 0:20bce0dcc921 110 getBytes(bytes);
wataloh 0:20bce0dcc921 111
wataloh 1:b2a9a6f2c30e 112 SERIAL_PRINT_DBG_ASR("len : %d\n",len);
wataloh 1:b2a9a6f2c30e 113 SERIAL_PRINT_DBG_ASR("data : ");
wataloh 0:20bce0dcc921 114 for (int i = 0; i < len; i++) {
wataloh 0:20bce0dcc921 115 if (i > 0) {
wataloh 1:b2a9a6f2c30e 116 SERIAL_PRINT_DBG_ASR(", ");
wataloh 0:20bce0dcc921 117 }
wataloh 0:20bce0dcc921 118 int b = bytes[i] & 0xff;
wataloh 0:20bce0dcc921 119 if (b < 0x10) {
wataloh 1:b2a9a6f2c30e 120 SERIAL_PRINT_DBG_ASR("0x%08x",b);
wataloh 0:20bce0dcc921 121 } else {
wataloh 1:b2a9a6f2c30e 122 SERIAL_PRINT_DBG_ASR("0x%08x",b);
wataloh 0:20bce0dcc921 123 }
wataloh 0:20bce0dcc921 124 }
wataloh 1:b2a9a6f2c30e 125 SERIAL_PRINT_DBG_ASR("\n");
wataloh 0:20bce0dcc921 126 }
wataloh 0:20bce0dcc921 127
wataloh 0:20bce0dcc921 128 void StatusCommand::dump() {
wataloh 1:b2a9a6f2c30e 129 SERIAL_PRINT_DBG_ASR("cmd : %s\n",_cmd == 0x30 ? "STATUS" : "STATUS_ACK");
wataloh 1:b2a9a6f2c30e 130 SERIAL_PRINT_DBG_ASR("bytes to send : %d\n",_bytesToSend);
wataloh 1:b2a9a6f2c30e 131 SERIAL_PRINT_DBG_ASR("bytes to receive : %d\n",_bytesToRecv);
wataloh 0:20bce0dcc921 132 }
wataloh 0:20bce0dcc921 133