Skip to content

Commit f09938f

Browse files
committed
Merge branch 'develop'
2 parents 3188045 + 303c4f4 commit f09938f

File tree

16 files changed

+208
-65
lines changed

16 files changed

+208
-65
lines changed

.github/workflows/buildExampleSketches.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
- name: Compile all examples
3737
uses: ArminJo/arduino-test-compile@v3
3838
with:
39+
sketches-exclude: PowerFunctions
3940
arduino-board-fqbn: ${{ matrix.arduino-boards-fqbn }}
4041
platform-url: https://dl.espressif.com/dl/package_esp32_index.json
4142
required-libraries: NimBLE-Arduino # use latest version
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: BuildPfExampleSketch
2+
on:
3+
push:
4+
paths:
5+
- '**.ino'
6+
- '**.cpp'
7+
- '**.h'
8+
- '.github/workflows/*.yml'
9+
pull_request:
10+
paths:
11+
- '**.ino'
12+
- '**.cpp'
13+
- '**.h'
14+
- '.github/workflows/*.yml'
15+
16+
jobs:
17+
build:
18+
name: ${{ matrix.arduino-boards-fqbn }}
19+
runs-on: ubuntu-latest
20+
21+
strategy:
22+
matrix:
23+
# The matrix will produce one job for each configuration parameter of type `arduino-boards-fqbn`
24+
arduino-boards-fqbn:
25+
- esp32:esp32:pico32:PartitionScheme=default,UploadSpeed=115200,DebugLevel=none # e.g. M5 Atom
26+
- esp32:esp32:heltec_wifi_kit_32:PSRAM=disabled,PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=40,FlashSize=4M,UploadSpeed=921600,DebugLevel=none
27+
- esp32:esp32:esp32wrover:PartitionScheme=default,FlashMode=qio,FlashFreq=80,UploadSpeed=921600,DebugLevel=none
28+
- esp8266:esp8266:nodemcuv2:xtal=80,vt=flash,exception=legacy,ssl=all,eesz=4M2M,led=2,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200
29+
- esp8266:esp8266:d1:xtal=80,vt=flash,exception=legacy,ssl=all,eesz=4M2M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=921600
30+
- esp8266:esp8266:huzzah:xtal=80,vt=flash,exception=legacy,ssl=all,eesz=4M2M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200
31+
- arduino:avr:uno
32+
- arduino:avr:nano:cpu=atmega328
33+
34+
# Do not cancel all jobs / architectures if one job fails
35+
fail-fast: false
36+
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v2
40+
41+
- name: Compile only power function example for different platforms
42+
uses: ArminJo/arduino-test-compile@v3
43+
with:
44+
arduino-board-fqbn: ${{ matrix.arduino-boards-fqbn }}
45+
sketch-names: "PowerFunctions.ino"
46+
platform-url: https://dl.espressif.com/dl/package_esp32_index.json,https://arduino.esp8266.com/stable/package_esp8266com_index.json
47+
required-libraries: NimBLE-Arduino # use latest version

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ All the included examples are a great source to find a solution or pattern for y
4949

