@@ -14,6 +14,8 @@ using namespace m5;
1414
1515M5_STAMPLC M5StamPLC;
1616
17+ static const char * TAG = " M5StamPLC" ;
18+
1719void M5_STAMPLC::begin ()
1820{
1921 M5.begin ();
@@ -34,8 +36,6 @@ void M5_STAMPLC::begin()
3436 if (_config.enableSdCard ) {
3537 sd_card_init ();
3638 }
37-
38- printf (" init done\n " );
3939}
4040
4141void M5_STAMPLC::update ()
@@ -48,34 +48,18 @@ void M5_STAMPLC::update()
4848/* -------------------------------------------------------------------------- */
4949void M5_STAMPLC::i2c_init ()
5050{
51- printf (" i2c init" );
5251 m5::In_I2C.release ();
5352 m5::In_I2C.begin (I2C_NUM_0, STAMPLC_PIN_I2C_INTER_SDA, STAMPLC_PIN_I2C_INTER_SCL);
54- // delay(1000);
55-
56- // Scan
57- printf (" start scan:\n " );
58- bool scan_list[120 ];
59- m5::In_I2C.scanID (scan_list);
60- uint8_t device_num = 0 ;
61- for (int i = 8 ; i < 0x78 ; i++) {
62- if (scan_list[i]) {
63- device_num++;
64- printf (" get 0x%02X\n " , i);
65- }
66- }
67- printf (" device num: %d\n " , device_num);
6853}
6954
7055/* -------------------------------------------------------------------------- */
7156/* IO EXT A */
7257/* -------------------------------------------------------------------------- */
7358void M5_STAMPLC::io_expander_a_init ()
7459{
75- printf (" io expander a init\n " );
7660 _io_expander_a = new PI4IOE5V6408_Class;
7761 if (!_io_expander_a->begin ()) {
78- printf ( " io expander a init failed\n " );
62+ ESP_LOGE (TAG, " io expander a init failed" );
7963 } else {
8064 _io_expander_a->resetIrq ();
8165
@@ -154,11 +138,9 @@ static std::vector<int> _out_pin_list = {0, 1, 2, 3};
154138
155139void M5_STAMPLC::io_expander_b_init ()
156140{
157- printf (" io expander b init\n " );
158-
159141 _io_expander_b = new AW9523_Class;
160142 if (!_io_expander_b->begin ()) {
161- printf ( " io expander b init failed\n " );
143+ ESP_LOGE (TAG, " io expander b init failed" );
162144 } else {
163145 _io_expander_b->configureDirection (0x0 ); // all inputs!
164146 _io_expander_b->openDrainPort0 (false ); // push pull default
@@ -227,10 +209,8 @@ void M5_STAMPLC::writePlcAllRelay(const uint8_t& relayState)
227209/* -------------------------------------------------------------------------- */
228210void M5_STAMPLC::lm75b_init ()
229211{
230- printf (" lm75b init\n " );
231-
232212 if (!LM75B.begin ()) {
233- printf ( " lm75b init failed\n " );
213+ ESP_LOGE (TAG, " lm75b init failed" );
234214 }
235215}
236216
@@ -244,10 +224,8 @@ float M5_STAMPLC::getTemp()
244224/* -------------------------------------------------------------------------- */
245225void M5_STAMPLC::ina226_init ()
246226{
247- printf (" ina226 init\n " );
248-
249227 if (!INA226.begin ()) {
250- printf ( " ina226 init failed\n " );
228+ ESP_LOGE (TAG, " ina226 init failed" );
251229 } else {
252230 // 28.4 Hz
253231 INA226.configure (INA226_AVERAGES_16, INA226_BUS_CONV_TIME_1100US, INA226_SHUNT_CONV_TIME_1100US,
@@ -271,9 +249,8 @@ float M5_STAMPLC::getIoSocketOutputCurrent()
271249/* -------------------------------------------------------------------------- */
272250void M5_STAMPLC::rx8130_init ()
273251{
274- printf (" rx8130 init\n " );
275252 if (!RX8130.begin ()) {
276- printf ( " rx8130 init failed!\n " );
253+ ESP_LOGE (TAG, " rx8130 init failed!" );
277254 } else {
278255 RX8130.disableIrq ();
279256 RX8130.clearIrqFlags ();
@@ -285,12 +262,8 @@ void M5_STAMPLC::rx8130_init()
285262/* -------------------------------------------------------------------------- */
286263void M5_STAMPLC::sd_card_init ()
287264{
288- printf (" sd card init\n " );
289-
290265 if (!SD.begin (STAMPLC_PIN_SD_CS, SPI, 4000000 )) {
291- printf (" sd card init failed\n " );
292- } else {
293- printf (" sd card init success\n " );
266+ ESP_LOGE (TAG, " sd card init failed" );
294267 }
295268}
296269
@@ -410,15 +383,12 @@ static void modbus_daemon(void* param)
410383{
411384 delay (2000 );
412385
413- printf (" start modbus daemon\n " );
414-
415386 mb_param_info_t reg_info;
416387
417388 while (1 ) {
418389 // Check for read/write events of Modbus master for certain events
419390 (void )mbc_slave_check_event ((mb_event_group_t )MB_READ_WRITE_MASK);
420391 ESP_ERROR_CHECK_WITHOUT_ABORT (mbc_slave_get_param_info (®_info, MB_PAR_INFO_GET_TOUT));
421- // const char* rw_str = (reg_info.type & MB_READ_MASK) ? "R" : "W";
422392
423393 // Filter events and process them accordingly
424394 if (reg_info.type & (MB_EVENT_HOLDING_REG_WR | MB_EVENT_HOLDING_REG_RD)) {
@@ -438,9 +408,6 @@ static void modbus_daemon(void* param)
438408 } else if (reg_info.type & MB_EVENT_DISCRETE_RD) {
439409 // Pass
440410 } else if (reg_info.type & (MB_EVENT_COILS_RD | MB_EVENT_COILS_WR)) {
441- // printf("> Get msg: C-{} addr: %d size: %d\n", rw_str, (unsigned)reg_info.mb_offset,
442- // (unsigned)reg_info.size);
443-
444411 // portENTER_CRITICAL(¶m_lock);
445412 modbus_handle_update_coils ();
446413 // portEXIT_CRITICAL(¶m_lock);
@@ -450,8 +417,6 @@ static void modbus_daemon(void* param)
450417
451418void M5_STAMPLC::modbus_slave_init ()
452419{
453- printf (" modbus slave init with id: %d, baud rate: %ld\n " , _config.modbusSlaveId , _config.modbusBaudRate );
454-
455420 // Using UART_NUM_1 for RS485
456421 Serial1.end ();
457422
@@ -526,8 +491,6 @@ void M5_STAMPLC::modbus_slave_init()
526491
527492void M5_STAMPLC::can_init ()
528493{
529- printf (" can init with baud rate: %ld\n " , _config.canBaudRate );
530-
531494 static twai_timing_config_t t_config;
532495 switch (_config.canBaudRate ) {
533496 case 25000 :
0 commit comments