Skip to content

Commit 946e0bf

Browse files
committed
adding DigiSpark MCU class
1 parent 10ff540 commit 946e0bf

File tree

3 files changed

+134
-1
lines changed

3 files changed

+134
-1
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright © 2017 Simon Rupf
3+
*
4+
* This file is part of MonSens.
5+
*
6+
* MonSens is free software: you can redistribute it and/or modify it under the
7+
* terms of the GNU Lesser General Public License as published by the Free
8+
* Software Foundation, either version 3 of the License, or (at your option)
9+
* any later version.
10+
*
11+
* MonSens is distributed in the hope that it will be useful, but WITHOUT ANY
12+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14+
* more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with MonSens. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
/**
21+
* @file
22+
* @author Simon Rupf <[email protected]>
23+
* @brief MonSens implementation for the DigiSpark microcontroller board.
24+
*
25+
* The DigiSpark MCU by DigiStump packages a small amount of memory and some
26+
* pins onto a circuit board that doubles as a USB plug.
27+
*/
28+
29+
#include <MonSens_DigiSpark.h>
30+
31+
/**
32+
* Initialize the communicator, to be called in the MCUs setup routine.
33+
*/
34+
void MonSens_DigiSpark::init() {
35+
SerialUSB.begin();
36+
}
37+
38+
/**
39+
* Read inputs and respond to them, to be called in the MCUs loop routine.
40+
*/
41+
void MonSens_DigiSpark::communicate() {
42+
// Check if a client has connected
43+
if (SerialUSB.available()) {
44+
char request[4];
45+
for (uint8_t i = 0; i < 3 && request[i] != '\r' && request[i] != '\n'; ++i) {
46+
request[i] = SerialUSB.read();
47+
SerialUSB.delay(50); // wait for the shell to be ready to read
48+
}
49+
50+
// ask sensors for output and return it
51+
askSensors(request);
52+
}
53+
54+
SerialUSB.delay(3);
55+
}
56+
57+
58+
/**
59+
* Write output to the MCUs interface, inserting a line break at the end.
60+
*/
61+
void MonSens_DigiSpark::println(const char* output) {
62+
SerialUSB.println(output);
63+
}
64+
void MonSens_DigiSpark::println(const __FlashStringHelper* output) {
65+
SerialUSB.println(output);
66+
}
67+

libraries/MonSens/MonSens_DigiSpark.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright © 2017 Simon Rupf
3+
*
4+
* This file is part of MonSens.
5+
*
6+
* MonSens is free software: you can redistribute it and/or modify it under the
7+
* terms of the GNU Lesser General Public License as published by the Free
8+
* Software Foundation, either version 3 of the License, or (at your option)
9+
* any later version.
10+
*
11+
* MonSens is distributed in the hope that it will be useful, but WITHOUT ANY
12+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14+
* more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with MonSens. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
/**
21+
* @file
22+
* @author Simon Rupf <[email protected]>
23+
* @brief MonSens implementation for the DigiSpark microcontroller board.
24+
*
25+
* The DigiSpark MCU by DigiStump packages a small amount of memory and some
26+
* pins onto a circuit board that doubles as a USB plug.
27+
*/
28+
29+
#ifndef MONSENS_DIGISPARK_H
30+
#define MONSENS_DIGISPARK_H
31+
32+
#include <MonSens.h>
33+
#include <DigiCDC.h>
34+
35+
/**
36+
* MonSens implementation for the DigiSpark microcontroller board.
37+
*/
38+
class MonSens_DigiSpark: public IMonSens_Communicator {
39+
public:
40+
/**
41+
* Constructor
42+
*/
43+
MonSens_DigiSpark() {}
44+
45+
/**
46+
* Initialize the communicator, to be called in the MCUs setup routine.
47+
*/
48+
void init();
49+
50+
/**
51+
* Read inputs and respond to them, to be called in the MCUs loop routine.
52+
*/
53+
void communicate();
54+
55+
protected:
56+
/**
57+
* Write output to the MCUs interface, inserting a line break at the end.
58+
*/
59+
void println(const char* output);
60+
void println(const __FlashStringHelper* output);
61+
};
62+
63+
#endif
64+

wireless/ESP8266/initialize-sketchbooks.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ do
4141
fi
4242
done
4343

44-
# MonSens libraries
44+
# MonSens libraries, excluding DigiSpark (those only works when the Arduino IDE
45+
# is set to that board)
4546
cp -r "$SELF_PATH/../../libraries/MonSens" "$LIBRARY_PATH/"
47+
rm "$LIBRARY_PATH/DigiSpark.*"
4648

4749
# MonSens sketches
4850
for SKETCH in monsens-esp8266-example

0 commit comments

Comments
 (0)