5050
You can find different Examples in the "examples" folder. You can select the examples in your Arduino IDE via the Menu "File->Examples". Just have a look on the videos to see the examples running :smiley:
5151
* **Boost.ino:** Example who uses the basic boost moovements (feasable for M.T.R.4 or Vernie model). http://www.youtube.com/watch?v=VgWObhyUmi0
52-
* **MoveHubColorSensor.ino:** Example which reads in the color Sensor value on port C and uses the detected color to set the Hub LED accordingly. https://youtu.be/_xCd9Owy1nk
52+
* **ColorSensor.ino:** Example which reads in the color Sensor value (attached to an abritary port) and uses the detected color to set the Hub LED accordingly. https://youtu.be/_xCd9Owy1nk
5353
* **MoveHubDeviceInfo.ino:** Example which displays the various device infos (firmware version, battery level, rssi, hardwar version, tilt) in the serial monitor
54-
* **MoveHubDistanceSensor.ino:** Example which reads in the input of the distance sencor and set the Hub LED color dependent on the distance. https://youtu.be/TOAQtGGjZ6c
55-
* **MoveHubRotationSensor.ino:** Example which reads in the input of the Tacho motor angle to set the Hub LED dependent on the angle to the scale of rainbow colors. https://youtu.be/c3DHpX55uN0
54+
* **DistanceSensor.ino:** Example which reads in the input of the distance sencor and set the Hub LED color dependent on the distance. https://youtu.be/TOAQtGGjZ6c
55+
* **RotationSensor.ino:** Example which reads in the input of the Tacho motor angle to set the Hub LED dependent on the angle to the scale of rainbow colors. https://youtu.be/c3DHpX55uN0
5656
* **TrainHub.ino:** Example for a PowererdUp Hub to set the speed of a train model. http://www.youtube.com/watch?v=o1hgZQz3go4
5757
* **TrainColor.ino:** Example of PoweredUp Hub combined with color sensor to control the speed of the train dependent on the detected color. https://youtu.be/GZ0fqe3-Bhw
5858
* **HubEmulation.ino:** Example of an emulated PoweredUp Hub two port hub (train hub) which could receive signals from the PoweredUp app and will send out the signals as IR commands to a Powerfunction remote receiver. https://www.youtube.com/watch?v=RTNexxT4-yQ
@@ -327,7 +327,7 @@ To signalize the app which devices are connected you have to send some commands
327327

328328
## PowerFunction IR
329329

330-
To use the PowerFunction Infrared library you have to connect a IR-LED to your ESP32 controller. To instanciate a new object, you have to define on which pin the IR Led is connected. Additionally you can define the Power function channel which should be used.
330+
To use the PowerFunction Infrared library you have to connect a IR-LED to your controller. The PowerFunction part of the legoino library will work on different hardware architectures (AVR, ESP8266, ESP32). To instanciate a new object, you have to define on which pin the IR Led is connected. Additionally you can define the Power function channel which should be used. Pay attention, that the channel in the library starts with 0 and on the physical IR Lego controller it starts with 1. So if you want to control channel 1 of your physical device, you have to use channel 0 in the PowerFunction part of the library.
331331

