From 3ae5f22e82a24f70398e2e3c05db540be74d8d3b Mon Sep 17 00:00:00 2001 From: DHJeff Date: Fri, 21 Apr 2017 17:39:06 +0800 Subject: [PATCH 01/10] Modified CIR Transmitter functions --- libraries/CIR/CIR.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/CIR/CIR.cpp b/libraries/CIR/CIR.cpp index 974b88c..ca9bd20 100644 --- a/libraries/CIR/CIR.cpp +++ b/libraries/CIR/CIR.cpp @@ -84,15 +84,15 @@ void CIR::enableTransmitter(void) { Wire.beginTransmission(0x48); Wire.write(0xA3); Wire.endTransmission(); + delay(1500); } void CIR::disableTransmitter(void) { - delay(15); + delay(100); Wire.begin(); Wire.beginTransmission(0x48); Wire.write(0xA4); Wire.endTransmission(); - } void CIR::sendEncode(uint32_t data) { From 90c14c898a4fde9bf022c81713dd39b26ce2edaf Mon Sep 17 00:00:00 2001 From: DHJeff Date: Mon, 24 Apr 2017 17:46:25 +0800 Subject: [PATCH 02/10] fixed typo in CIR examples --- libraries/CIR/examples/Receiver/Receiver.ino | 2 +- libraries/CIR/examples/Transmitter/Transmitter.ino | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/CIR/examples/Receiver/Receiver.ino b/libraries/CIR/examples/Receiver/Receiver.ino index b76cb97..c3d4388 100644 --- a/libraries/CIR/examples/Receiver/Receiver.ino +++ b/libraries/CIR/examples/Receiver/Receiver.ino @@ -8,7 +8,7 @@ CIR data is received by 38kHz IR receiver of the Primo board, It is based on the NEC protocol to decode signals from IR receiver to get hex code, you can see the hex code using serial - montior when the Primo board receive CIR data. + monitor when the Primo board receive CIR data. NEC Protocol: 9ms leading pulse burst diff --git a/libraries/CIR/examples/Transmitter/Transmitter.ino b/libraries/CIR/examples/Transmitter/Transmitter.ino index 1459919..a361f48 100644 --- a/libraries/CIR/examples/Transmitter/Transmitter.ino +++ b/libraries/CIR/examples/Transmitter/Transmitter.ino @@ -7,7 +7,7 @@ CIR library. The IR transmitter allows you to send hex code by infrared LED of the Primo board, the hex code is based on the NEC protocol - that transmiited consits of the following, using buttons to send + that transmitted consists of the following, using buttons to send hex code when a button is pressed. NEC Protocol: From c01d3c526840a2dfdb2229aadaee7e57944f7029 Mon Sep 17 00:00:00 2001 From: DHJeff Date: Tue, 25 Apr 2017 12:16:10 +0800 Subject: [PATCH 03/10] Modified commit in CIR examples --- libraries/CIR/examples/Receiver/Receiver.ino | 2 +- libraries/CIR/examples/Transmitter/Transmitter.ino | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/CIR/examples/Receiver/Receiver.ino b/libraries/CIR/examples/Receiver/Receiver.ino index c3d4388..b69e6b2 100644 --- a/libraries/CIR/examples/Receiver/Receiver.ino +++ b/libraries/CIR/examples/Receiver/Receiver.ino @@ -43,7 +43,7 @@ void setup() { } void loop() { - // check if IR receiver decodes signals and accord with NEC Protocl: + // check if IR receiver decodes signals and accord with NEC Protocol: if (Primo_CIR.getReceiverStatus()) // print hex code: PrintCirReceiverResult(); diff --git a/libraries/CIR/examples/Transmitter/Transmitter.ino b/libraries/CIR/examples/Transmitter/Transmitter.ino index a361f48..2867894 100644 --- a/libraries/CIR/examples/Transmitter/Transmitter.ino +++ b/libraries/CIR/examples/Transmitter/Transmitter.ino @@ -54,7 +54,7 @@ void loop() { // turn LED on: digitalWrite(LED_BUILTIN, HIGH); - // sned hex code: + // send hex code: Primo_CIR.sendEncode(HEX_1); // turn LED off: digitalWrite(LED_BUILTIN, LOW); From 6719a03e2472b0eaaa0d529afcad699de2c074e5 Mon Sep 17 00:00:00 2001 From: DHJeff Date: Fri, 28 Apr 2017 12:33:08 +0800 Subject: [PATCH 04/10] Removed old CIR library --- libraries/CIR/CIR.cpp | 115 ------------------ libraries/CIR/CIR.h | 59 --------- libraries/CIR/examples/Receiver/Receiver.ino | 62 ---------- .../CIR/examples/Transmitter/Transmitter.ino | 72 ----------- libraries/CIR/keywords.txt | 25 ---- libraries/CIR/library.properties | 10 -- 6 files changed, 343 deletions(-) delete mode 100644 libraries/CIR/CIR.cpp delete mode 100644 libraries/CIR/CIR.h delete mode 100644 libraries/CIR/examples/Receiver/Receiver.ino delete mode 100644 libraries/CIR/examples/Transmitter/Transmitter.ino delete mode 100644 libraries/CIR/keywords.txt delete mode 100644 libraries/CIR/library.properties diff --git a/libraries/CIR/CIR.cpp b/libraries/CIR/CIR.cpp deleted file mode 100644 index ca9bd20..0000000 --- a/libraries/CIR/CIR.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* -**************************************************************************** -* Copyright (c) 2017 Arduino srl. All right reserved. -* -* File : CIR.cpp -* Date : 2017/03/10 -* Revision : 0.0.1 $ -* Author: jeff[at]arduino[dot]org -* -**************************************************************************** - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "CIR.h" - -CIR::CIR(void) { - -} - -void CIR::enableReceiver(void) { - delay(100); - Wire.begin(); - Wire.beginTransmission(0x48); - Wire.write(0xA0); - Wire.endTransmission(); -} - -void CIR::disableReceiver(void) { - delay(15); - Wire.begin(); - Wire.beginTransmission(0x48); - Wire.write(0xA1); - Wire.endTransmission(); -} - -bool CIR::getReceiverStatus(void) { - delay(150); - Wire.begin(); - Wire.beginTransmission(0x48); - Wire.write(0xA2); - Wire.endTransmission(); - delay(15); - Wire.requestFrom(0x48,4, true); - recBuffer[0] = Wire.read(); - - int i; - - for (i=1;i<4;i++) { - recBuffer[i] = Wire.read(); - } - - if (recBuffer[0] == 0) - return false; - else - return true; -} - -uint32_t CIR::getDecode(void) { - uint32_t code=0; - code = (recBuffer[0] << 24); - code |= (recBuffer[1] << 16); - code |= (recBuffer[2] << 8); - code |= recBuffer[3]; - - return code; -} - -void CIR::enableTransmitter(void) { - delay(100); - Wire.begin(); - Wire.beginTransmission(0x48); - Wire.write(0xA3); - Wire.endTransmission(); - delay(1500); -} - -void CIR::disableTransmitter(void) { - delay(100); - Wire.begin(); - Wire.beginTransmission(0x48); - Wire.write(0xA4); - Wire.endTransmission(); -} - -void CIR::sendEncode(uint32_t data) { - - uint8_t transdata[4]; - transdata[0] = (data >> 24); - transdata[1] = (data >> 16); - transdata[2] = (data >> 8); - transdata[3] = data; - - delay(200); - Wire.begin(); - Wire.beginTransmission(0x48); - Wire.write(0xA5); - Wire.write(transdata[0]); - Wire.write(transdata[1]); - Wire.write(transdata[2]); - Wire.write(transdata[3]); - Wire.endTransmission(); -} diff --git a/libraries/CIR/CIR.h b/libraries/CIR/CIR.h deleted file mode 100644 index 6a67be0..0000000 --- a/libraries/CIR/CIR.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -**************************************************************************** -* Copyright (c) 2017 Arduino srl. All right reserved. -* -* File : CIR.h -* Date : 2017/03/10 -* Revision : 0.0.1 $ -* Author: jeff[at]arduino[dot]org -* -**************************************************************************** - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef __CIR_H__ -#define __CIR_H__ - -#include -#include -#include "Arduino.h" - -#define SEND_BUF_LENGTH 256 -#define REC_BUF_LENGTH 74 - -class CIR { -public: - CIR(void); - void enableReceiver(void); - void disableReceiver(void); - bool getReceiverStatus(void); - uint32_t getDecode(void); - - void enableTransmitter(void); - void disableTransmitter(void); - void sendEncode(uint32_t data); - - uint16_t recData[34]; - uint16_t leader_mark, leader_space, mark_max, mark_min, space_max, space_min; - -private: - uint8_t sendBuffer[SEND_BUF_LENGTH]; - uint8_t recBuffer[REC_BUF_LENGTH]; - - -}; - -#endif __CIR_H___ diff --git a/libraries/CIR/examples/Receiver/Receiver.ino b/libraries/CIR/examples/Receiver/Receiver.ino deleted file mode 100644 index b69e6b2..0000000 --- a/libraries/CIR/examples/Receiver/Receiver.ino +++ /dev/null @@ -1,62 +0,0 @@ -/* - Receiver.ino - - Written by Jeff Wu (jeff@arduino.org) - - This example for the Arduino Primo board shows how to use - CIR library. - CIR data is received by 38kHz IR receiver of the Primo board, - It is based on the NEC protocol to decode signals from IR - receiver to get hex code, you can see the hex code using serial - monitor when the Primo board receive CIR data. - - NEC Protocol: - 9ms leading pulse burst - 4.5ms space - 8-bit address for the receiving device - 8-bit logical inverse of the address - 8-bit command - 8-bit logical inverse of the command - Logical 0 : 560us + 560us - Logical 1 : 560us + 1690us - - This example code is in the public domain. - -*/ - -#include -#include "CIR.h" - -CIR Primo_CIR; - -void setup() { - // start serial port at 115200 bps: - Serial.begin(115200); - // initialize the LED pin as an output: - pinMode(LED_BUILTIN, OUTPUT); - // turn LED off: - digitalWrite(LED_BUILTIN, LOW); - // enable IR ready to receiver: - Primo_CIR.enableReceiver(); - // turn LED on: - digitalWrite(LED_BUILTIN, HIGH); -} - -void loop() { - // check if IR receiver decodes signals and accord with NEC Protocol: - if (Primo_CIR.getReceiverStatus()) - // print hex code: - PrintCirReceiverResult(); -} - -void PrintCirReceiverResult() { - // turn LED on: - digitalWrite(LED_BUILTIN, HIGH); - Serial.print("Data Code:"); - // convert to hex code and print: - Serial.println(Primo_CIR.getDecode(),HEX); - // new line: - Serial.print('\n'); - // turn LED off: - digitalWrite(LED_BUILTIN, LOW); -} diff --git a/libraries/CIR/examples/Transmitter/Transmitter.ino b/libraries/CIR/examples/Transmitter/Transmitter.ino deleted file mode 100644 index 2867894..0000000 --- a/libraries/CIR/examples/Transmitter/Transmitter.ino +++ /dev/null @@ -1,72 +0,0 @@ -/* - Transmitter.ino - - Written by Jeff Wu (jeff@arduino.org) - - This example for the Arduino Primo board shows how to use - CIR library. - The IR transmitter allows you to send hex code by infrared LED - of the Primo board, the hex code is based on the NEC protocol - that transmitted consists of the following, using buttons to send - hex code when a button is pressed. - - NEC Protocol: - 9ms leading pulse burst - 4.5ms space - 8-bit address for the receiving device - 8-bit logical inverse of the address - 8-bit command - 8-bit logical inverse of the command - Logical 0 : 560us + 560us - Logical 1 : 560us + 1690us - - This example code is in the public domain. - -*/ - -#include -#include "CIR.h" - -// define hex code: -#define HEX_1 0xC1AA1107 -#define HEX_2 0xC1AA68F0 - -CIR Primo_CIR; - -void setup() { - // initialize the LED pin as an output: - pinMode(LED_BUILTIN, OUTPUT); - // turn LED off: - digitalWrite(LED_BUILTIN, LOW); - // enable IR ready to transmitter: - Primo_CIR.enableTransmitter(); - // initialize the pushbutton pin as an input: - pinMode(USER1_BUTTON, INPUT); - pinMode(USER2_BUTTON, INPUT); - // turn LED on: - digitalWrite(LED_BUILTIN, HIGH); -} - -void loop() { - // check if the USER1 BUTTON is pressed: - if (!digitalRead(USER1_BUTTON)) - { - // turn LED on: - digitalWrite(LED_BUILTIN, HIGH); - - // send hex code: - Primo_CIR.sendEncode(HEX_1); - // turn LED off: - digitalWrite(LED_BUILTIN, LOW); - } - // check if the USER2 BUTTON is pressed: - else if (!digitalRead(USER2_BUTTON)) - { - // turn LED on: - digitalWrite(LED_BUILTIN, HIGH); - // sned hex code: - Primo_CIR.sendEncode(HEX_2); - // turn LED off: - digitalWrite(LED_BUILTIN, LOW); - } -} diff --git a/libraries/CIR/keywords.txt b/libraries/CIR/keywords.txt deleted file mode 100644 index a39f373..0000000 --- a/libraries/CIR/keywords.txt +++ /dev/null @@ -1,25 +0,0 @@ -####################################### -# Syntax Coloring Map for CIR -####################################### - -####################################### -# Datatypes (KEYWORD1) -####################################### - -CIR KEYWORD1 - -####################################### -# Methods and Functions (KEYWORD2) -####################################### - -enableReceiver KEYWORD2 -disableReceiver KEYWORD2 -getReceiverStatus KEYWORD2 -getDecode KEYWORD2 -enableTransmitter KEYWORD2 -disableTransmitter KEYWORD2 -sendEncode KEYWORD2 - -####################################### -# Constants (LITERAL1) -####################################### diff --git a/libraries/CIR/library.properties b/libraries/CIR/library.properties deleted file mode 100644 index 55edbfd..0000000 --- a/libraries/CIR/library.properties +++ /dev/null @@ -1,10 +0,0 @@ -name=CIR -version=0.0.1 -author=Jeff Wu -maintainer=Arduino -sentence=CIR Transmitter and Receiver -paragraph= This library is desigend for using Primo board to reveiving and sending CIR data -category=Communication -url=http://www.arduino.org/learning/reference/CIR -architectures=nrf52 - From 895706aa22c89a9334803f158dc1dc6ac469dbfb Mon Sep 17 00:00:00 2001 From: DHJeff Date: Fri, 28 Apr 2017 12:35:33 +0800 Subject: [PATCH 05/10] Added new cir library --- libraries/Cir/cir.cpp | 116 ++++++++++++++++++ libraries/Cir/cir.h | 59 +++++++++ libraries/Cir/examples/Receiver/Receiver.ino | 62 ++++++++++ .../Cir/examples/Transmitter/Transmitter.ino | 72 +++++++++++ libraries/Cir/keywords.txt | 25 ++++ libraries/Cir/library.properties | 9 ++ 6 files changed, 343 insertions(+) create mode 100644 libraries/Cir/cir.cpp create mode 100644 libraries/Cir/cir.h create mode 100644 libraries/Cir/examples/Receiver/Receiver.ino create mode 100644 libraries/Cir/examples/Transmitter/Transmitter.ino create mode 100644 libraries/Cir/keywords.txt create mode 100644 libraries/Cir/library.properties diff --git a/libraries/Cir/cir.cpp b/libraries/Cir/cir.cpp new file mode 100644 index 0000000..1749ba4 --- /dev/null +++ b/libraries/Cir/cir.cpp @@ -0,0 +1,116 @@ +/* +**************************************************************************** +* Copyright (c) 2017 Arduino srl. All right reserved. +* +* File : cir.cpp +* Date : 2017/03/10 +* Revision : 0.0.1 $ +* Author: jeff[at]arduino[dot]org +* +**************************************************************************** + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "cir.h" + +cir::cir(void) { + +} + +void cir::enableReceiver(void) { + delay(100); + Wire.begin(); + Wire.beginTransmission(0x48); + Wire.write(0xA0); + Wire.endTransmission(); +} + +void cir::disableReceiver(void) { + delay(15); + Wire.begin(); + Wire.beginTransmission(0x48); + Wire.write(0xA1); + Wire.endTransmission(); +} + +bool cir::getReceiverStatus(void) { + delay(150); + Wire.begin(); + Wire.beginTransmission(0x48); + Wire.write(0xA2); + Wire.endTransmission(); + delay(15); + Wire.requestFrom(0x48,4, true); + recBuffer[0] = Wire.read(); + + int i; + + for (i=1;i<4;i++) { + recBuffer[i] = Wire.read(); + } + + if (recBuffer[0] == 0) + return false; + else + return true; +} + +uint32_t cir::digitalRead(void) { + uint32_t code=0; + code = (recBuffer[0] << 24); + code |= (recBuffer[1] << 16); + code |= (recBuffer[2] << 8); + code |= recBuffer[3]; + + return code; +} + +void cir::enableTransmitter(void) { + delay(100); + Wire.begin(); + Wire.beginTransmission(0x48); + Wire.write(0xA3); + Wire.endTransmission(); + delay(1500); +} + +void cir::disableTransmitter(void) { + delay(100); + Wire.begin(); + Wire.beginTransmission(0x48); + Wire.write(0xA4); + Wire.endTransmission(); + +} + +void cir::digitalWrite(uint32_t data) { + + uint8_t transdata[4]; + transdata[0] = (data >> 24); + transdata[1] = (data >> 16); + transdata[2] = (data >> 8); + transdata[3] = data; + + delay(200); + Wire.begin(); + Wire.beginTransmission(0x48); + Wire.write(0xA5); + Wire.write(transdata[0]); + Wire.write(transdata[1]); + Wire.write(transdata[2]); + Wire.write(transdata[3]); + Wire.endTransmission(); +} diff --git a/libraries/Cir/cir.h b/libraries/Cir/cir.h new file mode 100644 index 0000000..ddfafe9 --- /dev/null +++ b/libraries/Cir/cir.h @@ -0,0 +1,59 @@ +/* +**************************************************************************** +* Copyright (c) 2017 Arduino srl. All right reserved. +* +* File : cir.h +* Date : 2017/03/10 +* Revision : 0.0.1 $ +* Author: jeff[at]arduino[dot]org +* +**************************************************************************** + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef __CIR_H__ +#define __CIR_H__ + +#include +#include +#include "Arduino.h" + +#define SEND_BUF_LENGTH 256 +#define REC_BUF_LENGTH 74 + +class cir { +public: + cir(void); + void enableReceiver(void); + void disableReceiver(void); + bool getReceiverStatus(void); + uint32_t digitalRead(void); + + void enableTransmitter(void); + void disableTransmitter(void); + void digitalWrite(uint32_t data); + + uint16_t recData[34]; + uint16_t leader_mark, leader_space, mark_max, mark_min, space_max, space_min; + +private: + uint8_t sendBuffer[SEND_BUF_LENGTH]; + uint8_t recBuffer[REC_BUF_LENGTH]; + + +}; + +#endif __CIR_H___ diff --git a/libraries/Cir/examples/Receiver/Receiver.ino b/libraries/Cir/examples/Receiver/Receiver.ino new file mode 100644 index 0000000..4da24f3 --- /dev/null +++ b/libraries/Cir/examples/Receiver/Receiver.ino @@ -0,0 +1,62 @@ +/* + Receiver.ino + + Written by Jeff Wu (jeff@arduino.org) + + This example for the Arduino Primo board shows how to use + cir library. + cir data is received by 38kHz IR receiver of the Primo board, + It is based on the NEC protocol to decode signals from IR + receiver to get hex code, you can see the hex code using serial + montior when the Primo board receive CIR data. + + NEC Protocol: + 9ms leading pulse burst + 4.5ms space + 8-bit address for the receiving device + 8-bit logical inverse of the address + 8-bit command + 8-bit logical inverse of the command + Logical 0 : 560us + 560us + Logical 1 : 560us + 1690us + + This example code is in the public domain. + +*/ + +#include +#include "cir.h" + +cir primo_cir; + +void setup() { + // start serial port at 115200 bps: + Serial.begin(115200); + // initialize the LED pin as an output: + pinMode(LED_BUILTIN, OUTPUT); + // turn LED off: + digitalWrite(LED_BUILTIN, LOW); + // enable IR ready to receiver: + primo_cir.enableReceiver(); + // turn LED on: + digitalWrite(LED_BUILTIN, HIGH); +} + +void loop() { + // check if IR receiver decodes signals and accord with NEC Protocl: + if (primo_cir.getReceiverStatus()) + // print hex code: + printCirReceiverResult(); +} + +void printCirReceiverResult() { + // turn LED on: + digitalWrite(LED_BUILTIN, HIGH); + Serial.print("Data Code:"); + // convert to hex code and print: + Serial.println(primo_cir.digitalRead(),HEX); + // new line: + Serial.print('\n'); + // turn LED off: + digitalWrite(LED_BUILTIN, LOW); +} diff --git a/libraries/Cir/examples/Transmitter/Transmitter.ino b/libraries/Cir/examples/Transmitter/Transmitter.ino new file mode 100644 index 0000000..8561e1a --- /dev/null +++ b/libraries/Cir/examples/Transmitter/Transmitter.ino @@ -0,0 +1,72 @@ +/* + Transmitter.ino + + Written by Jeff Wu (jeff@arduino.org) + + This example for the Arduino Primo board shows how to use + cir library. + The IR transmitter allows you to send hex code by infrared LED + of the Primo board, the hex code is based on the NEC protocol + that transmiited consits of the following, using buttons to send + hex code when a button is pressed. + + NEC Protocol: + 9ms leading pulse burst + 4.5ms space + 8-bit address for the receiving device + 8-bit logical inverse of the address + 8-bit command + 8-bit logical inverse of the command + Logical 0 : 560us + 560us + Logical 1 : 560us + 1690us + + This example code is in the public domain. + +*/ + +#include +#include "cir.h" + +// define hex code: +#define HEX_1 0xC1AA1107 +#define HEX_2 0xC1AA68F0 + +cir primo_cir; + +void setup() { + // initialize the LED pin as an output: + pinMode(LED_BUILTIN, OUTPUT); + // turn LED off: + digitalWrite(LED_BUILTIN, LOW); + // enable IR ready to transmitter: + primo_cir.enableTransmitter(); + // initialize the pushbutton pin as an input: + pinMode(USER1_BUTTON, INPUT); + pinMode(USER2_BUTTON, INPUT); + // turn LED on: + digitalWrite(LED_BUILTIN, HIGH); +} + +void loop() { + // check if the USER1 BUTTON is pressed: + if (!digitalRead(USER1_BUTTON)) + { + // turn LED on: + digitalWrite(LED_BUILTIN, HIGH); + + // sned hex code: + primo_cir.digitalWrite(HEX_1); + // turn LED off: + digitalWrite(LED_BUILTIN, LOW); + } + // check if the USER2 BUTTON is pressed: + else if (!digitalRead(USER2_BUTTON)) + { + // turn LED on: + digitalWrite(LED_BUILTIN, HIGH); + // sned hex code: + primo_cir.digitalWrite(HEX_2); + // turn LED off: + digitalWrite(LED_BUILTIN, LOW); + } +} diff --git a/libraries/Cir/keywords.txt b/libraries/Cir/keywords.txt new file mode 100644 index 0000000..7e7364b --- /dev/null +++ b/libraries/Cir/keywords.txt @@ -0,0 +1,25 @@ +####################################### +# Syntax Coloring Map for cir +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +cir KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +enableReceiver KEYWORD2 +disableReceiver KEYWORD2 +getReceiverStatus KEYWORD2 +digitalRead KEYWORD2 +enableTransmitter KEYWORD2 +disableTransmitter KEYWORD2 +digitalWrite KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### diff --git a/libraries/Cir/library.properties b/libraries/Cir/library.properties new file mode 100644 index 0000000..135c0df --- /dev/null +++ b/libraries/Cir/library.properties @@ -0,0 +1,9 @@ +name=Cir +version=0.0.1 +author=Jeff Wu +maintainer=Arduino +sentence=CIR Transmitter and Receiver +paragraph= This library is designed for using Primo board to reveiving and sending CIR data +category=Communication +url=http://www.arduino.org/learning/reference/cir +architectures=nrf52 \ No newline at end of file From 2c3c90e9bba31127faa7a53df80f992cad06b349 Mon Sep 17 00:00:00 2001 From: DHJeff Date: Fri, 28 Apr 2017 12:38:27 +0800 Subject: [PATCH 06/10] Added bat library --- libraries/Bat/bat.cpp | 64 +++++++++++++++++++ libraries/Bat/bat.h | 45 +++++++++++++ .../BatteryVoltageValue.ino | 59 +++++++++++++++++ libraries/Bat/keywords.txt | 19 ++++++ libraries/Bat/library.properties | 9 +++ 5 files changed, 196 insertions(+) create mode 100644 libraries/Bat/bat.cpp create mode 100644 libraries/Bat/bat.h create mode 100644 libraries/Bat/examples/BatteryVoltageValue/BatteryVoltageValue.ino create mode 100644 libraries/Bat/keywords.txt create mode 100644 libraries/Bat/library.properties diff --git a/libraries/Bat/bat.cpp b/libraries/Bat/bat.cpp new file mode 100644 index 0000000..46c63bc --- /dev/null +++ b/libraries/Bat/bat.cpp @@ -0,0 +1,64 @@ +/* +**************************************************************************** +* Copyright (c) 2017 Arduino srl. All right reserved. +* +* File : bat.cpp +* Date : 2017/04/10 +* Revision : 0.0.1 $ +* Author: jeff[at]arduino[dot]org +* +**************************************************************************** + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "bat.h" + +bat::bat(void) { + +} + +double bat::analogRead(void) { + double voltage; + uint32_t code=0; + + delay(150); + + int i; + for (i=0;i<4;i++) { + recBuffer[i] = 0; + } + + Wire.begin(); + Wire.beginTransmission(0x48); + Wire.write(0xED); + Wire.endTransmission(); + delay(15); + Wire.requestFrom(0x48,4, true); + recBuffer[0] = Wire.read(); + + for (i=1;i<4;i++) { + recBuffer[i] = Wire.read(); + } + + code = (recBuffer[0] << 24); + code |= (recBuffer[1] << 16); + code |= (recBuffer[2] << 8); + code |= recBuffer[3]; + + voltage = (6.665 * code) / 4096; + + return voltage; +} diff --git a/libraries/Bat/bat.h b/libraries/Bat/bat.h new file mode 100644 index 0000000..168300b --- /dev/null +++ b/libraries/Bat/bat.h @@ -0,0 +1,45 @@ +/* +**************************************************************************** +* Copyright (c) 2017 Arduino srl. All right reserved. +* +* File : bat.h +* Date : 2017/04/10 +* Revision : 0.0.1 $ +* Author: jeff[at]arduino[dot]org +* +**************************************************************************** + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef __BAT_H__ +#define __BAT_H__ + +#include +#include +#include "Arduino.h" + +#define REC_BUF_LENGTH 4 + +class bat { +public: + bat(void); + double analogRead(void); +private: + uint8_t recBuffer[REC_BUF_LENGTH]; + +}; + +#endif __BAT_H___ \ No newline at end of file diff --git a/libraries/Bat/examples/BatteryVoltageValue/BatteryVoltageValue.ino b/libraries/Bat/examples/BatteryVoltageValue/BatteryVoltageValue.ino new file mode 100644 index 0000000..2b6127a --- /dev/null +++ b/libraries/Bat/examples/BatteryVoltageValue/BatteryVoltageValue.ino @@ -0,0 +1,59 @@ +/* + BatteryVoltageValue.ino + Written by Jeff Wu (jeff@arduino.org) + This example for the Arduino Primo board shows how to use + bat library. + + This example allows you to get Battery Voltage Value of Primo + board, disabling STM32 enter to standby mode to avoid Primo board + enter to standby mode when Primo board is powered only by battery. + Primo board is able to send voltage value over serial port or BLE serial, + Create UART service compatible with Nordic's *nRF Toolbox* and Adafruit's + *Bluefruit LE* iOS/Android apps. You can also use another board with + serial_client example in File->Examples->BLE->Central menu to set up + a BLE serial connection between two different boards. + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include + + +// create ble serial instance +BLESerial bleSerial = BLESerial(); + +bat primo_bat; +double bat_voltage; + +void setup() { + // custom services and characteristics can be added as well + bleSerial.setLocalName("Arduino Primo"); + // start serial port at 115200 bps: + Serial.begin(115200); + // start BLE serial + bleSerial.begin(); + // disable STM32 enter to standby mode + stm32pwr.disableStandbyMode() ; + // initialize the LED pin as an output + pinMode(LED_BUILTIN, OUTPUT); +} + +void loop() { + delay(300); + // turn LED on + digitalWrite(LED_BUILTIN, HIGH); + // get battery voltage value + bat_voltage = primo_bat.analogRead(); + // print battery voltage vaule on serial port + Serial.print("Battery Voltage:" ); + Serial.println(bat_voltage,3); + // print battery voltage vaule on BLE serial + bleSerial.print("Battery Voltage:" ); + bleSerial.println(bat_voltage,3); + delay(300); + // turn LED off + digitalWrite(LED_BUILTIN, LOW); +} \ No newline at end of file diff --git a/libraries/Bat/keywords.txt b/libraries/Bat/keywords.txt new file mode 100644 index 0000000..9ed729c --- /dev/null +++ b/libraries/Bat/keywords.txt @@ -0,0 +1,19 @@ +####################################### +# Syntax Coloring Map bat +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +bat KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +analogRead KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### diff --git a/libraries/Bat/library.properties b/libraries/Bat/library.properties new file mode 100644 index 0000000..66dd4f4 --- /dev/null +++ b/libraries/Bat/library.properties @@ -0,0 +1,9 @@ +name=Bat +version=0.0.1 +author=Jeff Wu +maintainer=Arduino +sentence=bat +paragraph= This library is designed for using Primo board to get battery voltage value +category=Communication +url=http://www.arduino.org/learning/reference/bat +architectures=nrf52 \ No newline at end of file From 8e0cdc504299b3c379f4f09c7230ac381440af3b Mon Sep 17 00:00:00 2001 From: DHJeff Date: Fri, 28 Apr 2017 13:04:14 +0800 Subject: [PATCH 07/10] Added bat statement of pinMode --- cores/arduino/wiring_digital.c | 10 ++++++++++ variants/arduino_primo/variant.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 2543f9d..dc79fe2 100755 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -240,6 +240,16 @@ void pinMode( uint32_t ulPin, uint32_t ulMode ) return ; } + if ( (ulPin == 43) && (ulMode == INPUT) ) + { + delay(15); + TwoWire_begin(); + TwoWire_beginTransmission(0x48); + TwoWire_write(BAT_VOLT_IN); + TwoWire_endTransmission(); + return ; + } + if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN ) { return ; diff --git a/variants/arduino_primo/variant.h b/variants/arduino_primo/variant.h index 3e0a6d8..4f7cfc2 100755 --- a/variants/arduino_primo/variant.h +++ b/variants/arduino_primo/variant.h @@ -98,7 +98,7 @@ static const uint8_t GPIO_ESP_PW_H = 0b11101000; static const uint8_t GPIO_ESP_PW_L = 0b11101001; static const uint8_t GPIO_ESP_EN_H = 0b11101010; static const uint8_t GPIO_ESP_EN_L = 0b11101011; -static const uint8_t BAT_VOL_IN = 0b11101100; +static const uint8_t BAT_VOLT_IN = 0b11101100; static const uint8_t USER2_BUTTON_IN = 0b11101110; static const uint8_t GPIO_USER1_IT = 0b11111000; From 77aa4b0d862b66973c03737e6158bec186eff0e2 Mon Sep 17 00:00:00 2001 From: DHJeff Date: Fri, 28 Apr 2017 13:05:57 +0800 Subject: [PATCH 08/10] Added stm32pwr library --- .../Stm32pwr/examples/SleepMode/SleepMode.ino | 39 +++++++++ .../WiFiPowerManagement.ino | 45 +++++++++++ libraries/Stm32pwr/keywords.txt | 24 ++++++ libraries/Stm32pwr/library.properties | 9 +++ libraries/Stm32pwr/stm32pwr.cpp | 63 +++++++++++++++ libraries/Stm32pwr/stm32pwr.h | 81 +++++++++++++++++++ 6 files changed, 261 insertions(+) create mode 100644 libraries/Stm32pwr/examples/SleepMode/SleepMode.ino create mode 100644 libraries/Stm32pwr/examples/WiFiPowerManagement/WiFiPowerManagement.ino create mode 100644 libraries/Stm32pwr/keywords.txt create mode 100644 libraries/Stm32pwr/library.properties create mode 100644 libraries/Stm32pwr/stm32pwr.cpp create mode 100644 libraries/Stm32pwr/stm32pwr.h diff --git a/libraries/Stm32pwr/examples/SleepMode/SleepMode.ino b/libraries/Stm32pwr/examples/SleepMode/SleepMode.ino new file mode 100644 index 0000000..51ed733 --- /dev/null +++ b/libraries/Stm32pwr/examples/SleepMode/SleepMode.ino @@ -0,0 +1,39 @@ +/* + SleepMode.ino + + Written by Jeff Wu (jeff@arduino.org) + + This example for the Arduino Primo board shows how to use + stm32pwr library. + The STM32 has two functions for power savings. One is sleep mode, + and the other is standby mode. The USER1 BUTTON allows you setup + as an interrupt to trigger STM32 enter to sleep mode or wake up + from sleep mode. When the Primo board is powered by USB cable and + battery, and then disconnect the USB cable, the STM32 will enter + to standby mode or the Primo board is only powered by battery. + Waiting for Primo board reconnect to USB cable to wake up from + standby mode. The disableStandbyMode() function allows you to + disable STM32 enter to standby mode when the Primo disconnect + the USB cable. + + This example code is in the public domain. + +*/ + +#include + +void setup() { + // start serial port at 9600 bps + Serial.begin(9600); + // setup USER1_BUTTON as an interrupt to trigger STM32 + // enter to sleep mode or wake up from sleep mode + stm32pwr.enableSleepMode(); + // disable STM32 enter to standby mode + stm32pwr.disableStandbyMode() ; +} + +void loop() { + //Waiting for USER1 BUTTON press trigger STM32 enter to sleep mode + Serial.println("Waiting for USER1 BUTTON press"); + delay(5000); +} \ No newline at end of file diff --git a/libraries/Stm32pwr/examples/WiFiPowerManagement/WiFiPowerManagement.ino b/libraries/Stm32pwr/examples/WiFiPowerManagement/WiFiPowerManagement.ino new file mode 100644 index 0000000..2f689f4 --- /dev/null +++ b/libraries/Stm32pwr/examples/WiFiPowerManagement/WiFiPowerManagement.ino @@ -0,0 +1,45 @@ +/* + WiFiPowerManagement.ino + + Written by Jeff Wu (jeff@arduino.org) + + This example for the Arduino Primo board shows how to use + stm32pwr library. + The STM32 is able to turn the WiFi on or off directly, + Reducing the power consumption of Primo board. + + This example code is in the public domain. + +*/ + +#include + +int reading; // the current reading from the input pin +int state = true; //variable for setting WiFi status +long last_time = 0; // the last time the output pin was toggled +long debounce = 200; // the debounce time, increase if the output flickers + +void setup() { + // initialize the pushbutton pin as an input: + pinMode(USER2_BUTTON, INPUT); +} + +void loop() { + // read the state of the USER2 BUTTON value: + reading = digitalRead(USER2_BUTTON); + + // if the input is LOW and we've Waiting long enough to ignore any noise + // on the circuit, toggle the output pin and remember the time + if(reading == 0 && millis() - last_time > debounce ) { + state = !state; // reverse state + if(state == true) { + stm32pwr.powerOnWiFi(); //turn the WiFi on + stm32pwr.enableWiFi(); //enable WiFi + } + else { + stm32pwr.powerOffWiFi(); //turn the WiFi off + stm32pwr.disableWiFi(); //disable WiFi + } + last_time = millis(); + } +} \ No newline at end of file diff --git a/libraries/Stm32pwr/keywords.txt b/libraries/Stm32pwr/keywords.txt new file mode 100644 index 0000000..fd4ca2b --- /dev/null +++ b/libraries/Stm32pwr/keywords.txt @@ -0,0 +1,24 @@ +####################################### +# Syntax Coloring Map stm32pwr +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +stm32pwr KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +powerOnWiFi KEYWORD2 +powerOffWiFi KEYWORD2 +enableWiFi KEYWORD2 +disableWiFi KEYWORD2 +enableSleepMode KEYWORD2 +disableStandbyMode KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### diff --git a/libraries/Stm32pwr/library.properties b/libraries/Stm32pwr/library.properties new file mode 100644 index 0000000..5fd5d9c --- /dev/null +++ b/libraries/Stm32pwr/library.properties @@ -0,0 +1,9 @@ +name=Stm32pwr +version=0.0.1 +author=Jeff Wu +maintainer=Arduino +sentence=stm32pwr +paragraph=Allows STM32 enter to Sleep mode or standby mode +category=Communication +url=http://www.arduino.org/learning/reference/stm32pwr +architectures=nrf52 \ No newline at end of file diff --git a/libraries/Stm32pwr/stm32pwr.cpp b/libraries/Stm32pwr/stm32pwr.cpp new file mode 100644 index 0000000..61dd80a --- /dev/null +++ b/libraries/Stm32pwr/stm32pwr.cpp @@ -0,0 +1,63 @@ +/* +**************************************************************************** +* Copyright (c) 2017 Arduino srl. All right reserved. +* +* File : stm32pwr.cpp +* Date : 2017/04/30 +* Revision : 0.0.1 $ +* Author: jeff[at]arduino[dot]org +* +**************************************************************************** + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + +#include "stm32pwr.h" + + + +void stm32pwrClass::powerOnWiFi() +{ + digitalWrite(GPIO_ESP_PW, HIGH); +} + +void stm32pwrClass::powerOffWiFi() +{ + digitalWrite(GPIO_ESP_PW, LOW); +} + +void stm32pwrClass::enableWiFi() +{ + digitalWrite(GPIO_ESP_EN, HIGH); +} + +void stm32pwrClass::disableWiFi() +{ + digitalWrite(GPIO_ESP_EN, LOW); +} + +void stm32pwrClass::enableSleepMode() +{ + pinMode(USER1_BUTTON, STM32_IT); +} + +void stm32pwrClass::disableStandbyMode() +{ + pinMode(BAT_VOL, INPUT); +} + + +stm32pwrClass stm32pwr; diff --git a/libraries/Stm32pwr/stm32pwr.h b/libraries/Stm32pwr/stm32pwr.h new file mode 100644 index 0000000..a669abf --- /dev/null +++ b/libraries/Stm32pwr/stm32pwr.h @@ -0,0 +1,81 @@ +/* +**************************************************************************** +* Copyright (c) 2017 Arduino srl. All right reserved. +* +* File : stm32pwr.h +* Date : 2017/04/30 +* Revision : 0.0.1 $ +* Author: jeff[at]arduino[dot]org +* +**************************************************************************** + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + +#ifndef STM32PWR_h +#define STM32PWR_h + +#include "Arduino.h" + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif + + +class stm32pwrClass{ + + public: + + /** + * \turn the WiFi on + */ + void powerOnWiFi(void) ; + + /** + * \turn the WiFi off + */ + void powerOffWiFi(void) ; + + /** + * \enable WiFi + */ + void enableWiFi(void) ; + + /** + * \disable WiFi + */ + void disableWiFi(void) ; + + /** + * \setup USER1_BUTTON as an interrupt to trigger STM32 enter to sleep mode or wake up from sleep mode + */ + void enableSleepMode(void) ; + + /** + * \disable STM32 enter to standby mode + */ + void disableStandbyMode(void) ; + + private: + +}; + +extern stm32pwrClass stm32pwr; + +#endif //STM32PWR_h \ No newline at end of file From 2bd7a3872df14844433ca008346f042862186c56 Mon Sep 17 00:00:00 2001 From: DHJeff Date: Fri, 28 Apr 2017 16:26:39 +0800 Subject: [PATCH 09/10] Replaced delay function by nrf_delay_ms function --- cores/arduino/wiring_digital.c | 2 +- libraries/Bat/bat.cpp | 4 ++-- libraries/Bat/bat.h | 4 ++++ libraries/Cir/cir.cpp | 16 ++++++++-------- libraries/Cir/cir.h | 4 ++++ 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index dc79fe2..817518e 100755 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -242,7 +242,7 @@ void pinMode( uint32_t ulPin, uint32_t ulMode ) if ( (ulPin == 43) && (ulMode == INPUT) ) { - delay(15); + nrf_delay_ms(15); TwoWire_begin(); TwoWire_beginTransmission(0x48); TwoWire_write(BAT_VOLT_IN); diff --git a/libraries/Bat/bat.cpp b/libraries/Bat/bat.cpp index 46c63bc..3f17d97 100644 --- a/libraries/Bat/bat.cpp +++ b/libraries/Bat/bat.cpp @@ -34,7 +34,7 @@ double bat::analogRead(void) { double voltage; uint32_t code=0; - delay(150); + nrf_delay_ms(150); int i; for (i=0;i<4;i++) { @@ -45,7 +45,7 @@ double bat::analogRead(void) { Wire.beginTransmission(0x48); Wire.write(0xED); Wire.endTransmission(); - delay(15); + nrf_delay_ms(15); Wire.requestFrom(0x48,4, true); recBuffer[0] = Wire.read(); diff --git a/libraries/Bat/bat.h b/libraries/Bat/bat.h index 168300b..9b892bb 100644 --- a/libraries/Bat/bat.h +++ b/libraries/Bat/bat.h @@ -31,6 +31,10 @@ #include #include "Arduino.h" +extern "C" { + #include "nrf_delay.h" +} + #define REC_BUF_LENGTH 4 class bat { diff --git a/libraries/Cir/cir.cpp b/libraries/Cir/cir.cpp index 1749ba4..c55214b 100644 --- a/libraries/Cir/cir.cpp +++ b/libraries/Cir/cir.cpp @@ -31,7 +31,7 @@ cir::cir(void) { } void cir::enableReceiver(void) { - delay(100); + nrf_delay_ms(100); Wire.begin(); Wire.beginTransmission(0x48); Wire.write(0xA0); @@ -39,7 +39,7 @@ void cir::enableReceiver(void) { } void cir::disableReceiver(void) { - delay(15); + nrf_delay_ms(15); Wire.begin(); Wire.beginTransmission(0x48); Wire.write(0xA1); @@ -47,12 +47,12 @@ void cir::disableReceiver(void) { } bool cir::getReceiverStatus(void) { - delay(150); + nrf_delay_ms(150); Wire.begin(); Wire.beginTransmission(0x48); Wire.write(0xA2); Wire.endTransmission(); - delay(15); + nrf_delay_ms(15); Wire.requestFrom(0x48,4, true); recBuffer[0] = Wire.read(); @@ -79,16 +79,16 @@ uint32_t cir::digitalRead(void) { } void cir::enableTransmitter(void) { - delay(100); + nrf_delay_ms(100); Wire.begin(); Wire.beginTransmission(0x48); Wire.write(0xA3); Wire.endTransmission(); - delay(1500); + nrf_delay_ms(1500); } void cir::disableTransmitter(void) { - delay(100); + nrf_delay_ms(100); Wire.begin(); Wire.beginTransmission(0x48); Wire.write(0xA4); @@ -104,7 +104,7 @@ void cir::digitalWrite(uint32_t data) { transdata[2] = (data >> 8); transdata[3] = data; - delay(200); + nrf_delay_ms(200); Wire.begin(); Wire.beginTransmission(0x48); Wire.write(0xA5); diff --git a/libraries/Cir/cir.h b/libraries/Cir/cir.h index ddfafe9..98b6da9 100644 --- a/libraries/Cir/cir.h +++ b/libraries/Cir/cir.h @@ -31,6 +31,10 @@ #include #include "Arduino.h" +extern "C" { + #include "nrf_delay.h" +} + #define SEND_BUF_LENGTH 256 #define REC_BUF_LENGTH 74 From f1fb61ae753727a88c6c40e0fbfd04381f9fcf86 Mon Sep 17 00:00:00 2001 From: DHJeff Date: Fri, 28 Apr 2017 23:31:31 +0800 Subject: [PATCH 10/10] Renamed CIR, BAT and STM32 library folder name --- libraries/{Bat => BAT}/bat.cpp | 0 libraries/{Bat => BAT}/bat.h | 0 .../examples/BatteryVoltageValue/BatteryVoltageValue.ino | 0 libraries/{Bat => BAT}/keywords.txt | 0 libraries/{Bat => BAT}/library.properties | 2 +- libraries/{Cir => CIR}/cir.cpp | 0 libraries/{Cir => CIR}/cir.h | 0 libraries/{Cir => CIR}/examples/Receiver/Receiver.ino | 2 +- libraries/{Cir => CIR}/examples/Transmitter/Transmitter.ino | 0 libraries/{Cir => CIR}/keywords.txt | 0 libraries/{Cir => CIR}/library.properties | 2 +- .../{Stm32pwr => STM32PWR}/examples/SleepMode/SleepMode.ino | 0 .../examples/WiFiPowerManagement/WiFiPowerManagement.ino | 0 libraries/{Stm32pwr => STM32PWR}/keywords.txt | 0 libraries/{Stm32pwr => STM32PWR}/library.properties | 2 +- libraries/{Stm32pwr => STM32PWR}/stm32pwr.cpp | 0 libraries/{Stm32pwr => STM32PWR}/stm32pwr.h | 0 17 files changed, 4 insertions(+), 4 deletions(-) rename libraries/{Bat => BAT}/bat.cpp (100%) rename libraries/{Bat => BAT}/bat.h (100%) rename libraries/{Bat => BAT}/examples/BatteryVoltageValue/BatteryVoltageValue.ino (100%) rename libraries/{Bat => BAT}/keywords.txt (100%) rename libraries/{Bat => BAT}/library.properties (96%) rename libraries/{Cir => CIR}/cir.cpp (100%) rename libraries/{Cir => CIR}/cir.h (100%) rename libraries/{Cir => CIR}/examples/Receiver/Receiver.ino (95%) rename libraries/{Cir => CIR}/examples/Transmitter/Transmitter.ino (100%) rename libraries/{Cir => CIR}/keywords.txt (100%) rename libraries/{Cir => CIR}/library.properties (97%) rename libraries/{Stm32pwr => STM32PWR}/examples/SleepMode/SleepMode.ino (100%) rename libraries/{Stm32pwr => STM32PWR}/examples/WiFiPowerManagement/WiFiPowerManagement.ino (100%) rename libraries/{Stm32pwr => STM32PWR}/keywords.txt (100%) rename libraries/{Stm32pwr => STM32PWR}/library.properties (94%) rename libraries/{Stm32pwr => STM32PWR}/stm32pwr.cpp (100%) rename libraries/{Stm32pwr => STM32PWR}/stm32pwr.h (100%) diff --git a/libraries/Bat/bat.cpp b/libraries/BAT/bat.cpp similarity index 100% rename from libraries/Bat/bat.cpp rename to libraries/BAT/bat.cpp diff --git a/libraries/Bat/bat.h b/libraries/BAT/bat.h similarity index 100% rename from libraries/Bat/bat.h rename to libraries/BAT/bat.h diff --git a/libraries/Bat/examples/BatteryVoltageValue/BatteryVoltageValue.ino b/libraries/BAT/examples/BatteryVoltageValue/BatteryVoltageValue.ino similarity index 100% rename from libraries/Bat/examples/BatteryVoltageValue/BatteryVoltageValue.ino rename to libraries/BAT/examples/BatteryVoltageValue/BatteryVoltageValue.ino diff --git a/libraries/Bat/keywords.txt b/libraries/BAT/keywords.txt similarity index 100% rename from libraries/Bat/keywords.txt rename to libraries/BAT/keywords.txt diff --git a/libraries/Bat/library.properties b/libraries/BAT/library.properties similarity index 96% rename from libraries/Bat/library.properties rename to libraries/BAT/library.properties index 66dd4f4..0572243 100644 --- a/libraries/Bat/library.properties +++ b/libraries/BAT/library.properties @@ -1,4 +1,4 @@ -name=Bat +name=BAT version=0.0.1 author=Jeff Wu maintainer=Arduino diff --git a/libraries/Cir/cir.cpp b/libraries/CIR/cir.cpp similarity index 100% rename from libraries/Cir/cir.cpp rename to libraries/CIR/cir.cpp diff --git a/libraries/Cir/cir.h b/libraries/CIR/cir.h similarity index 100% rename from libraries/Cir/cir.h rename to libraries/CIR/cir.h diff --git a/libraries/Cir/examples/Receiver/Receiver.ino b/libraries/CIR/examples/Receiver/Receiver.ino similarity index 95% rename from libraries/Cir/examples/Receiver/Receiver.ino rename to libraries/CIR/examples/Receiver/Receiver.ino index 4da24f3..764fa00 100644 --- a/libraries/Cir/examples/Receiver/Receiver.ino +++ b/libraries/CIR/examples/Receiver/Receiver.ino @@ -5,7 +5,7 @@ This example for the Arduino Primo board shows how to use cir library. - cir data is received by 38kHz IR receiver of the Primo board, + CIR data is received by 38kHz IR receiver of the Primo board, It is based on the NEC protocol to decode signals from IR receiver to get hex code, you can see the hex code using serial montior when the Primo board receive CIR data. diff --git a/libraries/Cir/examples/Transmitter/Transmitter.ino b/libraries/CIR/examples/Transmitter/Transmitter.ino similarity index 100% rename from libraries/Cir/examples/Transmitter/Transmitter.ino rename to libraries/CIR/examples/Transmitter/Transmitter.ino diff --git a/libraries/Cir/keywords.txt b/libraries/CIR/keywords.txt similarity index 100% rename from libraries/Cir/keywords.txt rename to libraries/CIR/keywords.txt diff --git a/libraries/Cir/library.properties b/libraries/CIR/library.properties similarity index 97% rename from libraries/Cir/library.properties rename to libraries/CIR/library.properties index 135c0df..9da6224 100644 --- a/libraries/Cir/library.properties +++ b/libraries/CIR/library.properties @@ -1,4 +1,4 @@ -name=Cir +name=CIR version=0.0.1 author=Jeff Wu maintainer=Arduino diff --git a/libraries/Stm32pwr/examples/SleepMode/SleepMode.ino b/libraries/STM32PWR/examples/SleepMode/SleepMode.ino similarity index 100% rename from libraries/Stm32pwr/examples/SleepMode/SleepMode.ino rename to libraries/STM32PWR/examples/SleepMode/SleepMode.ino diff --git a/libraries/Stm32pwr/examples/WiFiPowerManagement/WiFiPowerManagement.ino b/libraries/STM32PWR/examples/WiFiPowerManagement/WiFiPowerManagement.ino similarity index 100% rename from libraries/Stm32pwr/examples/WiFiPowerManagement/WiFiPowerManagement.ino rename to libraries/STM32PWR/examples/WiFiPowerManagement/WiFiPowerManagement.ino diff --git a/libraries/Stm32pwr/keywords.txt b/libraries/STM32PWR/keywords.txt similarity index 100% rename from libraries/Stm32pwr/keywords.txt rename to libraries/STM32PWR/keywords.txt diff --git a/libraries/Stm32pwr/library.properties b/libraries/STM32PWR/library.properties similarity index 94% rename from libraries/Stm32pwr/library.properties rename to libraries/STM32PWR/library.properties index 5fd5d9c..cf1d058 100644 --- a/libraries/Stm32pwr/library.properties +++ b/libraries/STM32PWR/library.properties @@ -1,4 +1,4 @@ -name=Stm32pwr +name=STM32PWR version=0.0.1 author=Jeff Wu maintainer=Arduino diff --git a/libraries/Stm32pwr/stm32pwr.cpp b/libraries/STM32PWR/stm32pwr.cpp similarity index 100% rename from libraries/Stm32pwr/stm32pwr.cpp rename to libraries/STM32PWR/stm32pwr.cpp diff --git a/libraries/Stm32pwr/stm32pwr.h b/libraries/STM32PWR/stm32pwr.h similarity index 100% rename from libraries/Stm32pwr/stm32pwr.h rename to libraries/STM32PWR/stm32pwr.h