Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #37602 > unrolled thread
| Started by | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| First post | 2019-10-23 00:19 -0700 |
| Last post | 2019-10-23 12:08 -0700 |
| Articles | 18 — 5 participants |
Back to article view | Back to comp.lang.javascript
Light on Light off problem Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-23 00:19 -0700
Re: Light on Light off problem Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-23 00:58 -0700
Re: Light on Light off problem luserdroog <luser.droog@gmail.com> - 2019-10-23 01:04 -0700
Re: Light on Light off problem Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-23 01:25 -0700
Re: Light on Light off problem Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-23 01:29 -0700
Re: Light on Light off problem JJ <jj4public@vfemail.net> - 2019-10-23 15:46 +0700
Re: Light on Light off problem Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-23 01:57 -0700
Re: Light on Light off problem "R.Wieser" <address@not.available> - 2019-10-23 10:29 +0200
Re: Light on Light off problem Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-23 02:04 -0700
Re: Light on Light off problem "R.Wieser" <address@not.available> - 2019-10-23 11:30 +0200
Re: Light on Light off problem Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-23 02:39 -0700
Re: Light on Light off problem Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-23 02:44 -0700
Re: Light on Light off problem Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-23 03:01 -0700
Re: Light on Light off problem Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-23 02:16 -0700
Re: Light on Light off problem Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-23 02:31 -0700
Re: Light on Light off problem Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-23 03:30 -0700
Re: Light on Light off problem Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-10-23 08:25 -0700
Re: Light on Light off problem "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2019-10-23 12:08 -0700
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-10-23 00:19 -0700 |
| Subject | Light on Light off problem |
| Message-ID | <72db4297-267f-49d5-b858-c835a7f7eaa8@googlegroups.com> |
A storage have 128 individual automated light swithches. The states ON and OFF for the lightswitches, is stored in a single ON and OFF timings array for the individual switches. During day they are turned on and off multiple times, and the states and timing stored. But at closing in evening a routine needed to check all lights turned off must be written to check thru the array. Suggestion for howto do the check on array to see all lightbulbs turned off, store the ones still turned on, and then turn them off. "Seem a bit cumbersome to make" Well it easy to read array backward to see, the ones from end still turned on. But many lightswitches could been set on earlier. Oh the array values is sorted on timings. A neat little problem...! :D One could make an extra array names "OFF", with 128 booleans. Toogle thru the switch timing array and set the new array TRUE when OFF value comes and FALSE when ON values comes. In the end the values that are FALSE in the OFF array still on? How would you solve it?
[toc] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-10-23 00:58 -0700 |
| Message-ID | <9892d2f7-c5ae-4c89-98b3-7a3d389a6908@googlegroups.com> |
| In reply to | #37602 |
Den onsdag 23 oktober 2019 kl. 09:19:37 UTC+2 skrev Jonas Thörnvall:
> A storage have 128 individual automated light swithches.
>
> The states ON and OFF for the lightswitches, is stored in a single ON and OFF timings array for the individual switches.
> During day they are turned on and off multiple times, and the states and timing stored.
>
> But at closing in evening a routine needed to check all lights turned off must be written to check thru the array.
>
> Suggestion for howto do the check on array to see all lightbulbs turned off, store the ones still turned on, and then turn them off.
>
> "Seem a bit cumbersome to make"
>
> Well it easy to read array backward to see, the ones from end still turned on. But many lightswitches could been set on earlier.
>
> Oh the array values is sorted on timings.
>
>
> A neat little problem...! :D
> One could make an extra array names "OFF", with 128 booleans.
> Toogle thru the switch timing array and set the new array TRUE when OFF value comes and FALSE when ON values comes.
>
> In the end the values that are FALSE in the OFF array still on?
>
> How would you solve it?
Here is what i was thinking but there still something wrong.
function lateNotesFix(){
var switchnr=0;var OFF = [];
for (var l=0;l<128;l++){
OFF[l]=true;
}
//Now we walk thrur recorded notes switch the 128 values,
// on "false" and off "true"
for (var k=0;k<track[rectrack].midiMess.length-1;k++){
if (track[rectrack].midiMess[k].data0==144){
switchnr=track[rectrack].midiMess[k].data1;
OFF[switchnr]=false;
} else { OFF[switchnr]=true;}
}
//Here we put in off values for notes still on
for (var l=0;l<128;l++){
if (OFF[l]==false){
track[rectrack].midiMess.push({
time: re-1,
data0: 128,
data1: track[rectrack].midiMess[l].data1,
data2: 0
});
}
}
}
}
[toc] | [prev] | [next] | [standalone]
| From | luserdroog <luser.droog@gmail.com> |
|---|---|
| Date | 2019-10-23 01:04 -0700 |
| Message-ID | <4cb8cda6-9231-4e3e-b427-21a230cc35b9@googlegroups.com> |
| In reply to | #37603 |
On Wednesday, October 23, 2019 at 2:58:08 AM UTC-5, Jonas Thörnvall wrote:
> for (var k=0;k<track[rectrack].midiMess.length-1;k++){
Isn't length-1 a valid index for the last element?
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-10-23 01:25 -0700 |
| Message-ID | <8778a247-62e2-41e5-9d1d-6b71411f4b93@googlegroups.com> |
| In reply to | #37604 |
Den onsdag 23 oktober 2019 kl. 10:04:17 UTC+2 skrev luserdroog:
> On Wednesday, October 23, 2019 at 2:58:08 AM UTC-5, Jonas Thörnvall wrote:
>
> > for (var k=0;k<track[rectrack].midiMess.length-1;k++){
>
> Isn't length-1 a valid index for the last element?
Yeah it sure is just realised i did push something strange to data1.
This is what should be pushed.
data1: l,
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-10-23 01:29 -0700 |
| Message-ID | <7aa18c3c-fed7-4c3d-9422-2e33e66b0f00@googlegroups.com> |
| In reply to | #37604 |
Den onsdag 23 oktober 2019 kl. 10:04:17 UTC+2 skrev luserdroog:
> On Wednesday, October 23, 2019 at 2:58:08 AM UTC-5, Jonas Thörnvall wrote:
>
> > for (var k=0;k<track[rectrack].midiMess.length-1;k++){
>
> Isn't length-1 a valid index for the last element?
Thanks for help now i have early and late note fixed, it isn't 100% proof you can do weird things that i do not handle like push and release note before recording start, but that seem kind of fucked up to start with.
And you can push note before recording start and hold it until after ending.
I really do not know if i should take care of those, they seem a bit luney to start with.
function earlyNotesFix() {
console.log("earlyNotesFix");
//Check if any messages
if (track[rectrack].midiMess.length>0){
var i=0;earlyfound=false;
//Check how many early startpoints
var savetime=track[rectrack].midiMess[i].time;
while (track[rectrack].midiMess[i].time<track[rectrack].midiMess[i+1].time && i<track[rectrack].midiMess.length-2){
i++;
}
if (i!=track[rectrack].midiMess.length-2) {earlyfound=true;}
//alert(i);
//Fix the early pushed keys
//j is the note after last early event.
j=i+1;i=0;
if (earlyfound==true){
//console.log("found early note");
while (i<=j && track[rectrack].midiMess[i].data0==144) {
track[rectrack].midiMess[i].time=rs+1;
i++;
}
}
}
}
function lateNotesFix(){
//Check if any messages
if (track[rectrack].midiMess.length>0){
//Trying another approach,first all notes initiated to OFF, in off array
var switchnr=0;var OFF = [];
for (var k=0;k<128;k++){
OFF[k]=true;
}
//Now we switch the 128 values, on "false" and off "true"
for (var l=0;l<track[rectrack].midiMess.length;l++){
switchnr=track[rectrack].midiMess[l].data1;
alert("switchnr="+switchnr);
if (track[rectrack].midiMess[l].data0==144)
{OFF[switchnr]=false;}
else if (track[rectrack].midiMess[l].data0==128)
{ OFF[switchnr]=true;}
}
//Here we create off values for notes that still on.
for (var l=0;l<128;l++){
if (OFF[l]==false){
track[rectrack].midiMess.push({
time: re-1,
data0: 128,
data1: l,
data2: 0
});
}
}
}
}
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2019-10-23 15:46 +0700 |
| Message-ID | <d7iw5o2yrq8z.1rnieblw2m61t$.dlg@40tude.net> |
| In reply to | #37603 |
On Wed, 23 Oct 2019 00:58:02 -0700 (PDT), Jonas Thörnvall wrote:
> Den onsdag 23 oktober 2019 kl. 09:19:37 UTC+2 skrev Jonas Thörnvall:
>> A storage have 128 individual automated light swithches.
>>
>> The states ON and OFF for the lightswitches, is stored in a single ON and
>> OFF timings array for the individual switches. During day they are
>> turned on and off multiple times, and the states and timing stored.
>>
>> But at closing in evening a routine needed to check all lights turned
>> off must be written to check thru the array.
>>
>> Suggestion for howto do the check on array to see all lightbulbs turned
>> off, store the ones still turned on, and then turn them off.
>>
>> "Seem a bit cumbersome to make"
>>
>> Well it easy to read array backward to see, the ones from end still
>> turned on. But many lightswitches could been set on earlier.
>>
>> Oh the array values is sorted on timings.
>>
>> A neat little problem...! :D One could make an extra array names "OFF",
>> with 128 booleans. Toogle thru the switch timing array and set the new
>> array TRUE when OFF value comes and FALSE when ON values comes.
>>
>> In the end the values that are FALSE in the OFF array still on?
>>
>> How would you solve it?
>
> Here is what i was thinking but there still something wrong.
> function lateNotesFix(){
> var switchnr=0;var OFF = [];
>
> for (var l=0;l<128;l++){
> OFF[l]=true;
> }
> //Now we walk thrur recorded notes switch the 128 values,
> // on "false" and off "true"
> for (var k=0;k<track[rectrack].midiMess.length-1;k++){
> if (track[rectrack].midiMess[k].data0==144){
> switchnr=track[rectrack].midiMess[k].data1;
> OFF[switchnr]=false;
> } else { OFF[switchnr]=true;}
> }
> //Here we put in off values for notes still on
> for (var l=0;l<128;l++){
> if (OFF[l]==false){
> track[rectrack].midiMess.push({
> time: re-1,
> data0: 128,
> data1: track[rectrack].midiMess[l].data1,
> data2: 0
> });
> }
> }
> }
> }
Seems to me that you don't keep track of which notes were played and other
things which are affected by them.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-10-23 01:57 -0700 |
| Message-ID | <b8b39d31-af51-485a-a7b0-f7026bc6301c@googlegroups.com> |
| In reply to | #37609 |
Den onsdag 23 oktober 2019 kl. 10:46:33 UTC+2 skrev JJ:
> On Wed, 23 Oct 2019 00:58:02 -0700 (PDT), Jonas Thörnvall wrote:
> > Den onsdag 23 oktober 2019 kl. 09:19:37 UTC+2 skrev Jonas Thörnvall:
> >> A storage have 128 individual automated light swithches.
> >>
> >> The states ON and OFF for the lightswitches, is stored in a single ON and
> >> OFF timings array for the individual switches. During day they are
> >> turned on and off multiple times, and the states and timing stored.
> >>
> >> But at closing in evening a routine needed to check all lights turned
> >> off must be written to check thru the array.
> >>
> >> Suggestion for howto do the check on array to see all lightbulbs turned
> >> off, store the ones still turned on, and then turn them off.
> >>
> >> "Seem a bit cumbersome to make"
> >>
> >> Well it easy to read array backward to see, the ones from end still
> >> turned on. But many lightswitches could been set on earlier.
> >>
> >> Oh the array values is sorted on timings.
> >>
> >> A neat little problem...! :D One could make an extra array names "OFF",
> >> with 128 booleans. Toogle thru the switch timing array and set the new
> >> array TRUE when OFF value comes and FALSE when ON values comes.
> >>
> >> In the end the values that are FALSE in the OFF array still on?
> >>
> >> How would you solve it?
> >
> > Here is what i was thinking but there still something wrong.
> > function lateNotesFix(){
> > var switchnr=0;var OFF = [];
> >
> > for (var l=0;l<128;l++){
> > OFF[l]=true;
> > }
> > //Now we walk thrur recorded notes switch the 128 values,
> > // on "false" and off "true"
> > for (var k=0;k<track[rectrack].midiMess.length-1;k++){
> > if (track[rectrack].midiMess[k].data0==144){
> > switchnr=track[rectrack].midiMess[k].data1;
> > OFF[switchnr]=false;
> > } else { OFF[switchnr]=true;}
> > }
> > //Here we put in off values for notes still on
> > for (var l=0;l<128;l++){
> > if (OFF[l]==false){
> > track[rectrack].midiMess.push({
> > time: re-1,
> > data0: 128,
> > data1: track[rectrack].midiMess[l].data1,
> > data2: 0
> > });
> > }
> > }
> > }
> > }
>
> Seems to me that you don't keep track of which notes were played and other
> things which are affected by them.
Well a recording is just a list "array" with noteNr, state "on/off
How do you suggest to know if the keys been pressed, and if the last state of one pressed was on or off without scrolling thru?
I make a help array "boolean on and off for each note" and simply scroll thru recorded notes array. Then i check the boolean for if last press of each note either was on and off.
I can't see any easier way to do it.
Remember this is done after recording, "or storage closure", i am checking if they pressed to early, "or in this case did not release "off" when recording stopped.
If late pressed i have to crate note, if to early i have to move startpoint to zero.
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-10-23 10:29 +0200 |
| Message-ID | <qop31t$hvf$1@gioia.aioe.org> |
| In reply to | #37602 |
Jonas,
> Suggestion for howto do the check on array to see all lightbulbs turned
> off
I don't get it. Whats the problem with an "if ({array element} = {some
content} ) then" construction ? What is the /problem/ you (think you) have
?
> store the ones still turned on,
Why ? All you want to do is to switch the ones that are still on to off.
You can do that in the checking loop itself, no need to store anything.
.. And can be done even easier : just tell all of them (one by one ? Or
perhaps by a broadcast ?) to switch off. That is, if you have seperate
commands for on and off switching ofcourse.
> "Seem a bit cumbersome to make"
>
> Well it easy to read array backward to see, the ones from end still
> turned on. But many lightswitches could been set on earlier.
I don't get that I'm afraid. Somehow you seem to be saying that the lamps
could be in a state thats different from what you have in the list ?
> One could make an extra array names "OFF", with 128 booleans.
Or you could start with showing us what you have stored in the array you've
already got (one lamps record will probably do fine), so we know what you
are looking at, and perhaps do something more than guessing. <whistle>
A little bit about the lamps themselves would be good too : Do they just
toggle or do they have seperate on and off commands ? Can you ask for their
current state ?
> How would you solve it?
See above. I would KISS it (Keep It Stupidly Simple. Or Keep It Simple,
Stupid. Your choice :-p ) and not even check the current states, as they
would not do me any good (after execution all the lamps should be off).
Regards,
Rudy Wieser
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-10-23 02:04 -0700 |
| Message-ID | <6520f776-416e-42c7-8033-b81922479ef4@googlegroups.com> |
| In reply to | #37608 |
Den onsdag 23 oktober 2019 kl. 10:29:56 UTC+2 skrev R.Wieser:
> Jonas,
>
> > Suggestion for howto do the check on array to see all lightbulbs turned
> > off
>
> I don't get it. Whats the problem with an "if ({array element} = {some
> content} ) then" construction ? What is the /problem/ you (think you) have
> ?
>
> > store the ones still turned on,
>
> Why ? All you want to do is to switch the ones that are still on to off.
> You can do that in the checking loop itself, no need to store anything.
>
> .. And can be done even easier : just tell all of them (one by one ? Or
> perhaps by a broadcast ?) to switch off. That is, if you have seperate
> commands for on and off switching ofcourse.
>
> > "Seem a bit cumbersome to make"
> >
> > Well it easy to read array backward to see, the ones from end still
> > turned on. But many lightswitches could been set on earlier.
>
> I don't get that I'm afraid. Somehow you seem to be saying that the lamps
> could be in a state thats different from what you have in the list ?
>
> > One could make an extra array names "OFF", with 128 booleans.
>
> Or you could start with showing us what you have stored in the array you've
> already got (one lamps record will probably do fine), so we know what you
> are looking at, and perhaps do something more than guessing. <whistle>
>
> A little bit about the lamps themselves would be good too : Do they just
> toggle or do they have seperate on and off commands ? Can you ask for their
> current state ?
>
> > How would you solve it?
>
> See above. I would KISS it (Keep It Stupidly Simple. Or Keep It Simple,
> Stupid. Your choice :-p ) and not even check the current states, as they
> would not do me any good (after execution all the lamps should be off).
>
> Regards,
> Rudy Wieser
Well there is more to the problem each on and off is recorded, so there is many on and off during day. All switches and their states is stored in a list.
Now you have to find a way to check which switches that have been pressed and if their ***last state*** is an on or an off.
It is a single list with the switchNr, state and "state change timings" sorted by time. It is not certain that each switch been on during day.
Switchnr State Time
89 ON 12.23.01
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-10-23 11:30 +0200 |
| Message-ID | <qop6ka$1301$1@gioia.aioe.org> |
| In reply to | #37611 |
Jonas, > Now you have to find a way to check which switches > that have been pressed and if their ***last state*** is > an on or an off. And I have asked you /why/ you would need to check that state, the last one or otherwise. I even gave you a reason why you /wouldn't/ need too ... > I think you suggest doing it one by one, in this case would > be idiotic. You would need to read thru array 128 times.... If I would have suggested that that would be stupid, yes. But tell me: You wanted to store the lamps that have the "ON" state into a new array. Would you need to go thru the origional array 128 times for that too ? If not, why should you for what I'm suggesting (hint: just exchange the "store in a result array": with "send the OFF command"). But, as you have refused to answer the questions I asked and I have zero wish to fight you to get them I'm going to terminate our conversation. Goodbye. Regards, Rudy Wieser
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-10-23 02:39 -0700 |
| Message-ID | <ee21f3b5-4352-4610-b9f7-ac1d5eb91c0a@googlegroups.com> |
| In reply to | #37613 |
Den onsdag 23 oktober 2019 kl. 11:30:57 UTC+2 skrev R.Wieser: > Jonas, > > > Now you have to find a way to check which switches > > that have been pressed and if their ***last state*** is > > an on or an off. > > And I have asked you /why/ you would need to check that state, the last one > or otherwise. > > I even gave you a reason why you /wouldn't/ need too ... > > > I think you suggest doing it one by one, in this case would > > be idiotic. You would need to read thru array 128 times.... > > If I would have suggested that that would be stupid, yes. But tell me: You > wanted to store the lamps that have the "ON" state into a new array. > Would you need to go thru the origional array 128 times for that too ? If > not, why should you for what I'm suggesting (hint: just exchange the "store > in a result array": with "send the OFF command"). > > But, as you have refused to answer the questions I asked and I have zero > wish to fight you to get them I'm going to terminate our conversation. > Goodbye. > > Regards, > Rudy Wieser You still do not get it Rudy, the events is stored in a list. I understand that you want to have a separate "on/off storage for each switch" at start, that is not the case Rudy there is no time for extra setting other then the list with switchNr,state and time. Well the process of lamps on and of is realtime critical ;) So during day there is no time to store "extra" which is on and off. The hardware just create the list automatically. It is your job to find out "batch" which ones still on.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-10-23 02:44 -0700 |
| Message-ID | <58b73a9b-5163-4fc8-915f-c70149a0c1e5@googlegroups.com> |
| In reply to | #37615 |
Den onsdag 23 oktober 2019 kl. 11:39:32 UTC+2 skrev Jonas Thörnvall: > Den onsdag 23 oktober 2019 kl. 11:30:57 UTC+2 skrev R.Wieser: > > Jonas, > > > > > Now you have to find a way to check which switches > > > that have been pressed and if their ***last state*** is > > > an on or an off. > > > > And I have asked you /why/ you would need to check that state, the last one > > or otherwise. > > > > I even gave you a reason why you /wouldn't/ need too ... > > > > > I think you suggest doing it one by one, in this case would > > > be idiotic. You would need to read thru array 128 times.... > > > > If I would have suggested that that would be stupid, yes. But tell me: You > > wanted to store the lamps that have the "ON" state into a new array. > > Would you need to go thru the origional array 128 times for that too ? If > > not, why should you for what I'm suggesting (hint: just exchange the "store > > in a result array": with "send the OFF command"). > > > > But, as you have refused to answer the questions I asked and I have zero > > wish to fight you to get them I'm going to terminate our conversation. > > Goodbye. > > > > Regards, > > Rudy Wieser > You still do not get it Rudy, the events is stored in a list. > I understand that you want to have a separate "on/off storage for each switch" at start, that is not the case Rudy there is no time for extra setting other then the list with switchNr,state and time. > > Well the process of lamps on and of is realtime critical ;) > So during day there is no time to store "extra" which is on and off. > The hardware just create the list automatically. > > It is your job to find out "batch" which ones still on. It seem people missunderstod the problem, it is not a case of holding true or false for 128 switches. It is finding out which ones still on "from a list where they been set on and off during day"....
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-10-23 03:01 -0700 |
| Message-ID | <bcdfdd0c-69d0-41bf-b3cb-211441dda3bb@googlegroups.com> |
| In reply to | #37616 |
Den onsdag 23 oktober 2019 kl. 11:44:18 UTC+2 skrev Jonas Thörnvall: > Den onsdag 23 oktober 2019 kl. 11:39:32 UTC+2 skrev Jonas Thörnvall: > > Den onsdag 23 oktober 2019 kl. 11:30:57 UTC+2 skrev R.Wieser: > > > Jonas, > > > > > > > Now you have to find a way to check which switches > > > > that have been pressed and if their ***last state*** is > > > > an on or an off. > > > > > > And I have asked you /why/ you would need to check that state, the last one > > > or otherwise. > > > > > > I even gave you a reason why you /wouldn't/ need too ... > > > > > > > I think you suggest doing it one by one, in this case would > > > > be idiotic. You would need to read thru array 128 times.... > > > > > > If I would have suggested that that would be stupid, yes. But tell me: You > > > wanted to store the lamps that have the "ON" state into a new array. > > > Would you need to go thru the origional array 128 times for that too ? If > > > not, why should you for what I'm suggesting (hint: just exchange the "store > > > in a result array": with "send the OFF command"). > > > > > > But, as you have refused to answer the questions I asked and I have zero > > > wish to fight you to get them I'm going to terminate our conversation. > > > Goodbye. > > > > > > Regards, > > > Rudy Wieser > > You still do not get it Rudy, the events is stored in a list. > > I understand that you want to have a separate "on/off storage for each switch" at start, that is not the case Rudy there is no time for extra setting other then the list with switchNr,state and time. > > > > Well the process of lamps on and of is realtime critical ;) > > So during day there is no time to store "extra" which is on and off. > > The hardware just create the list automatically. > > > > It is your job to find out "batch" which ones still on. > > It seem people missunderstod the problem, it is not a case of holding true or false for 128 switches. > > It is finding out which ones still on "from a list where they been set on and off during day".... Anyway here is the problem solved "batch" after recording, Rudy suggested a state storage for each note during recording. I do not think that is the way to go. https://midisequenser.000webhostapp.com/ So if user play early i now move note to "starttime rec" and if they press/hold and release to late "after rec end". I create the note offs and push them to the recorded note array.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-10-23 02:16 -0700 |
| Message-ID | <60cb4fd7-9663-45a8-9363-89c20c409f9a@googlegroups.com> |
| In reply to | #37608 |
Den onsdag 23 oktober 2019 kl. 10:29:56 UTC+2 skrev R.Wieser:
> Jonas,
>
> > Suggestion for howto do the check on array to see all lightbulbs turned
> > off
>
> I don't get it. Whats the problem with an "if ({array element} = {some
> content} ) then" construction ? What is the /problem/ you (think you) have
> ?
>
> > store the ones still turned on,
>
> Why ? All you want to do is to switch the ones that are still on to off.
> You can do that in the checking loop itself, no need to store anything.
>
> .. And can be done even easier : just tell all of them (one by one ? Or
> perhaps by a broadcast ?) to switch off. That is, if you have seperate
> commands for on and off switching ofcourse.
>
> > "Seem a bit cumbersome to make"
> >
> > Well it easy to read array backward to see, the ones from end still
> > turned on. But many lightswitches could been set on earlier.
>
> I don't get that I'm afraid. Somehow you seem to be saying that the lamps
> could be in a state thats different from what you have in the list ?
>
> > One could make an extra array names "OFF", with 128 booleans.
>
> Or you could start with showing us what you have stored in the array you've
> already got (one lamps record will probably do fine), so we know what you
> are looking at, and perhaps do something more than guessing. <whistle>
>
> A little bit about the lamps themselves would be good too : Do they just
> toggle or do they have seperate on and off commands ? Can you ask for their
> current state ?
>
> > How would you solve it?
>
> See above. I would KISS it (Keep It Stupidly Simple. Or Keep It Simple,
> Stupid. Your choice :-p ) and not even check the current states, as they
> would not do me any good (after execution all the lamps should be off).
>
> Regards,
> Rudy Wieser
I think you suggest doing it one by one, in this case would be idiotic. You would need to read thru array 128 times....
By having an help array to look at you get them in one swoop "one reading".
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-10-23 02:31 -0700 |
| Message-ID | <52e54b3c-c530-4aa6-b801-f2e3ecac19cd@googlegroups.com> |
| In reply to | #37608 |
Den onsdag 23 oktober 2019 kl. 10:29:56 UTC+2 skrev R.Wieser:
> Jonas,
>
> > Suggestion for howto do the check on array to see all lightbulbs turned
> > off
>
> I don't get it. Whats the problem with an "if ({array element} = {some
> content} ) then" construction ? What is the /problem/ you (think you) have
> ?
>
> > store the ones still turned on,
>
> Why ? All you want to do is to switch the ones that are still on to off.
> You can do that in the checking loop itself, no need to store anything.
>
> .. And can be done even easier : just tell all of them (one by one ? Or
> perhaps by a broadcast ?) to switch off. That is, if you have seperate
> commands for on and off switching ofcourse.
>
> > "Seem a bit cumbersome to make"
> >
> > Well it easy to read array backward to see, the ones from end still
> > turned on. But many lightswitches could been set on earlier.
>
> I don't get that I'm afraid. Somehow you seem to be saying that the lamps
> could be in a state thats different from what you have in the list ?
>
> > One could make an extra array names "OFF", with 128 booleans.
>
> Or you could start with showing us what you have stored in the array you've
> already got (one lamps record will probably do fine), so we know what you
> are looking at, and perhaps do something more than guessing. <whistle>
>
> A little bit about the lamps themselves would be good too : Do they just
> toggle or do they have seperate on and off commands ? Can you ask for their
> current state ?
>
> > How would you solve it?
>
> See above. I would KISS it (Keep It Stupidly Simple. Or Keep It Simple,
> Stupid. Your choice :-p ) and not even check the current states, as they
> would not do me any good (after execution all the lamps should be off).
>
> Regards,
> Rudy Wieser
Okay i make an object for you. Do a try.
The created list below.
lightEvent: []
//OBJECT ATTRIBUTES PUSHED TO LIGHTEVENT{time:0,switchNr:0,State:boolean}
Now the above list is created realtime by hardware in millisec, so there is no extra time to set and hold the states "for each switch" during day.
Lets say it manage the heaters of a nuclear plant LoL
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-10-23 03:30 -0700 |
| Message-ID | <09b62a8c-5005-4ff7-9a1c-c025a48ba545@googlegroups.com> |
| In reply to | #37608 |
Den onsdag 23 oktober 2019 kl. 10:29:56 UTC+2 skrev R.Wieser:
> Jonas,
>
> > Suggestion for howto do the check on array to see all lightbulbs turned
> > off
>
> I don't get it. Whats the problem with an "if ({array element} = {some
> content} ) then" construction ? What is the /problem/ you (think you) have
> ?
>
> > store the ones still turned on,
>
> Why ? All you want to do is to switch the ones that are still on to off.
> You can do that in the checking loop itself, no need to store anything.
>
> .. And can be done even easier : just tell all of them (one by one ? Or
> perhaps by a broadcast ?) to switch off. That is, if you have seperate
> commands for on and off switching ofcourse.
>
> > "Seem a bit cumbersome to make"
> >
> > Well it easy to read array backward to see, the ones from end still
> > turned on. But many lightswitches could been set on earlier.
>
> I don't get that I'm afraid. Somehow you seem to be saying that the lamps
> could be in a state thats different from what you have in the list ?
>
> > One could make an extra array names "OFF", with 128 booleans.
>
> Or you could start with showing us what you have stored in the array you've
> already got (one lamps record will probably do fine), so we know what you
> are looking at, and perhaps do something more than guessing. <whistle>
>
> A little bit about the lamps themselves would be good too : Do they just
> toggle or do they have seperate on and off commands ? Can you ask for their
> current state ?
>
> > How would you solve it?
>
> See above. I would KISS it (Keep It Stupidly Simple. Or Keep It Simple,
> Stupid. Your choice :-p ) and not even check the current states, as they
> would not do me any good (after execution all the lamps should be off).
>
> Regards,
> Rudy Wieser
Yeah you are right with perfect users it would not be needed Rudy, unfortunately sometimes they will blip the switch to early in the morning and somtimes they blip it after workday ended.
And in the end i will draw a graph of how the blip the lightswitches, and that graph just look terrible if switches on before worktime or switches not turned of after worktime ended.
https://midisequenser.000webhostapp.com/
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-10-23 08:25 -0700 |
| Message-ID | <3751e5f3-1a62-4a01-a6c3-f11592fdd4b8@googlegroups.com> |
| In reply to | #37618 |
Den onsdag 23 oktober 2019 kl. 12:30:41 UTC+2 skrev Jonas Thörnvall:
> Den onsdag 23 oktober 2019 kl. 10:29:56 UTC+2 skrev R.Wieser:
> > Jonas,
> >
> > > Suggestion for howto do the check on array to see all lightbulbs turned
> > > off
> >
> > I don't get it. Whats the problem with an "if ({array element} = {some
> > content} ) then" construction ? What is the /problem/ you (think you) have
> > ?
> >
> > > store the ones still turned on,
> >
> > Why ? All you want to do is to switch the ones that are still on to off.
> > You can do that in the checking loop itself, no need to store anything.
> >
> > .. And can be done even easier : just tell all of them (one by one ? Or
> > perhaps by a broadcast ?) to switch off. That is, if you have seperate
> > commands for on and off switching ofcourse.
> >
> > > "Seem a bit cumbersome to make"
> > >
> > > Well it easy to read array backward to see, the ones from end still
> > > turned on. But many lightswitches could been set on earlier.
> >
> > I don't get that I'm afraid. Somehow you seem to be saying that the lamps
> > could be in a state thats different from what you have in the list ?
> >
> > > One could make an extra array names "OFF", with 128 booleans.
> >
> > Or you could start with showing us what you have stored in the array you've
> > already got (one lamps record will probably do fine), so we know what you
> > are looking at, and perhaps do something more than guessing. <whistle>
> >
> > A little bit about the lamps themselves would be good too : Do they just
> > toggle or do they have seperate on and off commands ? Can you ask for their
> > current state ?
> >
> > > How would you solve it?
> >
> > See above. I would KISS it (Keep It Stupidly Simple. Or Keep It Simple,
> > Stupid. Your choice :-p ) and not even check the current states, as they
> > would not do me any good (after execution all the lamps should be off).
> >
> > Regards,
> > Rudy Wieser
>
> Yeah you are right with perfect users it would not be needed Rudy, unfortunately sometimes they will blip the switch to early in the morning and somtimes they blip it after workday ended.
>
> And in the end i will draw a graph of how the blip the lightswitches, and that graph just look terrible if switches on before worktime or switches not turned of after worktime ended.
>
> https://midisequenser.000webhostapp.com/
Last commen on light on and off, for the to early on switch one probably should solve it same way as the to late case. Right now i am actually recording the early pressed notes. I probably should not and instead create "notes on" for switches that start with off. Using a help array just like with the nonereleased.
But it works fine for now, but with that solution implemented one simply would cover every case, even the most foolish ones.
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2019-10-23 12:08 -0700 |
| Message-ID | <5bc9e661-7365-46d7-92cf-791802d9d68e@googlegroups.com> |
| In reply to | #37602 |
On Wednesday, October 23, 2019 at 2:19:37 AM UTC-5, Jonas Thörnvall wrote:
> A storage have 128 individual automated light swithches.
>
> The states ON and OFF for the lightswitches, is stored in a single ON and OFF timings array for the individual switches.
> During day they are turned on and off multiple times, and the states and timing stored.
>
> But at closing in evening a routine needed to check all lights turned off must be written to check thru the array.
>
> Suggestion for howto do the check on array to see all lightbulbs turned off, store the ones still turned on, and then turn them off.
>
> "Seem a bit cumbersome to make"
>
> Well it easy to read array backward to see, the ones from end still turned on. But many lightswitches could been set on earlier.
>
> Oh the array values is sorted on timings.
>
>
> A neat little problem...! :D
> One could make an extra array names "OFF", with 128 booleans.
> Toogle thru the switch timing array and set the new array TRUE when OFF value comes and FALSE when ON values comes.
>
> In the end the values that are FALSE in the OFF array still on?
>
> How would you solve it?
```JavaScript
class LightManager {
constructor(size) {
this._history = []
this._state = new Array(size).fill(false)
}
on(index) {
this._state[index] = true
this._history.push([new Date(),index,true])
}
off(index) {
this._state[index] = false
this._history.push([new Date(),index,false])
}
reset() {
this._history = []
this._state.fill(false)
}
findOnLights() {
return this._state.reduce((indexes, s, i) => {
if (s)
indexes.push(i)
return indexes
}, [])
}
findOffLights() {
return this._state.reduce((indexes, s, i) => {
if (!s)
indexes.push(i)
return indexes
}, [])
}
printHistory() {
return this._history.map(([date, index, state]) =>
`${date.toISOString()}; [${index}] := ${state}`
).join('\r\n')
}
print() {
return this._state.map(Number).join('')
}
}
let lm = new LightManager(128)
lm.on(15)
lm.off(15)
//randomly toggle
for (let i = 0; i < 128; i++) {
let methodName = Boolean(Math.round(Math.random())) ?
'on' : 'off'
lm[methodName](i)
}
console.log(lm.printHistory())
console.log(lm.print())
console.log(lm.findOnLights())
```
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web