Temporary Connector Reversed Version

Dependencies:   UniGraphic mbed vt100

afero_poc15_180403R , J1 のピン配置を反転させたヴァージョンです。

Color2系を使用するためには以下のピンをジャンパで接続してください。
J1-D7 <-> J1-D0
J1-D6 <-> J1-D1

(調査中) また、こちらでテストした範囲では、
FRDM-KL25Z の V3.3 を、Modulo2 の VCC_3V3 ピンに接続してやる必要がありました。

尚、J1-D1, D0 を使用するために UART を無効にしているため
ログは表示されません。

TFTモジュールについて 
aitendoのTFTモジュールはデフォルトでは8bit bus モードになっています。
/media/uploads/Rhyme/img_2364.jpg

半田のジャンパを変えて、SPIの設定にしてください。
/media/uploads/Rhyme/img_2363.jpg

サーミスタについて
POC1.5 では サーミスタは 25℃の時に抵抗値が 50.0kΩになる502AT-11 が
4.95kΩのプルアップ(実際は10kΩx2の並列)で使用されていました。

今回の試作では抵抗値が 10.0kΩの 103AT-11 が
5.1kΩのプルアップで使用されていますので、係数を合わせるために
SMTC502AT-11 のコンストラクタを 
R0 = 10.0
R1 = 5.1
B = 3435
T0 = 298.15
で呼ぶように変更しました。

