Exemple #1
0
void General::Initialize() {
    INIT_CONTROL(GRP_BEHAVIOR, GroupBox, _behaviorGroup);
    INIT_CONTROL(CHK_STARTUP, Checkbox, _startup);
    INIT_CONTROL(CHK_NOTIFY, Checkbox, _notifyIcon);
    INIT_CONTROL(CHK_SOUNDS, Checkbox, _sounds);

    INIT_CONTROL(GRP_SKIN, GroupBox, _skinGroup);
    INIT_CONTROL(CMB_SKIN, ComboBox, _skin);
    _skin.OnSelectionChange = [this]() {
        LoadSkinInfo(_skin.Selection());
        return true;
    };
    INIT_CONTROL(LBL_AUTHOR, Label, _author);
    INIT_CONTROL(BTN_WEBSITE, Button, _website);
    _website.OnClick = [this]() {
        if (_url != L"") {
            ShellExecute(NULL, L"open", _url.c_str(),
                NULL, NULL, SW_SHOWNORMAL);
        }
        return true;
    };

    INIT_CONTROL(GRP_LANGUAGE, GroupBox, _languageGroup);
    INIT_CONTROL(CMB_LANG, ComboBox, _language);
    _language.OnSelectionChange = [this]() {
        // Handle language selection change 
        return true;
    };
}
control_t *route_control_create(route_t* route) {
		if (route == NULL)
				return NULL;

		control_t *control = (control_t*)vp_os_malloc(sizeof(control_t));
		control_t *control_head = control;
		NODE_T *target = route->head;

		if (target == NULL)
				return NULL;

		//INIT_CONTROL(control, 0, 0, 0);

		angle_t hori_angle;
		angle_t vert_angle;
		distance_t distance;

		vp_os_mutex_lock(&NOW_mutex);
		distance_t last_x = NOW.x;
		distance_t last_y = NOW.y;
		distance_t last_z = NOW.z;
		vp_os_mutex_unlock(&NOW_mutex);

		while (target != NULL) {
				//get paras
				distance_t vect_x = target->x - last_x;
				distance_t vect_y = target->y - last_y;
				distance_t vect_z = target->z - last_z;

				printf("last %lf %lf %lf\n", last_x, last_y, last_z);
				printf("vect %lf %lf %lf\n", vect_x, vect_y, vect_z);

				last_x = target->x;
				last_y = target->y;
				last_z = target->z;

				//calcu
				MAKE_HORI_ANGLE(hori_angle, vect_x, vect_y);
				MAKE_VERT_ANGLE(vert_angle, vect_x, vect_y, vect_z);
				distance = sqrt(POW2(vect_x) + POW2(vect_y) + POW2(vect_z)) * route->unit_distance;
				
				//init control node
				INIT_CONTROL(control, hori_angle, vert_angle, distance);

				printf("control dis%lf angle%lf\n", control->distance, control->hori_angle);
				
				if (target->next != NULL) {
						control->next = (control_t*)vp_os_malloc(sizeof(control_t));
						control = control->next;
				}


				target = target->next;
		}

		return control_head;
}
Exemple #3
0
/* Main function
 * Fills the box with accepted parts and then transmits it to the printer
 */
void* doBox(void*a) {
	/* INIT *******************************************************************/
	INCLUDE(Box)
	INCLUDE(Valve)
	INIT_LOGGER();
	INIT_CONTROL();
	INIT_CHECK_FOR_APP_END();
	extern int PARTS_BY_BOX;
	extern int MAX_REFUSED_PARTS_BY_BOX;
	extern int CurrentBatchProdMax;
	extern int CurrentProducedBoxes;
	extern int CurrentBatchRefusedPartsNumber;
	extern int BOXES_BY_PALETTE;
	extern sem_t SemSyncBoxPrint;
	extern sem_t SemPushBoxPrint;
	extern sem_t SemNewPart;
	int refusedPartsCount = 0; /* Number of parts that have been refused for the current box (not to be higher than MAX_REFUSED_PARTS_BY_BOX) */
	int currentBoxPartsNumber = 0;

#ifdef DBG
	printf("%d\n", (int) getpid());
#endif

	/* MAIN LOOP **************************************************************/
	for (;;) {
		CHECK_WAIT_BOOL(Box);
		CHECK_FOR_APP_END_AND_STOP("Box");
		DBGPRINT("doBox", "Main", "Task is unlocked.");

		bool boxIsMissing = TRUE;
#ifdef SIMU_MODE
		boxIsMissing = simu_missing_box();
#endif

		if (boxIsMissing) {
			/* Closing the valve */
			LOCK(Valve);
			DBGPRINT("doBox", "Main", "Closing valve.");
			LOG("doBox: Missing box, ERROR.");
			LOCK(Box); /* Forbidding ourself to do another loop before the green
					   * light has been set by the doControl thread */

			/* Sending error message */
			ERR_MSG(ERR_BOX);
			/* Going back to the beginning of the loop and standing still until
			 * the doControl thread says otherwise */
			continue;
		}

		/* At the end of the loop (and thus at its beginning, the other way
		 * around), we are basically just waiting for a new part
		 * This part will come as a unlocking the sempahore SemSimuNewPart
		 * (supposed to be an IT) */
		sem_wait(&SemNewPart);

		bool refused = TRUE;
#ifdef SIMU_MODE
		refused = simu_refusal();
#endif
		if (!refused) /* Part is accepted */ {
			DBGPRINT("doBox", "Main", "New accepted part.");
			LOG("doBox: New accepted part.");
			/* There's a new part to put in that freaking box: */
			currentBoxPartsNumber = (currentBoxPartsNumber + 1) % PARTS_BY_BOX;
			DBGPRINT("doBox", "Main", "currentBoxPartsNumber=");
#ifdef DBG
			printf("%d\n", currentBoxPartsNumber);
#endif

			if (!currentBoxPartsNumber) /* Is the box full? */ {
				DBGPRINT("doBox", "Main", "The box is full");
				refusedPartsCount = 0; /* Reset refused parts by box counter */
				CurrentProducedBoxes++;
				if ((CurrentProducedBoxes / BOXES_BY_PALETTE) >= CurrentBatchProdMax) {
					/* The current batch is over, so close the valve */
					LOCK(Valve);
					/* And send a log so that the client is able to know that
					 * the production of the current batch is over
					 * (important call, not to be deleted or changed) */
					LOG(PRODUCTION_IS_OVER_MSG);
				}
				/* **** "READY TO GO TO PRINTER" SEMAPHORE CHECK */
				sem_wait(&SemSyncBoxPrint);
				sem_post(&SemPushBoxPrint);
			}
		} else {
			DBGPRINT("doBox", "Main", "New REFUSED part.");
			LOG("doBox: New REFUSED part.");

			refusedPartsCount++;
			CurrentBatchRefusedPartsNumber++;
			if (refusedPartsCount >= MAX_REFUSED_PARTS_BY_BOX) {
				/* Closing the valve */
				refusedPartsCount = 0; /* Resetting the counter, so that when
									    * the error is marked as "solved" we
									    * don't go back into error mode */
				LOCK(Valve);
				DBGPRINT("doBox", "Main", "Closing valve.");
				LOG("doBox: Refused rate is too high, ERROR.");
				LOCK(Box); /* Forbidding ourself to do another loop before the
						   * green light has been set by the doControl thread */

				/* Sending error message */
				ERR_MSG(ERR_BOX_REFUSED_RATE);
			}
		}
	}
}