Add query parameter to generic resouce macros
Modify all callback functions to use new signature. ota-update now uses this to pass the partition to some get/put methods.
This commit is contained in:
parent
954da749eb
commit
e3784fa9c7
20 changed files with 357 additions and 82 deletions
|
@ -17,7 +17,8 @@
|
|||
#include "generic_resource.h"
|
||||
#include "led_pwm.h"
|
||||
|
||||
int pwm_from_string (const char *name, const char *uri, const char *s)
|
||||
int pwm_from_string
|
||||
(const char *name, const char *uri, const char *query, const char *s)
|
||||
{
|
||||
uint32_t tmp = strtoul (s, NULL, 10);
|
||||
if (tmp > 255) {
|
||||
|
@ -28,7 +29,13 @@ int pwm_from_string (const char *name, const char *uri, const char *s)
|
|||
}
|
||||
|
||||
size_t
|
||||
pwm_to_string (const char *name, const char *uri, char *buf, size_t bufsize)
|
||||
pwm_to_string
|
||||
( const char *name
|
||||
, const char *uri
|
||||
, const char *query
|
||||
, char *buf
|
||||
, size_t bufsize
|
||||
)
|
||||
{
|
||||
return snprintf (buf, bufsize, "%d", pwm);
|
||||
}
|
||||
|
@ -42,7 +49,8 @@ GENERIC_RESOURCE \
|
|||
, pwm_to_string
|
||||
);
|
||||
|
||||
int period_from_string (const char *name, const char *uri, const char *s)
|
||||
int period_from_string
|
||||
(const char *name, const char *uri, const char *query, const char *s)
|
||||
{
|
||||
uint32_t tmp = (strtoul (s, NULL, 10) + 50) / 100;
|
||||
if (tmp > 10) {
|
||||
|
@ -56,7 +64,13 @@ int period_from_string (const char *name, const char *uri, const char *s)
|
|||
}
|
||||
|
||||
size_t
|
||||
period_to_string (const char *name, const char *uri, char *buf, size_t bufsize)
|
||||
period_to_string
|
||||
( const char *name
|
||||
, const char *uri
|
||||
, const char *query
|
||||
, char *buf
|
||||
, size_t bufsize
|
||||
)
|
||||
{
|
||||
return snprintf (buf, bufsize, "%d", period_100ms * 100);
|
||||
}
|
||||
|
@ -71,7 +85,13 @@ GENERIC_RESOURCE \
|
|||
);
|
||||
|
||||
size_t
|
||||
analog2_v (const char *name, const char *uri, char *buf, size_t bufsize)
|
||||
analog2_v
|
||||
( const char *name
|
||||
, const char *uri
|
||||
, const char *query
|
||||
, char *buf
|
||||
, size_t bufsize
|
||||
)
|
||||
{
|
||||
return snprintf
|
||||
(buf, bufsize, "%d.%03d", analog2_voltage / 1000, analog2_voltage % 1000);
|
||||
|
@ -87,7 +107,13 @@ GENERIC_RESOURCE \
|
|||
);
|
||||
|
||||
size_t
|
||||
analog5_v (const char *name, const char *uri, char *buf, size_t bufsize)
|
||||
analog5_v
|
||||
( const char *name
|
||||
, const char *uri
|
||||
, const char *query
|
||||
, char *buf
|
||||
, size_t bufsize
|
||||
)
|
||||
{
|
||||
return snprintf
|
||||
(buf, bufsize, "%d.%03d", analog5_voltage / 1000, analog5_voltage % 1000);
|
||||
|
|
|
@ -25,10 +25,10 @@ void setup (void)
|
|||
{
|
||||
arduino_pwm_timer_init ();
|
||||
rest_init_engine ();
|
||||
rest_activate_resource (&res_led_pwm, "led/pwm");
|
||||
rest_activate_resource (&res_led_period, "led/period");
|
||||
rest_activate_resource (&res_analog2_voltage, "analog/2");
|
||||
rest_activate_resource (&res_analog5_voltage, "analog/5");
|
||||
rest_activate_resource (&res_led_pwm, (char *)"led/pwm");
|
||||
rest_activate_resource (&res_led_period, (char *)"led/period");
|
||||
rest_activate_resource (&res_analog2_voltage, (char *)"analog/2");
|
||||
rest_activate_resource (&res_analog5_voltage, (char *)"analog/5");
|
||||
}
|
||||
|
||||
void loop (void)
|
||||
|
@ -37,7 +37,7 @@ void loop (void)
|
|||
analogWrite (LED_PIN, 255 - pwm);
|
||||
analog2_voltage = analogRead (A2) * 1600L / 1023L;
|
||||
analog5_voltage = analogRead (A5) * 1600L / 1023L;
|
||||
printf ("clock : %u\nmillis: %lu\n", clock_time (), millis ());
|
||||
printf ("clock : %lu\nmillis: %lu\n", clock_time (), millis ());
|
||||
delay (period_100ms * 100);
|
||||
analogWrite (LED_PIN, 255); /* OFF: LED on merkur-board is wired to +3.3V */
|
||||
delay (period_100ms * 100);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue