FedeDP / Clightd

A linux bus interface that lets you change screen brightness, compute captured webcam frames brightness and change screen temperature.
GNU General Public License v3.0
81 stars 10 forks source link

Possibility for use CJMCU-88 ALS sensor #31

Closed lukas1760 closed 4 years ago

lukas1760 commented 4 years ago

Is there a way to use a i2c ALS device (CJMCU-88) instead of camera on Raspbian to detect the light intensity?

FedeDP commented 4 years ago

Hi! Clightd should already support ALS devices: https://github.com/FedeDP/Clightd/wiki/Sensors . Is this working for you: busctl call org.clightd.clightd /org/clightd/clightd/Sensor/Als org.clightd.clightd.Sensor IsAvailable "s" "" ?

FedeDP commented 4 years ago

@lukas1760 Any news on this?

lukas1760 commented 4 years ago

No. Currently I have problem with basic funcionality. I have older version working with picamera on RPi3 with Stretch, but it didn't work on buster in my case. I can post any log if you want.

FedeDP commented 4 years ago

I can post any log if you want.

Yes, please! Can you post systemctl status clightd.service output?

lukas1760 commented 4 years ago

clightd.service - Bus service to manage various screen related properties (gamma, dpms, backligh Loaded: loaded (/usr/lib/systemd/system/clightd.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2019-10-08 15:42:56 CEST; 2min 43s ago Main PID: 341 (clightd) Tasks: 2 (limit: 1480) Memory: 1.5M CGroup: /system.slice/clightd.service \u2514\u2500341 /usr/lib/clightd/clightd

Oct 08 15:42:54 raspberrypi systemd[1]: Starting Bus service to manage various screen related prop Oct 08 15:42:55 raspberrypi clightd[341]: Registered Als sensor. Oct 08 15:42:55 raspberrypi clightd[341]: Registered Camera sensor. Oct 08 15:42:55 raspberrypi clightd[341]: (watch_displays_using_udev) Starting Oct 08 15:42:56 raspberrypi systemd[1]: Started Bus service to manage various screen related prope ~ but I have no config file in home/user/.config directory and also no log file in home/user directory

lukas1760 commented 4 years ago

and ALS sensor is CJMCU-88

FedeDP commented 4 years ago

It seems that Clightd is correctly working.
What about clight? Which versions are you on?

Btw can you try busctl call org.clightd.clightd /org/clightd/clightd/Sensor/Als org.clightd.clightd.Sensor IsAvailable "s" "" to test taking a capture with your ALS sensor?

lukas1760 commented 4 years ago

I tried it yesterday so it's the last version. reply on your command is sb "" false

FedeDP commented 4 years ago

Ok, so clightd cannot see any ALS device.

Can you share your ls /sys/class/als output?

lukas1760 commented 4 years ago

hmm..I don't have als folder in /sys/class but if I try i2cdetect -y 1, I see it in the matrix.

FedeDP commented 4 years ago

What about ls /sys/bus/acpi/drivers/acpi_als/ ?

lukas1760 commented 4 years ago

nothing. I have only this in /sys/bus/ directory amba cpu hid media nvmem serial clockevents event_source i2c mipi-dsi platform spi clocksource genpd iscsi_flashnode mmc scsi usb container gpio mdio_bus mmc_rpmb sdio workqueue

and /sys/class/

backlight graphics iscsi_session raw thermal bcm2708_vcio hidraw iscsi_transport rc tty bcm2835-gpiomem hwmon leds regulator uio bdi i2c-adapter lirc rfkill usbmisc block i2c-dev mdio_bus rtc vc bluetooth ieee80211 mem scsi_device vchiq bsg input misc scsi_disk vc-mem devcoredump iscsi_connection mmc_host scsi_host vc-sm dma iscsi_endpoint net sound video4linux drm iscsi_host power_supply spi_master vtconsole gpio iscsi_iface pwm spi_slave watchdog

FedeDP commented 4 years ago

It seems like your ALS device is not using acpi-als driver (that is supported by clightd).

Can you share with me udevadm monitor output while attaching the ALS device? Ie: you start "udevadm monitor" and then, while monitor is running, you attach the device.

FedeDP commented 4 years ago

Ps: what about ls /sys/bus/iio/devices/ too?

lukas1760 commented 4 years ago

udevadm monitor nothing will happen...

i don't have iio directory

FedeDP commented 4 years ago

What about ls /sys/class/backlight/?

lukas1760 commented 4 years ago

This directory is empty. Could you write the exact name or paste link on supported device?

FedeDP commented 4 years ago

Clightd supports devices through iio::acpi-als kernel module. Have a look here: https://01.org/linuxgraphics/gfx-docs/drm/driver-api/iio/core.html#industrial-i-o-devices. It seems like your device driver does not expose any iio subsystem interface...

FedeDP commented 4 years ago

Mmh after quite a long search, i can say that: CJMCU-88 als chip is TMD27713 by Ams, here its databook: https://iq.components-store.com/datasheets/00/TMD27713.pdf.

It seems like there is in-kernel support for it, in iio subsystem: https://github.com/torvalds/linux/blob/master/drivers/iio/light/tsl2772.c, thus theoretically it should work fine.

It was moved out of staging on 12 may 2018: https://github.com/torvalds/linux/commits/master/drivers/iio/light/tsl2772.c.

If you have an older kernel, you should build its support from staging.

lukas1760 commented 4 years ago

Great job! But I have no idea how to do it. :) Anyway it also doesn't work even if only pi camera is connected. As I said..

No. Currently I have problem with basic funcionality. I have older version working with picamera on RPi3 with Stretch, but it didn't work on buster in my case. I can post any log if you want.

FedeDP commented 4 years ago

Mmmh ok let's fix that then!

Which Clight/Clightd/libmodule versions are you using? On which OS?

lukas1760 commented 4 years ago

It's raspbian buster with latest libmodule. It is fresh install without anything else. Just OS, clight and also dependencies

FedeDP commented 4 years ago

Thus you are using libmodule 5.0.0 and clight/clightd from git master, can confirm?

Can you paste here clight log from a --verbose run?

lukas1760 commented 4 years ago

Agree. Here is log from /.local/share/clight/clight.log. I think that is the same. clight.log

FedeDP commented 4 years ago

Agree. Here is log from /.local/share/clight/clight.log. I think that is the same.

That is a different issue upon Clight :) I have found the root cause and i will fix it asap! In the meantime, you could set a fixed location or uncomment "no_gamma = true;" line in conf file.

