Hello everyone,
I'm new to GEVCU7 and currently trying to add a new device to its codebase. However, since the codebase is quite extensive and I lack sufficient expertise, I've struggled to integrate it successfully.
My specific task is to read the state of the GEVCU7's DIN0 pin and print its state on the serial monitor. Essentially, I'm trying to integrate a proximity sensor, where the sensor's Normally Open (NO) pin is connected to DIN0.
Could someone kindly guide me on how to:
- Properly integrate this functionality?
- Get a quick overview of the directory structure to understand how to add and manage new devices in the codebase?
Any advice, examples, or pointers would be greatly appreciated.
Thank you!
I made GEVCU7 so I'd probably be the most help.
As a quick aside, for those who don't know, GEVCU7 is an open source vehicle control unit built around a Teensy micromod.
To quickly get up and running, you might be best off adding this functionality to an existing device driver so you can see what is going on. A reasonable place to start would be the "VehicleSpecific" driver found in src/devices/misc/VehicleSpecific.cpp
This shows a variety of things you need to do to make a device and set it up:
1. The constructor sets the common and short name for showing names to the end user
2. The header gives a unique 15 bit identifier for this device. In this case, it's 0x3000.
3. The header also sets up a define for the timer tick you want. It's in microseconds so 100000 = 100ms.
4. In the setup function it attaches the tick handler so you can get ticks at your requested interval
5. Then in handleTick those ticks are handled. Here is where you'd want to read your pin.
6. So, in there, you have lines like "if (systemIO.getDigitalIn(5))" this requests the status of DIN5. So, for you, you'd want systemIO.getDigitalIn(0)
7. There is a logging class that can send data to the console for you. There are lines like "Logger::debug("VS Setting gear to reverse");" in the code. This would send a debugging level message. GEVCU7 lets you set a logging level for the console so you'd need LOGLEVEL=0 to see debugging messages. There are also alert, error, info levels.
8. If I were you, I'd remove the existing example code and put just your check for DIN0 in there and have a logging level of like info (so, Logger:info) to show the information. Since the tick defaults to 100ms you'd get ten updates per second. You can drop that down to once per second or whatever you need.
So, that's how to get it initially going. To create a new device, just basically copy an existing device that's close to what you want to do and change the ID and character strings for common and short names then do your mods. The devices auto register themselves so all you need to do is instantiate your object and it does the rest. Note the last line of VehicleSpecific.cpp is "DMAMEM VehicleSpecific vehicle;"
Note, also, that this is all built upon Teensyduino. You can flash normal teensy code to the device and since it's basically a fancy Teensy 4.1 it will work the same way. If you want to use Serial.print it will go to the USB serial port just like you'd expect with Teensyduino. If you want to use the normal digital I/O functions, they work but you'd be working behind the back of the rest of the code and your results may not be ideal.