1from __future__ import print_function
2
3import ttfw_idf
4
5EXPECT_TIMEOUT = 20
6
7
8@ttfw_idf.idf_example_test(env_tag='Example_I2C_CCS811_SENSOR')
9def test_i2ctools_example(env, extra_data):
10    # Get device under test, flash and start example. "i2ctool" must be defined in EnvConfig
11    dut = env.get_dut('i2ctools', 'examples/peripherals/i2c/i2c_tools', dut_class=ttfw_idf.ESP32DUT)
12    dut.start_app()
13    dut.expect('i2c-tools>', timeout=EXPECT_TIMEOUT)
14    # Get i2c address
15    dut.write('i2cdetect')
16    dut.expect('5b', timeout=EXPECT_TIMEOUT)
17    # Get chip ID
18    dut.write('i2cget -c 0x5b -r 0x20 -l 1')
19    dut.expect('0x81', timeout=EXPECT_TIMEOUT)
20    # Reset sensor
21    dut.write('i2cset -c 0x5b -r 0xFF 0x11 0xE5 0x72 0x8A')
22    dut.expect('OK', timeout=EXPECT_TIMEOUT)
23    # Get status
24    dut.write('i2cget -c 0x5b -r 0x00 -l 1')
25    dut.expect_any('0x10', timeout=EXPECT_TIMEOUT)
26    # Change work mode
27    dut.write('i2cset -c 0x5b -r 0xF4')
28    dut.expect('OK', timeout=EXPECT_TIMEOUT)
29    dut.write('i2cset -c 0x5b -r 0x01 0x10')
30    dut.expect('OK', timeout=EXPECT_TIMEOUT)
31    # Get new status
32    dut.write('i2cget -c 0x5b -r 0x00 -l 1')
33    dut.expect_any('0x98', '0x90', timeout=EXPECT_TIMEOUT)
34
35
36if __name__ == '__main__':
37    test_i2ctools_example()
38