Skip to content

Commit

Permalink
Merge pull request phev-remote#4 from GMTA/add-parking-lights-support
Browse files Browse the repository at this point in the history
Add parking lights support
  • Loading branch information
papawattu authored Sep 23, 2020
2 parents 4baa09a + e86328a commit b804493
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
21 changes: 17 additions & 4 deletions include/phevargs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdint.h>

#define HEADLIGHTS "headlights"
#define PARKING_LIGHTS "parkinglights"
#define BATTERY "battery"
#define AIRCON "aircon"
#define AIRCON_MODE "acmode"
Expand All @@ -24,7 +25,20 @@
#define WINDSCREEN "windscreen"
#define WAIT_FOR_REG_MAX 40

typedef enum phev_args_commands_t { CMD_UNSET, CMD_MONITOR, CMD_INVALID, CMD_STATUS, CMD_REGISTER, CMD_HEADLIGHTS, CMD_BATTERY, CMD_AIRCON, CMD_AIRCON_MODE, CMD_GET_REG_VAL, CMD_DISPLAY_REG } phev_args_commands_t;
typedef enum phev_args_commands_t {
CMD_UNSET,
CMD_MONITOR,
CMD_INVALID,
CMD_STATUS,
CMD_REGISTER,
CMD_HEADLIGHTS,
CMD_PARKING_LIGHTS,
CMD_BATTERY,
CMD_AIRCON,
CMD_AIRCON_MODE,
CMD_GET_REG_VAL,
CMD_DISPLAY_REG,
} phev_args_commands_t;

