Devlog #09
I implemented some cool things, so let’s look at them.
printf
I got tired of the old way of sending data via USB (via snprintf and CDC_Transmit_FS) so I made my own USB_printf. It works almost like a regular printf. By almost I mean it does not work with floats, but that’s limited by the environment. If I ran it on linux or windows (just the formatting part) it would work fine, but on STM32 it’s a little different.
The function is just a wrapper for the old way, but with added timeout. It also checks whether any device is connected to usb, but it’s kinda weird. This way the function does not block the rest of the program when host is not connected.
Here’s how it looks:
uint8_t USB_printf(const char* fmt, ...);
So really nothing special, looks just like regular printf
Saving uptime data
Now via WriteHourStats I am able to write data about total uptime to eeprom. Inside the implementation I used something that I rarely use: union. Many people never even heard of it. Union makes all the inner properties share the same address. Example from the source code:
union HourBuffer {
uint8_t b8[2];
uint16_t b16;
} buffer;
No matter what I try to access, whether its b8[0] or b16 I get the same value. Well, not exactly. By accessing b8[0] i get lower part of b16, its the same as doing b16 & 0xff. Here I am writing data so I need to set b16 to a certain value. This also meant that it sets b8[0] and b[1]. This does not impact performance nor does it increase memory usage. The union is still just 16 bits. It can be done simpler but it is more readable and I wanted to use a union :) All it does is that it avoids weird pointer casting or shifting the value.
Next Steps
Now I’ll focus either on saving calibration data, that I started a little, or do something with the adc, like measuring temperature of the reference section, heater current and voltage on both +15V rails.