The worst part is that the result register is a 16 bit value that's split so that 4 bits give you exponent and 12 bits give you manitsa for float point and you have a formula for calculating the lux. I felt if I ran this code on our microcontroller that it would shame me how bad it was.
I know what you mean. What I’m doing for the last years, is using more conditions. Every time I want to know what specific variable has or which return value, it reminds me of setting proper conditions.
Then you can just step in important stuff. Of course when you use dependency which are not from yourself and have not access to code it’s different.
Why would he convert unsigned char to float just to print it as %d? What was the idea behind that bc all i can see is waste of microcontrollers memory lmao
Because in datasheet it says that16-bit result register (0x00) has 2 two fields a 4-bit exponent and 12-bit mantissa so you would need to calculate real float value. I thought he should just bit shift to get both values and then plug them into formula. I guess he thought he could just do int -> float typecast and magic compiler will do magic things.
Printing as %d just AND with & just shows he has no idea what is going on.
Seems like he knows enough to copy examples can’t see where to cut the fluff. Or he’s trying to make it hard to follow so he looks complex. You know, job security.
getResult is a function in a function. while doesn’t have the necessary predicate. Printing the address of the float as an integer rather than printing a float.
Also, the indentation is atrocious, magic numbers in the read register call, missing semicolons.
I was a about to comment something like "I thought I knew how to code, but I don't have any idea what this says or why it's bad" - basically because it's using a data type and a function that I'm not familiar with. And also what I presume to be memory locations? (The hex)
But then I went and read it again. It's super easy to understand, and yea, it's wicked, wicked bad.
How many assignments do you need there partner? Why not reassign the same value a few more times, what could it hurt hey?
Edit: wait that uint8 declaration is presumably an integer type, and he then assigns it to a float value when it is the return from the function?
This gets better and better (read: worse and worse) the more you read it.
23
u/CrazySD93 Mar 02 '23
Looks like a lot of example code I see on shitty microcontroller how-to's.
31
u/KingJeff314 Mar 02 '23
6
u/Lava-Lamp-Goo Mar 02 '23
Why would he convert unsigned char to float just to print it as %d? What was the idea behind that bc all i can see is waste of microcontrollers memory lmao
92
u/[deleted] Mar 02 '23
I lol'd hard at that float function
48
u/blownIGBT Mar 02 '23
Seems like he knows enough to copy examples can’t see where to cut the fluff. Or he’s trying to make it hard to follow so he looks complex. You know, job security.
48
u/reallokiscarlet Mar 02 '23
Is that a fucking
Function defined in a function?
14
u/CaitaXD Mar 02 '23
This is not legal c I'm pretty shure
11
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Mar 02 '23
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
3
u/StochasticTinkr Mar 02 '23
getResult is a function in a function. while doesn’t have the necessary predicate. Printing the address of the float as an integer rather than printing a float.
Also, the indentation is atrocious, magic numbers in the read register call, missing semicolons.
This isn’t C. This is compiler error.
2
u/invaderdan Mar 02 '23
I was a about to comment something like "I thought I knew how to code, but I don't have any idea what this says or why it's bad" - basically because it's using a data type and a function that I'm not familiar with. And also what I presume to be memory locations? (The hex)
But then I went and read it again. It's super easy to understand, and yea, it's wicked, wicked bad.
How many assignments do you need there partner? Why not reassign the same value a few more times, what could it hurt hey?
Edit: wait that uint8 declaration is presumably an integer type, and he then assigns it to a float value when it is the return from the function?
This gets better and better (read: worse and worse) the more you read it.
1
u/Equivalent-Win-1294 Mar 02 '23
Well, he’s not wrong about his claims.
1
u/BinaryBlasphemy Mar 02 '23
Some people can’t afford indentation you insensitive goon!
1
u/TrillOGeebs Mar 02 '23
I’m the address of the result being printed
1
u/djaure Mar 02 '23
He didn’t say how he codes tho
1
u/[deleted] Mar 02 '23
Idiots: AI is going to take programmers jobs! The AI:
1
u/TheEeveeLovers May 05 '23 edited May 05 '23
What really gets me about this is
res = ambient_resultWhen
resis typefloatandambient_resultis typeuint8_tPretty sure Visual Studio would warn this as a loss of data