332332
```c++
333333
#include "PowerFunctions.h"
@@ -426,6 +426,8 @@ Thanks to [@fvanroie](https://github.com/fvanroie) for his contribution about ca
426426
427427
Thanks for the original [PowerFunctions](https://github.com/jurriaan/Arduino-PowerFunctions) Library by [@jurriaan](https://github.com/jurriaan)
428428
429+
Thanks to [@wmarkow](https://github.com/wmarkow) for his detailed input about hub emulation issues on Android devices and his proposals.
430+
429431
# Remarks
430432
Prerequisite of that library is the NimBLE-Arduino library (https://github.com/h2zero/NimBLE-Arduino) with at least version 1.0.1 Otherwise the notifcations of changed charachteristic values will not work. So just install as a prerequesite the version 1.0.1 of that library via the Arduino Library manager or the platform.io library manager (https://www.arduinolibraries.info/libraries/nim-ble-arduino)
431433
Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
2-
* A MoveHub basic example to connect a boost hub, set the led color of the hub
3-
* dependent on the detected color of the color/distance sensor.
2+
* A Hub basic example to connect a hub, set the led color of the hub
3+
* dependent on the detected color of the color/distance sensor which
4+
* could be attached to any free port. The sketch will wait till a color
5+
* sensor ist attached to a port.
46
*
57
* (c) Copyright 2020 - Cornelius Munz
68
* Released under MIT License
@@ -10,13 +12,13 @@
1012
#include "Lpf2Hub.h"
1113

1214
// create a hub instance
13-
Lpf2Hub myMoveHub;
14-
byte portC = (byte)MoveHubPort::C;
15+
Lpf2Hub myHub;
16+
bool isInitialized = false;
1517

1618
void setup()
1719
{
1820
Serial.begin(115200);
19-
myMoveHub.init(); // initalize the MoveHub instance
21+
myHub.init(); // initalize the hub instance
2022
}
2123

2224
// callback function to handle updates of sensor values
@@ -25,7 +27,9 @@ void colorDistanceSensorCallback(void *hub, byte portNumber, DeviceType deviceTy
2527
Lpf2Hub *myHub = (Lpf2Hub *)hub;
2628

2729
Serial.print("sensorMessage callback for port: ");
28-
Serial.println(portNumber, DEC);
30+
Serial.print(portNumber, DEC);
31+
Serial.print(" value: ");
32+
Serial.println(pData[4], DEC);
2933
if (deviceType == DeviceType::COLOR_DISTANCE_SENSOR)
3034
{
3135
int color = myHub->parseColor(pData);
@@ -43,27 +47,34 @@ void loop()
4347
{
4448

4549
// connect flow. Search for BLE services and try to connect if the uuid of the hub is found
46-
if (myMoveHub.isConnecting())
50+
if (myHub.isConnecting())
4751
{
48-
myMoveHub.connectHub();
49-
if (myMoveHub.isConnected())
52+
myHub.connectHub();
53+
if (myHub.isConnected())
5054
{
5155
Serial.println("Connected to HUB");
52-
delay(200); //needed because otherwise the message is to fast after the connection procedure and the message will get lost
53-
// connect color/distance sensor to port c, activate sensor for updates
54-
myMoveHub.activatePortDevice(portC, colorDistanceSensorCallback);
55-
myMoveHub.setLedColor(GREEN);
56+
myHub.setLedColor(BLUE);
5657
}
5758
else
5859
{
5960
Serial.println("Failed to connect to HUB");
6061
}
6162
}
6263

63-
// if connected, you can set the name of the hub, the led color and shut it down
64-
if (myMoveHub.isConnected())
64+
if (myHub.isConnected() && !isInitialized)
6565
{
66-
// nothing has to be done because the sensor values are received in the callback function if an update occurs
66+
delay(200);
67+
Serial.print("check ports... if needed sensor is already connected: ");
68+
byte portForDevice = myHub.getPortForDeviceType((byte)DeviceType::COLOR_DISTANCE_SENSOR);
69+
Serial.println(portForDevice, DEC);
70+
if (portForDevice != 255)
71+
{
72+
Serial.println("activatePortDevice");
73+
myHub.activatePortDevice(portForDevice, colorDistanceSensorCallback);
74+
delay(200);
75+
myHub.setLedColor(GREEN);
76+
isInitialized = true;
77+
};
6778
}
6879

6980
} // End of loop

examples/MoveHubDistanceSensor/MoveHubDistanceSensor.ino renamed to examples/DistanceSensor/DistanceSensor.ino

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
2-
* A MoveHub basic example to connect a boost hub, set the led color of the hub
3-
* dependent on the detected distance of the distance/color sensor
2+
* A hub basic example to connect a hub, set the led color of the hub
3+
* dependent on the detected distance of the distance/color sensor. The sensor
4+
* can be connect to any port. The sketch will wait till a color-distance sensor
5+
* will be attached on any port.
46
*
57
* (c) Copyright 2020 - Cornelius Munz
68
* Released under MIT License
@@ -10,16 +12,18 @@
1012
#include "Lpf2Hub.h"
1113

1214
// create a hub instance
13-
Lpf2Hub myMoveHub;
14-
byte portC = (byte)MoveHubPort::C;
15+
Lpf2Hub myHub;
16+
bool isInitialized = false;
1517

1618
// callback function to handle updates of sensor values
1719
void distanceSensorCallback(void *hub, byte portNumber, DeviceType deviceType, uint8_t *pData)
1820
{
1921
Lpf2Hub *myHub = (Lpf2Hub *)hub;
2022

2123
Serial.print("sensorMessage callback for port: ");
22-
Serial.println(portNumber, DEC);
24+
Serial.print(portNumber, DEC);
25+
Serial.print(" value: ");
26+
Serial.println(pData[7], DEC);
2327
if (deviceType == DeviceType::COLOR_DISTANCE_SENSOR)
2428
{
2529
double distance = myHub->parseDistance(pData);
@@ -47,34 +51,42 @@ void distanceSensorCallback(void *hub, byte portNumber, DeviceType deviceType, u
4751
void setup()
4852
{
4953
Serial.begin(115200);
50-
myMoveHub.init(); // initalize the MoveHub instance
54+
myHub.init(); // initalize the MoveHub instance
5155
}
5256

5357
// main loop
5458
void loop()
5559
{
5660

5761
// connect flow. Search for BLE services and try to connect if the uuid of the hub is found
58-
if (myMoveHub.isConnecting())
62+
if (myHub.isConnecting())
5963
{
60-
myMoveHub.connectHub();
61-
if (myMoveHub.isConnected())
64+
myHub.connectHub();
65+
if (myHub.isConnected())
6266
{
6367
Serial.println("Connected to HUB");
64-
delay(200); //needed because otherwise the message is to fast after the connection procedure and the message will get lost
65-
// connect color/distance sensor to port c, activate sensor for updates, set callback function if distance value changes
66-
myMoveHub.activatePortDevice(portC, distanceSensorCallback);
67-
myMoveHub.setLedColor(GREEN);
68+
myHub.setLedColor(BLUE);
6869
}
6970
else
7071
{
7172
Serial.println("Failed to connect to HUB");
7273
}
7374
}
7475

75-
// if connected, you can set the name of the hub, the led color and shut it down
76-
if (myMoveHub.isConnected())
76+
if (myHub.isConnected() && !isInitialized)
7777
{
78+
delay(200);
79+
Serial.print("check ports... if needed sensor is already connected: ");
80+
byte portForDevice = myHub.getPortForDeviceType((byte)DeviceType::COLOR_DISTANCE_SENSOR);
81+
Serial.println(portForDevice, DEC);
82+
if (portForDevice != 255)
83+
{
84+
Serial.println("activatePortDevice");
85+
myHub.activatePortDevice(portForDevice, distanceSensorCallback);
86+
delay(200);
87+
myHub.setLedColor(GREEN);
88+
isInitialized = true;
89+
};
7890
}
7991

8092
} // End of loop
Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/**
2-
* A MoveHub basic example to connect a boost hub, set the led color of the hub
3-
* dependent on the detected rotation of the boost tacho motor. Usage of callback function
4-
* if motor angle is changed
2+
* A hub basic example to connect a hub, set the led color of the hub
3+
* dependent on the detected rotation of the connected tacho motor. Usage of callback function
4+
* if motor angle is changed. The tacho motor can be attached to any port and the
5+
* sketch will wait until the tacho motor is attached. If the hub button is pressed,
6+
* the encode position will be set to 0
57
*
68
* (c) Copyright 2020 - Cornelius Munz
79
* Released under MIT License
@@ -10,10 +12,13 @@
1012

1113
#include "Lpf2Hub.h"
1214

13-
// create a hub instance
14-
Lpf2Hub myMoveHub;
15-
byte portD = (byte)MoveHubPort::D;
15+
// Define here the linear/angular motor which you will connect to a port of your hub
16+
DeviceType device = DeviceType::MEDIUM_LINEAR_MOTOR;
1617

18+
// create a hub instance
19+
Lpf2Hub myHub;
20+
byte port;
21+
bool isInitialized = false;
1722

1823
void buttonCallback(void *hub, HubPropertyReference hubProperty, uint8_t *pData)
1924
{
@@ -22,7 +27,7 @@ void buttonCallback(void *hub, HubPropertyReference hubProperty, uint8_t *pData)
2227
if (hubProperty == HubPropertyReference::BUTTON)
2328
{
2429
if (myHub->parseHubButton(pData) == ButtonState::PRESSED) {
25-
myHub->setAbsoluteMotorEncoderPosition(portD, 0);
30+
myHub->setAbsoluteMotorEncoderPosition(port, 0);
2631
}
2732
}
2833
}
@@ -47,38 +52,46 @@ void tachoMotorCallback(void *hub, byte portNumber, DeviceType deviceType, uint8
4752
void setup()
4853
{
4954
Serial.begin(115200);
50-
myMoveHub.init(); // initalize the MoveHub instance
55+
myHub.init(); // initalize the MoveHub instance
5156
}
5257

5358
// main loop
5459
void loop()
5560
{
5661

5762
// connect flow. Search for BLE services and try to connect if the uuid of the hub is found
58-
if (myMoveHub.isConnecting())
63+
if (myHub.isConnecting())
5964
{
60-
myMoveHub.connectHub();
61-
if (myMoveHub.isConnected())
65+
myHub.connectHub();
66+
if (myHub.isConnected())
6267
{
6368
Serial.println("Connected to HUB");
6469
delay(200); //needed because otherwise the message is to fast after the connection procedure and the message will get lost
65-
// connect boost tacho motor to port d, activate sensor for updates, set callback function for rotation changes
66-
myMoveHub.activatePortDevice(portD, tachoMotorCallback);
67-
delay(50);
68-
myMoveHub.activateHubPropertyUpdate(HubPropertyReference::BUTTON, buttonCallback);
69-
70-
myMoveHub.setLedColor(GREEN);
70+
myHub.activateHubPropertyUpdate(HubPropertyReference::BUTTON, buttonCallback);
71+
myHub.setLedColor(BLUE);
7172
}
7273
else
7374
{
7475
Serial.println("Failed to connect to HUB");
7576
}
7677
}
7778

78-
// if connected, you can set the name of the hub, the led color and shut it down
79-
if (myMoveHub.isConnected())
79+
if (myHub.isConnected() && !isInitialized)
8080
{
81-
// nothing has to be done because the sensor values are received in the callback function if an update occurs
81+
delay(200);
82+
Serial.print("check ports... if needed sensor is already connected: ");
83+
byte portForDevice = myHub.getPortForDeviceType((byte)device);
84+
Serial.println(portForDevice, DEC);
85+
if (portForDevice != 255)
86+
{
87+
port = portForDevice;
88+
Serial.println("activatePortDevice");
89+
myHub.activatePortDevice(portForDevice, tachoMotorCallback);
90+
delay(200);
91+
myHub.setLedColor(GREEN);
92+
isInitialized = true;
93+
};
8294
}
8395

96+
8497
} // End of loop

examples/TrainColor/TrainColor.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* A Train hub basic example to connect a PoweredUp hub, and set the speed of the train
33
* motor dependent on the detected color. If the train is stopped, you can start the train by
4-
* pressing the hub button.
4+
* pressing the hub button. The train motor has to be connected to Port A and the Color sensor to Port B
55
*
66
* (c) Copyright 2020 - Cornelius Munz
77
* Released under MIT License

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Legoino
2-
version=1.0.2
2+
version=1.0.3
33
author=Cornelius Munz <cornelius.munz@gmx.de>
44
maintainer=Cornelius Munz <cornelius.munz@gmx.de>
55
sentence=Library for controlling PoweredUp, Boost, Corntrol+ controllers/hubs

src/Boost.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*
99
*/
1010

11+
#if defined(ESP32)
12+
1113
#include "Boost.h"
1214

1315
Boost::Boost(){};
@@ -104,3 +106,5 @@ void Boost::moveArcRight(int degrees = 90)
104106
{
105107
moveArc(degrees);
106108
}
109+
110+
#endif // ESP32

0 commit comments

Comments
 (0)