sparkie37:
I wonder if someone can help me I'm attempting to find all valid codes for my device.
I have a few codes but was hoping someone might be able to say
int = hex 0x659A9966 +1
0x659A9966 is just a number; if you want to go through all of them, you can just add 1. The basics:
You don’t need to “try all of them”, and it will be a very long search if you do.
You need to identify the pattern…
659A9966
99+66=FF
659A50AF
50+AF=FF
659AD02F
D0+2F=FF
659A7887
78+87=FF
659A38C7
38+C7=FF
So the first 659A is the “address” of the device. Although some devices do sometimes respond to multiple addresses. If for example the require more than 256 keys, or are a hybrid device. That’s fairly unusual however.
The second two hex bytes are the key code (00-FF) and the inverse of the key code for error detection purposes. Unless the 3rd and 4th bytes are the exact inverse of each other the device will ignore the code.
So it is pointless adding just one. You will be testing 255 invalid codes for every 1 valid one.
Only 256 codes that need testing by adding 256 and subtracting 1 each time (I.e. add 255) and you probably do not need to test anything outside range 659A00FF through 659AFF00.
Also note that a code may need to be sent and received more than once, or with a certain delay from the previous one to be considered valid. Do not know if the library does that for you, but it’s worth considering if you are just going to belt out each code with no gap in between in loop().
Edit: also note that the address corresponds to the same pattern 65+9A=FF
But that is not always the case. This allowed for 256 different devices, but when NEC “ran out” of unique devices they started issuing/using a 16 bit address, instead of 8 bit address and sending non-inverted and inverted error checking versions. The theory is that an error in the address would be very unlikely to mutate into an address for a different device, given people have a very limited number of devices almost certainly with very different addresses (not just one or two bits different). That’s not the case with key codes though, where it would be very easy to mutate the code for key ‘0’ into ‘1’ as usually they use consecutive codes.
pcbbc:
You don’t need to “try all of them”, and it will be a very long search if you do.
You need to identify the pattern...
659A9966
99+66=FF
659A50AF
50+AF=FF
659AD02F
D0+2F=FF
659A7887
78+87=FF
659A38C7
38+C7=FF
So the first 659A is the “address” of the device. Although some devices do sometimes respond to multiple addresses. If for example the require more than 256 keys, or are a hybrid device. That’s fairly unusual however.
The second two hex bytes are the key code (00-FF) and the inverse of the key code for error detection purposes. Unless the 3rd and 4th bytes are the exact inverse of each other the device will ignore the code.
So it is pointless adding just one. You will be testing 255 invalid codes for every 1 valid one.
Only 256 codes that need testing by adding 256 and subtracting 1 each time (I.e. add 255) and you probably do not need to test anything outside range 659A00FF through 659AFF00.
Also note that a code may need to be sent and received more than once, or with a certain delay from the previous one to be considered valid. Do not know if the library does that for you, but it’s worth considering if you are just going to belt out each code with no gap in between in loop().
Edit: also note that the address corresponds to the same pattern 65+9A=FF
But that is not always the case. This allowed for 256 different devices, but when NEC “ran out” of unique devices they started issuing/using a 16 bit address, instead of 8 bit address and sending non-inverted and inverted error checking versions. The theory is that an error in the address would be very unlikely to mutate into an address for a different device, given people have a very limited number of devices almost certainly with very different addresses (not just one or two bits different). That’s not the case with key codes though, where it would be very easy to mutate the code for key ‘0’ into ‘1’ as usually they use consecutive codes.
ok thanks how do i put that into code that starts from keyboard press in serial terminal and steps through each code???
Repeatedly add 255 to the first possibly valid code, 0x659A00FF, will give you the next valid code.
Use at least uint32_t (unsigned long) data type for your variable, as stated earlier.
You have most of the code for processing the keyboard input, although you are not handling line endings correctly.
The sketch simply generates this series from post #3 which identified the relationship between the third and fourth hex digit pair. One entry is printed every 2 seconds:
The variable i is simply a representation of the third hex digit pair in the number series above, running from hex 00 to FF (decimal 0 to 255)
The variable code is the full number above running from 659A00FF to 659AFF00. Yes, it need not have been global.