typedef struct phev_args_opts_t {
bool init;
Expand All @@ -50,7 +64,7 @@ static uint8_t PHEV_ARGS_DEFAULT_MAC[] = {0,0,0,0,0,0};
static const char * phev_args_argp_program_version = "Version\t" VERSION;
static const char * phev_args_argp_program_bug_address = "[email protected]";
static char phev_args_doc[] = "\n\nProgram to control the car via the remote WiFi interface. Requires this device to be connected to the REMOTE**** access point with a valid IP address, which is on the 192.168.8.x subnet.\n\nTHIS PROGRAM COMES WITH NO WARRANTY ANY DAMAGE TO THE CAR OR ANY OTHER EQUIPMENT IS AT THE USERS OWN RISK.";
static char phev_args_args_doc[] = "register\nbattery\naircon [on|off]\nacmode [heat|cool|windscreen] [10|20|30]\nheadlights [on|off]\nmonitor\nget <register>";
static char phev_args_args_doc[] = "register\nbattery\naircon [on|off]\nacmode [heat|cool|windscreen] [10|20|30]\nheadlights [on|off]\nparkinglights [on|off]\nmonitor\nget <register>";
static struct argp_option phev_args_options[] = {
{ "mac", 'm', "<MAC ADDRESS>",0, "MAC address."},
{ "host", 'h', "<HOST NAME>",OPTION_HIDDEN, "IP address of car - defaults to 192.168.8.46."},
Expand All @@ -60,5 +74,4 @@ static struct argp_option phev_args_options[] = {
};
phev_args_opts_t * phev_args_parse(int argc, char *argv[]);


#endif
#endif
32 changes: 12 additions & 20 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,9 @@ static void operationCallbackNoExit(phevCtx_t *ctx, void *value)
{
printf("Operation successful\n");
}
static void batteryLevelCallback(phevCtx_t *ctx, void *level)
{
printf("Battery %d\n", *((int *)level));
phev_exit(ctx);
exit(0);
}
static void turnonlights(phevCtx_t *ctx)
{
printf("\n\nTURN ON LIGHTS\n\n");
ctx->serviceCtx->pipe->currentXOR = 0xd0;
phev_headLights(ctx,true,NULL);
}
static bool d = true;

static int main_eventHandler(phevEvent_t *event)
{

phevCtx_t *ctx = event->ctx;

phev_args_opts_t *opts = (phev_args_opts_t *)phev_getUserCtx(ctx);
Expand Down Expand Up @@ -147,20 +134,26 @@ static int main_eventHandler(phevEvent_t *event)
{
case CMD_HEADLIGHTS:
{
printf("Turning %s headlights\n",(opts->operand_on ? "ON" : "OFF"));
phev_headLights(event->ctx,opts->operand_on,operationCallback);
printf("Turning %s headlights\n", opts->operand_on ? "ON" : "OFF");
phev_headLights(event->ctx, opts->operand_on, operationCallback);
break;
}
case CMD_PARKING_LIGHTS:
{
printf("Turning %s parking lights\n", opts->operand_on ? "ON" : "OFF");
phev_parkingLights(event->ctx, opts->operand_on, operationCallback);
break;
}
case CMD_AIRCON:
{
printf("Turning air conditioning %s\n", (opts->operand_on ? "ON" : "OFF"));
printf("Turning air conditioning %s\n", opts->operand_on ? "ON" : "OFF");
phev_airCon(event->ctx, opts->operand_on, operationCallback);
break;
}
case CMD_AIRCON_MODE:
{
printf("Switching air conditioning mode to %d for %d mins\n", opts->operand_mode, opts->operand_time);
phev_airConMode(event->ctx,opts->operand_mode,opts->operand_time,operationCallback);
phev_airConMode(event->ctx, opts->operand_mode, opts->operand_time, operationCallback);
break;
}
}
Expand Down Expand Up @@ -196,9 +189,9 @@ void print_intro()
printf("Designed and coded by Jamie Nuttall 2020\nMIT License\n\n");
printf("Type 'x' then enter to quit.\n");
}

int main(int argc, char *argv[])
{

phevCtx_t *ctx = NULL;

phev_args_opts_t *opts = phev_args_parse(argc, argv);
Expand Down Expand Up @@ -254,7 +247,6 @@ int main(int argc, char *argv[])
int ret = pthread_create(&main, NULL, main_thread, (void *)ctx);
//main_thread((void *) ctx);
char ch;
static bool d = true;
do
{
ch = getchar();
Expand Down
18 changes: 10 additions & 8 deletions src/phevargs.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include <stddef.h>
#include "phevargs.h"


int phev_args_validate(int arg_num,phev_args_opts_t * opts)
{
switch (opts->command)
{
case CMD_HEADLIGHTS:
case CMD_PARKING_LIGHTS:
case CMD_AIRCON:
{
if(arg_num == 2)
Expand Down Expand Up @@ -60,6 +60,7 @@ int phev_args_validate(int arg_num,phev_args_opts_t * opts)
opts->error = true;
return 1;
}

int phev_args_process_operands(char * arg, int arg_num, phev_args_opts_t * opts)
{
switch (opts->command)
Expand All @@ -70,6 +71,7 @@ int phev_args_process_operands(char * arg, int arg_num, phev_args_opts_t * opts)
break;
}
case CMD_HEADLIGHTS:
case CMD_PARKING_LIGHTS:
case CMD_AIRCON: {
if(arg_num == 1)
{
Expand Down Expand Up @@ -157,13 +159,9 @@ int phev_args_process_operands(char * arg, int arg_num, phev_args_opts_t * opts)
break;
}
}
if(!opts->error)
{
return 0;
} else {
return 1;
}
return opts->error ? 1 : 0;
}

int phev_args_process_command(char * arg, int arg_num, phev_args_opts_t * opts)
{
if(strcmp(arg,REGISTER) == 0 && arg_num ==0)
Expand All @@ -174,6 +172,10 @@ int phev_args_process_command(char * arg, int arg_num, phev_args_opts_t * opts)
{
opts->command = CMD_HEADLIGHTS;
}
if(strcmp(arg,PARKING_LIGHTS) == 0 && arg_num == 0)
{
opts->command = CMD_PARKING_LIGHTS;
}
if(strcmp(arg,BATTERY) == 0 && arg_num == 0)
{
opts->command = CMD_BATTERY;
Expand All @@ -196,6 +198,7 @@ int phev_args_process_command(char * arg, int arg_num, phev_args_opts_t * opts)
}
return 0;
}

static error_t phev_args_parse_opt(int key, char *arg, struct argp_state *state) {
phev_args_opts_t * opts = state->input;

Expand Down Expand Up @@ -262,7 +265,6 @@ static error_t phev_args_parse_opt(int key, char *arg, struct argp_state *state)
}
case ARGP_KEY_END:
{

if(opts->error)
{
opts->command = CMD_INVALID;
Expand Down

0 comments on commit b804493

Please sign in to comment.