And btw thanks for spotting this issue!

lukas1760 commented 4 years ago

Sorry, My bad. :-) I disabled gamma so now I’m waiting for your answer. Your welcome!

FedeDP commented 4 years ago

So, is it working fine now, with gamma disabled? :)

lukas1760 commented 4 years ago

Unfortunately no. Camera is connected, checked with ffplay command but still not working. Here is status of clightd.service

clightd.service - Bus service to manage various screen related properties (gamma, dpms, backlight) Loaded: loaded (/usr/lib/systemd/system/clightd.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2019-11-03 15:56:14 CET; 3 days ago Main PID: 354 (clightd) Tasks: 2 (limit: 1480) Memory: 2.0M CGroup: /system.slice/clightd.service \u2514\u2500354 /usr/lib/clightd/clightd

Nov 03 15:56:12 raspberrypi systemd[1]: Starting Bus service to manage various screen related properties (gamma, dpms, Nov 03 15:56:14 raspberrypi clightd[354]: Registered Als sensor. Nov 03 15:56:14 raspberrypi clightd[354]: Registered Camera sensor. Nov 03 15:56:14 raspberrypi clightd[354]: (watch_displays_using_udev) Starting Nov 03 15:56:14 raspberrypi systemd[1]: Started Bus service to manage various screen related properties (gamma, dpms, b Nov 03 15:56:26 raspberrypi clightd[354]: No video capture device: Success Nov 03 15:56:36 raspberrypi clightd[354]: No video capture device: Success Nov 06 18:23:55 raspberrypi clightd[354]: No video capture device: Success Nov 06 18:26:17 raspberrypi clightd[354]: No video capture device: Success

EDIT: now it's working. It was necessary to manually setup video device in config file. So what about the ALS sensor? Do you have idea how to build it? Thanks

FedeDP commented 4 years ago

now it's working. It was necessary to manually setup video device in config file

Great to know! Note also that latest Clight commit: https://github.com/FedeDP/Clight/commit/ebe7f7042e9ce516dc6e47da94f55f5925acdcec should address that issue!

So what about the ALS sensor?

What's your current kernel version? uname -a will tell us!

lukas1760 commented 4 years ago

Good job! Linux raspberrypi 4.19.75-v7+ #1270 SMP Tue Sep 24 18:45:11 BST 2019 armv7l

FedeDP commented 4 years ago

Your kernel was release @Sat, 21 Sep 2019 08:36:07; it means it already has correct driver out of staging.

Maybe it is not built for raspbian? What is your sudo depmod -av | grep tsl2772 output?

If it does not output anything, you are out of luck and it seems you'll have to build the kernel module manually.

lukas1760 commented 4 years ago

Like you said. No output. :-(

FedeDP commented 4 years ago

Ok then you should build drivers/iio/light/tsl2772.c kernel module! You can follow archwiki page or any of the resources online, eg: https://askubuntu.com/questions/168279/how-do-i-build-a-single-in-tree-kernel-module.

FedeDP commented 4 years ago

For comparison, this is my depmod output:

sudo depmod -av | grep tsl27
/lib/modules/5.3.0-19-generic/kernel/drivers/iio/light/tsl2772.ko needs "iio_push_event": /lib/modules/5.3.0-19-generic/kernel/drivers/iio/industrialio.ko
lukas1760 commented 4 years ago

I spent little bit more time on it and now I have kernel module. Actually my depmod output is same like your but I don't now how to setup sensor in clight

FedeDP commented 4 years ago

I spent little bit more time on it and now I have kernel module.

Great to hear! Sorry for not being helpful but i am quite busy at the moment :)

Can you try a: busctl call org.clightd.clightd /org/clightd/clightd/Sensor/Als org.clightd.clightd.Sensor IsAvailable "s" "" ? If it still does not work, can you try to forcefully modprobe the kernel module (ie: sudo modprobe tsl2772) and run it again?

lukas1760 commented 4 years ago

It's okay, I have a lot of work too. :) Output is the same: sb "" false Module is loaded automatically at startup and also I see it in lsmod output. Maybe bad driver? I don't know where is the problem. :(

FedeDP commented 4 years ago

What does udevadm monitor say now that you have correct driver? If udev is empty too, what does dmesg say when you attach your device?

lukas1760 commented 4 years ago

What does udevadm monitor say now that you have correct driver?

nothing

If udev is empty too, what does dmesg say when you attach your device?

dmesg.txt

FedeDP commented 4 years ago

This is the only log about your driver in dmesg:

[ 4.896924] tsl2772: no symbol version for module_layout [ 4.896963] tsl2772: loading out-of-tree module taints kernel.

But then it gets loaded as you see int in lsmod output. It seems like it does not see any device though...

lukas1760 commented 4 years ago

It's weird because I see address of this sensor in output of i2cdetect -y 1

FedeDP commented 4 years ago

Mmmh i am out of ideas indeed. You can try to read a guide, eg: https://bootlin.com/blog/building-a-linux-system-for-the-stm32mp1-connecting-an-i2c-sensor/ , and check if we did anything wrong... (look for "iio" in the article). Everything looks fine to me though...

FedeDP commented 4 years ago

Hi! Can you try to modprobe acpi_als driver? It is a driver to interface with als iio; clightd uses that.

lukas1760 commented 4 years ago

Hi! At first... happy new year!

Hi! Can you try to modprobe acpi_als driver? It is a driver to interface with als iio; clightd uses that.

no i don't have acpi_als driver, also I didn't find it in lsmod

lukas1760 commented 4 years ago

I think that rpi don't have acpi support

FedeDP commented 4 years ago

Thanks! Can you share output of ls /sys/bus/iio/devices ?

Happy new year!

FedeDP commented 4 years ago

I'll close this issue in favor of #34; hopefully i will be able to finally fix als support for you too :)