Skip to content

Commit b1a7375

Browse files
committed
show rs485 result and end test on button pressure
1 parent b2e8beb commit b1a7375

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

examples/utility/Provisioning_2.0/OptaFactoryTest.cpp

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#ifdef ARDUINO_OPTA
1010
#include "OptaFactoryTest.h"
11-
11+
#include "utility/ResetInput.h"
1212

1313
#define VID_FINDER 0x35D1
1414
#define VID_ARDUINO 0x2341
@@ -62,6 +62,11 @@ void OptaFactoryTestClass::begin() {
6262
do{
6363
_info = boardInfo();
6464
} while (_info == nullptr);
65+
if(_info->_board_functionalities.rs485 == 1){
66+
ResetInput::getInstance().setPinChangedCallback(buttonCallbackRS485);
67+
} else {
68+
ResetInput::getInstance().setPinChangedCallback(endCallback);
69+
}
6570

6671
}
6772
void OptaFactoryTestClass::optaIDTest() {
@@ -183,6 +188,10 @@ bool OptaFactoryTestClass::poll() {
183188

184189
}
185190

191+
if (_showRS485Result){
192+
showRS485SuccessResult();
193+
}
194+
186195
if (_nextBoardInfoPrint < millis())
187196
{
188197
_nextBoardInfoPrint = millis() + 3000;
@@ -300,14 +309,10 @@ void OptaFactoryTestClass::inputManage(void)
300309
digitalWrite(LEDG, LOW);
301310
digitalWrite(LEDB, LOW);
302311
_all_on = false;
303-
if(_info->_board_functionalities.rs485 == 0) {
304-
_test_running = false;
305-
}
306312
}
307313
}
308314

309315
void OptaFactoryTestClass::rs485Manage() {
310-
bool rs485_ok = false;
311316
uint32_t t_rs485_pulse = 0;
312317
digitalWrite(MY_RS485_RE_PIN, HIGH);
313318
digitalWrite(MY_RS485_DE_PIN, HIGH);
@@ -355,21 +360,12 @@ void OptaFactoryTestClass::rs485Manage() {
355360
if((_rs485_pulse == N_PULSE) || (_rs485_pulse == N_PULSE + 1))
356361
{
357362
Serial.println("RS485 check OK");
358-
rs485_ok = true;
363+
_rs485_test_done = true;
364+
_rs485_ok = true;
359365
}
360366
}
361367
}
362368

363-
if(rs485_ok == true)
364-
{
365-
digitalWrite(RL1, HIGH);
366-
digitalWrite(LED1_SYS, HIGH);
367-
delay(1000);
368-
digitalWrite(RL1, LOW);
369-
digitalWrite(LED1_SYS, LOW);
370-
_rs485_test_done = true;
371-
_test_running = false;
372-
}
373369
}
374370

375371

@@ -488,6 +484,37 @@ void OptaFactoryTestClass::printModel(void)
488484
Serial.println(" <<<\n");
489485
}
490486

487+
void OptaFactoryTestClass::endCallback() {
488+
if(digitalRead(BTN_USER) == HIGH)
489+
{
490+
_test_running = false;
491+
}
492+
}
493+
494+
void OptaFactoryTestClass::buttonCallbackRS485()
495+
{
496+
497+
if(digitalRead(BTN_USER) == LOW && _rs485_ok == true)
498+
{
499+
_showRS485Result = true;
500+
}
501+
}
502+
503+
void OptaFactoryTestClass::showRS485SuccessResult() {
504+
digitalWrite(RL1, HIGH);
505+
digitalWrite(LED1_SYS, HIGH);
506+
digitalWrite(RL4, HIGH);
507+
digitalWrite(LED4_SYS, HIGH);
508+
delay(1000);
509+
digitalWrite(RL1, LOW);
510+
digitalWrite(LED1_SYS, LOW);
511+
digitalWrite(RL4, LOW);
512+
digitalWrite(LED4_SYS, LOW);
513+
_test_running = false;
514+
_showRS485Result = false;
515+
516+
}
517+
491518
void OptaFactoryTestClass::rs485Rcv() {
492519
_rs485_pulse++;
493520
}

examples/utility/Provisioning_2.0/OptaFactoryTest.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ class OptaFactoryTestClass {
1919
void rs485Manage();
2020
void printInfo();
2121
void printModel();
22+
static void endCallback();
23+
static void buttonCallbackRS485();
24+
void showRS485SuccessResult();
2225
static void rs485Rcv();
2326
static inline uint32_t _rs485_pulse = 0;
2427
bool _all_on = false;
2528
bool _rs485_test_done = false;
26-
bool _test_running = false;
29+
static inline bool _test_running = false;
30+
static inline bool _rs485_ok = false;
31+
static inline bool _showRS485Result = false;
2732
OptaBoardInfo *_info = nullptr;
2833
uint32_t _ms10 = 0;
2934
uint32_t _ms100 = 0;

0 commit comments

Comments
 (0)