Committer:
Rhyme
Date:
Tue Apr 24 08:58:33 2018 +0000
Revision:
0:0b6732b53bf4
Temporary Connector Reversed Version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:0b6732b53bf4 1 /**
Rhyme 0:0b6732b53bf4 2 * Copyright 2015 Afero, Inc.
Rhyme 0:0b6732b53bf4 3 *
Rhyme 0:0b6732b53bf4 4 * Licensed under the Apache License, Version 2.0 (the "License");
Rhyme 0:0b6732b53bf4 5 * you may not use this file except in compliance with the License.
Rhyme 0:0b6732b53bf4 6 * You may obtain a copy of the License at
Rhyme 0:0b6732b53bf4 7 *
Rhyme 0:0b6732b53bf4 8 * http://www.apache.org/licenses/LICENSE-2.0
Rhyme 0:0b6732b53bf4 9 *
Rhyme 0:0b6732b53bf4 10 * Unless required by applicable law or agreed to in writing, software
Rhyme 0:0b6732b53bf4 11 * distributed under the License is distributed on an "AS IS" BASIS,
Rhyme 0:0b6732b53bf4 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Rhyme 0:0b6732b53bf4 13 * See the License for the specific language governing permissions and
Rhyme 0:0b6732b53bf4 14 * limitations under the License.
Rhyme 0:0b6732b53bf4 15 */
Rhyme 0:0b6732b53bf4 16
Rhyme 0:0b6732b53bf4 17 //wsugi #include "Arduino.h"
Rhyme 0:0b6732b53bf4 18 #include "mbed.h"
Rhyme 0:0b6732b53bf4 19 #include <stdio.h>
Rhyme 0:0b6732b53bf4 20 #include "Command.h"
Rhyme 0:0b6732b53bf4 21 #include "msg_types.h"
Rhyme 0:0b6732b53bf4 22
Rhyme 0:0b6732b53bf4 23 #define SERIAL_PRINT_DBG_ASR_ON 0
Rhyme 0:0b6732b53bf4 24
Rhyme 0:0b6732b53bf4 25 #define CMD_HDR_LEN 4 // 4 byte header on all commands
Rhyme 0:0b6732b53bf4 26 #define CMD_VAL_LEN 2 // 2 byte value length for commands that have a value
Rhyme 0:0b6732b53bf4 27
Rhyme 0:0b6732b53bf4 28 const char *CMD_NAMES[] = {"SET ", "GET ", "UPDATE"};
Rhyme 0:0b6732b53bf4 29
Rhyme 0:0b6732b53bf4 30
Rhyme 0:0b6732b53bf4 31 Command::Command(uint16_t len, uint8_t *bytes) {
Rhyme 0:0b6732b53bf4 32 int index = 0;
Rhyme 0:0b6732b53bf4 33
Rhyme 0:0b6732b53bf4 34 _cmd = bytes[index++];
Rhyme 0:0b6732b53bf4 35 _requestId = bytes[index++];
Rhyme 0:0b6732b53bf4 36 _attrId = bytes[index + 0] | bytes[index + 1] << 8;
Rhyme 0:0b6732b53bf4 37 index += 2;
Rhyme 0:0b6732b53bf4 38
Rhyme 0:0b6732b53bf4 39 if (_cmd == MSG_TYPE_GET) {
Rhyme 0:0b6732b53bf4 40 return;
Rhyme 0:0b6732b53bf4 41 }
Rhyme 0:0b6732b53bf4 42 if (_cmd == MSG_TYPE_UPDATE) {
Rhyme 0:0b6732b53bf4 43 _status = bytes[index++];
Rhyme 0:0b6732b53bf4 44 _reason = bytes[index++];
Rhyme 0:0b6732b53bf4 45 }
Rhyme 0:0b6732b53bf4 46
Rhyme 0:0b6732b53bf4 47 _valueLen = bytes[index + 0] | bytes[index + 1] << 8;
Rhyme 0:0b6732b53bf4 48 index += 2;
Rhyme 0:0b6732b53bf4 49 _value = new uint8_t[_valueLen];
Rhyme 0:0b6732b53bf4 50 for (int i = 0; i < _valueLen; i++) {
Rhyme 0:0b6732b53bf4 51 _value[i] = bytes[index + i];
Rhyme 0:0b6732b53bf4 52 }
Rhyme 0:0b6732b53bf4 53 }
Rhyme 0:0b6732b53bf4 54
Rhyme 0:0b6732b53bf4 55 Command::Command(uint8_t requestId, const char *str) {
Rhyme 0:0b6732b53bf4 56 _requestId = requestId & 0xff;
Rhyme 0:0b6732b53bf4 57
Rhyme 0:0b6732b53bf4 58 char *cp; //wsugi = strdup(str);
Rhyme 0:0b6732b53bf4 59 //wsugi 00 start
Rhyme 0:0b6732b53bf4 60 {
Rhyme 0:0b6732b53bf4 61 int length = strlen(str)+1;
Rhyme 0:0b6732b53bf4 62 cp = (char*)malloc(length);
Rhyme 0:0b6732b53bf4 63 strcpy(cp,str);
Rhyme 0:0b6732b53bf4 64 }
Rhyme 0:0b6732b53bf4 65 //wsugi 00 end
Rhyme 0:0b6732b53bf4 66 char *tok = strtok(cp, " ");
Rhyme 0:0b6732b53bf4 67 _cmd = strToCmd(tok);
Rhyme 0:0b6732b53bf4 68
Rhyme 0:0b6732b53bf4 69 tok = strtok(NULL, " ");
Rhyme 0:0b6732b53bf4 70 _attrId = strToAttrId(tok);
Rhyme 0:0b6732b53bf4 71
Rhyme 0:0b6732b53bf4 72 if (_cmd == MSG_TYPE_GET) {
Rhyme 0:0b6732b53bf4 73 _valueLen = 0;
Rhyme 0:0b6732b53bf4 74 _value = NULL;
Rhyme 0:0b6732b53bf4 75 } else {
Rhyme 0:0b6732b53bf4 76 tok = strtok(NULL, " ");
Rhyme 0:0b6732b53bf4 77 _valueLen = strlen(tok) / 2;
Rhyme 0:0b6732b53bf4 78 _value = new uint8_t[_valueLen];
Rhyme 0:0b6732b53bf4 79 strToValue(tok, _value);
Rhyme 0:0b6732b53bf4 80 }
Rhyme 0:0b6732b53bf4 81
Rhyme 0:0b6732b53bf4 82 free(cp);
Rhyme 0:0b6732b53bf4 83 }
Rhyme 0:0b6732b53bf4 84
Rhyme 0:0b6732b53bf4 85 Command::Command(uint8_t requestId, uint8_t cmd, uint16_t attrId) {
Rhyme 0:0b6732b53bf4 86 _requestId = requestId;
Rhyme 0:0b6732b53bf4 87 _cmd = cmd;
Rhyme 0:0b6732b53bf4 88 _attrId = attrId;
Rhyme 0:0b6732b53bf4 89 _valueLen = 0;
Rhyme 0:0b6732b53bf4 90 _value = NULL;
Rhyme 0:0b6732b53bf4 91 }
Rhyme 0:0b6732b53bf4 92
Rhyme 0:0b6732b53bf4 93 Command::Command(uint8_t requestId, uint8_t cmd, uint16_t attrId, uint16_t valueLen, uint8_t *value) {
Rhyme 0:0b6732b53bf4 94 _requestId = requestId;
Rhyme 0:0b6732b53bf4 95 _cmd = cmd;
Rhyme 0:0b6732b53bf4 96 _attrId = attrId;
Rhyme 0:0b6732b53bf4 97 _valueLen = valueLen;
Rhyme 0:0b6732b53bf4 98 _value = new uint8_t[_valueLen];
Rhyme 0:0b6732b53bf4 99 memcpy(_value, value, valueLen);
Rhyme 0:0b6732b53bf4 100 }
Rhyme 0:0b6732b53bf4 101
Rhyme 0:0b6732b53bf4 102 Command::Command(uint8_t requestId, uint8_t cmd, uint16_t attrId, uint8_t status, uint8_t reason, uint16_t valueLen,
Rhyme 0:0b6732b53bf4 103 uint8_t *value) {
Rhyme 0:0b6732b53bf4 104 _requestId = requestId;
Rhyme 0:0b6732b53bf4 105 _cmd = cmd;
Rhyme 0:0b6732b53bf4 106 _attrId = attrId;
Rhyme 0:0b6732b53bf4 107 _status = status;
Rhyme 0:0b6732b53bf4 108 _reason = reason;
Rhyme 0:0b6732b53bf4 109 _valueLen = valueLen;
Rhyme 0:0b6732b53bf4 110 _value = new uint8_t[_valueLen];
Rhyme 0:0b6732b53bf4 111 memcpy(_value, value, valueLen);
Rhyme 0:0b6732b53bf4 112 }
Rhyme 0:0b6732b53bf4 113
Rhyme 0:0b6732b53bf4 114 Command::Command() {
Rhyme 0:0b6732b53bf4 115 }
Rhyme 0:0b6732b53bf4 116
Rhyme 0:0b6732b53bf4 117 Command::~Command() {
Rhyme 0:0b6732b53bf4 118 if (_value != NULL) {
Rhyme 0:0b6732b53bf4 119 delete[] _value; //wsugi delete (_value);
Rhyme 0:0b6732b53bf4 120 }
Rhyme 0:0b6732b53bf4 121 }
Rhyme 0:0b6732b53bf4 122
Rhyme 0:0b6732b53bf4 123 int Command::strToValue(char *valueStr, uint8_t *value) {
Rhyme 0:0b6732b53bf4 124 for (int i = 0; i < (int) (strlen(valueStr) / 2); i++) {
Rhyme 0:0b6732b53bf4 125 int j = i * 2;
Rhyme 0:0b6732b53bf4 126 value[i] = getVal(valueStr[j + 1]) + (getVal(valueStr[j]) << 4);
Rhyme 0:0b6732b53bf4 127 }
Rhyme 0:0b6732b53bf4 128
Rhyme 0:0b6732b53bf4 129 return 0;
Rhyme 0:0b6732b53bf4 130 }
Rhyme 0:0b6732b53bf4 131
Rhyme 0:0b6732b53bf4 132 uint16_t Command::strToAttrId(char *attrIdStr) {
Rhyme 0:0b6732b53bf4 133 return atoi(attrIdStr);
Rhyme 0:0b6732b53bf4 134 //return String(attrIdStr).toInt();
Rhyme 0:0b6732b53bf4 135 }
Rhyme 0:0b6732b53bf4 136
Rhyme 0:0b6732b53bf4 137 uint8_t Command::strToCmd(char *cmdStr) {
Rhyme 0:0b6732b53bf4 138 char c = cmdStr[0];
Rhyme 0:0b6732b53bf4 139 if (c == 'g' || c == 'G') {
Rhyme 0:0b6732b53bf4 140 return MSG_TYPE_GET;
Rhyme 0:0b6732b53bf4 141 } else if (c == 's' || c == 'S') {
Rhyme 0:0b6732b53bf4 142 return MSG_TYPE_SET;
Rhyme 0:0b6732b53bf4 143 } else if (c == 'u' || c == 'U') {
Rhyme 0:0b6732b53bf4 144 return MSG_TYPE_UPDATE;
Rhyme 0:0b6732b53bf4 145 }
Rhyme 0:0b6732b53bf4 146
Rhyme 0:0b6732b53bf4 147 return 0xFF ;
Rhyme 0:0b6732b53bf4 148 }
Rhyme 0:0b6732b53bf4 149
Rhyme 0:0b6732b53bf4 150 uint8_t Command::getCommand() {
Rhyme 0:0b6732b53bf4 151 return _cmd;
Rhyme 0:0b6732b53bf4 152 }
Rhyme 0:0b6732b53bf4 153
Rhyme 0:0b6732b53bf4 154 uint8_t Command::getReqId() {
Rhyme 0:0b6732b53bf4 155 return _requestId;
Rhyme 0:0b6732b53bf4 156 }
Rhyme 0:0b6732b53bf4 157
Rhyme 0:0b6732b53bf4 158 uint16_t Command::getAttrId() {
Rhyme 0:0b6732b53bf4 159 return _attrId;
Rhyme 0:0b6732b53bf4 160 }
Rhyme 0:0b6732b53bf4 161
Rhyme 0:0b6732b53bf4 162 uint16_t Command::getValueLen() {
Rhyme 0:0b6732b53bf4 163 return _valueLen;
Rhyme 0:0b6732b53bf4 164 }
Rhyme 0:0b6732b53bf4 165
Rhyme 0:0b6732b53bf4 166 void Command::getValue(uint8_t *value) {
Rhyme 0:0b6732b53bf4 167 for (int i = 0; i < _valueLen; i++) {
Rhyme 0:0b6732b53bf4 168 value[i] = _value[i];
Rhyme 0:0b6732b53bf4 169 }
Rhyme 0:0b6732b53bf4 170 }
Rhyme 0:0b6732b53bf4 171
Rhyme 0:0b6732b53bf4 172 uint8_t *Command::getValueP() {
Rhyme 0:0b6732b53bf4 173 return _value;
Rhyme 0:0b6732b53bf4 174 }
Rhyme 0:0b6732b53bf4 175
Rhyme 0:0b6732b53bf4 176 uint16_t Command::getSize() {
Rhyme 0:0b6732b53bf4 177 uint16_t len = CMD_HDR_LEN;
Rhyme 0:0b6732b53bf4 178
Rhyme 0:0b6732b53bf4 179 if (_cmd != MSG_TYPE_GET) {
Rhyme 0:0b6732b53bf4 180 len += CMD_VAL_LEN + _valueLen;
Rhyme 0:0b6732b53bf4 181 }
Rhyme 0:0b6732b53bf4 182
Rhyme 0:0b6732b53bf4 183 if (_cmd == MSG_TYPE_UPDATE) {
Rhyme 0:0b6732b53bf4 184 len += 2; // status byte + reason byte
Rhyme 0:0b6732b53bf4 185 }
Rhyme 0:0b6732b53bf4 186
Rhyme 0:0b6732b53bf4 187 return len;
Rhyme 0:0b6732b53bf4 188 }
Rhyme 0:0b6732b53bf4 189
Rhyme 0:0b6732b53bf4 190 uint16_t Command::getBytes(uint8_t *bytes) {
Rhyme 0:0b6732b53bf4 191 uint16_t len = getSize();
Rhyme 0:0b6732b53bf4 192
Rhyme 0:0b6732b53bf4 193 int index = 0;
Rhyme 0:0b6732b53bf4 194
Rhyme 0:0b6732b53bf4 195 bytes[index++] = (_cmd);
Rhyme 0:0b6732b53bf4 196
Rhyme 0:0b6732b53bf4 197 bytes[index++] = (_requestId);
Rhyme 0:0b6732b53bf4 198
Rhyme 0:0b6732b53bf4 199 bytes[index++] = (_attrId & 0xff);
Rhyme 0:0b6732b53bf4 200 bytes[index++] = ((_attrId >> 8) & 0xff);
Rhyme 0:0b6732b53bf4 201
Rhyme 0:0b6732b53bf4 202 if (_cmd == MSG_TYPE_GET) {
Rhyme 0:0b6732b53bf4 203 return len;
Rhyme 0:0b6732b53bf4 204 }
Rhyme 0:0b6732b53bf4 205
Rhyme 0:0b6732b53bf4 206 if (_cmd == MSG_TYPE_UPDATE) {
Rhyme 0:0b6732b53bf4 207 bytes[index++] = (_status);
Rhyme 0:0b6732b53bf4 208 bytes[index++] = (_reason);
Rhyme 0:0b6732b53bf4 209 }
Rhyme 0:0b6732b53bf4 210
Rhyme 0:0b6732b53bf4 211 bytes[index++] = (_valueLen & 0xff);
Rhyme 0:0b6732b53bf4 212 bytes[index++] = ((_valueLen >> 8) & 0xff);
Rhyme 0:0b6732b53bf4 213
Rhyme 0:0b6732b53bf4 214 for (int i = 0; i < _valueLen; i++) {
Rhyme 0:0b6732b53bf4 215 bytes[index++] = (_value[i]);
Rhyme 0:0b6732b53bf4 216 }
Rhyme 0:0b6732b53bf4 217
Rhyme 0:0b6732b53bf4 218 return len;
Rhyme 0:0b6732b53bf4 219 }
Rhyme 0:0b6732b53bf4 220
Rhyme 0:0b6732b53bf4 221 bool Command::isValid() {
Rhyme 0:0b6732b53bf4 222 return (_cmd == MSG_TYPE_SET) || (_cmd == MSG_TYPE_GET) || (_cmd == MSG_TYPE_UPDATE);
Rhyme 0:0b6732b53bf4 223 }
Rhyme 0:0b6732b53bf4 224
Rhyme 0:0b6732b53bf4 225 void Command::dumpBytes() {
Rhyme 0:0b6732b53bf4 226 #if SERIAL_PRINT_DBG_ASR_ON
Rhyme 0:0b6732b53bf4 227 uint16_t len = getSize();
Rhyme 0:0b6732b53bf4 228 uint8_t bytes[len];
Rhyme 0:0b6732b53bf4 229 getBytes(bytes);
Rhyme 0:0b6732b53bf4 230
Rhyme 0:0b6732b53bf4 231 _printBuf[0] = 0;
Rhyme 0:0b6732b53bf4 232 sprintf(_printBuf, "len: %d value: ", len);
Rhyme 0:0b6732b53bf4 233 for (int i = 0; i < len; i++) {
Rhyme 0:0b6732b53bf4 234 int b = bytes[i] & 0xff;
Rhyme 0:0b6732b53bf4 235 sprintf(&_printBuf[strlen(_printBuf)], "%02x", b);
Rhyme 0:0b6732b53bf4 236 }
Rhyme 0:0b6732b53bf4 237 printf("%s\n",_printBuf);
Rhyme 0:0b6732b53bf4 238 #endif
Rhyme 0:0b6732b53bf4 239 }
Rhyme 0:0b6732b53bf4 240
Rhyme 0:0b6732b53bf4 241 void Command::dump() {
Rhyme 0:0b6732b53bf4 242 #if SERIAL_PRINT_DBG_ASR_ON
Rhyme 0:0b6732b53bf4 243 _printBuf[0] = 0;
Rhyme 0:0b6732b53bf4 244 sprintf(_printBuf, "cmd: %s attr: %d value: ",
Rhyme 0:0b6732b53bf4 245 CMD_NAMES[_cmd - MESSAGE_CHANNEL_BASE - 1],
Rhyme 0:0b6732b53bf4 246 _attrId
Rhyme 0:0b6732b53bf4 247 );
Rhyme 0:0b6732b53bf4 248 if (_cmd != MSG_TYPE_GET) {
Rhyme 0:0b6732b53bf4 249 for (int i = 0; i < _valueLen; i++) {
Rhyme 0:0b6732b53bf4 250 int b = _value[i] & 0xff;
Rhyme 0:0b6732b53bf4 251 sprintf(&_printBuf[strlen(_printBuf)], "%02x", b);
Rhyme 0:0b6732b53bf4 252 }
Rhyme 0:0b6732b53bf4 253 }
Rhyme 0:0b6732b53bf4 254 printf("%s\n",_printBuf);
Rhyme 0:0b6732b53bf4 255 #endif
Rhyme 0:0b6732b53bf4 256 }
Rhyme 0:0b6732b53bf4 257
Rhyme 0:0b6732b53bf4 258 uint8_t Command::getVal(char c) {
Rhyme 0:0b6732b53bf4 259 if (c >= '0' && c <= '9')
Rhyme 0:0b6732b53bf4 260 return (uint8_t)(c - '0');
Rhyme 0:0b6732b53bf4 261 else if (c >= 'A' && c <= 'F')
Rhyme 0:0b6732b53bf4 262 return (uint8_t)(c - 'A' + 10);
Rhyme 0:0b6732b53bf4 263 else if (c >= 'a' && c <= 'f')
Rhyme 0:0b6732b53bf4 264 return (uint8_t)(c - 'a' + 10);
Rhyme 0:0b6732b53bf4 265
Rhyme 0:0b6732b53bf4 266 printf("bad hex char: %c\n",c);
Rhyme 0:0b6732b53bf4 267
Rhyme 0:0b6732b53bf4 268 return 0;
Rhyme 0:0b6732b53bf4 269 }