add buttons in Factory
This commit is contained in:
parent
38bfd12b25
commit
1b926c1ab9
@ -6,16 +6,50 @@ static Factory theFactory;
|
||||
|
||||
|
||||
//all the getters
|
||||
LED* l()
|
||||
{
|
||||
return &theFactory.l_;
|
||||
LED* l1() {
|
||||
return &theFactory.l1_;
|
||||
}
|
||||
LED* l2(){
|
||||
LED* l2() {
|
||||
return &theFactory.l2_;
|
||||
}
|
||||
LED* l3() {
|
||||
return &theFactory.l3_;
|
||||
}
|
||||
LED* l4() {
|
||||
return &theFactory.l4_;
|
||||
}
|
||||
LED* l5() {
|
||||
return &theFactory.l5_;
|
||||
}
|
||||
LED* l6() {
|
||||
return &theFactory.l6_;
|
||||
}
|
||||
LED* l7() {
|
||||
return &theFactory.l7_;
|
||||
}
|
||||
LED* l8() {
|
||||
return &theFactory.l8_;
|
||||
}
|
||||
LED* l9() {
|
||||
return &theFactory.l9_;
|
||||
}
|
||||
LED* l10() {
|
||||
return &theFactory.l10_;
|
||||
}
|
||||
|
||||
LEDBlinker* lb() {
|
||||
return &theFactory.lb_;
|
||||
BUTTON* b1() {
|
||||
return &theFactory.b1_;
|
||||
}
|
||||
BUTTON* b2() {
|
||||
return &theFactory.b2_;
|
||||
}
|
||||
BUTTON* b3() {
|
||||
return &theFactory.b3_;
|
||||
}
|
||||
|
||||
|
||||
LEDBlinker* lb1() {
|
||||
return &theFactory.lb1_;
|
||||
}
|
||||
|
||||
LEDBlinker* lb2() {
|
||||
@ -23,22 +57,46 @@ LEDBlinker* lb2() {
|
||||
}
|
||||
|
||||
//initialize all objects
|
||||
void Factory_init()
|
||||
{
|
||||
LED_init(l(),LID);
|
||||
LED_init(l2(),2);
|
||||
LED_initHW(l());
|
||||
void Factory_init() {
|
||||
LED_init(l1(), 1);
|
||||
LED_init(l2(), 2);
|
||||
LED_init(l3(), 3);
|
||||
LED_init(l4(), 4);
|
||||
LED_init(l5(), 5);
|
||||
LED_init(l6(), 6);
|
||||
LED_init(l7(), 7);
|
||||
LED_init(l8(), 8);
|
||||
LED_init(l9(), 9);
|
||||
LED_init(l10(), 10);
|
||||
|
||||
BUTTON_init(b1(), 1);
|
||||
BUTTON_init(b2(), 2);
|
||||
BUTTON_init(b3(), 3);
|
||||
|
||||
|
||||
LED_initHW(l1());
|
||||
LED_initHW(l2());
|
||||
LED_initHW(l3());
|
||||
LED_initHW(l4());
|
||||
LED_initHW(l5());
|
||||
LED_initHW(l6());
|
||||
LED_initHW(l7());
|
||||
LED_initHW(l8());
|
||||
LED_initHW(l9());
|
||||
LED_initHW(l10());
|
||||
|
||||
BUTTON_initHW(b1());
|
||||
BUTTON_initHW(b2());
|
||||
BUTTON_initHW(b3());
|
||||
}
|
||||
|
||||
//connect objects if required
|
||||
void Factory_build()
|
||||
{
|
||||
|
||||
void Factory_build() {
|
||||
|
||||
}
|
||||
|
||||
//start all state machines
|
||||
void Factory_start() {
|
||||
LEDBlinker_startBehaviour(lb());
|
||||
LEDBlinker_startBehaviour(lb1());
|
||||
LEDBlinker_startBehaviour(lb2());
|
||||
}
|
||||
|
@ -8,15 +8,27 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "../../board/led/led.h"
|
||||
#include "../../board/button/button.h"
|
||||
#include "../ledblinker.h"
|
||||
#define LID 5
|
||||
#define LID 1
|
||||
|
||||
|
||||
struct Factory_
|
||||
{
|
||||
LED l_;
|
||||
struct Factory_ {
|
||||
LED l1_;
|
||||
LED l2_;
|
||||
LEDBlinker lb_;
|
||||
LED l3_;
|
||||
LED l4_;
|
||||
LED l5_;
|
||||
LED l6_;
|
||||
LED l7_;
|
||||
LED l8_;
|
||||
LED l9_;
|
||||
LED l10_;
|
||||
BUTTON b1_;
|
||||
BUTTON b2_;
|
||||
BUTTON b3_;
|
||||
|
||||
LEDBlinker lb1_;
|
||||
LEDBlinker lb2_;
|
||||
};
|
||||
|
||||
@ -28,9 +40,22 @@ void Factory_build();
|
||||
void Factory_start();
|
||||
|
||||
//these are global getters for our objects
|
||||
LED* l();
|
||||
LED* l2();
|
||||
LEDBlinker* lb();
|
||||
LED* l1();
|
||||
LED* l2();
|
||||
LED* l3();
|
||||
LED* l4();
|
||||
LED* l5();
|
||||
LED* l6();
|
||||
LED* l7();
|
||||
LED* l8();
|
||||
LED* l9();
|
||||
LED* l10();
|
||||
|
||||
BUTTON* b1();
|
||||
BUTTON* b2();
|
||||
BUTTON* b3();
|
||||
|
||||
LEDBlinker* lb1();
|
||||
LEDBlinker* lb2();
|
||||
|
||||
#endif
|
@ -2,40 +2,33 @@
|
||||
#include "factory/factory.h"
|
||||
#include "../board/led/led.h"
|
||||
|
||||
void LEDBlinker_init(LEDBlinker* me)
|
||||
{
|
||||
void LEDBlinker_init(LEDBlinker* me) {
|
||||
me->state = ST_LBINIT;
|
||||
}
|
||||
|
||||
void LEDBlinker_startBehaviour(LEDBlinker* me)
|
||||
{
|
||||
void LEDBlinker_startBehaviour(LEDBlinker* me) {
|
||||
POST(me, &LEDBlinker_processEvent, evLBInit,0,0);
|
||||
}
|
||||
|
||||
bool LEDBlinker_processEvent(Event* ev)
|
||||
{
|
||||
bool LEDBlinker_processEvent(Event* ev) {
|
||||
bool processed = false;
|
||||
LEDBlinker* me = (LEDBlinker*)Event_getTarget(ev);
|
||||
LBSTATES oldState = me->state;
|
||||
evIDT evid = Event_getId(ev);
|
||||
|
||||
switch (me->state)
|
||||
{
|
||||
switch (me->state) {
|
||||
case ST_LBINIT:
|
||||
if (evid == evLBInit)
|
||||
{
|
||||
if (evid == evLBInit) {
|
||||
me->state = ST_LBOFF;
|
||||
}
|
||||
break;
|
||||
case ST_LBOFF:
|
||||
if (evid == evLBTMOn)
|
||||
{
|
||||
if (evid == evLBTMOn) {
|
||||
me->state = ST_LBON;
|
||||
}
|
||||
break;
|
||||
case ST_LBON:
|
||||
if (evid == evLBTMOff)
|
||||
{
|
||||
if (evid == evLBTMOff) {
|
||||
me->state = ST_LBOFF;
|
||||
}
|
||||
break;
|
||||
@ -43,10 +36,8 @@ bool LEDBlinker_processEvent(Event* ev)
|
||||
break;
|
||||
}
|
||||
|
||||
if (oldState != me->state)
|
||||
{
|
||||
switch (me->state)
|
||||
{
|
||||
if (oldState != me->state) {
|
||||
switch (me->state) {
|
||||
case ST_LBINIT:
|
||||
break;
|
||||
case ST_LBOFF:
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "../board/led/led.h"
|
||||
#include "../app/factory/factory.h"
|
||||
#include "../xf/xf.h"
|
||||
#include "../board/button/button.h"
|
||||
|
||||
bool test(Event* ev);
|
||||
|
||||
@ -35,13 +36,30 @@ void main(void)
|
||||
|
||||
Factory_init();
|
||||
Factory_build();
|
||||
Factory_start();
|
||||
//Factory_start();
|
||||
|
||||
TMR0_SetInterruptHandler(XF_decrementAndQueueTimers);
|
||||
//TMR0_SetInterruptHandler(XF_decrementAndQueueTimers);
|
||||
|
||||
|
||||
|
||||
while (1)
|
||||
{
|
||||
XF_executeOnce();
|
||||
while (1) {
|
||||
//XF_executeOnce();
|
||||
if (BUTTON_isPressed(b1())) {
|
||||
LED_on(l3());
|
||||
} else {
|
||||
LED_off(l3());
|
||||
}
|
||||
|
||||
if (BUTTON_isPressed(b2())) {
|
||||
LED_on(l2());
|
||||
} else {
|
||||
LED_off(l2());
|
||||
}
|
||||
|
||||
if (BUTTON_isPressed(b3())) {
|
||||
LED_on(l1());
|
||||
} else {
|
||||
LED_off(l1());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
68
03-software/ch/kb28/blinkerProject/board/button/button.c
Normal file
68
03-software/ch/kb28/blinkerProject/board/button/button.c
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* @file button.c
|
||||
* @author Rémi Heredero (remi@heredero.ch)
|
||||
* @version 0.1
|
||||
* @date 2023-06-06
|
||||
*
|
||||
*/
|
||||
|
||||
#include "button.h"
|
||||
#include "../../mcc_generated_files/pin_manager.h"
|
||||
|
||||
/**
|
||||
* @brief Initialize the button
|
||||
*
|
||||
* @param me The object to initialize
|
||||
* @param id The id of the button
|
||||
*/
|
||||
void BUTTON_init(BUTTON* me, uint8_t id) {
|
||||
me->id = id;
|
||||
me->state = ST_PBINIT;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the hardware of the button
|
||||
*
|
||||
* @param me The object to initialize
|
||||
*/
|
||||
void BUTTON_initHW(BUTTON* me) {
|
||||
switch (me->id) {
|
||||
case 1:
|
||||
INPUT1_SetDigitalInput();
|
||||
break;
|
||||
case 2:
|
||||
INPUT2_SetDigitalInput();
|
||||
break;
|
||||
case 3:
|
||||
INPUT3_SetDigitalInput();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the button is pressed
|
||||
* The function returns true if the button is pressed, false otherwise
|
||||
*
|
||||
* @param me The object to check
|
||||
* @return true if the button is pressed
|
||||
* @return false if the button is not pressed
|
||||
*/
|
||||
bool BUTTON_isPressed(BUTTON* me) {
|
||||
switch (me->id) {
|
||||
case 1:
|
||||
return INPUT1_GetValue();
|
||||
break;
|
||||
case 2:
|
||||
return INPUT2_GetValue();
|
||||
break;
|
||||
case 3:
|
||||
return INPUT3_GetValue();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
27
03-software/ch/kb28/blinkerProject/board/button/button.h
Normal file
27
03-software/ch/kb28/blinkerProject/board/button/button.h
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @file button.h
|
||||
* @author Rémi Heredero (remi@heredero.ch)
|
||||
* @version 0.1
|
||||
* @date 2023-06-06
|
||||
*
|
||||
*/
|
||||
#ifndef BUTTON_H
|
||||
#define BUTTON_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum {ST_PBINIT, ST_PBWAIT, ST_PBPOLL, ST_PBRELEASED, ST_PBPRESSED} BUTTON_STATES;
|
||||
typedef enum {evPBInit, evPBPoll} BUTTON_EVENTS;
|
||||
|
||||
typedef struct {
|
||||
uint8_t id;
|
||||
BUTTON_STATES state;
|
||||
|
||||
} BUTTON;
|
||||
|
||||
void BUTTON_init(BUTTON* me, uint8_t id);
|
||||
void BUTTON_initHW(BUTTON* me);
|
||||
bool BUTTON_isPressed(BUTTON* me);
|
||||
|
||||
#endif /* BUTTON_H */
|
@ -11,6 +11,9 @@
|
||||
<itemPath>ch/kb28/blinkerProject/app/ledblinker.h</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="board" displayName="board" projectFiles="true">
|
||||
<logicalFolder name="button" displayName="button" projectFiles="true">
|
||||
<itemPath>ch/kb28/blinkerProject/board/button/button.h</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="led" displayName="led" projectFiles="true">
|
||||
<itemPath>ch/kb28/blinkerProject/board/led/led.h</itemPath>
|
||||
</logicalFolder>
|
||||
@ -47,6 +50,9 @@
|
||||
<itemPath>ch/kb28/blinkerProject/app/main.c</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="board" displayName="board" projectFiles="true">
|
||||
<logicalFolder name="button" displayName="button" projectFiles="true">
|
||||
<itemPath>ch/kb28/blinkerProject/board/button/button.c</itemPath>
|
||||
</logicalFolder>
|
||||
<logicalFolder name="led" displayName="led" projectFiles="true">
|
||||
<itemPath>ch/kb28/blinkerProject/board/led/led.c</itemPath>
|
||||
</logicalFolder>
|
||||
@ -84,7 +90,7 @@
|
||||
<targetDevice>PIC18F87K22</targetDevice>
|
||||
<targetHeader></targetHeader>
|
||||
<targetPluginBoard></targetPluginBoard>
|
||||
<platformTool>noID</platformTool>
|
||||
<platformTool>PICkit3PlatformTool</platformTool>
|
||||
<languageToolchain>XC8</languageToolchain>
|
||||
<languageToolchainVersion>2.41</languageToolchainVersion>
|
||||
<platform>2</platform>
|
||||
@ -199,6 +205,94 @@
|
||||
<property key="program-the-device-with-default-config-words" value="true"/>
|
||||
<property key="remove-unused-sections" value="true"/>
|
||||
</HI-TECH-LINK>
|
||||
<PICkit3PlatformTool>
|
||||
<property key="AutoSelectMemRanges" value="auto"/>
|
||||
<property key="Freeze Peripherals" value="true"/>
|
||||
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
|
||||
<property key="ToolFirmwareFilePath"
|
||||
value="Press to browse for a specific firmware version"/>
|
||||
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
|
||||
<property key="debugoptions.debug-startup" value="Use system settings"/>
|
||||
<property key="debugoptions.reset-behaviour" value="Use system settings"/>
|
||||
<property key="debugoptions.useswbreakpoints" value="false"/>
|
||||
<property key="hwtoolclock.frcindebug" value="false"/>
|
||||
<property key="memories.aux" value="false"/>
|
||||
<property key="memories.bootflash" value="true"/>
|
||||
<property key="memories.configurationmemory" value="true"/>
|
||||
<property key="memories.configurationmemory2" value="true"/>
|
||||
<property key="memories.dataflash" value="true"/>
|
||||
<property key="memories.eeprom" value="true"/>
|
||||
<property key="memories.flashdata" value="true"/>
|
||||
<property key="memories.id" value="true"/>
|
||||
<property key="memories.instruction.ram" value="true"/>
|
||||
<property key="memories.instruction.ram.ranges"
|
||||
value="${memories.instruction.ram.ranges}"/>
|
||||
<property key="memories.programmemory" value="true"/>
|
||||
<property key="memories.programmemory.ranges" value="0-1ffff"/>
|
||||
<property key="poweroptions.powerenable" value="false"/>
|
||||
<property key="programmertogo.imagename" value=""/>
|
||||
<property key="programoptions.donoteraseauxmem" value="false"/>
|
||||
<property key="programoptions.eraseb4program" value="true"/>
|
||||
<property key="programoptions.pgmspeed" value="2"/>
|
||||
<property key="programoptions.preservedataflash" value="false"/>
|
||||
<property key="programoptions.preservedataflash.ranges"
|
||||
value="${programoptions.preservedataflash.ranges}"/>
|
||||
<property key="programoptions.preserveeeprom" value="false"/>
|
||||
<property key="programoptions.preserveeeprom.ranges" value="0-3ff"/>
|
||||
<property key="programoptions.preserveprogram.ranges" value=""/>
|
||||
<property key="programoptions.preserveprogramrange" value="false"/>
|
||||
<property key="programoptions.preserveuserid" value="false"/>
|
||||
<property key="programoptions.programcalmem" value="false"/>
|
||||
<property key="programoptions.programuserotp" value="false"/>
|
||||
<property key="programoptions.testmodeentrymethod" value="VDDFirst"/>
|
||||
<property key="programoptions.usehighvoltageonmclr" value="false"/>
|
||||
<property key="programoptions.uselvpprogramming" value="false"/>
|
||||
<property key="voltagevalue" value="3.25"/>
|
||||
</PICkit3PlatformTool>
|
||||
<Tool>
|
||||
<property key="AutoSelectMemRanges" value="auto"/>
|
||||
<property key="Freeze Peripherals" value="true"/>
|
||||
<property key="SecureSegment.SegmentProgramming" value="FullChipProgramming"/>
|
||||
<property key="ToolFirmwareFilePath"
|
||||
value="Press to browse for a specific firmware version"/>
|
||||
<property key="ToolFirmwareOption.UseLatestFirmware" value="true"/>
|
||||
<property key="debugoptions.debug-startup" value="Use system settings"/>
|
||||
<property key="debugoptions.reset-behaviour" value="Use system settings"/>
|
||||
<property key="debugoptions.useswbreakpoints" value="false"/>
|
||||
<property key="hwtoolclock.frcindebug" value="false"/>
|
||||
<property key="memories.aux" value="false"/>
|
||||
<property key="memories.bootflash" value="true"/>
|
||||
<property key="memories.configurationmemory" value="true"/>
|
||||
<property key="memories.configurationmemory2" value="true"/>
|
||||
<property key="memories.dataflash" value="true"/>
|
||||
<property key="memories.eeprom" value="true"/>
|
||||
<property key="memories.flashdata" value="true"/>
|
||||
<property key="memories.id" value="true"/>
|
||||
<property key="memories.instruction.ram" value="true"/>
|
||||
<property key="memories.instruction.ram.ranges"
|
||||
value="${memories.instruction.ram.ranges}"/>
|
||||
<property key="memories.programmemory" value="true"/>
|
||||
<property key="memories.programmemory.ranges" value="0-1ffff"/>
|
||||
<property key="poweroptions.powerenable" value="false"/>
|
||||
<property key="programmertogo.imagename" value=""/>
|
||||
<property key="programoptions.donoteraseauxmem" value="false"/>
|
||||
<property key="programoptions.eraseb4program" value="true"/>
|
||||
<property key="programoptions.pgmspeed" value="2"/>
|
||||
<property key="programoptions.preservedataflash" value="false"/>
|
||||
<property key="programoptions.preservedataflash.ranges"
|
||||
value="${programoptions.preservedataflash.ranges}"/>
|
||||
<property key="programoptions.preserveeeprom" value="false"/>
|
||||
<property key="programoptions.preserveeeprom.ranges" value="0-3ff"/>
|
||||
<property key="programoptions.preserveprogram.ranges" value=""/>
|
||||
<property key="programoptions.preserveprogramrange" value="false"/>
|
||||
<property key="programoptions.preserveuserid" value="false"/>
|
||||
<property key="programoptions.programcalmem" value="false"/>
|
||||
<property key="programoptions.programuserotp" value="false"/>
|
||||
<property key="programoptions.testmodeentrymethod" value="VDDFirst"/>
|
||||
<property key="programoptions.usehighvoltageonmclr" value="false"/>
|
||||
<property key="programoptions.uselvpprogramming" value="false"/>
|
||||
<property key="voltagevalue" value="3.25"/>
|
||||
</Tool>
|
||||
<XC8-CO>
|
||||
<property key="coverage-enable" value=""/>
|
||||
<property key="stack-guidance" value="false"/>
|
||||
|
Reference in New Issue
Block a user