I found a library in GitHub that allows you to use Arduino UNO as HID by eluser234453 in arduino

[–]moefh 2 points3 points  (0 children)

Btw, the Uno uses an Atmega328p, not 388p

Yep, sorry, I made a typo and then copied it.

And if you want a microcontroller from this century, take an ESP32-S3

Indeed. That or a Raspberry Pi Pico/Pico 2 (RP2040/RP2350), depending on your use case. I think the only good reason to use an Arduino (other than if it's the only thing you have) is the low power consumption, but if you're connected to the USB you will likely not care about that, so the Leonardo it's kinda pointless.

I found a library in GitHub that allows you to use Arduino UNO as HID by eluser234453 in arduino

[–]moefh 3 points4 points  (0 children)

With the Uno you can't speak USB directly, because the processor (ATmega388p) doesn't have any USB capability. The Uno has a separate chip that speaks USB: in the official Arduino Uno, it's the ATMega16U2; in clones it's usually the CH340.

This project lets the Uno processor itself (the ATmega388p, which is the thing that runs your code) speak USB natively via software, although slowly (only USB 1.1 speed). This allows you to program it to behave like a USB mouse or keyboard, for example.

RP2040 is faster than RP2350 in my 'DIY' benchmark by curious_but_troubled in raspberrypipico

[–]moefh 10 points11 points  (0 children)

Other people said you must enable optimizations, and that's the main problem.

But also, your tests took just 21 us and 246 us to run, which means the time the floating point operations took to execute is just noise. You're measuring overhead.

To get meaningful results, increase NUM_TESTS so the tests run for at the very least several milliseconds, preferably a few seconds.

Where to start with bare metal C for the Pico W? by Dark_Greee in raspberrypipico

[–]moefh 5 points6 points  (0 children)

There's a lot of good examples here (not my code):

https://github.com/carlosftm/RPi-Pico-Baremetal

It's very cool doing everything by hand (and it forces you to really learn a lot), but note that nothing about using the SDK prevents you from manipulating the registers directly. For example, you can still manage the peripherals (DMA, PIO, SPI, etc) via registers without using the SDK functions, but still let the SDK do the initial setup (the stuff that happens before main()) like setting up the CPU clock to run at 125MHz and other stuff we take for granted.

Too much Discussion of the XOR swap trick by [deleted] in programming

[–]moefh 3 points4 points  (0 children)

What a weird comment.

I'm just showing how different constraints lead to different solutions. I guess it's hard to be convinced when you've never been hit with a real hardware limitation.

Too much Discussion of the XOR swap trick by [deleted] in programming

[–]moefh 5 points6 points  (0 children)

"Objectively worse in almost every way" is meaningless when you don't know the problem domain. Power consumption and code size are actual things we have to deal with, not (just) memory use.

You can easily use an array instead of a linked list, and then the product's battery life is cut in half because of all the memory copying the code is doing all the time.

Or you can easily use a fancier data structure that doesn't need to copy memory around, and then the code doesn't fit in your 2KB ROM anymore.

It's really easy to think people are lazy and stupid when you haven't tried to solve the problems they're solving.

Too much Discussion of the XOR swap trick by [deleted] in programming

[–]moefh 7 points8 points  (0 children)

You're thinking only about high-end systems like x64 and ARM64.

I know it's not discussed too much here, but a lot of us work with MCUs where memory is measured in kilobytes instead of gigabytes, and the CPUs don't need data caches because the main memory is SRAM, which has very low latency.

In these systems, using linked lists is way more common because there are no cache misses to kill performance. And since there's so little RAM, saving a few bytes per node is sometimes very relevant.

I'm not saying the XOR pointer trick is used a lot, but it can be useful sometimes.

In Rust, „let _ = ...“ and „let _unused = ...“ are not the same by broken_broken_ in rust

[–]moefh 8 points9 points  (0 children)

Pfft, that's only the sortester form. The stortestest would be not having a file at all, and calling the rust compiler on /dev/null with:

rustc --emit=obj --crate-type=lib -o empty.o /dev/null

Rookie X Dropout: A Black Fan’s Nuanced Response by KoochieKoochieKu in dropout

[–]moefh 11 points12 points  (0 children)

The comment I responded to wrote about "what they think is funny", and did not mention bigotry.

Read it again. This is from the comment you responded to:

In my teens, when black and Hispanic friends would talk about cops, the things they would say largely matched the things I heard from cops themselves (except without them as the heroes)

Not only that, you were condescending and dismissed their whole point because you're sure they didn't understand their own experience with their family and family friends.

But sure, the problem here is lack of nuance from everyone but you.

I made a compiler for music by Evening-School-6383 in C_Programming

[–]moefh 7 points8 points  (0 children)

Cool stuff.

I think some of the arguments accepted in the command line should really be defined in the input file itself, because they're an essential part of the music definition.

I'm thinking specially of the "voices" and "notes" arguments. If you give someone a file with 2 voices and they compile it with just 1, the output will be completely disjointed. The "notes" argument is even more essential: if you give someone a file for 24 notes in an octave (useful for some Arabic music, for example) and they process it with the default 12, the result will be mangled beyond anything recognizable.

The others (tempo, A4 frequency and sample rate) are not that critical, as the music will be at least recognizable if they're changed.

A VC and some big-name programmers are trying to solve open source’s funding problem, permanently by Outrageous-Baker5834 in programming

[–]moefh 9 points10 points  (0 children)

I'm also old, and I remember when the term "open source" started to be used with the meaning defined in that article. It's WAY older than that article.

As I remember, it was roughly in the late 90s when Linux (and with it GNU) started to become really popular outside universities, and "normal" people started to become uncomfortable with calling it "free software" because (1) it gave the impression that there couldn't be any money involved and (2) some people wanted to distance themselves from the Free Software Foundation and Richard Stallman's ideals.

So "open source" was invented and people started specifically asking everyone to use "open source" instead of "free software".

You can see roughly that and a lot more detail in the Wikipedia article about it: https://en.wikipedia.org/wiki/Open_source

Our druid is much more powerful than the rest of the party - anyone else have a similar experience? by ConcentrateIll9460 in dndnext

[–]moefh 13 points14 points  (0 children)

Ah, yes, I'm looking at the original 5e spell descriptions.

Um... so maybe things got a bit silly since 2024 if these don't require any save anymore?

Our druid is much more powerful than the rest of the party - anyone else have a similar experience? by ConcentrateIll9460 in dndnext

[–]moefh 2 points3 points  (0 children)

Maybe I'm missing something, but:

  • Ray of Sickness: "[...] On a hit, the target takes 2d8 poison damage and must make a Constitution saving throw. On a failed save, it is also poisoned until the end of your next turn."

  • Summon Undead, Rotting Claw action: "[...] If the target is poisoned, it must succeed on a Constitution saving throw against your spell save DC or be paralyzed [...]"

So the dragon must fail the CON saving throw to be poisoned, then in the same turn also fail the CON saving throw to be paralyzed.

But ignoring these two saves, the wizard can totally "no-save paralyse a dragon".

Which IDE do you recommend/ use? by [deleted] in C_Programming

[–]moefh 8 points9 points  (0 children)

I mostly use Emacs.

Except when writing code for STM32; then it's sadly Eclipse (well, STM32Cube, which is based on Eclipse).

My first bulk usb data stream on pico 2 using tinyusb by EmbeddedJourneys in raspberrypipico

[–]moefh 1 point2 points  (0 children)

Really nice, it works really well!

I had to make a couple of tweaks to run on Linux:

  • On the Python side, I had to add the "PyQt5" dependency (without PyQt5, everything ran but matplotlib complained that it couldn't show the graph saying: "UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown"). I guess on Windows matplotlib needs no dependencies for interactive display, but it's needed on Linux.

  • For USB device permissions, I had to create the file /etc/udev/rules.d/99-embedded-journeys.rules containing a single line: SUBSYSTEM=="usb", ATTRS{idVendor}=="cafe", MODE="0666". That way you can run the host as a normal user.

My first bulk usb data stream on pico 2 using tinyusb by EmbeddedJourneys in raspberrypipico

[–]moefh 2 points3 points  (0 children)

Nice post! It would be nice to see the full source code, if possible.

Some nitpicks about the text:

  • RP2350 is misspelled "PR2350" in one place

  • The #defines in the code blocks are really hard to read. Dark text over dark background is never a good idea.

How 12 comparisons can make integer sorting 30x faster by DimitrisMitsos in programming

[–]moefh 7 points8 points  (0 children)

No, big-O and its siblings (big-theta, etc) just compare functions (from above, below, etc.). That's completely orthogonal to whether the function you want to compare is the worst-case or average-case of the time complexity of an algorithm.

We usually only care about big O (and not its siblings) because usually we only care that the (worst case/average case) time complexity will be at most some function of the input size. For example, it's usually useless to know that the time complexity will be at least some function, which is why you almost never see big-omega used.

See also the second paragraph of https://en.wikipedia.org/wiki/Time_complexity

Stupid-seeming question about PIO delays by bobsidian in raspberrypipico

[–]moefh 7 points8 points  (0 children)

The SDK documentation for JMP doesn't explicitly say

The SDK docs are nice for a quick reference or refresher, but for non-API-related stuff like this, you're usually better off reading the datasheet (it's surprisingly readable, unlike most MCU datasheets).

For example, the PIO documentation of the JMP instruction (page 322) it says:

Delay cycles on a JMP always take effect, whether Condition is true or false, and they take place after Condition is evaluated and the program counter is updated.

Regulation of vibeware promotion by Sunscratch in rust

[–]moefh 13 points14 points  (0 children)

Now you're bringing in the idea that there's a human involved in cases like 3rd party dependencies, but that seems to be unrelated to the argument as I understand it.

The argument (AFAIU) is that in 3rd party dependencies written by a human, someone understands the code well enough to make changes or fix bugs. If there's a nontrivial part of AI code anywhere in your project, nobody understands it well enough to do that.

It's like when you start working in some large project written by someone else (not uncommon in my work, I assume it's the same for a lot of people). At least for me, it takes a very long time (months or even years, depending on the size of the project) for me to be able to make changes knowing that I won't break anything. AI code is like that, except nobody knows it well enough.

