Dimming with c#

Moderator: Telldus

Post Reply
Lullen
Posts: 7
Joined: Fri Mar 17, 2023 9:45 am

Dimming with c#

Post by Lullen »

I have recently bought a tellstick (usb) to play a bit with and everything seems to work great except that the dimming does not fully work for me.
When I try to set the dim level to 130,140,150,160 it lowers to minimum. On the rest of the values most work as they should. I want to have at least 25 different dim levels. When I try to write out the chars for the non working levels it just writes out "" or " ".

Here is my code. Am I doing something wrong here? Or should I just look for working chars?

Code: Select all

public void Dim(int deviceId, int level)
        {
            if (level > 25)
            {
                throw new ArgumentException("Max value is 25");
            }
            else if(level < 0)
            {
                throw new ArgumentException("Min value is 0");
            }

            if (level == 0)
            {
                TelldusNETWrapper.tdTurnOff(deviceId);
            }
            else
            {
                var charLevel = Convert.ToChar(level*11);
                TelldusNETWrapper.tdDim(deviceId, charLevel);
            }
        }
Thanks,
Ludwig
micke.prag
Site Admin
Posts: 2243
Joined: Fri Mar 17, 2023 9:45 am
Location: Lund
Contact:

Re: Dimming with c#

Post by micke.prag »

First, Nexa devices only have 16 steps for dimming.

Second, since you seem to have problem > 127 I suspect there is some thing with the signing of the variables. The parameter needs to be unsigned (0-255), I guess you send a signed value (-127 - 127)?
Micke Prag
Software
Telldus Technologies
Lullen
Posts: 7
Joined: Fri Mar 17, 2023 9:45 am

Re: Dimming with c#

Post by Lullen »

Aha so they only have 16 steps. Why does the code accept from 0-255 then?
Then I suppose there is a step each 16 value. But what happends in the code if lets say I send the value of 36? As it does not get set to 0 I might suspect that it is set to the step2(value 31) or 3(value 47)?
I am able to set the value again from 161 to 255 so there is no problem with unsigned/signed.
micke.prag
Site Admin
Posts: 2243
Joined: Fri Mar 17, 2023 9:45 am
Location: Lund
Contact:

Re: Dimming with c#

Post by micke.prag »

Lullen wrote:Aha so they only have 16 steps. Why does the code accept from 0-255 then?
The API is universal and is designed to fit other dimmers than Nexa. There is no sense in designing an API that will be limited to one brand.
Lullen wrote:Then I suppose there is a step each 16 value.
This is the actual code:

Code: Select all

if (method == TELLSTICK_DIM) {
	unsigned char newLevel = level/16;
	for (int i = 3; i >= 0; --i) {
		m.append(newLevel & 1 << i ? "10" : "01");
	}
}
http://developer.telldus.com/browser/te ... a.cpp#L133
Micke Prag
Software
Telldus Technologies
Lullen
Posts: 7
Joined: Fri Mar 17, 2023 9:45 am

Re: Dimming with c#

Post by Lullen »

Aha then it works as I suspected.
Post Reply