It can be arranged.
Hey @Backpackingvet , I thought you had your Covid Jabs
It looks like you might need a booster
You have run out of (((5G)))
ok wellā¦ i got the hardware all wired up on the Photon and it works with pin control test logicā¦ butā¦ damn strings and countersā¦
I have string data coming in as const char *data that I need to parse. The first bit will be a number (the number of sales, could be 1 to 3 digits long), then a space, then some more alphanumeric string stuff. I need to figure out how to pull the number into an int variable then track if itās increased since the last time the data came in. Strings and data types and finding the first space character so I know how to split it offā¦ well letās just say I donāt think in these low level computer logic terms so well. My thought was to create a separate function call and pass the data variable to which could parse it and check the current count with a global variableās value and if itās > then hit the pin real quick before passing control back to the loopā¦ but likeā¦ how?
Short and simple
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *p;
int i;
if(argc <= 1 || !argv[1][0]) {
printf("Pass me a string in the form \"123 Some alphanumeric string\" as the first argument and I will magically split it\n");
return(-1);
}
for(p = argv[1];p[0] && p[0] != ' '; p++);
if(p[0])
0[p++] = 0;
i = atoi(argv[1]);
printf("First integer part: %d\n", i);
printf("Second alphanumeric part: %s\n", p);
return(0);
}
Thanks! Iāll check it out later once I get a chance to tinker on this again.
If youāve ever wondered how those anti-theft tags work, when you pass through the portal at the store, whether they are RFID, RF, UHFā¦ wonder no more: I found this cool video from Ben āApplied Scienceā Krasnow (if you donāt know this guy incidentally, watch his videos: youāll wonder how you went through school without him as a teacher):
Itās nothing to do with RFID - or it is, in a caveman sort of way - and itās pretty damn interesting.
whether they are RFID, RF, UHF
Actually not this partā¦ these are called ābit tagsā either binary 1 or 0, on or offā¦ RFID tags are iso15693 and 13.56MHz that leverage EAS features (electronic article surveillance)ā¦ in fact we have to disable these features on the VivoKey Spark 1 or you might possibly be setting off badly configured antitheft systems in certain stores that use RFID tags for inventory control (and antitheft is part of that system).
int main(int argc, char *argv[])
I get an error;
cannot convert āconst char*ā to āchar**ā for argument ā2ā to āint salescount(int, char**)ā
My ignorance (and unwillingness to properly figure this out myself) is woefully showing here, but basically what Iād like to do is something like this;
int salescount = 0; //global var tracking sales count
void soundtrigger(char salesdatastring)
{
//magic that splits the salesdatastring
magic splitty uppy code
//magic that checks split count against global var
if argv[0] > salescount {
digitalWrite(sound, HIGH); // sets the LED on
delay(200); // waits for 200mS
digitalWrite(sound, LOW); // sets the LED off
salescount = argv[0]; // update global sales count var
}
return;
}
Part of the problem is that C doesnāt really have a āstringā type, it uses an array of characters instead (and frequently just deals with pointers to those arrays).
However, if you can guarantee that the format of the array is 1 to 3 numeric digit characters, followed by a space, followed by some alphanumeric data that we donāt really care about, it is a lot easier.
Fortunately as @anon3825968 noted the atoi function ignores any leading white space, converts the digits into an integer, and then stops when it hits the first non-digit character.
So to grab the integer you just needā¦
int number;
number = atoi(data);
So, save your current count and have a comparisonā¦
#include <stdlib.h>
void hitpin();
/* Stuff */
char * data;
int count, number;
/* More stuff */
number = atoi(data);
if (number > count)
{
count = number;
hitpin();
}
/* Even more stuff */
If this doesnāt do what you want then you need to let us know what you want.
Added the following after your latest postā¦
Converting your pseudo codeā¦
int salescount = 0; //global var tracking sales count
void soundtrigger(char *salesdatastring)
{
int newcount;
//magic that splits the salesdatastring
newcount = atoi(salesdatastring);
//magic that checks split count against global var
if newcount > salescount {
digitalWrite(sound, HIGH); // sets the LED on
delay(200); // waits for 200mS
digitalWrite(sound, LOW); // sets the LED off
salescount = newcount; // update global sales count var
}
return;
}
cannot convert āconst char*ā to āchar**ā
Ah yes sorry, I should have mentioned it: argv in a main() function is mutable - and I whipped up my code snippet based on that cuz I thought it was obvious.
You need to copy your const char *
to a char *
if you want to modify it. If you donāt intend to modify it and the compiler complains about the assignment, you can cast it but itās not terribly clean.
EDIT: looks like that ship has sailed. I really should refresh my browser more often
@Pilgrimsmaster Tumbleweeds? Stand back, I got this.
I present to you an argument against metric time.
That oughta stir 'em up!
So that is 10.18. Presumably 10 is noon/midnight, so 10.18 would equate to almost 13 minutes past noon.
What is so difficult about that?
O.k. it is 10.1827 which is just the other side of 12:13. I did assume 20 hours in a day, 10 ante meridian and 10 post meridian. If not then this is remarkably well lit for the middle of the night.
I canāt for the life of me imagine that metric time, given itās pedantic need for unambiguity would permit an A.M or P.M. designation. I submit to you sir that there are only 10 hours per day.
Furthermore I would point out the possibly false assumption that this time system would experience time zones (see unambiguity comment from above).
So itās 18 metric minutes past the origin point, which is assumably the Greenwich Observatory, although that would be an assumption all of itās own.
The clock could then be anywhere in the world, although the sunlight would suggest itās nearly opposite whatever is being used as a prime meridian.
Time is a construct. Play with it however you like.
Ah. But the architecture reminds me of New Scotland Yard, so I submit that this is in fact on the heart of London and so very close to the meridian. I did find an article which suggested that in fact current 6am should be 0/10 but that was purely their suggestion. They didnāt mention time zones at all but given they chose 6am to represent the start of daylight I think that they assumed local time.
So, if there are only 10 hours in the day this is 00:26ā¦ As this is London (prove me wrong) this is the middle of the night.
Time is Relative (just ask Einstein)