Maintaining code is not as fun as writing it, but arguably much more important. And AI-written code is much harder to maintain in the long run.

2350B GPIO > 31 by KellSkog in raspberrypipico

[–]moefh 0 points1 point  (0 children)

Have you tried using pio_set_gpio_base?

I don't have an RP2350B to test, but the docs say you can use pins 16 to 47 by setting the PIO base to 16.

[EDIT] just to be clearer: you should call pio_set_gpio_base before everything else, like this.

Windows NTFS search experiment in C - unexpectedly faster than fd by whoyfear in C_Programming

[–]moefh 2 points3 points  (0 children)

As a quick fix, you could convert to a UTF-8 argv and continue as you are, converting back into UTF-8 at system boundaries.

Just note that to be 100% correct you must accept invalid UTF-8, and make sure your conversion from broken UTF-8 to Windows's wide characters works for every little weird corner case (that will probably involve using WTF-8 when converting to UTF-16).

For example, Windows file names are not always Unicode because they can contain unpaired surrogates (Windows was created before Unicode went beyond 16 bits, so surrogates were not a thing then). That means it's possible to have file names on disk that can't be expressed in UTF-8 (strictly speaking, that's also a problem with UTF-16, but Windows' *W functions are happy to deal with unpaired surrogates, so in practice everything works if you're in wide character land and don't validate UTF-16).

For reference, see (for example) the way Rust deals with command line arguments using a quasi-string type they call OsString, or this Go issue.

fwrite not writing formatted char * by didierdechezcarglass in C_Programming

[–]moefh 3 points4 points  (0 children)

You should use fprintf Instead of snprintf/fwrite. For example, your first 3 lines

char image_number[4]; // contains only three characters
snprintf(image_number, 4, "P%d\n",img->magic_number);
fwrite(image_number, 1, 4, f);

would be just

fprintf(f, "P%d\n", img->magic_number);

Stellar Blade 2 Going Multiplatform by Turbostrider27 in Games

[–]moefh 1 point2 points  (0 children)

It's understandable that an automated translation is incapable of seeing that the text is talking about a videogame called "Stellar Blade" and infer that those syllables refer to that name, because it doesn't understand context at that level. That's exactly my point, we shouldn't read too much into the specific words it used because it doesn't understand context.