Set/setPixel and Get weren't using the same indices. I've taken the ones
used in Get and applied them to setPixel too.
This fixes testImageNoise for the monochrome image.
Tested on the following chips/boards:
* RP2040 (Raspberry Pi Pico)
* ATSAMD21 (Adafruit PyBadge)
* NRF52840 (PCA10056 developer board)
* ESP8266 (NodeMCU)
* ATmega328p (Arduino Uno)
* ESP32C3 (WaveShare ESP-C3-32S-Kit)
* FE310 (SiFive HiFive1 rev B)
The sensitivity threshold in the example may need to be adjusted per
board though, the default value of 100 typically recognizes when a cable
is being touched but the RP2040 for example is capable of doing much
more precise measurements if the power supply is sufficiently
noise-free.
For bigger images, the pixel index might not fit in a int16. Therefore,
int is needed during the calculation.
While fixing this bug, I've added a few tests that verify the Image
implementation by creating images, filling them with random data, and
then checking whether they still contain the same data. This test failed
before the patch.
At least one ft6336 device reports all 255 values from the first read
after reset or poweron, even after waiting the specified 300ms reset
delay.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
wifinina driver was not handling concurrent socket connections
correctly. When trying to make multiple socket connections, the sockfd
returned by the first Socket() call would be the same sockfd returned by
subsequent Socket() calls. The problem is the sockfd returned by
Socket() isn't used until Connect() (or Appect()). This would result in
Connect() trying to use the same sockfd for multiple connections,
causing wifinina fw to lock up.
The solution in this PR is to create a new sockfd space managed by the
driver that gives the app a unique, safe sockfd for each connection.
The real underlying sock fd returned by fw is set on Connect() (or
Accept()), and mapped back to the apps sockfd using a map:
sockets map[int]*Socket // keyed by sockfd
Where Socket has a reference to the fw sock:
type Socket struct {
protocol int
clientConnected bool
laddr netip.AddrPort // Set in Bind()
raddr netip.AddrPort // Set in Connect()
sock // Device socket, as returned from w.getSocket()
}
rpc_wifi_connect() will return 0 on successful connection, so check for
that. Also, check that if passphrase is given, that it's the minimum 8
chars per WPA Wifi.
Fix an error I introduced in porting wifinina to netdev. The driver was
starting a client on the socket once, during Connect. The first UDP
send on the socket would succeed, any subsequent sends would fail. The
fix is to start the client on the socket for each UDP send.
I think I see the logic in this design, so the fix makes sense. If the
device was sending to many UDP clients, it could use a single socket,
but change the dst addr for each send. The pkt data would be queued to
hw just once, and then sent from hw to each client dst addr. This would
be a real efficient way to multicast to many clients.